Skip to contentSkip to conversation

cmd: part: Add 'number' sub-command

PATCH New Igor Opaniuk 4 participants 7 messages Jun 14, 2019 – Jul 24, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

From: Ruslan Trofymenko <[email protected]>

This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition.

Use case:
For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used:

=> setenv bootpart 1:f

where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed.

So it would be nice to get rid of that 0xf magic number and use partition name instead, like this:

=> part number mmc 1 userdata part_num
=> setenv bootpart 1:${part_num}

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/part.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
cmd/part.c +15 -1
index bfb6488b0f..653e13ced1 100644
@@ -24,6 +24,7 @@
 enum cmd_part_info {
 	CMD_PART_INFO_START = 0,
 	CMD_PART_INFO_SIZE,
+	CMD_PART_INFO_NUMBER
 };
 
 static int do_part_uuid(int argc, char * const argv[])
@@ -149,6 +150,9 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
 	case CMD_PART_INFO_SIZE:
 		snprintf(buf, sizeof(buf), LBAF, info.size);
 		break;
+	case CMD_PART_INFO_NUMBER:
+		snprintf(buf, sizeof(buf), "%d", part);
+		break;
 	default:
 		printf("** Unknown cmd_part_info value: %d\n", param);
 		return 1;
@@ -172,6 +176,11 @@ static int do_part_size(int argc, char * const argv[])
 	return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
 }
 
+static int do_part_number(int argc, char * const argv[])
+{
+	return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	if (argc < 2)
@@ -185,6 +194,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return do_part_start(argc - 2, argv + 2);
 	else if (!strcmp(argv[1], "size"))
 		return do_part_size(argc - 2, argv + 2);
+	else if (!strcmp(argv[1], "number"))
+		return do_part_number(argc - 2, argv + 2);
 
 	return CMD_RET_USAGE;
 }
@@ -206,5 +217,8 @@ U_BOOT_CMD(
 	"      part can be either partition number or partition name\n"
 	"part size <interface> <dev> <part> <varname>\n"
 	"    - set environment variable to the size of the partition (in blocks)\n"
-	"      part can be either partition number or partition name"
+	"      part can be either partition number or partition name\n"
+	"part number <interface> <dev> <part> <varname>\n"
+	"    - set environment variable to the partition number using the partition name\n"
+	"      part must be specified as partition name"
 );
Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

Hi Igor,

I believe it's common sense, best practice and it is generally polite to include in CC anybody who contributed with review comments during the previous patch iterations. Otherwise, it raises questions, mistrust and all kind of weird assumptions, which may hurt the community in the long run. I believe the beauty of community-driven development is being straight to each other and keeping things transparent. So, if you don't mind, please include me in CC if I've already commented on your patches.

Signature · 2 lines
Best regards,
Eugeniu.
#2 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

Hi Eugeniu,

Quoted 12 lines · Eugeniu Rosca

Hi Igor,

I believe it's common sense, best practice and it is generally polite to include in CC anybody who contributed with review comments during the previous patch iterations. Otherwise, it raises questions, mistrust and all kind of weird assumptions, which may hurt the community in the long run. I believe the beauty of community-driven development is being straight to each other and keeping things transparent. So, if you don't mind, please include me in CC if I've already commented on your patches.

Quoted 3 lines

--
Best regards,
Eugeniu.

