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 95A69C433EF for ; Wed, 6 Jul 2022 10:59:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2DB3784542; Wed, 6 Jul 2022 12:59:24 +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=1657105164; bh=F630Y5A/4tvLS1Tz/nLDp4zdAnjdNvRGye4Vqet3urU=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ZUrPKRyXyld9ehm0O1RoNAyVilhw/P9Eg32pquHhc1OziGIiVH05cuQ6PZMwejT2R 2GFfSiSvHTGcQ+gJlSfdGtvv7eQC3GETfxZLfinuoojDORbtiKcKby53Hi5gizNK7G GbrD2XolRkF/z+L4IgLRMO+x1vKmBtbmzm0uMHqfg9SN+oVEv5NmeJaKPu13SpmdyQ uX5kph29P++458NZ/p1DIlfkJ7+OVAM/FsocGjaknZ9fCsgpaFaEr8WQg8S8Spb0eb p1Mrdaipd9TtYaKvjd7ulhGYAAzJAwq/QF8o1T6rEIIz8Xv7gKVhyAmz7SrflOLTHN cNYm1Hz0ORL1A== 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 7690B8452D; Wed, 6 Jul 2022 12:59:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1657105162; bh=F630Y5A/4tvLS1Tz/nLDp4zdAnjdNvRGye4Vqet3urU=; h=From:To:Cc:Subject:Date:From; b=j3K9BMHDQ963fscNr4OpBw0GxIpRqQEqZTt8eoP72ayFO3YhExbp2GKDyD4cn5RfB QR0Bs1pXUMV/hU0hPP2/Gmym4EsIxpTN9hIvfreAB53/mMpZUqC5QhEnAHob05F58V 57BZ+x5Qb4sIVsVNlHoxBzFPVo//4JM/zqubipc/AFqpq0TMcxGpWHttswKCa1Ic7U CkT+9BlGhL6pq08nTymigcB2gcz5T8nmD3RTG2XxR79QKSSHOQjOWVbcqnk8QInrwv h8jnWduZXfJnLDButbVn1qlluGWK1latWzdwP1Ygy6LvXhvzJdE2Q0D8n+nea5kyHy h7F4p8E2yO03w== From: Harald Seiler To: Peng Fan , Jaehoon Chung Cc: Marek Vasut , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Andreas Dannenberg , u-boot@lists.denx.de, Harald Seiler Subject: [PATCH] spl: mmc: Use correct MMC device when loading image Date: Wed, 6 Jul 2022 12:58:28 +0200 Message-Id: <20220706105828.783967-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 --- common/spl/spl_mmc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index e1a7d25bd0..22c8a8097c 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -371,9 +371,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 || mmc->block_dev.devnum != mmc_dev) { err = spl_mmc_find_device(&mmc, bootdev->boot_device); if (err) return err; -- 2.36.1