From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F3032FB1 for ; Mon, 24 May 2021 00:37:15 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CBA6311B3; Sun, 23 May 2021 17:37:09 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 564643F73D; Sun, 23 May 2021 17:37:08 -0700 (PDT) From: Andre Przywara To: Simon Glass , Jagan Teki Cc: u-boot@lists.denx.de, linux-sunxi@lists.linux.dev, Patrick Delaunay , Sean Anderson , Heiko Schocher , Kever Yang , Philipp Tomsich Subject: [RFC PATCH 2/3] sunxi: Implement fastboot_get_mmc_device() Date: Mon, 24 May 2021 01:36:49 +0100 Message-Id: <20210524003650.24469-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210524003650.24469-1-andre.przywara@arm.com> References: <20210524003650.24469-1-andre.przywara@arm.com> X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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 --- 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