mediatek: mt7622: bpi-r64: rewrite MMC uImage.FIT sysupgrade

Similar to mt7623, also no longer use 'blockdev' and stop relying on
in-kernel partition parsers. Instead, strip off all metadata using
'fwtool' while writing the firmware image and scrape the number of
blocks written from 'dd', then use that block offset to stash the
configuration backup.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle 2021-11-12 14:54:52 +00:00
parent c3c67fe7b1
commit 8fd0268b5f
No known key found for this signature in database
GPG key ID: 5A8F39C31C3217CA
2 changed files with 14 additions and 17 deletions

View file

@ -1,5 +1,5 @@
REQUIRE_IMAGE_METADATA=1 REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv blockdev' RAMFS_COPY_BIN='fw_printenv fw_setenv fwtool'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock' RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
platform_do_upgrade() { platform_do_upgrade() {
@ -12,17 +12,12 @@ platform_do_upgrade() {
export_partdevice rootdev 0 export_partdevice rootdev 0
case "$rootdev" in case "$rootdev" in
mmc*) mmc*)
blockdev --rereadpt /dev/$rootdev || return 1 sync
local fitpart=$(find_mmc_part "production" $rootdev) export UPGRADE_MMC_PARTDEV=$(find_mmc_part "production" $rootdev)
[ "$fitpart" ] || return 1 [ "$UPGRADE_MMC_PARTDEV" ] || return 1
dd if=/dev/zero of=$fitpart bs=4096 count=1 2>/dev/null 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)))
blockdev --rereadpt /dev/$rootdev [ "$UPGRADE_MMC_IMAGE_BLOCKS" ] || return 0
get_image "$1" | dd of=$fitpart dd if=/dev/zero of=$UPGRADE_MMC_PARTDEV bs=512 seek=$UPGRADE_MMC_IMAGE_BLOCKS count=8
blockdev --rereadpt /dev/$rootdev
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
;; ;;
*) *)
CI_KERNPART="fit" CI_KERNPART="fit"
@ -92,10 +87,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

@ -2,7 +2,7 @@ ARCH:=aarch64
SUBTARGET:=mt7622 SUBTARGET:=mt7622
BOARDNAME:=MT7622 BOARDNAME:=MT7622
CPU_TYPE:=cortex-a53 CPU_TYPE:=cortex-a53
DEFAULT_PACKAGES += kmod-mt7615e kmod-mt7615-firmware wpad-basic-wolfssl blockdev uboot-envtools DEFAULT_PACKAGES += kmod-mt7615e kmod-mt7615-firmware wpad-basic-wolfssl uboot-envtools
KERNELNAME:=Image dtbs KERNELNAME:=Image dtbs
define Target/Description define Target/Description