Skip to contentSkip to conversation

efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support

PATCH Superseded Javier Martinez Canillas 5 participants 18 messages Jun 13, 2025 – Jun 16, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support

This patch series implements support for the EFI_PARTITION_INFO_PROTOCOL, to provide cached partition information for GPT partition types.

The EFI specification mentions that the protocol can understand legacy MBR partition types, but that's for backward compatibility and not implemented by this series. It can be added as a follow-up if needed, to make it fully compliant with the spec.

Patch #1 moves the logic to get a GPT partition table entry to a helper part_get_gpt_pte() function.

Patch #2 exposes that helper function to be used by the efi_loader.

Patch #3 implements the actual protocol support using the mentioned helper to get the GPT partitions table entries.

Javier Martinez Canillas (3):
disk: efi: Move logic to get a GPT entry into a helper function
disk: efi: expose the part_get_gpt_pte() helper function
efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support

 disk/part_efi.c           | 67 +++++++++++++++++++++++----------------
 include/part.h            | 14 ++++++++
 include/part_efi.h        | 20 ++++++++++++
 lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++--
 4 files changed, 110 insertions(+), 29 deletions(-)
Signature · 4 lines
2.49.0

base-commit: 2ab10ed2399b0c1c790733884935c94ad65aa2a8
branch: add-efi-part-info-proto
#1 lore raw

PATCH 1/3 disk: efi: Move logic to get a GPT entry into a helper function

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

 disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +40 -27
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
 	return 0;
 }
 
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+	gpt_entry *gpt_pte = NULL;
+
+	/* "part" argument must be at least 1 */
+	if (part < 1) {
+		log_debug("Invalid Argument(s)\n");
+		return -EINVAL;
+	}
+
+	/* This function validates AND fills in the GPT header and PTE */
+	if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
+		return -EINVAL;
+
+	if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
+	    !is_pte_valid(&gpt_pte[part - 1])) {
+		log_debug("Invalid partition number %d\n", part);
+		free(gpt_pte);
+		return -EPERM;
+	}
+
+	memcpy(gpt_e, &gpt_pte[part - 1], sizeof(*gpt_e));
+
+	free(gpt_pte);
+	return 0;
+}
+
 static void __maybe_unused part_print_efi(struct blk_desc *desc)
 {
 	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
@@ -261,45 +289,32 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc)
 static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
 					    struct disk_partition *info)
 {
-	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
-	gpt_entry *gpt_pte = NULL;
-
-	/* "part" argument must be at least 1 */
-	if (part < 1) {
-		log_debug("Invalid Argument(s)\n");
-		return -EINVAL;
-	}
-
-	/* This function validates AND fills in the GPT header and PTE */
-	if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
-		return -EINVAL;
+	gpt_entry gpt_pte = {};
+	int ret;
 
-	if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
-	    !is_pte_valid(&gpt_pte[part - 1])) {
-		log_debug("Invalid partition number %d\n", part);
-		free(gpt_pte);
-		return -EPERM;
-	}
+	ret = part_get_gpt_pte(desc, part, &gpt_pte);
+	if (ret)
+		return ret;
 
 	/* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */
-	info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba);
+	info->start = (lbaint_t)le64_to_cpu(gpt_pte.starting_lba);
 	/* The ending LBA is inclusive, to calculate size, add 1 to it */
-	info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1
+	info->size = (lbaint_t)le64_to_cpu(gpt_pte.ending_lba) + 1
 		     - info->start;
 	info->blksz = desc->blksz;
 
 	snprintf((char *)info->name, sizeof(info->name), "%s",
-		 print_efiname(&gpt_pte[part - 1]));
+		 print_efiname(&gpt_pte));
 	strcpy((char *)info->type, "U-Boot");
-	info->bootable = get_bootable(&gpt_pte[part - 1]);
-	info->type_flags = gpt_pte[part - 1].attributes.fields.type_guid_specific;
+	info->bootable = get_bootable(&gpt_pte);
+	info->type_flags = gpt_pte.attributes.fields.type_guid_specific;
 	if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
-		uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b,
+		uuid_bin_to_str(gpt_pte.unique_partition_guid.b,
 				(char *)disk_partition_uuid(info),
 				UUID_STR_FORMAT_GUID);
 	}
 	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
-		uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b,
+		uuid_bin_to_str(gpt_pte.partition_type_guid.b,
 				(char *)disk_partition_type_guid(info),
 				UUID_STR_FORMAT_GUID);
 	}
