[PATCH v2 4/4] cmd: gpt: fix gpt read

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sat Sep 2 09:35:24 CEST 2023


To partition a block device the partition type GUIDs are needed but
'gpt read' does not provide these. Add the missing parts.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
v2:
	use accessor for type_guid field
---
 cmd/gpt.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index e7a53747fc..8e1de24845 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -182,7 +182,9 @@ static int calc_parts_list_len(int numparts)
 	partlistlen += numparts * (strlen("start=0x,") + lbaint_size);
 	partlistlen += numparts * (strlen("size=0x,") + lbaint_size);
 	if (IS_ENABLED(CONFIG_PARTITION_UUIDS))
-		partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN);
+		partlistlen += numparts * (strlen("uuid=,") + UUID_STR_LEN);
+	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
+		partlistlen += numparts * (strlen("type=;") + UUID_STR_LEN);
 	debug("Length of partitions_list is %d for %d partitions\n",
 	      partlistlen, numparts);
 	return partlistlen;
@@ -221,6 +223,9 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info,
 	if (IS_ENABLED(CONFIG_PARTITION_UUIDS))
 		disk_partition_set_uuid(&newpart->gpt_part_info,
 					disk_partition_uuid(info));
+	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
+		disk_partition_set_type_guid(&newpart->gpt_part_info,
+					     disk_partition_type_guid(info));
 	newpart->partnum = partnum;
 
 	return newpart;
@@ -259,6 +264,9 @@ static void print_gpt_info(void)
 		if (CONFIG_IS_ENABLED(PARTITION_UUIDS))
 			printf("UUID %s\n",
 			       disk_partition_uuid(&curr->gpt_part_info));
+		if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
+			printf("Type GUID %s\n",
+			       disk_partition_type_guid(&curr->gpt_part_info));
 		printf("\n");
 	}
 }
@@ -308,6 +316,12 @@ static int create_gpt_partitions_list(int numparts, const char *guid,
 				disk_partition_uuid(&curr->gpt_part_info),
 				UUID_STR_LEN + 1);
 		}
+		if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+			strcat(partitions_list, ",type=");
+			strncat(partitions_list,
+				disk_partition_type_guid(&curr->gpt_part_info),
+				UUID_STR_LEN + 1);
+		}
 		strcat(partitions_list, ";");
 	}
 	return 0;
-- 
2.40.1



More information about the U-Boot mailing list