#!/bin/sh # Build and install the patched bwn driver (if_bwn.ko), the patched PCIe # bridge (bhndb_pci.ko) and the Broadcom v4 firmware (bwn_v4_n.ko) on a # clean FreeBSD 15.1 system. # # Usage: sudo ./build.sh [SRC_ROOT] # Default SRC_ROOT=/usr/src # # What it does: # 1. Builds if_bwn.ko (sys/modules/bwn) -> /boot/modules/if_bwn.ko # 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. # over the fallback rtwn0/wlan0 interface) is never disrupted by this script. # # After reboot, bwn0 attaches on the BCM43224 and uses legacy INTx (the # 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 fi echo "==> [1/3] Building if_bwn.ko" make -C "$SRC/sys/modules/bwn" SRCTOP="$SRC" SYSDIR="$SRC/sys" clean make -C "$SRC/sys/modules/bwn" SRCTOP="$SRC" SYSDIR="$SRC/sys" install -m 444 -o root -g wheel "$SRC/sys/modules/bwn/if_bwn.ko" /boot/modules/if_bwn.ko sync echo " -> /boot/modules/if_bwn.ko" echo "==> [2/3] Building bhndb_pci.ko (NO_MSI quirk)" make -C "$SRC/sys/modules/bhnd/bhndb_pci" SRCTOP="$SRC" SYSDIR="$SRC/sys" clean make -C "$SRC/sys/modules/bhnd/bhndb_pci" SRCTOP="$SRC" SYSDIR="$SRC/sys" install -m 444 -o root -g wheel "$SRC/sys/modules/bhnd/bhndb_pci/bhndb_pci.ko" /boot/kernel/bhndb_pci.ko sync echo " -> /boot/kernel/bhndb_pci.ko" echo "==> [3/3] Building + installing bwn_v4_n.ko (firmware)" make -C "$HERE/src/firmware" SRCTOP="$SRC" SYSDIR="$SRC/sys" clean make -C "$HERE/src/firmware" SRCTOP="$SRC" SYSDIR="$SRC/sys" install -m 444 -o root -g wheel "$HERE/src/firmware/bwn_v4_n.ko" /boot/modules/bwn_v4_n.ko sync 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" else 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, installed and indexed. REBOOT to activate." echo " After reboot, create the interface with:" echo " ifconfig wlan create wlandev bwn0 [wap]" exit 0