@@ -307,8 +322,6 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
 	log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start,
 		  info->size, info->name);
 
-	/* Remember to free pte */
-	free(gpt_pte);
 	return 0;
 }
 
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 1/3] disk: efi: Move logic to get a GPT entry into a helper function

Quoted 16 lines · Javier Martinez Canillas

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

 disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +0 -0
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
        return 0;

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 226

Quoted 10 lines
disk/part_efi.c +8 -0
 }
 
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+       gpt_entry *gpt_pte = NULL;
+
+       /* "part" argument must be at least 1 */
+       if (part < 1) {
+               log_debug("Invalid Argument(s)\n");

I think this should be a log_err an match the comment above

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 236

Quoted 10 lines
disk/part_efi.c +10 -0
+               return -EINVAL;
+       }
+
+       /* This function validates AND fills in the GPT header and PTE */
+       if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
+               return -EINVAL;
+
+       if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
+           !is_pte_valid(&gpt_pte[part - 1])) {
+               log_debug("Invalid partition number %d\n", part);

I haven't read the reat yet, but isn't this something we want visible as a normal error?

Quoted 14 lines
disk/part_efi.c +10 -0
+               free(gpt_pte);
+               return -EPERM;
+       }
+
+       memcpy(gpt_e, &gpt_pte[part - 1], sizeof(*gpt_e));
+
+       free(gpt_pte);
+       return 0;
+}
+
 static void __maybe_unused part_print_efi(struct blk_desc *desc)
 {
        ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);

disk/part_efi.c static void __maybe_unused part_print_efi(struct blk_desc *desc) · line 290

Quoted 2 lines
disk/part_efi.c +0 -0
@@ -261,45 +289,32 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc)
 static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
                                            struct disk_partition *info)

[..]

Rest looks good

Thanks
/Ilias

#3 lore raw

Re: [PATCH 1/3] disk: efi: Move logic to get a GPT entry into a helper function

Quoted 20 lines · Ilias Apalodimas
Quoted 18 lines · Javier Martinez Canillas

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

  disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
  1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +0 -0
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
         return 0;
  }
 
Quoted 10 lines

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 226

Quoted 8 lines
disk/part_efi.c +8 -0
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+       gpt_entry *gpt_pte = NULL;
+
+       /* "part" argument must be at least 1 */
+       if (part < 1) {
+               log_debug("Invalid Argument(s)\n");

I think this should be a log_err an match the comment above

Screen output during a running EFI application like GRUB should be avoided as output will no longer match the expected cursor positioning for the EFI console.

Please, stick to log_debug().

Shell commands like gpt should write a message based on error codes.

Best regards

Heinrich

Quoted 37 lines

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 236

Quoted 11 lines
disk/part_efi.c +10 -0
+               return -EINVAL;
+       }
+
+       /* This function validates AND fills in the GPT header and PTE */
+       if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
+               return -EINVAL;
+
+       if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
+           !is_pte_valid(&gpt_pte[part - 1])) {
+               log_debug("Invalid partition number %d\n", part);

I haven't read the reat yet, but isn't this something we want visible as a normal error?

Quoted 14 lines
disk/part_efi.c +10 -0
+               free(gpt_pte);
+               return -EPERM;
+       }
+
+       memcpy(gpt_e, &gpt_pte[part - 1], sizeof(*gpt_e));
+
+       free(gpt_pte);
+       return 0;
+}
+
  static void __maybe_unused part_print_efi(struct blk_desc *desc)
  {
         ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);

disk/part_efi.c static void __maybe_unused part_print_efi(struct blk_desc *desc) · line 290

Quoted 2 lines
disk/part_efi.c +0 -0
@@ -261,45 +289,32 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc)
  static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
                                             struct disk_partition *info)

[..]

Rest looks good

Thanks
/Ilias

#4 lore raw

Re: [PATCH 1/3] disk: efi: Move logic to get a GPT entry into a helper function

Heinrich Schuchardt <[email protected]> writes:

Thanks Ilias and Heinrich for your review / feedback.

Quoted 32 lines · Ilias Apalodimas
Quoted 20 lines
Quoted 18 lines · Javier Martinez Canillas

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

  disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
  1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +0 -0
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
         return 0;
  }
 
Quoted 10 lines

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 226

