platform.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. platform_export_bootpart() {
  2. local cmdline uuid disk
  3. if read cmdline < /proc/cmdline; then
  4. case "$cmdline" in
  5. *block2mtd=*)
  6. disk="${cmdline##*block2mtd=}"
  7. disk="${disk%%,*}"
  8. ;;
  9. *root=*)
  10. disk="${cmdline##*root=}"
  11. disk="${disk%% *}"
  12. ;;
  13. esac
  14. case "$disk" in
  15. PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-02)
  16. uuid="${disk#PARTUUID=}"
  17. uuid="${uuid%-02}"
  18. for disk in /dev/[hsv]d[a-z]; do
  19. set -- $(dd if=$disk bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
  20. if [ "$4$3$2$1" = "$uuid" ]; then
  21. export BOOTPART="${disk}1"
  22. return 0
  23. fi
  24. done
  25. ;;
  26. /dev/*)
  27. export BOOTPART="${disk%[0-9]}1"
  28. return 0
  29. ;;
  30. esac
  31. fi
  32. return 1
  33. }
  34. platform_check_image() {
  35. [ "$#" -gt 1 ] && return 1
  36. case "$(get_magic_word "$1")" in
  37. eb48|eb63) return 0;;
  38. *)
  39. echo "Invalid image type"
  40. return 1
  41. ;;
  42. esac
  43. }
  44. platform_copy_config() {
  45. if [ -b "$BOOTPART" ]; then
  46. mount -t ext4 -o rw,noatime "$BOOTPART" /mnt
  47. cp -af "$CONF_TAR" /mnt/
  48. umount /mnt
  49. fi
  50. }
  51. platform_do_upgrade() {
  52. platform_export_bootpart
  53. if [ -b "${BOOTPART%[0-9]}" ]; then
  54. sync
  55. get_image "$@" | dd of="${BOOTPART%[0-9]}" bs=4096 conv=fsync
  56. sleep 1
  57. fi
  58. }