mediatek: mt7623: re-write sysupgrade uImage.FIT on MMC

Re-reading the partition table doesn't work reliably, it fails if
anything on the device is still in use and it's not trivial to prevent
every possible case of a block device still being in use somehow.

Therefore, instead of relying on the in-kernel partition parser to know
where to write the configuration backup, use OpenWrt's format-agnostic
fwtool to strip off all metadata from the image and count its blocks
while writing. In that way we can know where to write the config backup
without needing the kernel to parse the MBR and FIT structures.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle 2021-11-12 11:50:26 +00:00
parent 0cbc6b16db
commit c3c67fe7b1
No known key found for this signature in database
GPG Key ID: 5A8F39C31C3217CA
2 changed files with 13 additions and 16 deletions

View File

@ -1,6 +1,6 @@
REQUIRE_IMAGE_METADATA=1 REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='blockdev' RAMFS_COPY_BIN='fwtool'
# Full system upgrade including preloader for MediaTek SoCs on eMMC or SD # Full system upgrade including preloader for MediaTek SoCs on eMMC or SD
mtk_mmc_full_upgrade() { mtk_mmc_full_upgrade() {
@ -84,19 +84,14 @@ platform_do_upgrade() {
case "$board" in case "$board" in
bananapi,bpi-r2) bananapi,bpi-r2)
sync
export_bootdevice export_bootdevice
export_partdevice rootdev 0
blockdev --rereadpt /dev/$rootdev || return 1
export_partdevice fitpart 3 export_partdevice fitpart 3
[ "$fitpart" ] || return 1 [ "$fitpart" ] || return 1
dd if=/dev/zero of=$fitpart bs=4096 count=1 2>/dev/null export UPGRADE_MMC_PARTDEV="/dev/$fitpart"
blockdev --rereadpt /dev/$rootdev 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)))
get_image "$1" | dd of=$fitpart [ "$UPGRADE_MMC_IMAGE_BLOCKS" ] || return 0
blockdev --rereadpt /dev/$rootdev dd if=/dev/zero of=$UPGRADE_MMC_PARTDEV bs=512 seek=$UPGRADE_MMC_IMAGE_BLOCKS count=8
local datapart=$(find_mmc_part "rootfs_data" $rootdev)
[ "$datapart" ] || return 0
dd if=/dev/zero of=$datapart bs=4096 count=1 2>/dev/null
echo $datapart > /tmp/sysupgrade.datapart
;; ;;
unielec,u7623-02-emmc-512m) unielec,u7623-02-emmc-512m)
@ -172,10 +167,12 @@ platform_check_image() {
} }
platform_copy_config_mmc() { platform_copy_config_mmc() {
[ -e "$UPGRADE_BACKUP" ] || return if [ ! -e "$UPGRADE_BACKUP" ] ||
local datapart=$(cat /tmp/sysupgrade.datapart) [ ! -e "$UPGRADE_MMC_PARTDEV" ] ||
[ "$datapart" ] || echo "no rootfs_data partition, cannot keep configuration." >&2 [ ! "$UPGRADE_MMC_IMAGE_BLOCKS" ]; then
dd if="$UPGRADE_BACKUP" of=$datapart return
fi
dd if="$UPGRADE_BACKUP" of="$UPGRADE_MMC_PARTDEV" bs=512 seek=$UPGRADE_MMC_IMAGE_BLOCKS
sync sync
} }

View File

@ -9,7 +9,7 @@ CPU_TYPE:=cortex-a7
CPU_SUBTYPE:=neon-vfpv4 CPU_SUBTYPE:=neon-vfpv4
KERNELNAME:=Image dtbs zImage KERNELNAME:=Image dtbs zImage
FEATURES+=display usbgadget FEATURES+=display usbgadget
DEFAULT_PACKAGES+=blockdev uboot-envtools DEFAULT_PACKAGES+=uboot-envtools
define Target/Description define Target/Description
Build firmware images for MediaTek mt7623 ARM based boards. Build firmware images for MediaTek mt7623 ARM based boards.