platform.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. platform_check_image() {
  2. true
  3. }
  4. platform_copy_config() {
  5. local partdev
  6. if export_partdevice partdev -1; then
  7. mount -t vfat -o rw,noatime "/dev/$partdev" /mnt
  8. cp -af "$CONF_TAR" /mnt/
  9. umount /mnt
  10. fi
  11. }
  12. platform_do_upgrade() {
  13. local diskdev partdev ibs diff
  14. if export_bootdevice && export_partdevice diskdev -2; then
  15. sync
  16. if [ "$SAVE_PARTITIONS" = "1" ]; then
  17. get_partitions "/dev/$diskdev" bootdisk
  18. #get block size
  19. if [ -f "/sys/block/$diskdev/queue/physical_block_size" ]; then
  20. ibs="$(cat "/sys/block/$diskdev/queue/physical_block_size")"
  21. else
  22. ibs=512
  23. fi
  24. #extract the boot sector from the image
  25. get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  26. get_partitions /tmp/image.bs image
  27. #compare tables
  28. diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  29. if [ -n "$diff" ]; then
  30. echo "Partition layout is changed. Full image will be written."
  31. ask_bool 0 "Abort" && exit
  32. get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  33. return 0
  34. fi
  35. #write uboot image
  36. get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 conv=notrunc
  37. #iterate over each partition from the image and write it to the boot disk
  38. while read part start size; do
  39. part="$(($part - 2))"
  40. if export_partdevice partdev $part; then
  41. echo "Writing image to /dev/$partdev..."
  42. get_image "$@" | dd of="/dev/$partdev" ibs="$ibs" obs=1M skip="$start" count="$size" conv=fsync
  43. else
  44. echo "Unable to find partition $part device, skipped."
  45. fi
  46. done < /tmp/partmap.image
  47. #copy partition uuid
  48. echo "Writing new UUID to /dev/$diskdev..."
  49. get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  50. else
  51. get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  52. fi
  53. sleep 1
  54. fi
  55. }