wget2nand 2.3 KB

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