platform.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #
  2. # Copyright (C) 2014 OpenWrt.org
  3. #
  4. platform_get_rootfs() {
  5. local rootfsdev
  6. if read cmdline < /proc/cmdline; then
  7. case "$cmdline" in
  8. *block2mtd=*)
  9. rootfsdev="${cmdline##*block2mtd=}"
  10. rootfsdev="${rootfsdev%%,*}"
  11. ;;
  12. *root=*)
  13. rootfsdev="${cmdline##*root=}"
  14. rootfsdev="${rootfsdev%% *}"
  15. ;;
  16. esac
  17. echo "${rootfsdev}"
  18. fi
  19. }
  20. platform_copy_config() {
  21. local board="$(cat /tmp/sysinfo/board_name)"
  22. case "$board" in
  23. erlite)
  24. mount -t vfat /dev/sda1 /mnt
  25. cp -af "$CONF_TAR" /mnt/
  26. umount /mnt
  27. ;;
  28. esac
  29. }
  30. platform_do_flash() {
  31. local tar_file=$1
  32. local board=$2
  33. local kernel=$3
  34. local rootfs=$4
  35. mkdir -p /boot
  36. mount -t vfat /dev/$kernel /boot
  37. [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
  38. mv /boot/vmlinux.64 /boot/vmlinux.64.previous
  39. mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
  40. }
  41. echo "flashing kernel to /dev/$kernel"
  42. tar xf $tar_file sysupgrade-$board/kernel -O > /boot/vmlinux.64
  43. md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
  44. echo "flashing rootfs to ${rootfs}"
  45. tar xf $tar_file sysupgrade-$board/root -O | dd of="${rootfs}" bs=4096
  46. sync
  47. umount /boot
  48. }
  49. platform_do_upgrade() {
  50. local tar_file="$1"
  51. local board=$(cat /tmp/sysinfo/board_name)
  52. local rootfs="$(platform_get_rootfs)"
  53. local kernel=
  54. [ -b "${rootfs}" ] || return 1
  55. case "$board" in
  56. erlite)
  57. kernel=sda1
  58. ;;
  59. er)
  60. kernel=mmcblk0p1
  61. ;;
  62. *)
  63. return 1
  64. esac
  65. platform_do_flash $tar_file $board $kernel $rootfs
  66. return 0
  67. }
  68. platform_check_image() {
  69. local board=$(cat /tmp/sysinfo/board_name)
  70. case "$board" in
  71. erlite | \
  72. er)
  73. local tar_file="$1"
  74. local kernel_length=`(tar xf $tar_file sysupgrade-$board/kernel -O | wc -c) 2> /dev/null`
  75. local rootfs_length=`(tar xf $tar_file sysupgrade-$board/root -O | wc -c) 2> /dev/null`
  76. [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
  77. echo "The upgarde image is corrupt."
  78. return 1
  79. }
  80. return 0
  81. ;;
  82. esac
  83. echo "Sysupgrade is not yet supported on $board."
  84. return 1
  85. }