[PATCH v1 2/2] commands: mmc_extcsd: fix enhanced-area / GPP size display arithmetic

Johannes Schneider johannes.schneider at leica-geosystems.com
Wed Jun 17 03:34:48 PDT 2026


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 at 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




More information about the barebox mailing list