[PATCH v2] spl: Add generic SPL MTD loader support

Quentin Schulz quentin.schulz at cherry.de
Wed Feb 25 16:46:21 CET 2026


Hi Fabio,

On 2/20/26 4:12 AM, Fabio Estevam wrote:
> From: Fabio Estevam <festevam at nabladev.com>
> 
> Add support for loading the next stage from an MTD device in SPL.
> 
> Introduce CONFIG_SPL_MTD_LOAD and a generic SPL MTD loader
> implementation that uses the MTD subsystem to read the U-Boot payload.
> 
> The loader works with any MTD-backed storage, including raw NAND and
> SPI NAND, without being tied to a specific NAND type.
> 
> The payload offset defaults to CONFIG_SYS_MTD_U_BOOT_OFFS and can be
> overridden via the device tree property:
> 
>      u-boot,spl-payload-offset
> 

Missing update to docs (at the very least in 
doc/device-tree-bindings/config.txt). I'm also not entirely sure we 
should have two loaders use the same property for different media.

What happens if you have a system with SPI NOR and MTD support but the 
payload is at a different offset? Some Rockchip platforms have support 
for SPI flashes and NANDs, e.g. RK3568 to only name one. It seems it's 
possible to have both a SPI flash and NAND flash according to the 
datasheet and VCCIO2 IO block in Radxa Rock 3A schematics (the PX30 
datasheet mentions support for both as well but I only saw the same pins 
for both controllers).

> To support both raw NAND and SPI NAND boot flows, the loader is
> registered for BOOT_DEVICE_NAND and BOOT_DEVICE_SPI. This allows it
> to operate correctly on platforms where the ROM reports either NAND
> or SPI as the boot source while using the same MTD-based loading
> infrastructure.
> 
> The required NAND core and SPI NAND drivers are built for SPL when
> CONFIG_SPL_MTD_LOAD is enabled.
> 
> This provides reusable infrastructure for boards that boot from MTD
> devices without relying on SPI-specific or NAND-specific SPL loaders.
> 
> Signed-off-by: Fabio Estevam <festevam at nabladev.com>
> ---
> Changes since v1:
> - Use uclass_get_device_by_seq().
> - Use puts() instead of debug() for error.
> - Include the new loader to include/spl_load.h.
> - Introduce SPL_MTD_SPI_NAND.
> 
>   common/spl/Kconfig        | 30 ++++++++++++++
>   common/spl/Makefile       |  1 +
>   common/spl/spl_mtd.c      | 83 +++++++++++++++++++++++++++++++++++++++
>   drivers/mtd/Makefile      |  1 +
>   drivers/mtd/nand/Makefile |  4 +-
>   include/spl_load.h        |  1 +
>   6 files changed, 119 insertions(+), 1 deletion(-)
>   create mode 100644 common/spl/spl_mtd.c
> 
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> index 2998b7acb75f..16dbc5b54324 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -933,6 +933,12 @@ config SYS_MMCSD_FS_BOOT_PARTITION
>   	  used in fs mode.
>   	  Use -1 as a special value to use the first bootable partition.
>   
> +config SYS_SPL_MTD_SEQ
> +	int "MTD device number for the SPL load"
> +	default 0
> +	help
> +	  MTD device number used for the SPL load.
> +
>   config SPL_MMC_TINY
>   	bool "Tiny MMC framework in SPL"
>   	depends on SPL_MMC
> @@ -1578,6 +1584,30 @@ config SPL_SPI_LOAD
>   
>   endif # SPL_SPI_FLASH_SUPPORT
>   
> +config SPL_MTD_LOAD
> +	bool "Support loading from a generic MTD device"
> +	depends on SPL
> +	depends on MTD && DM_MTD
> +	help
> +	  Enable support for loading the next stage from an MTD device
> +	  using the MTD subsystem in SPL.
> +
> +	  This supports raw NAND and SPI NAND devices.
> +
> +config SPL_MTD_SPI_NAND
> +	bool "Enable SPI NAND support in SPL"
> +	depends on SPL_MTD_LOAD
> +	select MTD_SPI_NAND
> +	help
> +	 Build SPI NAND support for SPL.
> +
> +config SYS_MTD_U_BOOT_OFFS
> +	hex "address of U-boot payload in the MTD device"
> +	default 0x0
> +	help
> +	 Address within the MTD device where the U-boot payload is fetched
> +	 from.
> +

Specify this can be overridden in DT with the DT property you read in 
the driver.

Cheers,
Quentin


More information about the U-Boot mailing list