efi: fix block io revision and test
cover efi: fix block io revision and test
Make sure we set the Revision field of our EFI_BLOCK_IO_PROTOCOL structures to a valid value and add a unit test to verify that.
This can be tested on the sandbox with the following command:
./u-boot -T -c 'setenv efi_selftest block device; bootefi selftest'
---
Vincent Stehlé (2):
lib/efi_loader: fix block io revision
lib/efi_selftest: test block io revision
lib/efi_loader/efi_disk.c | 1 + lib/efi_selftest/efi_selftest_block_device.c | 50 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
---
base-commit: 1a8b7ad50aed5f5f0a4ccbfd455233919c097293
change-id: 20260608-rev-772dedbb2fda
Best regards,
Signature · 1 line
Vincent.
PATCH 1/2 lib/efi_loader: fix block io revision
The Revision field of the EFI_BLOCK_IO_PROTOCOL structure must be set to one of the two valid values [1], but this is not initialized in the efi_loader; fix it.
--- lib/efi_loader/efi_disk.c | 1 + 1 file changed, 1 insertion(+)
lib/efi_loader/efi_disk.c +1 -0
@@ -305,6 +305,7 @@ static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this) }static const struct efi_block_io block_io_disk_template = { + .revision =EFI_BLOCK_IO_PROTOCOL_REVISION3 , .reset = &efi_disk_reset, .read_blocks = &efi_disk_read_blocks, .write_blocks = &efi_disk_write_blocks,
Signature · 1 line
2.53.0
Re: [PATCH 1/2] lib/efi_loader: fix block io revision
Quoted 9 lines · Vincent Stehlé
The Revision field of the
EFI_BLOCK_IO_PROTOCOLstructure must be set to one of the two valid values [1], but this is not initialized in theefi_loader; fix it.Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Tom Rini <[email protected]>
Quoted 17 lines
--- lib/efi_loader/efi_disk.c | 1 + 1 file changed, 1 insertion(+)lib/efi_loader/efi_disk.c +1
-0@@ -305,6 +305,7 @@ static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this) }static const struct efi_block_io block_io_disk_template = { + .revision =EFI_BLOCK_IO_PROTOCOL_REVISION3 , .reset = &efi_disk_reset, .read_blocks = &efi_disk_read_blocks, .write_blocks = &efi_disk_write_blocks,
PATCH 2/2 lib/efi_selftest: test block io revision
In reply to Vincent StehléEnhance the unit test to verify all Revision fields 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'
--- lib/efi_selftest/efi_selftest_block_device.c | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +50 -0
@@ -170,6 +170,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,
@@ -603,6 +604,55 @@ 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); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to locate block io handles\n" ); +return EFI_ST_FAILURE ; + } + +/* +* Verify all handles with block io. +* If an error is encountered, the loop exits early instead of +* returning, to free the handles buffer. +*/ +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); +break ; + } + +/* 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 %d\n" , + (unsigned int )rev); +break ; + } + } + +/* Free handles buffer. */ + ret = boottime->free_pool (handles); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to free block io handles\n" ); +return EFI_ST_FAILURE ; + } + +/* If we exited the loop on block io handles early this is a failure. */ +if (i != no_handles) +return EFI_ST_FAILURE ; +return EFI_ST_SUCCESS ; }
Signature · 1 line
2.53.0
Re: [PATCH 2/2] lib/efi_selftest: test block io revision
Quoted 32 lines · Vincent Stehlé
Enhance the unit test to verify all Revision fields of all the
EFI_BLOCK_IO_PROTOCOLstructures.
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_selftestblock device; bootefi selftest'Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Tom Rini <[email protected]>--- lib/efi_selftest/efi_selftest_block_device.c | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)lib/efi_selftest/efi_selftest_block_device.c +1
-0@@ -170,6 +170,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,@@ -603,6 +604,55 @@ static int execute(void)return EFI_ST_FAILURE ;
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 614
Quoted 10 lines
lib/efi_selftest/efi_selftest_block_device.c +8
-0} +/* Get all handles with block io. */ + ret = boottime->locate_handle_buffer (BY_PROTOCOL , + &block_io_protocol_guid,NULL , + &no_handles, &handles); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to locate block io handles\n" ); +return EFI_ST_FAILURE ; + }
Thank you for providing this test.
The test should pass when invoking U-Boot without any block device.
EFI_NOT_FOUND should not be reported as failure instead you should leave with EFI_ST_SUCCESS.
Quoted 15 lines
lib/efi_selftest/efi_selftest_block_device.c +15
-0+ +/* +* Verify all handles with block io. +* If an error is encountered, the loop exits early instead of +* returning, to free the handles buffer. +*/ +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 ) {
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 639
Quoted 10 lines
lib/efi_selftest/efi_selftest_block_device.c +10
-0+efi_st_error ("Failed to open block io protocol %d\n" , + (unsigned int )i); +break ; + } + +/* 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 %d\n",
The field is unsigned. So we need %u here.
Best regards
Heinrich
Quoted 20 lines
lib/efi_selftest/efi_selftest_block_device.c +16
-0+ (unsigned int)rev); +break ; + } + } + +/* Free handles buffer. */ + ret = boottime->free_pool (handles); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to free block io handles\n" ); +return EFI_ST_FAILURE ; + } + +/* If we exited the loop on block io handles early this is a failure. */ +if (i != no_handles) +return EFI_ST_FAILURE ; +return EFI_ST_SUCCESS ; }
Re: [PATCH 2/2] lib/efi_selftest: test block io revision
Hi Heinrich,
Thank you for your review.
I agree with your two remarks and I will send a v2.
Best regards,
Vincent.
PATCH v2 1/1 lib/efi_selftest: test block io revision
In reply to Vincent StehléEnhance the unit test to verify all Revision fields 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'
---
Changes for v2:
- Deal gracefully with no block io protocol found.
- Print revision with %u in case of error as it is unsigned.
--- lib/efi_selftest/efi_selftest_block_device.c | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +56 -0
@@ -170,6 +170,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,
@@ -603,6 +604,61 @@ 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 : +case EFI_NOT_FOUND :/* no_handles == 0, handles == NULL */ +break ; +default : +efi_st_error ("Locate handle buffer failed\n" ); +return EFI_ST_FAILURE ; + } + +/* +* Verify all handles with block io. +* If an error is encountered, the loop exits early instead of +* returning, to free the handles buffer. +*/ +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); +break ; + } + +/* 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); +break ; + } + } + +/* Free handles buffer. */ +if (handles) { + ret = boottime->free_pool (handles); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to free block io handles\n" ); +return EFI_ST_FAILURE ; + } + } + +/* If we exited the loop on block io handles early this is a failure. */ +if (i != no_handles) +return EFI_ST_FAILURE ; +return EFI_ST_SUCCESS ; }
---
base-commit: fcda974e36033ad5331a9b4a4a551af4e141ad7d
change-id: 20260608-rev-772dedbb2fda
Best regards,
Signature · 1 line
Vincent.
Re: [PATCH v2] lib/efi_selftest: test block io revision
Quoted 35 lines · Vincent Stehlé
Enhance the unit test to verify all Revision fields of all the
EFI_BLOCK_IO_PROTOCOLstructures.
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_selftestblock device; bootefi selftest'Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Tom Rini <[email protected]>---
Changes for v2:
- Deal gracefully with no block io protocol found.
- Print revision with %u in case of error as it is unsigned.--- lib/efi_selftest/efi_selftest_block_device.c | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)lib/efi_selftest/efi_selftest_block_device.c +1
-0@@ -170,6 +170,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,
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 612
Quoted 9 lines
lib/efi_selftest/efi_selftest_block_device.c +6
-0@@ -603,6 +604,61 @@ 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 EFI_SUCCESS and no_handles = 0 or handles = NULL, we have a bug.
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 614
Quoted 2 lines
lib/efi_selftest/efi_selftest_block_device.c +2
-0+case EFI_NOT_FOUND :/* no_handles == 0, handles == NULL */ +break ;
Only for EFI_SUCCESS updating the two variables is mandated in the UEFI specification. Don't expect no_handles == 0 or handles = NULL here. (I know EDK II and U-Boot currently do it. But here we are testing.)
In my v1 review I misguided you.
EFI_NOT_FOUND is a legal value but needs special treatment here:
In setup() we installed a block IO protocol. The protocol is not uninstalled before teardown(). Execute() is only called if setup() succeeded.
If we can't find any block IO protocol here, then something is badly broken and we should error out with a specific error message, e.g.
"No block IO protocol found though one installed in setup\n"
Quoted 21 lines
lib/efi_selftest/efi_selftest_block_device.c +21
-0+default : +efi_st_error ("Locate handle buffer failed\n" ); +return EFI_ST_FAILURE ; + } + +/* +* Verify all handles with block io. +* If an error is encountered, the loop exits early instead of +* returning, to free the handles buffer. +*/ +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);
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 645
Quoted 10 lines
lib/efi_selftest/efi_selftest_block_device.c +10
-0+break ; + } + +/* 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); +break ;
Should we check that all function pointers are non-NULL, too?
Best regards
Heinrich
Quoted 25 lines
lib/efi_selftest/efi_selftest_block_device.c +16
-1+ } + } + +/* Free handles buffer. */ +if (handles) { + ret = boottime->free_pool (handles); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("Failed to free block io handles\n" ); +return EFI_ST_FAILURE ; + } + } + +/* If we exited the loop on block io handles early this is a failure. */ +if (i != no_handles) +return EFI_ST_FAILURE ; +return EFI_ST_SUCCESS ; } ---base-commit:
fcda974e36033ad5331a9b4a4a551af4e141ad7d
change-id: 20260608-rev-772dedbb2fdaBest regards,
Re: [PATCH v2] lib/efi_selftest: test block io revision
Hi Heinrich,
Thank you for your review; I will send a v3 to address all your feedbacks.
Best regards,
Vincent.
v3 cover efi_selftest: block io protocol verifications
In reply to Vincent StehléThe first patch of this series makes sure in the block device selftest to free a remaining handles buffer during teardown().
This allows to simplify error handling in the second patch, without fear of leaking memory.
The second patch's main intent is to test the revision field of all the block io protocol structures.
This is the test corresponding to the fix in commit 62d7a49c4db6 ("lib/efi_loader: fix block io revision").
While we are at it, let's verify the protocol's pointers as well (as suggested by Heinrich).
---
Changes for v2:
- Deal gracefully with no block io protocol found.
- Print revision with %u in case of error as it is unsigned.
---
Changes for v3:
- Introduce a preliminary patch to make handles pointer global and free it also in teardown(), to simplify error handling.
- Verify handles number and pointer on the normal path.
- Treat block io protocol not found as an error; we installed one during setup() therefore we expect at least one.
- Simplify error handling and return in case of error in the loop rather than breaking.
- Verify all block io pointers as well.
- Remove leading `lib/' from commit title.
---
Vincent Stehlé (2):
efi_selftest: free handles on teardown()
efi_selftest: test block io revision and pointers
lib/efi_selftest/efi_selftest_block_device.c | 77 +++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)
---
base-commit: 6902fb4c17faa375003124c451c2550deab5463d
change-id: 20260608-rev-772dedbb2fda
Best regards,
Signature · 1 line
Vincent.
PATCH v3 1/2 efi_selftest: free handles on teardown()
In the block device selftest, make the handles pointer global and free it also in teardown(), to simplify error handling.
We also need to nullify the pointer after freeing it on the normal path, to avoid freeing it a second time during teardown().
--- lib/efi_selftest/efi_selftest_block_device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
lib/efi_selftest/efi_selftest_block_device.c +13 -1
@@ -58,6 +58,9 @@ static const struct compressed_disk_image img = EFI_ST_DISK_IMG;/* Decompressed disk image */ static u8 *image; +/* Handles buffer */ +static efi_handle_t *handles; +/* * Reset service of the block IO protocol. *
@@ -276,6 +279,15 @@ static int teardown(void)return EFI_ST_FAILURE ; } } + +if (handles) { + r = boottime->free_pool (handles); +if (r !=EFI_SUCCESS ) { +efi_st_error ("Failed to free handles\n" ); +return EFI_ST_FAILURE ; + } + } +return r; }
@@ -303,7 +315,6 @@ static int execute(void) {efi_status_t ret;efi_uintn_t no_handles, i, len; -efi_handle_t *handles;efi_handle_t handle_partition =NULL ;struct efi_device_path *dp_partition;struct efi_block_io *block_io_protocol;
@@ -372,6 +383,7 @@ static int execute(void)break ; } ret = boottime->free_pool (handles); + handles =NULL ;/* Avoid double free on teardown(). */ if (ret !=EFI_SUCCESS ) {efi_st_error ("Failed to free pool memory\n" );return EFI_ST_FAILURE ;
Signature · 1 line
2.53.0
Re: [PATCH v3 1/2] efi_selftest: free handles on teardown()
Quoted 50 lines · Vincent Stehlé
In the block device selftest, make the handles pointer global and free it also in
teardown(), to simplify error handling.We also need to nullify the pointer after freeing it on the normal path, to avoid freeing it a second time during
teardown().Signed-off-by Vincent Stehlé <[email protected]>--- lib/efi_selftest/efi_selftest_block_device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)lib/efi_selftest/efi_selftest_block_device.c +12
-1@@ -58,6 +58,9 @@ static const struct compressed_disk_image img = EFI_ST_DISK_IMG;/* Decompressed disk image */ static u8 *image; +/* Handles buffer */ +static efi_handle_t *handles; +/* * Reset service of the block IO protocol. * @@ -276,6 +279,15 @@ static int teardown(void)return EFI_ST_FAILURE ; } } + +if (handles) { + r = boottime->free_pool (handles); +if (r !=EFI_SUCCESS ) { +efi_st_error ("Failed to free handles\n" ); +return EFI_ST_FAILURE ; + } + } +return r; }@@ -303,7 +315,6 @@ static int execute(void) {efi_status_t ret;efi_uintn_t no_handles, i, len; -efi_handle_t *handles;efi_handle_t handle_partition =NULL ;struct efi_device_path *dp_partition;struct efi_block_io *block_io_protocol;
lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 386
Quoted 4 lines
lib/efi_selftest/efi_selftest_block_device.c +1
-0@@ -372,6 +383,7 @@ static int execute(void)break ; } ret = boottime->free_pool (handles); + handles =NULL ;/* Avoid double free on teardown(). */
Thank you for fixing the memory leak.
handles is a static variable. Why do you explicitly set it to NULL?
Best regards
Heinrich
Quoted 4 lines
lib/efi_selftest/efi_selftest_block_device.c +0
-0if (ret !=EFI_SUCCESS ) {efi_st_error ("Failed to free pool memory\n" );return EFI_ST_FAILURE ;
Heinrich Schuchardt
Reviewed-byRe: [PATCH v3 1/2] efi_selftest: free handles on teardown()
Quoted 57 lines · Heinrich Schuchardt
Quoted 49 lines · Vincent Stehlé
In the block device selftest, make the handles pointer global and free it also in
teardown(), to simplify error handling.We also need to nullify the pointer after freeing it on the normal path, to avoid freeing it a second time during
teardown().Signed-off-by Vincent Stehlé <[email protected]>---
lib/efi_selftest/efi_selftest_block_device.c| 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)lib/efi_selftest/efi_selftest_block_device.c +12
-1@@ -58,6 +58,9 @@ static const struct compressed_disk_image img =EFI_ST_DISK_IMG ; /* Decompressed disk image */ static u8 *image; +/* Handles buffer */ +static efi_handle_t *handles; + /** Reset service of the block IO protocol. * @@ -276,6 +279,15 @@ static int teardown(void) return EFI_ST_FAILURE; } } + + if (handles) { + r = boottime->free_pool(handles); + if (r != EFI_SUCCESS) { + efi_st_error("Failed to free handles\n"); + return EFI_ST_FAILURE; + } + } + return r; }@@ -303,7 +315,6 @@ static int execute(void) { efi_status_t ret; efi_uintn_t no_handles, i, len; - efi_handle_t *handles; efi_handle_t handle_partition = NULL; struct efi_device_path *dp_partition; struct efi_block_io *block_io_protocol;lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 386
Quoted 4 lines
lib/efi_selftest/efi_selftest_block_device.c +1
-0@@ -372,6 +383,7 @@ static int execute(void) break; } ret = boottime->free_pool(handles); + handles = NULL; /* Avoid double free on teardown(). */Thank you for fixing the memory leak.
Quoted 5 lines
handles is a static variable. Why do you explicitly set it to NULL?
Best regards
Heinrich
Sorry I misread the patch.
Quoted 6 lines
Quoted 5 lines
lib/efi_selftest/efi_selftest_block_device.c +0
-0if (ret != EFI_SUCCESS) { efi_st_error("Failed to free pool memory\n"); return EFI_ST_FAILURE;
PATCH v3 2/2 efi_selftest: test block io revision and pointers
In reply to Vincent Stehlé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'
--- lib/efi_selftest/efi_selftest_block_device.c | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +63 -0
@@ -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 ; }
Signature · 1 line
2.53.0