[PATCH] zynqmp: Dynamic setting mmcdev and mmcroot

egyszeregy at freemail.hu egyszeregy at freemail.hu
Thu Jan 30 22:57:06 CET 2025


From: Benjamin Szőke <egyszeregy at freemail.hu>

Dynamic setting mmcdev and mmcroot.
Then when boot linux, we can have correct "root=/dev/mmcblk[x]p2"

ref: board/freescale/common/mmc.c
https://github.com/u-boot/u-boot/blob/master/board/freescale/common/mmc.c

Signed-off-by: Benjamin Szőke <egyszeregy at freemail.hu>
---
 board/xilinx/zynqmp/zynqmp.c    | 18 ++++++++++++++++++
 include/configs/xilinx_zynqmp.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 8cdd9d8600..d450b53982 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -401,10 +401,14 @@ static int boot_targets_setup(void)
 	struct udevice *dev;
 	int bootseq = -1;
 	int bootseq_len = 0;
+	int mmc_dev_no = -1;
 	int env_targets_len = 0;
 	const char *mode = NULL;
 	char *new_targets;
 	char *env_targets;
+	char *autodetect_str = env_get("mmcautodetect");
+	char cmd[32];
+	char mmcblk[32];
 
 	bootmode = zynqmp_get_bootmode();
 
@@ -438,6 +442,7 @@ static int boot_targets_setup(void)
 		debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
 
 		mode = "mmc";
+		mmc_dev_no = 0;
 		bootseq = dev_seq(dev);
 		env_set("modeboot", "emmcboot");
 		break;
@@ -453,6 +458,7 @@ static int boot_targets_setup(void)
 		debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
 
 		mode = "mmc";
+		mmc_dev_no = 0;
 		bootseq = dev_seq(dev);
 		env_set("modeboot", "sdboot");
 		break;
@@ -471,6 +477,7 @@ static int boot_targets_setup(void)
 		debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
 
 		mode = "mmc";
+		mmc_dev_no = 1;
 		bootseq = dev_seq(dev);
 		env_set("modeboot", "sdboot");
 		break;
@@ -513,6 +520,17 @@ static int boot_targets_setup(void)
 
 		env_set("boot_targets", new_targets);
 		free(new_targets);
+
+		if ((autodetect_str && !strcmp(autodetect_str, "yes")) && (mmc_dev_no >= 0)) {
+			env_set_ulong("mmcdev", (unsigned long)mmc_dev_no);
+
+			/* Set mmcblk env */
+			sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", mmc_dev_no);
+			env_set("mmcroot", mmcblk);
+
+			sprintf(cmd, "mmc dev %d", mmc_dev_no);
+			run_command(cmd, 0);
+		}
 	}
 
 	return 0;
diff --git a/include/configs/xilinx_zynqmp.h b/include/configs/xilinx_zynqmp.h
index bb0db7c5ca..1113101717 100644
--- a/include/configs/xilinx_zynqmp.h
+++ b/include/configs/xilinx_zynqmp.h
@@ -180,6 +180,7 @@
 #define CFG_EXTRA_ENV_SETTINGS \
 	ENV_MEM_LAYOUT_SETTINGS \
 	BOOTENV
+	"mmcautodetect=yes\0"
 #endif
 
 /* SPL can't handle all huge variables - define just DFU */
-- 
2.47.1.windows.2



More information about the U-Boot mailing list