From patchwork Mon May 24 00:36:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 1482583 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FpJG13TC4z9s5R for ; Mon, 24 May 2021 10:37:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8384D82E85; Mon, 24 May 2021 02:37:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0FACB82E6A; Mon, 24 May 2021 02:37:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id A202982E6D for ; Mon, 24 May 2021 02:37:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com 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-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean 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)