sockit.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Copyright (C) 2014-2015 OpenWrt.org
  3. #
  4. BOOTPART=/dev/mmcblk0p2
  5. CFGPART=/dev/mmcblk0p3
  6. identify_magic() {
  7. local magic=$1
  8. case "$magic" in
  9. "55424923")
  10. echo "ubi"
  11. ;;
  12. "31181006")
  13. echo "ubifs"
  14. ;;
  15. "68737173")
  16. echo "squashfs"
  17. ;;
  18. "d00dfeed")
  19. echo "fit"
  20. ;;
  21. "00000000")
  22. echo "ext4"
  23. ;;
  24. "4349"*)
  25. echo "combined"
  26. ;;
  27. *)
  28. echo "unknown $magic"
  29. ;;
  30. esac
  31. }
  32. get_magic_long_tar() {
  33. ( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
  34. }
  35. identify_tar() {
  36. identify_magic $(get_magic_long_tar "$1" "$2")
  37. }
  38. platform_do_check_sockit() {
  39. local board=$(socfpga_board_name)
  40. local magic_long="$(get_magic_long "$1")"
  41. echo "magic = $magic_long"
  42. if [ "$magic_long" = "73797375" ] ; then
  43. local rootfs_type="$(identify_tar "$1" sysupgrade-$board/root)"
  44. if [ "$rootfs_type" = "ubifs" ] ; then
  45. nand_do_platform_check $board $1
  46. return 0;
  47. fi
  48. [ "$rootfs_type" = "ext4" ] && return 0
  49. echo "Unknown rootfs type $rootfs_type !"
  50. fi
  51. return 1
  52. }
  53. platform_do_upgrade_sockit() {
  54. local board=$(socfpga_board_name)
  55. local magic_long="$(get_magic_long "$1")"
  56. echo "magic = $magic_long"
  57. if [ "$magic_long" = "73797375" ] ; then
  58. local rootfs_type="$(identify_tar "$1" sysupgrade-$board/root)"
  59. if [ "$rootfs_type" = "ext4" ] ; then
  60. sync
  61. tar xf "$1" sysupgrade-$board/root -O | \
  62. dd of="$BOOTPART" bs=512 conv=fsync
  63. return 0
  64. fi
  65. echo "Unknown rootfs type $rootfs_type !"
  66. fi
  67. return 1
  68. }
  69. platform_copy_config() {
  70. if [ -b "$CFGPART" ]; then
  71. mount -o rw,noatime "$CFGPART" /mnt
  72. cp -af "$CONF_TAR" /mnt/
  73. umount /mnt
  74. fi
  75. }