[U-Boot] [PATCH v6 12/18] cmd: part: update command to support GPT over MTD

Patrick Delaunay patrick.delaunay at st.com
Thu May 11 07:52:02 UTC 2017


support part list for MTD device
> part list nand 0
> part list nor 0

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---

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

 cmd/part.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/cmd/part.c b/cmd/part.c
index 8ba0598..ef5d979 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -21,6 +21,7 @@
 #include <command.h>
 #include <part.h>
 #include <vsprintf.h>
+#include <linux/mtd/mtd.h>
 
 static int do_part_uuid(int argc, char * const argv[])
 {
@@ -48,10 +49,14 @@ static int do_part_uuid(int argc, char * const argv[])
 static int do_part_list(int argc, char * const argv[])
 {
 	int ret;
-	struct blk_desc *desc;
+	struct blk_desc *desc = NULL;
 	char *var = NULL;
 	bool bootable = false;
 	int i;
+#ifdef CONFIG_EFI_PARTITION_MTD
+	struct mtd_info *mtd = NULL;
+	char mtd_dev[16];
+#endif
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
@@ -77,10 +82,19 @@ static int do_part_list(int argc, char * const argv[])
 			return CMD_RET_USAGE;
 	}
 
-	ret = blk_get_device_by_str(argv[0], argv[1], &desc);
-	if (ret < 0)
-		return 1;
-
+#ifdef CONFIG_EFI_PARTITION_MTD
+	if ((strlen(argv[0]) + strlen(argv[1])) < sizeof(mtd_dev)) {
+		sprintf(mtd_dev, "%s%s", argv[0], argv[1]);
+		mtd = get_mtd_device_nm(mtd_dev);
+	}
+	if (IS_ERR(mtd)) {
+#endif
+		ret = blk_get_device_by_str(argv[0], argv[1], &desc);
+		if (ret < 0)
+			return 1;
+#ifdef CONFIG_EFI_PARTITION_MTD
+	}
+#endif
 	if (var != NULL) {
 		int p;
 		char str[512] = { '\0', };
@@ -88,10 +102,21 @@ static int do_part_list(int argc, char * const argv[])
 
 		for (p = 1; p < 128; p++) {
 			char t[5];
-			int r = part_get_info(desc, p, &info);
+			int r;
 
-			if (r != 0)
-				continue;
+			if (desc) {
+				r = part_get_info(desc, p, &info);
+				if (r != 0)
+					continue;
+			}
+#ifdef CONFIG_EFI_PARTITION_MTD
+			else {
+				r = part_get_info_efi_mtd(mtd, p, &info);
+				/* Stop for first non valid partition */
+				if (r != 0)
+					break;
+			}
+#endif
 
 			if (bootable && !info.bootable)
 				continue;
@@ -100,10 +125,18 @@ static int do_part_list(int argc, char * const argv[])
 			strcat(str, t);
 		}
 		setenv(var, str);
+
 		return 0;
 	}
 
+#ifndef CONFIG_EFI_PARTITION_MTD
 	part_print(desc);
+#else
+	if (desc)
+		part_print(desc);
+	else
+		part_print_efi_mtd(mtd);
+#endif
 
 	return 0;
 }
-- 
1.9.1



More information about the U-Boot mailing list