Sorry, it's just my inattention (Friday evening, you know :) ), I've copied-pasted (yes,
I still can't force myself to use patman and somehow automate this process) the list of people from CC headers from v3 patch [1], so please don't take it personally.

Thanks for all your effort and reviews of my patches, I really appreciate it.

[1] https://patchwork.ozlabs.org/patch/1044151/

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#3 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

In reply to Igor Opaniuk

Hi Igor,

Once again:

Thanks!

Quoted 93 lines · Igor Opaniuk

From: Ruslan Trofymenko <[email protected]>

This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition.

Use case:
For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used:

=> setenv bootpart 1:f

where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed.

So it would be nice to get rid of that 0xf magic number and use partition name instead, like this:

=> part number mmc 1 userdata part_num
=> setenv bootpart 1:${part_num}

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/part.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
cmd/part.c +15 -2
index bfb6488b0f..653e13ced1 100644
@@ -24,6 +24,7 @@
 enum cmd_part_info {
        CMD_PART_INFO_START = 0,
        CMD_PART_INFO_SIZE,
+       CMD_PART_INFO_NUMBER
 };
 
 static int do_part_uuid(int argc, char * const argv[])
@@ -149,6 +150,9 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
        case CMD_PART_INFO_SIZE:
                snprintf(buf, sizeof(buf), LBAF, info.size);
                break;
+       case CMD_PART_INFO_NUMBER:
+               snprintf(buf, sizeof(buf), "%d", part);
+               break;
        default:
                printf("** Unknown cmd_part_info value: %d\n", param);
                return 1;
@@ -172,6 +176,11 @@ static int do_part_size(int argc, char * const argv[])
        return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
 }
 
+static int do_part_number(int argc, char * const argv[])
+{
+       return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        if (argc < 2)
@@ -185,6 +194,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return do_part_start(argc - 2, argv + 2);
        else if (!strcmp(argv[1], "size"))
                return do_part_size(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "number"))
+               return do_part_number(argc - 2, argv + 2);
 
        return CMD_RET_USAGE;
 }
@@ -206,5 +217,8 @@ U_BOOT_CMD(
        "      part can be either partition number or partition name\n"
        "part size <interface> <dev> <part> <varname>\n"
        "    - set environment variable to the size of the partition (in blocks)\n"
-       "      part can be either partition number or partition name"
+       "      part can be either partition number or partition name\n"
+       "part number <interface> <dev> <part> <varname>\n"
+       "    - set environment variable to the partition number using the partition name\n"
+       "      part must be specified as partition name"
 );
--

2.17.1

#4 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

Hi Tom,

Quoted 88 lines · Sam Protsenko

Hi Igor,

Once again:

Thanks!

Quoted 78 lines · Igor Opaniuk

From: Ruslan Trofymenko <[email protected]>

This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition.

Use case:
For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used:

=> setenv bootpart 1:f

where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed.

So it would be nice to get rid of that 0xf magic number and use partition name instead, like this:

=> part number mmc 1 userdata part_num
=> setenv bootpart 1:${part_num}

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/part.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
cmd/part.c +11 -0
index bfb6488b0f..653e13ced1 100644
@@ -24,6 +24,7 @@
 enum cmd_part_info {
        CMD_PART_INFO_START = 0,
        CMD_PART_INFO_SIZE,
+       CMD_PART_INFO_NUMBER
 };
 
 static int do_part_uuid(int argc, char * const argv[])
@@ -149,6 +150,9 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
        case CMD_PART_INFO_SIZE:
                snprintf(buf, sizeof(buf), LBAF, info.size);
                break;
+       case CMD_PART_INFO_NUMBER:
+               snprintf(buf, sizeof(buf), "%d", part);
+               break;
        default:
                printf("** Unknown cmd_part_info value: %d\n", param);
                return 1;
@@ -172,6 +176,11 @@ static int do_part_size(int argc, char * const argv[])
        return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
 }
 
+static int do_part_number(int argc, char * const argv[])
+{
+       return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        if (argc < 2)
@@ -185,6 +194,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return do_part_start(argc - 2, argv + 2);
        else if (!strcmp(argv[1], "size"))
                return do_part_size(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "number"))
+               return do_part_number(argc - 2, argv + 2);
 
Quoted 15 lines
Quoted 13 lines
cmd/part.c +4 -2
        return CMD_RET_USAGE;
 }
