Skip to contentSkip to conversation

cmd: part: Add partition-related type command

PATCH In review Enric Balletbo i Serra 2 participants 9 messages Jan 10, 2023 – Jan 19, 2023

lore
Share & tools
lore
#0 lore raw

v3 cover cmd: part: Add partition-related type command

This series are a consequence on the discussion of the patch [1]. It introduces some new patches in order to address the feedback received, adds the documentation and fixes a small typo found during the work on these patches.

Best regards,
Enric

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Changes in v3:
- Add the entry in doc/usage/cmd/index.rst.
- Provide examples for the other sub-commands.
- Fix return value chapter, 0 (true) on success and 1(false) on error.
- Add reviewed by tags

Changes in v2:
- New patch (1) in the series to fix a trivial type
- New patch (2) in the series to introduce the documentation of the part type command
- Fix typo s/partittion/partition/ in commit message
- Add gpt test for the part type command
- Add the man-page for part command in doc/usage/cmd

Enric Balletbo i Serra (4):
doc: man-page for the part command
doc/README.gpt: Fix typo 'a optionnal'
cmd: part: Add partition-related type command
test/py: gpt: add test for the gpt partition type GUID identifier

 cmd/part.c                |  29 +++++++
 doc/README.gpt            |   2 +-
 doc/usage/cmd/part.rst    | 154 ++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst       |   1 +
 test/py/tests/test_gpt.py |  23 ++++++
 5 files changed, 208 insertions(+), 1 deletion(-)
 create mode 100644 doc/usage/cmd/part.rst
Signature · 1 line
2.39.0
#1 lore raw

PATCH v3 1/4 doc: man-page for the part command

Provide a man-page for the part command.

---

Changes in v3:
- Add the entry in doc/usage/cmd/index.rst.
- Provide examples for the other sub-commands.
- Fix return value chapter, 0 (true) on success and 1(false) on error.
- Add reviewed by tags

Changes in v2:
- New patch (1) in the series to fix a trivial type
- New patch (2) in the series to introduce the documentation of the part type command
- Fix typo s/partittion/partition/ in commit message
- Add gpt test for the part type command
- Add the man-page for part command in doc/usage/cmd

 doc/usage/cmd/part.rst | 136 +++++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst    |   1 +
 2 files changed, 137 insertions(+)
 create mode 100644 doc/usage/cmd/part.rst
doc/usage/cmd/part.rst new file +136 -0
new file mode 100644
index 0000000000..ed464b180b
@@ -0,0 +1,136 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+part command
+===============
+
+Synopis
+-------
+
+::
+
+    part uuid <interface> <dev>:<part> [varname]
+    part list <interface> <dev> [flags] [varname]
+    part start <interface> <dev> <part> <varname>
+    part size <interface> <dev> <part> <varname>
+    part number <interface> <dev> <part> <varname>
+    part types
+
+Description
+-----------
+
+The `part` command is used to manage disk partition related commands.
+
+The 'part uuid' command prints or sets an environment variable to partition UUID
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    varname
+        an optional environment variable to store the current partition UUID value into.
+
+The 'part list' command prints or sets an environment variable to the list of partitions
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    flags
+        -bootable
+            lists only bootable partitions
+    varname
+        an optional environment variable to store the list of partitions value into.
+
+The 'part start' commnad sets an environment variable to the start of the partition (in blocks),
+part can be either partition number or partition name.
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    varname
+        a variable to store the current start of the partition value into.
+
+The 'part size' command sets an environment variable to the size of the partition (in blocks),
+part can be either partition number or partition name.
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    varname
+        a variable to store the current size of the partition value into.
+
+The 'part number' command sets an environment variable to the partition number using the partition name,
+part must be specified as partition name.
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    varname
+        a variable to store the current partition number value into
+
+The 'part types' command list supported partition table types.
+
+Examples
+--------
+
+::
+
+    => host bind 0 ./test_gpt_disk_image.bin
+    => part uuid host 0:1
+    24156b69-3378-497f-bb3e-b982223de528
+    => part uuid host 0:1 varname
+    => env print varname
+    varname=24156b69-3378-497f-bb3e-b982223de528
+    =>
+    => part list host 0
+
+    Partition Map for HOST device 0  --   Partition Type: EFI
+
+    Part	Start LBA	End LBA		Name
+    Attributes
+    Type GUID
+    Partition GUID
+    1	        0x00000800	0x00000fff	"second"
+    attrs:	0x0000000000000000
+    type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
+                (data)
+    guid:	24156b69-3378-497f-bb3e-b982223de528
+    2	        0x00001000	0x00001bff	"first"
+    attrs:	0x0000000000000000
+    type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
+                (data)
+    guid:	5272ee44-29ab-4d46-af6c-4b45ac67d3b7
+    =>
+    => part start host 0 2 varname
+    => env print varname
+    varname=1000
+    =>
+    => part size host 0 2 varname
+    => env print varname
+    varname=c00
+    =>
+    => part number host 0 2 varname
+    => env print varname
+    varname=0x2
+    =>
+    => part types
+    Supported partition tables: EFI, AMIGA, DOS, ISO, MAC
+
+Return value
+------------
+
+The return value $? is set to 0 (true) if the command succededd. If an
+error occurs, the return value $? is set to 1 (false).
doc/usage/index.rst +1 -0
index bbd40a6e18..cf3666a77d 100644
@@ -61,6 +61,7 @@ Shell commands
    cmd/mbr
    cmd/md
    cmd/mmc
