[PATCH v2 1/4] disk: Add partition lookup by type GUID functionality
Simon Glass
sjg at chromium.org
Tue Jan 13 21:03:11 CET 2026
Hi Balaji,
On Fri, 9 Jan 2026 at 00:09, Balaji Selvanathan
<balaji.selvanathan at oss.qualcomm.com> wrote:
>
> Introduce part_get_info_by_type_guid() function to enable partition
> lookup using partition type GUID. This complements the existing UUID
> lookup functionality and provides more flexible partition discovery
> mechanisms.
>
> Signed-off-by: Balaji Selvanathan <balaji.selvanathan at oss.qualcomm.com>
> ---
> Changes in v2:
> - No changes
>
> disk/part.c | 39 +++++++++++++++++++++++++++++++++++++++
> include/part.h | 21 +++++++++++++++++++++
> 2 files changed, 60 insertions(+)
Do you feel able to write a test for this? There is a ChromeOS image
(mmc5.img) which has a lot of GUIDs in it.
root = oftree_root(oftree_default());
node = ofnode_find_subnode(root, "mmc5");
ut_assert(ofnode_valid(node));
ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
Then something like:
struct udevice *dev, blk;
ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, &dev))
ut_assertok(blk_get_from_parent(dev, &blk));
// it would be better if your function took a struct udevice *, but
that conversion has not been completed for other functions yet, so up
to you...
struct blk_desc *desc = mmc_get_blk_desc(struct mmc *mmc)
>
> diff --git a/disk/part.c b/disk/part.c
> index 49a0fca6b89..2bc21dd66cc 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -731,6 +731,45 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
> return -ENOENT;
> }
>
> +int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
> + struct disk_partition *info)
> +{
> + struct part_driver *part_drv;
> + int ret;
> + int i;
> +
> + if (!IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
> + return -ENOENT;
> +
> + part_drv = part_driver_lookup_type(desc);
> + if (!part_drv)
> + return -1;
-ENOENT ? We should not return -PERM in an open-coded way
> +
> + if (!part_drv->get_info) {
> + log_debug("## Driver %s does not have the get_info() method\n",
> + part_drv->name);
> + return -ENOSYS;
> + }
> +
> + for (i = 1; i < part_drv->max_entries; i++) {
> + ret = part_drv->get_info(desc, i, info);
> + if (ret != 0) {
if (ret)
> + /*
> + * Partition with this index can't be obtained, but
> + * further partitions might be, so keep checking.
> + */
> + continue;
> + }
> +
> + if (!strncasecmp(type_guid, disk_partition_type_guid(info), UUID_STR_LEN)) {
long line?
> + /* matched */
> + return i;
> + }
> + }
> +
> + return -ENOENT;
> +}
> +
> /**
> * Get partition info from device number and partition name.
> *
> diff --git a/include/part.h b/include/part.h
> index daebbbc2e68..85457618cdf 100644
> --- a/include/part.h
> +++ b/include/part.h
> @@ -327,6 +327,20 @@ int part_get_info_by_name(struct blk_desc *desc, const char *name,
> int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
> struct disk_partition *info);
>
> +/**
> + * part_get_info_by_type_guid() - Search for a partition by type GUID
> + * among all available registered partitions
> + *
> + * @desc: block device descriptor
> + * @type_guid: the specified partition type GUID
> + * @info: the disk partition info
> + *
> + * Return: the partition number on match (starting on 1), -ENOENT on no match,
> + * otherwise error
> + */
> +int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
> + struct disk_partition *info);
> +
> /**
> * part_get_info_by_dev_and_name_or_num() - Get partition info from dev number
> * and part name, or dev number and
> @@ -404,6 +418,13 @@ static inline int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
> return -ENOENT;
> }
>
> +static inline int part_get_info_by_type_guid(struct blk_desc *desc,
> + const char *type_guid,
> + struct disk_partition *info)
> +{
> + return -ENOENT;
> +}
> +
> static inline int
> part_get_info_by_dev_and_name_or_num(const char *dev_iface,
> const char *dev_part_str,
> --
> 2.34.1
>
Regards,
Simon
More information about the U-Boot
mailing list