treewide: do board detection during preinit
authorMathias Kresin <dev@kresin.me>
Fri, 7 Apr 2017 16:01:17 +0000 (18:01 +0200)
committerMathias Kresin <dev@kresin.me>
Sat, 15 Jul 2017 21:13:34 +0000 (23:13 +0200)
Do the board detection during preinit to unify it across all targets.

Signed-off-by: Mathias Kresin <dev@kresin.me>
13 files changed:
target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/cns3xxx/base-files/lib/cns3xxx.sh
target/linux/cns3xxx/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/imx6/base-files/lib/imx6.sh
target/linux/imx6/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/ixp4xx/base-files/lib/ixp4xx.sh
target/linux/ixp4xx/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/kirkwood/base-files/lib/kirkwood.sh
target/linux/kirkwood/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/mvebu/base-files/lib/mvebu.sh
target/linux/mvebu/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/orion/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]
target/linux/ppc40x/base-files/lib/preinit/01_sysinfo [new file with mode: 0644]

diff --git a/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo b/target/linux/brcm47xx/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..8a2de67
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+do_sysinfo_brcm47xx() {
+       local name="$(sed -ne 's/^machine[ \t]*: //p' /proc/cpuinfo)"
+       [ -z "$name" ] && name="unknown"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+       echo "$name" > /tmp/sysinfo/board_name
+       echo "unknown" > /tmp/sysinfo/model
+}
+
+boot_hook_add preinit_main do_sysinfo_brcm47xx
index 476f9be21de095c3cf8e0b65584b98319e5f8acb..fb2c1043e13bc4fd9b8934465fe3cda74733cd5e 100644 (file)
@@ -1,9 +1,9 @@
 #!/bin/sh
-#
-# Copyright (C) 2012 OpenWrt.org
-#
 