Quoted 8 lines
disk/part_efi.c +8 -0
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+       gpt_entry *gpt_pte = NULL;
+
+       /* "part" argument must be at least 1 */
+       if (part < 1) {
+               log_debug("Invalid Argument(s)\n");

I think this should be a log_err an match the comment above

Quoted 6 lines

Screen output during a running EFI application like GRUB should be avoided as output will no longer match the expected cursor positioning for the EFI console.

Please, stick to log_debug().

I agree. This allows to have for example flicker-free boot output. But also, I tried to follow the convention I noticed in this file and AFAICT most messages printouts were using just log_debug().

Quoted 6 lines

Shell commands like gpt should write a message based on error codes.

Best regards

Heinrich

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#5 lore raw

Re: [PATCH 1/3] disk: efi: Move logic to get a GPT entry into a helper function

Quoted 41 lines · Javier Martinez Canillas

Heinrich Schuchardt <[email protected]> writes:

Thanks Ilias and Heinrich for your review / feedback.

Quoted 36 lines · Ilias Apalodimas
Quoted 20 lines
Quoted 18 lines · Javier Martinez Canillas

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

  disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
  1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +0 -0
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
         return 0;
  }
 
Quoted 10 lines

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 226

Quoted 8 lines
disk/part_efi.c +8 -0
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+       gpt_entry *gpt_pte = NULL;
+
+       /* "part" argument must be at least 1 */
+       if (part < 1) {
+               log_debug("Invalid Argument(s)\n");

I think this should be a log_err an match the comment above

Screen output during a running EFI application like GRUB should be avoided as output will no longer match the expected cursor positioning for the EFI console.

Quoted 6 lines
Quoted 2 lines

Please, stick to log_debug().

I agree. This allows to have for example flicker-free boot output. But also, I tried to follow the convention I noticed in this file and AFAICT most messages printouts were using just log_debug().

Ah yes, Heinrich is right, I forgot that this is going to be plugged in an EFI protocol

Thanks
/Ilias

Quoted 15 lines
Quoted 7 lines

Shell commands like gpt should write a message based on error codes.

Best regards

Heinrich

--
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat

#6 lore raw

Re: [PATCH 1/3] disk: efi: Move logic to get a GPT entry into a helper function

Ilias Apalodimas <[email protected]> writes:

Hello Ilias,

Quoted 46 lines
Quoted 44 lines · Javier Martinez Canillas

Heinrich Schuchardt <[email protected]> writes:

Thanks Ilias and Heinrich for your review / feedback.

Quoted 38 lines · Ilias Apalodimas
Quoted 20 lines
Quoted 18 lines · Javier Martinez Canillas

Factor out the logic to get the Partition Table Entry (PTE) of a given partition into a helper function, since it could be used by other code.

---

  disk/part_efi.c | 67 +++++++++++++++++++++++++++++--------------------
  1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +0 -0
index 932d058c184c..c7d79e253958 100644
@@ -216,6 +216,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
         return 0;
  }
 
Quoted 10 lines

disk/part_efi.c int get_disk_guid(struct blk_desc *desc, char *guid) · line 226

Quoted 8 lines
disk/part_efi.c +8 -0
+static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+{
+       ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
+       gpt_entry *gpt_pte = NULL;
+
+       /* "part" argument must be at least 1 */
+       if (part < 1) {
+               log_debug("Invalid Argument(s)\n");

I think this should be a log_err an match the comment above

Screen output during a running EFI application like GRUB should be avoided as output will no longer match the expected cursor positioning for the EFI console.

Please, stick to log_debug().

Quoted 7 lines
Quoted 3 lines

I agree. This allows to have for example flicker-free boot output. But also, I tried to follow the convention I noticed in this file and AFAICT most messages printouts were using just log_debug().

Ah yes, Heinrich is right, I forgot that this is going to be plugged in an EFI protocol

Cool, does it mean that I've your r-b tag for this patch too ?

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#7 lore raw

PATCH 2/3 disk: efi: expose the part_get_gpt_pte() helper function

In reply to Javier Martinez Canillas

This function will be used by the EFI application disk support code to provide data required by the EFI_PARTITION_INFORMATION_PROTOCOL.

---

 disk/part_efi.c |  2 +-
 include/part.h  | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
disk/part_efi.c +1 -1
index c7d79e253958..9f7907075887 100644
@@ -216,7 +216,7 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
 	return 0;
 }
 
-static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
 {
 	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
 	gpt_entry *gpt_pte = NULL;
include/part.h +14 -0
index fcb3c13dea4d..ae36f23e33bb 100644
@@ -628,6 +628,20 @@ int gpt_verify_partitions(struct blk_desc *desc,
  */
 int get_disk_guid(struct blk_desc *desc, char *guid);
 
+/**
+ * part_get_gpt_pte() - Get the GPT partition table entry of a partition
+ *
+ * This function reads the GPT partition table entry (PTE) for a given
+ * block device and partition number.
+ *
+ * @desc:	block device descriptor
+ * @part:	partition number for which to return the PTE
+ * @gpt_e:	GPT partition table entry
+ *
+ * Return:	0 on success, otherwise error
+ */
+int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e);
+
 #endif
 
 #if CONFIG_IS_ENABLED(DOS_PARTITION)
Signature · 1 line
2.49.0
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] disk: efi: expose the part_get_gpt_pte() helper function

Thanks Javier,

Quoted 6 lines · Javier Martinez Canillas

This function will be used by the EFI application disk support code to provide data required by the EFI_PARTITION_INFORMATION_PROTOCOL.

---

Quoted 46 lines
 disk/part_efi.c |  2 +-
 include/part.h  | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
disk/part_efi.c +1 -1
index c7d79e253958..9f7907075887 100644
@@ -216,7 +216,7 @@ int get_disk_guid(struct blk_desc *desc, char *guid)
        return 0;
 }
 
