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?
On Wed, 18 Jun 2025 at 11:01, Javier Martinez Canillas <javi...@redhat.com> wrote: > > Test 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. > > Suggested-by: Tom Rini <tr...@konsulko.com> > Signed-off-by: Javier Martinez Canillas <javi...@redhat.com> > --- Reviewed-by: Ilias Apalodimas <ilias.apalodi...@linaro.org> > > 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(+) > > diff --git a/lib/efi_selftest/efi_selftest_block_device.c > b/lib/efi_selftest/efi_selftest_block_device.c > index a367e8b89d17..0ee909da87d6 100644 > --- a/lib/efi_selftest/efi_selftest_block_device.c > +++ b/lib/efi_selftest/efi_selftest_block_device.c > @@ -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 >