[PATCH v2 0/4] 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/20220727133534.126824-1-eba...
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 | 109 ++++++++++++++++++++++++++++++++++++++ test/py/tests/test_gpt.py | 23 ++++++++ 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 doc/usage/cmd/part.rst

Provide a man-page for the part command.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com ---
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 | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 doc/usage/cmd/part.rst
diff --git a/doc/usage/cmd/part.rst b/doc/usage/cmd/part.rst new file mode 100644 index 0000000000..be931e520f --- /dev/null +++ b/doc/usage/cmd/part.rst @@ -0,0 +1,97 @@ +.. 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' 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' 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' 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. + +Example +------- + +This example shows listing supported partition types:: + + U-Boot> part types + Supported partition tables: EFI, AMIGA, DOS, ISO, MAC + +Return value +------------ + +The return value $? is always 0 (true).

On Thu, 22 Dec 2022 at 07:25, Enric Balletbo i Serra eballetb@redhat.com wrote:
Provide a man-page for the part command.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com
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 | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 doc/usage/cmd/part.rst
Reviewed-by: Simon Glass sjg@chromium.org

On 12/22/22 11:30, Enric Balletbo i Serra wrote:
Provide a man-page for the part command.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com
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 | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 doc/usage/cmd/part.rst
diff --git a/doc/usage/cmd/part.rst b/doc/usage/cmd/part.rst new file mode 100644 index 0000000000..be931e520f --- /dev/null +++ b/doc/usage/cmd/part.rst
Thanks for providing this man-page.
The patch lacks an entry in doc/usage/cmd/index.rst.
@@ -0,0 +1,97 @@ +.. 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' 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' 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' sets an environment variable to the partition number using the partition name, +part must be specified as partition name.
- interfaceH
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.
+Example +-------
+This example shows listing supported partition types::
- U-Boot> part types
- Supported partition tables: EFI, AMIGA, DOS, ISO, MAC
Please, provide examples for the other sub-commands too.
+Return value +------------
+The return value $? is always 0 (true).
1 (false) is returned in case of errors. Please, have a look at the code.
Best regards
Heinrich

Change the string 'a optionnal' to 'an optional'.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com ---
(no changes since v1)
doc/README.gpt | 2 +- doc/usage/cmd/part.rst | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/doc/README.gpt b/doc/README.gpt index 91e397d06f..cc2a1b7ac7 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -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=...; diff --git a/doc/usage/cmd/part.rst b/doc/usage/cmd/part.rst index be931e520f..0d098c7e3f 100644 --- a/doc/usage/cmd/part.rst +++ b/doc/usage/cmd/part.rst @@ -45,7 +45,7 @@ The 'part list' command prints or sets an environment variable to the list of pa varname an optional environment variable to store the list of partitions value into.
-The 'part start' sets an environment variable to the start of the partition (in blocks), +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 @@ -57,7 +57,7 @@ part can be either partition number or partition name. varname a variable to store the current start of the partition value into.
-The 'part size' sets an environment variable to the size of the partition (in blocks), +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 @@ -69,7 +69,7 @@ part can be either partition number or partition name. varname a variable to store the current size of the partition value into.
-The 'part number' sets an environment variable to the partition number using the partition name, +The 'part number' command sets an environment variable to the partition number using the partition name, part must be specified as partition name.
interface

On Thu, 22 Dec 2022 at 07:25, Enric Balletbo i Serra eballetb@redhat.com wrote:
Change the string 'a optionnal' to 'an optional'.
among other things
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com
(no changes since v1)
doc/README.gpt | 2 +- doc/usage/cmd/part.rst | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com ---
(no changes since v1)
cmd/part.c | 29 +++++++++++++++++++++++++++++ doc/usage/cmd/part.rst | 12 ++++++++++++ 2 files changed, 41 insertions(+)
diff --git a/cmd/part.c b/cmd/part.c index 9d419c967c..26b0cc84fe 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -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" ); diff --git a/doc/usage/cmd/part.rst b/doc/usage/cmd/part.rst index 0d098c7e3f..85cca0f0c7 100644 --- a/doc/usage/cmd/part.rst +++ b/doc/usage/cmd/part.rst @@ -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.
Example

On Thu, 22 Dec 2022 at 07:26, Enric Balletbo i Serra eballetb@redhat.com wrote:
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.
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com
(no changes since v1)
cmd/part.c | 29 +++++++++++++++++++++++++++++ doc/usage/cmd/part.rst | 12 ++++++++++++ 2 files changed, 41 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

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 ).
Signed-off-by: Enric Balletbo i Serra eballetbo@redhat.com ---
(no changes since v1)
test/py/tests/test_gpt.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py index cb44e1d789..73bfbf77a2 100644 --- a/test/py/tests/test_gpt.py +++ b/test/py/tests/test_gpt.py @@ -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
+@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.requiredtool('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 + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.requiredtool('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')
participants (3)
-
Enric Balletbo i Serra
-
Heinrich Schuchardt
-
Simon Glass