3 local diskdev partdev
diff
5 export_bootdevice
&& export_partdevice diskdev
0 ||
{
6 v
"Unable to determine upgrade device"
10 get_partitions
"/dev/$diskdev" bootdisk
12 v
"Extract boot sector from the image"
13 get_image_dd
"$1" of
=/tmp
/image.bs count
=1 bs
=512b
15 get_partitions
/tmp
/image.bs image
18 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
20 rm -f /tmp
/image.bs
/tmp
/partmap.bootdisk
/tmp
/partmap.image
22 if [ -n "$diff" ]; then
23 v
"Partition layout has changed. Full image will be written."
24 ask_bool
0 "Abort" && exit 1
30 local board
=$
(board_name
)
31 local diskdev partdev
diff
33 export_bootdevice
&& export_partdevice diskdev
0 ||
{
34 v
"Unable to determine upgrade device"
40 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
41 get_partitions
"/dev/$diskdev" bootdisk
43 v
"Extract boot sector from the image"
44 get_image_dd
"$1" of
=/tmp
/image.bs count
=1 bs
=512b
46 get_partitions
/tmp
/image.bs image
49 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
54 if [ -n "$diff" ]; then
55 get_image_dd
"$1" of
="/dev/$diskdev" bs
=4096 conv
=fsync
57 # Separate removal and addtion is necessary; otherwise, partition 1
58 # will be missing if it overlaps with the old partition 2
59 partx
-d - "/dev/$diskdev"
60 partx
-a - "/dev/$diskdev"
62 v
"Writing bootloader to /dev/$diskdev"
63 get_image_dd
"$1" of
="$diskdev" bs
=512 skip
=1 seek
=1 count
=2048 conv
=fsync
64 #iterate over each partition from the image and write it to the boot disk
65 while read part start size
; do
66 if export_partdevice partdev
$part; then
67 v
"Writing image to /dev/$partdev..."
68 get_image_dd
"$1" of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
70 v
"Unable to find partition $part device, skipped."
72 done < /tmp
/partmap.image
74 v
"Writing new UUID to /dev/$diskdev..."
75 get_image_dd
"$1" of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
81 sdcard_copy_config
() {
84 if export_partdevice partdev
1; then
86 [ -f /boot
/kernel.img
] || mount
-o rw
,noatime
/dev
/$partdev /boot
87 cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"