From: Mathias Kresin Date: Fri, 7 Apr 2017 16:09:08 +0000 (+0200) Subject: treewide: populate boardname and model earlier X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=ac3e05c5d757334944fbf1f14583164cd1d69172;p=openwrt%2Fstaging%2Frmilecki.git treewide: populate boardname and model earlier For targets using the generic board detection and board specific settings in diag.sh, the board name is still unset at the time the set_state() provided by diag.sh is called by 10_indicate_preinit. Change the execution order to ensure the boardname is populated before required the first time. Do the target specific board detection as early as possible, directly followed by the generic one to allow a seamless switch to the generic function for populating /tmp/sysinfo/. Signed-off-by: Mathias Kresin --- diff --git a/package/base-files/files/lib/preinit/02_sysinfo b/package/base-files/files/lib/preinit/02_sysinfo new file mode 100644 index 00000000000..65b50968e2c --- /dev/null +++ b/package/base-files/files/lib/preinit/02_sysinfo @@ -0,0 +1,10 @@ +do_sysinfo_generic() { + [ -d /proc/device-tree ] || return + mkdir -p /tmp/sysinfo + [ -e /tmp/sysinfo/board_name ] || \ + echo "$(strings /proc/device-tree/compatible | head -1)" > /tmp/sysinfo/board_name + [ ! -e /tmp/sysinfo/model -a -e /proc/device-tree/model ] && \ + echo "$(cat /proc/device-tree/model)" > /tmp/sysinfo/model +} + +boot_hook_add preinit_main do_sysinfo_generic diff --git a/package/base-files/files/lib/preinit/10_sysinfo b/package/base-files/files/lib/preinit/10_sysinfo deleted file mode 100644 index 65b50968e2c..00000000000 --- a/package/base-files/files/lib/preinit/10_sysinfo +++ /dev/null @@ -1,10 +0,0 @@ -do_sysinfo_generic() { - [ -d /proc/device-tree ] || return - mkdir -p /tmp/sysinfo - [ -e /tmp/sysinfo/board_name ] || \ - echo "$(strings /proc/device-tree/compatible | head -1)" > /tmp/sysinfo/board_name - [ ! -e /tmp/sysinfo/model -a -e /proc/device-tree/model ] && \ - echo "$(cat /proc/device-tree/model)" > /tmp/sysinfo/model -} - -boot_hook_add preinit_main do_sysinfo_generic diff --git a/target/linux/adm5120/base-files/lib/preinit/01_preinit_do_adm5120.sh b/target/linux/adm5120/base-files/lib/preinit/01_preinit_do_adm5120.sh new file mode 100644 index 00000000000..4fca1e71b2f --- /dev/null +++ b/target/linux/adm5120/base-files/lib/preinit/01_preinit_do_adm5120.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +do_adm5120() { + . /lib/adm5120.sh +} + +boot_hook_add preinit_main do_adm5120 diff --git a/target/linux/adm5120/base-files/lib/preinit/05_preinit_do_adm5120.sh b/target/linux/adm5120/base-files/lib/preinit/05_preinit_do_adm5120.sh deleted file mode 100644 index 4fca1e71b2f..00000000000 --- a/target/linux/adm5120/base-files/lib/preinit/05_preinit_do_adm5120.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -do_adm5120() { - . /lib/adm5120.sh -} - -boot_hook_add preinit_main do_adm5120 diff --git a/target/linux/apm821xx/base-files/lib/preinit/01_preinit_do_apm821xx.sh b/target/linux/apm821xx/base-files/lib/preinit/01_preinit_do_apm821xx.sh new file mode 100644 index 00000000000..5675357533b --- /dev/null +++ b/target/linux/apm821xx/base-files/lib/preinit/01_preinit_do_apm821xx.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_apm821xx() { + . /lib/apm821xx.sh + + apm821xx_board_detect +} + +boot_hook_add preinit_main do_apm821xx diff --git a/target/linux/apm821xx/base-files/lib/preinit/03_preinit_do_apm821xx.sh b/target/linux/apm821xx/base-files/lib/preinit/03_preinit_do_apm821xx.sh deleted file mode 100644 index 5675357533b..00000000000 --- a/target/linux/apm821xx/base-files/lib/preinit/03_preinit_do_apm821xx.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_apm821xx() { - . /lib/apm821xx.sh - - apm821xx_board_detect -} - -boot_hook_add preinit_main do_apm821xx diff --git a/target/linux/ar71xx/base-files/lib/preinit/01_preinit_do_ar71xx.sh b/target/linux/ar71xx/base-files/lib/preinit/01_preinit_do_ar71xx.sh new file mode 100644 index 00000000000..ff5407a0d40 --- /dev/null +++ b/target/linux/ar71xx/base-files/lib/preinit/01_preinit_do_ar71xx.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_ar71xx() { + . /lib/ar71xx.sh + + ar71xx_board_detect +} + +boot_hook_add preinit_main do_ar71xx diff --git a/target/linux/ar71xx/base-files/lib/preinit/03_preinit_do_ar71xx.sh b/target/linux/ar71xx/base-files/lib/preinit/03_preinit_do_ar71xx.sh deleted file mode 100644 index ff5407a0d40..00000000000 --- a/target/linux/ar71xx/base-files/lib/preinit/03_preinit_do_ar71xx.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_ar71xx() { - . /lib/ar71xx.sh - - ar71xx_board_detect -} - -boot_hook_add preinit_main do_ar71xx diff --git a/target/linux/at91/base-files/lib/preinit/01_preinit_do_at91.sh b/target/linux/at91/base-files/lib/preinit/01_preinit_do_at91.sh new file mode 100644 index 00000000000..5c981016a40 --- /dev/null +++ b/target/linux/at91/base-files/lib/preinit/01_preinit_do_at91.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_at91() { + . /lib/at91.sh + + at91_board_detect +} + +boot_hook_add preinit_main do_at91 diff --git a/target/linux/at91/base-files/lib/preinit/03_preinit_do_at91.sh b/target/linux/at91/base-files/lib/preinit/03_preinit_do_at91.sh deleted file mode 100644 index 5c981016a40..00000000000 --- a/target/linux/at91/base-files/lib/preinit/03_preinit_do_at91.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_at91() { - . /lib/at91.sh - - at91_board_detect -} - -boot_hook_add preinit_main do_at91 diff --git a/target/linux/brcm2708/base-files/lib/preinit/01_preinit_do_brcm2708.sh b/target/linux/brcm2708/base-files/lib/preinit/01_preinit_do_brcm2708.sh new file mode 100644 index 00000000000..294364848d7 --- /dev/null +++ b/target/linux/brcm2708/base-files/lib/preinit/01_preinit_do_brcm2708.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2015 OpenWrt.org + +do_brcm2708() { + . /lib/brcm2708.sh + + brcm2708_detect +} + +boot_hook_add preinit_main do_brcm2708 diff --git a/target/linux/brcm2708/base-files/lib/preinit/03_preinit_do_brcm2708.sh b/target/linux/brcm2708/base-files/lib/preinit/03_preinit_do_brcm2708.sh deleted file mode 100644 index 294364848d7..00000000000 --- a/target/linux/brcm2708/base-files/lib/preinit/03_preinit_do_brcm2708.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# Copyright (C) 2015 OpenWrt.org - -do_brcm2708() { - . /lib/brcm2708.sh - - brcm2708_detect -} - -boot_hook_add preinit_main do_brcm2708 diff --git a/target/linux/brcm63xx/base-files/lib/preinit/01_do_brcm63xx.sh b/target/linux/brcm63xx/base-files/lib/preinit/01_do_brcm63xx.sh new file mode 100644 index 00000000000..41796950248 --- /dev/null +++ b/target/linux/brcm63xx/base-files/lib/preinit/01_do_brcm63xx.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_brcm63xx() { + . /lib/brcm63xx.sh + + brcm63xx_detect +} + +boot_hook_add preinit_main do_brcm63xx diff --git a/target/linux/brcm63xx/base-files/lib/preinit/03_do_brcm63xx.sh b/target/linux/brcm63xx/base-files/lib/preinit/03_do_brcm63xx.sh deleted file mode 100644 index 41796950248..00000000000 --- a/target/linux/brcm63xx/base-files/lib/preinit/03_do_brcm63xx.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_brcm63xx() { - . /lib/brcm63xx.sh - - brcm63xx_detect -} - -boot_hook_add preinit_main do_brcm63xx diff --git a/target/linux/ipq806x/base-files/lib/preinit/01_preinit_do_ipq806x.sh b/target/linux/ipq806x/base-files/lib/preinit/01_preinit_do_ipq806x.sh new file mode 100644 index 00000000000..785f1ebb8b3 --- /dev/null +++ b/target/linux/ipq806x/base-files/lib/preinit/01_preinit_do_ipq806x.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# +# Copyright (c) 2014 The Linux Foundation. All rights reserved. +# + +do_ipq806x() { + . /lib/ipq806x.sh + + ipq806x_board_detect +} + +boot_hook_add preinit_main do_ipq806x diff --git a/target/linux/ipq806x/base-files/lib/preinit/03_preinit_do_ipq806x.sh b/target/linux/ipq806x/base-files/lib/preinit/03_preinit_do_ipq806x.sh deleted file mode 100644 index 785f1ebb8b3..00000000000 --- a/target/linux/ipq806x/base-files/lib/preinit/03_preinit_do_ipq806x.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2014 The Linux Foundation. All rights reserved. -# - -do_ipq806x() { - . /lib/ipq806x.sh - - ipq806x_board_detect -} - -boot_hook_add preinit_main do_ipq806x diff --git a/target/linux/lantiq/base-files/lib/preinit/01_preinit_board.sh b/target/linux/lantiq/base-files/lib/preinit/01_preinit_board.sh new file mode 100755 index 00000000000..aef946036eb --- /dev/null +++ b/target/linux/lantiq/base-files/lib/preinit/01_preinit_board.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +lantiq_board_detect() { + name=`grep "^machine" /proc/cpuinfo | sed "s/machine.*: \(.*\)/\1/g" | sed "s/\(.*\) - .*/\1/g"` + model=`grep "^machine" /proc/cpuinfo | sed "s/machine.*: \(.*\)/\1/g" | sed "s/.* - \(.*\)/\1/g"` + [ -z "$name" ] && name="unknown" + [ -z "$model" ] && model="unknown" + [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" + echo $name > /tmp/sysinfo/board_name + echo $model > /tmp/sysinfo/model +} + +do_lantiq() { + . /lib/functions/lantiq.sh + + lantiq_board_detect +} + +boot_hook_add preinit_main do_lantiq diff --git a/target/linux/lantiq/base-files/lib/preinit/03_preinit_board.sh b/target/linux/lantiq/base-files/lib/preinit/03_preinit_board.sh deleted file mode 100755 index aef946036eb..00000000000 --- a/target/linux/lantiq/base-files/lib/preinit/03_preinit_board.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -lantiq_board_detect() { - name=`grep "^machine" /proc/cpuinfo | sed "s/machine.*: \(.*\)/\1/g" | sed "s/\(.*\) - .*/\1/g"` - model=`grep "^machine" /proc/cpuinfo | sed "s/machine.*: \(.*\)/\1/g" | sed "s/.* - \(.*\)/\1/g"` - [ -z "$name" ] && name="unknown" - [ -z "$model" ] && model="unknown" - [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" - echo $name > /tmp/sysinfo/board_name - echo $model > /tmp/sysinfo/model -} - -do_lantiq() { - . /lib/functions/lantiq.sh - - lantiq_board_detect -} - -boot_hook_add preinit_main do_lantiq diff --git a/target/linux/mcs814x/base-files/lib/preinit/01_preinit_do_mcs814x.sh b/target/linux/mcs814x/base-files/lib/preinit/01_preinit_do_mcs814x.sh new file mode 100755 index 00000000000..d509770c551 --- /dev/null +++ b/target/linux/mcs814x/base-files/lib/preinit/01_preinit_do_mcs814x.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_mcs814x() { + . /lib/mcs814x.sh + + mcs814x_board_detect +} + +boot_hook_add preinit_main do_mcs814x diff --git a/target/linux/mcs814x/base-files/lib/preinit/03_preinit_do_mcs814x.sh b/target/linux/mcs814x/base-files/lib/preinit/03_preinit_do_mcs814x.sh deleted file mode 100755 index d509770c551..00000000000 --- a/target/linux/mcs814x/base-files/lib/preinit/03_preinit_do_mcs814x.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_mcs814x() { - . /lib/mcs814x.sh - - mcs814x_board_detect -} - -boot_hook_add preinit_main do_mcs814x diff --git a/target/linux/mpc85xx/base-files/lib/preinit/01_preinit_do_mpc85xx.sh b/target/linux/mpc85xx/base-files/lib/preinit/01_preinit_do_mpc85xx.sh new file mode 100644 index 00000000000..88ba608379a --- /dev/null +++ b/target/linux/mpc85xx/base-files/lib/preinit/01_preinit_do_mpc85xx.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_mpc85xx() { + . /lib/mpc85xx.sh + + mpc85xx_board_detect +} + +boot_hook_add preinit_main do_mpc85xx diff --git a/target/linux/mpc85xx/base-files/lib/preinit/03_preinit_do_mpc85xx.sh b/target/linux/mpc85xx/base-files/lib/preinit/03_preinit_do_mpc85xx.sh deleted file mode 100644 index 88ba608379a..00000000000 --- a/target/linux/mpc85xx/base-files/lib/preinit/03_preinit_do_mpc85xx.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_mpc85xx() { - . /lib/mpc85xx.sh - - mpc85xx_board_detect -} - -boot_hook_add preinit_main do_mpc85xx diff --git a/target/linux/mxs/base-files/lib/preinit/01_preinit_do_mxs.sh b/target/linux/mxs/base-files/lib/preinit/01_preinit_do_mxs.sh new file mode 100644 index 00000000000..692078d3e20 --- /dev/null +++ b/target/linux/mxs/base-files/lib/preinit/01_preinit_do_mxs.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_mxs() { + . /lib/mxs.sh + + mxs_board_detect +} + +boot_hook_add preinit_main do_mxs diff --git a/target/linux/mxs/base-files/lib/preinit/03_preinit_do_mxs.sh b/target/linux/mxs/base-files/lib/preinit/03_preinit_do_mxs.sh deleted file mode 100644 index 692078d3e20..00000000000 --- a/target/linux/mxs/base-files/lib/preinit/03_preinit_do_mxs.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_mxs() { - . /lib/mxs.sh - - mxs_board_detect -} - -boot_hook_add preinit_main do_mxs diff --git a/target/linux/octeon/base-files/lib/preinit/01_sysinfo b/target/linux/octeon/base-files/lib/preinit/01_sysinfo new file mode 100644 index 00000000000..d8f467ed277 --- /dev/null +++ b/target/linux/octeon/base-files/lib/preinit/01_sysinfo @@ -0,0 +1,31 @@ +do_sysinfo_octeon() { + local machine + local name + + machine=$(grep "^system type" /proc/cpuinfo | sed "s/system type.*: \(.*\)/\1/g") + + case "$machine" in + "UBNT_E100"*) + name="erlite" + ;; + + "UBNT_E200"*) + name="er" + ;; + + "UBNT_E220"*) + name="erpro" + ;; + + *) + name="generic" + ;; + esac + + [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" + + echo "$name" > /tmp/sysinfo/board_name + echo "$machine" > /tmp/sysinfo/model +} + +boot_hook_add preinit_main do_sysinfo_octeon diff --git a/target/linux/octeon/base-files/lib/preinit/20_sysinfo b/target/linux/octeon/base-files/lib/preinit/20_sysinfo deleted file mode 100644 index d8f467ed277..00000000000 --- a/target/linux/octeon/base-files/lib/preinit/20_sysinfo +++ /dev/null @@ -1,31 +0,0 @@ -do_sysinfo_octeon() { - local machine - local name - - machine=$(grep "^system type" /proc/cpuinfo | sed "s/system type.*: \(.*\)/\1/g") - - case "$machine" in - "UBNT_E100"*) - name="erlite" - ;; - - "UBNT_E200"*) - name="er" - ;; - - "UBNT_E220"*) - name="erpro" - ;; - - *) - name="generic" - ;; - esac - - [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" - - echo "$name" > /tmp/sysinfo/board_name - echo "$machine" > /tmp/sysinfo/model -} - -boot_hook_add preinit_main do_sysinfo_octeon diff --git a/target/linux/oxnas/base-files/lib/preinit/01_preinit_do_oxnas.sh b/target/linux/oxnas/base-files/lib/preinit/01_preinit_do_oxnas.sh new file mode 100644 index 00000000000..ca7bce10542 --- /dev/null +++ b/target/linux/oxnas/base-files/lib/preinit/01_preinit_do_oxnas.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_oxnas() { + . /lib/oxnas.sh + + oxnas_board_detect +} + +boot_hook_add preinit_main do_oxnas diff --git a/target/linux/oxnas/base-files/lib/preinit/03_preinit_do_oxnas.sh b/target/linux/oxnas/base-files/lib/preinit/03_preinit_do_oxnas.sh deleted file mode 100644 index ca7bce10542..00000000000 --- a/target/linux/oxnas/base-files/lib/preinit/03_preinit_do_oxnas.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_oxnas() { - . /lib/oxnas.sh - - oxnas_board_detect -} - -boot_hook_add preinit_main do_oxnas diff --git a/target/linux/ramips/base-files/lib/preinit/01_preinit_do_ramips.sh b/target/linux/ramips/base-files/lib/preinit/01_preinit_do_ramips.sh new file mode 100644 index 00000000000..31ef5f81467 --- /dev/null +++ b/target/linux/ramips/base-files/lib/preinit/01_preinit_do_ramips.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +do_ramips() { + . /lib/ramips.sh + + ramips_board_detect +} + +boot_hook_add preinit_main do_ramips diff --git a/target/linux/ramips/base-files/lib/preinit/03_preinit_do_ramips.sh b/target/linux/ramips/base-files/lib/preinit/03_preinit_do_ramips.sh deleted file mode 100644 index 31ef5f81467..00000000000 --- a/target/linux/ramips/base-files/lib/preinit/03_preinit_do_ramips.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -do_ramips() { - . /lib/ramips.sh - - ramips_board_detect -} - -boot_hook_add preinit_main do_ramips diff --git a/target/linux/rb532/base-files/lib/preinit/01_sysinfo b/target/linux/rb532/base-files/lib/preinit/01_sysinfo new file mode 100644 index 00000000000..4c932fde19d --- /dev/null +++ b/target/linux/rb532/base-files/lib/preinit/01_sysinfo @@ -0,0 +1,11 @@ +get_model_rb532() { + grep system\ type /proc/cpuinfo | awk -F ": " '{print $2}' +} + +do_sysinfo_rb532() { + mkdir -p /tmp/sysinfo + echo rb532 > /tmp/sysinfo/board_name + get_model_rb532 > /tmp/sysinfo/model +} + +boot_hook_add preinit_main do_sysinfo_rb532 diff --git a/target/linux/rb532/base-files/lib/preinit/10_sysinfo b/target/linux/rb532/base-files/lib/preinit/10_sysinfo deleted file mode 100644 index 4c932fde19d..00000000000 --- a/target/linux/rb532/base-files/lib/preinit/10_sysinfo +++ /dev/null @@ -1,11 +0,0 @@ -get_model_rb532() { - grep system\ type /proc/cpuinfo | awk -F ": " '{print $2}' -} - -do_sysinfo_rb532() { - mkdir -p /tmp/sysinfo - echo rb532 > /tmp/sysinfo/board_name - get_model_rb532 > /tmp/sysinfo/model -} - -boot_hook_add preinit_main do_sysinfo_rb532 diff --git a/target/linux/x86/base-files/lib/preinit/01_sysinfo b/target/linux/x86/base-files/lib/preinit/01_sysinfo new file mode 100644 index 00000000000..cb63a040142 --- /dev/null +++ b/target/linux/x86/base-files/lib/preinit/01_sysinfo @@ -0,0 +1,28 @@ +do_sysinfo_x86() { + local vendor product file + + for file in sys_vendor board_vendor; do + vendor="$(cat /sys/devices/virtual/dmi/id/$file 2>/dev/null)" + [ -n "$vendor" ] && break + done + + for file in product_name board_name; do + product="$(cat /sys/devices/virtual/dmi/id/$file 2>/dev/null)" + [ -n "$product" ] && break + done + + [ -n "$vendor" -a -n "$product" ] || return + + mkdir -p /tmp/sysinfo + + echo "$vendor $product" > /tmp/sysinfo/model + + sed -e ' + y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; + s/[^a-z0-9_-]\+/-/g; + s/^-//; + s/-$//; + ' /tmp/sysinfo/model > /tmp/sysinfo/board_name +} + +boot_hook_add preinit_main do_sysinfo_x86 diff --git a/target/linux/x86/base-files/lib/preinit/20_sysinfo b/target/linux/x86/base-files/lib/preinit/20_sysinfo deleted file mode 100644 index cb63a040142..00000000000 --- a/target/linux/x86/base-files/lib/preinit/20_sysinfo +++ /dev/null @@ -1,28 +0,0 @@ -do_sysinfo_x86() { - local vendor product file - - for file in sys_vendor board_vendor; do - vendor="$(cat /sys/devices/virtual/dmi/id/$file 2>/dev/null)" - [ -n "$vendor" ] && break - done - - for file in product_name board_name; do - product="$(cat /sys/devices/virtual/dmi/id/$file 2>/dev/null)" - [ -n "$product" ] && break - done - - [ -n "$vendor" -a -n "$product" ] || return - - mkdir -p /tmp/sysinfo - - echo "$vendor $product" > /tmp/sysinfo/model - - sed -e ' - y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; - s/[^a-z0-9_-]\+/-/g; - s/^-//; - s/-$//; - ' /tmp/sysinfo/model > /tmp/sysinfo/board_name -} - -boot_hook_add preinit_main do_sysinfo_x86