1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_start_image
5 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * This test checks the StartImage boot service.
8 * The efi_selftest_miniapp_exit.efi application is loaded into memory
12 #include <efi_selftest.h>
13 /* Include containing the miniapp.efi application */
14 #include "efi_miniapp_file_image_exit.h"
16 /* Block size of compressed disk image */
17 #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
19 /* Binary logarithm of the block size */
20 #define LB_BLOCK_SIZE 9
22 static efi_handle_t image_handle
;
23 static struct efi_boot_services
*boottime
;
25 /* One 8 byte block of the compressed disk image */
31 /* Compressed file image */
32 struct compressed_file_image
{
37 static struct compressed_file_image img
= EFI_ST_DISK_IMG
;
39 /* Decompressed file image */
43 * Decompress the disk image.
45 * @image decompressed disk image
48 static efi_status_t
decompress(u8
**image
)
56 ret
= boottime
->allocate_pool(EFI_LOADER_DATA
, img
.length
,
58 if (ret
!= EFI_SUCCESS
) {
59 efi_st_error("Out of memory\n");
62 boottime
->set_mem(buf
, img
.length
, 0);
65 if (!img
.lines
[i
].line
)
67 addr
= img
.lines
[i
].addr
;
68 len
= COMPRESSED_DISK_IMAGE_BLOCK_SIZE
;
69 if (addr
+ len
> img
.length
)
70 len
= img
.length
- addr
;
71 boottime
->copy_mem(buf
+ addr
, img
.lines
[i
].line
, len
);
80 * @handle: handle of the loaded image
81 * @systable: system table
82 * @return: EFI_ST_SUCCESS for success
84 static int setup(const efi_handle_t handle
,
85 const struct efi_system_table
*systable
)
87 image_handle
= handle
;
88 boottime
= systable
->boottime
;
90 /* Load the application image into memory */
93 return EFI_ST_SUCCESS
;
97 * Tear down unit test.
99 * @return: EFI_ST_SUCCESS for success
101 static int teardown(void)
103 efi_status_t r
= EFI_ST_SUCCESS
;
106 r
= boottime
->free_pool(image
);
107 if (r
!= EFI_SUCCESS
) {
108 efi_st_error("Failed to free image\n");
109 return EFI_ST_FAILURE
;
118 * Load and start the application image.
120 * @return: EFI_ST_SUCCESS for success
122 static int execute(void)
126 efi_uintn_t exit_data_size
= 0;
127 u16
*exit_data
= NULL
;
128 u16 expected_text
[] = EFI_ST_SUCCESS_STR
;
130 ret
= boottime
->load_image(false, image_handle
, NULL
, image
,
131 img
.length
, &handle
);
132 if (ret
!= EFI_SUCCESS
) {
133 efi_st_error("Failed to load image\n");
134 return EFI_ST_FAILURE
;
136 ret
= boottime
->start_image(handle
, &exit_data_size
, &exit_data
);
137 if (ret
!= EFI_UNSUPPORTED
) {
138 efi_st_error("Wrong return value from application\n");
139 return EFI_ST_FAILURE
;
141 if (!exit_data
|| exit_data_size
!= sizeof(expected_text
) ||
142 efi_st_memcmp(exit_data
, expected_text
, sizeof(expected_text
))) {
143 efi_st_error("Incorrect exit data\n");
144 return EFI_ST_FAILURE
;
146 ret
= boottime
->free_pool(exit_data
);
147 if (ret
!= EFI_SUCCESS
) {
148 efi_st_error("Failed to free exit data\n");
149 return EFI_ST_FAILURE
;
152 return EFI_ST_SUCCESS
;
155 EFI_UNIT_TEST(startimage_exit
) = {
156 .name
= "start image exit",
157 .phase
= EFI_EXECUTE_BEFORE_BOOTTIME_EXIT
,
160 .teardown
= teardown
,