+   cmd/part
    cmd/pause
    cmd/pinmux
    cmd/printenv
Signature · 1 line
2.39.0
#3 lore raw

PATCH v3 2/4 doc/README.gpt: Fix typo 'a optionnal'

In reply to Enric Balletbo i Serra

Change the string 'a optionnal' to 'an optional'.

---

(no changes since v1)

 doc/README.gpt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
doc/README.gpt +1 -1
index 91e397d06f..cc2a1b7ac7 100644
@@ -260,7 +260,7 @@ Partition type GUID:
 For created partition, the used partition type GUID is
 PARTITION_BASIC_DATA_GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
 
-If you define 'CONFIG_PARTITION_TYPE_GUID', a optionnal parameter 'type'
+If you define 'CONFIG_PARTITION_TYPE_GUID', an optional parameter 'type'
 can specify a other partition type guid:
 
      "uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
Signature · 1 line
2.39.0
#5 lore raw

PATCH v3 3/4 cmd: part: Add partition-related type command

In reply to Enric Balletbo i Serra

This implements the following command:

part type mmc 0:1
-> print partition type UUID
part type mmc 0:1 uuid
-> set environment variable to partition type UUID

"part type" can be useful when writing a bootcmd which searches for a specific partition type to enable automatic discovery of partitions and their intended usage or mount point.

---

(no changes since v1)

 cmd/part.c             | 29 +++++++++++++++++++++++++++++
 doc/usage/cmd/part.rst | 18 ++++++++++++++++++
 2 files changed, 47 insertions(+)
cmd/part.c +29 -0
index 9d419c967c..26b0cc84fe 100644
@@ -182,6 +182,29 @@ static int do_part_number(int argc, char *const argv[])
 	return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
 }
 