@@ -206,5 +217,8 @@ U_BOOT_CMD(
        "      part can be either partition number or partition name\n"
        "part size <interface> <dev> <part> <varname>\n"
        "    - set environment variable to the size of the partition (in blocks)\n"
-       "      part can be either partition number or partition name"
+       "      part can be either partition number or partition name\n"
+       "part number <interface> <dev> <part> <varname>\n"
+       "    - set environment variable to the partition number using the partition name\n"
+       "      part must be specified as partition name"
 );
--
Quoted 2 lines

2.17.1

Are there any objections from your side to get this patch applied? If there are any comments/suggestions, please let me know!

Thanks!

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#5 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

Quoted 102 lines · Igor Opaniuk

Hi Tom,

Quoted 98 lines · Sam Protsenko

Hi Igor,

Once again:

Thanks!

Quoted 88 lines · Igor Opaniuk

From: Ruslan Trofymenko <[email protected]>

This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition.

Use case:
For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used:

=> setenv bootpart 1:f

where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed.

So it would be nice to get rid of that 0xf magic number and use partition name instead, like this:

=> part number mmc 1 userdata part_num
=> setenv bootpart 1:${part_num}

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 cmd/part.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
cmd/part.c +14 -1
index bfb6488b0f..653e13ced1 100644
@@ -24,6 +24,7 @@
 enum cmd_part_info {
        CMD_PART_INFO_START = 0,
        CMD_PART_INFO_SIZE,
+       CMD_PART_INFO_NUMBER
 };
 
 static int do_part_uuid(int argc, char * const argv[])
@@ -149,6 +150,9 @@ static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
        case CMD_PART_INFO_SIZE:
                snprintf(buf, sizeof(buf), LBAF, info.size);
                break;
+       case CMD_PART_INFO_NUMBER:
+               snprintf(buf, sizeof(buf), "%d", part);
+               break;
        default:
                printf("** Unknown cmd_part_info value: %d\n", param);
                return 1;
@@ -172,6 +176,11 @@ static int do_part_size(int argc, char * const argv[])
        return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
 }
 
+static int do_part_number(int argc, char * const argv[])
+{
+       return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        if (argc < 2)
@@ -185,6 +194,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return do_part_start(argc - 2, argv + 2);
        else if (!strcmp(argv[1], "size"))
                return do_part_size(argc - 2, argv + 2);
+       else if (!strcmp(argv[1], "number"))
+               return do_part_number(argc - 2, argv + 2);
 
        return CMD_RET_USAGE;
 }
@@ -206,5 +217,8 @@ U_BOOT_CMD(
        "      part can be either partition number or partition name\n"
        "part size <interface> <dev> <part> <varname>\n"
        "    - set environment variable to the size of the partition (in blocks)\n"
-       "      part can be either partition number or partition name"
+       "      part can be either partition number or partition name\n"
+       "part number <interface> <dev> <part> <varname>\n"
+       "    - set environment variable to the partition number using the partition name\n"
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
cmd/part.c +1 -1
+       "      part must be specified as partition name"
 );
--

2.17.1

Are there any objections from your side to get this patch applied? If there are any comments/suggestions, please let me know!

I'll need to grab this by itself and see what the overall size growth from this code is, since it's adding new unconditional commands. While I don't think every new sub-command needs a CONFIG option, one of the common critiques of how U-Boot is going these days is that size is always growing on platforms that don't make use of this new functionality.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190715/ad7c9ec1/attachment.sig>
#6 lore raw

PATCH v5 1/1 cmd: part: Add 'number' sub-command

In reply to Igor Opaniuk
Quoted 21 lines · Igor Opaniuk

From: Ruslan Trofymenko <[email protected]>

This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition.

Use case:
For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used:

=> setenv bootpart 1:f

where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed.

So it would be nice to get rid of that 0xf magic number and use partition name instead, like this:

=> part number mmc 1 userdata part_num
=> setenv bootpart 1:${part_num}

Quoted 6 lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190724/8f62a61e/attachment.sig>