2 REQUIRE_IMAGE_METADATA
=1
3 RAMFS_COPY_BIN
='fwtool'
5 # Legacy full system upgrade including preloader for MediaTek SoCs on eMMC or SD
6 legacy_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 [ "$UPGRADE_OPT_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 EMMC_KERN_DEV
="/dev/$fitpart"
94 unielec
,u7623-02-emmc-512m
)
95 local magic
="$(get_magic_long "$1")"
96 if [ "$magic" = "53444d4d" ]; then
97 legacy_mtk_mmc_full_upgrade
"$1"
98 else # Old partial image starting with uImage
99 # Keep the persistent random mac address (if it exists)
100 recoverydev
=mmcblk0p1
101 mkdir
-p /tmp
/recovery
102 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
103 [ -f "/tmp/recovery/mac_addr" ] && \
104 mv -f /tmp
/recovery
/mac_addr
/tmp
/
107 # 1310720 is the offset in bytes from the start of eMMC and to
108 # the location of the kernel (2560 512 byte sectors)
109 get_image
"$1" |
dd of
=/dev
/mmcblk0 bs
=1310720 seek
=1 conv
=fsync
111 mount
-o rw
,noatime
/dev
/$recoverydev /tmp
/recovery
112 [ -f "/tmp/mac_addr" ] && mv -f /tmp
/mac_addr
/tmp
/recovery
118 default_do_upgrade
"$1"
123 platform_check_image
() {
124 local magic
="$(get_magic_long "$1")"
126 [ "$#" -gt 1 ] && return 1
128 case "$(board_name)" in
131 [ "$magic" != "d00dfeed" ] && {
132 echo "Invalid image type."
136 unielec
,u7623-02-emmc-512m
)
137 # Can always upgrade to the new-style full image
138 [ "$magic" = "53444d4d" ] && return 0
140 # need to update to new bootchain via full image first
141 [ "$magic" = "d00dfeed" ] && {
142 echo "Please use full eMMC image to update bootloader first."
146 # Legacy uImage directly at 0xA00 on the eMMC.
147 [ "$magic" != "27051956" ] && {
148 echo "Invalid image type."
153 echo "Sysupgrade is not supported on your board yet."
161 platform_copy_config
() {
162 case "$(board_name)" in
167 unielec
,u7623-02-emmc-512m
)
168 # platform_do_upgrade() will have set $recoverydev
169 if [ -n "$recoverydev" ]; then
170 mkdir
-p /tmp
/recovery
171 mount
-o rw
,noatime
"/dev/$recoverydev" -t vfat
/tmp
/recovery
172 cp -af "$UPGRADE_BACKUP" "/tmp/recovery/$BACKUP_FILE"