Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04DF1CCA481 for ; Mon, 11 Jul 2022 12:35:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F084583EF2; Mon, 11 Jul 2022 14:35:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1657542945; bh=g8qChjxsD8cH1Sk9Q6/vJns8+Cgh1Tjp8zVM2NiJrYk=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=d5sy4OpOYVomnqXW/MYB/prYkA19AnjMcgX7aBEzz7m+HUjgRzLUUNHEy26RxwtxE 6FQRPrMbd7s4HfLt97AUgy/EDioyCYPdE08KsWFX1gTRaDn1JzedRG0dBVoPd5l54M kpzHFXXdSGoDStncIcJKGPX2v3nPjwBGc3HHJtKWPN7D5Us7lZkcnpHN3sJe+0fr4L 0vW9o1Qcju5NHoyElPhSabYX6CqkAWS+SF1BMZxBqD0gCVZra+QZNm/zO/k7vJTZ5W d2kgnk7Ep5LEeLwFGYXlCwU5+cS5rIZIi3U9HY+UFAzJoqx7lQxgyUHpYIgwZdjVL6 O0Max4Ss95fJA== Received: from maia.denx.de (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: hws@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 9373C83FDE; Mon, 11 Jul 2022 14:35:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1657542942; bh=g8qChjxsD8cH1Sk9Q6/vJns8+Cgh1Tjp8zVM2NiJrYk=; h=From:To:Cc:Subject:Date:From; b=Gk9XXFBjcEbml1htWrXaC+QRgXcZpV4QQ/O1fdx0pwJlrlR3K8vd4ezR0ZWamRwwJ 6+iS0+mDlkcuWVFpCPUF8HQAzIVmrONF6XsbNE+Mp4xZqOn/OmsjMUQSk8Gtmn/v5M jsi49t3BGJ6t8/JS/R86L5+j4BokofRU0kXWeyE18n+gaBkBf2x9QpdIFkPp1vBCge 4giyriZlABgRwuxnFB9ALSag05ndHvxB6qQcGALecP8TwRESPGc0dYgKAkClghOX85 DaahuF2lM4ZztiTDWGKq5beKJgEPLBexnGZ4nnpkEHeE4b9hL1BAUxkbO2BIq9oHxk cfNk9z4u7+n0Q== From: Harald Seiler To: Peng Fan , Jaehoon Chung Cc: Quentin Schulz , Marek Vasut , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Andreas Dannenberg , u-boot@lists.denx.de, Harald Seiler Subject: [PATCH v2] spl: mmc: Use correct MMC device when loading image Date: Mon, 11 Jul 2022 14:35:32 +0200 Message-Id: <20220711123532.219426-1-hws@denx.de> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean When attempting to load images from multiple MMC devices in sequence, spl_mmc_load() chooses the wrong device from the second attempt onwards. The reason is that MMC initialization is only done on its first call and spl_mmc_load() will then continue using this same device for all future calls. Fix this by checking the devnum of the "cached" device struct against the one which is requested. If they match, use the cached one but if they do not match, initialize the new device. This fixes specifying multiple MMC devices in the SPL's boot order to fall back when U-Boot Proper is corrupted or missing on the first attempted MMC device. Fixes: e1eb6ada4e38 ("spl: Make image loader infrastructure more universal") Signed-off-by: Harald Seiler --- Notes: Changes in v2: - Make it work with CONFIG_SPL_BLK as well common/spl/spl_mmc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index e1a7d25bd0..1c12f69d96 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -361,6 +361,17 @@ int __weak spl_mmc_emmc_boot_partition(struct mmc *mmc) return default_spl_mmc_emmc_boot_partition(mmc); } +static int spl_mmc_get_mmc_devnum(struct mmc *mmc) +{ + struct blk_desc *block_dev; +#if !CONFIG_IS_ENABLED(BLK) + block_dev = &mmc->block_dev; +#else + block_dev = dev_get_uclass_plat(mmc->dev); +#endif + return block_dev->devnum; +} + int spl_mmc_load(struct spl_image_info *spl_image, struct spl_boot_device *bootdev, const char *filename, @@ -371,9 +382,11 @@ int spl_mmc_load(struct spl_image_info *spl_image, u32 boot_mode; int err = 0; __maybe_unused int part = 0; + int mmc_dev; - /* Perform peripheral init only once */ - if (!mmc) { + /* Perform peripheral init only once for an mmc device */ + mmc_dev = spl_mmc_get_device_index(bootdev->boot_device); + if (!mmc || spl_mmc_get_mmc_devnum(mmc) != mmc_dev) { err = spl_mmc_find_device(&mmc, bootdev->boot_device); if (err) return err; -- 2.36.1