29eac77dfb0ae52f241696f3f62dce7d16106b20
1 platform_export_bootpart
() {
2 local cmdline uuid disk
4 if read cmdline
< /proc
/cmdline
; then
7 disk
="${cmdline##*block2mtd=}"
11 disk
="${cmdline##*root=}"
17 PARTUUID
=[a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
][a-f0-9
]-02)
18 uuid
="${disk#PARTUUID=}"
20 for disk
in /dev
/*; do
21 [ -b "$disk" ] ||
continue
22 set -- $
(dd if=$disk bs
=1 skip
=440 count
=4 2>/dev
/null |
hexdump -v -e '4/1 "%02x "')
23 if [ "$4$3$2$1" = "$uuid" ]; then
24 export BOOTPART
="${disk}1"
30 export BOOTPART
="${disk%[0-9]}1"
39 platform_check_image
() {
40 [ "$#" -gt 1 ] && return 1
42 case "$(get_magic_word "$1")" in
45 echo "Invalid image type"
51 platform_copy_config
() {
52 if [ -b "$BOOTPART" ]; then
53 mount
-t ext4
-o rw
,noatime
"$BOOTPART" /mnt
54 cp -af "$CONF_TAR" /mnt
/
59 get_partitions
() { # <device> <filename>
63 if [ -b "$disk" -o -f "$disk" ]; then
64 echo "Reading partition table from $filename..."
66 local magic
="$(hexdump -v -n 2 -s 0x1FE -e '1/2 "0x
%04X
"' "$disk")"
67 if [ "$magic" != 0xAA55 ]; then
68 echo "Invalid partition table on $disk"
72 rm -f "/tmp/partmap.$filename"
75 for part
in 1 2 3 4; do
76 set -- $
(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk")
78 local type="$(($1 % 256))"
82 [ $type -gt 0 ] ||
continue
84 printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename"
89 platform_do_upgrade
() {
90 platform_export_bootpart
91 disk
="${BOOTPART%[0-9]}"
93 if [ -b "$disk" ]; then
95 if [ "$SAVE_PARTITIONS" = "1" ]; then
96 get_partitions
"$disk" bootdisk
100 if [ -f "/sys/block/${disk##*/}/queue/physical_block_size" ]; then
101 ibs
="$(cat "/sys
/block
/${disk##*/}/queue
/physical_block_size
")"
106 #extract the boot sector from the image
107 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
109 get_partitions
/tmp
/image.bs image
112 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
113 if [ -n "$diff" ]; then
114 echo "Partition layout is changed. Full image will be written."
115 ask_bool
0 "Abort" && exit
117 get_image
"$@" |
dd of
="$disk" bs
=4096 conv
=fsync
121 #iterate over each partition from the image and write it to the boot disk
122 while read part start size
; do
123 echo "Writing image to $disk$part..."
124 get_image
"$@" |
dd of
="$disk$part" ibs
="$ibs" obs
=1M skip
="$start" count
="$size" conv
=fsync
125 done < /tmp
/partmap.image
128 echo "Writing new UUID to $disk$part..."
129 get_image
"$@" |
dd of
="$disk" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
131 get_image
"$@" |
dd of
="$disk" bs
=4096 conv
=fsync