2 REQUIRE_IMAGE_METADATA
=1
3 RAMFS_COPY_BIN
='fwtool'
5 # Full system upgrade including preloader for MediaTek SoCs on eMMC or SD
6 mtk_mmc_full_upgrade
() {
7 local diskdev partdev
diff oldrecovery
9 if grep -q root
=/dev
/mmcblk0p2
/proc
/cmdline
; then
15 export_bootdevice
&& export_partdevice diskdev
0 ||
{
16 echo "Unable to determine upgrade device"
20 #Keep the persistent random mac address (if it exists)
21 mkdir
-p /tmp
/recovery
22 export_partdevice recoverydev
$oldrecovery
23 if mount
-o rw
,noatime
"/dev/$recoverydev" -tvfat /tmp
/recovery
; then
24 [ -f "/tmp/recovery/mac_addr" ] && cp /tmp
/recovery
/mac_addr
/tmp
/
29 if [ "$SAVE_PARTITIONS" = "1" ]; then
30 get_partitions
"/dev/$diskdev" bootdisk
32 #extract the boot sector from the image
33 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
35 get_partitions
/tmp
/image.bs image
38 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
43 if [ -n "$diff" ]; then
44 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
46 # Separate removal and addition is necessary; otherwise, partition 1
47 # will be missing if it overlaps with the old partition 2
48 partx
-d - "/dev/$diskdev"
49 partx
-a - "/dev/$diskdev"
51 # iterate over each partition from the image and write it to the boot disk
52 while read part start size
; do
54 if export_partdevice partdev
$part; then
55 echo "Writing image to /dev/$partdev..."
56 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
58 echo "Unable to find partition $part device, skipped."
60 done < /tmp
/partmap.image
63 echo "Writing new UUID to /dev/$diskdev..."
64 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
67 export_partdevice recoverydev
2
68 if mount
-o rw
,noatime
"/dev/$recoverydev" -t vfat
/tmp
/recovery
; then
69 [ -f "/tmp/mac_addr" ] && cp /tmp
/mac_addr
/tmp
/recovery
71 if [ "$diskdev" = "mmcblk0" -a -r /tmp
/recovery
/eMMCboot.bin
]; then
72 echo 0 > /sys
/block
/mmcblk0boot
0/force_ro
73 dd if=/tmp
/recovery
/eMMCboot.bin of
=/dev
/mmcblk0boot0 conv
=fsync
75 echo 1 > /sys
/block
/mmcblk0boot
0/force_ro
82 platform_do_upgrade
() {
83 local board
=$
(board_name
)
89 export_partdevice fitpart
3
90 [ "$fitpart" ] ||
return 1
91 export UPGRADE_MMC_PARTDEV
="/dev/$fitpart"
92 export UPGRADE_MMC_IMAGE_BLOCKS
=$
(($
(get_image
"$1" | fwtool
-i /dev
/null
-T - |
dd of
=$UPGRADE_MMC_PARTDEV bs
=512 2>&1 |
grep "records out" | cut
-d' ' -f1)))
93 [ "$UPGRADE_MMC_IMAGE_BLOCKS" ] ||
return 0
94 dd if=/dev
/zero of
=$UPGRADE_MMC_PARTDEV bs
=512 seek
=$UPGRADE_MMC_IMAGE_BLOCKS count
=8
97 unielec
,u7623-02-emmc-512m
)
98 local magic
="$(get_magic_long "$1")"
99 if [ "$magic" = "53444d4d" ]; then
100 mtk_mmc_full_upgrade
"$1"
101 else # Old partial image starting with uImage
102 # Keep the persistent random mac address (if it exists)
103 recoverydev
=mmcblk0p1
104 mkdir
-p /tmp
/recovery
105 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
106 [ -f "/tmp/recovery/mac_addr" ] && \
107 mv -f /tmp
/recovery
/mac_addr
/tmp
/
110 # 1310720 is the offset in bytes from the start of eMMC and to
111 # the location of the kernel (2560 512 byte sectors)
112 get_image
"$1" |
dd of
=/dev
/mmcblk0 bs
=1310720 seek
=1 conv
=fsync
114 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
115 [ -f "/tmp/mac_addr" ] && mv -f /tmp
/mac_addr
/tmp
/recovery
121 default_do_upgrade
"$1"
128 platform_check_image
() {
129 local board
=$
(board_name
)
130 local magic
="$(get_magic_long "$1")"
131 local diskdev partdev
diff
133 [ "$#" -gt 1 ] && return 1
137 [ "$magic" != "d00dfeed" ] && {
138 echo "Invalid image type."
142 unielec
,u7623-02-emmc-512m
)
143 # Can always upgrade to the new-style full image
144 [ "$magic" = "53444d4d" ] && return 0
146 # Legacy uImage directly at 0xA00 on the eMMC.
147 [ "$magic" != "27051956" ] && {
148 echo "Invalid image type."
151 rootpart
=$
(cat /proc
/cmdline
)
152 rootpart
="${rootpart##*root=}"
153 rootpart
="${rootpart%% *}"
154 [ "$rootpart" != "/dev/mmcblk0p2" ] && {
155 echo "Cannot downgrade to legacy image."
161 echo "Sysupgrade is not supported on your board yet."
169 platform_copy_config_mmc
() {
170 if [ ! -e "$UPGRADE_BACKUP" ] ||
171 [ ! -e "$UPGRADE_MMC_PARTDEV" ] ||
172 [ ! "$UPGRADE_MMC_IMAGE_BLOCKS" ]; then
175 dd if="$UPGRADE_BACKUP" of
="$UPGRADE_MMC_PARTDEV" bs
=512 seek
=$UPGRADE_MMC_IMAGE_BLOCKS
179 platform_copy_config
() {
180 case "$(board_name)" in
182 platform_copy_config_mmc
184 unielec
,u7623-02-emmc-512m
)
185 # platform_do_upgrade() will have set $recoverydev
186 if [ -n "$recoverydev" ]; then
187 mkdir
-p /tmp
/recovery
188 mount
-o rw
,noatime
"/dev/$recoverydev" -t vfat
/tmp
/recovery
189 cp -af "$UPGRADE_BACKUP" "/tmp/recovery/$BACKUP_FILE"