Skip to contentSkip to conversation

spl: mmc: introduce spl_mmc_get_uboot_raw_sector

PATCH New peng.fan at nxp.com 1 participant 9 messages Sep 23, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/9 spl: mmc: introduce spl_mmc_get_uboot_raw_sector

From: Peng Fan <[email protected]>

Introduce a weak function spl_mmc_get_uboot_raw_sector, then platform could have their own implementation.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Andreas Dannenberg <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Michal Simek <[email protected]>

---

V2:
None

 common/spl/spl_mmc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
common/spl/spl_mmc.c +11 -0
index 6c6eaf4ec8..ebc566081a 100644
@@ -313,6 +313,15 @@ int spl_boot_partition(const u32 boot_device)
 }
 #endif
 
+unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
+{
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
+	return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
+#else
+	return 0;
+#endif
+}
+
 int spl_mmc_load(struct spl_image_info *spl_image,
 		 struct spl_boot_device *bootdev,
 		 const char *filename,
@@ -340,6 +349,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 		}
 	}
 
+	raw_sect = spl_mmc_get_uboot_raw_sector(mmc);
+
 	boot_mode = spl_boot_mode(bootdev->boot_device);
 	err = -EINVAL;
 	switch (boot_mode) {
Signature · 1 line
2.16.4
#1 lore raw

PATCH v2 2/9 spl: spi: introduce spl_spi_get_uboot_offs

From: Peng Fan <[email protected]>

Introduce a weak function spl_spi_get_uboot_offs, then platform could have their own implementation.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Andreas Dannenberg <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Michal Simek <[email protected]>

---

V2:
switch raw_sector to offs

 common/spl/spl_spi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
common/spl/spl_spi.c +9 -1
index 9b74473377..84f20ea4ed 100644
@@ -62,6 +62,12 @@ static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
 	else
 		return 0;
 }
+
+unsigned int __weak spl_spi_get_uboot_offs(struct spi_flash *flash)
+{
+	return CONFIG_SYS_SPI_U_BOOT_OFFS;
+}
+
 /*
  * The main entry for SPI booting. It's necessary that SDRAM is already
  * configured and available since this code loads the main U-Boot image
@@ -71,7 +77,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
 	int err = 0;
-	unsigned payload_offs = CONFIG_SYS_SPI_U_BOOT_OFFS;
+	unsigned int payload_offs;
 	struct spi_flash *flash;
 	struct image_header *header;
 
@@ -90,6 +96,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 		return -ENODEV;
 	}
 
+	payload_offs = spl_spi_get_uboot_offs(flash);
+
 	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
 
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Signature · 1 line
2.16.4
#2 lore raw

PATCH v2 3/9 spl: nor: introduce spl_nor_get_uboot_base

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

Introduce weak spl_nor_get_uboot_base, then platform have their own implementation.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Andreas Dannenberg <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Michal Simek <[email protected]>

---

V2:
None

 common/spl/spl_nor.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
common/spl/spl_nor.c +9 -4
index 969e319de0..0f8afa6f92 100644
@@ -18,6 +18,11 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 }
 #endif
 
+unsigned long __weak spl_nor_get_uboot_base(void)
+{
+	return CONFIG_SYS_UBOOT_BASE;
+}
+
 static int spl_nor_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
@@ -80,25 +85,25 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 	 * defined location in SDRAM
 	 */
 #ifdef CONFIG_SPL_LOAD_FIT
-	header = (const struct image_header *)CONFIG_SYS_UBOOT_BASE;
+	header = (const struct image_header *)spl_nor_get_uboot_base();
 	if (image_get_magic(header) == FDT_MAGIC) {
 		debug("Found FIT format U-Boot\n");
 		load.bl_len = 1;
 		load.read = spl_nor_load_read;
 		ret = spl_load_simple_fit(spl_image, &load,
-					  CONFIG_SYS_UBOOT_BASE,
+					  spl_nor_get_uboot_base(),
 					  (void *)header);
 
 		return ret;
 	}
 #endif
 	ret = spl_parse_image_header(spl_image,
-			(const struct image_header *)CONFIG_SYS_UBOOT_BASE);
+			(const struct image_header *)spl_nor_get_uboot_base());
 	if (ret)
 		return ret;
 
 	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
