public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] mmc: allow forward compatibility for EXT_CSD_REV
@ 2026-03-26  5:55 박민우 (MW Park)
  2026-04-08 16:21 ` Peng Fan
  0 siblings, 1 reply; 3+ messages in thread
From: 박민우 (MW Park) @ 2026-03-26  5:55 UTC (permalink / raw)
  To: u-boot@lists.denx.de; +Cc: peng.fan@nxp.com, jh80.chung@samsung.com

[-- Attachment #1: Type: text/plain, Size: 2740 bytes --]

According to the JEDEC Standard, the EXT_CSD format is meant to be
forward compatible. As long as CSD_STRUCTURE does not change, all
values for EXT_CSD_REV are authorized.

Currently, if an eMMC device with a newer EXT_CSD_REV (e.g., eMMC 5.1B
with EXT_CSD_REV=9) is used, U-Boot fails to initialize it and returns
-EINVAL because the revision is larger than the mmc_versions array size.

Fix this by falling back to the latest supported version if the
EXT_CSD_REV exceeds the known versions. This ensures forward
compatibility with future eMMC specifications.

Signed-off-by: MW Park <mw.park@telechips.com>
---
 drivers/mmc/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index c5705f4f215..dbec728a474 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2334,6 +2334,7 @@ static int mmc_startup_v4(struct mmc *mmc)
        u64 capacity;
        bool has_parts = false;
        bool part_completed;
+       u8 rev;
        static const u32 mmc_versions[] = {
                MMC_VERSION_4,
                MMC_VERSION_4_1,
@@ -2380,12 +2381,19 @@ static int mmc_startup_v4(struct mmc *mmc)
                return -ENOMEM;
        memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
 #endif
-       if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions)) {
-               err = -EINVAL;
-               goto error;
-       }
+       rev = ext_csd[EXT_CSD_REV];
+
+       /*
+        * According to the JEDEC Standard, the EXT_CSD format is meant to be
+        * forward compatible. As long as CSD_STRUCTURE does not change, all
+        * values for EXT_CSD_REV are authorized.
+        * If the EXT_CSD_REV exceeds the known versions, fallback to the
+        * latest supported version instead of returning an error.
+        */
+       if (rev >= ARRAY_SIZE(mmc_versions))
+               rev = ARRAY_SIZE(mmc_versions) - 1;

-       mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]];
+       mmc->version = mmc_versions[rev];

        if (mmc->version >= MMC_VERSION_4_2) {
                /*
--
2.34.1
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Telechips Inc. If you are not the intended recipient of this email, you must neither take any action based upon its contents nor copy or show it to anyone. Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. Please consider the environment before printing this email.

[-- Attachment #2: 0001-mmc-allow-forward-compatibility-for-EXT_CSD_REV.patch --]
[-- Type: application/octet-stream, Size: 2104 bytes --]

From f783ea55ce5fb80a8c2a67cce151ea217b835f2a Mon Sep 17 00:00:00 2001
From: MW Park <mw.park@telechips.com>
Date: Thu, 26 Mar 2026 14:41:16 +0900
Subject: [PATCH] mmc: allow forward compatibility for EXT_CSD_REV

According to the JEDEC Standard, the EXT_CSD format is meant to be
forward compatible. As long as CSD_STRUCTURE does not change, all
values for EXT_CSD_REV are authorized.

Currently, if an eMMC device with a newer EXT_CSD_REV (e.g., eMMC 5.1B
with EXT_CSD_REV=9) is used, U-Boot fails to initialize it and returns
-EINVAL because the revision is larger than the mmc_versions array size.

Fix this by falling back to the latest supported version if the
EXT_CSD_REV exceeds the known versions. This ensures forward
compatibility with future eMMC specifications.

Signed-off-by: MW Park <mw.park@telechips.com>
---
 drivers/mmc/mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index c5705f4f215..497ad172a3a 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2334,6 +2334,7 @@ static int mmc_startup_v4(struct mmc *mmc)
 	u64 capacity;
 	bool has_parts = false;
 	bool part_completed;
+	u8 rev;
 	static const u32 mmc_versions[] = {
 		MMC_VERSION_4,
 		MMC_VERSION_4_1,
@@ -2380,12 +2381,19 @@ static int mmc_startup_v4(struct mmc *mmc)
 		return -ENOMEM;
 	memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
 #endif
-	if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions)) {
-		err = -EINVAL;
-		goto error;
-	}
+	rev = ext_csd[EXT_CSD_REV];
+
+	/*
+	 * According to the JEDEC Standard, the EXT_CSD format is meant to be
+	 * forward compatible. As long as CSD_STRUCTURE does not change, all
+	 * values for EXT_CSD_REV are authorized.
+	 * If the EXT_CSD_REV exceeds the known versions, fallback to the
+	 * latest supported version instead of returning an error.
+	 */
+	if (rev >= ARRAY_SIZE(mmc_versions))
+		rev = ARRAY_SIZE(mmc_versions) - 1;
 
-	mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]];
+	mmc->version = mmc_versions[rev];
 
 	if (mmc->version >= MMC_VERSION_4_2) {
 		/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-09  1:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26  5:55 [PATCH] mmc: allow forward compatibility for EXT_CSD_REV 박민우 (MW Park)
2026-04-08 16:21 ` Peng Fan
2026-04-09  1:23   ` 박민우 (MW Park)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox