0026-sunxi-sysupgrade-sync-with-x86.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Thu, 4 May 2017 07:39:20 +0200
  3. Subject: sunxi: sysupgrade: sync with x86
  4. sunxi sysupgrade was based on the x86 implementation; sync fixes and other
  5. changes from the current x86 version:
  6. x86: fix sysupgrades on disks with 4k block size
  7. x86: sysupgrade: move partition table change check to platform_check_image
  8. x86: sysupgrade: refactor platform_do_upgrade
  9. x86: sysupgrade: explicitly rescan disk after writing partition table
  10. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  11. diff --git a/target/linux/sunxi/Makefile b/target/linux/sunxi/Makefile
  12. index 3c2f14b8418e1d296a239027f6fdee9b5ba8f9b2..f8b8aa750a7145c9954df5a5a6a2e85f2610a72f 100644
  13. --- a/target/linux/sunxi/Makefile
  14. +++ b/target/linux/sunxi/Makefile
  15. @@ -28,6 +28,6 @@ KERNELNAME:=zImage dtbs
  16. include $(INCLUDE_DIR)/target.mk
  17. DEFAULT_PACKAGES += uboot-envtools
  18. -DEFAULT_PACKAGES += mkf2fs e2fsprogs
  19. +DEFAULT_PACKAGES += partx-utils mkf2fs e2fsprogs
  20. $(eval $(call BuildTarget))
  21. diff --git a/target/linux/sunxi/base-files/lib/upgrade/platform.sh b/target/linux/sunxi/base-files/lib/upgrade/platform.sh
  22. index 776bdf53bf89c5eafc24b7b59b943e12f3fab77e..88ef4790e9c1452f8ce57fe1c265ce47810830ee 100644
  23. --- a/target/linux/sunxi/base-files/lib/upgrade/platform.sh
  24. +++ b/target/linux/sunxi/base-files/lib/upgrade/platform.sh
  25. @@ -1,5 +1,28 @@
  26. platform_check_image() {
  27. - true
  28. + local diskdev partdev diff
  29. +
  30. + export_bootdevice && export_partdevice diskdev -2 || {
  31. + echo "Unable to determine upgrade device"
  32. + return 1
  33. + }
  34. +
  35. + get_partitions "/dev/$diskdev" bootdisk
  36. +
  37. + #extract the boot sector from the image
  38. + get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
  39. +
  40. + get_partitions /tmp/image.bs image
  41. +
  42. + #compare tables
  43. + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  44. +
  45. + rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
  46. +
  47. + if [ -n "$diff" ]; then
  48. + echo "Partition layout has changed. Full image will be written."
  49. + ask_bool 0 "Abort" && exit 1
  50. + return 0
  51. + fi
  52. }
  53. platform_copy_config() {
  54. @@ -13,55 +36,54 @@ platform_copy_config() {
  55. }
  56. platform_do_upgrade() {
  57. - local diskdev partdev ibs diff
  58. -
  59. - if export_bootdevice && export_partdevice diskdev -2; then
  60. - sync
  61. - if [ "$SAVE_PARTITIONS" = "1" ]; then
  62. - get_partitions "/dev/$diskdev" bootdisk
  63. -
  64. - #get block size
  65. - if [ -f "/sys/block/$diskdev/queue/physical_block_size" ]; then
  66. - ibs="$(cat "/sys/block/$diskdev/queue/physical_block_size")"
  67. - else
  68. - ibs=512
  69. - fi
  70. -
  71. - #extract the boot sector from the image
  72. - get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  73. -
  74. - get_partitions /tmp/image.bs image
  75. -
  76. - #compare tables
  77. - diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  78. - if [ -n "$diff" ]; then
  79. - echo "Partition layout is changed. Full image will be written."
  80. - ask_bool 0 "Abort" && exit
  81. -
  82. - get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  83. - return 0
  84. - fi
  85. -
  86. - #write uboot image
  87. - get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 count=1016 conv=fsync
  88. - #iterate over each partition from the image and write it to the boot disk
  89. - while read part start size; do
  90. - part="$(($part - 2))"
  91. - if export_partdevice partdev $part; then
  92. - echo "Writing image to /dev/$partdev..."
  93. - get_image "$@" | dd of="/dev/$partdev" ibs="$ibs" obs=1M skip="$start" count="$size" conv=fsync
  94. - else
  95. - echo "Unable to find partition $part device, skipped."
  96. - fi
  97. - done < /tmp/partmap.image
  98. -
  99. - #copy partition uuid
  100. - echo "Writing new UUID to /dev/$diskdev..."
  101. - get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  102. + local diskdev partdev diff
  103. +
  104. + export_bootdevice && export_partdevice diskdev -2 || {
  105. + echo "Unable to determine upgrade device"
  106. + return 1
  107. + }
  108. +
  109. + sync
  110. +
  111. + if [ "$SAVE_PARTITIONS" = "1" ]; then
  112. + get_partitions "/dev/$diskdev" bootdisk
  113. +
  114. + #extract the boot sector from the image
  115. + get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  116. +
  117. + get_partitions /tmp/image.bs image
  118. +
  119. + #compare tables
  120. + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  121. + else
  122. + diff=1
  123. + fi
  124. +
  125. + if [ -n "$diff" ]; then
  126. + get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  127. +
  128. + # Separate removal and addtion is necessary; otherwise, partition 1
  129. + # will be missing if it overlaps with the old partition 2
  130. + partx -d - "/dev/$diskdev"
  131. + partx -a - "/dev/$diskdev"
  132. +
  133. + return 0
  134. + fi
  135. +
  136. + #write uboot image
  137. + get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 count=1016 conv=fsync
  138. + #iterate over each partition from the image and write it to the boot disk
  139. + while read part start size; do
  140. + part="$(($part - 2))"
  141. + if export_partdevice partdev $part; then
  142. + echo "Writing image to /dev/$partdev..."
  143. + get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
  144. else
  145. - get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  146. + echo "Unable to find partition $part device, skipped."
  147. fi
  148. + done < /tmp/partmap.image
  149. - sleep 1
  150. - fi
  151. + #copy partition uuid
  152. + echo "Writing new UUID to /dev/$diskdev..."
  153. + get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  154. }