| 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 | . /lib/functions.sh |
| 10 | |
| 11 | [ -d /tmp/wget2nand-rootfs ] && { |
| 12 | echo "/tmp/wget2nand-rootfs already exists" |
| 13 | exit 1 |
| 14 | } |
| 15 | |
| 16 | [ -d /tmp/wget2nand-kernel ] && { |
| 17 | echo "/tmp/wget2nand-kernel already exists" |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | # need to find the wget server from the command line |
| 22 | url=$1 |
| 23 | [ -z "$url" ] && { |
| 24 | echo "No URL specified for image TGZ" |
| 25 | echo "Usage : $0 URL" |
| 26 | exit 1 |
| 27 | } |
| 28 | |
| 29 | # first get an address for br-lan using udhcpc |
| 30 | killall udhcpc |
| 31 | /sbin/udhcpc -i br-lan |
| 32 | |
| 33 | mtd_kernel="$(find_mtd_part 'kernel')" |
| 34 | mtd_rootfs="$(find_mtd_part 'rootfs')" |
| 35 | [ -z "$mtd_kernel" -o -z "$mtd_rootfs" ] && { |
| 36 | echo "Cannot find NAND Flash partitions" |
| 37 | exit 1 |
| 38 | } |
| 39 | |
| 40 | echo "Erasing filesystem..." |
| 41 | mtd erase kernel 2>/dev/null >/dev/null |
| 42 | mtd erase rootfs 2>/dev/null >/dev/null |
| 43 | |
| 44 | echo "Mounting $mtd_rootfs as new root and $mtd_kernel as kernel partition" |
| 45 | |
| 46 | mkdir /tmp/wget2nand-rootfs |
| 47 | mkdir /tmp/wget2nand-kernel |
| 48 | mount -t yaffs2 "$mtd_rootfs" /tmp/wget2nand-rootfs |
| 49 | mount -t yaffs2 "$mtd_kernel" /tmp/wget2nand-kernel |
| 50 | |
| 51 | echo "Erasing existing files..." |
| 52 | rm -rf /tmp/wget2nand-rootfs/* |
| 53 | |
| 54 | echo "Copying filesystem..." |
| 55 | ( wget -O - $url/openwrt-adm5120-rb1xx-rootfs.tar.gz) | ( cd /tmp/wget2nand-rootfs/; tar xvz ) |
| 56 | # RouterBOOT is looking for a kernel named "kernel" |
| 57 | wget -O /tmp/wget2nand-kernel/kernel $url/openwrt-adm5120-rb1xx-vmlinux.elf |
| 58 | |
| 59 | chmod +x /tmp/wget2nand-kernel/kernel |
| 60 | |
| 61 | # make sure everything is written before we unmount the partitions |
| 62 | echo "chmod ugo+x /" > /tmp/wget2nand-rootfs/etc/uci-defaults/set_root_permission |
| 63 | sync |
| 64 | ls /tmp/wget2nand-kernel/ |
| 65 | ls /tmp/wget2nand-rootfs/ |
| 66 | # use kexec if present |
| 67 | [ -x /usr/sbin/kexec ] && { |
| 68 | kexec -l /tmp/wget2nand-kernel/kernel --command-line="$(cat /proc/cmdline) rootfstype=yaffs2 root=$mtd_kernel" |
| 69 | kexec -e |
| 70 | } |
| 71 | # unmount the partitions and remove the directories into which they were mounted |
| 72 | umount /tmp/wget2nand-kernel |
| 73 | umount /tmp/wget2nand-rootfs |
| 74 | rmdir /tmp/wget2nand-kernel |
| 75 | rmdir /tmp/wget2nand-rootfs |
| 76 | |
| 77 | # all done |
| 78 | echo "Image written, you can now reboot. Remember to change the boot source to Boot from Nand" |
| 79 | |