[RFC] rockchip: spl: Support reading FIT from eMMC boot partition

Dragan Simic dsimic at manjaro.org
Fri Feb 2 05:30:44 CET 2024


Hello Jonas,

On 2024-02-02 01:11, Jonas Karlman wrote:
> Enable support for loading FIT from eMMC boot partition when
> SUPPORT_EMMC_BOOT Kconfig option is enabled.
> 
> FIT is only loaded from boot partition when the boot partition is set 
> to
> boot0 (1) or boo1 (2) in the extcsd partition config. FIT is read from
> sector 1024 (512 KiB) of the configured boot partition.
> 
> Following can be used to write U-Boot to boot partition 1 of eMMC:
> 
>   # Load TPL+SPL from SD-card
>   => load mmc 1:1 20000000 idbloader.img
> 
>   => mmc dev 0
>   # Access eMMC user partition
>   => mmc partconf 0 0 0 0
>   # Write TPL+SPL to eMMC user partition (512 KiB @ 32 KiB)
>   => mmc write 20000000 40 400
> 
>   # Load FIT from SD-card
>   => load mmc 1:1 20000000 u-boot.itb
> 
>   => mmc dev 0
>   # Access eMMC boot partition 1
>   => mmc partconf 0 0 0 1
>   # Write FIT to eMMC boot partition 1 (2 MiB @ 512 KiB)
>   => mmc write 20000000 400 1000
> 
>   # Configure to use boot partition 1
>   => mmc partconf 0 0 1 0
>   # Show partition config
>   => mmc partconf 0
> 
> Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
> ---
> - Is loading FIT from emmc boot partition a feature of intereset to
>   anyone else?

I find this quite usable.  Thus, I'd support this feature to be polished
further and eventually merged.

> - I used a @ 512 KiB offset for FIT, should leave enough space for e.g.
>   TPL/SPL, vendor storage or environment before FIT.
> - Is @ 512 KiB offset a good default option? Or would e.g. @ 0 or
>   @ 32KiB a more apropriate offset?
> - This does not add kind of fallback to use the normal @ 8 MiB offset 
> in
>   user partition. Is that something that would be needed?

I'd say that the fallback is needed, because we still want to be able
to continue booting the standard way.

> ---
>  arch/arm/mach-rockchip/spl.c     | 23 +++++++++++++++++++++++
>  configs/generic-rk3568_defconfig |  1 +
>  configs/generic-rk3588_defconfig |  1 +
>  3 files changed, 25 insertions(+)
> 
> diff --git a/arch/arm/mach-rockchip/spl.c 
> b/arch/arm/mach-rockchip/spl.c
> index c4d3983a6735..2015d9d72dbd 100644
> --- a/arch/arm/mach-rockchip/spl.c
> +++ b/arch/arm/mach-rockchip/spl.c
> @@ -68,9 +68,32 @@ u32 spl_boot_device(void)
> 
>  u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
> +	if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT) && !IS_SD(mmc)) {
> +		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
> +		case 1:
> +		case 2:
> +			/* Read FIT from a boot partition */
> +			return MMCSD_MODE_EMMCBOOT;
> +		}
> +	}
> +
>  	return MMCSD_MODE_RAW;
>  }
> 
> +unsigned long arch_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
> unsigned long raw_sect)
> +{
> +	if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT) && !IS_SD(mmc)) {
> +		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
> +		case 1:
> +		case 2:
> +			/* Read FIT from sector 1024 (512 KiB) of boot partition */
> +			return 0x400;
> +		}
> +	}
> +
> +	return raw_sect;
> +}
> +
>  #define TIMER_LOAD_COUNT_L	0x00
>  #define TIMER_LOAD_COUNT_H	0x04
>  #define TIMER_CONTROL_REG	0x10
> diff --git a/configs/generic-rk3568_defconfig 
> b/configs/generic-rk3568_defconfig
> index 18a62b0033a0..b90ecb643dc7 100644
> --- a/configs/generic-rk3568_defconfig
> +++ b/configs/generic-rk3568_defconfig
> @@ -51,6 +51,7 @@ CONFIG_ROCKCHIP_GPIO=y
>  CONFIG_MISC=y
>  # CONFIG_ROCKCHIP_IODOMAIN is not set
>  CONFIG_SUPPORT_EMMC_RPMB=y
> +CONFIG_SUPPORT_EMMC_BOOT=y
>  CONFIG_MMC_HS200_SUPPORT=y
>  CONFIG_SPL_MMC_HS200_SUPPORT=y
>  CONFIG_MMC_DW=y
> diff --git a/configs/generic-rk3588_defconfig 
> b/configs/generic-rk3588_defconfig
> index 4755b27c1dea..a9329eb1c625 100644
> --- a/configs/generic-rk3588_defconfig
> +++ b/configs/generic-rk3588_defconfig
> @@ -52,6 +52,7 @@ CONFIG_SPL_CLK=y
>  CONFIG_ROCKCHIP_GPIO=y
>  CONFIG_MISC=y
>  CONFIG_SUPPORT_EMMC_RPMB=y
> +CONFIG_SUPPORT_EMMC_BOOT=y
>  CONFIG_MMC_HS200_SUPPORT=y
>  CONFIG_SPL_MMC_HS200_SUPPORT=y
>  CONFIG_MMC_DW=y


More information about the U-Boot mailing list