platform.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Copyright (C) 2011 OpenWrt.org
  3. #
  4. PART_NAME=firmware
  5. tplink_get_hwid() {
  6. local part
  7. part=$(find_mtd_part u-boot)
  8. [ -z "$part" ] && return 1
  9. dd if=$part bs=4 count=1 skip=81728 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  10. }
  11. tplink_get_image_hwid() {
  12. get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  13. }
  14. tplink_get_image_boot_size() {
  15. get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  16. }
  17. platform_check_image() {
  18. local board=$(board_name)
  19. local magic="$(get_magic_long "$1")"
  20. [ "$#" -gt 1 ] && return 1
  21. case $board in
  22. tl-wdr4900-v1)
  23. [ "$magic" != "01000000" ] && {
  24. echo "Invalid image type."
  25. return 1
  26. }
  27. local hwid
  28. local imageid
  29. hwid=$(tplink_get_hwid)
  30. imageid=$(tplink_get_image_hwid "$1")
  31. [ "$hwid" != "$imageid" ] && {
  32. echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
  33. return 1
  34. }
  35. local boot_size
  36. boot_size=$(tplink_get_image_boot_size "$1")
  37. [ "$boot_size" != "00000000" ] && {
  38. echo "Invalid image, it contains a bootloader."
  39. return 1
  40. }
  41. return 0
  42. ;;
  43. esac
  44. echo "Sysupgrade is not yet supported on $board."
  45. return 1
  46. }
  47. platform_do_upgrade() {
  48. local board=$(board_name)
  49. case "$board" in
  50. *)
  51. default_do_upgrade "$ARGV"
  52. ;;
  53. esac
  54. }
  55. disable_watchdog() {
  56. killall watchdog
  57. ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
  58. echo 'Could not disable watchdog'
  59. return 1
  60. }
  61. }
  62. append sysupgrade_pre_upgrade disable_watchdog