776bdf53bf89c5eafc24b7b59b943e12f3fab77e
[openwrt/openwrt.git] / target / linux / sunxi / base-files / lib / upgrade / platform.sh
1 platform_check_image() {
2 true
3 }
4
5 platform_copy_config() {
6 local partdev
7
8 if export_partdevice partdev -1; then
9 mount -t vfat -o rw,noatime "/dev/$partdev" /mnt
10 cp -af "$CONF_TAR" /mnt/
11 umount /mnt
12 fi
13 }
14
15 platform_do_upgrade() {
16 local diskdev partdev ibs diff
17
18 if export_bootdevice && export_partdevice diskdev -2; then
19 sync
20 if [ "$SAVE_PARTITIONS" = "1" ]; then
21 get_partitions "/dev/$diskdev" bootdisk
22
23 #get block size
24 if [ -f "/sys/block/$diskdev/queue/physical_block_size" ]; then
25 ibs="$(cat "/sys/block/$diskdev/queue/physical_block_size")"
26 else
27 ibs=512
28 fi
29
30 #extract the boot sector from the image
31 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
32
33 get_partitions /tmp/image.bs image
34
35 #compare tables
36 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
37 if [ -n "$diff" ]; then
38 echo "Partition layout is changed. Full image will be written."
39 ask_bool 0 "Abort" && exit
40
41 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
42 return 0
43 fi
44
45 #write uboot image
46 get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 count=1016 conv=fsync
47 #iterate over each partition from the image and write it to the boot disk
48 while read part start size; do
49 part="$(($part - 2))"
50 if export_partdevice partdev $part; then
51 echo "Writing image to /dev/$partdev..."
52 get_image "$@" | dd of="/dev/$partdev" ibs="$ibs" obs=1M skip="$start" count="$size" conv=fsync
53 else
54 echo "Unable to find partition $part device, skipped."
55 fi
56 done < /tmp/partmap.image
57
58 #copy partition uuid
59 echo "Writing new UUID to /dev/$diskdev..."
60 get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
61 else
62 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
63 fi
64
65 sleep 1
66 fi
67 }