From: Johannes Schneider <johannes.schneider@leica-geosystems.com>
To: barebox@lists.infradead.org
Cc: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Subject: [PATCH v1 2/2] commands: mmc_extcsd: fix enhanced-area / GPP size display arithmetic
Date: Wed, 17 Jun 2026 10:34:48 +0000 [thread overview]
Message-ID: <20260617103448.1563040-2-johannes.schneider@leica-geosystems.com> (raw)
In-Reply-To: <20260617103448.1563040-1-johannes.schneider@leica-geosystems.com>
Per JEDEC eMMC 5.1 (JESD84-B51, February 2015), the displayed byte
size for the enhanced user data area and for each general-purpose
partition is the product of the SIZE_MULT bytes, the write-protect
group size, the erase group size, and 512 KiB:
§7.4.90 ENH_SIZE_MULT [142:140] (p. 219):
Enhanced User Data Area x Size =
(ENH_SIZE_MULT_2 * 2^16 + ENH_SIZE_MULT_1 * 2^8
+ ENH_SIZE_MULT_0 * 2^0)
* HC_WP_GRP_SIZE * HC_ERASE_GRP_SIZE * 512 kBytes
§7.4.89 GP_SIZE_MULT_GP0..GP3 [154:143] (p. 218):
General_Purpose_Partition_X Size =
(GP_SIZE_MULT_X_2 * 2^16 + GP_SIZE_MULT_X_1 * 2^8
+ GP_SIZE_MULT_X_0 * 2^0)
* HC_WP_GRP_SIZE * HC_ERASE_GRP_SIZE * 512 kBytes
The displayed-size code in mmc_extcsd.c for ENH_SIZE_MULT and for
all four GP_SIZE_MULT[0..3] cases instead *added* HC_WP_GRP_SIZE
and HC_ERASE_GRP_SIZE before multiplying by the SIZE_MULT and
SZ_512K factors, producing nonsensical values. The neighbouring
MAX_ENH_SIZE_MULT case already uses the correct multiplication.
Bring the five buggy cases in line.
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
commands/mmc_extcsd.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c
index e7b0fd82ee..b898bd8515 100644
--- a/commands/mmc_extcsd.c
+++ b/commands/mmc_extcsd.c
@@ -1342,7 +1342,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_ENH_SIZE_MULT:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
- tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
+ tmp = tmp * get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
tmp64 *= tmp;
tmp64 *= SZ_512K;
printf("\tEnhanced User Data Area %i Size: %llu B\n",
@@ -1351,7 +1351,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_GP_SIZE_MULT3:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
- tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
+ tmp = tmp * get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
tmp64 *= tmp;
tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_3 Size: %llu B\n", tmp64);
@@ -1359,7 +1359,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_GP_SIZE_MULT2:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
- tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
+ tmp = tmp * get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
tmp64 *= tmp;
tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_2 Size: %llu B\n", tmp64);
@@ -1367,7 +1367,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_GP_SIZE_MULT1:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
- tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
+ tmp = tmp * get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
tmp64 *= tmp;
tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_1 Size: %llu B\n", tmp64);
@@ -1375,7 +1375,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_GP_SIZE_MULT0:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
- tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
+ tmp = tmp * get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
tmp64 *= tmp;
tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_0 Size: %llu B\n", tmp64);
--
2.43.0
next prev parent reply other threads:[~2026-06-17 10:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 10:34 [PATCH v1 1/2] commands: mmc: add mmc-utils compatible enh_area set subcommand Johannes Schneider
2026-06-17 10:34 ` Johannes Schneider [this message]
2026-06-17 10:51 ` [PATCH v1 2/2] commands: mmc_extcsd: fix enhanced-area / GPP size display arithmetic Ahmad Fatoum
2026-06-18 7:00 ` (subset) " Sascha Hauer
2026-06-18 7:00 ` (subset) [PATCH v1 1/2] commands: mmc: add mmc-utils compatible enh_area set subcommand Sascha Hauer
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=20260617103448.1563040-2-johannes.schneider@leica-geosystems.com \
--to=johannes.schneider@leica-geosystems.com \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox