Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -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 application loader |
| 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 | |
| 8 | #ifndef _EFI_SELFTEST_H |
| 9 | #define _EFI_SELFTEST_H |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <efi.h> |
| 13 | #include <efi_api.h> |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 14 | #include <efi_loader.h> |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 15 | #include <linker_lists.h> |
| 16 | |
Heinrich Schuchardt | 1afe5f7 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 17 | #define EFI_ST_SUCCESS 0 |
| 18 | #define EFI_ST_FAILURE 1 |
| 19 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 20 | /* |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 21 | * Prints a message. |
| 22 | */ |
| 23 | #define efi_st_printf(...) \ |
| 24 | (efi_st_printc(-1, __VA_ARGS__)) |
| 25 | |
| 26 | /* |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 27 | * Prints an error message. |
| 28 | * |
| 29 | * @... format string followed by fields to print |
| 30 | */ |
| 31 | #define efi_st_error(...) \ |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 32 | (efi_st_printc(EFI_LIGHTRED, "%s(%u):\nERROR: ", __FILE__, __LINE__), \ |
| 33 | efi_st_printc(EFI_LIGHTRED, __VA_ARGS__)) |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 34 | |
| 35 | /* |
Heinrich Schuchardt | c53591c | 2017-11-06 21:17:43 +0100 | [diff] [blame] | 36 | * Prints a TODO message. |
| 37 | * |
| 38 | * @... format string followed by fields to print |
| 39 | */ |
| 40 | #define efi_st_todo(...) \ |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 41 | (efi_st_printc(EFI_YELLOW, "%s(%u):\nTODO: ", __FILE__, __LINE__), \ |
| 42 | efi_st_printc(EFI_YELLOW, __VA_ARGS__)) \ |
Heinrich Schuchardt | c53591c | 2017-11-06 21:17:43 +0100 | [diff] [blame] | 43 | |
| 44 | /* |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 45 | * A test may be setup and executed at boottime, |
| 46 | * it may be setup at boottime and executed at runtime, |
| 47 | * or it may be setup and executed at runtime. |
| 48 | */ |
| 49 | enum efi_test_phase { |
| 50 | EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1, |
| 51 | EFI_SETUP_BEFORE_BOOTTIME_EXIT, |
| 52 | EFI_SETUP_AFTER_BOOTTIME_EXIT, |
| 53 | }; |
| 54 | |
| 55 | extern struct efi_simple_text_output_protocol *con_out; |
Heinrich Schuchardt | 3dabffd | 2018-09-08 10:20:10 +0200 | [diff] [blame] | 56 | extern struct efi_simple_text_input_protocol *con_in; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Exit the boot services. |
| 60 | * |
| 61 | * The size of the memory map is determined. |
| 62 | * Pool memory is allocated to copy the memory map. |
| 63 | * The memory amp is copied and the map key is obtained. |
| 64 | * The map key is used to exit the boot services. |
| 65 | */ |
| 66 | void efi_st_exit_boot_services(void); |
| 67 | |
| 68 | /* |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 69 | * Print a colored message |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 70 | * |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 71 | * @color color, see constants in efi_api.h, use -1 for no color |
| 72 | * @fmt printf format |
| 73 | * @... arguments to be printed |
| 74 | * on return position of terminating zero word |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 75 | */ |
Heinrich Schuchardt | 9137df8 | 2018-01-11 08:15:54 +0100 | [diff] [blame] | 76 | void efi_st_printc(int color, const char *fmt, ...) |
| 77 | __attribute__ ((format (__printf__, 2, 3))); |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 78 | |
Heinrich Schuchardt | 9cda2ef | 2018-09-11 22:38:04 +0200 | [diff] [blame] | 79 | /** |
| 80 | * efi_st_translate_char() - translate a unicode character to a string |
| 81 | * |
| 82 | * @code: unicode character |
| 83 | * Return: string |
| 84 | */ |
| 85 | u16 *efi_st_translate_char(u16 code); |
| 86 | |
| 87 | /** |
| 88 | * efi_st_translate_code() - translate a scan code to a human readable string |
| 89 | * |
| 90 | * @code: unicode character |
| 91 | * Return: string |
| 92 | */ |
| 93 | u16 *efi_st_translate_code(u16 code); |
| 94 | |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 95 | /* |
Heinrich Schuchardt | 2a6daf7 | 2017-10-05 16:36:07 +0200 | [diff] [blame] | 96 | * Compare memory. |
| 97 | * We cannot use lib/string.c due to different CFLAGS values. |
| 98 | * |
| 99 | * @buf1: first buffer |
| 100 | * @buf2: second buffer |
| 101 | * @length: number of bytes to compare |
| 102 | * @return: 0 if both buffers contain the same bytes |
| 103 | */ |
| 104 | int efi_st_memcmp(const void *buf1, const void *buf2, size_t length); |
| 105 | |
| 106 | /* |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 107 | * Compare an u16 string to a char string. |
| 108 | * |
| 109 | * @buf1: u16 string |
| 110 | * @buf2: char string |
| 111 | * @return: 0 if both buffers contain the same bytes |
| 112 | */ |
| 113 | int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2); |
| 114 | |
| 115 | /* |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 116 | * Reads an Unicode character from the input device. |
| 117 | * |
| 118 | * @return: Unicode character |
| 119 | */ |
| 120 | u16 efi_st_get_key(void); |
| 121 | |
| 122 | /** |
| 123 | * struct efi_unit_test - EFI unit test |
| 124 | * |
| 125 | * An efi_unit_test provides a interface to an EFI unit test. |
| 126 | * |
| 127 | * @name: name of unit test |
| 128 | * @phase: specifies when setup and execute are executed |
| 129 | * @setup: set up the unit test |
| 130 | * @teardown: tear down the unit test |
| 131 | * @execute: execute the unit test |
Heinrich Schuchardt | a9d2260 | 2018-04-16 07:59:03 +0200 | [diff] [blame] | 132 | * @setup_ok: setup was successful (set at runtime) |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 133 | * @on_request: test is only executed on request |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 134 | */ |
| 135 | struct efi_unit_test { |
| 136 | const char *name; |
| 137 | const enum efi_test_phase phase; |
| 138 | int (*setup)(const efi_handle_t handle, |
| 139 | const struct efi_system_table *systable); |
| 140 | int (*execute)(void); |
| 141 | int (*teardown)(void); |
Heinrich Schuchardt | a9d2260 | 2018-04-16 07:59:03 +0200 | [diff] [blame] | 142 | int setup_ok; |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 143 | bool on_request; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | /* Declare a new EFI unit test */ |
| 147 | #define EFI_UNIT_TEST(__name) \ |
| 148 | ll_entry_declare(struct efi_unit_test, __name, efi_unit_test) |
| 149 | |
| 150 | #endif /* _EFI_SELFTEST_H */ |