efi_selftest: test block io revision and pointers

Enhance the unit test to verify all Revision fields and all pointers of all
the EFI_BLOCK_IO_PROTOCOL structures.
As the unit test registers its own block io protocol for test purposes,
make sure to initialize its revision properly, as it will be verified as
well.

This can run on the sandbox with the following command:

  ./u-boot -T -c 'setenv efi_selftest block device; bootefi selftest'

Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
Vincent Stehlé
2026-07-16 00:40:42 +02:00
committed by Heinrich Schuchardt
parent 226a73bf1b
commit 650dcf4520
@@ -173,6 +173,7 @@ static efi_status_t decompress(u8 **image)
static struct efi_block_io_media media;
static struct efi_block_io block_io = {
.revision = EFI_BLOCK_IO_PROTOCOL_REVISION3,
.media = &media,
.reset = reset,
.read_blocks = read_blocks,
@@ -615,6 +616,68 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Get all handles with block io. */
ret = boottime->locate_handle_buffer(BY_PROTOCOL,
&block_io_protocol_guid, NULL,
&no_handles, &handles);
switch (ret) {
case EFI_SUCCESS:
if (!no_handles || !handles) {
efi_st_error("Locate handle buffer bad handles\n");
return EFI_ST_FAILURE;
}
break;
case EFI_NOT_FOUND:
efi_st_error("No block IO protocol found though one installed in setup\n");
return EFI_ST_FAILURE;
default:
efi_st_error("Locate handle buffer failed\n");
return EFI_ST_FAILURE;
}
/* Verify all handles with block io. */
for (i = 0; i < no_handles; ++i) {
u64 rev;
ret = boottime->open_protocol(handles[i],
&block_io_protocol_guid,
(void *)&block_io_protocol,
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (ret != EFI_SUCCESS) {
efi_st_error("Failed to open block io protocol %d\n",
(unsigned int)i);
return EFI_ST_FAILURE;
}
/* Verify block io revision. */
rev = block_io_protocol->revision;
if (rev != EFI_BLOCK_IO_PROTOCOL_REVISION2 &&
rev != EFI_BLOCK_IO_PROTOCOL_REVISION3) {
efi_st_error("Bad block io revision %u\n",
(unsigned int)rev);
return EFI_ST_FAILURE;
}
/* Verify block io pointers. */
if (!block_io_protocol->media ||
!block_io_protocol->reset ||
!block_io_protocol->read_blocks ||
!block_io_protocol->write_blocks ||
!block_io_protocol->flush_blocks) {
efi_st_error("Bad block io pointer\n");
return EFI_ST_FAILURE;
}
}
/* Free handles buffer. */
ret = boottime->free_pool(handles);
handles = NULL; /* Avoid double free on teardown(). */
if (ret != EFI_SUCCESS) {
efi_st_error("Failed to free block io handles\n");
return EFI_ST_FAILURE;
}
return EFI_ST_SUCCESS;
}