mirror of
https://github.com/openwrt/openwrt.git
synced 2025-01-31 08:25:29 +00:00
mediatek: mt7623: prepare for full sysupgrade support on UniElec U7623
An upcoming commit will add a full system image for U7623 which will contain the MBR partition table and U-Boot too. That contrasts with the current image which only owns the eMMC from sector 0xa00 onwards, and must start with a legacy uImage. Prepare for sysupgrade to the new images, and cope with the fact that the recovery partition will be /dev/mmcblk0p2 instead of /dev/mmcblk0p1 after the upgrade. This commit could potentially be backported to 19.07 to allow for direct sysupgrade to the new image layout. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
This commit is contained in:
parent
7a1eaa446b
commit
29fa5526a2
@ -10,7 +10,11 @@ move_config() {
|
|||||||
partnum=2
|
partnum=2
|
||||||
;;
|
;;
|
||||||
unielec,u7623-02-emmc-512m)
|
unielec,u7623-02-emmc-512m)
|
||||||
partnum=1
|
if grep -q root=/dev/mmcblk0p2 /proc/cmdline; then
|
||||||
|
partnum=1;
|
||||||
|
else
|
||||||
|
partnum=2;
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
return 1
|
return 1
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
platform_do_upgrade() {
|
|
||||||
local board=$(board_name)
|
|
||||||
|
|
||||||
case "$board" in
|
REQUIRE_IMAGE_METADATA=1
|
||||||
bananapi,bpi-r2)
|
|
||||||
local diskdev partdev diff
|
# Full system upgrade including preloader for MediaTek SoCs on eMMC or SD
|
||||||
|
mtk_mmc_full_upgrade() {
|
||||||
|
local diskdev partdev diff oldrecovery
|
||||||
|
|
||||||
|
if grep -q root=/dev/mmcblk0p2 /proc/cmdline; then
|
||||||
|
oldrecovery=1
|
||||||
|
else
|
||||||
|
oldrecovery=2
|
||||||
|
fi
|
||||||
|
|
||||||
export_bootdevice && export_partdevice diskdev 0 || {
|
export_bootdevice && export_partdevice diskdev 0 || {
|
||||||
echo "Unable to determine upgrade device"
|
echo "Unable to determine upgrade device"
|
||||||
@ -12,7 +18,7 @@ platform_do_upgrade() {
|
|||||||
|
|
||||||
#Keep the persistent random mac address (if it exists)
|
#Keep the persistent random mac address (if it exists)
|
||||||
mkdir -p /tmp/recovery
|
mkdir -p /tmp/recovery
|
||||||
export_partdevice recoverydev 2
|
export_partdevice recoverydev $oldrecovery
|
||||||
if mount -o rw,noatime "/dev/$recoverydev" -tvfat /tmp/recovery; then
|
if mount -o rw,noatime "/dev/$recoverydev" -tvfat /tmp/recovery; then
|
||||||
[ -f "/tmp/recovery/mac_addr" ] && cp /tmp/recovery/mac_addr /tmp/
|
[ -f "/tmp/recovery/mac_addr" ] && cp /tmp/recovery/mac_addr /tmp/
|
||||||
umount /tmp/recovery
|
umount /tmp/recovery
|
||||||
@ -36,12 +42,12 @@ platform_do_upgrade() {
|
|||||||
if [ -n "$diff" ]; then
|
if [ -n "$diff" ]; then
|
||||||
get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
|
get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
|
||||||
|
|
||||||
# Separate removal and addtion is necessary; otherwise, partition 1
|
# Separate removal and addition is necessary; otherwise, partition 1
|
||||||
# will be missing if it overlaps with the old partition 2
|
# will be missing if it overlaps with the old partition 2
|
||||||
partx -d - "/dev/$diskdev"
|
partx -d - "/dev/$diskdev"
|
||||||
partx -a - "/dev/$diskdev"
|
partx -a - "/dev/$diskdev"
|
||||||
else
|
else
|
||||||
#iterate over each partition from the image and write it to the boot disk
|
# iterate over each partition from the image and write it to the boot disk
|
||||||
while read part start size; do
|
while read part start size; do
|
||||||
part="$(($part - 2))"
|
part="$(($part - 2))"
|
||||||
if export_partdevice partdev $part; then
|
if export_partdevice partdev $part; then
|
||||||
@ -57,6 +63,7 @@ platform_do_upgrade() {
|
|||||||
get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
|
get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export_partdevice recoverydev 2
|
||||||
if mount -o rw,noatime "/dev/$recoverydev" -t vfat /tmp/recovery; then
|
if mount -o rw,noatime "/dev/$recoverydev" -t vfat /tmp/recovery; then
|
||||||
[ -f "/tmp/mac_addr" ] && cp /tmp/mac_addr /tmp/recovery
|
[ -f "/tmp/mac_addr" ] && cp /tmp/mac_addr /tmp/recovery
|
||||||
|
|
||||||
@ -69,24 +76,38 @@ platform_do_upgrade() {
|
|||||||
sync
|
sync
|
||||||
umount /tmp/recovery
|
umount /tmp/recovery
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
platform_do_upgrade() {
|
||||||
|
local board=$(board_name)
|
||||||
|
|
||||||
|
case "$board" in
|
||||||
|
bananapi,bpi-r2)
|
||||||
|
mtk_mmc_full_upgrade "$1"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
unielec,u7623-02-emmc-512m)
|
unielec,u7623-02-emmc-512m)
|
||||||
#Keep the persisten random mac address (if it exists)
|
local magic="$(get_magic_long "$1")"
|
||||||
|
if [ "$magic" = "53444d4d" ]; then
|
||||||
|
mtk_mmc_full_upgrade "$1"
|
||||||
|
else # Old partial image starting with uImage
|
||||||
|
# Keep the persistent random mac address (if it exists)
|
||||||
|
recoverydev=mmcblk0p1
|
||||||
mkdir -p /tmp/recovery
|
mkdir -p /tmp/recovery
|
||||||
mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
|
mount -o rw,noatime /dev/$recoverydev /tmp/recovery
|
||||||
[ -f "/tmp/recovery/mac_addr" ] && \
|
[ -f "/tmp/recovery/mac_addr" ] && \
|
||||||
mv -f /tmp/recovery/mac_addr /tmp/
|
mv -f /tmp/recovery/mac_addr /tmp/
|
||||||
umount /tmp/recovery
|
umount /tmp/recovery
|
||||||
|
|
||||||
#1310720 is the offset in bytes from the start of eMMC and to
|
# 1310720 is the offset in bytes from the start of eMMC and to
|
||||||
#the location of the kernel (2560 512 byte sectors)
|
# the location of the kernel (2560 512 byte sectors)
|
||||||
get_image "$1" | dd of=/dev/mmcblk0 bs=1310720 seek=1 conv=fsync
|
get_image "$1" | dd of=/dev/mmcblk0 bs=1310720 seek=1 conv=fsync
|
||||||
|
|
||||||
mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
|
mount -o rw,noatime /dev/$recoverydev /tmp/recovery
|
||||||
[ -f "/tmp/mac_addr" ] && mv -f /tmp/mac_addr /tmp/recovery
|
[ -f "/tmp/mac_addr" ] && mv -f /tmp/mac_addr /tmp/recovery
|
||||||
sync
|
sync
|
||||||
umount /tmp/recovery
|
umount /tmp/recovery
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
default_do_upgrade "$1"
|
default_do_upgrade "$1"
|
||||||
@ -133,10 +154,21 @@ platform_check_image() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
unielec,u7623-02-emmc-512m)
|
unielec,u7623-02-emmc-512m)
|
||||||
|
# Can always upgrade to the new-style full image
|
||||||
|
[ "$magic" = "53444d4d" ] && return 0
|
||||||
|
|
||||||
|
# Legacy uImage directly at 0xA00 on the eMMC.
|
||||||
[ "$magic" != "27051956" ] && {
|
[ "$magic" != "27051956" ] && {
|
||||||
echo "Invalid image type."
|
echo "Invalid image type."
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
rootpart=$(cat /proc/cmdline)
|
||||||
|
rootpart="${rootpart##*root=}"
|
||||||
|
rootpart="${rootpart%% *}"
|
||||||
|
[ "$rootpart" != "/dev/mmcblk0p2" ] && {
|
||||||
|
echo "Cannot downgrade to legacy image."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -148,25 +180,18 @@ platform_check_image() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_copy_config_emmc() {
|
|
||||||
local partdev
|
|
||||||
|
|
||||||
if export_bootdevice && export_partdevice partdev $1; then
|
|
||||||
mkdir -p /recovery
|
|
||||||
mount -o rw,noatime "/dev/$partdev" -t vfat /recovery
|
|
||||||
cp -af "$UPGRADE_BACKUP" "/recovery/$BACKUP_FILE"
|
|
||||||
sync
|
|
||||||
umount /recovery
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
platform_copy_config() {
|
platform_copy_config() {
|
||||||
case "$(board_name)" in
|
case "$(board_name)" in
|
||||||
bananapi,bpi-r2)
|
bananapi,bpi-r2|\
|
||||||
platform_copy_config_emmc 2
|
|
||||||
;;
|
|
||||||
unielec,u7623-02-emmc-512m)
|
unielec,u7623-02-emmc-512m)
|
||||||
platform_copy_config_emmc 1
|
# platform_do_upgrade() will have set $recoverydev
|
||||||
|
if [ -n "$recoverydev" ]; then
|
||||||
|
mkdir -p /tmp/recovery
|
||||||
|
mount -o rw,noatime "/dev/$recoverydev" -t vfat /tmp/recovery
|
||||||
|
cp -af "$UPGRADE_BACKUP" "/tmp/recovery/$BACKUP_FILE"
|
||||||
|
sync
|
||||||
|
umount /tmp/recovery
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user