Skip to contentSkip to conversation

mmc: allow use of hardware partition names for mmc partconf

PATCH In review Tim Harvey 4 participants 13 messages Apr 27, 2024 – May 14, 2024 MMC, SD and SDIO

lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

PATCH v3 1/1 mmc: allow use of hardware partition names for mmc partconf

eMMC devices have hardware partitions such as user, boot0, and boot1.

Add an enumerated type defining the hardware partition values and an array of names describing them by name that can be used throughout U-Boot.

Allow these names to be displayed when reading and used when setting the mmc PARTITION_CONFIG field via 'mmc partconf'.

Before:
u-boot=> mmc partconf 2 1 1 0 && mmc partconf 2
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x1
BOOT_PARTITION_ENABLE: 0x2
PARTITION_ACCESS: 0x0

After:
u-boot=> mmc partconf 2 1 1 0 && mmc partconf 2 EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x1
BOOT_PARTITION_ENABLE: 0x1 (boot0)
PARTITION_ACCESS: 0x0
u-boot=> mmc partconf 2 1 boot1 0 && mmc partconf 2 EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x1
BOOT_PARTITION_ENABLE: 0x2 (boot1)
PARTITION_ACCESS: 0x0

---
v3:
- define partition names and values in mmc.h/mmc.c for others to use

v2:
- fix typo in subject
- add names for gp1..gp4

---
 cmd/mmc.c         | 14 +++++++++++---
 drivers/mmc/mmc.c | 11 +++++++++++
 include/mmc.h     | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)
cmd/mmc.c +11 -3
index 2d5430a53079..26ab4450816b 100644
@@ -14,6 +14,7 @@
 #include <part.h>
 #include <sparse_format.h>
 #include <image-sparse.h>
+#include <linux/ctype.h>
 
 static int curr_device = -1;
 
@@ -918,8 +919,8 @@ static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 
 	printf("EXT_CSD[179], PARTITION_CONFIG:\n"
 		"BOOT_ACK: 0x%x\n"
-		"BOOT_PARTITION_ENABLE: 0x%x\n"
-		"PARTITION_ACCESS: 0x%x\n", ack, part, access);
+		"BOOT_PARTITION_ENABLE: 0x%x (%s)\n"
+		"PARTITION_ACCESS: 0x%x\n", ack, part, emmc_hwpart_names[part], access);
 
 	return CMD_RET_SUCCESS;
 }
@@ -949,7 +950,14 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 		return mmc_partconf_print(mmc, cmd_arg2(argc, argv));
 
 	ack = dectoul(argv[2], NULL);
-	part_num = dectoul(argv[3], NULL);
+	if (!isdigit(*argv[3])) {
+		for (part_num = 0; part_num <= EMMC_HWPART_USER; part_num++) {
+			if (!strcmp(argv[3], emmc_hwpart_names[part_num]))
+				break;
+		}
+	} else {
+		part_num = dectoul(argv[3], NULL);
+	}
 	access = dectoul(argv[4], NULL);
 
 	/* acknowledge to be sent during boot operation */
drivers/mmc/mmc.c +11 -0
index 7b068c71ff37..132afe1b8a29 100644
@@ -29,6 +29,17 @@
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
 
+const char *emmc_hwpart_names[] = {
+	"user",
+	"boot0",
+	"boot1",
+	"gp1",
+	"gp2",
+	"gp3",
+	"gp4",
+	"user",
+};
+
 static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);
 
 #if !CONFIG_IS_ENABLED(DM_MMC)
include/mmc.h +15 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
 #define MMC_TIMING_MMC_HS200	9
 #define MMC_TIMING_MMC_HS400	10
 
