5e5c356ed6946ab98c5a2a39b037aeef96bcc30f
[openwrt/staging/stintel.git] / target / linux / mvebu / cortexa72 / base-files / lib / upgrade / emmc-puzzle.sh
1 platform_do_upgrade_emmc() {
2 local board=$(board_name)
3 local diskdev partdev
4
5 export_bootdevice && export_partdevice diskdev 0 || {
6 v "Unable to determine upgrade device"
7 return 1
8 }
9 sync
10 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
11 get_partitions "/dev/$diskdev" bootdisk
12 v "Extract boot sector from the image"
13 get_image_dd "$1" of=/tmp/image.bs count=1 bs=512b
14 get_partitions /tmp/image.bs image
15 fi
16
17 #iterate over each partition from the image and write it to the boot disk
18 while read part start size; do
19 if export_partdevice partdev $part; then
20 if [ "$partdev" = "mmcblk0p2" ]; then
21 v "Writing image mmcblk0p3 for /dev/$partdev $start $size"
22 get_image_dd "$1" of="/dev/mmcblk0p3" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
23 elif [ "$partdev" = "mmcblk0p1" ]; then
24 v "Writing image mmcblk0p1 for /dev/$partdev $start $size"
25 get_image_dd "$1" of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
26 fi
27 else
28 v "Unable to find partition $part device, skipped."
29 fi
30 done < /tmp/partmap.image
31
32 v "Writing new UUID to /dev/$diskdev..."
33 get_image_dd "$1" of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
34
35 sleep 1
36 }