ramips: enhance user-space board detection
authorGabor Juhos <juhosg@openwrt.org>
Sun, 3 Mar 2013 12:47:02 +0000 (12:47 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Sun, 3 Mar 2013 12:47:02 +0000 (12:47 +0000)
Similar to ar71xx, detect only once and cache the strings in
/tmp/sysinfo/model and /tmp/sysinfo/boardname.

Signed-off-by: Daniel Golle <dgolle@allnet.de>
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 35850

target/linux/ramips/base-files/lib/preinit/03_preinit_do_ramips.sh
target/linux/ramips/base-files/lib/ramips.sh

index e76418dad0a36759da6a700a82a3c5e706d5a5e0..31ef5f81467d5e64a2b54d129f6a5f4dd3d7da86 100644 (file)
@@ -2,6 +2,8 @@
 
 do_ramips() {
        . /lib/ramips.sh
+
+       ramips_board_detect
 }
 
 boot_hook_add preinit_main do_ramips
index 8ca3bfbc5852e8d261966cab860f4146d1fd3338..4687856e6f3590affd255026a9f6fe26be6c307d 100755 (executable)
@@ -1,9 +1,13 @@
 #!/bin/sh
 #
-# Copyright (C) 2010 OpenWrt.org
+# Copyright (C) 2010-2013 OpenWrt.org
 #
 
-ramips_board_name() {
+RAMIPS_BOARD_NAME=
+RAMIPS_MODEL=
+
+
+ramips_board_detect() {
        local machine
        local name
 
@@ -189,5 +193,20 @@ ramips_board_name() {
                ;;
        esac
 
-       echo $name
+       [ -z "$RAMIPS_BOARD_NAME" ] && RAMIPS_BOARD_NAME="$name"
+       [ -z "$RAMIPS_MODEL" ] && RAMIPS_MODEL="$machine"
+
+       [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+
+       echo "$RAMIPS_BOARD_NAME" > /tmp/sysinfo/board_name
+       echo "$RAMIPS_MODEL" > /tmp/sysinfo/model
+}
+
+ramips_board_name() {
+       local name
+
+       [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
+       [ -z "$name" ] && name="unknown"
+
+       echo "$name"
 }