platform.sh 4.0 KB

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