Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 2 | /* |
| 3 | * EFI efi_selftest |
| 4 | * |
| 5 | * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Heinrich Schuchardt | d5e8571 | 2020-08-22 09:14:56 +0200 | [diff] [blame] | 8 | #include <command.h> |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 9 | #include <efi_selftest.h> |
| 10 | #include <vsprintf.h> |
| 11 | |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 12 | /* Constants for test step bitmap */ |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 13 | #define EFI_ST_SETUP 1 |
| 14 | #define EFI_ST_EXECUTE 2 |
| 15 | #define EFI_ST_TEARDOWN 4 |
| 16 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 17 | static const struct efi_system_table *systable; |
| 18 | static const struct efi_boot_services *boottime; |
| 19 | static const struct efi_runtime_services *runtime; |
| 20 | static efi_handle_t handle; |
| 21 | static u16 reset_message[] = L"Selftest completed"; |
Heinrich Schuchardt | 7281933 | 2018-10-22 23:15:10 +0200 | [diff] [blame] | 22 | static int *setup_status; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Exit the boot services. |
| 26 | * |
| 27 | * The size of the memory map is determined. |
| 28 | * Pool memory is allocated to copy the memory map. |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 29 | * The memory map is copied and the map key is obtained. |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 30 | * The map key is used to exit the boot services. |
| 31 | */ |
| 32 | void efi_st_exit_boot_services(void) |
| 33 | { |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 34 | efi_uintn_t map_size = 0; |
| 35 | efi_uintn_t map_key; |
| 36 | efi_uintn_t desc_size; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 37 | u32 desc_version; |
| 38 | efi_status_t ret; |
| 39 | struct efi_mem_desc *memory_map; |
| 40 | |
Heinrich Schuchardt | 628dbd7 | 2020-11-12 21:26:28 +0100 | [diff] [blame] | 41 | /* Do not detach devices in ExitBootServices. We need the console. */ |
| 42 | efi_st_keep_devices = true; |
| 43 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 44 | ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size, |
| 45 | &desc_version); |
| 46 | if (ret != EFI_BUFFER_TOO_SMALL) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 47 | efi_st_error( |
| 48 | "GetMemoryMap did not return EFI_BUFFER_TOO_SMALL\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 49 | return; |
| 50 | } |
| 51 | /* Allocate extra space for newly allocated memory */ |
| 52 | map_size += sizeof(struct efi_mem_desc); |
| 53 | ret = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size, |
| 54 | (void **)&memory_map); |
| 55 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 56 | efi_st_error("AllocatePool did not return EFI_SUCCESS\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 57 | return; |
| 58 | } |
| 59 | ret = boottime->get_memory_map(&map_size, memory_map, &map_key, |
| 60 | &desc_size, &desc_version); |
| 61 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 62 | efi_st_error("GetMemoryMap did not return EFI_SUCCESS\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | ret = boottime->exit_boot_services(handle, map_key); |
| 66 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 67 | efi_st_error("ExitBootServices did not return EFI_SUCCESS\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 68 | return; |
| 69 | } |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 70 | efi_st_printc(EFI_WHITE, "\nBoot services terminated\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Set up a test. |
| 75 | * |
| 76 | * @test the test to be executed |
| 77 | * @failures counter that will be incremented if a failure occurs |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 78 | * @return EFI_ST_SUCCESS for success |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 79 | */ |
| 80 | static int setup(struct efi_unit_test *test, unsigned int *failures) |
| 81 | { |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 82 | int ret; |
| 83 | |
| 84 | if (!test->setup) |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 85 | return EFI_ST_SUCCESS; |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 86 | efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name); |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 87 | ret = test->setup(handle, systable); |
| 88 | if (ret != EFI_ST_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 89 | efi_st_error("Setting up '%s' failed\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 90 | ++*failures; |
| 91 | } else { |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 92 | efi_st_printc(EFI_LIGHTGREEN, |
| 93 | "Setting up '%s' succeeded\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 94 | } |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 95 | return ret; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Execute a test. |
| 100 | * |
| 101 | * @test the test to be executed |
| 102 | * @failures counter that will be incremented if a failure occurs |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 103 | * @return EFI_ST_SUCCESS for success |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 104 | */ |
| 105 | static int execute(struct efi_unit_test *test, unsigned int *failures) |
| 106 | { |
| 107 | int ret; |
| 108 | |
| 109 | if (!test->execute) |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 110 | return EFI_ST_SUCCESS; |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 111 | efi_st_printc(EFI_LIGHTBLUE, "\nExecuting '%s'\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 112 | ret = test->execute(); |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 113 | if (ret != EFI_ST_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 114 | efi_st_error("Executing '%s' failed\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 115 | ++*failures; |
| 116 | } else { |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 117 | efi_st_printc(EFI_LIGHTGREEN, |
| 118 | "Executing '%s' succeeded\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 119 | } |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Tear down a test. |
| 125 | * |
| 126 | * @test the test to be torn down |
| 127 | * @failures counter that will be incremented if a failure occurs |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 128 | * @return EFI_ST_SUCCESS for success |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 129 | */ |
| 130 | static int teardown(struct efi_unit_test *test, unsigned int *failures) |
| 131 | { |
| 132 | int ret; |
| 133 | |
| 134 | if (!test->teardown) |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 135 | return EFI_ST_SUCCESS; |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 136 | efi_st_printc(EFI_LIGHTBLUE, "\nTearing down '%s'\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 137 | ret = test->teardown(); |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 138 | if (ret != EFI_ST_SUCCESS) { |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 139 | efi_st_error("Tearing down '%s' failed\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 140 | ++*failures; |
| 141 | } else { |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 142 | efi_st_printc(EFI_LIGHTGREEN, |
| 143 | "Tearing down '%s' succeeded\n", test->name); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 144 | } |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | /* |
Heinrich Schuchardt | 496005d | 2020-09-30 21:52:09 +0200 | [diff] [blame] | 149 | * Check that a test requiring reset exists. |
| 150 | * |
| 151 | * @testname: name of the test |
| 152 | * @return: test, or NULL if not found |
| 153 | */ |
| 154 | static bool need_reset(const u16 *testname) |
| 155 | { |
| 156 | struct efi_unit_test *test; |
| 157 | |
| 158 | for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); |
| 159 | test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { |
| 160 | if (testname && efi_st_strcmp_16_8(testname, test->name)) |
| 161 | continue; |
| 162 | if (test->phase == EFI_SETUP_BEFORE_BOOTTIME_EXIT || |
Heinrich Schuchardt | c7c782a | 2021-03-24 17:48:01 +0100 | [diff] [blame] | 163 | test->phase == EFI_SETTING_VIRTUAL_ADDRESS_MAP) |
Heinrich Schuchardt | 496005d | 2020-09-30 21:52:09 +0200 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | /* |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 170 | * Check that a test exists. |
| 171 | * |
| 172 | * @testname: name of the test |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 173 | * @return: test, or NULL if not found |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 174 | */ |
| 175 | static struct efi_unit_test *find_test(const u16 *testname) |
| 176 | { |
| 177 | struct efi_unit_test *test; |
| 178 | |
| 179 | for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); |
| 180 | test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { |
| 181 | if (!efi_st_strcmp_16_8(testname, test->name)) |
| 182 | return test; |
| 183 | } |
| 184 | efi_st_printf("\nTest '%ps' not found\n", testname); |
| 185 | return NULL; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * List all available tests. |
| 190 | */ |
| 191 | static void list_all_tests(void) |
| 192 | { |
| 193 | struct efi_unit_test *test; |
| 194 | |
| 195 | /* List all tests */ |
| 196 | efi_st_printf("\nAvailable tests:\n"); |
| 197 | for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); |
| 198 | test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { |
| 199 | efi_st_printf("'%s'%s\n", test->name, |
| 200 | test->on_request ? " - on request" : ""); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 205 | * Execute test steps of one phase. |
| 206 | * |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 207 | * @testname name of a single selected test or NULL |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 208 | * @phase test phase |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 209 | * @steps steps to execute (mask with bits from EFI_ST_...) |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 210 | * failures returns EFI_ST_SUCCESS if all test steps succeeded |
| 211 | */ |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 212 | void efi_st_do_tests(const u16 *testname, unsigned int phase, |
| 213 | unsigned int steps, unsigned int *failures) |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 214 | { |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 215 | int i = 0; |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 216 | struct efi_unit_test *test; |
| 217 | |
| 218 | for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 219 | test < ll_entry_end(struct efi_unit_test, efi_unit_test); |
| 220 | ++test, ++i) { |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 221 | if (testname ? |
| 222 | efi_st_strcmp_16_8(testname, test->name) : test->on_request) |
| 223 | continue; |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 224 | if (test->phase != phase) |
| 225 | continue; |
| 226 | if (steps & EFI_ST_SETUP) |
Heinrich Schuchardt | 7281933 | 2018-10-22 23:15:10 +0200 | [diff] [blame] | 227 | setup_status[i] = setup(test, failures); |
| 228 | if (steps & EFI_ST_EXECUTE && setup_status[i] == EFI_ST_SUCCESS) |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 229 | execute(test, failures); |
| 230 | if (steps & EFI_ST_TEARDOWN) |
| 231 | teardown(test, failures); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 236 | * Execute selftest of the EFI API |
| 237 | * |
| 238 | * This is the main entry point of the EFI selftest application. |
| 239 | * |
| 240 | * All tests use a driver model and are run in three phases: |
| 241 | * setup, execute, teardown. |
| 242 | * |
| 243 | * A test may be setup and executed at boottime, |
| 244 | * it may be setup at boottime and executed at runtime, |
| 245 | * or it may be setup and executed at runtime. |
| 246 | * |
| 247 | * After executing all tests the system is reset. |
| 248 | * |
| 249 | * @image_handle: handle of the loaded EFI image |
| 250 | * @systab: EFI system table |
| 251 | */ |
| 252 | efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, |
| 253 | struct efi_system_table *systab) |
| 254 | { |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 255 | unsigned int failures = 0; |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 256 | const u16 *testname = NULL; |
| 257 | struct efi_loaded_image *loaded_image; |
| 258 | efi_status_t ret; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 259 | |
| 260 | systable = systab; |
| 261 | boottime = systable->boottime; |
| 262 | runtime = systable->runtime; |
| 263 | handle = image_handle; |
| 264 | con_out = systable->con_out; |
| 265 | con_in = systable->con_in; |
| 266 | |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 267 | ret = boottime->handle_protocol(image_handle, &efi_guid_loaded_image, |
| 268 | (void **)&loaded_image); |
| 269 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | bf7ea1d | 2017-11-26 14:05:19 +0100 | [diff] [blame] | 270 | efi_st_error("Cannot open loaded image protocol\n"); |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | if (loaded_image->load_options) |
| 275 | testname = (u16 *)loaded_image->load_options; |
| 276 | |
| 277 | if (testname) { |
| 278 | if (!efi_st_strcmp_16_8(testname, "list") || |
| 279 | !find_test(testname)) { |
| 280 | list_all_tests(); |
| 281 | /* |
| 282 | * TODO: |
| 283 | * Once the Exit boottime service is correctly |
| 284 | * implemented we should call |
| 285 | * boottime->exit(image_handle, EFI_SUCCESS, 0, NULL); |
| 286 | * here, cf. |
| 287 | * https://lists.denx.de/pipermail/u-boot/2017-October/308720.html |
| 288 | */ |
| 289 | return EFI_SUCCESS; |
| 290 | } |
| 291 | } |
| 292 | |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 293 | efi_st_printc(EFI_WHITE, "\nTesting EFI API implementation\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 294 | |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 295 | if (testname) |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 296 | efi_st_printc(EFI_WHITE, "\nSelected test: '%ps'\n", testname); |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 297 | else |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 298 | efi_st_printc(EFI_WHITE, "\nNumber of tests to execute: %u\n", |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 299 | ll_entry_count(struct efi_unit_test, |
| 300 | efi_unit_test)); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 301 | |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 302 | /* Allocate buffer for setup results */ |
| 303 | ret = boottime->allocate_pool(EFI_RUNTIME_SERVICES_DATA, sizeof(int) * |
| 304 | ll_entry_count(struct efi_unit_test, |
| 305 | efi_unit_test), |
Heinrich Schuchardt | 7281933 | 2018-10-22 23:15:10 +0200 | [diff] [blame] | 306 | (void **)&setup_status); |
Heinrich Schuchardt | 0e77ca9 | 2018-10-19 07:51:26 +0200 | [diff] [blame] | 307 | if (ret != EFI_SUCCESS) { |
| 308 | efi_st_error("Allocate pool failed\n"); |
| 309 | return ret; |
| 310 | } |
| 311 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 312 | /* Execute boottime tests */ |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 313 | efi_st_do_tests(testname, EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 314 | EFI_ST_SETUP | EFI_ST_EXECUTE | EFI_ST_TEARDOWN, |
| 315 | &failures); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 316 | |
Heinrich Schuchardt | 496005d | 2020-09-30 21:52:09 +0200 | [diff] [blame] | 317 | if (!need_reset(testname)) { |
| 318 | if (failures) |
| 319 | ret = EFI_PROTOCOL_ERROR; |
| 320 | |
| 321 | /* Give feedback */ |
| 322 | efi_st_printc(EFI_WHITE, "\nSummary: %u failures\n\n", |
| 323 | failures); |
| 324 | return ret; |
| 325 | } |
| 326 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 327 | /* Execute mixed tests */ |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 328 | efi_st_do_tests(testname, EFI_SETUP_BEFORE_BOOTTIME_EXIT, |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 329 | EFI_ST_SETUP, &failures); |
Heinrich Schuchardt | c7c782a | 2021-03-24 17:48:01 +0100 | [diff] [blame] | 330 | efi_st_do_tests(testname, EFI_SETTING_VIRTUAL_ADDRESS_MAP, |
| 331 | EFI_ST_SETUP, &failures); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 332 | |
| 333 | efi_st_exit_boot_services(); |
| 334 | |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 335 | efi_st_do_tests(testname, EFI_SETUP_BEFORE_BOOTTIME_EXIT, |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 336 | EFI_ST_EXECUTE | EFI_ST_TEARDOWN, &failures); |
Heinrich Schuchardt | c7c782a | 2021-03-24 17:48:01 +0100 | [diff] [blame] | 337 | /* Execute test setting the virtual address map */ |
| 338 | efi_st_do_tests(testname, EFI_SETTING_VIRTUAL_ADDRESS_MAP, |
| 339 | EFI_ST_EXECUTE | EFI_ST_TEARDOWN, |
Heinrich Schuchardt | 2eb1558 | 2017-10-18 18:13:12 +0200 | [diff] [blame] | 340 | &failures); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 341 | |
| 342 | /* Give feedback */ |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 343 | efi_st_printc(EFI_WHITE, "\nSummary: %u failures\n\n", failures); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 344 | |
| 345 | /* Reset system */ |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 346 | efi_st_printf("Preparing for reset. Press any key...\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 347 | efi_st_get_key(); |
Heinrich Schuchardt | d5e8571 | 2020-08-22 09:14:56 +0200 | [diff] [blame] | 348 | |
Heinrich Schuchardt | c450db5 | 2020-09-10 07:47:58 +0200 | [diff] [blame] | 349 | if (IS_ENABLED(CONFIG_EFI_HAVE_RUNTIME_RESET)) { |
Heinrich Schuchardt | d5e8571 | 2020-08-22 09:14:56 +0200 | [diff] [blame] | 350 | runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY, |
| 351 | sizeof(reset_message), reset_message); |
Heinrich Schuchardt | c450db5 | 2020-09-10 07:47:58 +0200 | [diff] [blame] | 352 | } else { |
| 353 | efi_restore_gd(); |
Heinrich Schuchardt | d5e8571 | 2020-08-22 09:14:56 +0200 | [diff] [blame] | 354 | do_reset(NULL, 0, 0, NULL); |
Heinrich Schuchardt | c450db5 | 2020-09-10 07:47:58 +0200 | [diff] [blame] | 355 | } |
Heinrich Schuchardt | d5e8571 | 2020-08-22 09:14:56 +0200 | [diff] [blame] | 356 | |
Heinrich Schuchardt | cbfdf81 | 2017-10-04 12:37:02 +0200 | [diff] [blame] | 357 | efi_st_printf("\n"); |
Simon Glass | 0b9680f | 2018-06-18 08:08:21 -0600 | [diff] [blame] | 358 | efi_st_error("Reset failed\n"); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 359 | |
| 360 | return EFI_UNSUPPORTED; |
| 361 | } |