]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
brcm47xx: rework model detection
authorJo-Philipp Wich <jo@mein.io>
Mon, 30 Jul 2018 06:36:26 +0000 (08:36 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 30 Jul 2018 09:10:47 +0000 (11:10 +0200)
On brcm47xx boards, the model ID is the combination of the "boardtype" nvram
variable and an optional supplemental "boardnum" variable while the human
readable model name is usually exposed in the "machine" field of the
/proc/cpuinfo file.

Move the extraction of the board nvram variables and model name string into
the 01_sysinfo file and rework the 01_detect board configuration script to
solely use the prepared sysinfo values without performing own detection
logic.

As a consequence, we can drop the ucidef_set_board_id() and
ucidef_set_model_name() invocations in favor to the generic behaviour
which copies the /tmp/sysinfo/{board_name,model} values into the board.json
"id" and "name" fields respectively.

Since "01_detect" only contains network configuration logic after this
change, move it to "01_network" and rename the contained "detect_by_xxx"
functions to "configure_by_xxx" instead, to avoid potential confusion.

Fixes FS#1576
Acked-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
target/linux/brcm47xx/base-files/etc/board.d/01_network [moved from target/linux/brcm47xx/base-files/etc/board.d/01_detect with 91% similarity]
target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo

similarity index 91%
rename from target/linux/brcm47xx/base-files/etc/board.d/01_detect
rename to target/linux/brcm47xx/base-files/etc/board.d/01_network
index 237314544b383e2131c340a1082c97e64d66a37b..762dd213978cf3b13c24550f0263fc95efd6ba3d 100755 (executable)
@@ -4,7 +4,7 @@
 . /lib/functions/system.sh
 . /lib/functions/uci-defaults.sh
 
-detect_by_vlanports() {
+configure_by_vlanports() {
        local vlan0ports="$(nvram get vlan0ports)"
        local vlan1ports="$(nvram get vlan1ports)"
        local vlan2ports="$(nvram get vlan2ports)"
@@ -44,7 +44,7 @@ detect_by_vlanports() {
        fi
 }
 
-detect_by_boardnum() {
+configure_by_boardnum() {
        local boardnum="$1"
 
        case "$boardnum" in
@@ -56,12 +56,12 @@ detect_by_boardnum() {
 
        # Generic detection fallback
        *)
-               detect_by_vlanports
+               configure_by_vlanports
                ;;
        esac
 }
 
-detect_by_boardtype() {
+configure_by_boardtype() {
        local boardtype="$1"
        local boardnum="$2"
 
@@ -111,12 +111,12 @@ detect_by_boardtype() {
                ;;
 
        *)
-               detect_by_boardnum "$boardnum"
+               configure_by_boardnum "$boardnum"
                ;;
        esac
 }
 
-detect_by_model() {
+configure_by_model() {
        local model="$1"
        local boardtype="$2"
        local boardnum="$3"
@@ -172,21 +172,24 @@ detect_by_model() {
                ;;
 
        *)
-               detect_by_boardtype "$boardtype" "$boardnum"
+               configure_by_boardtype "$boardtype" "$boardnum"
                ;;
        esac
 }
 
 
-model="$(board_name)"
-boardtype="$(nvram get boardtype)"
-boardnum="$(nvram get boardnum)"
+model="$(cat /tmp/sysinfo/model)"
+boardtype="$(board_name)"
 
-board_config_update
+case "$boardtype" in
+       *:*)
+               boardnum="${boardtype##*:}"
+               boardtype="${boardtype%:*}"
+       ;;
+esac
 
-ucidef_set_board_id "$boardtype${boardnum:+:$boardnum}"
-ucidef_set_model_name "$model"
+board_config_update
 
-detect_by_model "$model" "$boardtype" "$boardnum"
+configure_by_model "$model" "$boardtype" "$boardnum"
 
 board_config_flush
index 8a2de67bc55603035e44f26bb397c43f79814acf..a3b0c38437b11b88bed692667b7c6cc10b5f9c3f 100644 (file)
@@ -1,12 +1,16 @@
 #!/bin/sh
 
 do_sysinfo_brcm47xx() {
-       local name="$(sed -ne 's/^machine[ \t]*: //p' /proc/cpuinfo)"
-       [ -z "$name" ] && name="unknown"
+       local boardtype="$(nvram get boardtype)"
+       local boardnum="$(nvram get boardnum)"
+       local model="$(sed -ne 's/^machine[ \t]*: //p' /proc/cpuinfo)"
+
+       [ -z "$model" ] && model="unknown"
+       [ -z "$boardtype" ] && boardtype="unknown"
 
        [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
-       echo "$name" > /tmp/sysinfo/board_name
-       echo "unknown" > /tmp/sysinfo/model
+       echo "$boardtype${boardnum:+:$boardnum}" > /tmp/sysinfo/board_name
+       echo "$model" > /tmp/sysinfo/model
 }
 
 boot_hook_add preinit_main do_sysinfo_brcm47xx