board/common: probe for wifi radios

Relocate probe of wifi radios from gen-hardware to 00-probe.  This saves
one python invocation and some precious CPU cycles at boot.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-03-20 16:18:05 +01:00
parent 07f23ec4f5
commit f257ab58d4
2 changed files with 55 additions and 5 deletions
@@ -521,6 +521,52 @@ def probe_dtsystem(out):
return 0
def probe_wifi_radios(out):
"""Probe wifi radios via sysfs/iw and store in output dict."""
# feature-wifi is the only Buildroot package that enables CONFIG_MAC80211/
# CONFIG_CFG80211, so this directory exists iff WiFi support is built in.
# feature-wifi also selects BR2_PACKAGE_IW, so iw(8) is always available
# when this directory exists -- no separate iw check needed.
ieee80211 = "/sys/class/ieee80211"
if not os.path.exists(ieee80211):
return
radios = sorted(os.listdir(ieee80211))
if not radios:
return
out["wifi-radios"] = []
for phy in radios:
info = {"name": phy, "bands": []}
try:
result = subprocess.run(
["iw", "phy", phy, "info"],
capture_output=True, text=True, timeout=5
)
if result.returncode != 0:
continue
except Exception:
continue
freqs = []
for line in result.stdout.splitlines():
stripped = line.strip()
if stripped.startswith("* ") and "MHz" in stripped:
try:
freqs.append(int(float(stripped.split()[1])))
except (ValueError, IndexError):
pass
if any(2400 <= f <= 2500 for f in freqs):
info["bands"].append({"name": "2.4GHz"})
if any(5150 <= f <= 5900 for f in freqs):
info["bands"].append({"name": "5GHz"})
if any(5955 <= f <= 7115 for f in freqs):
info["bands"].append({"name": "6GHz"})
out["wifi-radios"].append(info)
def main():
out = {
"vendor": None,
@@ -546,6 +592,8 @@ def main():
if err:
return err
probe_wifi_radios(out)
if not out["factory-password-hash"]:
sys.stdout.write("\n\n\033[31mCRITICAL BOOTSTRAP ERROR\n" +
"NO FACTORY PASSWORD FOUND\033[0m\n\n")
+7 -5
View File
@@ -6,7 +6,11 @@ if jq -e '.["usb-ports"]' /run/system.json > /dev/null; then
else
usb_ports=""
fi
wifi_radios=$(/usr/libexec/infix/iw.py list 2>/dev/null | jq -r '.[]' || echo "")
if jq -e '.["wifi-radios"]' /run/system.json > /dev/null 2>&1; then
wifi_radios=$(jq -r '.["wifi-radios"][].name' /run/system.json)
else
wifi_radios=""
fi
gen_port()
@@ -27,11 +31,9 @@ gen_radio()
{
radio="$1"
# Detect supported bands from iw.py info JSON output
phy_info=$(/usr/libexec/infix/iw.py info "$radio" 2>/dev/null || echo '{"bands":[]}')
# Check if 2.4GHz band exists (band name "2.4GHz")
# Read band info from system.json (probed at boot by 00-probe)
phy_info=$(jq -r --arg r "$radio" '.["wifi-radios"][] | select(.name == $r)' /run/system.json 2>/dev/null || echo '{"bands":[]}')
has_2ghz=$(echo "$phy_info" | jq '[.bands[] | select(.name == "2.4GHz")] | length')
# Check if 5GHz band exists (band name "5GHz")
has_5ghz=$(echo "$phy_info" | jq '[.bands[] | select(.name == "5GHz")] | length')
# Determine band setting