mediatek: mt7623: phase out uImage.FIT partition parser
authorDaniel Golle <daniel@makrotopia.org>
Sat, 24 Feb 2024 03:00:27 +0000 (03:00 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 24 Feb 2024 03:02:35 +0000 (03:02 +0000)
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 <daniel@makrotopia.org>
package/boot/uboot-envtools/files/mediatek_mt7623
package/boot/uboot-mediatek/patches/300-mt7623-fix-mmc-get-env-dev.patch [new file with mode: 0644]
package/boot/uboot-mediatek/patches/302-mt7623-generic-reset-button-ignore-env.patch
package/boot/uboot-mediatek/patches/313-mt7623-select-rootdisk.patch [new file with mode: 0644]
package/boot/uboot-mediatek/patches/400-update-bpir2-defconfig.patch
package/boot/uboot-mediatek/patches/500-board-mt7623-fix-mmc-detect.patch [deleted file]
target/linux/mediatek/dts/mt7623a-unielec-u7623-02.dts
target/linux/mediatek/image/mt7623.mk
target/linux/mediatek/mt7623/base-files/lib/upgrade/platform.sh
target/linux/mediatek/mt7623/config-6.1
target/linux/mediatek/patches-6.1/164-dts-mt7623-bpi-r2-rootdisk-for-fitblk.patch [new file with mode: 0644]

index fd2a01006a8e08436106788b022a90f136ba3ea5..a676e98bd79819eaff29dc0ebf2c930fc533c1c4 100644 (file)
@@ -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 (file)
index 0000000..86c48ba
--- /dev/null
@@ -0,0 +1,46 @@
+--- a/board/mediatek/mt7623/mt7623_rfb.c
++++ b/board/mediatek/mt7623/mt7623_rfb.c
+@@ -5,6 +5,7 @@
+ #include <common.h>
+ #include <mmc.h>
++#include <part.h>
+ #include <asm/global_data.h>
+ 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
index 928dfe8428a3de2680a60e78110d185a980d7746..b8d89058a2e93aee2b1beebcc3067004bff3850e 100644 (file)
@@ -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 <common.h>
@@ -9,6 +9,7 @@
 +#include <env.h>
 +#include <init.h>
  #include <mmc.h>
+ #include <part.h>
  #include <asm/global_data.h>
 +#include <linux/delay.h>
 +
@@ -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 (file)
index 0000000..0089307
--- /dev/null
@@ -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;
++}
index ca011aeca9609e6c5e5d983beb5dff915717e721..ab3424e6b591baea5d51ea2b85eb9af2f3d1b92b 100644 (file)
@@ -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
  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
  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
  # 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
 +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  \e[0;36m[$bootedfrom]\e[0m    \e[33m$ver\e[0m" ; 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 (file)
index 2f0ed85..0000000
+++ /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 <env.h>
- #include <init.h>
- #include <mmc.h>
-+#include <part.h>
- #include <asm/global_data.h>
- #include <linux/delay.h>
-@@ -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) {
index bcd81ba6da75cc032114a27da680bb009d664d6f..75ee0723ece6ca361b73fcb7c326d0dbef735ca5 100644 (file)
@@ -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>;
+                               };
+                       };
+               };
+       };
 };
index 2c4402da6619491e870a509c4a1166d9f07ebd6e..24663551e0f7cb9a859003ae9540aca6f6690583 100644 (file)
@@ -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
 
index 5d12b6989e574a6d304d141a0c0baace4a13ae0d..98f76ff49f00c8f65784bbdc3772cde8cf4a0fb5 100755 (executable)
@@ -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)
index 765f14fe902ada915e3e084949da8436bf96c0d3..a083809e345be8826ca0b5d1f5f56f89df156ea0 100644 (file)
@@ -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 (file)
index 0000000..06d54ec
--- /dev/null
@@ -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 = <&reg_3p3v>;
+       vqmmc-supply = <&reg_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 = <&reg_3p3v>;
+       vqmmc-supply = <&reg_3p3v>;
++
++      card@0 {
++              compatible = "mmc-card";
++              reg = <0>;
++
++              block {
++                      compatible = "block-device";
++                      partitions {
++                              sd_rootdisk: block-partition-fit {
++                                      partno = <3>;
++                              };
++                      };
++              };
++      };
+ };
+ &mt6323_leds {