Boards may need to read boot metadata before choosing the partition
containing U-Boot. The partition hook currently runs before the MMC
device is initialized, so it cannot do this reliably.

Defer selection until the raw partition load and provide the initialized
device to the existing hook. Explicit partition loads keep their supplied
coordinates, and a successful Falcon boot needs no U-Boot selection.

Signed-off-by: Carlo Caione <[email protected]>
---
 arch/arm/mach-stm32mp/stm32mp1/spl.c |  2 +-
 common/spl/spl_mmc.c                 |  7 +++++--
 include/spl.h                        | 15 +++++++++------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-stm32mp/stm32mp1/spl.c 
b/arch/arm/mach-stm32mp/stm32mp1/spl.c
index d2e41b8e65f..2229ebf5eeb 100644
--- a/arch/arm/mach-stm32mp/stm32mp1/spl.c
+++ b/arch/arm/mach-stm32mp/stm32mp1/spl.c
@@ -62,7 +62,7 @@ u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 }
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
-int spl_mmc_boot_partition(const u32 boot_device)
+int spl_mmc_boot_partition(struct mmc *mmc, const u32 boot_device)
 {
        switch (boot_device) {
        case BOOT_DEVICE_MMC1:
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index cc16709dc9b..3e637f5adbd 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -301,7 +301,7 @@ u32 __weak spl_mmc_boot_mode(struct mmc *mmc, const u32 
boot_device)
 }
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
-int __weak spl_mmc_boot_partition(const u32 boot_device)
+int __weak spl_mmc_boot_partition(struct mmc *mmc, const u32 boot_device)
 {
        return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
 }
@@ -431,6 +431,9 @@ int spl_mmc_load(struct spl_image_info *spl_image,
                        return 0;
 #elif defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION) || \
       defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE)
+               if (IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION) 
&&
+                   raw_part == -1)
+                       raw_part = spl_mmc_boot_partition(mmc, 
bootdev->boot_device);
                ret = mmc_load_image_raw_partition(spl_image, bootdev,
                                                   mmc, raw_part,
                                                   raw_sect);
@@ -466,7 +469,7 @@ int spl_mmc_load_image(struct spl_image_info *spl_image,
                            NULL,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
-                           spl_mmc_boot_partition(bootdev->boot_device),
+                           -1,
 #else
                            0,
 #endif
diff --git a/include/spl.h b/include/spl.h
index 5078d7525ab..08a84536f51 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -595,18 +595,20 @@ u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 
boot_device);
 
 /**
  * spl_mmc_boot_partition() - MMC partition to load U-Boot from.
+ * @mmc:               Initialized MMC device
  * @boot_device:       ID of the device which the MMC driver wants to load
  *                     U-Boot from.
  *
- * This function should return the partition number which the SPL
- * should load U-Boot from (on the given boot_device) when
- * CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION is set.
+ * Called before loading U-Boot in raw partition mode, after any Falcon
+ * attempt. The hook may select the hardware area containing the image;
+ * it must leave that area selected. It may run for each MMC load attempt.
  *
  * If not overridden, it is weakly defined in common/spl/spl_mmc.c.
+ *
+ * Return: Partition number to load U-Boot from.
  */
-int spl_mmc_boot_partition(const u32 boot_device);
+int spl_mmc_boot_partition(struct mmc *mmc, const u32 boot_device);
 
-struct mmc;
 /**
  * default_spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot 
from.
  * mmc:                        Pointer for the mmc device structure
@@ -972,7 +974,8 @@ int spl_mmc_load_image(struct spl_image_info *spl_image,
  * @param spl_image    Image data filled in by loading process
  * @param bootdev      Describes which device to load from
  * @param filename     Name of file to load (in FS mode)
- * @param raw_part     Partition to load from (in RAW mode)
+ * @param raw_part     Partition to load from (in RAW mode), or -1 to call
+ *                     spl_mmc_boot_partition() in partition-number mode
  * @param raw_sect     Sector to load from (in RAW mode)
  *
  * Return: 0 on success, otherwise error code

-- 
2.55.0

Reply via email to