Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (218 loc) · 9.03 KB
/
Copy pathMakefile
File metadata and controls
251 lines (218 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Raspberry Pi 5 Hardware Support Modules — consolidated build
# SPDX-License-Identifier: BSD-2-Clause
#
# Single self-contained Makefile that builds every kernel module in this
# repository. bsd.kmod.mk builds exactly one KMOD per make invocation, so
# this file runs in two modes:
#
# * Orchestrator mode (MODULE undefined, the default): defines the
# user-facing targets (all, install, clean, load, unload, status, ...)
# and drives the leaf once per module via ${MAKE} MODULE=<m>.
# * Leaf mode (MODULE defined): selects one module's SRCS/CFLAGS/EXPORT_SYMS
# and includes <bsd.kmod.mk>, which does the actual compile/link/install.
#
# To add a module: append it to MODULES and add its SRCS_<m> / CFLAGS_<m>
# (and optional EXPORT_SYMS_<m>) below.
MODULES= bcm2712 rpi5 rp1_eth rp1_pcie2_recon bcm2712_pcie rp1_gpio cyw43455
# --- Per-module build definitions (visible in both modes) -----------------
# SRCS_<m>: sources + interface/opt headers generated by bsd.kmod.mk
# CFLAGS_<m>: extra -I paths (every module also gets -I/usr/src/sys)
# EXPORT_SYMS_<m>: symbols published for other modules to link against
SRCS_bcm2712= bcm2712.c device_if.h bus_if.h pwmbus_if.h opt_fdt.h opt_global.h
CFLAGS_bcm2712= -I/usr/src/sys/dev/pwm
EXPORT_SYMS_bcm2712= bcm2712_read_cpu_temp bcm2712_get_softc \
bcm2712_pwm_set_config bcm2712_pwm_enable \
bcm2712_read_fan_rpm
SRCS_rpi5= rpi5.c device_if.h bus_if.h opt_fdt.h opt_global.h
CFLAGS_rpi5= -I/usr/src/sys/contrib/libfdt -I/usr/src/sys/dev/fdt
SRCS_rp1_eth= rp1_eth_cfg.c rp1_eth.c device_if.h bus_if.h opt_fdt.h opt_global.h
CFLAGS_rp1_eth= -I/usr/src/sys/contrib/libfdt -I/usr/src/sys/dev/fdt \
-I/usr/src/sys/dev/mii
SRCS_rp1_pcie2_recon= rp1_pcie2_recon.c device_if.h bus_if.h opt_fdt.h \
opt_global.h
CFLAGS_rp1_pcie2_recon= -I/usr/src/sys/contrib/libfdt -I/usr/src/sys/dev/fdt
SRCS_bcm2712_pcie= bcm2712_pcie.c device_if.h bus_if.h acpi_if.h \
opt_acpi.h opt_global.h
CFLAGS_bcm2712_pcie= -I/usr/src/sys/contrib/libfdt \
-I/usr/src/sys/contrib/dev/acpica/include
EXPORT_SYMS_bcm2712_pcie= bcm2712_pcie_register_rp1_intr \
bcm2712_pcie_deregister_rp1_intr \
bcm2712_pcie_gem_iack
SRCS_rp1_gpio= rp1_gpio.c device_if.h bus_if.h ofw_bus_if.h opt_fdt.h \
opt_global.h opt_platform.h gpio_if.h fdt_pinctrl_if.h
CFLAGS_rp1_gpio= -I/usr/src/sys/contrib/libfdt -I/usr/src/sys/dev/fdt \
-I/usr/src/sys/dev/gpio
SRCS_cyw43455= cyw43455.c cyw43455_sdio.c cyw43455_fwil.c cyw43455_fw.c \
cyw43455_sdpcm.c cyw43455_cfg.c cyw43455_events.c \
cyw43455_scan.c cyw43455_security.c \
sdio_if.h device_if.h bus_if.h
CFLAGS_cyw43455= -I/usr/src/sys/contrib/libfdt
# cyw43455 firmware delivery: the .ko does NOT embed firmware. Images are
# obtained at attach time through firmware(9) from /boot/firmware/cyw43455/
# (or preloaded from /boot/loader.conf), so the regulatory .clm_blob can be
# swapped per-deployment without rebuilding. They are downloaded from GitHub
# (RPi-Distro/firmware-nonfree) into CYW43455_FW_CACHE by fetch-cyw43455-fw,
# then deployed by install-cyw43455. Override CYW43455_FW_CACHE to point at a
# directory that already holds the brcmfmac43455-sdio.* files to skip fetching.
CYW43455_FW_DIR= /boot/firmware/cyw43455
CYW43455_FW_CACHE?= ${.CURDIR}/fw
CYW43455_FW_FILES= brcmfmac43455-sdio.bin brcmfmac43455-sdio.txt \
brcmfmac43455-sdio.clm_blob
.if defined(MODULE)
# ======================================================================
# Leaf mode — build a single module via bsd.kmod.mk
# ======================================================================
.PATH: ${.CURDIR}
KMOD= ${MODULE}
SRCS= ${SRCS_${MODULE}}
CFLAGS+= -I/usr/src/sys ${CFLAGS_${MODULE}}
.if !empty(EXPORT_SYMS_${MODULE})
EXPORT_SYMS= ${EXPORT_SYMS_${MODULE}}
.endif
.if ${MODULE} == "cyw43455"
# sdio_if.h is the one interface header bsd.kmod.mk does not locate on its
# own; generate it explicitly from the SDIO kobj method file. device_if.h
# and bus_if.h are produced by bsd.kmod.mk like every other module.
sdio_if.h: /usr/src/sys/dev/sdio/sdio_if.m
awk -f /usr/src/sys/tools/makeobjops.awk \
/usr/src/sys/dev/sdio/sdio_if.m -h
CLEANFILES+= sdio_if.h sdio_if.c
.endif
.include <bsd.kmod.mk>
.else
# ======================================================================
# Orchestrator mode — user-facing targets
# ======================================================================
# Leaf builds share one OBJDIR (the repo root) and each regenerates shared
# objects (device_if.o, bus_if.o, ...), so they must not run concurrently.
.NOTPARALLEL:
# Aggregate targets declared first so `all` is the default target (the .for
# loops below would otherwise make build-<first module> the default).
all: ${MODULES:%=build-%}
install: ${MODULES:%=install-%}
clean: ${MODULES:%=clean-%}
# Per-module build/clean targets + a bare-name alias (e.g. `make bcm2712`).
.for m in ${MODULES}
build-${m}:
@echo "==> build ${m}"
@${MAKE} MODULE=${m}
${m}: build-${m}
clean-${m}:
@echo "==> clean ${m}"
@${MAKE} MODULE=${m} clean
.endfor
# Generic install for every module except cyw43455 (special-cased below).
.for m in ${MODULES:Ncyw43455}
install-${m}:
@echo "==> install ${m}"
@${MAKE} MODULE=${m} install
.endfor
# Per-module load/unload (kldstat-guarded; idempotent).
.for m in ${MODULES}
load-${m}:
@if kldstat | grep -q ${m}; then \
echo "${m} already loaded"; \
else \
kldload ${m} && echo "${m} loaded"; \
fi
unload-${m}:
@if kldstat | grep -q ${m}; then \
kldunload ${m} && echo "${m} unloaded"; \
else \
echo "${m} not loaded"; \
fi
.endfor
# cyw43455: install the module, then deploy its firmware images.
# Download the firmware images from GitHub into CYW43455_FW_CACHE (cached;
# already-present files are skipped). Runs as the invoking user — no root.
fetch-cyw43455-fw:
@sh ${.CURDIR}/tools/cyw43455_fw_fetch.sh ${CYW43455_FW_CACHE}
install-cyw43455: fetch-cyw43455-fw
@echo "==> install cyw43455"
@${MAKE} MODULE=cyw43455 install
@echo "Installing CYW43455 firmware to ${CYW43455_FW_DIR}/..."
@install -d -m 755 ${CYW43455_FW_DIR}
@for f in ${CYW43455_FW_FILES}; do \
if [ -f "${CYW43455_FW_CACHE}/$$f" ]; then \
install -o root -g wheel -m 444 "${CYW43455_FW_CACHE}/$$f" \
"${CYW43455_FW_DIR}/$$f" && echo " installed $$f"; \
else \
echo " WARNING: $$f missing from ${CYW43455_FW_CACHE}/"; \
fi; \
done
# Load/unload aggregates. bcm2712_pcie auto-loads as an rp1_eth dependency;
# unload runs leaf-first so dependants release before their providers.
load: load-bcm2712 load-rpi5 load-rp1_eth load-rp1_gpio load-cyw43455
unload: unload-rp1_gpio unload-rp1_pcie2_recon unload-rp1_eth unload-rpi5 \
unload-bcm2712
# Build, install, load, and report.
test: all install load status
# Integration test harness lives in test/ (shell-driven; kept separate).
test-suite:
@${MAKE} -C test
dev-test:
@${MAKE} -C test dev-test
stress-test:
@${MAKE} -C test stress-test
status:
@echo "=== Module Status ==="
@for m in bcm2712 rpi5 rp1_eth; do \
if kldstat | grep -q $$m; then \
echo " [+] $$m is loaded"; \
else \
echo " [-] $$m is NOT loaded"; \
fi; \
done
@echo ""
@echo "=== sysctl Interface ==="
@if sysctl hw.rpi5.fan >/dev/null 2>&1; then \
echo " [+] hw.rpi5 sysctl available"; \
sysctl hw.rpi5.fan.current_state hw.rpi5.fan.cpu_temp; \
else \
echo " [-] hw.rpi5 sysctl NOT available"; \
fi
@if sysctl hw.rp1_eth.cfg.status_decoded >/dev/null 2>&1; then \
echo " [+] hw.rp1_eth sysctl available"; \
sysctl hw.rp1_eth.cfg.status_decoded; \
else \
echo " [-] hw.rp1_eth sysctl NOT available"; \
fi
help:
@echo "Raspberry Pi 5 Hardware Support Modules — build system"
@echo ""
@echo "Modules: ${MODULES}"
@echo ""
@echo "Build targets:"
@echo " all Build every module (default)"
@echo " <module> Build one module (e.g. 'make cyw43455')"
@echo " clean Remove all build artifacts"
@echo " clean-<module> Clean one module"
@echo ""
@echo "Firmware (cyw43455):"
@echo " fetch-cyw43455-fw Download firmware from GitHub into ${CYW43455_FW_CACHE}"
@echo ""
@echo "Install / load (require root):"
@echo " install Install every module (cyw43455 also fetches+installs firmware)"
@echo " install-<module> Install one module"
@echo " load / unload Load/unload the runtime module set"
@echo " load-<m>/unload-<m> Load/unload one module"
@echo " status Show load state + sysctl interface"
@echo ""
@echo "Test:"
@echo " test Build, install, load, status"
@echo " test-suite Run test/ integration suite"
@echo " dev-test Quick test/ validation"
@echo " stress-test test/ load/unload stress run"
@echo ""
@echo "Examples:"
@echo " make # build all"
@echo " make cyw43455 # build one module"
@echo " sudo make install # install all"
@echo " sudo make load # load runtime set"
@echo " make status # check state"
.PHONY: all install clean load unload status test test-suite dev-test \
stress-test help fetch-cyw43455-fw
.for m in ${MODULES}
.PHONY: ${m} build-${m} install-${m} clean-${m} load-${m} unload-${m}
.endfor
.endif