[PATCH v3 1/2] spl: mmc: Pass eMMC HW partition and SW partition to spl_mmc_get_uboot_raw_sector()

Marek Vasut marex at denx.de
Tue Apr 4 20:05:14 CEST 2023


Pass both eMMC HW partition and software partition numbers to
spl_mmc_get_uboot_raw_sector() so the function can better decide
which offset within the partition to load payload from.

Signed-off-by: Fedor Ross <fedor.ross at ifm.com>
Signed-off-by: Marek Vasut <marex at denx.de>
---
Cc: Jaehoon Chung <jh80.chung at samsung.com>
Cc: Peng Fan <peng.fan at nxp.com>
---
V2: No change
V3: Update on u-boot/master, update spl.h function prototype
---
 arch/arm/mach-imx/image-container.c               |  2 ++
 arch/arm/mach-sunxi/board.c                       |  2 ++
 .../advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c |  4 +++-
 common/spl/spl_mmc.c                              | 15 +++++++++------
 include/spl.h                                     |  4 ++++
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/image-container.c b/arch/arm/mach-imx/image-container.c
index 5b059a64292..2eb8d5f6b9d 100644
--- a/arch/arm/mach-imx/image-container.c
+++ b/arch/arm/mach-imx/image-container.c
@@ -216,6 +216,8 @@ unsigned long spl_spi_get_uboot_offs(struct spi_flash *flash)
 
 #ifdef CONFIG_SPL_MMC
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect)
 {
 	int end;
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 391a65a5495..3be444d84fe 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -324,6 +324,8 @@ uint32_t sunxi_get_spl_size(void)
  * immediately follow the SPL if that is bigger than that.
  */
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect)
 {
 	unsigned long spl_size = sunxi_get_spl_size();
diff --git a/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c b/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
index 466174679e8..af9d0040261 100644
--- a/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
+++ b/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
@@ -194,7 +194,9 @@ int board_late_init(void)
 #ifdef CONFIG_SPL_MMC
 #define UBOOT_RAW_SECTOR_OFFSET 0x40
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
-					   unsigned long raw_sector)
+					   unsigned long hw_part,
+					   unsigned long raw_part,
+					   unsigned long raw_sect);
 {
 	u32 boot_dev = spl_boot_device();
 
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index bd5e6adf1ea..f1f87d78ba7 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -362,6 +362,8 @@ int __weak spl_mmc_boot_partition(const u32 boot_device)
 #endif
 
 unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+						  unsigned long hw_part,
+						  unsigned long raw_part,
 						  unsigned long raw_sect)
 {
 	return raw_sect;
@@ -410,7 +412,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	static struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
-	__maybe_unused int part = 0;
+	__maybe_unused int hw_part = 0;
 	int mmc_dev;
 
 	/* Perform peripheral init only once for an mmc device */
@@ -434,12 +436,12 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	err = -EINVAL;
 	switch (boot_mode) {
 	case MMCSD_MODE_EMMCBOOT:
-		part = spl_mmc_emmc_boot_partition(mmc);
+		hw_part = spl_mmc_emmc_boot_partition(mmc);
 
 		if (CONFIG_IS_ENABLED(MMC_TINY))
-			err = mmc_switch_part(mmc, part);
+			err = mmc_switch_part(mmc, hw_part);
 		else
-			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
+			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), hw_part);
 
 		if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -457,7 +459,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 				return err;
 		}
 
-		raw_sect = spl_mmc_get_uboot_raw_sector(mmc, raw_sect);
+		raw_sect = spl_mmc_get_uboot_raw_sector(mmc, hw_part,
+							raw_part, raw_sect);
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 		err = mmc_load_image_raw_partition(spl_image, bootdev,
@@ -468,7 +471,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		err = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
-				raw_sect + spl_mmc_raw_uboot_offset(part));
+				raw_sect + spl_mmc_raw_uboot_offset(hw_part));
 		if (!err)
 			return err;
 #endif
diff --git a/include/spl.h b/include/spl.h
index 7e0f5ac63b0..5e174547f26 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -473,10 +473,14 @@ void spl_set_bd(void);
  * where the start of the U-Boot image has been written to.
  *
  * @mmc: struct mmc that describes the devie where U-Boot resides
+ * @hw_part: The eMMC hardware partition where U-Boot is by default.
+ * @raw_part: The software partition where U-Boot is by default.
  * @raw_sect: The raw sector number where U-Boot is by default.
  * Return: The raw sector location that U-Boot resides at
  */
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect);
 
 /**
-- 
2.39.2



More information about the U-Boot mailing list