2
0
forked from Ivasoft/openwrt

mediatek: rework Bananapi BPi-R2

* introduce recovery (=initramfs) vs. production dual boot scheme
 * make use of uImage.FIT (instead of FAT partition)
 * generate images using build steps (instead of external scripts)
 * simplify sysupgrade and config restore (thanks to uImage.FIT)
 * make sure mmc devices are ordered persistently (set DT aliases)

This commit breaks sysupgrade from existing installations, you will
have to re-install using the sdcard.img.gz image.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle
2021-07-10 16:35:47 +01:00
parent 6b2000b6ff
commit 86a61e716e
8 changed files with 156 additions and 150 deletions

View File

@@ -1,5 +1,6 @@
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='blockdev'
# Full system upgrade including preloader for MediaTek SoCs on eMMC or SD
mtk_mmc_full_upgrade() {
@@ -83,7 +84,18 @@ platform_do_upgrade() {
case "$board" in
bananapi,bpi-r2)
mtk_mmc_full_upgrade "$1"
export_bootdevice
export_partdevice rootdev 0
export_partdevice fitpart 3
[ "$fitpart" ] || return 1
dd if=/dev/zero of=/dev/$fitpart bs=4096 count=1 2>/dev/null
blockdev --rereadpt /dev/$rootdev
get_image "$1" | dd of=/dev/$fitpart
blockdev --rereadpt /dev/$rootdev
local datapart=$(get_partition_by_name $rootdev "rootfs_data")
[ "$datapart" ] || return 0
dd if=/dev/zero of=/dev/$datapart bs=4096 count=1 2>/dev/null
echo $datapart > /tmp/sysupgrade.datapart
;;
unielec,u7623-02-emmc-512m)
@@ -126,32 +138,10 @@ platform_check_image() {
case "$board" in
bananapi,bpi-r2)
[ "$magic" != "53444d4d" ] && {
[ "$magic" != "d00dfeed" ] && {
echo "Invalid image type."
return 1
}
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
get_partitions "/dev/$diskdev" bootdisk
#extract the boot sector from the image
get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
get_partitions /tmp/image.bs image
#compare tables
diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
if [ -n "$diff" ]; then
echo "Partition layout has changed. Full image will be written."
ask_bool 0 "Abort" && exit 1
return 0
fi
;;
unielec,u7623-02-emmc-512m)
# Can always upgrade to the new-style full image
@@ -180,9 +170,19 @@ platform_check_image() {
return 0
}
platform_copy_config_mmc() {
[ -e "$UPGRADE_BACKUP" ] || return
local datapart=$(cat /tmp/sysupgrade.datapart)
[ "$datapart" ] || echo "no rootfs_data partition, cannot keep configuration." >&2
dd if="$UPGRADE_BACKUP" of=/dev/$datapart
sync
}
platform_copy_config() {
case "$(board_name)" in
bananapi,bpi-r2|\
bananapi,bpi-r2)
platform_copy_config_mmc
;;
unielec,u7623-02-emmc-512m)
# platform_do_upgrade() will have set $recoverydev
if [ -n "$recoverydev" ]; then