blob: 986924b881dd904498e182210386523a4a880985 [file] [log] [blame]
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * efi_selftest_variables_runtime
4 *
5 * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
7 * This unit test checks the runtime services for variables after
8 * ExitBootServices():
9 * GetVariable, GetNextVariableName, SetVariable, QueryVariableInfo.
10 */
11
12#include <efi_selftest.h>
13
14#define EFI_ST_MAX_DATA_SIZE 16
15#define EFI_ST_MAX_VARNAME_SIZE 40
16
17static struct efi_boot_services *boottime;
18static struct efi_runtime_services *runtime;
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020019static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020020
21/*
22 * Setup unit test.
23 *
24 * @handle handle of the loaded image
25 * @systable system table
26 */
27static int setup(const efi_handle_t img_handle,
28 const struct efi_system_table *systable)
29{
30 boottime = systable->boottime;
31 runtime = systable->runtime;
32
33 return EFI_ST_SUCCESS;
34}
35
36/**
37 * execute() - execute unit test
38 *
39 * As runtime support is not implmented expect EFI_UNSUPPORTED to be returned.
40 */
41static int execute(void)
42{
43 efi_status_t ret;
44 efi_uintn_t len;
45 u32 attr;
46 u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c,
47 0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,};
48 u8 data[EFI_ST_MAX_DATA_SIZE];
49 u16 varname[EFI_ST_MAX_VARNAME_SIZE];
50 efi_guid_t guid;
51 u64 max_storage, rem_storage, max_size;
52
53 ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
54 &max_storage, &rem_storage,
55 &max_size);
56 if (ret != EFI_UNSUPPORTED) {
57 efi_st_error("QueryVariableInfo failed\n");
58 return EFI_ST_FAILURE;
59 }
60
Simon Glass90975372022-01-23 12:55:12 -070061 ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020062 EFI_VARIABLE_BOOTSERVICE_ACCESS |
63 EFI_VARIABLE_RUNTIME_ACCESS,
64 3, v + 4);
Ilias Apalodimas86ba8692024-04-18 15:54:50 +030065 if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) {
66 /* At runtime only non-volatile variables may be set. */
67 if (ret != EFI_INVALID_PARAMETER) {
68 efi_st_error("SetVariable failed\n");
69 return EFI_ST_FAILURE;
70 }
71 } else {
72 if (ret != EFI_UNSUPPORTED) {
73 efi_st_error("SetVariable failed\n");
74 return EFI_ST_FAILURE;
75 }
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020076 }
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020077 len = EFI_ST_MAX_DATA_SIZE;
Simon Glass90975372022-01-23 12:55:12 -070078 ret = runtime->get_variable(u"PlatformLangCodes", &guid_vendor0,
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020079 &attr, &len, data);
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020080 if (ret != EFI_SUCCESS) {
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020081 efi_st_error("GetVariable failed\n");
82 return EFI_ST_FAILURE;
83 }
84 memset(&guid, 0, 16);
85 *varname = 0;
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020086 len = 2 * EFI_ST_MAX_VARNAME_SIZE;
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020087 ret = runtime->get_next_variable_name(&len, varname, &guid);
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020088 if (ret != EFI_SUCCESS) {
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020089 efi_st_error("GetNextVariableName failed\n");
90 return EFI_ST_FAILURE;
91 }
92
93 return EFI_ST_SUCCESS;
94}
95
96EFI_UNIT_TEST(variables_run) = {
97 .name = "variables at runtime",
98 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
99 .setup = setup,
100 .execute = execute,
101};