base-files: add helper functions for adding wlan device entries to board.json
authorFelix Fietkau <nbd@nbd.name>
Fri, 30 Sep 2022 17:19:51 +0000 (19:19 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 14 Oct 2022 11:12:30 +0000 (13:12 +0200)
These will be used to give WLAN PHYs a specific name based on path specified
in board.json. The platform board.d script can assign a specific order based
on available slots (PCIe slots, WMAC device) and device tree configuration.

This helps with maintaining config compatibility in case the device path
changes due to kernel upgrades.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/base-files/files/lib/functions/system.sh
package/base-files/files/lib/functions/uci-defaults.sh

index 22eb00c5155e9f287671b1ff82151fdf8c8394c8..29de2e5dd691e0a1c3c70f09ff36fa50f87a928a 100644 (file)
@@ -283,3 +283,7 @@ macaddr_canonicalize() {
 
        printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
 }
+
+dt_is_enabled() {
+       grep -q okay "/proc/device-tree/$1/status"
+}
index 86f16b51254c9d654987884d0e238527a5bd3850..a37e8cf82416d3afe7637c61150d7aee8f2399f5 100644 (file)
@@ -646,6 +646,21 @@ ucidef_set_ntpserver() {
        json_select ..
 }
 
+ucidef_add_wlan() {
+       local path="$1"; shift
+
+       ucidef_wlan_idx=${ucidef_wlan_idx:-0}
+
+       json_select_object wlan
+       json_select_object "wl$ucidef_wlan_idx"
+       json_add_string path "$path"
+       json_add_fields "$@"
+       json_select ..
+       json_select ..
+
+       ucidef_wlan_idx="$((ucidef_wlan_idx + 1))"
+}
+
 board_config_update() {
        json_init
        [ -f ${CFG} ] && json_load "$(cat ${CFG})"