+	       (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
 	       spl_image->size);
 
 	return 0;
Signature · 1 line
2.16.4
#3 lore raw

PATCH v2 4/9 spl: nand: Introduce spl_nand_get_uboot_raw_page

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

Introduce weak spl_nand_get_uboot_raw_page, then platform could have their own implementation.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Andreas Dannenberg <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Michal Simek <[email protected]>

---

V2:
None

 common/spl/spl_nand.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/spl/spl_nand.c +7 -2
index e2bcefb111..d3185dc017 100644
@@ -11,6 +11,11 @@
 #include <linux/libfdt_env.h>
 #include <fdt.h>
 
+uint32_t __weak spl_nand_get_uboot_raw_page(void)
+{
+	return CONFIG_SYS_NAND_U_BOOT_OFFS;
+}
+
 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
 static int spl_nand_load_image(struct spl_image_info *spl_image,
 			struct spl_boot_device *bootdev)
@@ -21,7 +26,7 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 	       CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
 	       CONFIG_SYS_NAND_U_BOOT_DST);
 
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+	nand_spl_load_image(spl_nand_get_uboot_raw_page(),
 			    CONFIG_SYS_NAND_U_BOOT_SIZE,
 			    (void *)CONFIG_SYS_NAND_U_BOOT_DST);
 	spl_set_header_raw_uboot(spl_image);
@@ -139,7 +144,7 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 #endif
 #endif
 	/* Load u-boot */
-	err = spl_nand_load_element(spl_image, CONFIG_SYS_NAND_U_BOOT_OFFS,
+	err = spl_nand_load_element(spl_image, spl_nand_get_uboot_raw_page(),
 				    header);
 #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
 #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
Signature · 1 line
2.16.4
#4 lore raw

PATCH v2 5/9 imx8: Add support to get container image set size

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

To avoid hardcoded offset when adding u-boot.cnt to flash.bin, we use flexible offset which is calculated based on the size of the container image generated int the first stage. And pad u-boot.cnt at 1KB alignment.

So add code to get the offset when SPL loading u-boot.cnt.

---

V2:
None

 arch/arm/mach-imx/Makefile      |   9 +-
 arch/arm/mach-imx/imx8/Makefile |   2 +-
 arch/arm/mach-imx/imx8/image.c  | 246 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 255 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-imx/imx8/image.c
arch/arm/mach-imx/Makefile +8 -1
index 199b2df22b..46bc2a21e2 100644
@@ -169,9 +169,16 @@ u-boot.cnt: MKIMAGEOUTPUT = u-boot.cnt.log
 ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y)
 u-boot.cnt: u-boot.bin container.cfg FORCE
 	$(call if_changed,mkimage)
-endif
 flash.bin: spl/u-boot-spl.bin FORCE
 	$(call if_changed,mkimage)
+	@flashbin_size=`wc -c flash.bin | awk '{print $$1}'`; \
+                   pad_cnt=$$(((flashbin_size + 0x400 - 1) / 0x400)); \
+                   echo "append u-boot.cnt at $$pad_cnt KB"; \
+                   dd if=u-boot.cnt of=flash.bin bs=1K seek=$$pad_cnt;
+else
+flash.bin: spl/u-boot-spl.bin FORCE
+	$(call if_changed,mkimage)
+endif
 endif
 
 else
arch/arm/mach-imx/imx8/Makefile +1 -1
index 97f9d22945..39e384d5c7 100644
@@ -8,5 +8,5 @@ obj-y += cpu.o iomux.o misc.o lowlevel_init.o
 obj-$(CONFIG_OF_SYSTEM_SETUP) += fdt.o
 
 ifdef CONFIG_SPL_BUILD
-obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += parse-container.o
+obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image.o parse-container.o
 endif
arch/arm/mach-imx/imx8/image.c new file +246 -0

246 lines not on this page · raw message

Signature · 1 line
2.16.4
#5 lore raw

PATCH v2 6/9 imx8: update README

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

After u-boot.cnt is padded to flash.bin automatically by script, no need to burn the image mannually, so drop the step.

---

V2:
None

 board/freescale/imx8qm_mek/README  | 1 -
 board/freescale/imx8qxp_mek/README | 1 -
 2 files changed, 2 deletions(-)
