Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 2 | /* |
| 3 | * efi_selftest_miniapp_exit |
| 4 | * |
| 5 | * Copyright (c) 2018 Heinrich Schuchardt |
| 6 | * |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 7 | * This EFI application is run by the StartImage selftest. |
| 8 | * It uses the Exit boot service to return. |
| 9 | */ |
| 10 | |
Heinrich Schuchardt | 1696dd0 | 2018-09-30 13:26:36 +0200 | [diff] [blame] | 11 | #include <efi_selftest.h> |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 12 | |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 13 | static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * check_loaded_image_protocol() - check image_base/image_size |
| 17 | * |
| 18 | * Try to open the loaded image protocol. Check that this function is located |
| 19 | * between image_base and image_base + image_size. |
| 20 | * |
| 21 | * @image_handle: handle of the loaded image |
| 22 | * @systable: system table |
Heinrich Schuchardt | fbe9021 | 2022-01-20 19:48:20 +0100 | [diff] [blame] | 23 | * Return: status code |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 24 | */ |
| 25 | static efi_status_t EFIAPI check_loaded_image_protocol |
| 26 | (efi_handle_t image_handle, struct efi_system_table *systable) |
| 27 | { |
| 28 | struct efi_simple_text_output_protocol *cout = systable->con_out; |
| 29 | struct efi_boot_services *boottime = systable->boottime; |
| 30 | struct efi_loaded_image *loaded_image_protocol; |
| 31 | efi_status_t ret; |
| 32 | |
| 33 | /* |
| 34 | * Open the loaded image protocol. |
| 35 | */ |
| 36 | ret = boottime->open_protocol |
| 37 | (image_handle, &loaded_image_protocol_guid, |
| 38 | (void **)&loaded_image_protocol, NULL, |
| 39 | NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); |
| 40 | if (ret != EFI_SUCCESS) { |
| 41 | cout->output_string(cout, |
Heinrich Schuchardt | 9b9da8e | 2024-01-24 21:04:32 +0100 | [diff] [blame] | 42 | u"Could not open loaded image protocol\n"); |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 43 | return ret; |
| 44 | } |
| 45 | if ((void *)check_loaded_image_protocol < |
| 46 | loaded_image_protocol->image_base || |
| 47 | (void *)check_loaded_image_protocol >= |
| 48 | loaded_image_protocol->image_base + |
| 49 | loaded_image_protocol->image_size) { |
| 50 | cout->output_string(cout, |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 51 | u"Incorrect image_base or image_size\n"); |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 52 | return EFI_NOT_FOUND; |
| 53 | } |
| 54 | return EFI_SUCCESS; |
| 55 | } |
| 56 | |
| 57 | /** |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 58 | * Entry point of the EFI application. |
| 59 | * |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 60 | * @handle: handle of the loaded image |
| 61 | * @systable: system table |
Heinrich Schuchardt | fbe9021 | 2022-01-20 19:48:20 +0100 | [diff] [blame] | 62 | * Return: status code |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 63 | */ |
| 64 | efi_status_t EFIAPI efi_main(efi_handle_t handle, |
| 65 | struct efi_system_table *systable) |
| 66 | { |
| 67 | struct efi_simple_text_output_protocol *con_out = systable->con_out; |
Heinrich Schuchardt | 1696dd0 | 2018-09-30 13:26:36 +0200 | [diff] [blame] | 68 | efi_status_t ret; |
| 69 | u16 text[] = EFI_ST_SUCCESS_STR; |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 70 | |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 71 | con_out->output_string(con_out, u"EFI application calling Exit\n"); |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 72 | |
Heinrich Schuchardt | 1696dd0 | 2018-09-30 13:26:36 +0200 | [diff] [blame] | 73 | if (check_loaded_image_protocol(handle, systable) != EFI_SUCCESS) { |
| 74 | con_out->output_string(con_out, |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 75 | u"Loaded image protocol missing\n"); |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 76 | ret = EFI_NOT_FOUND; |
Heinrich Schuchardt | 1696dd0 | 2018-09-30 13:26:36 +0200 | [diff] [blame] | 77 | goto out; |
| 78 | } |
Heinrich Schuchardt | f92074f | 2018-09-30 09:20:06 +0200 | [diff] [blame] | 79 | |
Heinrich Schuchardt | 1696dd0 | 2018-09-30 13:26:36 +0200 | [diff] [blame] | 80 | /* This return value is expected by the calling test */ |
| 81 | ret = EFI_UNSUPPORTED; |
| 82 | out: |
| 83 | systable->boottime->exit(handle, ret, sizeof(text), text); |
Heinrich Schuchardt | e3cde3a | 2018-01-19 19:01:05 +0100 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * This statement should not be reached. |
| 87 | * To enable testing use a different return value. |
| 88 | */ |
| 89 | return EFI_SUCCESS; |
| 90 | } |