platform.sh 1.5 KB

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