1 platform_check_image_sdcard
() {
3 local diskdev partdev
diff
5 export_bootdevice
&& export_partdevice diskdev
0 ||
{
6 echo "Unable to determine upgrade device"
10 get_partitions
"/dev/$diskdev" bootdisk
12 #extract the 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 echo "Partition layout has changed. Full image will be written."
24 ask_bool
0 "Abort" && exit 1
29 platform_do_upgrade_sdcard
() {
30 local board
=$
(board_name
)
31 local diskdev partdev
diff
33 export_bootdevice
&& export_partdevice diskdev
0 ||
{
34 echo "Unable to determine upgrade device"
40 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
41 get_partitions
"/dev/$diskdev" bootdisk
43 #extract the 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"
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 echo "Writing image to /dev/$partdev..."
68 get_image_dd
"$1" of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
70 echo "Unable to find partition $part device, skipped."
72 done < /tmp
/partmap.image
75 echo "Writing new UUID to /dev/$diskdev..."
76 get_image_dd
"$1" of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
82 platform_copy_config_sdcard
() {
85 if export_partdevice partdev
1; then
87 [ -f /boot
/kernel.img
] || mount
-o rw
,noatime
/dev
/$partdev /boot
88 cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"