summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Yeryomin <roman@advem.lv>2014-03-11 00:54:50 +0200
committerRoman Yeryomin <roman@advem.lv>2014-03-11 00:54:50 +0200
commit68861cc62872ac7a2cf40acc70c4a8688660bc8e (patch)
treef98a1ee4a6024a2cc7769090455a4bbf095969cd
parentd53bc6bfaf30d6180d4b2e18ea54409a4bafeebc (diff)
Add preinit and uci-defaults scripts infrastructure. Generate network config automagically. Read lan/wan MAC addresses from MIB.
Signed-off-by: Roman Yeryomin <roman@advem.lv>
-rw-r--r--target/linux/realtek/base-files.mk5
-rw-r--r--target/linux/realtek/base-files/etc/config/network16
-rwxr-xr-xtarget/linux/realtek/base-files/etc/uci-defaults/02_network59
-rw-r--r--target/linux/realtek/base-files/lib/preinit/03_preinit_do_realtek.sh9
-rw-r--r--target/linux/realtek/base-files/lib/preinit/06_set_iface_mac35
-rw-r--r--target/linux/realtek/base-files/lib/preinit/07_set_preinit_iface_realtek12
-rwxr-xr-xtarget/linux/realtek/base-files/lib/realtek.sh40
7 files changed, 160 insertions, 16 deletions
diff --git a/target/linux/realtek/base-files.mk b/target/linux/realtek/base-files.mk
new file mode 100644
index 000000000..d6682bd38
--- /dev/null
+++ b/target/linux/realtek/base-files.mk
@@ -0,0 +1,5 @@
+define Package/base-files/install-target
+ rm -f $(1)/etc/config/network
+endef
+
+
diff --git a/target/linux/realtek/base-files/etc/config/network b/target/linux/realtek/base-files/etc/config/network
deleted file mode 100644
index 19c85f8f9..000000000
--- a/target/linux/realtek/base-files/etc/config/network
+++ /dev/null
@@ -1,16 +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 eth2 eth3 eth4"
- option type bridge
- option proto static
- option ipaddr 192.168.2.1
- option netmask 255.255.255.0
-
-config interface wan
- option ifname eth1
- option proto dhcp
diff --git a/target/linux/realtek/base-files/etc/uci-defaults/02_network b/target/linux/realtek/base-files/etc/uci-defaults/02_network
new file mode 100755
index 000000000..d2d2e9829
--- /dev/null
+++ b/target/linux/realtek/base-files/etc/uci-defaults/02_network
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. /lib/realtek.sh
+. /lib/functions/uci-defaults.sh
+
+realtek_setup_interfaces()
+{
+ local board="$1"
+
+ ucidef_set_interface_loopback
+
+ case $board in
+ generic | \
+ nprove | \
+ nprove2)
+ ucidef_set_interfaces_lan_wan "eth0 eth2 eth3 eth4" "eth1"
+ ;;
+
+ nprove3)
+ ucidef_set_interface_lan "eth0.1"
+ ;;
+
+ *)
+ ucidef_set_interfaces_lan_wan "eth0" "eth1"
+ ;;
+ esac
+}
+
+realtek_setup_macs()
+{
+ local board="$1"
+ local lan_mac=""
+ local wan_mac=""
+
+ case $board in
+ generic | \
+ nprove)
+ lan_mac=$(rtkmib --get mac0)
+ wan_mac=$(rtkmib --get mac1)
+ ;;
+ esac
+
+ [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
+ [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
+}
+
+[ -e /etc/config/network ] && exit 0
+
+touch /etc/config/network
+
+board=$(realtek_board_name)
+
+realtek_setup_interfaces $board
+realtek_setup_macs $board
+
+uci commit network
+
+exit 0
diff --git a/target/linux/realtek/base-files/lib/preinit/03_preinit_do_realtek.sh b/target/linux/realtek/base-files/lib/preinit/03_preinit_do_realtek.sh
new file mode 100644
index 000000000..32b83308b
--- /dev/null
+++ b/target/linux/realtek/base-files/lib/preinit/03_preinit_do_realtek.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+do_realtek() {
+ . /lib/realtek.sh
+
+ realtek_board_detect
+}
+
+boot_hook_add preinit_main do_realtek
diff --git a/target/linux/realtek/base-files/lib/preinit/06_set_iface_mac b/target/linux/realtek/base-files/lib/preinit/06_set_iface_mac
new file mode 100644
index 000000000..ff27fc952
--- /dev/null
+++ b/target/linux/realtek/base-files/lib/preinit/06_set_iface_mac
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+
+preinit_set_mac_address() {
+ local mac
+
+ . /lib/functions.sh
+ . /lib/realtek.sh
+
+ case $(realtek_board_name) in
+ generic |\
+ nprove |\
+ nprove2)
+ mac=$(rtkmib --get mac0)
+ ifconfig eth0 hw ether $mac 2>/dev/null
+ ;;
+ sl-r7205)
+ mac=$(mtd_get_mac_binary factory 4)
+ mac=$(macaddr_setbit_la "$mac")
+ ifconfig eth0 hw ether $mac 2>/dev/null
+ ;;
+ dir-645)
+ mac=$(mtd_get_mac_ascii nvram lanmac)
+ mac=$(macaddr_setbit_la "$mac")
+ ifconfig eth0 hw ether $mac 2>/dev/null
+ ;;
+ xdxrn502j)
+ mac=$(mtd_get_mac_binary factory 40)
+ ifconfig eth0 hw ether $mac 2>/dev/null
+ ;;
+ esac
+}
+
+boot_hook_add preinit_main preinit_set_mac_address
diff --git a/target/linux/realtek/base-files/lib/preinit/07_set_preinit_iface_realtek b/target/linux/realtek/base-files/lib/preinit/07_set_preinit_iface_realtek
new file mode 100644
index 000000000..dba89a5c9
--- /dev/null
+++ b/target/linux/realtek/base-files/lib/preinit/07_set_preinit_iface_realtek
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+
+. /lib/realtek.sh
+
+realtek_set_preinit_iface() {
+ ifname=eth0
+}
+
+boot_hook_add preinit_main realtek_set_preinit_iface
diff --git a/target/linux/realtek/base-files/lib/realtek.sh b/target/linux/realtek/base-files/lib/realtek.sh
new file mode 100755
index 000000000..7f29dc253
--- /dev/null
+++ b/target/linux/realtek/base-files/lib/realtek.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+
+REALTEK_BOARD_NAME=
+REALTEK_MODEL=
+
+realtek_board_detect() {
+ local machine
+ local name
+
+ machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
+
+ case "$machine" in
+ *"Nprove")
+ name="nprove"
+ ;;
+ *)
+ name="generic"
+ ;;
+ esac
+
+ [ -z "$REALTEK_BOARD_NAME" ] && REALTEK_BOARD_NAME="$name"
+ [ -z "$REALTEK_MODEL" ] && REALTEK_MODEL="$machine"
+
+ [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
+
+ echo "$REALTEK_BOARD_NAME" > /tmp/sysinfo/board_name
+ echo "$REALTEK_MODEL" > /tmp/sysinfo/model
+}
+
+realtek_board_name() {
+ local name
+
+ [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
+ [ -z "$name" ] && name="unknown"
+
+ echo "$name"
+}