4 get_image "$file" | dd bs=1 count=2 skip="$pos" 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
7 platform_check_image_sdcard() {
9 local magic diskdev partdev diff
11 magic=$(get_magic_at "$file" 510)
12 [ "$magic" != "55aa" ] && {
13 echo "Failed to verify MBR boot signature."
17 export_bootdevice && export_partdevice diskdev 0 || {
18 echo "Unable to determine upgrade device"
22 get_partitions "/dev/$diskdev" bootdisk
24 #extract the boot sector from the image
25 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
27 get_partitions /tmp/image.bs image
30 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
32 rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
34 if [ -n "$diff" ]; then
35 echo "Partition layout has changed. Full image will be written."
36 ask_bool 0 "Abort" && exit 1
41 platform_do_upgrade_sdcard() {
42 local board=$(board_name)
43 local diskdev partdev diff
45 export_bootdevice && export_partdevice diskdev 0 || {
46 echo "Unable to determine upgrade device"
52 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
53 get_partitions "/dev/$diskdev" bootdisk
55 #extract the boot sector from the image
56 get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
58 get_partitions /tmp/image.bs image
61 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
66 if [ -n "$diff" ]; then
67 get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
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"
75 get_image "$@" | dd of="$diskdev" bs=512 skip=1 seek=1 count=2048 conv=fsync
76 #iterate over each partition from the image and write it to the boot disk
77 while read part start size; do
78 if export_partdevice partdev $part; then
79 echo "Writing image to /dev/$partdev..."
80 get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
82 echo "Unable to find partition $part device, skipped."
84 done < /tmp/partmap.image
87 echo "Writing new UUID to /dev/$diskdev..."
88 get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
93 fw_setenv openwrt_bootargs 'earlyprintk console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=auto rootwait'
94 fw_setenv openwrt_mmcload 'setenv bootargs "$openwrt_bootargs cfg80211.freg=$regdomain"; fatload mmc 0 0x01000000 zImage; fatload mmc 0 0x02000000 armada-385-turris-omnia.dtb'
95 fw_setenv factory_mmcload 'setenv bootargs "$bootargs cfg80211.freg=$regdomain"; btrload mmc 0 0x01000000 boot/zImage @; btrload mmc 0 0x02000000 boot/dtb @'
96 fw_setenv mmcboot 'run openwrt_mmcload || run factory_mmcload; bootz 0x01000000 - 0x02000000'
103 platform_copy_config_sdcard() {
106 if export_partdevice partdev 1; then
108 [ -f /boot/kernel.img ] || mount -o rw,noatime /dev/$partdev /boot
109 cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"