efi_loader: add EFI_PARTITION_INFO_PROTOCOL support
v2 cover efi_loader: 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.
Patch #4 extends the existing block io EFI selftest to also check for some cached data provided by the partition info protocol.
This is a v2 of the series, the first version can be found here:
https://lists.denx.de/pipermail/u-boot/2025-June/592237.html
The EFI_PARTITION_INFO_PROTOCOL implementation is added unconditionally, because the u-boot-size-test.sh reports the code increase is negligible:
./u-boot-size-test.sh qemu_arm64_lwip --all
...
01: Merge tag 'u-boot-dfu-20250616' of https://source.denx.de/u-boot/custodians/u-boot-dfu
02: disk: efi: Move logic to get a GPT entry into a helper function
03: disk: efi: expose the part_get_gpt_pte() helper function
04: efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support
05: efi_selftest: Add basic partition info check to block io test
5 0 0 /5 qemu_arm64_lwip
Completed: 5 total built, 5 newly), duration 0:01:32, rate 0.05 /tmp/qemu_arm64_lwip/add-efi-part-info-proto-v2/boards.cfg is up to date. Nothing to do. Summary of 5 commits for 1 boards (1 thread, 8 jobs per thread)
01: Merge tag 'u-boot-dfu-20250616' of https://source.denx.de/u-boot/custodians/u-boot-dfu
02: disk: efi: Move logic to get a GPT entry into a helper function
aarch64: (for 1/1 boards) all -64.0 text -64.0
qemu_arm64_lwip: all -64 text -64
u-boot: add: 0/0, grow: 0/-1 bytes: 0/-72 (-72)
function old new delta
part_get_info_efi 468 396 -72
03: disk: efi: expose the part_get_gpt_pte() helper function
aarch64: (for 1/1 boards) all +32.0 text +32.0
qemu_arm64_lwip: all +32 text +32
u-boot: add: 1/0, grow: 0/-1 bytes: 200/-164 (36)
function old new delta
part_get_gpt_pte - 200 +200
part_get_info_efi 396 232 -164
04: efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support
aarch64: (for 1/1 boards) all +144.0 rodata +16.0 text +128.0
qemu_arm64_lwip: all +144 rodata +16 text +128
u-boot: add: 0/0, grow: 1/0 bytes: 148/0 (148)
function old new delta
static.efi_disk_add_dev 636 784 +148
05: efi_selftest: Add basic partition info check to block io test
aarch64: (for 1/1 boards) all +563.0 rodata +179.0 text +384.0
qemu_arm64_lwip: all +563 rodata +179 text +384
u-boot: add: 1/0, grow: 1/0 bytes: 384/0 (384)
function old new delta
execute 36428 36796 +368
partition_info_guid - 16 +16
(no errors to report)
Changes in v2:
- Add a test for the EFI partition information protocol (Tom Rini).
Javier Martinez Canillas (4):
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
efi_selftest: Add basic partition info check to block io test
disk/part_efi.c | 67 ++++++++++++-------- include/part.h | 14 ++++ include/part_efi.h | 20 ++++++ lib/efi_loader/efi_disk.c | 38 ++++++++++- lib/efi_selftest/efi_selftest_block_device.c | 29 +++++++++ 5 files changed, 139 insertions(+), 29 deletions(-)
Signature · 4 lines
2.49.0 base-commit: 17012e3068d047ad71460f039eeb0c3be63f82a0 branch: add-efi-part-info-proto-v2
PATCH v2 1/4 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.
---
(no changes since v1)
disk/part_efi.c | 67 +++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 27 deletions(-)
disk/part_efi.c +40 -27
@@ -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
PATCH v2 2/4 disk: efi: expose the part_get_gpt_pte() helper function
In reply to Javier Martinez CanillasThis function will be used by the EFI application disk support code to provide data required by the EFI_PARTITION_INFORMATION_PROTOCOL.
---
(no changes since v1)
disk/part_efi.c | 2 +- include/part.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
disk/part_efi.c +1 -1
@@ -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
@@ -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
PATCH v2 3/4 efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support
In reply to Javier Martinez CanillasThe 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.
---
(no changes since v1)
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
@@ -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
@@ -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
Re: [PATCH v2 3/4] efi_loader: disk: add EFI_PARTITION_INFO_PROTOCOL support
Quoted 10 lines · 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.
Signed-off-by Javier Martinez Canillas <[email protected]>
Quoted 134 lines
---
(no changes since v1)
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@@ -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
-3@@ -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. -- 2.49.0
PATCH v2 4/4 efi_selftest: Add basic partition info check to block io test
In reply to Javier Martinez CanillasTest the EFI_PARTITION_INFO_PROTOCOL in the existing EFI_BLOCK_IO_PROTOCOL unit test. It is fairly basic, since it only checks that the values of the struct efi_partition_info .revision, .type and .system fields are correct.
It doesn't check the MBR partition record information, because that's not supported by the EFI_PARTITION_INFO_PROTOCOL implementation yet. The test can be extended once the support is implemented, or if the in-memory disk image used for the test is modified to have a GPT partition type instead.
---
Changes in v2:
- Add a test for the EFI partition information protocol (Tom Rini).
lib/efi_selftest/efi_selftest_block_device.c | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +29 -0
@@ -29,6 +29,7 @@ static struct efi_boot_services *boottime;static const efi_guid_t block_io_protocol_guid =EFI_BLOCK_IO_PROTOCOL_GUID ;static const efi_guid_t guid_device_path =EFI_DEVICE_PATH_PROTOCOL_GUID ; +static const efi_guid_t partition_info_guid =EFI_PARTITION_INFO_PROTOCOL_GUID ;static const efi_guid_t guid_simple_file_system_protocol =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID ;static const efi_guid_t guid_file_system_info =EFI_FILE_SYSTEM_INFO_GUID ;
@@ -310,6 +311,7 @@ static int execute(void)struct efi_file_system_info info;u16 label[12 ]; } system_info; +struct efi_partition_info *part_info;efi_uintn_t buf_size;char buf[16 ]__aligned(ARCH_DMA_MINALIGN) ;u32 part1_size;
@@ -375,6 +377,33 @@ static int execute(void) part1_size - 1);return EFI_ST_FAILURE ; } + +/* Open the partition information protocol */ + ret = boottime->open_protocol (handle_partition, + &partition_info_guid, + (void **)&part_info,NULL ,NULL , +EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to open partition information protocol\n" ); +return EFI_ST_FAILURE ; + } +/* Check that cached partition information is the expected */ +if (part_info->revision !=EFI_PARTITION_INFO_PROTOCOL_REVISION ) { +efi_st_error ("Partition info revision %x, expected %x\n" , + part_info->revision,EFI_PARTITION_INFO_PROTOCOL_REVISION ); +return EFI_ST_FAILURE ; + } +if (part_info->type !=PARTITION_TYPE_MBR ) { +efi_st_error ("Partition info type %x, expected %x\n" , + part_info->type,PARTITION_TYPE_MBR ); +return EFI_ST_FAILURE ; + } +if (part_info->system !=0 ) { +efi_st_error ("Partition info system %x, expected 0\n" , + part_info->system); +return EFI_ST_FAILURE ; + } +/* Open the simple file system protocol */ ret = boottime->open_protocol(handle_partition, &guid_simple_file_system_protocol,
Signature · 1 line
2.49.0
Re: [PATCH v2 4/4] efi_selftest: Add basic partition info check to block io test
Hi Heinrich
This looks reasonable to be, but a bit limited since we only check for MBR. However, this is not a patch limitation since the image we create on the fly is based on MBR.
I think this is a good start and we can extend it by creating a GPT based image as well?
Quoted 5 lines · Javier Martinez Canillas
Test the
EFI_PARTITION_INFO_PROTOCOLin the existingEFI_BLOCK_IO_PROTOCOLunit test. It is fairly basic, since it only checks that the values of the structefi_partition_info.revision, .type and .system fields are correct.
Quoted 8 lines
It doesn't check the MBR partition record information, because that's not supported by the
EFI_PARTITION_INFO_PROTOCOLimplementation yet. The test can be extended once the support is implemented, or if the in-memory disk image used for the test is modified to have a GPT partition type instead.Suggested-by Tom Rini <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
Quoted 64 lines
Changes in v2:
- Add a test for the EFI partition information protocol (Tom Rini).lib/efi_selftest/efi_selftest_block_device.c | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+)lib/efi_selftest/efi_selftest_block_device.c +29
-1@@ -29,6 +29,7 @@ static struct efi_boot_services *boottime;static const efi_guid_t block_io_protocol_guid =EFI_BLOCK_IO_PROTOCOL_GUID ;static const efi_guid_t guid_device_path =EFI_DEVICE_PATH_PROTOCOL_GUID ; +static const efi_guid_t partition_info_guid =EFI_PARTITION_INFO_PROTOCOL_GUID ;static const efi_guid_t guid_simple_file_system_protocol =EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID ;static const efi_guid_t guid_file_system_info =EFI_FILE_SYSTEM_INFO_GUID ;@@ -310,6 +311,7 @@ static int execute(void)struct efi_file_system_info info;u16 label[12 ]; } system_info; +struct efi_partition_info *part_info;efi_uintn_t buf_size;char buf[16 ]__aligned(ARCH_DMA_MINALIGN) ;u32 part1_size;@@ -375,6 +377,33 @@ static int execute(void) part1_size - 1);return EFI_ST_FAILURE ; } + +/* Open the partition information protocol */ + ret = boottime->open_protocol (handle_partition, + &partition_info_guid, + (void **)&part_info,NULL ,NULL , +EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to open partition information protocol\n" ); +return EFI_ST_FAILURE ; + } +/* Check that cached partition information is the expected */ +if (part_info->revision !=EFI_PARTITION_INFO_PROTOCOL_REVISION ) { +efi_st_error ("Partition info revision %x, expected %x\n" , + part_info->revision,EFI_PARTITION_INFO_PROTOCOL_REVISION ); +return EFI_ST_FAILURE ; + } +if (part_info->type !=PARTITION_TYPE_MBR ) { +efi_st_error ("Partition info type %x, expected %x\n" , + part_info->type,PARTITION_TYPE_MBR ); +return EFI_ST_FAILURE ; + } +if (part_info->system !=0 ) { +efi_st_error ("Partition info system %x, expected 0\n" , + part_info->system); +return EFI_ST_FAILURE ; + } +/* Open the simple file system protocol */ ret = boottime->open_protocol(handle_partition, &guid_simple_file_system_protocol, --2.49.0
Quoted 57 lines · Javier Martinez Canillas
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.
Patch #4 extends the existing block io EFI selftest to also check for some cached data provided by the partition info protocol.
This is a v2 of the series, the first version can be found here:
https://lists.denx.de/pipermail/u-boot/2025-June/592237.html
The
EFI_PARTITION_INFO_PROTOCOLimplementation is added unconditionally, because theu-boot-size-test.shreports the code increase is negligible:./u-boot-size-test.sh
qemu_arm64_lwip--all
...
01: Merge tag 'u-boot-dfu-20250616' of https://source.denx.de/u-boot/custodians/u-boot-dfu
02: disk: efi: Move logic to get a GPT entry into a helper function
03: disk: efi: expose thepart_get_gpt_pte()helper function
04:efi_loader: disk: addEFI_PARTITION_INFO_PROTOCOLsupport
05:efi_selftest: Add basic partition info check to block io test
5 0 0 /5qemu_arm64_lwip
Completed: 5 total built, 5 newly), duration 0:01:32, rate 0.05/tmp/qemu_arm64_lwip/add-efi-part-info-proto-v2/boards.cfgis up to date. Nothing to do. Summary of 5 commits for 1 boards (1 thread, 8 jobs per thread)
01: Merge tag 'u-boot-dfu-20250616' of https://source.denx.de/u-boot/custodians/u-boot-dfu
02: disk: efi: Move logic to get a GPT entry into a helper function
aarch64: (for 1/1 boards) all -64.0 text -64.0
qemu_arm64_lwip: all -64 text -64
u-boot: add: 0/0, grow: 0/-1 bytes: 0/-72 (-72)
function old new delta
part_get_info_efi468 396 -72
03: disk: efi: expose thepart_get_gpt_pte()helper function
aarch64: (for 1/1 boards) all +32.0 text +32.0
qemu_arm64_lwip: all +32 text +32
u-boot: add: 1/0, grow: 0/-1 bytes: 200/-164 (36)
function old new delta
part_get_gpt_pte- 200 +200
part_get_info_efi396 232 -164
04:efi_loader: disk: addEFI_PARTITION_INFO_PROTOCOLsupport
aarch64: (for 1/1 boards) all +144.0 rodata +16.0 text +128.0
qemu_arm64_lwip: all +144 rodata +16 text +128
u-boot: add: 0/0, grow: 1/0 bytes: 148/0 (148)
function old new delta
static.efi_disk_add_dev 636 784 +148
Quoted 8 lines
05:
efi_selftest: Add basic partition info check to block io test
aarch64: (for 1/1 boards) all +563.0 rodata +179.0 text +384.0
qemu_arm64_lwip: all +563 rodata +179 text +384
u-boot: add: 1/0, grow: 1/0 bytes: 384/0 (384)
function old new delta
execute 36428 36796 +368
partition_info_guid- 16 +16
(no errors to report)
Thanks for digging at the size part here. I don't think that amount of growth justifies a new Kconfig option.
Signature · 1 line
Tom
Tom Rini <[email protected]> writes:
Hello Tom,
Quoted 1 line · Javier Martinez Canillas
[...]
Quoted 9 lines
Quoted 8 lines
05:
efi_selftest: Add basic partition info check to block io test
aarch64: (for 1/1 boards) all +563.0 rodata +179.0 text +384.0
qemu_arm64_lwip: all +563 rodata +179 text +384
u-boot: add: 1/0, grow: 1/0 bytes: 384/0 (384)
function old new delta
execute 36428 36796 +368
partition_info_guid- 16 +16
(no errors to report)
Quoted 3 lines
Thanks for digging at the size part here. I don't think that amount of growth justifies a new
Kconfigoption.
On the contrary, thanks for pointing me to your script. It's really awesome.
Quoted 2 lines
Signature · 1 line
Tom
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Javier I reviewed the patches but I probably missed something.
I am getting a compilation error with the selftests applied. #include <part_efi.h> seems to be missing.
Thanks
/Ilias
Quoted 34 lines · Javier Martinez Canillas
Tom Rini <[email protected]> writes:
Hello Tom,
Quoted 1 line · Javier Martinez Canillas
[...]
Quoted 9 lines
Quoted 8 lines
05:
efi_selftest: Add basic partition info check to block io test
aarch64: (for 1/1 boards) all +563.0 rodata +179.0 text +384.0
qemu_arm64_lwip: all +563 rodata +179 text +384
u-boot: add: 1/0, grow: 1/0 bytes: 384/0 (384)
function old new delta
execute 36428 36796 +368
partition_info_guid- 16 +16
(no errors to report)Quoted 3 lines
Thanks for digging at the size part here. I don't think that amount of growth justifies a new
Kconfigoption.On the contrary, thanks for pointing me to your script. It's really awesome.
Quoted 2 lines
--
Tom--
Best regards,Javier Martinez Canillas
Core Platforms
Red Hat
Ilias Apalodimas <[email protected]> writes:
Hello Ilias,
Quoted 5 lines
Javier I reviewed the patches but I probably missed something.
I am getting a compilation error with the selftests applied. #include <
part_efi.h> seems to be missing.
Sorry about that. What's the command you are using to build so that I can replicate the issue. I tested with the following build command:
make qemu-x86_64_defconfig && make -j8
Quoted 4 lines
Thanks
/Ilias
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Hi Javier no worries
Quoted 7 lines · Javier Martinez Canillas
Ilias Apalodimas <[email protected]> writes:
Hello Ilias,
Quoted 2 lines
Javier I reviewed the patches but I probably missed something.
Quoted 8 lines
Quoted 3 lines
I am getting a compilation error with the selftests applied. #include <
part_efi.h> seems to be missing.Sorry about that. What's the command you are using to build so that I can replicate the issue. I tested with the following build command:
make qemu-x86_64_defconfig && make -j8
Yea that's ok. The problem appears only if you test the patches against -next. There are big changes in the kbuild system. AFAICT it's only that include missing to make -next happy.
Cheers
/Ilias
Quoted 13 lines
Quoted 5 lines
Thanks
/Ilias
--
Best regards,Javier Martinez Canillas
Core Platforms
Red Hat
Quoted 15 lines · Ilias Apalodimas
Hi Javier no worries
Quoted 11 lines · Javier Martinez Canillas
Ilias Apalodimas <[email protected]> writes:
Hello Ilias,
Quoted 5 lines
Javier I reviewed the patches but I probably missed something.
I am getting a compilation error with the selftests applied. #include <
part_efi.h> seems to be missing.
Quoted 9 lines
Quoted 4 lines
Sorry about that. What's the command you are using to build so that I can replicate the issue. I tested with the following build command:
make qemu-x86_64_defconfig && make -j8
Yea that's ok. The problem appears only if you test the patches against -next. There are big changes in the kbuild system. AFAICT it's only that include missing to make -next happy.
Thanks for letting me know and also for pointing out that I should base on -next. Once your pipeline [0] finishes, I'll rebase, fix and re-send.
[0]: https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/26761
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat