]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_selftest: test block io revision and pointers
authorVincent Stehlé <vincent.stehle@arm.com>
Fri, 26 Jun 2026 14:47:59 +0000 (16:47 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 15 Jul 2026 22:40:42 +0000 (00:40 +0200)
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>
lib/efi_selftest/efi_selftest_block_device.c

index b5f6f9353cdc589070fad7348b076ff0fe856bd7..847d93693eeca98177a45f057ef40e669042780f 100644 (file)
@@ -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;
 }