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