3 REQUIRE_IMAGE_METADATA
=1
5 # copied from x86's platform.sh
7 platform_check_image
() {
8 local diskdev partdev
diff
10 [ "$#" -gt 1 ] && return 1
12 export_bootdevice
&& export_partdevice diskdev
0 ||
{
13 echo "Unable to determine upgrade device"
17 get_partitions
"/dev/$diskdev" bootdisk
19 #extract the boot sector from the image
20 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
2>/dev
/null
22 get_partitions
/tmp
/image.bs image
25 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
27 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
29 if [ -n "$diff" ]; then
30 echo "Partition layout has changed. Full image will be written."
31 ask_bool
0 "Abort" && exit 1
38 platform_do_upgrade
() {
39 local diskdev partdev
diff
41 export_bootdevice
&& export_partdevice diskdev
0 ||
{
42 echo "Unable to determine upgrade device"
48 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
49 get_partitions
"/dev/$diskdev" bootdisk
51 #extract the boot sector from the image
52 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
54 get_partitions
/tmp
/image.bs image
57 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
62 if [ -n "$diff" ]; then
63 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=2M conv
=fsync
65 # Separate removal and addtion is necessary; otherwise, partition 1
66 # will be missing if it overlaps with the old partition 2
67 partx
-d - "/dev/$diskdev"
68 partx
-a - "/dev/$diskdev"
73 #iterate over each partition from the image and write it to the boot disk
74 while read part start size
; do
75 if export_partdevice partdev
$part; then
76 echo "Writing image to /dev/$partdev..."
77 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
79 echo "Unable to find partition $part device, skipped."
81 done < /tmp
/partmap.image
84 echo "Writing new UUID to /dev/$diskdev..."
85 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
88 platform_copy_config
() {
91 if export_partdevice partdev
1; then
93 [ -f /boot
/kernel.img
] || mount
-t vfat
-o rw
,noatime
"/dev/$partdev" /boot
94 cp -af "$CONF_TAR" "/boot/$BACKUP_FILE"
95 tar -C / -zxvf "$CONF_TAR" boot
/config.txt