platform.sh 2.0 KB

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