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