-static int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
+int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e)
 {
        ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
        gpt_entry *gpt_pte = NULL;
include/part.h +14 -1
index fcb3c13dea4d..ae36f23e33bb 100644
@@ -628,6 +628,20 @@ int gpt_verify_partitions(struct blk_desc *desc,
  */
 int get_disk_guid(struct blk_desc *desc, char *guid);
 
+/**
+ * part_get_gpt_pte() - Get the GPT partition table entry of a partition
+ *
+ * This function reads the GPT partition table entry (PTE) for a given
+ * block device and partition number.
+ *
+ * @desc:      block device descriptor
+ * @part:      partition number for which to return the PTE
+ * @gpt_e:     GPT partition table entry
+ *
+ * Return:     0 on success, otherwise error
+ */
+int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e);
+
 #endif
 
 #if CONFIG_IS_ENABLED(DOS_PARTITION)
--

2.49.0

#9 lore raw

PATCH 3/3 efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support

In reply to Javier Martinez Canillas

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

This patch just implements support for GPT partition types. The legacy MBR partition types is only needed for backward compatibility and can be added as a follow-up if needed, to make it fully compliant with the EFI spec.

---

 include/part_efi.h        | 20 ++++++++++++++++++++
 lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 56 insertions(+), 2 deletions(-)
include/part_efi.h +20 -0
index 59b7895b8a23..fb402df6f13e 100644
@@ -138,4 +138,24 @@ typedef struct _legacy_mbr {
 	__le16 signature;
 } __packed legacy_mbr;
 
+#define EFI_PARTITION_INFO_PROTOCOL_GUID \
+	EFI_GUID(0x8cf2f62c, 0xbc9b, 0x4821, 0x80, \
+		 0x8d, 0xec, 0x9e, 0xc4, 0x21, 0xa1, 0xa0)
+
+#define EFI_PARTITION_INFO_PROTOCOL_REVISION 0x0001000
+#define PARTITION_TYPE_OTHER 0x00
+#define PARTITION_TYPE_MBR 0x01
+#define PARTITION_TYPE_GPT 0x02
+
+struct efi_partition_info {
+	u32 revision;
+	u32 type;
+	u8 system;
+	u8 reserved[7];
+	union {
+		struct partition mbr;
+		gpt_entry gpt;
+	} info;
+} __packed;
+
 #endif	/* _DISK_PART_EFI_H */
lib/efi_loader/efi_disk.c +36 -2
index 47b583cc5e12..ba41b77b9d1c 100644
@@ -26,6 +26,7 @@ struct efi_system_partition efi_system_partition = {
 
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
+const efi_guid_t efi_partition_info_guid = EFI_PARTITION_INFO_PROTOCOL_GUID;
 
 /**
  * struct efi_disk_obj - EFI disk object
@@ -35,6 +36,7 @@ const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
  * @media:	block I/O media information
  * @dp:		device path to the block device
  * @volume:	simple file system protocol of the partition
+ * @info:	EFI partition info protocol interface
  */
 struct efi_disk_obj {
 	struct efi_object header;
@@ -42,6 +44,7 @@ struct efi_disk_obj {
 	struct efi_block_io_media media;
 	struct efi_device_path *dp;
 	struct efi_simple_file_system_protocol *volume;
+	struct efi_partition_info info;
 };
 
 /**
@@ -426,6 +429,7 @@ static efi_status_t efi_disk_add_dev(
 	/* Fill in object data */
 	if (part_info) {
 		struct efi_device_path *node = efi_dp_part_node(desc, part);
+		struct efi_partition_info *info = &diskobj->info;
 		struct efi_handler *handler;
 		void *protocol_interface;
 
@@ -454,18 +458,47 @@ static efi_status_t efi_disk_add_dev(
 			goto error;
 		}
 
+		info->revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
+
+		switch (desc->part_type) {
+		case PART_TYPE_EFI:
+			info->type = PARTITION_TYPE_GPT;
+			ret = part_get_gpt_pte(desc, part, &info->info.gpt);
+			if (ret) {
+				log_debug("get PTE for part %d failed %ld\n",
+					  part, ret);
+				goto error;
+			}
+
+			break;
+		case PART_TYPE_DOS:
+			info->type = PARTITION_TYPE_MBR;
+
+			/* TODO: implement support for MBR partition types */
+			log_debug("EFI_PARTITION_INFO_PROTOCOL doesn't support MBR\n");
+
+			break;
+		default:
+			info->type = PARTITION_TYPE_OTHER;
+
+			break;
+		}
+
 		diskobj->dp = efi_dp_append_node(dp_parent, node);
 		efi_free_pool(node);
 		diskobj->media.last_block = part_info->size - 1;
-		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION)
+		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
 			esp_guid = &efi_system_partition_guid;
+			info->system = 1;
+		}
+
 	} else {
 		diskobj->dp = efi_dp_from_part(desc, part);
 		diskobj->media.last_block = desc->lba - 1;
 	}
 
 	/*
-	 * Install the device path and the block IO protocol.
+	 * Install the device path, the block IO and partition info protocols.
 	 *
 	 * InstallMultipleProtocolInterfaces() checks if the device path is
 	 * already installed on an other handle and returns EFI_ALREADY_STARTED
@@ -476,6 +509,7 @@ static efi_status_t efi_disk_add_dev(
 					&handle,
 					&efi_guid_device_path, diskobj->dp,
 					&efi_block_io_guid, &diskobj->ops,
+					&efi_partition_info_guid, &diskobj->info,
 					/*
 					 * esp_guid must be last entry as it
 					 * can be NULL. Its interface is NULL.
Signature · 1 line
2.49.0
#10 lore raw

Am 13. Juni 2025 10:57:38 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 3 lines

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

U-Boot is targeting the EBBR specifcation which defines a subset of UEFI.

Which application needs this protocol?
Are you planning to add it to the EBBR specification?

Best regards

Heinrich

Quoted 135 lines

This patch just implements support for GPT partition types. The legacy MBR partition types is only needed for backward compatibility and can be added as a follow-up if needed, to make it fully compliant with the EFI spec.

---

include/part_efi.h | 20 ++++++++++++++++++++
lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--

2 files changed, 56 insertions(+), 2 deletions(-)
include/part_efi.h +20 -0
index 59b7895b8a23..fb402df6f13e 100644
@@ -138,4 +138,24 @@ typedef struct _legacy_mbr {
 	__le16 signature;
 } __packed legacy_mbr;
 
+#define EFI_PARTITION_INFO_PROTOCOL_GUID \
+	EFI_GUID(0x8cf2f62c, 0xbc9b, 0x4821, 0x80, \
+		 0x8d, 0xec, 0x9e, 0xc4, 0x21, 0xa1, 0xa0)
+
+#define EFI_PARTITION_INFO_PROTOCOL_REVISION 0x0001000
+#define PARTITION_TYPE_OTHER 0x00
+#define PARTITION_TYPE_MBR 0x01
+#define PARTITION_TYPE_GPT 0x02
+
+struct efi_partition_info {
+	u32 revision;
+	u32 type;
+	u8 system;
+	u8 reserved[7];
+	union {
+		struct partition mbr;
+		gpt_entry gpt;
+	} info;
+} __packed;
+
 #endif	/* _DISK_PART_EFI_H */
lib/efi_loader/efi_disk.c +36 -2
index 47b583cc5e12..ba41b77b9d1c 100644
@@ -26,6 +26,7 @@ struct efi_system_partition efi_system_partition = {
 
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
+const efi_guid_t efi_partition_info_guid = EFI_PARTITION_INFO_PROTOCOL_GUID;
 
 /**
 * struct efi_disk_obj - EFI disk object
@@ -35,6 +36,7 @@ const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
 * @media:	block I/O media information
 * @dp:		device path to the block device
 * @volume:	simple file system protocol of the partition
+ * @info:	EFI partition info protocol interface
 */
 struct efi_disk_obj {
 	struct efi_object header;
@@ -42,6 +44,7 @@ struct efi_disk_obj {
 	struct efi_block_io_media media;
 	struct efi_device_path *dp;
 	struct efi_simple_file_system_protocol *volume;
+	struct efi_partition_info info;
 };
 
 /**
@@ -426,6 +429,7 @@ static efi_status_t efi_disk_add_dev(
 	/* Fill in object data */
 	if (part_info) {
 		struct efi_device_path *node = efi_dp_part_node(desc, part);
+		struct efi_partition_info *info = &diskobj->info;
 		struct efi_handler *handler;
 		void *protocol_interface;
 
@@ -454,18 +458,47 @@ static efi_status_t efi_disk_add_dev(
 			goto error;
 		}
 
+		info->revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
+
+		switch (desc->part_type) {
+		case PART_TYPE_EFI:
+			info->type = PARTITION_TYPE_GPT;
+			ret = part_get_gpt_pte(desc, part, &info->info.gpt);
+			if (ret) {
+				log_debug("get PTE for part %d failed %ld\n",
+					  part, ret);
+				goto error;
+			}
+
+			break;
+		case PART_TYPE_DOS:
+			info->type = PARTITION_TYPE_MBR;
+
+			/* TODO: implement support for MBR partition types */
+			log_debug("EFI_PARTITION_INFO_PROTOCOL doesn't support MBR\n");
+
+			break;
+		default:
+			info->type = PARTITION_TYPE_OTHER;
+
+			break;
+		}
+
 		diskobj->dp = efi_dp_append_node(dp_parent, node);
 		efi_free_pool(node);
 		diskobj->media.last_block = part_info->size - 1;
-		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION)
+		if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
 			esp_guid = &efi_system_partition_guid;
+			info->system = 1;
+		}
+
 	} else {
 		diskobj->dp = efi_dp_from_part(desc, part);
 		diskobj->media.last_block = desc->lba - 1;
 	}
 
 	/*
-	 * Install the device path and the block IO protocol.
+	 * Install the device path, the block IO and partition info protocols.
 	 *
 	 * InstallMultipleProtocolInterfaces() checks if the device path is
 	 * already installed on an other handle and returns EFI_ALREADY_STARTED
@@ -476,6 +509,7 @@ static efi_status_t efi_disk_add_dev(
 					&handle,
 					&efi_guid_device_path, diskobj->dp,
 					&efi_block_io_guid, &diskobj->ops,
+					&efi_partition_info_guid, &diskobj->info,
 					/*
 					 * esp_guid must be last entry as it
 					 * can be NULL. Its interface is NULL.
#11 lore raw

Heinrich Schuchardt <[email protected]> writes:

Hello Heinrich,

Thanks for your feedback.

Quoted 7 lines

Am 13. Juni 2025 10:57:38 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 3 lines

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

U-Boot is targeting the EBBR specifcation which defines a subset of UEFI.

Interesting. I knew that the u-boot EFI implementation was to support SystemReady IR (what is now called SystemReady DeviceTree) and EBBR, but I didn't know that meant to only implement what's required by EBBR.

I noticed that EFI_PARTITION_INFO_PROTOCOL is not even required by SBBR and only EFI_BLOCK_IO_PROTOCOL is required there just like for EBBR.

Quoted 1 line

Which application needs this protocol?

We are experimenting with a new A/B boot protocol and an EFI binary that implements it. It's inspired on what the Android Boot Loader does for its A/B booting too.

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Quoted 2 lines

Are you planning to add it to the EBBR specification?

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

Quoted 4 lines

Best regards

Heinrich

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#12 lore raw

Am 13. Juni 2025 16:54:48 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 23 lines

Heinrich Schuchardt <[email protected]> writes:

Hello Heinrich,

Thanks for your feedback.

Quoted 7 lines

Am 13. Juni 2025 10:57:38 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 3 lines

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

U-Boot is targeting the EBBR specifcation which defines a subset of UEFI.

Interesting. I knew that the u-boot EFI implementation was to support SystemReady IR (what is now called SystemReady DeviceTree) and EBBR, but I didn't know that meant to only implement what's required by EBBR.

I noticed that EFI_PARTITION_INFO_PROTOCOL is not even required by SBBR and only EFI_BLOCK_IO_PROTOCOL is required there just like for EBBR.

Quoted 1 line

Which application needs this protocol?

Quoted 7 lines

We are experimenting with a new A/B boot protocol and an EFI binary that implements it. It's inspired on what the Android Boot Loader does for its A/B booting too.

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Linaro already implemented A/B EFI Boot in U-Boot. (https://docs.u-boot.org/en/latest/develop/uefi/fwu_updates.html). What are you missing in the existing solution?

Best regards

Heinrich

Quoted 13 lines
Quoted 3 lines

Are you planning to add it to the EBBR specification?

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

Quoted 4 lines

Best regards

Heinrich

#13 lore raw
Quoted 28 lines · Heinrich Schuchardt

Am 13. Juni 2025 16:54:48 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 27 lines

Heinrich Schuchardt <[email protected]> writes:

Hello Heinrich,

Thanks for your feedback.

Quoted 7 lines

Am 13. Juni 2025 10:57:38 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 3 lines

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

U-Boot is targeting the EBBR specifcation which defines a subset of UEFI.

Interesting. I knew that the u-boot EFI implementation was to support SystemReady IR (what is now called SystemReady DeviceTree) and EBBR, but I didn't know that meant to only implement what's required by EBBR.

I noticed that EFI_PARTITION_INFO_PROTOCOL is not even required by SBBR and only EFI_BLOCK_IO_PROTOCOL is required there just like for EBBR.

Quoted 1 line

Which application needs this protocol?

We are experimenting with a new A/B boot protocol and an EFI binary that implements it. It's inspired on what the Android Boot Loader does for its A/B booting too.

Quoted 6 lines
Quoted 3 lines

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Linaro already implemented A/B EFI Boot in U-Boot. (https://docs.u-boot.org/en/latest/develop/uefi/fwu_updates.html). What are you missing in the existing solution?

Maybe I haven't explained myself clearly but we are talking about different things here. The solution you mention is to support A/B *firmware* updates, while I was talking about A/B *Linux kernel* updates.

ukiboot already works on platforms that use an edk2 based EFI firmwares, since these provide the EFI_PARTITION_INFO_PROTOCOL. I just want to make it work on platforms that use u-boot instead.

Quoted 4 lines

Best regards

Heinrich

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#14 lore raw
In reply to Javier Martinez Canillas
Quoted 31 lines · Javier Martinez Canillas

Heinrich Schuchardt <[email protected]> writes:

Hello Heinrich,

Thanks for your feedback.

Quoted 7 lines

Am 13. Juni 2025 10:57:38 MESZ schrieb Javier Martinez Canillas <[email protected]>:

Quoted 3 lines

The UEFI 2.10 specification mentions that this protocol shall be installed along with EFI_BLOCK_IO_PROTOCOL. It provides cached partition information for MBR and GPT partition types.

U-Boot is targeting the EBBR specifcation which defines a subset of UEFI.

Interesting. I knew that the u-boot EFI implementation was to support SystemReady IR (what is now called SystemReady DeviceTree) and EBBR, but I didn't know that meant to only implement what's required by EBBR.

I noticed that EFI_PARTITION_INFO_PROTOCOL is not even required by SBBR and only EFI_BLOCK_IO_PROTOCOL is required there just like for EBBR.

Quoted 1 line

Which application needs this protocol?

We are experimenting with a new A/B boot protocol and an EFI binary that implements it. It's inspired on what the Android Boot Loader does for its A/B booting too.

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Quoted 6 lines
Quoted 2 lines

Are you planning to add it to the EBBR specification?

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

We are not strictly and only EBBR requirements, if there is good reason to add more features (and tests). But Heinrich's follow-up question is quite important. I feel like there's already a half dozen offerings of A/B update that works within UEFI.

Signature · 1 line
Tom
#15 lore raw

Tom Rini <[email protected]> writes:

Hello Tom,

Quoted 1 line · Javier Martinez Canillas

[...]

Quoted 4 lines
Quoted 4 lines

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Are you planning to add it to the EBBR specification?

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

We are not strictly and only EBBR requirements, if there is good reason

That's good to know. Heinrich's answer seemed to imply that u-boot was limited to EBBR requirements.

Quoted 1 line

to add more features (and tests). But Heinrich's follow-up question is

Oh, I missed the lib/efi_selftest directory. I'll see to add a test then.

Quoted 3 lines

quite important. I feel like there's already a half dozen offerings of A/B update that works within UEFI.

I just brought the A/B boot protocol used by ukiboot because I was asked how I was using the EFI_PARTITION_INFO_PROTOCOL. But I'm not proposing to add a new A/B update mechanism for u-boot, just to implement an existing EFI protocol...

Quoted 2 lines
Signature · 1 line
Tom
Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#16 lore raw
Quoted 15 lines · Javier Martinez Canillas

Tom Rini <[email protected]> writes:

Hello Tom,

Quoted 1 line · Javier Martinez Canillas

[...]

Quoted 7 lines
Quoted 7 lines

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Quoted 2 lines

Are you planning to add it to the EBBR specification?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

We are not strictly and only EBBR requirements, if there is good reason

That's good to know. Heinrich's answer seemed to imply that u-boot was limited to EBBR requirements.

It's one of the main users, yes, but it shouldn't be seen as *only* for that.

Quoted 3 lines
Quoted 1 line

to add more features (and tests). But Heinrich's follow-up question is

Oh, I missed the lib/efi_selftest directory. I'll see to add a test then.

Thanks.

Quoted 8 lines
Quoted 3 lines

quite important. I feel like there's already a half dozen offerings of A/B update that works within UEFI.

I just brought the A/B boot protocol used by ukiboot because I was asked how I was using the EFI_PARTITION_INFO_PROTOCOL. But I'm not proposing to add a new A/B update mechanism for u-boot, just to implement an existing EFI protocol...

Yes, this was more a lament for the ecosystem as a whole really. The concept of A/B(/Golden) with various security features is pretty old at this point, there's many implementations. I wish there was not "here is yet another" in the space.

But regardless, we should aim to have U-Boot be able to be used with it. Otherwise my crystal ball says that a few years down the line it'll be hard to use Fedora-IoT-distro on common-device with U-Boot.

Signature · 1 line
Tom
#17 lore raw
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

The project is https://gitlab.com/CentOS/automotive/src/ukiboot and reads UKI (https://uapi-group.org/specifications/specs/unified_kernel_image)
images from raw data partitions. Just like ABL reads Android Boot images.

Quoted 2 lines

Are you planning to add it to the EBBR specification?

I haven't thought about it before but I also didn't know that u-boot had this requirement. Probably it should be documented somewhere to make it more clear? Maybe I didn't look enough but didn't find a doc in the repo.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

We are not strictly and only EBBR requirements, if there is good reason

That's good to know. Heinrich's answer seemed to imply that u-boot was limited to EBBR requirements.

It's one of the main users, yes, but it shouldn't be seen as *only* for that.

Also to note that EBBR is a living spec and can evolve, typically the way we've done that historically is to have an implementation, or at least patches, in U-Boot first to prove out the idea before putting something in the spec so IMO this is the right way to go about this.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

to add more features (and tests). But Heinrich's follow-up question is

Oh, I missed the lib/efi_selftest directory. I'll see to add a test then.

Thanks.

Yes, the lack of tests was the first thing I noticed on the patches ;-)

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

quite important. I feel like there's already a half dozen offerings of A/B update that works within UEFI.

I just brought the A/B boot protocol used by ukiboot because I was asked how I was using the EFI_PARTITION_INFO_PROTOCOL. But I'm not proposing to add a new A/B update mechanism for u-boot, just to implement an existing EFI protocol...

Quoted 8 lines

Yes, this was more a lament for the ecosystem as a whole really. The concept of A/B(/Golden) with various security features is pretty old at this point, there's many implementations. I wish there was not "here is yet another" in the space.

But regardless, we should aim to have U-Boot be able to be used with it. Otherwise my crystal ball says that a few years down the line it'll be hard to use Fedora-IoT-distro on common-device with U-Boot.

There's a basic concept of a fallback with the UEFI bootnext bits but yes, if UEFI actually had the ability to deal with proper A/B we wouldn't need a dozen different ways to do it, sigh, of course there's some harder things that also need to be addressed like changes for signing keys etc.

The other initial feedback I would ask is around a Kconfig to make it optional, will everyone want/need it, what's the size impact?

Cheers,
Peter