[PATCH 1/1] cmd: gpt: fix gpt read
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Sun Aug 27 09:43: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.
Part of gpt.c has been written to work with CONFIG_PARTITION_UUIDS=n. But
when reading the disk information this is not considered. Currently we let
CONFIG_CMD_GPT select CONFIG_PARTITION_UUIDS but we should enable dropping
this requirement.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
cmd/gpt.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 964056bd28..d5d525397f 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -173,7 +173,10 @@ static int calc_parts_list_len(int numparts)
/* see part.h for definition of struct disk_partition */
partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1);
partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1);
- partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1);
+ if (CONFIG_IS_ENABLED(PARTITION_UUIDS))
+ partlistlen += numparts * (strlen("uuid=,") + UUID_STR_LEN + 1);
+ if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
+ partlistlen += numparts * (strlen("type=;") + UUID_STR_LEN + 1);
/* for the terminating null */
partlistlen++;
debug("Length of partitions_list is %d for %d partitions\n", partlistlen,
@@ -217,6 +220,12 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info,
/* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */
newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
#endif
+#ifdef CONFIG_PARTITION_TYPE_GUID
+ strncpy(newpart->gpt_part_info.type_guid, (const char *)info->type_guid,
+ UUID_STR_LEN);
+ newpart->gpt_part_info.type_guid[UUID_STR_LEN] = '\0';
+#endif
+
newpart->partnum = partnum;
return newpart;
@@ -254,6 +263,9 @@ static void print_gpt_info(void)
curr->gpt_part_info.bootable & PART_BOOTABLE);
#ifdef CONFIG_PARTITION_UUIDS
printf("UUID %s\n", curr->gpt_part_info.uuid);
+#endif
+#ifdef CONFIG_PARTITION_TYPE_GUID
+ printf("Type GUID %s\n", curr->gpt_part_info.type_guid);
#endif
printf("\n");
}
@@ -298,10 +310,16 @@ static int create_gpt_partitions_list(int numparts, const char *guid,
(unsigned long long)curr->gpt_part_info.size *
curr->gpt_part_info.blksz);
strncat(partitions_list, partstr, PART_NAME_LEN + 1);
-
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
strcat(partitions_list, ",uuid=");
strncat(partitions_list, curr->gpt_part_info.uuid,
UUID_STR_LEN + 1);
+#endif
+#ifdef CONFIG_PARTITION_TYPE_GUID
+ strcat(partitions_list, ",type=");
+ strncat(partitions_list, curr->gpt_part_info.type_guid,
+ UUID_STR_LEN + 1);
+#endif
strcat(partitions_list, ";");
}
return 0;
--
2.40.1
More information about the U-Boot
mailing list