aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Seiler <hws@denx.de>2022-07-11 14:35:32 +0200
committerTom Rini <trini@konsulko.com>2022-08-04 13:59:59 -0400
commitbf28d9a65999bcf60425e65a7daf0d539838a845 (patch)
tree9960ed3d750ff60521aa23915f1a85405db12f55
parentc588ca873488605b3b4ee9fa756b2e25d3bd167a (diff)
downloadu-boot-bf28d9a65999bcf60425e65a7daf0d539838a845.zip
u-boot-bf28d9a65999bcf60425e65a7daf0d539838a845.tar.gz
u-boot-bf28d9a65999bcf60425e65a7daf0d539838a845.tar.bz2
spl: mmc: Use correct MMC device when loading image
When attempting to load images from multiple MMC devices in sequence, spl_mmc_load() chooses the wrong device from the second attempt onwards. The reason is that MMC initialization is only done on its first call and spl_mmc_load() will then continue using this same device for all future calls. Fix this by checking the devnum of the "cached" device struct against the one which is requested. If they match, use the cached one but if they do not match, initialize the new device. This fixes specifying multiple MMC devices in the SPL's boot order to fall back when U-Boot Proper is corrupted or missing on the first attempted MMC device. Fixes: e1eb6ada4e38 ("spl: Make image loader infrastructure more universal") Signed-off-by: Harald Seiler <hws@denx.de>
-rw-r--r--common/spl/spl_mmc.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index f661474..23a395e 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -398,6 +398,17 @@ int __weak spl_mmc_emmc_boot_partition(struct mmc *mmc)
return default_spl_mmc_emmc_boot_partition(mmc);
}
+static int spl_mmc_get_mmc_devnum(struct mmc *mmc)
+{
+ struct blk_desc *block_dev;
+#if !CONFIG_IS_ENABLED(BLK)
+ block_dev = &mmc->block_dev;
+#else
+ block_dev = dev_get_uclass_plat(mmc->dev);
+#endif
+ return block_dev->devnum;
+}
+
int spl_mmc_load(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
const char *filename,
@@ -408,9 +419,11 @@ int spl_mmc_load(struct spl_image_info *spl_image,
u32 boot_mode;
int err = 0;
__maybe_unused int part = 0;
+ int mmc_dev;
- /* Perform peripheral init only once */
- if (!mmc) {
+ /* Perform peripheral init only once for an mmc device */
+ mmc_dev = spl_mmc_get_device_index(bootdev->boot_device);
+ if (!mmc || spl_mmc_get_mmc_devnum(mmc) != mmc_dev) {
err = spl_mmc_find_device(&mmc, bootdev->boot_device);
if (err)
return err;