rockchip: require image metadata
[openwrt/staging/hauke.git] / target / linux / rockchip / armv8 / base-files / lib / upgrade / platform.sh
1 REQUIRE_IMAGE_METADATA=1
2
3 platform_check_image() {
4 local diskdev partdev diff
5
6 export_bootdevice && export_partdevice diskdev 0 || {
7 echo "Unable to determine upgrade device"
8 return 1
9 }
10
11 get_partitions "/dev/$diskdev" bootdisk
12
13 #extract the boot sector from the image
14 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
15
16 get_partitions /tmp/image.bs image
17
18 #compare tables
19 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
20
21 rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
22
23 if [ -n "$diff" ]; then
24 echo "Partition layout has changed. Full image will be written."
25 ask_bool 0 "Abort" && exit 1
26 return 0
27 fi
28 }
29
30 platform_copy_config() {
31 local partdev
32
33 if export_partdevice partdev 1; then
34 mount -o rw,noatime "/dev/$partdev" /mnt
35 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
36 umount /mnt
37 fi
38 }
39
40 platform_do_upgrade() {
41 local diskdev partdev diff
42
43 export_bootdevice && export_partdevice diskdev 0 || {
44 echo "Unable to determine upgrade device"
45 return 1
46 }
47
48 sync
49
50 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
51 get_partitions "/dev/$diskdev" bootdisk
52
53 #extract the boot sector from the image
54 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
55
56 get_partitions /tmp/image.bs image
57
58 #compare tables
59 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
60 else
61 diff=1
62 fi
63
64 if [ -n "$diff" ]; then
65 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
66
67 # Separate removal and addtion is necessary; otherwise, partition 1
68 # will be missing if it overlaps with the old partition 2
69 partx -d - "/dev/$diskdev"
70 partx -a - "/dev/$diskdev"
71
72 return 0
73 fi
74
75 #iterate over each partition from the image and write it to the boot disk
76 while read part start size; do
77 if export_partdevice partdev $part; then
78 echo "Writing image to /dev/$partdev..."
79 get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
80 else
81 echo "Unable to find partition $part device, skipped."
82 fi
83 done < /tmp/partmap.image
84
85 #copy partition uuid
86 echo "Writing new UUID to /dev/$diskdev..."
87 get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
88 }