wget2nand 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. wget2nand_dir=/tmp/wget2nand
  11. mnt_kernel=$wget2nand_dir/mnt_kernel
  12. mnt_rootfs=$wget2nand_dir/mnt_rootfs
  13. src_rootfs=$wget2nand_dir/rootfs.tgz
  14. src_kernel=$wget2nand_dir/kernel
  15. [ -d "$wget2nand_dir" ] && {
  16. echo "$wget2nand_dir already exists"
  17. exit 1
  18. }
  19. # need to find the wget server from the command line
  20. url=$1
  21. [ -z "$url" ] && {
  22. echo "No URL specified for image TGZ"
  23. echo "Usage : $0 URL"
  24. exit 1
  25. }
  26. url_kernel=$url/openwrt-ar71xx-mikrotik-vmlinux-lzma.elf
  27. url_rootfs=$url/openwrt-ar71xx-mikrotik-rootfs.tar.gz
  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. mkdir "$wget2nand_dir"
  35. wget $url_kernel -O "$src_kernel" || {
  36. echo "Unable to download $url_kernel"
  37. exit 1
  38. }
  39. wget $url_rootfs -O "$src_rootfs" || {
  40. echo "Unable to download $url_rootfs"
  41. exit 1
  42. }
  43. echo "Erasing filesystem..."
  44. mtd erase kernel 2>/dev/null >/dev/null
  45. mtd erase rootfs 2>/dev/null >/dev/null
  46. echo "Mounting $mtd_rootfs as new root and $mtd_kernel as kernel partition"
  47. mkdir "$mnt_kernel"
  48. mkdir "$mnt_rootfs"
  49. mount -t yaffs2 "$mtd_kernel" "$mnt_kernel"
  50. mount -t yaffs2 "$mtd_rootfs" "$mnt_rootfs"
  51. echo "Copying kernel..."
  52. cp $src_kernel $mnt_kernel/kernel || {
  53. echo "Error occured while copying the kernel"
  54. exit 1
  55. }
  56. chmod +x $mnt_kernel/kernel
  57. echo "Preparing filesystem..."
  58. ( cd "$mnt_rootfs"; tar xvz -f "$src_rootfs" )
  59. # make sure everything is written before we unmount the partitions
  60. echo "chmod ugo+x /" > $mnt_rootfs/etc/uci-defaults/set_root_permission
  61. sync
  62. ls $mnt_kernel >/dev/null
  63. ls $mnt_rootfs >/dev/null
  64. echo "Cleaning up..."
  65. # unmount the partitions and remove the directories into which they were mounted
  66. umount $mnt_kernel
  67. umount $mnt_rootfs
  68. rm -rf $wget2nand_dir
  69. # all done
  70. echo "Image written, you can now reboot. Remember to change the boot source to Boot from Nand"