[PATCH 16/17] imx: Support loading container image from RAM device

Alice Guo alice.guo at oss.nxp.com
Wed Oct 16 09:18:09 CEST 2024


From: Ye Li <ye.li at nxp.com>

For some debug case, we have preloaded the full boot image to RAM
device. Add the support that SPL can load the u-boot-atf container
from the RAM device.

Signed-off-by: Ye Li <ye.li at nxp.com>
Signed-off-by: Alice Guo <alice.guo at nxp.com>
---
 arch/arm/mach-imx/image-container.c | 22 ++++++++++++++++++++++
 common/spl/spl_ram.c                | 34 ++++++++++++++++++++--------------
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-imx/image-container.c b/arch/arm/mach-imx/image-container.c
index 54ae7721888dbc93fdaba8e5aedc52c4506bb1c1..27dc162f2517b6d75b0ed95510c09385f7cbc859 100644
--- a/arch/arm/mach-imx/image-container.c
+++ b/arch/arm/mach-imx/image-container.c
@@ -21,6 +21,7 @@
 #define NAND_DEV	2
 #define QSPI_NOR_DEV	3
 #define ROM_API_DEV	4
+#define RAM_DEV	5
 
 /* The unit of second image offset number which provision by the fuse bits */
 #define SND_IMG_OFF_UNIT    (0x100000UL)
@@ -148,6 +149,11 @@ static int get_dev_container_size(void *dev, int dev_type, unsigned long offset,
 	}
 #endif
 
+#ifdef CONFIG_SPL_RAM_SUPPORT
+	if (dev_type == RAM_DEV)
+		memcpy(buf, (const void *)offset, CONTAINER_HDR_ALIGNMENT);
+#endif
+
 	ret = get_container_size((ulong)buf, header_length);
 
 	free(buf);
@@ -222,6 +228,8 @@ static unsigned long get_boot_device_offset(void *dev, int dev_type)
 			CONTAINER_HDR_NAND_OFFSET;
 	} else if (dev_type == QSPI_NOR_DEV) {
 		offset = CONTAINER_HDR_QSPI_OFFSET + 0x08000000;
+	} else if (dev_type == RAM_DEV) {
+		offset = (unsigned long)dev + CONTAINER_HDR_MMCSD_OFFSET;
 	} else {
 		printf("Not supported dev_type: %d\n", dev_type);
 	}
@@ -382,3 +390,17 @@ ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev)
 	return end;
 }
 #endif
+
+#ifdef CONFIG_SPL_RAM_SUPPORT
+unsigned long spl_ram_get_uboot_base(void)
+{
+	ulong end;
+
+	end = get_imageset_end((void *)CONFIG_SPL_LOAD_FIT_ADDRESS, RAM_DEV);
+	end = ROUND(end, SZ_1K);
+
+	printf("Load image from RAM 0x%lx\n", end);
+
+	return end;
+}
+#endif
diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c
index 71b7a8374bbbf534e1b2c28e02205af035fcfd8b..c3a1df59e3f3bcc19a6cdff21ec66a4bd4df7b93 100644
--- a/common/spl/spl_ram.c
+++ b/common/spl/spl_ram.c
@@ -16,24 +16,25 @@
 #include <spl.h>
 #include <linux/libfdt.h>
 
-static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
-			       ulong count, void *buf)
+unsigned long __weak spl_ram_get_uboot_base(void)
 {
 	ulong addr = 0;
 
-	debug("%s: sector %lx, count %lx, buf %lx\n",
-	      __func__, sector, count, (ulong)buf);
-
 	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
 		addr = IF_ENABLED_INT(CONFIG_SPL_LOAD_FIT,
 				      CONFIG_SPL_LOAD_FIT_ADDRESS);
 	}
-	addr += sector;
-	if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD))
-		addr += image_load_offset;
 
-	memcpy(buf, (void *)addr, count);
+	return addr;
+}
+
+static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
+			       ulong count, void *buf)
+{
+	debug("%s: sector %lx, count %lx, buf %lx\n",
+	      __func__, sector, count, (ulong)buf);
 
+	memcpy(buf, (void *)(sector), count);
 	return count;
 }
 
@@ -44,10 +45,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
 	ulong addr = 0;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
-		addr = IF_ENABLED_INT(CONFIG_SPL_LOAD_FIT,
-				      CONFIG_SPL_LOAD_FIT_ADDRESS);
-	}
+	header = (struct legacy_img_hdr *)spl_ram_get_uboot_base();
 
 	if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) {
 		ret = image_pre_load(addr);
@@ -70,7 +68,15 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
 
 		debug("Found FIT\n");
 		spl_load_init(&load, spl_ram_load_read, NULL, 1);
-		ret = spl_load_simple_fit(spl_image, &load, 0, header);
+		ret = spl_load_simple_fit(spl_image, &load, (ulong)header, header);
+	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+		struct spl_load_info load;
+
+		memset(&load, 0, sizeof(load));
+		load.bl_len = 1;
+		load.read = spl_ram_load_read;
+
+		ret = spl_load_imx_container(spl_image, &load, (ulong)header);
 	} else {
 		ulong u_boot_pos = spl_get_image_pos();
 

-- 
2.34.1



More information about the U-Boot mailing list