wget2nand 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. [ -d /tmp/wget2nand ] && {
  11. echo "/tmp/wget2nand already exists"
  12. exit 1
  13. }
  14. # first get an address for br-lan using udhcpc
  15. killall udhcpc
  16. /sbin/udhcpc -i br-lan
  17. # need to find the wget server from the command line
  18. url=$1
  19. [ -z "$url" ] && {
  20. echo "No URL specified for image TGZ"
  21. echo "Usage : $0 URL"
  22. exit 1
  23. }
  24. boot="$(find_mtd_part 'Routerboard NAND Boot')"
  25. main="$(find_mtd_part 'rootfs')"
  26. [ -z "$boot" -o -z "$main" ] && {
  27. echo "Cannot find NAND Flash partitions"
  28. exit 1
  29. }
  30. echo "Erasing filesystem."
  31. mtd erase Boot 2>/dev/null >/dev/null
  32. mtd erase Main 2>/dev/null >/dev/null
  33. echo "Mounting $main as new root and $boot as boot partition"
  34. mkdir /tmp/wget2nand/
  35. mkdir /tmp/wget2nand-boot
  36. mount -t yaffs2 "$main" /tmp/wget2nand/
  37. mount -t yaffs2 "$boot" /tmp/wget2nand-boot
  38. echo "Copying filesystem..."
  39. ( wget -O - $url/openwrt-rb532-rootfs.tgz) | ( cd /tmp/wget2nand/; tar xvz )
  40. wget -O /tmp/wget2nand-boot/kernel $url/openwrt-rb532-vmlinux
  41. # No need to patch the kernel, this was done during the build process
  42. chmod +x /tmp/wget2nand-boot/kernel
  43. # make sure everything is written before we unmount the partitions
  44. echo "chmod ugo+x /" > /tmp/wget2nand/etc/uci-defaults/set_root_permission
  45. sync
  46. ls /tmp/wget2nand-boot/
  47. ls /tmp/wget2nand/
  48. # use kexec if present
  49. [ -x /usr/bin/kexec ] && {
  50. kexec -l /tmp/wget2nand-boot/kernel --command-line="$(cat /proc/cmdline) root=$main rootfstype=yaffs2"
  51. kexec -e
  52. }
  53. # unmount the partitions and remove the directories into which they were mounted
  54. umount /tmp/wget2nand-boot
  55. umount /tmp/wget2nand
  56. rmdir /tmp/wget2nand-boot
  57. rmdir /tmp/wget2nand
  58. # all done
  59. echo "Image written, you can now reboot. Remember to change the boot source to Boot from Nand"