0086-x86-make-sysupgrade-work-without-partx.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From: Jo-Philipp Wich <jo@mein.io>
  2. Date: Wed, 30 Mar 2016 03:10:51 +0200
  3. Subject: x86: make sysupgrade work without partx
  4. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  5. Backport of LEDE 9f422eba7c1a297a96a03b1cce05fa3cb9d71a4a
  6. diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
  7. index c21f1a7e5feba553110f138c14977daaa472da70..f12deebf6484df6f3f69e453ad67688a76d57972 100644
  8. --- a/target/linux/x86/base-files/lib/upgrade/platform.sh
  9. +++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
  10. @@ -61,7 +61,27 @@ get_partitions() { # <device> <filename>
  11. if [ -b "$disk" -o -f "$disk" ]; then
  12. echo "Reading partition table from $filename..."
  13. - partx -r "$disk" -gbo NR,START,SECTORS > "/tmp/partx.$filename"
  14. +
  15. + local magic="$(hexdump -v -n 2 -s 0x1FE -e '1/2 "0x%04X"' "$disk")"
  16. + if [ "$magic" != 0xAA55 ]; then
  17. + echo "Invalid partition table on $disk"
  18. + exit
  19. + fi
  20. +
  21. + rm -f "/tmp/partmap.$filename"
  22. +
  23. + local part
  24. + for part in 1 2 3 4; do
  25. + set -- $(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk")
  26. +
  27. + local type="$(($1 % 256))"
  28. + local lba="$(($2))"
  29. + local num="$(($3))"
  30. +
  31. + [ $type -gt 0 ] || continue
  32. +
  33. + printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename"
  34. + done
  35. fi
  36. }
  37. @@ -76,9 +96,11 @@ platform_do_upgrade() {
  38. #get block size
  39. - sectors="$(partx -r $disk -gbo SECTORS --nr 1:1)"
  40. - size="$(partx -r $disk -gbo SIZE --nr 1:1)"
  41. - ibs="$(($size / $sectors))"
  42. + if [ -f "/sys/block/${disk##*/}/queue/physical_block_size" ]; then
  43. + ibs="$(cat "/sys/block/${disk##*/}/queue/physical_block_size")"
  44. + else
  45. + ibs=512
  46. + fi
  47. #extract the boot sector from the image
  48. get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  49. @@ -86,7 +108,7 @@ platform_do_upgrade() {
  50. get_partitions /tmp/image.bs image
  51. #compare tables
  52. - diff="$(grep -F -x -v -f /tmp/partx.bootdisk /tmp/partx.image)"
  53. + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  54. if [ -n "$diff" ]; then
  55. echo "Partition layout is changed. Full image will be written."
  56. ask_bool 0 "Abort" && exit
  57. @@ -99,7 +121,7 @@ platform_do_upgrade() {
  58. while read part start size; do
  59. echo "Writing image to $disk$part..."
  60. get_image "$@" | dd of="$disk$part" ibs="$ibs" obs=1M skip="$start" count="$size" conv=fsync
  61. - done < /tmp/partx.image
  62. + done < /tmp/partmap.image
  63. #copy partition uuid
  64. echo "Writing new UUID to $disk$part..."