Skip to contentSkip to conversation

spl: mmc: introduce spl_mmc_get_uboot_raw_sector

PATCH Superseded Peng Fan 2 participants 8 messages Sep 20, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/6 spl: mmc: introduce spl_mmc_get_uboot_raw_sector

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]>
---
 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
author
#1 lore raw

PATCH 2/6 spl: spi: introduce spl_spi_get_uboot_raw_sector

Introduce a weak function spl_spi_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]>
---
 common/spl/spl_spi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
common/spl/spl_spi.c +9 -1
index 9b74473377..1ba0e497d2 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_raw_sector(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_raw_sector(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 2/6 spl: spi: introduce spl_spi_get_uboot_raw_sector

Hi Peng,

Quoted 44 lines · Peng Fan

Introduce a weak function spl_spi_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]>
---
  common/spl/spl_spi.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
common/spl/spl_spi.c +7 -1
index 9b74473377..1ba0e497d2 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_raw_sector(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;
 

common/spl/spl_spi.c static int spl_spi_load_image(struct spl_image_info *spl_image, · line 99

Quoted 4 lines
common/spl/spl_spi.c +1 -0
@@ -90,6 +96,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
  		return -ENODEV;
  	}
 
+	payload_offs = spl_spi_get_uboot_raw_sector(flash);

I don't really like the function name here "_raw_sector" as this is not a sector number in SPI flash but an address offset.

Thanks,
Stefan

author
#3 lore raw

PATCH 2/6 spl: spi: introduce spl_spi_get_uboot_raw_sector

Quoted 52 lines

Subject: Re: [PATCH 2/6] spl: spi: introduce spl_spi_get_uboot_raw_sector

Hi Peng,

common/spl/spl_spi.c static ulong spl_spi_fit_read(struct spl_load_info

Quoted 22 lines · Peng Fan

Introduce a weak function spl_spi_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]>
---
  common/spl/spl_spi.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
common/spl/spl_spi.c index renamed from common/spl/spl_spi.c +0 -0

9b74473377..1ba0e497d2 100644

common/spl/spl_spi.c +0 -0
@@ -62,6 +62,12 @@ static ulong spl_spi_fit_read(struct spl_load_info

*load, ulong sector,

Quoted 12 lines
common/spl/spl_spi.c +6 -0
  	else
  		return 0;
  }
+
+unsigned int __weak spl_spi_get_uboot_raw_sector(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
Quoted 1 line

image @@ -71,7 +77,7 @@ static int spl_spi_load_image(struct

spl_image_info *spl_image,

common/spl/spl_spi.c static int spl_spi_load_image(struct spl_image_info

Quoted 9 lines
  			      struct spl_boot_device *bootdev)
  {
  	int err = 0;
common/spl/spl_spi.c +1 -1
-	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,

Quoted 7 lines

common/spl/spl_spi.c static int spl_spi_load_image(struct spl_image_info *spl_image, · line 99

Quoted 4 lines
common/spl/spl_spi.c +1 -0
  		return -ENODEV;
  	}
 
+	payload_offs = spl_spi_get_uboot_raw_sector(flash);

I don't really like the function name here "_raw_sector" as this is not a sector number in SPI flash but an address offset.

Oh, yes. spl_spi_get_uboot_offs should be fine.

Thanks,
Peng.

Quoted 3 lines

Thanks,
Stefan

author
#4 lore raw

PATCH 3/6 spl: nor: introduce spl_nor_get_uboot_base

In reply to Peng Fan

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]>
---
 common/spl/spl_nor.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
common/spl/spl_nor.c +9 -4
index 969e319de0..cb5d12d53d 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
author
#5 lore raw

PATCH 4/6 spl: nand: Introduce spl_nand_get_uboot_raw_page

In reply to Peng Fan

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]>
---
 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
author
#6 lore raw

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

In reply to Peng Fan

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.

---
 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
author
#7 lore raw

PATCH 6/6 imx8: update README

In reply to Peng Fan

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

---
 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