treewide: use only board_name function to get name
authorMathias Kresin <dev@kresin.me>
Sun, 9 Jul 2017 11:00:36 +0000 (13:00 +0200)
committerMathias Kresin <dev@kresin.me>
Sat, 15 Jul 2017 21:13:34 +0000 (23:13 +0200)
Do not parse /tmp/sysinfo/board_name, /proc/cpuinfo or the device tree
compatible string directly. Always use the board_name function to get
the board name.

The admswconfig package still reads /proc/cpuinfo directly. The code
looks somehow broken and the whole adm5120 which uses this package
looks unmaintained. Leave it as it is for now.

Signed-off-by: Mathias Kresin <dev@kresin.me>
20 files changed:
target/linux/apm821xx/base-files/lib/preinit/79_move_config
target/linux/apm821xx/base-files/lib/upgrade/merakinand.sh
target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
target/linux/bcm53xx/base-files/etc/board.d/01_leds
target/linux/bcm53xx/base-files/etc/board.d/02_network
target/linux/brcm47xx/base-files/etc/board.d/01_detect
target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
target/linux/mediatek/base-files/lib/upgrade/platform.sh
target/linux/octeon/base-files/etc/board.d/01_network
target/linux/octeon/base-files/lib/preinit/79_move_config
target/linux/octeon/base-files/lib/upgrade/platform.sh
target/linux/omap24xx/base-files/etc/hotplug.d/firmware/10-bme-pmm-image
target/linux/omap24xx/base-files/etc/hotplug.d/firmware/20-p54spi-eeprom
target/linux/orion/base-files/etc/hotplug.d/usb/10-usb
target/linux/orion/generic/base-files/etc/uci-defaults/09_hardware
target/linux/orion/generic/base-files/lib/upgrade/platform.sh
target/linux/rb532/base-files/lib/upgrade/platform.sh
target/linux/x86/base-files/etc/board.d/01_leds
target/linux/x86/base-files/etc/board.d/02_network
target/linux/zynq/base-files/etc/board.d/02_network

