diff --git a/README.md b/README.md index 505c18b..770c674 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,10 @@ interface) is never disrupted. (`patches/patch-*.c` and `patches/patch-Makefile`). Safe to re-run. - `build.sh` — builds `if_bwn.ko` (`sys/modules/bwn`), `bhndb_pci.ko` (`sys/modules/bhnd/bhndb_pci`), and `bwn_v4_n.ko` (from `src/firmware/`); - installs them to `/boot/modules` and `/boot/kernel`; and appends - `bwn_v4_n_load="YES"` to `/boot/loader.conf` if missing (Fix 5). + installs them to `/boot/modules` and `/boot/kernel`; appends + `bwn_v4_n_load="YES"` to `/boot/loader.conf` if missing (Fix 5); and + regenerates `/boot/kernel/linker.hints` and `/boot/modules/linker.hints` + with `kldxref` so the loader finds the new modules (no manual step). ### Manual build (equivalent to build.sh) @@ -58,6 +60,12 @@ install -m 444 src/firmware/bwn_v4_n.ko /boot/modules/ # 4. loader.conf (Fix 5) echo 'bwn_v4_n_load="YES"' >> /boot/loader.conf + +# 5. Regenerate linker.hints so the loader indexes the new modules +# (else /boot/kernel/linker.hints stays empty -> 'linker.hints file +# truncated' warnings and modules fail to auto-load at boot). +kldxref /boot/kernel +kldxref /boot/modules ``` ## Directory layout diff --git a/build.sh b/build.sh index 5f23899..6dff828 100755 --- a/build.sh +++ b/build.sh @@ -11,6 +11,9 @@ # 2. Builds bhndb_pci.ko(sys/modules/bhnd/bhndb_pci) -> /boot/kernel/bhndb_pci.ko # 3. Builds bwn_v4_n.ko (src/firmware) -> /boot/modules/bwn_v4_n.ko # 4. Adds "bwn_v4_n_load=YES" to /boot/loader.conf (Fix 5) if missing. +# 5. Regenerates /boot/kernel/linker.hints (for bhndb_pci.ko) and +# /boot/modules/linker.hints (for if_bwn.ko + bwn_v4_n.ko) with kldxref +# so the loader finds the new modules without manual intervention. # # All changes take effect on the NEXT reboot (modules are only loaded at # boot). The running kernel is NOT touched, so an active SSH session (e.g. @@ -20,12 +23,19 @@ # NO_MSI quirk), so TX interrupts are delivered and the "device timeout" / # detach-panic / heap-corruption issues are resolved. set -e + +# Re-exec as root if we are not already (build + install + kldxref need it). +if [ "$(id -u)" -ne 0 ]; then + echo "build.sh needs root (install + kldxref); re-execing via sudo..." + exec sudo "$0" "$@" +fi + SRC="${1:-/usr/src}" HERE="$(cd "$(dirname "$0")" && pwd)" if [ ! -d "$SRC/sys" ]; then - echo "ERROR: $SRC/sys not found. Point SRC_ROOT at a FreeBSD 15.1 src tree." >&2 - exit 1 + echo "ERROR: $SRC/sys not found. Point SRC_ROOT at a FreeBSD 15.1 src tree." >&2 + exit 1 fi echo "==> [1/3] Building if_bwn.ko" @@ -51,14 +61,26 @@ echo " -> /boot/modules/bwn_v4_n.ko" echo "==> Adding firmware load to /boot/loader.conf (Fix 5)" if ! grep -q 'bwn_v4_n_load="YES"' /boot/loader.conf 2>/dev/null; then - cp /boot/loader.conf "$HERE/rc.conf.backups/loader.conf.before_build_$(date +%Y%m%d%H%M%S)" - printf '\n# bwn driver: load Broadcom v4 firmware at loader time (Fix 5)\nbwn_v4_n_load="YES"\n' >> /boot/loader.conf - echo " added bwn_v4_n_load=YES" + cp /boot/loader.conf "$HERE/rc.conf.backups/loader.conf.before_build_$(date +%Y%m%d%H%M%S)" + printf '\n# bwn driver: load Broadcom v4 firmware at loader time (Fix 5)\nbwn_v4_n_load="YES"\n' >> /boot/loader.conf + echo " added bwn_v4_n_load=YES" else - echo " already present, skipped" + echo " already present, skipped" fi +echo "==> Regenerating linker.hints (no manual kldxref needed)" +# The kernel hints file indexes /boot/kernel (where bhndb_pci.ko lives); the +# modules hints file indexes /boot/modules (if_bwn.ko + bwn_v4_n.ko). If either +# is stale/empty the loader prints "linker.hints file truncated" and may fail +# to auto-load modules, so rebuild both from the modules currently present. +kldxref /boot/kernel +kldxref /boot/modules +echo " /boot/kernel/linker.hints: $(wc -c < /boot/kernel/linker.hints) bytes" +echo " /boot/modules/linker.hints: $(wc -c < /boot/modules/linker.hints) bytes" + echo -echo "==> All modules built and installed. REBOOT to activate." +echo "==> All modules built, installed and indexed. REBOOT to activate." echo " After reboot, create the interface with:" echo " ifconfig wlan create wlandev bwn0 [wap]" + +exit 0