diff mbox series

[v2] cmd: mmc: allow use of hardware partition names for mmc partconf

Message ID 20240426171205.1382212-1-tharvey@gateworks.com
State Superseded
Delegated to: Jaehoon Chung
Headers show
Series [v2] cmd: mmc: allow use of hardware partition names for mmc partconf | expand

Commit Message

Tim Harvey April 26, 2024, 5:12 p.m. UTC
eMMC devices have hardware partitions such as user, boot0, and boot1.
Allow these names to be displayed when reading the mmc PARTITION_CONFIG
field via 'mmc partconf'. Additionally allow a name to be specified when
setting the PARTITION_CONFIG.

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

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
v2:
 - fix typo in subject
 - add names for gp1..gp4
---
 cmd/mmc.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

Comments

Marek Vasut April 26, 2024, 5:25 p.m. UTC | #1
On 4/26/24 7:12 PM, Tim Harvey wrote:
> eMMC devices have hardware partitions such as user, boot0, and boot1.
> Allow these names to be displayed when reading the mmc PARTITION_CONFIG
> field via 'mmc partconf'. Additionally allow a name to be specified when
> setting the PARTITION_CONFIG.
> 
> 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
> 
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
> ---
> v2:
>   - fix typo in subject
>   - add names for gp1..gp4
> ---
>   cmd/mmc.c | 25 ++++++++++++++++++++++---
>   1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index 2d5430a53079..af9a66cc6df4 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -14,6 +14,18 @@
>   #include <part.h>
>   #include <sparse_format.h>
>   #include <image-sparse.h>
> +#include <linux/ctype.h>
> +
> +static const char *mmc_partnames[] = {
> +	"user",
> +	"boot0",
> +	"boot1",
> +	"gp1",
> +	"gp2",
> +	"gp3",
> +	"gp4",

Uh, maybe gp%d are indexed from zero too ?

(sorry for the confusion)
Tim Harvey April 26, 2024, 5:36 p.m. UTC | #2
On Fri, Apr 26, 2024 at 10:25 AM Marek Vasut <marex@denx.de> wrote:
>
> On 4/26/24 7:12 PM, Tim Harvey wrote:
> > eMMC devices have hardware partitions such as user, boot0, and boot1.
> > Allow these names to be displayed when reading the mmc PARTITION_CONFIG
> > field via 'mmc partconf'. Additionally allow a name to be specified when
> > setting the PARTITION_CONFIG.
> >
> > 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
> >
> > Signed-off-by: Tim Harvey <tharvey@gateworks.com>
> > ---
> > v2:
> >   - fix typo in subject
> >   - add names for gp1..gp4
> > ---
> >   cmd/mmc.c | 25 ++++++++++++++++++++++---
> >   1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/cmd/mmc.c b/cmd/mmc.c
> > index 2d5430a53079..af9a66cc6df4 100644
> > --- a/cmd/mmc.c
> > +++ b/cmd/mmc.c
> > @@ -14,6 +14,18 @@
> >   #include <part.h>
> >   #include <sparse_format.h>
> >   #include <image-sparse.h>
> > +#include <linux/ctype.h>
> > +
> > +static const char *mmc_partnames[] = {
> > +     "user",
> > +     "boot0",
> > +     "boot1",
> > +     "gp1",
> > +     "gp2",
> > +     "gp3",
> > +     "gp4",
>
> Uh, maybe gp%d are indexed from zero too ?
>
> (sorry for the confusion)

but 'mmc hwpartition' does not list them 0 based:
u-boot=> mmc hwpartition
switch to partitions #0, OK
mmc2(part 0) is current device
Partition configuration:
        No enhanced user data area
        No GP1 partition
        No GP2 partition
        No GP3 partition
        No GP4 partition

I'm ok with either, I'm just not sure what is more understandable and standard.

Tim
Marek Vasut April 26, 2024, 5:42 p.m. UTC | #3
On 4/26/24 7:36 PM, Tim Harvey wrote:
> On Fri, Apr 26, 2024 at 10:25 AM Marek Vasut <marex@denx.de> wrote:
>>
>> On 4/26/24 7:12 PM, Tim Harvey wrote:
>>> eMMC devices have hardware partitions such as user, boot0, and boot1.
>>> Allow these names to be displayed when reading the mmc PARTITION_CONFIG
>>> field via 'mmc partconf'. Additionally allow a name to be specified when
>>> setting the PARTITION_CONFIG.
>>>
>>> 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
>>>
>>> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
>>> ---
>>> v2:
>>>    - fix typo in subject
>>>    - add names for gp1..gp4
>>> ---
>>>    cmd/mmc.c | 25 ++++++++++++++++++++++---
>>>    1 file changed, 22 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/cmd/mmc.c b/cmd/mmc.c
>>> index 2d5430a53079..af9a66cc6df4 100644
>>> --- a/cmd/mmc.c
>>> +++ b/cmd/mmc.c
>>> @@ -14,6 +14,18 @@
>>>    #include <part.h>
>>>    #include <sparse_format.h>
>>>    #include <image-sparse.h>
>>> +#include <linux/ctype.h>
>>> +
>>> +static const char *mmc_partnames[] = {
>>> +     "user",
>>> +     "boot0",
>>> +     "boot1",
>>> +     "gp1",
>>> +     "gp2",
>>> +     "gp3",
>>> +     "gp4",
>>
>> Uh, maybe gp%d are indexed from zero too ?
>>
>> (sorry for the confusion)
> 
> but 'mmc hwpartition' does not list them 0 based:
> u-boot=> mmc hwpartition
> switch to partitions #0, OK
> mmc2(part 0) is current device
> Partition configuration:
>          No enhanced user data area
>          No GP1 partition
>          No GP2 partition
>          No GP3 partition
>          No GP4 partition
> 
> I'm ok with either, I'm just not sure what is more understandable and standard.

Then 1-based counting is OK, thanks for checking !
Dragan Simic April 27, 2024, 7:25 a.m. UTC | #4
Hello Tim and Marek,

On 2024-04-26 19:36, Tim Harvey wrote:
> On Fri, Apr 26, 2024 at 10:25 AM Marek Vasut <marex@denx.de> wrote:
>> On 4/26/24 7:12 PM, Tim Harvey wrote:
>> > +static const char *mmc_partnames[] = {
>> > +     "user",
>> > +     "boot0",
>> > +     "boot1",
>> > +     "gp1",
>> > +     "gp2",
>> > +     "gp3",
>> > +     "gp4",
>> 
>> Uh, maybe gp%d are indexed from zero too ?
>> 
>> (sorry for the confusion)
> 
> but 'mmc hwpartition' does not list them 0 based:
> u-boot=> mmc hwpartition
> switch to partitions #0, OK
> mmc2(part 0) is current device
> Partition configuration:
>         No enhanced user data area
>         No GP1 partition
>         No GP2 partition
>         No GP3 partition
>         No GP4 partition
> 
> I'm ok with either, I'm just not sure what is more understandable and 
> standard.

I can confirm that JEDEC also starts the numbering of the GP
partitions from one in some of its documents.

Though, it's a bit intriguing why the numbering of the boot
partitions starts from zero.  Perhaps there's some good reason
for that difference.
Dragan Simic April 27, 2024, 7:30 a.m. UTC | #5
On 2024-04-27 09:25, Dragan Simic wrote:
> On 2024-04-26 19:36, Tim Harvey wrote:
>> On Fri, Apr 26, 2024 at 10:25 AM Marek Vasut <marex@denx.de> wrote:
>>> On 4/26/24 7:12 PM, Tim Harvey wrote:
>>> > +static const char *mmc_partnames[] = {
>>> > +     "user",
>>> > +     "boot0",
>>> > +     "boot1",
>>> > +     "gp1",
>>> > +     "gp2",
>>> > +     "gp3",
>>> > +     "gp4",
>>> 
>>> Uh, maybe gp%d are indexed from zero too ?
>>> 
>>> (sorry for the confusion)
>> 
>> but 'mmc hwpartition' does not list them 0 based:
>> u-boot=> mmc hwpartition
>> switch to partitions #0, OK
>> mmc2(part 0) is current device
>> Partition configuration:
>>         No enhanced user data area
>>         No GP1 partition
>>         No GP2 partition
>>         No GP3 partition
>>         No GP4 partition
>> 
>> I'm ok with either, I'm just not sure what is more understandable and 
>> standard.
> 
> I can confirm that JEDEC also starts the numbering of the GP
> partitions from one in some of its documents.
> 
> Though, it's a bit intriguing why the numbering of the boot
> partitions starts from zero.  Perhaps there's some good reason
> for that difference.

Hmm, it seems that JEDEC actually starts the numbering of the boot
partitions from one in some of its documents, instead of starting
from zero.  I'll try to research that better.
diff mbox series

Patch

diff --git a/cmd/mmc.c b/cmd/mmc.c
index 2d5430a53079..af9a66cc6df4 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -14,6 +14,18 @@ 
 #include <part.h>
 #include <sparse_format.h>
 #include <image-sparse.h>
+#include <linux/ctype.h>
+
+static const char *mmc_partnames[] = {
+	"user",
+	"boot0",
+	"boot1",
+	"gp1",
+	"gp2",
+	"gp3",
+	"gp4",
+	"user",
+};
 
 static int curr_device = -1;
 
@@ -918,8 +930,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, mmc_partnames[part], access);
 
 	return CMD_RET_SUCCESS;
 }
@@ -949,7 +961,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 < ARRAY_SIZE(mmc_partnames); part_num++) {
+			if (!strcmp(argv[3], mmc_partnames[part_num]))
+				break;
+		}
+	} else {
+		part_num = dectoul(argv[3], NULL);
+	}
 	access = dectoul(argv[4], NULL);
 
 	/* acknowledge to be sent during boot operation */