Move wget2nand to the base-files for adm5120 also fix default permission (#1812)
[openwrt/openwrt.git] / target / linux / adm5120-2.6 / base-files / default / sbin / wget2nand
1 #!/bin/sh
2 # wget2nand
3 # This script can be used to download a TGZ file from your build system which
4 # contains the files to be installed on the NAND flash on your RB1xx card.
5 # The one parameter is the URL of the TGZ file to be downloaded.
6 # Licence GPL V2
7 # Author david.goodenough@linkchoose.co.uk
8 # Based on cf2nand from RB532 support
9 . /etc/functions.sh
10
11 [ -d /tmp/wget2nand ] && {
12 echo "/tmp/wget2nand already exists"
13 exit 1
14 }
15
16 # first get an address for br-lan using udhcpc
17 killall udhcpc
18 /sbin/udhcpc -i br-lan
19
20 # need to find the wget server from the command line
21 url=$1
22 [ -z "$url" ] && {
23 echo "No URL specified for image TGZ"
24 echo "Usage : $0 URL"
25 exit 1
26 }
27
28 boot="$(find_mtd_part 'RouterBoard NAND Boot')"
29 main="$(find_mtd_part 'rootfs')"
30 [ -z "$boot" -o -z "$main" ] && {
31 echo "Cannot find NAND Flash partitions"
32 exit 1
33 }
34
35 echo "Erasing filesystem."
36 mtd erase Boot 2>/dev/null >/dev/null
37 mtd erase Main 2>/dev/null >/dev/null
38
39 echo "Mounting $main as new root and $boot as boot partition"
40
41 mkdir /tmp/wget2nand/
42 mkdir /tmp/wget2nand-boot
43 mount -t yaffs2 "$main" /tmp/wget2nand/
44 mount -t yaffs2 "$boot" /tmp/wget2nand-boot
45
46 echo "Copying filesystem..."
47 ( wget -O - $url/openwrt-adm5120-2.6-rootfs.tgz) | ( cd /tmp/wget2nand/; tar xvz )
48 wget -O /tmp/wget2nand-boot/kernel $url/openwrt-adm5120-2.6-vmlinux.elf
49
50 # update the command line on the kernel to boot from the right place
51 [ ! -e /sbin/patch-cmdline ] && {
52 echo "Cannot find patch-cmdline"
53 exit 1
54 }
55
56 echo "Patching the kernel command line"
57 /sbin/patch-cmdline /tmp/wget2nand-boot/kernel "root=/dev/mtdblock1 rootfstype=yaffs2 init=/etc/preinit "
58 chmod +x /tmp/wget2nand-boot/kernel
59
60 # make sure everything is written before we unmount the partitions
61 echo "chmod ugo+x /" > /tmp/wget2nand/etc/uci-defaults/set_root_permission
62 sync
63 ls /tmp/wget2nand-boot/
64 ls /tmp/wget2nand/
65 # unmount the partitions and remove the directories into which they were mounted
66 umount /tmp/wget2nand-boot
67 umount /tmp/wget2nand
68 rmdir /tmp/wget2nand-boot
69 rmdir /tmp/wget2nand
70
71 # all done
72 echo "Image written, you can now reboot. Remember to change the boot source to Boot from Nand"