+static int do_part_type(int argc, char *const argv[])
+{
+	int part;
+	struct blk_desc *dev_desc;
+	struct disk_partition info;
+
+	if (argc < 2)
+		return CMD_RET_USAGE;
+	if (argc > 3)
+		return CMD_RET_USAGE;
+
+	part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
+	if (part < 0)
+		return 1;
+
+	if (argc > 2)
+		env_set(argv[2], info.type_guid);
+	else
+		printf("%s\n", info.type_guid);
+
+	return 0;
+}
+
 static int do_part_types(int argc, char * const argv[])
 {
 	struct part_driver *drv = ll_entry_start(struct part_driver,
@@ -218,6 +241,8 @@ static int do_part(struct cmd_tbl *cmdtp, int flag, int argc,
 		return do_part_size(argc - 2, argv + 2);
 	else if (!strcmp(argv[1], "number"))
 		return do_part_number(argc - 2, argv + 2);
+	else if (!strcmp(argv[1], "type"))
+		return do_part_type(argc - 2, argv + 2);
 	else if (!strcmp(argv[1], "types"))
 		return do_part_types(argc - 2, argv + 2);
 	return CMD_RET_USAGE;
@@ -244,6 +269,10 @@ U_BOOT_CMD(
 	"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\n"
+	"part type <interface> <dev>:<part>\n"
+	"    - print partition type\n"
+	"part type <interface> <dev>:<part> <varname>\n"
+	"    - set environment variable to partition type\n"
 	"part types\n"
 	"    - list supported partition table types"
 );
doc/usage/cmd/part.rst +18 -0
index ed464b180b..8d2a280391 100644
@@ -13,6 +13,7 @@ Synopis
     part start <interface> <dev> <part> <varname>
     part size <interface> <dev> <part> <varname>
     part number <interface> <dev> <part> <varname>
+    part type <interface> <dev>:<part> [varname]
     part types
 
 Description
@@ -81,6 +82,17 @@ part must be specified as partition name.
     varname
         a variable to store the current partition number value into
 
+The 'part type' command prints or sets an environment variable to the partition type UUID.
+
+    interface
+        interface for accessing the block device (mmc, sata, scsi, usb, ....)
+    dev
+        device number
+    part
+        partition number
+    varname
+        a variable to store the current partition type UUID value into
+
 The 'part types' command list supported partition table types.
 
 Examples
@@ -126,6 +138,12 @@ Examples
     => env print varname
     varname=0x2
     =>
+    => part type host 0:1
+    ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
+    => part type host 0:1 varname
+    => env print varname
+    varname=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
+    =>
     => part types
     Supported partition tables: EFI, AMIGA, DOS, ISO, MAC
 
Signature · 1 line
2.39.0
#6 lore raw
Quoted 7 lines · Enric Balletbo i Serra

This implements the following command:

part type mmc 0:1
-> print partition type UUID
part type mmc 0:1 uuid
-> set environment variable to partition type UUID

Quoted 6 lines

"part type" can be useful when writing a bootcmd which searches for a specific partition type to enable automatic discovery of partitions and their intended usage or mount point.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#7 lore raw

PATCH v3 4/4 test/py: gpt: add test for the gpt partition type GUID identifier

In reply to Enric Balletbo i Serra

Add sandbox test for the gpt partition type command, the test uses the persistent data test_gpt_disk_image.bin to check that the first partition type GUID that identifies the type of the partition has the "Linux filesystem data" type ( 0FC63DAF-8483-4772-8E79-3D69D8477DE4 ).

---

(no changes since v1)

 test/py/tests/test_gpt.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
test/py/tests/test_gpt.py +23 -0
index cb44e1d789..73bfbf77a2 100644
@@ -134,6 +134,29 @@ def test_gpt_save_guid(state_disk_image, u_boot_console):
     output = u_boot_console.run_command('printenv newguid')
     assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
 
[email protected]('sandbox')
[email protected]('cmd_gpt')
[email protected]('sgdisk')
+def test_gpt_part_type_uuid(state_disk_image, u_boot_console):
+    """Test the gpt partittion type UUID command."""
+
+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
+    output = u_boot_console.run_command('part type host 0:1')
+    assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output
+
[email protected]('sandbox')
[email protected]('cmd_gpt')
[email protected]('sgdisk')
+def test_gpt_part_type_save_uuid(state_disk_image, u_boot_console):
+    """Test the gpt partittion type to save UUID into a string."""
+
+    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+        pytest.skip('gpt command not supported')
+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
+    output = u_boot_console.run_command('part type host 0:1 newguid')
+    output = u_boot_console.run_command('printenv newguid')
+    assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output
+
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_gpt')
 @pytest.mark.buildconfigspec('cmd_gpt_rename')
Signature · 1 line
2.39.0
#8 lore raw

Re: [PATCH v3 4/4] test/py: gpt: add test for the gpt partition type GUID identifier

Quoted 6 lines · Enric Balletbo i Serra

Add sandbox test for the gpt partition type command, the test uses the persistent data test_gpt_disk_image.bin to check that the first partition type GUID that identifies the type of the partition has the "Linux filesystem data" type ( 0FC63DAF-8483-4772-8E79-3D69D8477DE4 ).

Applied to u-boot/master, thanks!

Signature · 1 line
Tom