From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Johannes Schneider <johannes.schneider@leica-geosystems.com>,
barebox@lists.infradead.org
Subject: Re: [PATCH v1 2/2] commands: mmc_extcsd: fix enhanced-area / GPP size display arithmetic
Date: Wed, 17 Jun 2026 12:51:59 +0200 [thread overview]
Message-ID: <a02281e5-7a8c-46ee-b9e4-17f541703767@pengutronix.de> (raw)
In-Reply-To: <20260617103448.1563040-2-johannes.schneider@leica-geosystems.com>
On 6/17/26 12:34 PM, Johannes Schneider wrote:
> 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>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> 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);
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-06-17 10:53 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 ` [PATCH v1 2/2] commands: mmc_extcsd: fix enhanced-area / GPP size display arithmetic Johannes Schneider
2026-06-17 10:51 ` Ahmad Fatoum [this message]
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=a02281e5-7a8c-46ee-b9e4-17f541703767@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=johannes.schneider@leica-geosystems.com \
/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