From d7d10f2c1e8511fe07c9760e85f2272a85168f8d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 30 Jul 2018 08:36:26 +0200 Subject: brcm47xx: rework model detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jo-Philipp Wich --- .../brcm47xx/base-files/etc/board.d/01_detect | 192 -------------------- .../brcm47xx/base-files/etc/board.d/01_network | 195 +++++++++++++++++++++ .../brcm47xx/base-files/lib/preinit/01_sysinfo | 12 +- 3 files changed, 203 insertions(+), 196 deletions(-) delete mode 100755 target/linux/brcm47xx/base-files/etc/board.d/01_detect create mode 100755 target/linux/brcm47xx/base-files/etc/board.d/01_network (limited to 'target/linux') diff --git a/target/linux/brcm47xx/base-files/etc/board.d/01_detect b/target/linux/brcm47xx/base-files/etc/board.d/01_detect deleted file mode 100755 index 237314544b..0000000000 --- a/target/linux/brcm47xx/base-files/etc/board.d/01_detect +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006-2015 OpenWrt.org - -. /lib/functions/system.sh -. /lib/functions/uci-defaults.sh - -detect_by_vlanports() { - local vlan0ports="$(nvram get vlan0ports)" - local vlan1ports="$(nvram get vlan1ports)" - local vlan2ports="$(nvram get vlan2ports)" - local cpuport="$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")" - - if [ "${vlan0ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \ - [ "${vlan1ports:0:9}" = "0 1 2 3 8" -a "${vlan2ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \ - [ "${vlan2ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ]; - then - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0" - - elif [ "${vlan0ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \ - [ "${vlan1ports:0:9}" = "1 2 3 4 8" -a "${vlan2ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \ - [ "${vlan2ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ]; - then - ucidef_add_switch "switch0" \ - "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "8@eth0" - - elif [ "${vlan0ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \ - [ "${vlan1ports:0:9}" = "0 1 2 3 5" -a "${vlan2ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \ - [ "${vlan2ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ]; - then - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" - - elif [ "${vlan0ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \ - [ "${vlan1ports:0:9}" = "1 2 3 4 5" -a "${vlan2ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \ - [ "${vlan2ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ]; - then - ucidef_add_switch "switch0" \ - "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0" - - else - logger -t "01_detect" "Unable to determine network configuration" - ucidef_set_interface_lan "eth0" - fi -} - -detect_by_boardnum() { - local boardnum="$1" - - case "$boardnum" in - # WAP54G, Sitecom WL-105b - "2" | \ - "1024") - ucidef_set_interface_lan "eth0" - ;; - - # Generic detection fallback - *) - detect_by_vlanports - ;; - esac -} - -detect_by_boardtype() { - local boardtype="$1" - local boardnum="$2" - - case "$boardtype" in - "bcm94710r4") - ucidef_set_interfaces_lan_wan "eth0" "eth1" - ;; - - "0x0467") - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" - ;; - - "0x042f" | \ - "0x0472") - # WL-500gP - if [ "$boardnum" = "45" ]; then - ucidef_add_switch "switch0" \ - "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" - - # Generic BCM94704 - else - ucidef_set_interface_wan "eth1" - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" - - # MAC addresses on 4704 tend to be screwed up. Add a workaround here - local mac="$(nvram get et0macaddr)" - local pat="[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" - pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" - pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" - - case "$mac" in - $pat) - ucidef_set_interface_macaddr "lan" "$mac" - ucidef_set_interface_macaddr "wan" "$(macaddr_add "$mac" 1)" - ;; - esac - fi - ;; - - # Buffalo WBR-B11 and Buffalo WBR-G54 - "bcm94710ap") - ucidef_set_interface_wan "eth1" - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" - ;; - - *) - detect_by_boardnum "$boardnum" - ;; - esac -} - -detect_by_model() { - local model="$1" - local boardtype="$2" - local boardnum="$3" - - # Netgear WGT634U exception - if grep -sqE 'mtd0: 000(6|a)0000' /proc/mtd; then - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" - return - fi - - case "$model" in - "Asus WLHDD" | \ - "Asus WL300G") - ucidef_set_interface_lan "eth1" - ;; - - "Asus WL330GE") - ucidef_add_switch "switch0" "4:lan" "5t@eth0" - ;; - - "Asus WL500G" | \ - "Microsoft MN-700") - ucidef_set_interfaces_lan_wan "eth0" "eth1" - ;; - - "Asus RT-N12"* | \ - "Asus WL500GP V2" | \ - "Buffalo WHR-G125" | \ - "D-Link DIR-330" | \ - "Motorola WR850G" | \ - "Siemens SE505 V2") - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" - ;; - - "Asus WL700") - ucidef_add_switch "switch0" \ - "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" - ;; - - "Asus WL500W" | \ - "Dell TrueMobile 2300") - ucidef_set_interface_wan "eth1" - ucidef_add_switch "switch0" \ - "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0" - ;; - - "Asus RT-N16"* | \ - "Linksys E3000 V1") - ucidef_add_switch "switch0" \ - "0:wan" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "8@eth0" - ;; - - *) - detect_by_boardtype "$boardtype" "$boardnum" - ;; - esac -} - - -model="$(board_name)" -boardtype="$(nvram get boardtype)" -boardnum="$(nvram get boardnum)" - -board_config_update - -ucidef_set_board_id "$boardtype${boardnum:+:$boardnum}" -ucidef_set_model_name "$model" - -detect_by_model "$model" "$boardtype" "$boardnum" - -board_config_flush diff --git a/target/linux/brcm47xx/base-files/etc/board.d/01_network b/target/linux/brcm47xx/base-files/etc/board.d/01_network new file mode 100755 index 0000000000..762dd21397 --- /dev/null +++ b/target/linux/brcm47xx/base-files/etc/board.d/01_network @@ -0,0 +1,195 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006-2015 OpenWrt.org + +. /lib/functions/system.sh +. /lib/functions/uci-defaults.sh + +configure_by_vlanports() { + local vlan0ports="$(nvram get vlan0ports)" + local vlan1ports="$(nvram get vlan1ports)" + local vlan2ports="$(nvram get vlan2ports)" + local cpuport="$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")" + + if [ "${vlan0ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \ + [ "${vlan1ports:0:9}" = "0 1 2 3 8" -a "${vlan2ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \ + [ "${vlan2ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ]; + then + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0" + + elif [ "${vlan0ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \ + [ "${vlan1ports:0:9}" = "1 2 3 4 8" -a "${vlan2ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \ + [ "${vlan2ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ]; + then + ucidef_add_switch "switch0" \ + "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "8@eth0" + + elif [ "${vlan0ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \ + [ "${vlan1ports:0:9}" = "0 1 2 3 5" -a "${vlan2ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \ + [ "${vlan2ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ]; + then + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" + + elif [ "${vlan0ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \ + [ "${vlan1ports:0:9}" = "1 2 3 4 5" -a "${vlan2ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \ + [ "${vlan2ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ]; + then + ucidef_add_switch "switch0" \ + "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0" + + else + logger -t "01_detect" "Unable to determine network configuration" + ucidef_set_interface_lan "eth0" + fi +} + +configure_by_boardnum() { + local boardnum="$1" + + case "$boardnum" in + # WAP54G, Sitecom WL-105b + "2" | \ + "1024") + ucidef_set_interface_lan "eth0" + ;; + + # Generic detection fallback + *) + configure_by_vlanports + ;; + esac +} + +configure_by_boardtype() { + local boardtype="$1" + local boardnum="$2" + + case "$boardtype" in + "bcm94710r4") + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ;; + + "0x0467") + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" + ;; + + "0x042f" | \ + "0x0472") + # WL-500gP + if [ "$boardnum" = "45" ]; then + ucidef_add_switch "switch0" \ + "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" + + # Generic BCM94704 + else + ucidef_set_interface_wan "eth1" + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" + + # MAC addresses on 4704 tend to be screwed up. Add a workaround here + local mac="$(nvram get et0macaddr)" + local pat="[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" + pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" + pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]" + + case "$mac" in + $pat) + ucidef_set_interface_macaddr "lan" "$mac" + ucidef_set_interface_macaddr "wan" "$(macaddr_add "$mac" 1)" + ;; + esac + fi + ;; + + # Buffalo WBR-B11 and Buffalo WBR-G54 + "bcm94710ap") + ucidef_set_interface_wan "eth1" + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" + ;; + + *) + configure_by_boardnum "$boardnum" + ;; + esac +} + +configure_by_model() { + local model="$1" + local boardtype="$2" + local boardnum="$3" + + # Netgear WGT634U exception + if grep -sqE 'mtd0: 000(6|a)0000' /proc/mtd; then + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" + return + fi + + case "$model" in + "Asus WLHDD" | \ + "Asus WL300G") + ucidef_set_interface_lan "eth1" + ;; + + "Asus WL330GE") + ucidef_add_switch "switch0" "4:lan" "5t@eth0" + ;; + + "Asus WL500G" | \ + "Microsoft MN-700") + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ;; + + "Asus RT-N12"* | \ + "Asus WL500GP V2" | \ + "Buffalo WHR-G125" | \ + "D-Link DIR-330" | \ + "Motorola WR850G" | \ + "Siemens SE505 V2") + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0" + ;; + + "Asus WL700") + ucidef_add_switch "switch0" \ + "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0" + ;; + + "Asus WL500W" | \ + "Dell TrueMobile 2300") + ucidef_set_interface_wan "eth1" + ucidef_add_switch "switch0" \ + "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0" + ;; + + "Asus RT-N16"* | \ + "Linksys E3000 V1") + ucidef_add_switch "switch0" \ + "0:wan" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "8@eth0" + ;; + + *) + configure_by_boardtype "$boardtype" "$boardnum" + ;; + esac +} + + +model="$(cat /tmp/sysinfo/model)" +boardtype="$(board_name)" + +case "$boardtype" in + *:*) + boardnum="${boardtype##*:}" + boardtype="${boardtype%:*}" + ;; +esac + +board_config_update + +configure_by_model "$model" "$boardtype" "$boardnum" + +board_config_flush diff --git a/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo b/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo index 8a2de67bc5..a3b0c38437 100644 --- a/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo +++ b/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo @@ -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 -- cgit v1.2.3