Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions install/hardware/fix-bcm43xx.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Install Wi-Fi drivers for Broadcom chips found in some MacBooks, as well as other systems:
# - BCM4360 (2013–2015 MacBooks)
# - BCM4331 (2012, early 2013 MacBooks)
# - BCM43228 (HP ProBook 6570b)

pci_info=$(lspci -nn)

if (echo "$pci_info" | grep -q "14e4:43a0" || echo "$pci_info" | grep -q "14e4:4331"); then
echo "BCM4360 / BCM4331 detected"
if (echo "$pci_info" | grep -q "14e4:43a0" || echo "$pci_info" | grep -q "14e4:4331" || echo "$pci_info" | grep -q "14e4:4359"); then
echo "BCM4360 / BCM4331 / BCM43228 detected"
omarchy-pkg-add broadcom-wl-dkms
fi
14 changes: 14 additions & 0 deletions migrations/1792750214.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
echo "Install the Broadcom wl driver for BCM43228 Wi-Fi"

# Hardware setup only runs at install. A machine already running b43 on the
# b43-firmware package works, and broadcom-wl-dkms would blacklist b43.
bcm43228=""
if omarchy-hw-x86 && ! bcm43228=$(lspci -n -d 14e4:4359); then
echo "Unable to look for a BCM43228 adapter; rerun omarchy-migrate." >&2
exit 1
fi

if [[ -n $bcm43228 ]] && omarchy-pkg-missing broadcom-wl-dkms && omarchy-pkg-missing b43-firmware; then
omarchy-pkg-add broadcom-wl-dkms
omarchy-state set reboot-required
fi
84 changes: 84 additions & 0 deletions test/shell.d/bcm43228-wifi-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

setup="$ROOT/install/hardware/fix-bcm43xx.sh"
migration="$ROOT/migrations/1792750214.sh"
scratch=$(mktemp -d)
trap 'rm -rf "$scratch"' EXIT

bash -n "$setup" || fail "Broadcom hardware script has valid syntax"
bash -n "$migration" || fail "BCM43228 migration has valid syntax"

actions() {
[[ -f $scratch/actions ]] && cat "$scratch/actions" || true
}

run_setup() {
local pci=$1
rm -f "$scratch/actions"
lspci() { printf '%s\n' "$pci"; }
omarchy-pkg-add() { printf '%s\n' "$*" >>"$scratch/actions"; }
source "$setup"
}

for chip in "BCM43228 [14e4:4359]" "BCM4360 [14e4:43a0]" "BCM4331 [14e4:4331]"; do
run_setup "00:00.0 Network controller [0280]: Broadcom Inc. $chip" >/dev/null
[[ $(actions) == "broadcom-wl-dkms" ]] ||
fail "$chip installs broadcom-wl-dkms" "$(actions)"
done

run_setup "00:1f.6 Ethernet controller [0200]: Intel I219-LM [8086:15b7]" >/dev/null
[[ -z $(actions) ]] ||
fail "other network hardware installs no Broadcom driver" "$(actions)"

# A subshell, so the sourced migration's variables and exits stay out of the test.
run_migration() (
local arch=$1
local pci=$2
local installed=$3
rm -f "$scratch/actions"
omarchy-hw-x86() { [[ $arch == x86 ]]; }
lspci() {
[[ $pci != "fail" ]] || return 1
if [[ $pci == *"${@: -1}"* ]]; then
printf '%s\n' "$pci"
fi
}
omarchy-pkg-missing() { [[ " $installed " != *" $1 "* ]]; }
omarchy-pkg-add() { printf 'add %s\n' "$*" >>"$scratch/actions"; }
omarchy-state() { printf 'state %s\n' "$*" >>"$scratch/actions"; }
source "$migration"
)

bcm43228="00:00.0 Network controller [0280]: Broadcom Inc. BCM43228 [14e4:4359]"

run_migration x86 "00:1f.6 Ethernet controller [0200]: Intel I219-LM [8086:15b7]" "" >/dev/null
[[ -z $(actions) ]] ||
fail "the migration does nothing without a BCM43228" "$(actions)"

run_migration x86 "$bcm43228" "broadcom-wl-dkms" >/dev/null
[[ -z $(actions) ]] ||
fail "the migration leaves an installed broadcom-wl-dkms alone" "$(actions)"

run_migration x86 "$bcm43228" "b43-firmware" >/dev/null
[[ -z $(actions) ]] ||
fail "the migration leaves a machine running b43 on b43-firmware alone" "$(actions)"

run_migration aarch64 "$bcm43228" "" >/dev/null
[[ -z $(actions) ]] ||
fail "the migration asks for no x86-only driver on ARM" "$(actions)"

if run_migration x86 fail "" >/dev/null 2>&1; then
fail "the migration stays pending when lspci fails"
fi
[[ -z $(actions) ]] ||
fail "the migration changes nothing when lspci fails" "$(actions)"

run_migration x86 "$bcm43228" "" >/dev/null
[[ $(actions) == $'add broadcom-wl-dkms\nstate set reboot-required' ]] ||
fail "the migration installs broadcom-wl-dkms and asks for a reboot" "$(actions)"

pass "BCM43228 gets the wl driver on install and on existing machines"