d3a0bfc49146773058e2efec29b8743ebf16f67c
[openwrt/staging/chunkeey.git] / target / linux / brcm-2.4 / base-files / default / etc / preinit.arch
1 . /etc/functions.sh
2
3 failsafe_ip() {
4 ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
5 }
6
7 failsafe() {
8 lock /tmp/.failsafe
9 failsafe_ip
10
11 echo "0 1 2 3 4 5u*" > /proc/switch/eth0/vlan/0/ports
12
13 set_state failsafe
14 [ -x "/usr/sbin/nvram" ] && {
15 [ "$(nvram get boot_wait)" != "on" ] && {
16 nvram set boot_wait=on
17 nvram commit
18 }
19 }
20
21 netmsg 192.168.1.255 "Entering Failsafe!"
22 telnetd -l /bin/login <> /dev/null 2>&1
23
24 ash --login
25 }
26
27 mount none /proc -t proc
28
29 if grep devfs /proc/filesystems > /dev/null; then
30 mount none /dev -t devfs
31 M0=/dev/pty/m0
32 M1=/dev/pty/m1
33 HOTPLUG=/sbin/hotplug-call
34 else
35 mount -t sysfs none /sys
36 mount -t tmpfs tmpfs /dev -o size=512K
37 mknod /dev/console c 5 1
38 mkdir /dev/shm
39 /sbin/hotplug2 --no-persistent --coldplug --set-rules-file /etc/hotplug2-init.rules
40 M0=/dev/ptmx
41 M1=/dev/ptmx
42 HOTPLUG=
43 fi
44 mkdir -p /dev/pts
45 mount none /dev/pts -t devpts
46
47 # the shell really doesn't like having stdin/out closed
48 # that's why we use /dev/pty/m0 and m1 as replacement
49 # for /dev/console if there's no serial console available
50 dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null || \
51 exec <$M0 >$M1 2>&0
52
53 insmod diag
54 set_state preinit
55 trap 'FAILSAFE=true' USR1
56 echo '/sbin/hotplug.failsafe' > /proc/sys/kernel/hotplug
57
58 ifname=eth0
59
60 # hardware specific overrides
61 case "$(cat /proc/diag/model)" in
62 "Linksys WAP54G V1") ifname=eth1;;
63 "ASUS WL-HDD") ifname=eth1;;
64 "ASUS WL-300g") ifname=eth1;;
65 "ASUS (unknown, BCM4702)") ifname=eth1;;
66 esac
67
68 failsafe_ip
69
70 insmod switch-core
71 insmod switch-robo || insmod switch-adm || rmmod switch-core
72
73 [ -d /proc/switch/eth0 ] && {
74 echo 1 > /proc/switch/eth0/reset
75
76 # this would be easier if we blasted the message across all ports
77 # but we don't want packets leaking across interfaces
78 for port in $(seq 0 4); do {
79 echo "$port 5u*" > /proc/switch/eth0/vlan/0/ports
80 netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
81 }; done
82 } || netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
83
84 sleep 2
85 echo "$HOTPLUG" > /proc/sys/kernel/hotplug
86
87 ifconfig $ifname 0.0.0.0 down