[PATCH 18/18] arm64: versal-net: Add mmc_get_env_dev() and deduplicate MMC handling
Michal Simek
michal.simek at amd.com
Tue Jun 23 14:53:43 CEST 2026
The SD and eMMC cases in boot_targets_setup() duplicated the MMC device
lookup, and versal-net relied on the weak mmc_get_env_dev() default
instead of selecting the device matching the boot mode (unlike versal and
zynqmp).
Factor the lookup into mmc_get_bootseq(), mirroring spi_get_bootseq():
it maps the boot mode to the MMC node and returns the device sequence,
optionally handing back the mode banner so only boot_targets_setup()
prints it. mmc_get_env_dev() is now provided as a thin wrapper, and the
SD/eMMC cases call the helper instead of open-coding the lookups. The
local udevice pointer in boot_targets_setup() is no longer needed.
Signed-off-by: Michal Simek <michal.simek at amd.com>
---
board/xilinx/versal-net/board.c | 80 +++++++++++++++++++--------------
1 file changed, 47 insertions(+), 33 deletions(-)
diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index 9c0490cba980..ddac92660dfa 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -12,6 +12,7 @@
#include <env_internal.h>
#include <log.h>
#include <malloc.h>
+#include <mmc.h>
#include <spi.h>
#include <time.h>
#include <asm/cache.h>
@@ -110,10 +111,48 @@ int spi_get_env_dev(void)
return spi_get_bootseq(versal_net_get_bootmode(), NULL);
}
+static int mmc_get_bootseq(u8 bootmode, const char **modename)
+{
+ struct udevice *dev;
+ const char *name;
+
+ switch (bootmode) {
+ case SD_MODE:
+ if (modename)
+ *modename = "SD_MODE\n";
+ name = "mmc at f1040000";
+ break;
+ case EMMC_MODE:
+ if (modename)
+ *modename = "EMMC_MODE\n";
+ name = "mmc at f1050000";
+ break;
+ case SD_MODE1:
+ case SD1_LSHFT_MODE:
+ if (modename)
+ *modename = "SD_MODE1\n";
+ name = "mmc at f1050000";
+ break;
+ default:
+ return -1;
+ }
+
+ if (uclass_get_device_by_name(UCLASS_MMC, name, &dev)) {
+ debug("MMC driver for %s is not present\n", name);
+ return -1;
+ }
+
+ return dev_seq(dev);
+}
+
+int mmc_get_env_dev(void)
+{
+ return mmc_get_bootseq(versal_net_get_bootmode(), NULL);
+}
+
static int boot_targets_setup(void)
{
u8 bootmode;
- struct udevice *dev;
int bootseq = -1;
int bootseq_len = 0;
int env_targets_len = 0;
@@ -143,45 +182,20 @@ static int boot_targets_setup(void)
if (bootseq >= 0)
mode = "xspi";
break;
- case EMMC_MODE:
- puts("EMMC_MODE\n");
- if (uclass_get_device_by_name(UCLASS_MMC,
- "mmc at f1050000", &dev)) {
- debug("eMMC driver for eMMC device is not present\n");
- break;
- }
- mode = "mmc";
- bootseq = dev_seq(dev);
- break;
case SELECTMAP_MODE:
puts("SELECTMAP_MODE\n");
break;
- case SD_MODE:
- puts("SD_MODE\n");
- if (uclass_get_device_by_name(UCLASS_MMC,
- "mmc at f1040000", &dev)) {
- debug("SD0 driver for SD0 device is not present\n");
- break;
- }
- debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
-
- mode = "mmc";
- bootseq = dev_seq(dev);
- break;
case SD1_LSHFT_MODE:
puts("LVL_SHFT_");
fallthrough;
+ case SD_MODE:
+ case EMMC_MODE:
case SD_MODE1:
- puts("SD_MODE1\n");
- if (uclass_get_device_by_name(UCLASS_MMC,
- "mmc at f1050000", &dev)) {
- debug("SD1 driver for SD1 device is not present\n");
- break;
- }
- debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
-
- mode = "mmc";
- bootseq = dev_seq(dev);
+ bootseq = mmc_get_bootseq(bootmode, &modename);
+ if (modename)
+ puts(modename);
+ if (bootseq >= 0)
+ mode = "mmc";
break;
default:
printf("Invalid Boot Mode:0x%x\n", bootmode);
--
2.43.0
More information about the U-Boot
mailing list