change cp to $(CP)
[openwrt/svn-archive/archive.git] / openwrt / package / base-files / default / sbin / mount_root
1 #!/bin/sh
2 . /etc/nvram.sh
3 is_clean() {
4 grep Broadcom /proc/cpuinfo 2>&- >&- || return 0
5 OFFSET="$((0x$(dd if=/dev/mtdblock/1 bs=1 skip=$((0x14)) count=2 2>&- | hexdump | grep 0000000 | cut -d ' ' -f 2) - 1))"
6 dd if=/dev/mtdblock/1 bs=1 skip=$OFFSET count=1 2>&- | hexdump -v | grep ' 0000' > /dev/null && return 255 || return 0
7 }
8
9 if [ "$1" != "failsafe" ]; then
10 mount | grep jffs2 >&-
11 if [ $? = 0 ] ; then
12 if [ $(cat /proc/mtd | wc -l) = 6 ]; then
13 echo 5 > /proc/sys/diag
14 mtd unlock linux
15 mtd erase OpenWrt
16 jffs2root --move
17 else
18 mtd unlock rootfs
19 mount -o remount,rw /dev/root /
20 fi
21 else
22 if [ -z "$(nvram get no_root_swap)" ]; then
23 is_clean || {
24 mtd erase OpenWrt
25 mtd unlock linux
26 jffs2root --clean
27 }
28 mtd unlock OpenWrt
29 mount -t jffs2 /dev/mtdblock/4 /jffs
30 pivot_root /jffs /jffs/rom
31 mount none /proc -t proc
32 mount none /dev -t devfs
33 umount /rom/proc rom/dev >&-
34 fi
35 fi
36 fi
37 mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50%
38 mkdir -p /dev/pts
39 mount none /dev/pts -t devpts
40 grep sysfs /proc/filesystems >&- && mount -t sysfs none /sys