index f45619f..3ca8b0a 100644 (file)
@@ -3,7 +3,9 @@
 BOOTPART=/dev/sda1
 
 move_config() {
-       grep -q 'MyBook Live' /proc/cpuinfo || return
+       . /lib/functions.sh
+
+       [ "$(board_name)" = "mbl" ] || return
        if [ -b $BOOTPART ]; then
                mkdir -p /boot
                mount -t ext4 -o rw,noatime $BOOTPART /boot
index f025082..fb961b8 100755 (executable)
@@ -52,7 +52,7 @@ merakinand_do_platform_check() {
 
 merakinand_do_upgrade() {
        local tar_file="$1"
-       local board_name="$(cat /tmp/sysinfo/board_name)"
+       local board_name="$(board_name)"
 
        # Do we need to do any platform tweaks?
        case "$board_name" in
index 78cde20..dfc57b2 100644 (file)
@@ -51,7 +51,7 @@ merakinand_copy_caldata() {
        local cal_src=$1
        local cal_dst=$2
        local ubidev="$(nand_find_ubi $CI_UBIPART)"
-       local board_name="$(cat /tmp/sysinfo/board_name)"
+       local board_name="$(board_name)"
        local rootfs_size="$(ubinfo /dev/ubi0 -N rootfs_data | grep "Size" | awk '{ print $6 }')"
 
        # Setup partitions using board name, in case of future platforms
@@ -143,7 +143,7 @@ merakinand_do_platform_check() {
 
 merakinand_do_upgrade() {
        local tar_file="$1"
-       local board_name="$(cat /tmp/sysinfo/board_name)"
+       local board_name="$(board_name)"
 
        # Do we need to do any platform tweaks?
        case "$board_name" in
index ebfe363..80f799d 100755 (executable)
@@ -4,9 +4,7 @@
 
 board_config_update
 
-board=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1)
-
-case "$board" in
+case "$(board_name)" in
 netgear,r8000)
        ucidef_set_led_usbport "usb2" "USB 2.0" "bcm53xx:white:usb2" "usb1-port2" "usb2-port2"
        ucidef_set_led_usbport "usb3" "USB 3.0" "bcm53xx:white:usb3" "usb1-port1" "usb2-port1" "usb4-port1"
index 89bd544..dc17af4 100755 (executable)
@@ -8,7 +8,7 @@
 
 board_config_update
 
-board=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1)
+board=$(board_name)
 
 case "$board" in
 tenda,ac9)
index 357cc7f..f1022dc 100755 (executable)
@@ -175,7 +175,7 @@ detect_by_model() {
 }
 
 
-model="$(sed -ne 's/^machine[ \t]*: //p' /proc/cpuinfo)"
+model="$(board_name)"
 boardtype="$(nvram get boardtype)"
 boardnum="$(nvram get boardnum)"
 
index fc48cb1..166bc05 100644 (file)
@@ -68,7 +68,7 @@ zyxel_do_flash() {
 
 zyxel_do_upgrade() {
        local tar_file="$1"
-       local board=$(cat /tmp/sysinfo/board_name)
+       local board=$(board_name)
        local rootfs="$(zyxel_get_rootfs)"
        local kernel=
 
index 9a844bc..7e936c4 100755 (executable)
@@ -4,7 +4,7 @@
 
 platform_do_upgrade() {
        local tar_file="$1"
-       local board="$(cat /tmp/sysinfo/board_name)"
+       local board="$(board_name)"
 
        echo "flashing kernel"
        tar xf $tar_file sysupgrade-$board/kernel -O | mtd write - kernel
@@ -17,7 +17,7 @@ platform_do_upgrade() {
 
 platform_check_image() {
        local tar_file="$1"
-       local board=$(cat /tmp/sysinfo/board_name)
+       local board=$(board_name)
 
        case "$board" in
        mediatek,mt7623-rfb-nand-ephy |\
@@ -45,8 +45,7 @@ platform_check_image() {
 }
 
 platform_pre_upgrade() {
-       local board=$(cat /tmp/sysinfo/board_name)
-       case "$board" in
+       case "$(board_name)" in
        mediatek,mt7623-rfb-nand-ephy |\
        mediatek,mt7623-rfb-nand)
                nand_do_upgrade $1
index 851b7e8..79e5089 100755 (executable)
@@ -7,7 +7,7 @@
 
 board_config_update
 
-case "$(cat /tmp/sysinfo/board_name)" in
+case "$(board_name)" in
 erlite)
        ucidef_set_interfaces_lan_wan "eth0" "eth1"
        ;;
index 4ab321b..ec63d9f 100644 (file)
@@ -2,7 +2,9 @@
 # Copyright (C) 2014 OpenWrt.org
 
 move_config() {
-       case "$(cat /tmp/sysinfo/board_name)" in
+       . /lib/functions.sh
+
+       case "$(board_name)" in
                erlite)
                        mount -t vfat /dev/sda1 /mnt
                        [ -f /mnt/sysupgrade.tgz ] && mv -f /mnt/sysupgrade.tgz /
index 91763ce..cd49c0d 100755 (executable)
@@ -22,9 +22,7 @@ platform_get_rootfs() {
 }
 
 platform_copy_config() {
-       local board="$(cat /tmp/sysinfo/board_name)"
-
-       case "$board" in
+       case "$(board_name)" in
        erlite)
                mount -t vfat /dev/sda1 /mnt
                cp -af "$CONF_TAR" /mnt/
@@ -58,7 +56,7 @@ platform_do_flash() {
 
 platform_do_upgrade() {
        local tar_file="$1"
-       local board=$(cat /tmp/sysinfo/board_name)
+       local board=$(board_name)
        local rootfs="$(platform_get_rootfs)"
        local kernel=
 
@@ -81,7 +79,7 @@ platform_do_upgrade() {
 }
 
 platform_check_image() {
-       local board=$(cat /tmp/sysinfo/board_name)
+       local board=$(board_name)
 
        case "$board" in
        erlite | \
index d03c9de..26d367d 100644 (file)
@@ -7,8 +7,10 @@ n810_cal_bme_pmm_extract() {
        }
 }
 
+. /lib/functions.sh
+
 [ "$FIRMWARE" = "n810-cal-bme-pmm.fw" ] && {
-       [ -z "$(grep -e 'Nokia N810' /proc/cpuinfo)" ] || {
+       [ "$(board_name)" != "nokia,n810" ] || {
                [ -e /lib/firmware/n810-cal-bme-pmm.fw ] ||\
                        n810_cal_bme_pmm_extract
        }
index ca92f80..c535747 100644 (file)
@@ -22,8 +22,10 @@ p54spi_eeprom_extract() {
        }
 }
 
+. /lib/functions.sh
+
 [ "$FIRMWARE" = "3826.eeprom" ] && {
-       [ -z "$(grep -e 'Nokia N810' /proc/cpuinfo)" ] || {
+       [ "$(board_name)" != "nokia,n810" ] || {
                [ -e /lib/firmware/3826.eeprom ] ||\
                        p54spi_eeprom_extract
        }
index 5572dae..2ae0f73 100644 (file)
@@ -30,9 +30,9 @@ usb_led_off() {
 }
 
 get_usb_led() {
-       local hardware=`sed -n /Hardware/s/.*:.//p /proc/cpuinfo`
+       . /lib/functions.sh
 
-       case "${hardware}" in
+       case "$(board_name)" in
         'Linksys WRT350N v2')
                usb_led='wrt350nv2:green:usb'
                usb_device='1-1:1.0'
index 5b30f27..751749d 100644 (file)
@@ -10,7 +10,7 @@
 # This script sets system defaults for the hardware on firstboot
 #
 
-hardware=`sed -n /Hardware/s/.*:.//p /proc/cpuinfo`
+. /lib/functions.sh
 
 wrt350nv2_default() {
 # leds
@@ -47,7 +47,7 @@ __EOF
        }
 }
 
-case "${hardware}" in
+case "$(board_name)" in
  'Linksys WRT350N v2')
        wrt350nv2_default
        ;;
index 9c9967e..db23306 100644 (file)
@@ -8,7 +8,7 @@
 platform_check_image() {
        [ "${ARGC}" -gt 1 ] && { echo 'Too many arguments. Only flash file expected.'; return 1; }
 
-       local hardware=`sed -n /Hardware/s/.*:.//p /proc/cpuinfo`
+       local hardware="$(board_name)"
        local magic="$(get_magic_word "$1")"
        local magic_long="$(get_magic_long "$1")"
 
index bfa73a7..2beccc5 100644 (file)
@@ -15,10 +15,8 @@ platform_pre_upgrade() {
 }
 
 platform_nand_pre_upgrade() {
-       local board_name="$(cat /tmp/sysinfo/board_name)"
-
        mtd erase kernel
-       tar xf "$1" sysupgrade-$board_name/kernel -O | nandwrite -o /dev/mtd0 -
+       tar xf "$1" "sysupgrade-$(board_name)/kernel" -O | nandwrite -o /dev/mtd0 -
 }
 
 platform_do_upgrade() {
index 6a5ff03..04e1170 100755 (executable)
@@ -7,9 +7,7 @@
 
 board_config_update
 
-board=$(cat /tmp/sysinfo/board_name) 2>/dev/null
-
-case "$board" in
+case "$(board_name)" in
 pc-engines-apu|pc-engines-apu2)
        ucidef_set_led_netdev "wan" "WAN" "apu2:green:led3" "eth0"
        ucidef_set_led_netdev "lan" "LAN" "apu2:green:led2" "br-lan"
index 5bfe609..bea696d 100755 (executable)
@@ -8,9 +8,7 @@
 
 board_config_update
 
-board="$(cat /tmp/sysinfo/board_name)" 2>/dev/null
-
-case "$board" in
+case "$(board_name)" in
 pc-engines-apu|pc-engines-apu2)
        ucidef_set_interfaces_lan_wan "eth1 eth2" "eth0"
        ;;
index 9659673..ff90763 100755 (executable)
@@ -5,7 +5,7 @@
 
 board_config_update
 
-case "$(cat /tmp/sysinfo/board_name)" in
+case "$(board_name)" in
        xlnx,zynq-zc702|xlnx,zynq-zed|xlnx,zynq-zybo)
                ucidef_set_interface_lan 'eth0'
                ;;