platform.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # Copyright (C) 2011 OpenWrt.org
  3. #
  4. PART_NAME=firmware
  5. get_magic_long_at() {
  6. (get_image "$1" | dd bs=4 count=1 skip="$2" | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
  7. }
  8. tplink_get_hwid() {
  9. local part
  10. part=$(find_mtd_part u-boot)
  11. [ -z "$part" ] && return 1
  12. dd if=$part bs=4 count=1 skip=81728 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  13. }
  14. tplink_get_image_hwid() {
  15. get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  16. }
  17. tplink_get_image_boot_size() {
  18. get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  19. }
  20. platform_check_image() {
  21. local board=$(board_name)
  22. local magic="$(get_magic_long "$1")"
  23. [ "$#" -gt 1 ] && return 1
  24. case $board in
  25. aerohive,hiveap-330)
  26. local init_magic=$(get_magic_long_at "$1" "65536")
  27. local root_magic=$(get_magic_long_at "$1" "131072")
  28. local kernel_magic=$(get_magic_long_at "$1" "10551296")
  29. [ "$magic" != "d00dfeed" ] && {
  30. echo "Invalid dtb image type."
  31. return 1
  32. }
  33. [ "$init_magic" != "27051956" ] && {
  34. echo "Invalid initramfs image type."
  35. return 1
  36. }
  37. [ "$root_magic" != "68737173" ] && {
  38. echo "Invalid rootfs image type."
  39. return 1
  40. }
  41. [ "$kernel_magic" != "27051956" ] && {
  42. echo "Invalid kernel image type."
  43. return 1
  44. }
  45. return 0
  46. ;;
  47. tplink,tl-wdr4900-v1)
  48. [ "$magic" != "01000000" ] && {
  49. echo "Invalid image type."
  50. return 1
  51. }
  52. local hwid
  53. local imageid
  54. hwid=$(tplink_get_hwid)
  55. imageid=$(tplink_get_image_hwid "$1")
  56. [ "$hwid" != "$imageid" ] && {
  57. echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
  58. return 1
  59. }
  60. local boot_size
  61. boot_size=$(tplink_get_image_boot_size "$1")
  62. [ "$boot_size" != "00000000" ] && {
  63. echo "Invalid image, it contains a bootloader."
  64. return 1
  65. }
  66. return 0
  67. ;;
  68. esac
  69. echo "Sysupgrade is not yet supported on $board."
  70. return 1
  71. }
  72. platform_do_upgrade() {
  73. local board=$(board_name)
  74. case "$board" in
  75. *)
  76. default_do_upgrade "$ARGV"
  77. ;;
  78. esac
  79. }
  80. disable_watchdog() {
  81. killall watchdog
  82. ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
  83. echo 'Could not disable watchdog'
  84. return 1
  85. }
  86. }
  87. append sysupgrade_pre_upgrade disable_watchdog