[PATCH 1/1] Add mmc_set_env_dev to TI AM33xx, using the scratch reg of UART port

Da Shi Cao dscao999 at hotmail.com
Mon May 9 07:15:25 CEST 2022


Signed-off-by: Dashi Cao <dscao999 at gmail.com>
---
 board/ti/am335x/board.c | 40 ++++++++++++++++++++++++++++++++++++++++
 common/spl/spl.c        |  6 ++++++
 drivers/mmc/mmc.c       |  4 ++++
 include/mmc.h           |  1 +
 4 files changed, 51 insertions(+)

diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index 7c0545892c..577e4f2b1f 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -1010,3 +1010,43 @@ U_BOOT_DRVINFO(am335x_mmc1) = {
 	.plat = &am335x_mmc1_plat,
 };
 #endif
+
+#if  defined(CONFIG_SPL_MMC) && defined(CONFIG_AM33XX)
+struct uart_reg {
+	u16 resv0[4];
+	u16 uart_efr;
+	u16 resv1[3];
+	u16 uart_mcr;
+	u16 resv2[5];
+	u16 uart_spr;
+};
+
+int mmc_get_env_dev(void)
+{
+	u16 bdev = 0;
+	u16 efr, mcr;
+	volatile struct uart_reg *uart = (void *)UART0_BASE;
+
+	efr = uart->uart_efr;
+	mcr = uart->uart_mcr;
+	if ((efr & 0x10) == 0 || (mcr & 0x40) == 0)
+		bdev = uart->uart_spr;
+	else
+		printf("Cannot get mmc dev number from uart0 scratch reg\n");
+
+	return (bdev & 0x0ff);
+}
+
+void mmc_set_env_dev(u16 bdev)
+{
+	u16 efr, mcr;
+	volatile struct uart_reg *uart = (void *)UART0_BASE;
+
+	efr = uart->uart_efr;
+	mcr = uart->uart_mcr;
+	if ((efr & 0x10) == 0 || (mcr & 0x40) == 0)
+		uart->uart_spr = (bdev & 0x0ff);
+	else
+		printf("Cannot set mmc dev number to uart0 scratch reg\n");
+}
+#endif
diff --git a/common/spl/spl.c b/common/spl/spl.c
index c8c463f80b..a14ae76698 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -37,6 +37,7 @@
 #include <fdt_support.h>
 #include <bootcount.h>
 #include <wdt.h>
+#include <mmc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -723,6 +724,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	};
 	struct spl_image_info spl_image;
 	int ret;
+	short bootdev;
 
 	debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
 
@@ -798,6 +800,10 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 			puts(SPL_TPL_PROMPT "failed to boot from all boot devices\n");
 		hang();
 	}
+	bootdev = spl_image.boot_device - BOOT_DEVICE_MMC1;
+	if (bootdev < 0)
+		bootdev = -bootdev;
+	mmc_set_env_dev(bootdev);
 
 	spl_perform_fixups(&spl_image);
 	if (CONFIG_IS_ENABLED(HANDOFF)) {
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 8a7d073900..8c941b575a 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -3133,3 +3133,7 @@ __weak int mmc_get_env_dev(void)
 	return 0;
 #endif
 }
+
+__weak void mmc_set_env_dev(u16 bootdev)
+{
+}
diff --git a/include/mmc.h b/include/mmc.h
index 9b4dc68311..3c09652382 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -943,6 +943,7 @@ int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr);
 extern uint mmc_get_env_part(struct mmc *mmc);
 # endif
 int mmc_get_env_dev(void);
+void mmc_set_env_dev(u16 bootdev);
 
 /* Minimum partition switch timeout in units of 10-milliseconds */
 #define MMC_MIN_PART_SWITCH_TIME	30 /* 300 ms */
-- 
2.20.1


More information about the U-Boot mailing list