From: Sean Anderson <seanga2@gmail.com>
To: Anurag Dutta <a-dutta@ti.com>,
jagan@amarulasolutions.com, trini@konsulko.com
Cc: michal.simek@amd.com, venkatesh.abbarapu@amd.com,
boon.khai.ng@altera.com, s-k6@ti.com, gehariprasath@ti.com,
vigneshr@ti.com, u-kumar1@ti.com, u-boot@lists.denx.de
Subject: Re: [PATCH 1/7] common: spl: mtd: Add support for loading images from MTD
Date: Tue, 17 Feb 2026 09:54:42 -0500 [thread overview]
Message-ID: <19023fd3-ca7d-ad84-5c65-837676b034ed@gmail.com> (raw)
In-Reply-To: <20260217112156.272154-2-a-dutta@ti.com>
On 2/17/26 06:21, Anurag Dutta wrote:
> From: Apurva Nandan <a-nandan@ti.com>
>
> Introduce support for using MTD subsystem for loading images from
> memory flashes. This will provide the support of using mtd functions
> which are abstracted over the type of flash being used, to load the
> boot images from the flash.
>
> Currently, add support for only SPI NAND flashes. This can be extended
> to all other flash types, when required.
>
> Signed-off-by: Apurva Nandan <a-nandan@ti.com>
> Signed-off-by: Anurag Dutta <a-dutta@ti.com>
> ---
> common/spl/spl_mtd.c | 90 +++++++++++++++++++++++++++++++++++++++
> common/spl/spl_mtd_nand.c | 31 ++++++++++++++
> include/spl.h | 18 ++++++++
> 3 files changed, 139 insertions(+)
> create mode 100644 common/spl/spl_mtd.c
> create mode 100644 common/spl/spl_mtd_nand.c
>
> diff --git a/common/spl/spl_mtd.c b/common/spl/spl_mtd.c
> new file mode 100644
> index 00000000000..341e1a73392
> --- /dev/null
> +++ b/common/spl/spl_mtd.c
> @@ -0,0 +1,90 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * FIT image loader functions using MTD read
> + *
> + * Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/
> + * Apurva Nandan <a-nandan@ti.com>
> + */
> +#include <config.h>
> +#include <image.h>
> +#include <log.h>
> +#include <spl.h>
> +#include <asm/io.h>
> +#include <mtd.h>
> +
> +uint32_t __weak spl_mtd_get_uboot_offs(void)
> +{
> + return CONFIG_SYS_MTD_U_BOOT_OFFS;
> +}
> +
> +static ulong spl_mtd_fit_read(struct spl_load_info *load, ulong offs,
> + ulong size, void *dst)
> +{
> + struct mtd_info *mtd = load->priv;
> + int err;
> + size_t ret_len;
> +
> + err = mtd_read(mtd, offs, size, &ret_len, dst);
> + if (!err)
> + return ret_len;
> +
> + return 0;
> +}
> +
> +struct mtd_info *spl_prepare_mtd(uint boot_device)
> +{
> + struct mtd_info *mtd = NULL;
> +
> + mtd_probe_devices();
> +
> + switch (boot_device) {
> + case BOOT_DEVICE_SPINAND:
> + mtd = get_mtd_device_nm("spi-nand0");
> + break;
> + default:
> + puts(PHASE_PROMPT "Unsupported MTD Boot Device!\n");
> + break;
> + }
> +
> + return mtd;
> +}
> +
> +int spl_mtd_load(struct spl_image_info *spl_image,
> + struct mtd_info *mtd, struct spl_boot_device *bootdev)
> +{
> + int err;
> + struct legacy_img_hdr *header;
> + __maybe_unused struct spl_load_info load;
> + size_t ret_len;
> +
> + header = spl_get_load_buffer(0, sizeof(*header));
> +
> + err = mtd_read(mtd, spl_mtd_get_uboot_offs(), sizeof(*header),
> + &ret_len, (void *)header);
> + if (err)
> + return err;
> +
> + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
> + image_get_magic(header) == FDT_MAGIC) {
> + debug("Found FIT\n");
> + load.priv = mtd;
> + load.bl_len = 1;
> + load.read = spl_mtd_fit_read;
> + return spl_load_simple_fit(spl_image, &load,
> + spl_mtd_get_uboot_offs(), header);
> + } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
> + load.priv = mtd;
> + load.bl_len = 1;
> + load.read = spl_mtd_fit_read;
> + return spl_load_imx_container(spl_image, &load,
> + spl_mtd_get_uboot_offs());
> + } else {
> + err = spl_parse_image_header(spl_image, bootdev, header);
> + if (err)
> + return err;
> + return mtd_read(mtd, spl_mtd_get_uboot_offs(), spl_image->size,
> + &ret_len, (void *)(ulong)spl_image->load_addr);
> + }
>
Please use spl_load instead of hard-coding the image types. Thanks.
--Sean
> + return -EINVAL;
> +}
> diff --git a/common/spl/spl_mtd_nand.c b/common/spl/spl_mtd_nand.c
> new file mode 100644
> index 00000000000..9bc6ff86ee8
> --- /dev/null
> +++ b/common/spl/spl_mtd_nand.c
> @@ -0,0 +1,31 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * FIT image loader using MTD read
> + *
> + * Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/
> + * Anurag Dutta <a-dutta@ti.com>
> + */
> +#include <config.h>
> +#include <image.h>
> +#include <log.h>
> +#include <spl.h>
> +#include <asm/io.h>
> +#include <mtd.h>
> +
> +static int spl_mtd_load_image(struct spl_image_info *spl_image,
> + struct spl_boot_device *bootdev)
> +{
> + struct mtd_info *mtd;
> + int ret;
> +
> + mtd = spl_prepare_mtd(BOOT_DEVICE_SPINAND);
> + if (IS_ERR_OR_NULL(mtd)) {
> + printf("MTD device %s not found, ret %ld\n", "spi-nand",
> + PTR_ERR(mtd));
> + return -EINVAL;
> + }
> +
> + return spl_mtd_load(spl_image, mtd, bootdev);
> +}
> +
> +SPL_LOAD_IMAGE_METHOD("SPINAND", 0, BOOT_DEVICE_SPINAND, spl_mtd_load_image);
> diff --git a/include/spl.h b/include/spl.h
> index 06dc28362d3..c4442be4fdb 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -1219,4 +1219,22 @@ int spl_reloc_prepare(struct spl_image_info *image, ulong *addrp);
> */
> int spl_reloc_jump(struct spl_image_info *image, spl_jump_to_image_t func);
>
> +/* SPL MTD functions */
> +/**
> + * spl_prepare_mtd() - Prepares the mtd for the corresponidng boot device
> + *
> + * @boot_device: A number indicating the BOOT_DEVICE type
> + */
> +struct mtd_info *spl_prepare_mtd(uint boot_device);
> +
> +/**
> + * spl_mtd_load() - FIT Image loader
> + *
> + * @spl_image: SPL image to jump to
> + * @mtd: MTD device descriptor with geometry, flags, and read/write/erase function pointers
> + * @bootdev: boot device used by SPL
> + */
> +int spl_mtd_load(struct spl_image_info *spl_image, struct mtd_info *mtd,
> + struct spl_boot_device *bootdev);
> +
> #endif
next prev parent reply other threads:[~2026-02-17 14:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 11:21 [PATCH 0/7] OSPI NAND MTD load and boot support Anurag Dutta
2026-02-17 11:21 ` [PATCH 1/7] common: spl: mtd: Add support for loading images from MTD Anurag Dutta
2026-02-17 14:54 ` Sean Anderson [this message]
2026-02-17 15:14 ` Sean Anderson
2026-02-18 8:42 ` Anshul Dalal
2026-02-17 11:21 ` [PATCH 2/7] spl: mtd: Remove MTD device after loading images Anurag Dutta
2026-02-17 11:21 ` [PATCH 3/7] spl: mtd: Add bad block handling for SPL image loading Anurag Dutta
2026-02-19 8:38 ` Anshul Dalal
2026-02-17 11:21 ` [PATCH 4/7] spl: Add MTD loading support configuration Anurag Dutta
2026-02-17 11:21 ` [PATCH 5/7] mtd: nand: spi: Enable spinand build Kconfig option for spl Anurag Dutta
2026-02-17 11:21 ` [PATCH 6/7] arm: spl: Enumerate SPINAND as a boot device Anurag Dutta
2026-02-18 8:34 ` Anshul Dalal
2026-02-17 11:21 ` [PATCH 7/7] include: environment: ti: Add ospi_nand environment variables Anurag Dutta
2026-02-17 13:31 ` [PATCH 0/7] OSPI NAND MTD load and boot support Santhosh Kumar K
2026-02-17 13:37 ` Santhosh Kumar K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19023fd3-ca7d-ad84-5c65-837676b034ed@gmail.com \
--to=seanga2@gmail.com \
--cc=a-dutta@ti.com \
--cc=boon.khai.ng@altera.com \
--cc=gehariprasath@ti.com \
--cc=jagan@amarulasolutions.com \
--cc=michal.simek@amd.com \
--cc=s-k6@ti.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=u-kumar1@ti.com \
--cc=venkatesh.abbarapu@amd.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox