summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorApurva Nandan <a-nandan@ti.com>2023-05-26 14:42:28 +0530
committerPraneeth Bajjuri <praneeth@ti.com>2023-05-30 06:35:36 -0500
commite9cf6b5fe81daf8f1cacc348788259a5582c4c09 (patch)
tree257bd90ecf5c6a429928744cabb626ae65b14a7d /common
parent06a6631100a5f5aa262f4abb112ced5d5fa2efcf (diff)
common: spl: mtd: Add support for loading images from MTD
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>
Diffstat (limited to 'common')
-rw-r--r--common/spl/Kconfig15
-rw-r--r--common/spl/Makefile1
-rw-r--r--common/spl/spl_mtd.c94
3 files changed, 110 insertions, 0 deletions
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index f6e4bcc6b2..3dcdfb9c2b 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -864,6 +864,21 @@ config SPL_MTD_SUPPORT
devices. See SPL_NAND_SUPPORT and SPL_ONENAND_SUPPORT for how
to enable specific MTD drivers.
+config SPL_MTD_LOAD
+ bool "Support loading from MTD framework"
+ depends on SPL_MTD_SUPPORT
+ help
+ Enable support for loading next stage, U-Boot or otherwise, from
+ MTD Framework in U-Boot SPL.
+
+config SYS_MTD_U_BOOT_OFFS
+ hex "address of u-boot payload in MTD flash"
+ default 0x80000 if ARCH_K3
+ default 0x0
+ depends on SPL_MTD_LOAD
+ help
+ Address within MTD Flash from where the u-boot payload is fetched.
+
config SPL_MUSB_NEW
bool "Support new Mentor Graphics USB"
help
diff --git a/common/spl/Makefile b/common/spl/Makefile
index 13db3df993..1d09a4445a 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o
obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o
obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o
obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o
+obj-$(CONFIG_$(SPL_TPL_)MTD_LOAD) += spl_mtd.o
obj-$(CONFIG_$(SPL_TPL_)RAM_SUPPORT) += spl_ram.o
obj-$(CONFIG_$(SPL_TPL_)USB_SDP_SUPPORT) += spl_sdp.o
endif
diff --git a/common/spl/spl_mtd.c b/common/spl/spl_mtd.c
new file mode 100644
index 0000000000..8af3329f91
--- /dev/null
+++ b/common/spl/spl_mtd.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * FIT image loader using MTD read
+ *
+ * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
+ * Apurva Nandan <a-nandan@ti.com>
+ */
+#include <common.h>
+#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->dev;
+ int err;
+ size_t ret_len;
+
+ err = mtd_read(mtd, offs, size, &ret_len, dst);
+ if (!err)
+ return ret_len;
+
+ return 0;
+}
+
+static int spl_mtd_load_image(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev)
+{
+ int err;
+ struct legacy_img_hdr *header;
+ __maybe_unused struct spl_load_info load;
+ struct mtd_info *mtd;
+ size_t ret_len;
+
+ mtd_probe_devices();
+
+ switch (bootdev->boot_device) {
+ case BOOT_DEVICE_SPINAND:
+ mtd = get_mtd_device_nm("spi-nand0");
+ if (IS_ERR_OR_NULL(mtd))
+ printf("MTD device %s not found, ret %ld\n", "spi-nand",
+ PTR_ERR(mtd));
+ break;
+ default:
+ puts(SPL_TPL_PROMPT "Unsupported MTD Boot Device!\n");
+ return -EINVAL;
+ }
+
+ 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.dev = mtd;
+ load.priv = NULL;
+ load.filename = NULL;
+ 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.dev = mtd;
+ load.priv = NULL;
+ load.filename = NULL;
+ 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);
+ }
+
+ return -EINVAL;
+}
+
+SPL_LOAD_IMAGE_METHOD("SPINAND", 0, BOOT_DEVICE_SPINAND, spl_mtd_load_image);