-cns3xxx_board_name() {
+CNS3XXX_BOARD_NAME=
+CNS3XXX_MODEL=
+
+cns3xxx_board_detect() {
        local machine
        local name
 
@@ -17,6 +17,21 @@ cns3xxx_board_name() {
                        name="generic";
                        ;;
        esac
-       
-       echo $name
+
+       [ -z "$CNS3XXX_BOARD_NAME" ] && CNS3XXX_BOARD_NAME="$name"
+       [ -z "$CNS3XXX_MODEL" ] && CNS3XXX_MODEL="$machine"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+
+       echo "$CNS3XXX_BOARD_NAME" > /tmp/sysinfo/board_name
+       echo "$CNS3XXX_MODEL" > /tmp/sysinfo/model
+}
+
+cns3xxx_board_name() {
+       local name
+
+       [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
+       [ -z "$name" ] && name="unknown"
+
+       echo "$name"
 }
diff --git a/target/linux/cns3xxx/base-files/lib/preinit/01_sysinfo b/target/linux/cns3xxx/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..cc7b555
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_sysinfo_cns3xxx() {
+       . /lib/cns3xxx.sh
+
+       cns3xxx_board_detect
+}
+
+boot_hook_add preinit_main do_sysinfo_cns3xxx
index 94adf1ccb30783be4afc5fdc6f755cadcb24ed4e..385c54f9f97fd33972559e8b11c189ae4bcfce7b 100755 (executable)
@@ -75,7 +75,6 @@ imx6_board_detect() {
 imx6_board_name() {
        local name
 
-       [ -f /tmp/sysinfo/board_name ] || imx6_board_detect
        [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
        [ -z "$name" ] && name="unknown"
 
diff --git a/target/linux/imx6/base-files/lib/preinit/01_sysinfo b/target/linux/imx6/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..0a91aed
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_sysinfo_imx6() {
+       . /lib/imx6.sh
+
+       imx6_board_detect
+}
+
+boot_hook_add preinit_main do_sysinfo_imx6
index f7a6b76edaf706798a166003652dfdb04ddf2558..7486356b9cceae617a0fedd3e6f546443e7b2ffc 100644 (file)
@@ -3,23 +3,41 @@
 # Copyright (C) 2012 OpenWrt.org
 #
 
-ixp4xx_board_name() {
-        local machine
-        local name
-
-        machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /Hardware/ {print $2}' /proc/cpuinfo)
-
-        case "$machine" in
-               "Gateworks Cambria"*)
-                       name="cambria"
-                       ;;
-               "Gateworks Avila"*)
-                       name="avila"
-                       ;;
-               *)
-                       name="generic";
-                       ;;
+IXP4XX_BOARD_NAME=
+IXP4XX_MODEL=
+
+ixp4xx_board_detect() {
+       local machine
+       local name
+
+       machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /Hardware/ {print $2}' /proc/cpuinfo)
+
+       case "$machine" in
+       "Gateworks Cambria"*)
+               name="cambria"
+               ;;
+       "Gateworks Avila"*)
+               name="avila"
+               ;;
+       *)
+               name="generic";
+               ;;
        esac
 
+       [ -z "$IXP4XX_BOARD_NAME" ] && IXP4XX_BOARD_NAME="$name"
+       [ -z "$IXP4XX_MODEL" ] && IXP4XX_MODEL="$machine"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+
+       echo "$IXP4XX_BOARD_NAME" > /tmp/sysinfo/board_name
+       echo "$IXP4XX_MODEL" > /tmp/sysinfo/model
+}
+
+ixp4xx_board_name() {
+       local name
+
+       [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
+       [ -z "$name" ] && name="unknown"
+
        echo $name
 }
diff --git a/target/linux/ixp4xx/base-files/lib/preinit/01_sysinfo b/target/linux/ixp4xx/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..7699e9a
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_sysinfo_ixp4xx() {
+       . /lib/ixp4xx.sh
+
+       ixp4xx_board_detect
+}
+
+boot_hook_add preinit_main do_sysinfo_ixp4xx
index c29a315f79c01c8a7b3f3f790fe75193b06e1bad..20c6ebdfde7a088326f5b08f0aa3a0bad162066f 100755 (executable)
@@ -90,7 +90,6 @@ kirkwood_board_detect() {
 kirkwood_board_name() {
        local name
 
-       [ -f /tmp/sysinfo/board_name ] || kirkwood_board_detect
        [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
        [ -z "$name" ] && name="unknown"
 
diff --git a/target/linux/kirkwood/base-files/lib/preinit/01_sysinfo b/target/linux/kirkwood/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..d45fc92
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_sysinfo_kirkwood() {
+       . /lib/kirkwood.sh
+
+       kirkwood_board_detect
+}
+
+boot_hook_add preinit_main do_sysinfo_kirkwood
index ecf3d44848c19748300c6d91446b430e2c97878c..9096860dd4f1fee96cb6e7bacdefac81e2de7d68 100755 (executable)
@@ -75,7 +75,6 @@ mvebu_board_detect() {
 mvebu_board_name() {
        local name
 
-       [ -f /tmp/sysinfo/board_name ] || mvebu_board_detect
        [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
        [ -z "$name" ] && name="unknown"
 
diff --git a/target/linux/mvebu/base-files/lib/preinit/01_sysinfo b/target/linux/mvebu/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..6f473cf
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_sysinfo_mvebu() {
+       . /lib/mvebu.sh
+
+       mvebu_board_detect
+}
+
+boot_hook_add preinit_main do_sysinfo_mvebu
diff --git a/target/linux/orion/base-files/lib/preinit/01_sysinfo b/target/linux/orion/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..1ef07d7
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+do_sysinfo_orion() {
+       local name="$(sed -n /Hardware/s/.*:.//p /proc/cpuinfo)"
+       [ -z "$name" ] && name="unknown"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+       echo "$name" > /tmp/sysinfo/board_name
+       echo "unknown" > /tmp/sysinfo/model
+}
+
+boot_hook_add preinit_main do_sysinfo_orion
diff --git a/target/linux/ppc40x/base-files/lib/preinit/01_sysinfo b/target/linux/ppc40x/base-files/lib/preinit/01_sysinfo
new file mode 100644 (file)
index 0000000..9f82c84
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+do_sysinfo_ppc40x() {
+       local name="$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /model/ {print $2}' /proc/cpuinfo)"
+       [ -z "$name" ] && name="unknown"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+       echo "$name" > /tmp/sysinfo/board_name
+       echo "unknown" > /tmp/sysinfo/model
+}
+
+boot_hook_add preinit_main do_sysinfo_ppc40x