[RFC PATCH 2/3] sunxi: Implement fastboot_get_mmc_device()

Andre Przywara andre.przywara at arm.com
Mon May 24 02:36:49 CEST 2021


The default MMC device to use for the fastboot flash command is hard to
decide at runtime, since the numbering of the MMC devices depends on
devicetree nodes. On the hardware side, the eMMC is connected to device
2, but this might be U-Boot's device 1 or 2, depending on whether the DT
contains a WiFi node for the hardware MMC1 device.

To avoid hardcoding this for each board, let's scan all MMC devices, and
try to find the eMMC device, given that this is enabled. If not, we use
the SD card.

Signed-off-by: Andre Przywara <andre.przywara at arm.com>
---
 board/sunxi/board.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 21651a1bfca..5f64887e48b 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -625,6 +625,43 @@ int board_mmc_init(struct bd_info *bis)
 }
 #endif
 
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
+int fastboot_get_mmc_device(void)
+{
+	struct udevice *dev;
+	static int mmc_dev = -1;
+	int sd_card = -1;
+
+	if (mmc_dev != -1)
+		return mmc_dev;
+
+	for (uclass_first_device(UCLASS_MMC, &dev);
+	     dev;
+	     uclass_next_device(&dev)) {
+		struct mmc *mmc = mmc_get_mmc_dev(dev);
+
+		mmc_init(mmc);
+		if (!mmc->has_init)
+			continue;
+
+		if (IS_SD(mmc)) {
+			sd_card = dev->seq_;
+			continue;
+		} else {
+			mmc_dev =  dev->seq_;
+			break;
+		}
+	}
+
+	if (mmc_dev == -1)
+		mmc_dev = sd_card;
+	if (mmc_dev == -1)
+		mmc_dev = 0;
+
+	return mmc_dev;
+}
+#endif
+
 #ifdef CONFIG_SPL_BUILD
 
 static void sunxi_spl_store_dram_size(phys_addr_t dram_size)
-- 
2.17.5



More information about the U-Boot mailing list