msm8916-openwrt/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh
Chuanhong Guo a6991fc7d2 mediatek: mt7622: add a second u-boot for redmi-ax6s
The vendor u-boot knows nothing about UBI, and we used to have a
fixed-size kernel partition for vendor u-boot and UBI for rootfs.
However, that fixed partition becomes too small eventually, and
expanding it requires complicated procedure.

This commit changed the flash layout and added a second u-boot
where the kernel supposed to be.
Now the vendor u-boot chainloads our mainline u-boot, and our
u-boot reads kernel+rootfs from UBI, verifies it, and boot
into OpenWrt.

There are two possible ways to convert from the old fw:
Flash the factory image using mtd (provided by @rany2):

mount -o remount,ro /
mount -o remount,ro /overlay
cd /tmp
dd if=factory.bin bs=1M count=4 | mtd write - kernel
dd if=factory.bin bs=1M skip=4 | mtd -r write - ubi

Or, flash the 2nd u-boot via mtd and upload the firmware
to the 2nd u-boot using tftp:

1. prepare a tftp server at 192.168.1.254 to serve the
   sysupgrade image:
   openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-squashfs-sysupgrade.itb
2. upload the ubi-loader.itb to OpenWrt /tmp, and flash it to
   the old kernel partition:
   mtd -r write openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-ubi-loader.itb
3. The router should reboot and flash the sysupgrade image via TFTP.

Procedure for flashing from vendor firmware shouldn't change.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
2024-03-21 16:55:13 +08:00

112 lines
2.1 KiB
Bash
Executable File

REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fitblk'
platform_do_upgrade() {
local board=$(board_name)
local file_type=$(identify $1)
case "$board" in
bananapi,bpi-r64|\
linksys,e8450-ubi|\
ubnt,unifi-6-lr-v1-ubootmod|\
ubnt,unifi-6-lr-v2-ubootmod|\
ubnt,unifi-6-lr-v3-ubootmod|\
xiaomi,redmi-router-ax6s)
[ -e /dev/fit0 ] && fitblk /dev/fit0
[ -e /dev/fitrw ] && fitblk /dev/fitrw
bootdev="$(fitblk_get_bootdev)"
case "$bootdev" in
mmcblk*)
EMMC_KERN_DEV="/dev/$bootdev"
emmc_do_upgrade "$1"
;;
mtdblock*)
PART_NAME="/dev/mtd${bootdev:8}"
default_do_upgrade "$1"
;;
ubiblock*)
CI_KERNPART="fit"
nand_do_upgrade "$1"
;;
esac
;;
buffalo,wsr-2533dhp2|\
buffalo,wsr-3200ax4s)
local magic="$(get_magic_long "$1")"
# use "mtd write" if the magic is "DHP2 (0x44485032)"
# or "DHP3 (0x44485033)"
if [ "$magic" = "44485032" -o "$magic" = "44485033" ]; then
buffalo_upgrade_ubinized "$1"
else
CI_KERNPART="firmware"
nand_do_upgrade "$1"
fi
;;
dlink,eagle-pro-ai-m32-a1|\
dlink,eagle-pro-ai-r32-a1|\
elecom,wrc-x3200gst3|\
mediatek,mt7622-rfb1-ubi|\
netgear,wax206|\
totolink,a8000ru)
nand_do_upgrade "$1"
;;
linksys,e8450)
if grep -q mtdparts=slave /proc/cmdline; then
PART_NAME=firmware2
else
PART_NAME=firmware1
fi
default_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
}
PART_NAME=firmware
platform_check_image() {
local board=$(board_name)
local magic="$(get_magic_long "$1")"
[ "$#" -gt 1 ] && return 1
case "$board" in
buffalo,wsr-2533dhp2|\
buffalo,wsr-3200ax4s)
buffalo_check_image "$board" "$magic" "$1" || return 1
;;
dlink,eagle-pro-ai-m32-a1|\
dlink,eagle-pro-ai-r32-a1|\
elecom,wrc-x3200gst3|\
mediatek,mt7622-rfb1-ubi|\
netgear,wax206|\
totolink,a8000ru)
nand_do_platform_check "$board" "$1"
return $?
;;
*)
[ "$magic" != "d00dfeed" ] && {
echo "Invalid image type."
return 1
}
return 0
;;
esac
return 0
}
platform_copy_config() {
case "$(board_name)" in
bananapi,bpi-r64)
if fitblk_get_bootdev | grep -q mmc; then
emmc_copy_config
fi
;;
esac
}