[PATCH v3 2/2] efi_selftest: test block io revision and pointers

Vincent Stehlé vincent.stehle at arm.com
Fri Jun 26 16:47:59 CEST 2026


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 at gmx.de>
Signed-off-by: Vincent Stehlé <vincent.stehle at arm.com>
Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
Cc: Tom Rini <trini at konsulko.com>
---
 lib/efi_selftest/efi_selftest_block_device.c | 63 ++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

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;
 }
 

-- 
2.53.0



More information about the U-Boot mailing list