d4e99277d55574f4f00f9bc196ce62471d73d43a
[openwrt/svn-archive/archive.git] / openwrt / package / base-files / default / etc / preinit
1 #!/bin/sh
2 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
3 mount none /proc -t proc
4 insmod diag
5 echo 0x01 > /proc/sys/diag
6
7 ifconfig eth0 up
8 insmod switch-core
9 insmod switch-robo || insmod switch-adm || rmmod switch-core
10
11 case "$(nvram get boardtype)" in
12 0x0467) failsafe_vlan="0 1 2 3 5u*";;
13 *) failsafe_vlan="1 2 3 4 5u*";;
14 esac
15 # save the boot loader's vlan config
16 # we need it on some routers that have no vlan*ports set
17 [ -d /proc/switch/eth0 ] && {
18 v0p="$(cat /proc/switch/eth0/vlan/0/ports)"
19 v1p="$(cat /proc/switch/eth0/vlan/1/ports)"
20 v2p="$(cat /proc/switch/eth0/vlan/2/ports)"
21 echo 1 > /proc/switch/eth0/reset
22 echo "$failsafe_vlan" > /proc/switch/eth0/vlan/0/ports
23 }
24
25 # this delay is apparently necessary because the link isn't up yet
26 ifconfig eth0 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
27 netmsg 192.168.1.0 "(dummy message)" # b44 eats the first packet
28 netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
29
30 sleep 2
31
32 if [ $(cat /proc/sys/reset) = 1 -o "$(nvram get failsafe)" = 1 ]; then
33 export FAILSAFE=true
34 [ "$(nvram get boot_wait)" != "on" ] && {
35 nvram set boot_wait=on
36 nvram commit
37 }
38 while :; do { echo $(((X=(X+1)%8)%2)) > /proc/sys/diag; sleep $((X==0)); } done &
39 netmsg 192.168.1.255 "Entering Failsafe!"
40 else
41 netmsg 192.168.1.255 "Normal startup."
42 fi
43
44 mount_root ${FAILSAFE:+failsafe}
45
46 # revert to the boot loader's vlan config
47 # required for at least WRT54G v1.1
48 [ -d /proc/switch/eth0 ] && {
49 echo "$v0p" > /proc/switch/eth0/vlan/0/ports
50 echo "$v1p" > /proc/switch/eth0/vlan/1/ports
51 echo "$v2p" > /proc/switch/eth0/vlan/2/ports
52 }
53
54 # remove the drivers for now
55 rmmod switch-robo
56 rmmod switch-adm
57 rmmod switch-core
58 ifconfig eth0 0.0.0.0
59
60 exec /sbin/init