kirkwood: use uci-defaults to configure different boards
authorGabor Juhos <juhosg@openwrt.org>
Tue, 29 May 2012 16:39:15 +0000 (16:39 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Tue, 29 May 2012 16:39:15 +0000 (16:39 +0000)
Signed-off-by: Luka Perkov <openwrt@lukaperkov.net>
SVN-Revision: 31990

target/linux/kirkwood/base-files-Dockstar/etc/config/network [deleted file]
target/linux/kirkwood/base-files-Dockstar/etc/config/system [deleted file]
target/linux/kirkwood/base-files.mk [new file with mode: 0644]
target/linux/kirkwood/base-files/etc/uci-defaults/leds [new file with mode: 0644]
target/linux/kirkwood/base-files/etc/uci-defaults/network [new file with mode: 0644]
target/linux/kirkwood/base-files/lib/kirkwood.sh [new file with mode: 0644]

diff --git a/target/linux/kirkwood/base-files-Dockstar/etc/config/network b/target/linux/kirkwood/base-files-Dockstar/etc/config/network
deleted file mode 100644 (file)
index 9fd44f1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-config 'interface' 'loopback'
-        option 'ifname' 'lo'
-        option 'proto' 'static'
-        option 'ipaddr' '127.0.0.1'
-        option 'netmask' '255.0.0.0'
-
-config 'interface' 'lan'
-        option 'ifname' 'eth0'
-        option 'proto' 'dhcp'
diff --git a/target/linux/kirkwood/base-files-Dockstar/etc/config/system b/target/linux/kirkwood/base-files-Dockstar/etc/config/system
deleted file mode 100644 (file)
index 81ac978..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-# system file for Dockstar
-config system
-        option 'hostname' 'OpenWrt'
-        option 'timezone' 'UTC'
-
-config timeserver ntp
-       list server     0.openwrt.pool.ntp.org
-       list server     1.openwrt.pool.ntp.org
-       list server     2.openwrt.pool.ntp.org
-       list server     3.openwrt.pool.ntp.org
-
-config led
-        option 'sysfs' 'dockstar:green:health'
-        option 'trigger' 'none'
-        option 'default' '1'
-
-config led
-        option 'sysfs' 'dockstar:orange:misc'
-        option 'trigger' 'netdev'
-        option 'mode' 'tx rx'
-        option 'dev' 'eth0'
diff --git a/target/linux/kirkwood/base-files.mk b/target/linux/kirkwood/base-files.mk
new file mode 100644 (file)
index 0000000..fdd2c71
--- /dev/null
@@ -0,0 +1,3 @@
+define Package/base-files/install-target
+       rm -f $(1)/etc/config/network
+endef
diff --git a/target/linux/kirkwood/base-files/etc/uci-defaults/leds b/target/linux/kirkwood/base-files/etc/uci-defaults/leds
new file mode 100644 (file)
index 0000000..a0b1c1c
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+
+COMMIT_SYSTEM=0
+
+set_led_netdev() {
+       local cfg="led_$1"
+       local sysfs=$2
+       local dev=$3
+
+       uci -q get system.$cfg && return 0
+
+       uci batch <<EOF
+set system.$cfg='led'
+set system.$cfg.sysfs='$sysfs'
+set system.$cfg.trigger='netdev'
+set system.$cfg.dev='$dev'
+set system.$cfg.mode='link tx rx'
+EOF
+       COMMIT_SYSTEM=1
+}
+
+set_led_default() {
+       local cfg="led_$1"
+       local sysfs=$2
+       local default=$3
+
+       uci -q get system.$cfg && return 0
+
+       uci batch <<EOF
+set system.$cfg='led'
+set system.$cfg.sysfs='$sysfs'
+set system.$cfg.trigger='none'
+set system.$cfg.default='$default'
+EOF
+       COMMIT_SYSTEM=1
+}
+
+. /lib/kirkwood.sh
+
+hardware=$(kirkwood_hardware_name)
+
+case "$hardware" in
+"Seagate FreeAgent DockStar")
+       set_led_netdev "eth0" "dockstar:orange:misc" "eth0"
+       set_led_default "health" "dockstar:green:health" "1"
+       ;;
+
+*)
+       ;;
+esac
+
+[ "$COMMIT_SYSTEM" == "1" ] && uci commit system
+
+exit 0
diff --git a/target/linux/kirkwood/base-files/etc/uci-defaults/network b/target/linux/kirkwood/base-files/etc/uci-defaults/network
new file mode 100644 (file)
index 0000000..48c1232
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+
+[ -e /etc/config/network ] && exit 0
+
+set_lan_dhcp() {
+       local ifname=$1
+       uci batch <<EOF
+set network.lan='interface'
+set network.lan.ifname='$ifname'
+set network.lan.proto='dhcp'
+EOF
+}
+
+. /lib/functions/uci-defaults.sh
+. /lib/kirkwood.sh
+
+touch /etc/config/network
+
+ucidef_set_interface_loopback
+
+hardware=$(kirkwood_hardware_name)
+
+case "$hardware" in
+"Seagate FreeAgent DockStar")
+       set_lan_dhcp "eth0"
+       ;;
+
+"RaidSonic ICY BOX IB-NAS6210")
+       set_lan_dhcp "eth0"
+       ;;
+
+*)
+       ucidef_set_interface_lan "eth0"
+       ;;
+esac
+
+uci commit network
+
+exit 0
diff --git a/target/linux/kirkwood/base-files/lib/kirkwood.sh b/target/linux/kirkwood/base-files/lib/kirkwood.sh
new file mode 100644 (file)
index 0000000..4fcd760
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+kirkwood_hardware_name() {
+       grep ^Hardware /proc/cpuinfo | sed "s/Hardware.*: \(.*\)/\1/g"
+}