2 * efi_selftest_start_image
4 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 * SPDX-License-Identifier: GPL-2.0+
8 * This test checks the StartImage boot service.
9 * The efi_selftest_miniapp_exit.efi application is loaded into memory
13 #include <efi_selftest.h>
14 /* Include containing the miniapp.efi application */
15 #include "efi_miniapp_file_image_exit.h"
17 /* Block size of compressed disk image */
18 #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
20 /* Binary logarithm of the block size */
21 #define LB_BLOCK_SIZE 9
23 static efi_handle_t image_handle;
24 static struct efi_boot_services *boottime;
26 /* One 8 byte block of the compressed disk image */
32 /* Compressed file image */
33 struct compressed_file_image {
38 static struct compressed_file_image img = EFI_ST_DISK_IMG;
40 /* Decompressed file image */
44 * Decompress the disk image.
46 * @image decompressed disk image
49 static efi_status_t decompress(u8 **image)
57 ret = boottime->allocate_pool(EFI_LOADER_DATA, img.length,
59 if (ret != EFI_SUCCESS) {
60 efi_st_error("Out of memory\n");
63 boottime->set_mem(buf, img.length, 0);
66 if (!img.lines[i].line)
68 addr = img.lines[i].addr;
69 len = COMPRESSED_DISK_IMAGE_BLOCK_SIZE;
70 if (addr + len > img.length)
71 len = img.length - addr;
72 boottime->copy_mem(buf + addr, img.lines[i].line, len);
81 * @handle: handle of the loaded image
82 * @systable: system table
83 * @return: EFI_ST_SUCCESS for success
85 static int setup(const efi_handle_t handle,
86 const struct efi_system_table *systable)
88 image_handle = handle;
89 boottime = systable->boottime;
91 /* Load the application image into memory */
94 return EFI_ST_SUCCESS;
98 * Tear down unit test.
100 * @return: EFI_ST_SUCCESS for success
102 static int teardown(void)
104 efi_status_t r = EFI_ST_SUCCESS;
107 r = efi_free_pool(image);
108 if (r != EFI_SUCCESS) {
109 efi_st_error("Failed to free image\n");
110 return EFI_ST_FAILURE;
119 * Load and start the application image.
121 * @return: EFI_ST_SUCCESS for success
123 static int execute(void)
128 ret = boottime->load_image(false, image_handle, NULL, image,
129 img.length, &handle);
130 if (ret != EFI_SUCCESS) {
131 efi_st_error("Failed to load image\n");
132 return EFI_ST_FAILURE;
134 ret = boottime->start_image(handle, NULL, NULL);
135 if (ret != EFI_UNSUPPORTED) {
136 efi_st_error("Wrong return value from application\n");
137 return EFI_ST_FAILURE;
140 return EFI_ST_SUCCESS;
143 EFI_UNIT_TEST(startimage_exit) = {
144 .name = "start image exit",
145 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
148 .teardown = teardown,