add support for target 3c24xx (more known as Openmoko GTA02 "Freerunner") and merge...
[openwrt-working-2016/.git] / target / linux / s3c24xx / base-files / etc / preinit
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
4 . /etc/diag.sh
5 rm -rf /dev/console
6 mknod /dev/console c 204 64
7 exec </dev/console > /dev/console 2>&0
8
9 failsafe_ip() {
10         ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
11 }
12
13 failsafe() {
14         [ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
15                 failsafe_ip
16                 netmsg 192.168.1.255 "Entering Failsafe!"
17                 telnetd -l /bin/login <> /dev/null 2>&1
18         }
19         lock /tmp/.failsafe
20         ash --login
21 }
22
23 mount none /proc -t proc
24 mount none /sys  -t sysfs
25
26 size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)?mt-l:s}' /proc/meminfo)
27 mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
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 tmpfs tmpfs /dev -o size=512K
36 #       mknod /dev/console c 5 1
37         mkdir /dev/shm
38         /sbin/hotplug2 --coldplug --set-rules-file /etc/hotplug2-init.rules
39         /sbin/hotplug2 --no-coldplug --persistent --set-rules-file /etc/hotplug2-init.rules &
40         M0=/dev/ptmx
41         M1=/dev/ptmx
42         HOTPLUG=
43 fi
44
45 mkdir -p /dev/pts /dev/shm
46 mount none /dev/pts -t devpts
47
48 # the shell really doesn't like having stdin/out closed
49 # that's why we use /dev/pty/m0 and m1 as replacement
50 # for /dev/console if there's no serial console available
51 dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null && {
52         M0=/dev/console
53         M1=/dev/console
54 }
55
56 exec <$M0 >$M1 2>&0
57
58 echo "- preinit -"
59 trap 'FAILSAFE=true' USR1
60 [ -e /etc/preinit.arch ] && . /etc/preinit.arch
61 set_state preinit
62 echo "$HOTPLUG" > /proc/sys/kernel/hotplug
63 eval ${FAILSAFE:+failsafe}
64 lock -w /tmp/.failsafe
65 #mount_root
66 [ -f /sysupgrade.tgz ] && {
67         echo "- config restore -"
68         cd /
69         mv sysupgrade.tgz /tmp
70         tar xzf /tmp/sysupgrade.tgz
71         rm -f /tmp/sysupgrade.tgz
72         sync
73 }
74
75 echo "- init -"
76         
77 killall hotplug2
78 exec /sbin/init