platform.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. . /lib/cns3xxx.sh
  2. RAMFS_COPY_DATA="/lib/cns3xxx.sh"
  3. CI_BLKSZ=65536
  4. platform_find_partitions() {
  5. local first dev size erasesize name
  6. while read dev size erasesize name; do
  7. name=${name#'"'}; name=${name%'"'}
  8. case "$name" in
  9. vmlinux.bin.l7|kernel|linux|rootfs)
  10. if [ -z "$first" ]; then
  11. first="$name"
  12. else
  13. echo "$erasesize:$first:$name"
  14. break
  15. fi
  16. ;;
  17. esac
  18. done < /proc/mtd
  19. }
  20. platform_find_kernelpart() {
  21. local part
  22. for part in "${1%:*}" "${1#*:}"; do
  23. case "$part" in
  24. vmlinux.bin.l7|kernel|linux)
  25. echo "$part"
  26. break
  27. ;;
  28. esac
  29. done
  30. }
  31. platform_do_upgrade_combined() {
  32. local partitions=$(platform_find_partitions)
  33. local kernelpart=$(platform_find_kernelpart "${partitions#*:}")
  34. local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}"
  35. local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
  36. local kern_blocks=$(($kern_length / $CI_BLKSZ))
  37. local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ))
  38. v "platform_do_upgrade_combined"
  39. v "partitions=$partitions"
  40. v "kernelpart=$kernelpart"
  41. v "erase_size=$erase_size"
  42. v "kern_blocks=$kern_blocks"
  43. v "root_blocks=$root_blocks"
  44. if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
  45. [ ${kern_blocks:-0} -gt 0 ] && \
  46. [ ${root_blocks:-0} -gt 0 ] && \
  47. [ ${erase_size:-0} -gt 0 ];
  48. then
  49. local append=""
  50. [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
  51. dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null | mtd write - kernel
  52. dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null | \
  53. mtd -r $append write - rootfs
  54. else
  55. echo "invalid image"
  56. fi
  57. }
  58. platform_check_image() {
  59. local board=$(cns3xxx_board_name)
  60. local magic="$(get_magic_word "$1")"
  61. local magic_long="$(get_magic_long "$1")"
  62. [ "$#" -gt 1 ] && return 1
  63. case "$board" in
  64. laguna)
  65. [ "$magic" != "4349" ] && {
  66. echo "Invalid image. Use *-sysupgrade.bin files on this board"
  67. return 1
  68. }
  69. local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
  70. local md5_chk=$(dd if="$1" bs=$CI_BLKSZ skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
  71. if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
  72. return 0
  73. else
  74. echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
  75. return 1
  76. fi
  77. return 0
  78. ;;
  79. esac
  80. echo "Sysupgrade is not yet supported on $board."
  81. return 1
  82. }
  83. platform_do_upgrade() {
  84. local board=$(cns3xxx_board_name)
  85. v "board=$board"
  86. case "$board" in
  87. laguna)
  88. platform_do_upgrade_combined "$ARGV"
  89. ;;
  90. *)
  91. default_do_upgrade "$ARGV"
  92. ;;
  93. esac
  94. }
  95. disable_watchdog() {
  96. v "killing watchdog"
  97. killall watchdog
  98. ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
  99. echo 'Could not disable watchdog'
  100. return 1
  101. }
  102. }
  103. # CONFIG_WATCHDOG_NOWAYOUT=y - can't kill watchdog unless kernel cmdline has a mpcore_wdt.nowayout=0
  104. #append sysupgrade_pre_upgrade disable_watchdog