0022-x86-sysupgrade-refactor-platform_do_upgrade.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Wed, 3 May 2017 09:05:25 +0200
  3. Subject: x86: sysupgrade: refactor platform_do_upgrade
  4. By returning early when no upgrade device can be found and handling the
  5. SAVE_PARTITIONS=0 case differently, we can get rid of two levels of if.
  6. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  7. diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
  8. index 81b349a81816033eef9df464b2a70fdb998e5a1d..4fa71999be7be3972676a1019488972dccd57fa2 100644
  9. --- a/target/linux/x86/base-files/lib/upgrade/platform.sh
  10. +++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
  11. @@ -47,40 +47,43 @@ platform_copy_config() {
  12. platform_do_upgrade() {
  13. local diskdev partdev diff
  14. - if export_bootdevice && export_partdevice diskdev 0; then
  15. - sync
  16. - if [ "$SAVE_PARTITIONS" = "1" ]; then
  17. - get_partitions "/dev/$diskdev" bootdisk
  18. -
  19. - #extract the boot sector from the image
  20. - get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  21. -
  22. - get_partitions /tmp/image.bs image
  23. -
  24. - #compare tables
  25. - diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  26. - if [ -n "$diff" ]; then
  27. - get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  28. - return 0
  29. - fi
  30. -
  31. - #iterate over each partition from the image and write it to the boot disk
  32. - while read part start size; do
  33. - if export_partdevice partdev $part; then
  34. - echo "Writing image to /dev/$partdev..."
  35. - get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
  36. - else
  37. - echo "Unable to find partition $part device, skipped."
  38. - fi
  39. - done < /tmp/partmap.image
  40. -
  41. - #copy partition uuid
  42. - echo "Writing new UUID to /dev/$diskdev..."
  43. - get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  44. + export_bootdevice && export_partdevice diskdev 0 || {
  45. + echo "Unable to determine upgrade device"
  46. + return 1
  47. + }
  48. +
  49. + sync
  50. +
  51. + if [ "$SAVE_PARTITIONS" = "1" ]; then
  52. + get_partitions "/dev/$diskdev" bootdisk
  53. +
  54. + #extract the boot sector from the image
  55. + get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  56. +
  57. + get_partitions /tmp/image.bs image
  58. +
  59. + #compare tables
  60. + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  61. + else
  62. + diff=1
  63. + fi
  64. +
  65. + if [ -n "$diff" ]; then
  66. + get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  67. + return 0
  68. + fi
  69. +
  70. + #iterate over each partition from the image and write it to the boot disk
  71. + while read part start size; do
  72. + if export_partdevice partdev $part; then
  73. + echo "Writing image to /dev/$partdev..."
  74. + get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
  75. else
  76. - get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  77. + echo "Unable to find partition $part device, skipped."
  78. fi
  79. + done < /tmp/partmap.image
  80. - sleep 1
  81. - fi
  82. + #copy partition uuid
  83. + echo "Writing new UUID to /dev/$diskdev..."
  84. + get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  85. }