a6af7e117aaaeb037a8a39d2d9fc5aeb5b89a336
[openwrt-10.03/.git] / target / linux / ar71xx / base-files / etc / preinit.arch
1 #
2 # Copyright (C) 2009 OpenWrt.org
3 #
4
5 . /lib/ar71xx.sh
6
7 fetch_mac_from_mtd() {
8         local mtd_part=$1
9         local lan_env=$2
10         local wan_env=$3
11         local mtd mac
12
13         mtd=$(grep $mtd_part /proc/mtd | cut -d: -f1)
14         [ -z $mtd ] && return
15
16         mac=$(grep $lan_env /dev/$mtd | cut -d= -f2)
17         [ ! -z $mac ] && ifconfig eth0 hw ether $mac 2>/dev/null
18
19         mac=$(grep $wan_env /dev/$mtd | cut -d= -f2)
20         [ ! -z $mac ] && ifconfig eth1 hw ether $mac 2>/dev/null
21 }
22
23 preinit_load_modules() {
24         insmod input-core
25         insmod input-polldev
26         insmod gpio_buttons
27         insmod button-hotplug
28 }
29
30 preinit_set_mac_address() {
31         case $(ar71xx_board_name) in
32                 tew-632brp)
33                         fetch_mac_from_mtd config lan_mac wan_mac
34                         ;;
35                 wrt160nl)
36                         fetch_mac_from_mtd nvram lan_hwaddr wan_hwaddr
37                         ;;
38         esac
39 }
40
41 preinit_set_mac_address
42 preinit_load_modules
43
44 ifname=eth0
45
46 failsafe_ip
47
48 netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
49
50 ifconfig "$ifname" 0.0.0.0 down
51
52 sleep 2