blob: 0909a5ca748b8bdec9bbda30c310b03f177c6c49 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +01002/*
3 * efi_selftest_miniapp_exit
4 *
5 * Copyright (c) 2018 Heinrich Schuchardt
6 *
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +01007 * This EFI application is run by the StartImage selftest.
8 * It uses the Exit boot service to return.
9 */
10
Heinrich Schuchardt1696dd02018-09-30 13:26:36 +020011#include <efi_selftest.h>
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010012
Heinrich Schuchardt788ad412019-04-20 07:39:11 +020013static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020014
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 Schuchardtfbe90212022-01-20 19:48:20 +010023 * Return: status code
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020024 */
25static 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 Schuchardt9b9da8e2024-01-24 21:04:32 +010042 u"Could not open loaded image protocol\n");
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020043 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 Glass90975372022-01-23 12:55:12 -070051 u"Incorrect image_base or image_size\n");
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020052 return EFI_NOT_FOUND;
53 }
54 return EFI_SUCCESS;
55}
56
57/**
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010058 * Entry point of the EFI application.
59 *
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020060 * @handle: handle of the loaded image
61 * @systable: system table
Heinrich Schuchardtfbe90212022-01-20 19:48:20 +010062 * Return: status code
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010063 */
64efi_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 Schuchardt1696dd02018-09-30 13:26:36 +020068 efi_status_t ret;
69 u16 text[] = EFI_ST_SUCCESS_STR;
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010070
Simon Glass90975372022-01-23 12:55:12 -070071 con_out->output_string(con_out, u"EFI application calling Exit\n");
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010072
Heinrich Schuchardt1696dd02018-09-30 13:26:36 +020073 if (check_loaded_image_protocol(handle, systable) != EFI_SUCCESS) {
74 con_out->output_string(con_out,
Simon Glass90975372022-01-23 12:55:12 -070075 u"Loaded image protocol missing\n");
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020076 ret = EFI_NOT_FOUND;
Heinrich Schuchardt1696dd02018-09-30 13:26:36 +020077 goto out;
78 }
Heinrich Schuchardtf92074f2018-09-30 09:20:06 +020079
Heinrich Schuchardt1696dd02018-09-30 13:26:36 +020080 /* This return value is expected by the calling test */
81 ret = EFI_UNSUPPORTED;
82out:
83 systable->boottime->exit(handle, ret, sizeof(text), text);
Heinrich Schuchardte3cde3a2018-01-19 19:01:05 +010084
85 /*
86 * This statement should not be reached.
87 * To enable testing use a different return value.
88 */
89 return EFI_SUCCESS;
90}