From bf58bfb90e16aa7bedeafcf203504d4bad8be264 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 21 Jul 2020 09:53:32 +0100 Subject: [PATCH] mediatek: mt7623: fix sysupgrade from vendor OpenWrt on UniElec U7623 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This board ships with an ancient 14.07-based OpenWrt using block2mtd, and the MBR partition table contains nonsense. It is possible to sysupgrade to an upstream OpenWrt image, but the legacy layout of the OpenWrt images start at 0xA00 in the eMMC, with a raw uImage. The legacy OpenWrt image doesn't "own" the beginning of the device, including the MBR and U-Boot. This means that when a user upgrades to upstream OpenWrt, it doesn't boot because it can't find the right partitions. So hard-code them on the kernel's command line using CONFIG_CMDLINE_PARTITION (for block). Additionally, the vendor firmware doesn't cope with images larger than about 36MiB, because it only overwrites the contents of its "firmware" MTD partition. The current layout of the legacy image wastes a lot of space, allowing over 32MiB for the kernel and another 10MiB for the FAT recovery file system which is only created as 3MiB. So pull those in to allow 4¾ MiB for the kernel, 3MiB for recovery, and then we have over 20MiB for the root file system. This doesn't affect the new images which ship with a full eMMC image including a different MBR layout and a partition for U-Boot, because our modern U-Boot can actually pass the command line to the kernel, and the built-in one doesn't get used anyway. Tested by upgrading from vendor OpenWrt to the current legacy image, from legacy to itself, to the previous legacy layout, and then to finally the full-system image. Signed-off-by: David Woodhouse (cherry picked from commit 6eb63019afef89404899f2cb65fb4c16e00aa0ed) --- .../mediatek/image/gen_mt7623_emmc_img.sh | 22 ++++++++++++++----- target/linux/mediatek/mt7623/config-4.14 | 1 + .../0227-arm-dts-Add-Unielec-U7623-DTS.patch | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/target/linux/mediatek/image/gen_mt7623_emmc_img.sh b/target/linux/mediatek/image/gen_mt7623_emmc_img.sh index 1cb0883fb0..5b3aa175c8 100755 --- a/target/linux/mediatek/image/gen_mt7623_emmc_img.sh +++ b/target/linux/mediatek/image/gen_mt7623_emmc_img.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash - +# +# This script is used only to create the "legacy" image for UniElec U7623, +# suitable for upgrading from the vendor OpenWrt or from OpenWrt 19.07. +# OUTPUT_FILE=$1 KERNEL_FILE=$2 RECOVERY_FILE=$3 @@ -7,10 +10,19 @@ ROOTFS_FILE=$4 BS=512 -#These to offsets are relative to the absolute location of the kernel on the mmc -#(0xA00), so their position in the image is -2560 blocks -RECOVERY_OFFSET=67072 -ROOTFS_OFFSET=87552 +# These two offsets are relative to the absolute location of the kernel on the mmc +# (0xA00), so their position in the image is -2560 blocks +# +# They must be kept in sync with the default command line for U7623. +# blkdevparts=mmcblk0:3M@6M(recovery),256M@9M(root)" +# +# For upgrading from the vendor firmware, the total image must fit in its +# MTD 'firmware' partition, which is typically 36MiB. + +# In the legacy image, the uImage starts at block 0xa00. Allow 4864 KiB (9728) blocks. +RECOVERY_OFFSET=9728 +# The recovery image is 3MiB, or 6144 blocks. +ROOTFS_OFFSET=15872 dd bs="$BS" of="$OUTPUT_FILE" if="$KERNEL_FILE" dd bs="$BS" of="$OUTPUT_FILE" if="$RECOVERY_FILE" seek="$RECOVERY_OFFSET" diff --git a/target/linux/mediatek/mt7623/config-4.14 b/target/linux/mediatek/mt7623/config-4.14 index 35c738a940..c2133d026f 100644 --- a/target/linux/mediatek/mt7623/config-4.14 +++ b/target/linux/mediatek/mt7623/config-4.14 @@ -64,6 +64,7 @@ CONFIG_CLKSRC_MMIO=y CONFIG_CLONE_BACKWARDS=y CONFIG_CMDLINE="earlyprintk console=ttyS0,115200 rootfstype=squashfs,jffs2" CONFIG_CMDLINE_FROM_BOOTLOADER=y +CONFIG_CMDLINE_PARTITION=y CONFIG_COMMON_CLK=y CONFIG_COMMON_CLK_MEDIATEK=y CONFIG_COMMON_CLK_MT2701=y diff --git a/target/linux/mediatek/patches-4.14/0227-arm-dts-Add-Unielec-U7623-DTS.patch b/target/linux/mediatek/patches-4.14/0227-arm-dts-Add-Unielec-U7623-DTS.patch index f0aa1fdbfb..d2b5b1ee7e 100644 --- a/target/linux/mediatek/patches-4.14/0227-arm-dts-Add-Unielec-U7623-DTS.patch +++ b/target/linux/mediatek/patches-4.14/0227-arm-dts-Add-Unielec-U7623-DTS.patch @@ -63,7 +63,7 @@ Subject: [PATCH] arm: dts: Add Unielec U7623 DTS + }; + + chosen { -+ bootargs = "root=/dev/mmcblk0p2 rootfstype=squashfs,f2fs console=ttyS0,115200"; ++ bootargs = "root=/dev/mmcblk0p2 rootfstype=squashfs,f2fs console=ttyS0,115200 blkdevparts=mmcblk0:3M@6M(recovery),256M@9M(root)"; + stdout-path = "serial2:115200n8"; + }; + -- 2.30.2