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 f45619fdbd7e86d36d9e1132e15b301edf99cf7c..3ca8b0a71cdbd2f8cc104eaae8a1791eeb58aec0 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 f025082e767a88c4b559ec4969385b96e0b2c250..fb961b894540cda83263d44f07d5c686bc168fab 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 78cde20a130707382968a8d6e65db4e020054857..dfc57b23f54c89d2371e5a634fde892aec385f75 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 ebfe363fc1401fa1384d1934164755416d3a8e57..80f799d9d7eeaeba8aab56bb0e5e906bc557ee5b 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 89bd544950a98581861b36159e28dcc229a1bdd2..dc17af489100cd818304395e6280ce2ea87085cb 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 357cc7f22432d2803c464de1176197ea2c2182cf..f1022dc13a744a258cfbb1e7634071f323c87715 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 fc48cb1d025c2f092b72236e3a8c489184cfd844..166bc052c516033faa8746c72874420ce0a3b747 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 9a844bc7e1998e53c42ec4b8e6d62e1308061f1d..7e936c4dad8c508d01cbfcb129645f11efbb054f 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 851b7e8f184b5eef4032da9223ed21f65f34ebcc..79e508955ed553de5794f585395f80826f9ccac3 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 4ab321b690d667a36897147e78f0aca81e07d6ea..ec63d9f5ff1d51774c18d32c5a534b15ee66d645 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 91763ce1c66a6900e753a64da495a28a4ef02989..cd49c0da36ea62443d1367a403655ae1b08929dc 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 d03c9dee037e39d7283a3b56de195d55130583a2..26d367d3c76353fa20b7d7844bc048a05ddd648e 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 ca92f80bea84a5be08221057508a650d285aa324..c535747235ceb6038916a2cf15af3a43ff8d0555 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 5572daede19e611450ca09ab026fbf468ae3f531..2ae0f73bdcfb70f3cba0955493e4626c571780db 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 5b30f27e5e3843a90fe846eba331ba3d9975a84f..751749d13dd4ca5cd2d883f64cc04f80d5e8f2f5 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 9c9967e4afbb1397e34540d774531061ad178340..db2330684d267ce7d23cce1c837b97802627de73 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 bfa73a7a246da01f99cedd6eee92cebd354f2e7f..2beccc5985e78e599b4fc4c8eae723b8f0267189 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 6a5ff03b378a48eb32651db106578062de64f414..04e11705ac52ab26a8347a7d9d481e17b6449136 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 5bfe6097400e0989301bf2df4d3d738461d8f8ce..bea696d8fff541094d0b3a36cbed4f682222de3b 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 9659673618d846776907eaac8772c1e0d17be5f3..ff907637a6414163ce0d4c905af1f0d2aefb4116 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'
                ;;