board/freescale/imx8qm_mek/README +0 -1
index ebf630c446..a187ad8a09 100644
@@ -41,7 +41,6 @@ Build U-Boot
 ============
 $ make imx8qm_mek_defconfig
 $ make flash.bin
-$ dd if=u-boot.cnt of=flash.bin bs=512 seek=1984
 
 Flash the binary into the SD card
 =================================
board/freescale/imx8qxp_mek/README +0 -1
index 1ee0357961..e676e88664 100644
@@ -41,7 +41,6 @@ Build U-Boot
 ============
 $ make imx8qxp_mek_defconfig
 $ make flash.bin
-$ dd if=u-boot.cnt of=flash.bin bs=512 seek=1984
 
 Flash the binary into the SD card
 =================================
Signature · 1 line
2.16.4
#6 lore raw

PATCH v2 7/9 spl: nand: support loading i.MX container format file

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

i.MX8 only support AHAB secure boot with Container format image, we could not use FIT to support secure boot, so introduce container support to let SPL could load container images.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc York Sun <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>
Cc Heiko Schocher <[email protected]>

---

V2:
New

 common/spl/spl_nand.c | 9 +++++++++
 1 file changed, 9 insertions(+)
common/spl/spl_nand.c +9 -0
index d3185dc017..5f8a111a2f 100644
@@ -68,6 +68,15 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.bl_len = 1;
 		load.read = spl_nand_fit_read;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
+	} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+		struct spl_load_info load;
+
+		load.dev = NULL;
+		load.priv = NULL;
+		load.filename = NULL;
+		load.bl_len = 1;
+		load.read = spl_nand_fit_read;
+		return spl_load_imx_container(spl_image, &load, offset);
 	} else {
 		err = spl_parse_image_header(spl_image, header);
 		if (err)
Signature · 1 line
2.16.4
#7 lore raw

PATCH v2 8/9 spl: spi: support loading i.MX container format file

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

i.MX8 only support AHAB secure boot with Container format image, we could not use FIT to support secure boot, so introduce container support to let SPL could load container images.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc York Sun <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>
Cc Heiko Schocher <[email protected]>

---

V2:
New

 common/spl/spl_spi.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
common/spl/spl_spi.c +11 -0
index 84f20ea4ed..288dbb5fa9 100644
@@ -141,6 +141,17 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 			err = spl_load_simple_fit(spl_image, &load,
 						  payload_offs,
 						  header);
+		} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+			struct spl_load_info load;
+
+			load.dev = flash;
+			load.priv = NULL;
+			load.filename = NULL;
+			load.bl_len = 1;
+			load.read = spl_spi_fit_read;
+
+			err = spl_load_imx_container(spl_image, &load,
+						     payload_offs);
 		} else {
 			err = spl_parse_image_header(spl_image, header);
 			if (err)
Signature · 1 line
2.16.4
#8 lore raw

PATCH v2 9/9 spl: nor: support loading i.MX container format file

In reply to peng.fan at nxp.com

From: Peng Fan <[email protected]>

i.MX8 only support AHAB secure boot with Container format image, we could not use FIT to support secure boot, so introduce container support to let SPL could load container images.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc York Sun <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>
Cc Heiko Schocher <[email protected]>

---

V2:
New

 common/spl/spl_nor.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/spl/spl_nor.c +7 -2
index 0f8afa6f92..7df708de9b 100644
@@ -6,7 +6,6 @@
 #include <common.h>
 #include <spl.h>
 
-#ifdef CONFIG_SPL_LOAD_FIT
 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 			       ulong count, void *buf)
 {
@@ -16,7 +15,6 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 
 	return count;
 }
-#endif
 
 unsigned long __weak spl_nor_get_uboot_base(void)
 {
@@ -97,6 +95,13 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 		return ret;
 	}
 #endif
+	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+		load.bl_len = 1;
+		load.read = spl_nor_load_read;
+		return spl_load_imx_container(spl_image, &load,
+					      spl_nor_get_uboot_base());
+	}
+
 	ret = spl_parse_image_header(spl_image,
 			(const struct image_header *)spl_nor_get_uboot_base());
 	if (ret)
Signature · 1 line
2.16.4