+/* emmc hardware partition values */
+enum emmc_hwpart {
+	EMMC_HWPART_DEFAULT = 0,
+	EMMC_HWPART_BOOT0 = 1,
+	EMMC_HWPART_BOOT1 = 2,
+	EMMC_HWPART_GP1 = 3,
+	EMMC_HWPART_GP2 = 4,
+	EMMC_HWPART_GP3 = 5,
+	EMMC_HWPART_GP4 = 6,
+	EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];
+
 /* Driver model support */
 
 /**
Signature · 1 line
2.25.1
#1 lore raw

[...]

Quoted 12 lines
include/mmc.h +4 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
  #define MMC_TIMING_MMC_HS200	9
  #define MMC_TIMING_MMC_HS400	10
 
+/* emmc hardware partition values */
+enum emmc_hwpart {
+	EMMC_HWPART_DEFAULT = 0,
+	EMMC_HWPART_BOOT0 = 1,

include/mmc.h enum mmc_voltage { · line 397

Quoted 10 lines
include/mmc.h +10 -0
+	EMMC_HWPART_BOOT1 = 2,
+	EMMC_HWPART_GP1 = 3,
+	EMMC_HWPART_GP2 = 4,
+	EMMC_HWPART_GP3 = 5,
+	EMMC_HWPART_GP4 = 6,
+	EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];

Maybe the array should have fixed size here, i.e. 8 ?

#2 lore raw

Hi Marek,

Quoted 11 lines · Marek Vasut

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
  #define MMC_TIMING_MMC_HS200        9
  #define MMC_TIMING_MMC_HS400        10
 
Quoted 16 lines
Quoted 4 lines
include/mmc.h +4 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,
+     EMMC_HWPART_BOOT0 = 1,

include/mmc.h enum mmc_voltage { · line 397

Quoted 10 lines
include/mmc.h +10 -0
+     EMMC_HWPART_BOOT1 = 2,
+     EMMC_HWPART_GP1 = 3,
+     EMMC_HWPART_GP2 = 4,
+     EMMC_HWPART_GP3 = 5,
+     EMMC_HWPART_GP4 = 6,
+     EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];

Maybe the array should have fixed size here, i.e. 8 ?

Is there an ABI reason to do so? Can you explain further why it would be needed to do that?

#3 lore raw
Quoted 31 lines · E Shattow

Hi Marek,

Quoted 11 lines · Marek Vasut

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
   #define MMC_TIMING_MMC_HS200        9
   #define MMC_TIMING_MMC_HS400        10
 
Quoted 16 lines
Quoted 4 lines
include/mmc.h +4 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,
+     EMMC_HWPART_BOOT0 = 1,

include/mmc.h enum mmc_voltage { · line 397

Quoted 10 lines
include/mmc.h +10 -0
+     EMMC_HWPART_BOOT1 = 2,
+     EMMC_HWPART_GP1 = 3,
+     EMMC_HWPART_GP2 = 4,
+     EMMC_HWPART_GP3 = 5,
+     EMMC_HWPART_GP4 = 6,
+     EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];

Maybe the array should have fixed size here, i.e. 8 ?

Quoted 2 lines

Is there an ABI reason to do so? Can you explain further why it would be needed to do that?

It has nothing to do with ABI, it is only to let the compiler validate that nobody would index the array with index > 7 by accident.

#4 lore raw
Quoted 33 lines · Marek Vasut
Quoted 31 lines · E Shattow

Hi Marek,

Quoted 27 lines · Marek Vasut

[...]

Quoted 12 lines
include/mmc.h +4 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
   #define MMC_TIMING_MMC_HS200        9
   #define MMC_TIMING_MMC_HS400        10
 
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,
+     EMMC_HWPART_BOOT0 = 1,

include/mmc.h enum mmc_voltage { · line 397

Quoted 10 lines
include/mmc.h +10 -0
+     EMMC_HWPART_BOOT1 = 2,
+     EMMC_HWPART_GP1 = 3,
+     EMMC_HWPART_GP2 = 4,
+     EMMC_HWPART_GP3 = 5,
+     EMMC_HWPART_GP4 = 6,
+     EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];

Maybe the array should have fixed size here, i.e. 8 ?

Quoted 5 lines
Quoted 2 lines

Is there an ABI reason to do so? Can you explain further why it would be needed to do that?

It has nothing to do with ABI, it is only to let the compiler validate that nobody would index the array with index > 7 by accident.

At least GCC knows this without doing its work again ourselves. How about a const for the upper limit, where currently EMMC_HWPART_USER substitutes for expressing an upper limit? You may as well be writing EMMC_HWPART_MAX = 8 in the enum and using that for the initializer also any iterators with a less-than condition to make it more expressive.

$ gcc -o testobj test.c -Wall -Wextra -O2
test.c: In function ‘main’:
test.c:16:5: warning: array subscript 8 is above array bounds of
‘const char *[8]’ [-Warray-bounds=]
   16 |     printf(emmc_hwpart_names[8]);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:3:13: note: while referencing ‘emmc_hwpart_names’
    3 | const char *emmc_hwpart_names[] = {
      |             ^~~~~~~~~~~~~~~~~

#include <stdio.h>

const char *emmc_hwpart_names[] = {
       "user",
       "boot0",
       "boot1",
       "gp1",
       "gp2",
       "gp3",
       "gp4",
       "user",
};
int main(int argc, char** argv) {
    (void) argc; (void) argv;
    printf(emmc_hwpart_names[8]);

    return 0;
}

Sorry to belabor this and I'm not a professional programmer. Best regards, -E

#5 lore raw
Quoted 40 lines · E Shattow
Quoted 33 lines · Marek Vasut
Quoted 31 lines · E Shattow

Hi Marek,

Quoted 27 lines · Marek Vasut

[...]

Quoted 12 lines
include/mmc.h +4 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
    #define MMC_TIMING_MMC_HS200        9
    #define MMC_TIMING_MMC_HS400        10
 
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,
+     EMMC_HWPART_BOOT0 = 1,

include/mmc.h enum mmc_voltage { · line 397

Quoted 10 lines
include/mmc.h +10 -0
+     EMMC_HWPART_BOOT1 = 2,
+     EMMC_HWPART_GP1 = 3,
+     EMMC_HWPART_GP2 = 4,
+     EMMC_HWPART_GP3 = 5,
+     EMMC_HWPART_GP4 = 6,
+     EMMC_HWPART_USER = 7,
+};
+
+/* emmc hardware partition names */
+extern const char *emmc_hwpart_names[];

Maybe the array should have fixed size here, i.e. 8 ?

Quoted 5 lines
Quoted 2 lines

Is there an ABI reason to do so? Can you explain further why it would be needed to do that?

It has nothing to do with ABI, it is only to let the compiler validate that nobody would index the array with index > 7 by accident.

Quoted 6 lines

At least GCC knows this without doing its work again ourselves. How about a const for the upper limit, where currently EMMC_HWPART_USER substitutes for expressing an upper limit? You may as well be writing EMMC_HWPART_MAX = 8 in the enum and using that for the initializer also any iterators with a less-than condition to make it more expressive.

You could use ARRAY_SIZE(emmc_hwpart_names) in iterators, no extra symbols should be necessary.

Quoted 23 lines
$ gcc -o testobj test.c -Wall -Wextra -O2
test.c: In function ‘main’:
test.c:16:5: warning: array subscript 8 is above array bounds of
‘const char *[8]’ [-Warray-bounds=]
    16 |     printf(emmc_hwpart_names[8]);
       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:3:13: note: while referencing ‘emmc_hwpart_names’
     3 | const char *emmc_hwpart_names[] = {
       |             ^~~~~~~~~~~~~~~~~

#include <stdio.h>

const char *emmc_hwpart_names[] = {
        "user",
        "boot0",
        "boot1",
        "gp1",
        "gp2",
        "gp3",
        "gp4",
        "user",
};
Quoted 6 lines
int main(int argc, char** argv) {
     (void) argc; (void) argv;
     printf(emmc_hwpart_names[8]);

     return 0;
}

In case of this patched code here, the example is more like this:

a.c:
#include <stdio.h>
#include "h.h"

int main(void)
{
printf("%d\n", arr[8]); // This code contains a bug here return 0;
}

b.c:
int arr[2] = { 1, 2 };

h.h:
extern int arr[];

Compile:

$ gcc -O2 -Wall -c -o a.o a.c
$ gcc -O2 -Wall -c -o b.o b.c
$ gcc -O2 -Wall -o out a.o b.o

You won't get warning when compiling a.c , because gcc does not know the size of the array until the linking step. You will get a warning if you change the header like this:

h.h:
-extern int arr[];
+extern int arr[2];

#6 lore raw
In reply to Tim Harvey

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

include/mmc.h enum mmc_voltage { · line 386

Quoted 11 lines
include/mmc.h +3 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
  #define MMC_TIMING_MMC_HS200	9
  #define MMC_TIMING_MMC_HS400	10
 
+/* emmc hardware partition values */
+enum emmc_hwpart {
+	EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Quoted 7 lines
include/mmc.h +7 -0
+	EMMC_HWPART_BOOT0 = 1,
+	EMMC_HWPART_BOOT1 = 2,
+	EMMC_HWPART_GP1 = 3,
+	EMMC_HWPART_GP2 = 4,
+	EMMC_HWPART_GP3 = 5,
+	EMMC_HWPART_GP4 = 6,
+	EMMC_HWPART_USER = 7,

[...]

author
#7 lore raw
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
  #define MMC_TIMING_MMC_HS200        9
  #define MMC_TIMING_MMC_HS400        10
 
Quoted 7 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Hi Marek,

I can't find what you are referring to. I assume you are talking about calling the first name something other than 'user' as technically it's not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

Best Regards,

Tim

#8 lore raw
Quoted 22 lines · Tim Harvey
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
   #define MMC_TIMING_MMC_HS200        9
   #define MMC_TIMING_MMC_HS400        10
 
Quoted 7 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Quoted 7 lines

Hi Marek,

I can't find what you are referring to. I assume you are talking about calling the first name something other than 'user' as technically it's not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

It seems this whole thing is much older:

7dbe63bc950b ("SPL: Add CONFIG_SUPPORT_EMMC_BOOT support to CONFIG_SPL_FRAMEWORK")

+                * We need to check what the partition is configured to.
+                * 1 and 2 match up to boot0 / boot1 and 7 is user data
+                * which is the first physical partition (0).
+                */

+ int part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
+
+ if (part == 7)
+ part = 0;

author
#9 lore raw
Quoted 37 lines · Marek Vasut
Quoted 22 lines · Tim Harvey
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
   #define MMC_TIMING_MMC_HS200        9
   #define MMC_TIMING_MMC_HS400        10
 
Quoted 7 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Quoted 7 lines

Hi Marek,

I can't find what you are referring to. I assume you are talking about calling the first name something other than 'user' as technically it's not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

It seems this whole thing is much older:

7dbe63bc950b ("SPL: Add CONFIG_SUPPORT_EMMC_BOOT support to CONFIG_SPL_FRAMEWORK")

Review

Quoted 8 lines
(quoted diff) +8 -0
+                * We need to check what the partition is configured to.
+                * 1 and 2 match up to boot0 / boot1 and 7 is user data
+                * which is the first physical partition (0).
+                */
+               int part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
+
+               if (part == 7)
+                       part = 0;

Hi Marek,

Sorry, I haven't been able to work on U-Boot for the past week or so and am just getting back to this.

I'm glad you pointed this out as it made me aware that there is a bit of a mixing of eMMC PARTITION_CONFIG (Ext CSD 179) fields BOOT_PARTITION_ENABLE and PARTITION_ACCESS in U-Boot currently.

I'm going to add an enumerated type for each and update the various places where a 'conversion' as above is done but I'm still a bit torn on naming conventions.

Consider the following:
- the eMMC spec refers to boot partitions and gp partitions as 1 based
- the Linux kernel device names for these are 0 based
- U-Boot does not currently refer to the boot devices by names but does currently refer to the gp's by names using 1-based names (the 'mmc hwpartition' command)

Personally I would like to name the boot partitions 'boot0' and 'boot1' to match Linux but I think I should name the gp's 'gp1'...'gp4' to be backward compatible with the 'mmc hwpartition' command.

What do you think?

Best Regards,

Tim

#10 lore raw
Quoted 47 lines · Tim Harvey
Quoted 37 lines · Marek Vasut
Quoted 22 lines · Tim Harvey
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
    #define MMC_TIMING_MMC_HS200        9
    #define MMC_TIMING_MMC_HS400        10
 
Quoted 7 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Quoted 7 lines

Hi Marek,

I can't find what you are referring to. I assume you are talking about calling the first name something other than 'user' as technically it's not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

It seems this whole thing is much older:

7dbe63bc950b ("SPL: Add CONFIG_SUPPORT_EMMC_BOOT support to CONFIG_SPL_FRAMEWORK")

Review

Quoted 8 lines
(quoted diff) +8 -0
+                * We need to check what the partition is configured to.
+                * 1 and 2 match up to boot0 / boot1 and 7 is user data
+                * which is the first physical partition (0).
+                */
+               int part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
+
+               if (part == 7)
+                       part = 0;
Quoted 1 line

Hi Marek,

Hello Tim,

Quoted 2 lines

Sorry, I haven't been able to work on U-Boot for the past week or so and am just getting back to this.

No worries.

Quoted 15 lines

I'm glad you pointed this out as it made me aware that there is a bit of a mixing of eMMC PARTITION_CONFIG (Ext CSD 179) fields BOOT_PARTITION_ENABLE and PARTITION_ACCESS in U-Boot currently.

I'm going to add an enumerated type for each and update the various places where a 'conversion' as above is done but I'm still a bit torn on naming conventions.

Consider the following:
- the eMMC spec refers to boot partitions and gp partitions as 1 based
- the Linux kernel device names for these are 0 based
- U-Boot does not currently refer to the boot devices by names but does currently refer to the gp's by names using 1-based names (the 'mmc hwpartition' command)

Quoted 6 lines

Personally I would like to name the boot partitions 'boot0' and 'boot1' to match Linux but I think I should name the gp's 'gp1'...'gp4' to be backward compatible with the 'mmc hwpartition' command.

What do you think?

I agree.

Maybe you could also check this with Ulf (Linux MMC maintainer) and Avri (mmc-utils), both on To:, so we would be consistent and in sync ?

#11 lore raw

Hello all,

Quoted 73 lines · Marek Vasut
Quoted 47 lines · Tim Harvey
Quoted 43 lines · Marek Vasut
Quoted 22 lines · Tim Harvey
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
    #define MMC_TIMING_MMC_HS200        9
    #define MMC_TIMING_MMC_HS400        10
 
Quoted 7 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to USER HW partition. Have a look at the git log, there have been patches which handled this case in the MMC subsystem from about a year ago.

Quoted 5 lines

I can't find what you are referring to. I assume you are talking about calling the first name something other than 'user' as technically it's not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

It seems this whole thing is much older:

7dbe63bc950b ("SPL: Add CONFIG_SUPPORT_EMMC_BOOT support to CONFIG_SPL_FRAMEWORK")

+ * We need to check what the partition is configured
to.
+ * 1 and 2 match up to boot0 / boot1 and 7 is user
data

(quoted diff) +3 -0
+                * which is the first physical partition (0).
+                */
+               int part = (mmc->part_config >> 3) & 

PART_ACCESS_MASK;

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+               if (part == 7)
+                       part = 0;
Quoted 2 lines

Sorry, I haven't been able to work on U-Boot for the past week or so and am just getting back to this.

No worries.

Quoted 20 lines

I'm glad you pointed this out as it made me aware that there is a bit of a mixing of eMMC PARTITION_CONFIG (Ext CSD 179) fields BOOT_PARTITION_ENABLE and PARTITION_ACCESS in U-Boot currently.

I'm going to add an enumerated type for each and update the various places where a 'conversion' as above is done but I'm still a bit torn on naming conventions.

Consider the following:
- the eMMC spec refers to boot partitions and gp partitions as 1 based
- the Linux kernel device names for these are 0 based
- U-Boot does not currently refer to the boot devices by names but does currently refer to the gp's by names using 1-based names (the 'mmc hwpartition' command)

Personally I would like to name the boot partitions 'boot0' and 'boot1' to match Linux but I think I should name the gp's 'gp1'...'gp4' to be backward compatible with the 'mmc hwpartition' command.

Quoted 6 lines
Quoted 1 line

What do you think?

I agree.

Maybe you could also check this with Ulf (Linux MMC maintainer) and Avri (mmc-utils), both on To:, so we would be consistent and in sync ?

As I promised earlier, I went through a few JEDEC standards and some publicly available JEDEC documents and presentations, and my conclusion is that no official numbering scheme for the partitions seems to be defined there.

However, I'd propose that we keep "boot0" and "boot1", because that's pretty much become a de facto standard, and also switch to using "gp0" through "gp3" for the general-purpose partitions. That switch might be some kind of a backward-incompatible change, but it would follow the names of the corresponding GP_SIZE_MULT_GP0 ... GP_SIZE_MULT_GP3 fields in the EXT_CSD register, as defined by JEDEC, and it would also be more consistent with the numbering of the boot partitions.

Though, general-purpose partitions are mentioned as GPP1 ... GPP4 in one place in the JEDEC standard, which just confirms that no official numbering scheme seems to be defined. Moreover, the boot partitions are more than once referred to as "boot partition 1" and "boot partition 2" in the JEDEC standard, which means we're already not following the standard with "boot0" and "boot1".

Frankly, it's all a bit contradictory and confusing, but I think that the increased consistency would outweigh the backward-incompatible downside of the switch to "gp0" through "gp3".

author
#12 lore raw
Quoted 108 lines · Dragan Simic

Hello all,

Quoted 77 lines · Marek Vasut
Quoted 51 lines · Tim Harvey
Quoted 47 lines · Marek Vasut
Quoted 24 lines · Tim Harvey
Quoted 13 lines · Marek Vasut

On 4/27/24 2:11 AM, Tim Harvey wrote:

[...]

Quoted 8 lines
include/mmc.h +0 -0
index 4b8327f1f93b..7243bd761202 100644
@@ -381,6 +381,21 @@ enum mmc_voltage {
    #define MMC_TIMING_MMC_HS200        9
    #define MMC_TIMING_MMC_HS400        10
 
Quoted 9 lines

include/mmc.h enum mmc_voltage { · line 386

Quoted 3 lines
include/mmc.h +3 -0
+/* emmc hardware partition values */
+enum emmc_hwpart {
+     EMMC_HWPART_DEFAULT = 0,

One more thing ... eMMC hardware partition 0 and 7 are both referring to
USER HW partition. Have a look at the git log, there have been patches
which handled this case in the MMC subsystem from about a year ago.

Quoted 7 lines

I can't find what you are referring to. I assume you are talking about
calling the first name something other than 'user' as technically it's
not (but it gets treated as user).

Can you find the commit or discussion you are thinking about?

It seems this whole thing is much older:

7dbe63bc950b ("SPL: Add CONFIG_SUPPORT_EMMC_BOOT support to CONFIG_SPL_FRAMEWORK")

+ * We need to check what the partition is configured
to.
+ * 1 and 2 match up to boot0 / boot1 and 7 is user
data

(quoted diff) +3 -0
+                * which is the first physical partition (0).
+                */
+               int part = (mmc->part_config >> 3) &

PART_ACCESS_MASK;

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+               if (part == 7)
+                       part = 0;
Quoted 2 lines

Sorry, I haven't been able to work on U-Boot for the past week or so and am just getting back to this.

No worries.

Quoted 20 lines

I'm glad you pointed this out as it made me aware that there is a bit of a mixing of eMMC PARTITION_CONFIG (Ext CSD 179) fields BOOT_PARTITION_ENABLE and PARTITION_ACCESS in U-Boot currently.

I'm going to add an enumerated type for each and update the various places where a 'conversion' as above is done but I'm still a bit torn on naming conventions.

Consider the following:
- the eMMC spec refers to boot partitions and gp partitions as 1 based
- the Linux kernel device names for these are 0 based
- U-Boot does not currently refer to the boot devices by names but does currently refer to the gp's by names using 1-based names (the 'mmc hwpartition' command)

Personally I would like to name the boot partitions 'boot0' and 'boot1' to match Linux but I think I should name the gp's 'gp1'...'gp4' to be backward compatible with the 'mmc hwpartition' command.

Quoted 6 lines
Quoted 1 line

What do you think?

I agree.

Maybe you could also check this with Ulf (Linux MMC maintainer) and Avri (mmc-utils), both on To:, so we would be consistent and in sync ?

As I promised earlier, I went through a few JEDEC standards and some publicly available JEDEC documents and presentations, and my conclusion is that no official numbering scheme for the partitions seems to be defined there.

However, I'd propose that we keep "boot0" and "boot1", because that's pretty much become a de facto standard, and also switch to using "gp0" through "gp3" for the general-purpose partitions. That switch might be some kind of a backward-incompatible change, but it would follow the names of the corresponding GP_SIZE_MULT_GP0 ... GP_SIZE_MULT_GP3 fields in the EXT_CSD register, as defined by JEDEC, and it would also be more consistent with the numbering of the boot partitions.

Though, general-purpose partitions are mentioned as GPP1 ... GPP4 in one place in the JEDEC standard, which just confirms that no official numbering scheme seems to be defined. Moreover, the boot partitions are more than once referred to as "boot partition 1" and "boot partition 2" in the JEDEC standard, which means we're already not following the standard with "boot0" and "boot1".

Quoted 3 lines

Frankly, it's all a bit contradictory and confusing, but I think that the increased consistency would outweigh the backward-incompatible downside of the switch to "gp0" through "gp3".

Dragan,

Thanks for your freedback and sorry for the late reply.

I also went over the spec and found that they used 1 based naming in their referencing of the partitions but noticed that Linux uses 0 based naming for both boot partitions as well as gp's when creating devs. Seeing as both Linux and U-Boot tend to use 0 based naming I wanted to go that route but then I noticed the 'mmc hwpartition' command (enabled via MMC_HW_PARTITIONING) which is used to create gp's uses 1-based gp names in its parameter list and that 'mmc info' will display the gp's, if configured, as 1 based as well.

I submitted yesterday a new v3 series where I use boot0, boot1 for boot partitions but gp1, gp2, gp3, gp4 for gp names just to stick with the current usage of 'gp' in U-Boot (although the array of names isn't used currently in the 'mmc hwpartition' or 'mmc info' commands.

I'm open to further discussion on the matter. I hate to make things non-standard just to be backward compatible but I have no idea who is using the 'mmc hwpartition' or output of 'mmc info' currently with regards to gp's.

Best Regards,

Tim