From: Daniel Golle Date: Sat, 24 Feb 2024 03:00:27 +0000 (+0000) Subject: mediatek: mt7623: phase out uImage.FIT partition parser X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=6368ed1ae5b628898b33273c8950f7b7575e4414;p=openwrt%2Fstaging%2Fansuel.git mediatek: mt7623: phase out uImage.FIT partition parser Use the new fitblk driver on the BananaPi R2 as well as UniElec U7623. Introduce boot device selection for fitblk's /chosen/rootdisk handle, similar to how it is already done on MT7622, MT7986 and MT7988. Signed-off-by: Daniel Golle --- diff --git a/package/boot/uboot-envtools/files/mediatek_mt7623 b/package/boot/uboot-envtools/files/mediatek_mt7623 index fd2a01006a..a676e98bd7 100644 --- a/package/boot/uboot-envtools/files/mediatek_mt7623 +++ b/package/boot/uboot-envtools/files/mediatek_mt7623 @@ -13,10 +13,9 @@ board=$(board_name) case "$board" in bananapi,bpi-r2) - . /lib/upgrade/common.sh - export_bootdevice - export_partdevice ubootpart 1 - ubootenv_add_uci_config "/dev/$ubootpart" "0xb0000" "0x10000" "0x10000" "1" + . /lib/upgrade/platform.sh + bootdev="$(platform_get_bootdev)" + ubootenv_add_uci_config "/dev/${bootdev%p[0-9]*}p1" "0xb0000" "0x10000" "0x10000" "1" ;; unielec,u7623-02) ubootenv_add_uci_config "/dev/mmcblk0p1" "0xc0000" "0x10000" "0x10000" "1" diff --git a/package/boot/uboot-mediatek/patches/300-mt7623-fix-mmc-get-env-dev.patch b/package/boot/uboot-mediatek/patches/300-mt7623-fix-mmc-get-env-dev.patch new file mode 100644 index 0000000000..86c48badda --- /dev/null +++ b/package/boot/uboot-mediatek/patches/300-mt7623-fix-mmc-get-env-dev.patch @@ -0,0 +1,46 @@ +--- a/board/mediatek/mt7623/mt7623_rfb.c ++++ b/board/mediatek/mt7623/mt7623_rfb.c +@@ -5,6 +5,7 @@ + + #include + #include ++#include + #include + + DECLARE_GLOBAL_DATA_PTR; +@@ -22,8 +23,9 @@ int mmc_get_boot_dev(void) + { + int g_mmc_devid = -1; + char *uflag = (char *)0x81DFFFF0; ++ struct blk_desc *desc; + +- if (!find_mmc_device(1)) ++ if (blk_get_device_by_str("mmc", "1", &desc) < 0) + return 0; + + if (strncmp(uflag,"eMMC",4)==0) { +@@ -38,6 +40,23 @@ int mmc_get_boot_dev(void) + + int mmc_get_env_dev(void) + { +- return mmc_get_boot_dev(); ++ struct udevice *dev; ++ const char *mmcdev; ++ ++ switch (mmc_get_boot_dev()) { ++ case 0: ++ mmcdev = "mmc@11230000"; ++ break; ++ case 1: ++ mmcdev = "mmc@11240000"; ++ break; ++ default: ++ return -1; ++ } ++ ++ if (uclass_get_device_by_name(UCLASS_MMC, mmcdev, &dev)) ++ return -1; ++ ++ return dev_seq(dev); + } + #endif diff --git a/package/boot/uboot-mediatek/patches/302-mt7623-generic-reset-button-ignore-env.patch b/package/boot/uboot-mediatek/patches/302-mt7623-generic-reset-button-ignore-env.patch index 928dfe8428..b8d89058a2 100644 --- a/package/boot/uboot-mediatek/patches/302-mt7623-generic-reset-button-ignore-env.patch +++ b/package/boot/uboot-mediatek/patches/302-mt7623-generic-reset-button-ignore-env.patch @@ -1,6 +1,6 @@ --- a/board/mediatek/mt7623/mt7623_rfb.c +++ b/board/mediatek/mt7623/mt7623_rfb.c -@@ -4,8 +4,17 @@ +@@ -4,9 +4,18 @@ */ #include @@ -9,6 +9,7 @@ +#include +#include #include + #include #include +#include + @@ -18,8 +19,8 @@ DECLARE_GLOBAL_DATA_PTR; -@@ -41,3 +50,25 @@ int mmc_get_env_dev(void) - return mmc_get_boot_dev(); +@@ -60,3 +69,25 @@ int mmc_get_env_dev(void) + return dev_seq(dev); } #endif + diff --git a/package/boot/uboot-mediatek/patches/313-mt7623-select-rootdisk.patch b/package/boot/uboot-mediatek/patches/313-mt7623-select-rootdisk.patch new file mode 100644 index 0000000000..0089307bbd --- /dev/null +++ b/package/boot/uboot-mediatek/patches/313-mt7623-select-rootdisk.patch @@ -0,0 +1,46 @@ +--- a/board/mediatek/mt7623/mt7623_rfb.c ++++ b/board/mediatek/mt7623/mt7623_rfb.c +@@ -91,3 +91,43 @@ int board_late_init(void) + env_relocate(); + return 0; + } ++ ++int ft_system_setup(void *blob, struct bd_info *bd) ++{ ++ const u32 *media_handle_p; ++ int chosen, len, ret; ++ const char *media; ++ u32 media_handle; ++ ++#ifdef CONFIG_MMC ++ switch (mmc_get_boot_dev()) { ++ case 0: ++ media = "rootdisk-emmc"; ++ break ++ ;; ++ case 1: ++ media = "rootdisk-sd"; ++ break ++ ;; ++ } ++ ++ chosen = fdt_path_offset(blob, "/chosen"); ++ if (chosen <= 0) ++ return 0; ++ ++ media_handle_p = fdt_getprop(blob, chosen, media, &len); ++ if (media_handle_p <= 0 || len != 4) ++ return 0; ++ ++ media_handle = *media_handle_p; ++ ret = fdt_setprop(blob, chosen, "rootdisk", &media_handle, sizeof(media_handle)); ++ if (ret) { ++ printf("cannot set media phandle %s as rootdisk /chosen node\n", media); ++ return ret; ++ } ++ ++ printf("set /chosen/rootdisk to bootrom media: %s (phandle 0x%08x)\n", media, fdt32_to_cpu(media_handle)); ++#endif ++ ++ return 0; ++} diff --git a/package/boot/uboot-mediatek/patches/400-update-bpir2-defconfig.patch b/package/boot/uboot-mediatek/patches/400-update-bpir2-defconfig.patch index ca011aeca9..ab3424e6b5 100644 --- a/package/boot/uboot-mediatek/patches/400-update-bpir2-defconfig.patch +++ b/package/boot/uboot-mediatek/patches/400-update-bpir2-defconfig.patch @@ -1,6 +1,6 @@ --- a/configs/mt7623n_bpir2_defconfig +++ b/configs/mt7623n_bpir2_defconfig -@@ -7,34 +7,105 @@ CONFIG_SYS_MALLOC_F_LEN=0x4000 +@@ -7,34 +7,106 @@ CONFIG_SYS_MALLOC_F_LEN=0x4000 CONFIG_NR_DRAM_BANKS=1 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x81ffff10 @@ -18,6 +18,7 @@ +CONFIG_LED_GPIO=y +CONFIG_LOGLEVEL=7 +CONFIG_LOG=y ++CONFIG_OF_SYSTEM_SETUP=y +CONFIG_AUTOBOOT_KEYED=y +CONFIG_AUTOBOOT_MENU_SHOW=y +CONFIG_BOARD_LATE_INIT=y @@ -110,7 +111,7 @@ CONFIG_USE_IPADDR=y CONFIG_IPADDR="192.168.1.1" CONFIG_USE_SERVERIP=y -@@ -46,6 +117,12 @@ CONFIG_CLK=y +@@ -46,6 +118,12 @@ CONFIG_CLK=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_HS400_SUPPORT=y CONFIG_MMC_MTK=y @@ -123,7 +124,7 @@ CONFIG_PHY_FIXED=y CONFIG_MEDIATEK_ETH=y CONFIG_PINCTRL=y -@@ -55,10 +132,13 @@ CONFIG_POWER_DOMAIN=y +@@ -55,10 +133,13 @@ CONFIG_POWER_DOMAIN=y CONFIG_MTK_POWER_DOMAIN=y CONFIG_DM_SERIAL=y CONFIG_MTK_SERIAL=y @@ -139,7 +140,7 @@ # CONFIG_EFI_GRUB_ARM32_WORKAROUND is not set --- /dev/null +++ b/bananapi_bpi-r2_env -@@ -0,0 +1,70 @@ +@@ -0,0 +1,69 @@ +ipaddr=192.168.1.1 +serverip=192.168.1.254 +loadaddr=0x88000000 @@ -192,14 +193,13 @@ +sdmmc_write_recovery=iminfo $fileaddr && mmc dev 1 && part start mmc 1 $part_recovery part_addr && part size mmc 1 $part_recovery part_size && run mmc_write_vol +_checkbootedfrom=setenv _checkbootedfrom ; if itest.l *81dffff0 == 434d4d65 ; then setenv bootedfrom eMMC ; else setenv bootedfrom SD ; fi +_init_env=setenv _init_env ; setenv _create_env ; saveenv ; saveenv -+_firstboot=setenv _firstboot ; led $bootled_pwr off ;led $bootled_rec on ; run _checkbootedfrom _switch_to_menu _update_bootdev _update_bootcmd _update_bootcmd2 _init_env boot_first ++_firstboot=setenv _firstboot ; led $bootled_pwr off ;led $bootled_rec on ; run _checkbootedfrom _switch_to_menu _update_bootcmd _update_bootcmd2 _init_env boot_first +_set_bootcmd_sdmmc=setenv boot_production "led $bootled_rec off ; led $bootled_pwr on ; run sdmmc_read_production && bootm $loadaddr ; led $bootled_pwr off" +_set_bootcmd_emmc=setenv boot_production "led $bootled_rec off ; led $bootled_pwr on ; run emmc_read_production && bootm $loadaddr ; led $bootled_pwr off" +_update_bootcmd=setenv _update_bootcmd ; if test "$bootedfrom" = "SD" ; then run _set_bootcmd_sdmmc ; else run _set_bootcmd_emmc ; fi ; setenv _set_bootcmd_sdmmc ; setenv _set_bootcmd_emmc +_set_bootcmd2_sdmmc=setenv boot_recovery "led $bootled_pwr off ; led $bootled_rec on ; run sdmmc_read_recovery && bootm $loadaddr ; led $bootled_rec off" +_set_bootcmd2_emmc=setenv boot_recovery "led $bootled_pwr off ; led $bootled_rec on ; run emmc_read_recovery && bootm $loadaddr ; led $bootled_rec off" +_update_bootcmd2=setenv _update_bootcmd2 ; if test "$bootedfrom" = "SD" ; then run _set_bootcmd2_sdmmc ; else run _set_bootcmd2_emmc ; fi ; setenv _set_bootcmd2_sdmmc ; setenv _set_bootcmd2_emmc -+_update_bootdev=setenv _update_bootdev ; if test "$bootedfrom" = "SD" ; then setenv bootargs "$console root=/dev/mmcblk1p65" ; else setenv bootargs "$console root=/dev/mmcblk0p65" ; fi +_switch_to_menu=setenv _switch_to_menu ; setenv bootdelay 3 ; setenv bootmenu_delay 3 ; setenv bootmenu_0 $bootmenu_0d ; setenv bootmenu_0d ; run _bootmenu_update_title +_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title [$bootedfrom] $ver" ; run _set_bm2 +_set_bm2=setenv _set_bm2 ; setenv bootmenu_2 "Boot production system from $bootedfrom.=run boot_production ; run bootmenu_confirm_return" ; run _set_bm3 diff --git a/package/boot/uboot-mediatek/patches/500-board-mt7623-fix-mmc-detect.patch b/package/boot/uboot-mediatek/patches/500-board-mt7623-fix-mmc-detect.patch deleted file mode 100644 index 2f0ed85e53..0000000000 --- a/package/boot/uboot-mediatek/patches/500-board-mt7623-fix-mmc-detect.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- a/board/mediatek/mt7623/mt7623_rfb.c -+++ b/board/mediatek/mt7623/mt7623_rfb.c -@@ -9,6 +9,7 @@ - #include - #include - #include -+#include - #include - #include - -@@ -31,8 +32,9 @@ int mmc_get_boot_dev(void) - { - int g_mmc_devid = -1; - char *uflag = (char *)0x81DFFFF0; -+ struct blk_desc *desc; - -- if (!find_mmc_device(1)) -+ if (blk_get_device_by_str("mmc", "1", &desc) < 0) - return 0; - - if (strncmp(uflag,"eMMC",4)==0) { diff --git a/target/linux/mediatek/dts/mt7623a-unielec-u7623-02.dts b/target/linux/mediatek/dts/mt7623a-unielec-u7623-02.dts index bcd81ba6da..75ee0723ec 100644 --- a/target/linux/mediatek/dts/mt7623a-unielec-u7623-02.dts +++ b/target/linux/mediatek/dts/mt7623a-unielec-u7623-02.dts @@ -9,4 +9,26 @@ / { model = "UniElec U7623-02 eMMC"; compatible = "unielec,u7623-02", "mediatek,mt7623"; + + chosen { + stdout-path = "serial0:115200n8"; + bootargs = "earlycon=uart8250,mmio32,0x11004000 root=/dev/fit0"; + rootdisk = <&emmc_rootdisk>; + }; +}; + +&mmc0 { + card@0 { + compatible = "mmc-card"; + reg = <0>; + + block { + compatible = "block-device"; + partitions { + emmc_rootdisk: block-partition-env { + partno = <3>; + }; + }; + }; + }; }; diff --git a/target/linux/mediatek/image/mt7623.mk b/target/linux/mediatek/image/mt7623.mk index 2c4402da66..24663551e0 100644 --- a/target/linux/mediatek/image/mt7623.mk +++ b/target/linux/mediatek/image/mt7623.mk @@ -116,6 +116,8 @@ endif gzip ARTIFACTS := u-boot.bin preloader.bin sdcard.img.gz SUPPORTED_DEVICES := bananapi,bpi-r2 + DEVICE_COMPAT_VERSION := 1.1 + DEVICE_COMPAT_MESSAGE := Bootloader update required for switch to fitblk endef TARGET_DEVICES += bananapi_bpi-r2 diff --git a/target/linux/mediatek/mt7623/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/mt7623/base-files/lib/upgrade/platform.sh index 5d12b6989e..98f76ff49f 100755 --- a/target/linux/mediatek/mt7623/base-files/lib/upgrade/platform.sh +++ b/target/linux/mediatek/mt7623/base-files/lib/upgrade/platform.sh @@ -1,5 +1,20 @@ REQUIRE_IMAGE_METADATA=1 +platform_get_bootdev() { + local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)" + local handle bootdev + for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do + [ ! -e "$handle" ] && continue + if [ "$rootdisk" = "$(cat $handle)" ]; then + bootdev="${handle%/of_node/phandle}" + bootdev="${bootdev%/device}" + bootdev="${bootdev#/sys/class/block/}" + echo "$bootdev" + break + fi + done +} + # Legacy full system upgrade including preloader for MediaTek SoCs on eMMC or SD legacy_mtk_mmc_full_upgrade() { local diskdev partdev diff oldrecovery @@ -83,10 +98,10 @@ platform_do_upgrade() { case "$board" in bananapi,bpi-r2|\ unielec,u7623-02) - export_bootdevice - export_partdevice fitpart 3 - [ "$fitpart" ] || return 1 - EMMC_KERN_DEV="/dev/$fitpart" + [ -e /dev/fit0 ] && fitblk /dev/fit0 + [ -e /dev/fitrw ] && fitblk /dev/fitrw + bootdev="$(platform_get_bootdev)" + EMMC_KERN_DEV="/dev/$bootdev" emmc_do_upgrade "$1" ;; unielec,u7623-02-emmc-512m) diff --git a/target/linux/mediatek/mt7623/config-6.1 b/target/linux/mediatek/mt7623/config-6.1 index 765f14fe90..a083809e34 100644 --- a/target/linux/mediatek/mt7623/config-6.1 +++ b/target/linux/mediatek/mt7623/config-6.1 @@ -214,7 +214,7 @@ CONFIG_FB_SYS_COPYAREA=y CONFIG_FB_SYS_FILLRECT=y CONFIG_FB_SYS_FOPS=y CONFIG_FB_SYS_IMAGEBLIT=y -CONFIG_FIT_PARTITION=y +# CONFIG_FIT_PARTITION is not set CONFIG_FIXED_PHY=y CONFIG_FIX_EARLYCON_MEM=y CONFIG_FONT_8x16=y @@ -563,6 +563,7 @@ CONFIG_TREE_SRCU=y # CONFIG_UACCE is not set CONFIG_UBIFS_FS=y CONFIG_UEVENT_HELPER_PATH="" +CONFIG_UIMAGE_FIT_BLK=y CONFIG_UNCOMPRESS_INCLUDE="debug/uncompress.h" CONFIG_UNINLINE_SPIN_UNLOCK=y CONFIG_UNWINDER_ARM=y diff --git a/target/linux/mediatek/patches-6.1/164-dts-mt7623-bpi-r2-rootdisk-for-fitblk.patch b/target/linux/mediatek/patches-6.1/164-dts-mt7623-bpi-r2-rootdisk-for-fitblk.patch new file mode 100644 index 0000000000..06d54ec462 --- /dev/null +++ b/target/linux/mediatek/patches-6.1/164-dts-mt7623-bpi-r2-rootdisk-for-fitblk.patch @@ -0,0 +1,53 @@ +--- a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts ++++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts +@@ -27,6 +27,8 @@ + chosen { + stdout-path = "serial2:115200n8"; + bootargs = "earlycon=uart8250,mmio32,0x11004000 console=ttyS2,115200n8 console=tty1"; ++ rootdisk-emmc = <&emmc_rootdisk>; ++ rootdisk-sd = <&sd_rootdisk>; + }; + + connector { +@@ -315,6 +317,20 @@ + vmmc-supply = <®_3p3v>; + vqmmc-supply = <®_1p8v>; + non-removable; ++ ++ card@0 { ++ compatible = "mmc-card"; ++ reg = <0>; ++ ++ block { ++ compatible = "block-device"; ++ partitions { ++ emmc_rootdisk: block-partition-fit { ++ partno = <3>; ++ }; ++ }; ++ }; ++ }; + }; + + &mmc1 { +@@ -328,6 +344,20 @@ + cd-gpios = <&pio 261 GPIO_ACTIVE_LOW>; + vmmc-supply = <®_3p3v>; + vqmmc-supply = <®_3p3v>; ++ ++ card@0 { ++ compatible = "mmc-card"; ++ reg = <0>; ++ ++ block { ++ compatible = "block-device"; ++ partitions { ++ sd_rootdisk: block-partition-fit { ++ partno = <3>; ++ }; ++ }; ++ }; ++ }; + }; + + &mt6323_leds {