merakinand.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2016 Chris Blake <chrisrblake93@gmail.com>
  4. #
  5. # Custom upgrade script for Meraki NAND devices (ex. MR24)
  6. # Based on merakinand.sh from the ar71xx target
  7. #
  8. . /lib/apm821xx.sh
  9. . /lib/functions.sh
  10. merakinand_do_kernel_check() {
  11. local board_name="$1"
  12. local tar_file="$2"
  13. local image_magic_word=`(tar xf $tar_file sysupgrade-$board_name/kernel -O 2>/dev/null | dd bs=1 count=4 skip=0 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')`
  14. # What is our kernel magic string?
  15. case "$board_name" in
  16. "mr24"|\
  17. "mx60")
  18. [ "$image_magic_word" == "8e73ed8a" ] && {
  19. echo "pass" && return 0
  20. }
  21. ;;
  22. esac
  23. exit 1
  24. }
  25. merakinand_do_platform_check() {
  26. local board_name="$1"
  27. local tar_file="$2"
  28. local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
  29. local file_type="$(identify_tar $2 sysupgrade-$board_name/root)"
  30. local kernel_magic="$(merakinand_do_kernel_check $1 $2)"
  31. case "$board_name" in
  32. "mr24"|\
  33. "mx60")
  34. [ "$control_length" = 0 -o "$file_type" != "squashfs" -o "$kernel_magic" != "pass" ] && {
  35. echo "Invalid sysupgrade file for $board_name"
  36. return 1
  37. }
  38. ;;
  39. *)
  40. echo "Unsupported device $board_name";
  41. return 1
  42. ;;
  43. esac
  44. return 0
  45. }
  46. merakinand_do_upgrade() {
  47. local tar_file="$1"
  48. local board_name="$(cat /tmp/sysinfo/board_name)"
  49. # Do we need to do any platform tweaks?
  50. case "$board_name" in
  51. "mr24"|\
  52. "mx60")
  53. nand_do_upgrade $1
  54. ;;
  55. *)
  56. echo "Unsupported device $board_name";
  57. exit 1
  58. ;;
  59. esac
  60. }