summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent StehlĂ© <[email protected]>2026-06-26 16:47:59 +0200
committerHeinrich Schuchardt <[email protected]>2026-07-16 00:40:42 +0200
commit650dcf4520ac451db7a4dd3298034224181564e8 (patch)
treec082d2794a11f20c2b22af190db01ab6954209a1
parent226a73bf1b08747d09869d8c95b3a2a0ec5eebed (diff)
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 <[email protected]> Signed-off-by: Vincent StehlĂ© <[email protected]> Cc: Ilias Apalodimas <[email protected]> Cc: Tom Rini <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]>
-rw-r--r--lib/efi_selftest/efi_selftest_block_device.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c
index b5f6f9353cd..847d93693ee 100644
--- a/lib/efi_selftest/efi_selftest_block_device.c
+++ b/lib/efi_selftest/efi_selftest_block_device.c
@@ -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;
}