All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: Martin Rowe <martin.p.rowe@gmail.com>, u-boot@lists.denx.de
Subject: [PATCH v2 u-boot-mvebu 2/4] mmc: Read eMMC partition access bits before card reset
Date: Thu, 13 Apr 2023 22:57:48 +0200	[thread overview]
Message-ID: <20230413205750.10641-3-pali@kernel.org> (raw)
In-Reply-To: <20230413205750.10641-1-pali@kernel.org>

eMMC specification in section "Access partitions" says that all reset
events will restore the access bits in PARTITION_CONFIG CSD register to
default User Data Area value (0b000).

So read partition access bits from PARTITION_CONFIG CSD register before
issuing card reset. This allows SPL/U-Boot to get information which eMMC
partition was in use before SPL/U-Boot was booted. For some platforms this
is the way how to determinate boot partition from which BootROM loaded SPL.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/mmc/mmc.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index dde251c87bc7..771432de354d 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2329,8 +2329,17 @@ static int mmc_startup_v4(struct mmc *mmc)
 	/* store the partition info of emmc */
 	mmc->part_support = ext_csd[EXT_CSD_PARTITIONING_SUPPORT];
 	if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
-	    ext_csd[EXT_CSD_BOOT_MULT])
-		mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
+	    ext_csd[EXT_CSD_BOOT_MULT]) {
+		/*
+		 * At this stage PART_ACCESS_MASK bits in ext_csd[] are already cleared.
+		 * But it is possible that they were already filled into mmc->part_config.
+		 */
+		if (mmc->part_config == MMCPART_NOAVAILABLE)
+			mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
+		else
+			mmc->part_config = (ext_csd[EXT_CSD_PART_CONF] & ~PART_ACCESS_MASK) |
+					   (mmc->part_config & PART_ACCESS_MASK);
+	}
 	if (part_completed &&
 	    (ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & ENHNCD_SUPPORT))
 		mmc->part_attr = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE];
@@ -2600,7 +2609,6 @@ static int mmc_startup(struct mmc *mmc)
 #if CONFIG_IS_ENABLED(MMC_WRITE)
 	mmc->erase_grp_size = 1;
 #endif
-	mmc->part_config = MMCPART_NOAVAILABLE;
 
 	err = mmc_startup_v4(mmc);
 	if (err)
@@ -2848,9 +2856,26 @@ int mmc_get_op_cond(struct mmc *mmc, bool quiet)
 		return err;
 	mmc->ddr_mode = 0;
 
+	mmc->part_config = MMCPART_NOAVAILABLE;
+
 retry:
 	mmc_set_initial_state(mmc);
 
+	/*
+	 * Read partition access bits from partition config register before card reset command
+	 * because these bits are reset to default value (User Data Area) during card reset.
+	 * This allows us to preserve original value of partition access bits used by the code
+	 * which loaded us (for example BootROM) and use it for board specific boot purposes.
+	 */
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+		err = mmc_send_ext_csd(mmc, ext_csd);
+		if (err == 0 &&
+		    ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
+		     ext_csd[EXT_CSD_BOOT_MULT]))
+			mmc->part_config = ext_csd[EXT_CSD_PART_CONF] & PART_ACCESS_MASK;
+	}
+
 	/* Reset the Card */
 	err = mmc_go_idle(mmc);
 
-- 
2.20.1


  parent reply	other threads:[~2023-04-13 20:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 20:57 [PATCH v2 u-boot-mvebu 0/4] arm: mvebu: Fix eMMC boot Pali Rohár
2023-04-13 20:57 ` [PATCH v2 u-boot-mvebu 1/4] tools: kwboot: Fix MMC partitions documentation Pali Rohár
2023-04-13 20:57 ` Pali Rohár [this message]
2023-04-13 20:57 ` [PATCH v2 u-boot-mvebu 3/4] arm: mvebu: spl: Load proper U-Boot from correct eMMC partition Pali Rohár
2023-04-13 20:57 ` [PATCH v2 u-boot-mvebu 4/4] arm: mvebu: clearfog: Update eMMC/SD/SATA instructions Pali Rohár
2023-04-13 22:43   ` Martin Rowe
2023-04-26 23:44     ` Pali Rohár
2023-04-27  8:56       ` Stefan Roese
2023-04-29 11:08         ` Pali Rohár
2023-05-03  9:17           ` Stefan Roese
2023-05-03  9:43             ` Eugen Hristev
2023-05-03  9:57               ` Stefan Roese
2023-05-03 10:01                 ` Eugen Hristev
2023-05-03 10:12                   ` Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413205750.10641-3-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=martin.p.rowe@gmail.com \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.