diff mbox series

[1/3] cmd: part: Add subcommand to list supported partition tables

Message ID 20200317140906.858558-2-lusus@denx.de
State New
Headers show
Series cmd: add driver, fs and part type listing commands | expand

Commit Message

Niel Fourie March 17, 2020, 2:09 p.m. UTC
Add a subcommand "types" to the part command, which lists the supported
partition table types.

Signed-off-by: Niel Fourie <lusus at denx.de>
CC: Simon Glass <sjg at chromium.org>
---
 cmd/part.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/cmd/part.c b/cmd/part.c
index 5e4e45ca6d..fae5df7b71 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -182,6 +182,26 @@  static int do_part_number(int argc, char * const argv[])
 	return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
 }
 
+static int do_part_types(int argc, char * const argv[])
+{
+	struct part_driver *drv = ll_entry_start(struct part_driver,
+						 part_driver);
+	const int n_ents = ll_entry_count(struct part_driver, part_driver);
+	struct part_driver *entry;
+	int i = 0;
+
+	puts("Supported partition tables");
+
+	for (entry = drv; entry != drv + n_ents; entry++) {
+		printf("%c %s", i ? ',' : ':', entry->name);
+		i++;
+	}
+	if (!i)
+		puts(": <none>");
+	puts("\n");
+	return CMD_RET_SUCCESS;
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	if (argc < 2)
@@ -197,7 +217,8 @@  static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		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], "types"))
+		return do_part_types(argc - 2, argv + 2);
 	return CMD_RET_USAGE;
 }
 
@@ -221,5 +242,7 @@  U_BOOT_CMD(
 	"      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"
+	"      part must be specified as partition name\n"
+	"part types\n"
+	"    - list supported partition table types"
 );