1 REQUIRE_IMAGE_METADATA
=1
3 # Legacy full system upgrade including preloader for MediaTek SoCs on eMMC or SD
4 legacy_mtk_mmc_full_upgrade
() {
5 local diskdev partdev
diff oldrecovery
7 if grep -q root
=/dev
/mmcblk0p2
/proc
/cmdline
; then
13 export_bootdevice
&& export_partdevice diskdev
0 ||
{
14 echo "Unable to determine upgrade device"
18 #Keep the persistent random mac address (if it exists)
19 mkdir
-p /tmp
/recovery
20 export_partdevice recoverydev
$oldrecovery
21 if mount
-o rw
,noatime
"/dev/$recoverydev" -tvfat /tmp
/recovery
; then
22 [ -f "/tmp/recovery/mac_addr" ] && cp /tmp
/recovery
/mac_addr
/tmp
/
27 if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
28 get_partitions
"/dev/$diskdev" bootdisk
30 #extract the boot sector from the image
31 get_image
"$@" |
dd of
=/tmp
/image.bs count
=1 bs
=512b
33 get_partitions
/tmp
/image.bs image
36 diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
41 if [ -n "$diff" ]; then
42 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=4096 conv
=fsync
44 # Separate removal and addition is necessary; otherwise, partition 1
45 # will be missing if it overlaps with the old partition 2
46 partx
-d - "/dev/$diskdev"
47 partx
-a - "/dev/$diskdev"
49 # iterate over each partition from the image and write it to the boot disk
50 while read part start size
; do
52 if export_partdevice partdev
$part; then
53 echo "Writing image to /dev/$partdev..."
54 get_image
"$@" |
dd of
="/dev/$partdev" ibs
="512" obs
=1M skip
="$start" count
="$size" conv
=fsync
56 echo "Unable to find partition $part device, skipped."
58 done < /tmp
/partmap.image
61 echo "Writing new UUID to /dev/$diskdev..."
62 get_image
"$@" |
dd of
="/dev/$diskdev" bs
=1 skip
=440 count
=4 seek
=440 conv
=fsync
65 export_partdevice recoverydev
2
66 if mount
-o rw
,noatime
"/dev/$recoverydev" -t vfat
/tmp
/recovery
; then
67 [ -f "/tmp/mac_addr" ] && cp /tmp
/mac_addr
/tmp
/recovery
69 if [ "$diskdev" = "mmcblk0" -a -r /tmp
/recovery
/eMMCboot.bin
]; then
70 echo 0 > /sys
/block
/mmcblk0boot
0/force_ro
71 dd if=/tmp
/recovery
/eMMCboot.bin of
=/dev
/mmcblk0boot0 conv
=fsync
73 echo 1 > /sys
/block
/mmcblk0boot
0/force_ro
80 platform_do_upgrade
() {
81 local board
=$
(board_name
)
87 export_partdevice fitpart
3
88 [ "$fitpart" ] ||
return 1
89 EMMC_KERN_DEV
="/dev/$fitpart"
92 unielec
,u7623-02-emmc-512m
)
93 local magic
="$(get_magic_long "$1")"
94 if [ "$magic" = "53444d4d" ]; then
95 legacy_mtk_mmc_full_upgrade
"$1"
96 else # Old partial image starting with uImage
97 # Keep the persistent random mac address (if it exists)
99 mkdir
-p /tmp
/recovery
100 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
101 [ -f "/tmp/recovery/mac_addr" ] && \
102 mv -f /tmp
/recovery
/mac_addr
/tmp
/
105 # 1310720 is the offset in bytes from the start of eMMC and to
106 # the location of the kernel (2560 512 byte sectors)
107 get_image
"$1" |
dd of
=/dev
/mmcblk0 bs
=1310720 seek
=1 conv
=fsync
109 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
110 [ -f "/tmp/mac_addr" ] && mv -f /tmp
/mac_addr
/tmp
/recovery
116 default_do_upgrade
"$1"
121 platform_check_image
() {
122 local magic
="$(get_magic_long "$1")"
124 [ "$#" -gt 1 ] && return 1
126 case "$(board_name)" in
129 [ "$magic" != "d00dfeed" ] && {
130 echo "Invalid image type."
134 unielec
,u7623-02-emmc-512m
)
135 # Can always upgrade to the new-style full image
136 [ "$magic" = "53444d4d" ] && return 0
138 # need to update to new bootchain via full image first
139 [ "$magic" = "d00dfeed" ] && {
140 echo "Please use full eMMC image to update bootloader first."
144 # Legacy uImage directly at 0xA00 on the eMMC.
145 [ "$magic" != "27051956" ] && {
146 echo "Invalid image type."
151 echo "Sysupgrade is not supported on your board yet."
159 platform_copy_config
() {
160 case "$(board_name)" in
165 unielec
,u7623-02-emmc-512m
)
166 # platform_do_upgrade() will have set $recoverydev
167 if [ -n "$recoverydev" ]; then
168 mkdir
-p /tmp
/recovery
169 mount
-o rw
,noatime
"/dev/$recoverydev" -t vfat
/tmp
/recovery
170 cp -af "$UPGRADE_BACKUP" "/tmp/recovery/$BACKUP_FILE"