summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2025-11-22 10:34:03 -0600
committerTom Rini <[email protected]>2025-11-22 10:34:03 -0600
commit6e7d2399c8139f8e2d037e446236b8d8bdbca604 (patch)
tree8a3be782b836f8eb5b6c6143f5cdc1e011857fda
parent8ff90aa64b730c3f511921d4ff79e9f64e625867 (diff)
parente81750779ac031a0d9f69487f0295fb0732ba496 (diff)
Merge tag 'efi-next-2025-11-25' of https://source.denx.de/u-boot/custodians/u-boot-efi into next
Pull request efi-next-2025-11-25 CI: https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/28455 UEFI: * In UEFI selftests expose the runtime address as a global variable and use it to simplify some of the tests
-rw-r--r--include/efi_selftest.h5
-rw-r--r--lib/efi_selftest/efi_selftest.c8
-rw-r--r--lib/efi_selftest/efi_selftest_reset.c20
-rw-r--r--lib/efi_selftest/efi_selftest_rtc.c25
-rw-r--r--lib/efi_selftest/efi_selftest_set_virtual_address_map.c38
-rw-r--r--lib/efi_selftest/efi_selftest_variables.c121
-rw-r--r--lib/efi_selftest/efi_selftest_variables_common.c55
-rw-r--r--lib/efi_selftest/efi_selftest_variables_runtime.c183
8 files changed, 190 insertions, 265 deletions
diff --git a/include/efi_selftest.h b/include/efi_selftest.h
index 1b708849bcb..874f8b5efe7 100644
--- a/include/efi_selftest.h
+++ b/include/efi_selftest.h
@@ -19,6 +19,7 @@
extern const struct efi_system_table *st_systable;
extern const struct efi_boot_services *st_boottime;
+extern const struct efi_runtime_services *st_runtime;
/**
* efi_st_printf() - print a message
@@ -150,13 +151,11 @@ u16 efi_st_get_key(void);
/**
* efi_st_query_variable_common - Common variable tests for boottime/runtime
*
- * @runtime: Pointer to services table
* @attributes: Attributes used
*
* Return: EFI_ST_SUCCESS/FAILURE
*/
-int efi_st_query_variable_common(struct efi_runtime_services *runtime,
- u32 attributes);
+int efi_st_query_variable_common(u32 attributes);
/**
* struct efi_unit_test - EFI unit test
diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c
index 191da7fc451..2b95713afb4 100644
--- a/lib/efi_selftest/efi_selftest.c
+++ b/lib/efi_selftest/efi_selftest.c
@@ -16,7 +16,7 @@
const struct efi_system_table *st_systable;
const struct efi_boot_services *st_boottime;
-static const struct efi_runtime_services *runtime;
+const struct efi_runtime_services *st_runtime;
static efi_handle_t handle;
static u16 reset_message[] = u"Selftest completed";
static int *setup_status;
@@ -259,7 +259,7 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
st_systable = systab;
st_boottime = st_systable->boottime;
- runtime = st_systable->runtime;
+ st_runtime = st_systable->runtime;
handle = image_handle;
con_out = st_systable->con_out;
con_in = st_systable->con_in;
@@ -347,8 +347,8 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
efi_st_get_key();
if (IS_ENABLED(CONFIG_EFI_HAVE_RUNTIME_RESET)) {
- runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY,
- sizeof(reset_message), reset_message);
+ st_runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY,
+ sizeof(reset_message), reset_message);
} else {
efi_restore_gd();
do_reset(NULL, 0, 0, NULL);
diff --git a/lib/efi_selftest/efi_selftest_reset.c b/lib/efi_selftest/efi_selftest_reset.c
index 5dfe517de4f..8125f51815e 100644
--- a/lib/efi_selftest/efi_selftest_reset.c
+++ b/lib/efi_selftest/efi_selftest_reset.c
@@ -10,22 +10,6 @@
#include <efi_selftest.h>
-static struct efi_runtime_services *runtime;
-
-/*
- * Setup unit test.
- *
- * @handle: handle of the loaded image
- * @systable: system table
- * Return: EFI_ST_SUCCESS for success
- */
-static int setup(const efi_handle_t handle,
- const struct efi_system_table *systable)
-{
- runtime = systable->runtime;
- return EFI_ST_SUCCESS;
-}
-
/*
* Execute unit test.
*
@@ -35,7 +19,7 @@ static int execute(void)
{
u16 reset_data[] = u"Reset by selftest";
- runtime->reset_system(EFI_RESET_COLD, EFI_SUCCESS,
+ st_runtime->reset_system(EFI_RESET_COLD, EFI_SUCCESS,
sizeof(reset_data), reset_data);
efi_st_error("Reset failed.\n");
return EFI_ST_FAILURE;
@@ -44,7 +28,6 @@ static int execute(void)
EFI_UNIT_TEST(reset) = {
.name = "reset system",
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
- .setup = setup,
.execute = execute,
.on_request = true,
};
@@ -52,7 +35,6 @@ EFI_UNIT_TEST(reset) = {
EFI_UNIT_TEST(resetrt) = {
.name = "reset system runtime",
.phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
- .setup = setup,
.execute = execute,
.on_request = true,
};
diff --git a/lib/efi_selftest/efi_selftest_rtc.c b/lib/efi_selftest/efi_selftest_rtc.c
index e9e47e96c4b..54d4e786a8f 100644
--- a/lib/efi_selftest/efi_selftest_rtc.c
+++ b/lib/efi_selftest/efi_selftest_rtc.c
@@ -12,22 +12,6 @@
#define EFI_ST_NO_RTC "Could not read real time clock\n"
#define EFI_ST_NO_RTC_SET "Could not set real time clock\n"
-static struct efi_runtime_services *runtime;
-
-/*
- * Setup unit test.
- *
- * @handle: handle of the loaded image
- * @systable: system table
- * Return: EFI_ST_SUCCESS for success
- */
-static int setup(const efi_handle_t handle,
- const struct efi_system_table *systable)
-{
- runtime = systable->runtime;
- return EFI_ST_SUCCESS;
-}
-
/*
* Execute unit test.
*
@@ -53,7 +37,7 @@ static int execute(void)
#endif
/* Display current time */
- ret = runtime->get_time(&tm_old, NULL);
+ ret = st_runtime->get_time(&tm_old, NULL);
if (ret != EFI_SUCCESS) {
efi_st_error(EFI_ST_NO_RTC);
return EFI_ST_FAILURE;
@@ -63,12 +47,12 @@ static int execute(void)
tm_old.year, tm_old.month, tm_old.day,
tm_old.hour, tm_old.minute, tm_old.second);
#ifdef CONFIG_EFI_SET_TIME
- ret = runtime->set_time(&tm_new);
+ ret = st_runtime->set_time(&tm_new);
if (ret != EFI_SUCCESS) {
efi_st_error(EFI_ST_NO_RTC_SET);
return EFI_ST_FAILURE;
}
- ret = runtime->get_time(&tm, NULL);
+ ret = st_runtime->get_time(&tm, NULL);
if (ret != EFI_SUCCESS) {
efi_st_error(EFI_ST_NO_RTC);
return EFI_ST_FAILURE;
@@ -84,7 +68,7 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Set time back to old value */
- ret = runtime->set_time(&tm_old);
+ ret = st_runtime->set_time(&tm_old);
if (ret != EFI_SUCCESS) {
efi_st_error(EFI_ST_NO_RTC_SET);
return EFI_ST_FAILURE;
@@ -97,6 +81,5 @@ static int execute(void)
EFI_UNIT_TEST(rtc) = {
.name = "real time clock",
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
- .setup = setup,
.execute = execute,
};
diff --git a/lib/efi_selftest/efi_selftest_set_virtual_address_map.c b/lib/efi_selftest/efi_selftest_set_virtual_address_map.c
index d28ed83eb37..8bcf89274ce 100644
--- a/lib/efi_selftest/efi_selftest_set_virtual_address_map.c
+++ b/lib/efi_selftest/efi_selftest_set_virtual_address_map.c
@@ -10,8 +10,6 @@
#include <efi_selftest.h>
-static const struct efi_boot_services *boottime;
-static const struct efi_runtime_services *runtime;
static struct efi_event *event;
static struct efi_mem_desc *memory_map;
static efi_uintn_t map_size;
@@ -39,7 +37,7 @@ static void EFIAPI notify(struct efi_event *event, void *context)
++notify_call_count;
addr = (void *)(uintptr_t)page1;
- ret = runtime->convert_pointer(0, &addr);
+ ret = st_runtime->convert_pointer(0, &addr);
if (ret != EFI_SUCCESS) {
efi_st_error("ConvertPointer failed\n");
convert_pointer_failed = true;
@@ -52,7 +50,7 @@ static void EFIAPI notify(struct efi_event *event, void *context)
}
addr = (void *)(uintptr_t)page2;
- ret = runtime->convert_pointer(0, &addr);
+ ret = st_runtime->convert_pointer(0, &addr);
if (ret != EFI_SUCCESS) {
efi_st_error("ConvertPointer failed\n");
convert_pointer_failed = true;
@@ -82,19 +80,15 @@ static int setup(const efi_handle_t handle,
efi_status_t ret;
struct efi_mem_desc *end, *pos1, *pos2;
- boottime = systable->boottime;
- runtime = systable->runtime;
-
- ret = boottime->create_event(EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
- TPL_CALLBACK, notify, NULL,
- &event);
+ ret = st_boottime->create_event(EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
+ TPL_CALLBACK, notify, NULL, &event);
if (ret != EFI_SUCCESS) {
efi_st_error("could not create event\n");
return EFI_ST_FAILURE;
}
- ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
- &desc_version);
+ ret = st_boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
+ &desc_version);
if (ret != EFI_BUFFER_TOO_SMALL) {
efi_st_error(
"GetMemoryMap did not return EFI_BUFFER_TOO_SMALL\n");
@@ -102,26 +96,26 @@ static int setup(const efi_handle_t handle,
}
/* Allocate extra space for newly allocated memory */
map_size += 3 * sizeof(struct efi_mem_desc);
- ret = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
- (void **)&memory_map);
+ ret = st_boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
+ (void **)&memory_map);
if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
return EFI_ST_FAILURE;
}
- ret = boottime->get_memory_map(&map_size, memory_map, &map_key,
- &desc_size, &desc_version);
+ ret = st_boottime->get_memory_map(&map_size, memory_map, &map_key,
+ &desc_size, &desc_version);
if (ret != EFI_SUCCESS) {
efi_st_error("GetMemoryMap failed\n");
return EFI_ST_FAILURE;
}
- ret = boottime->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
- EFI_BOOT_SERVICES_DATA, 2, &page1);
+ ret = st_boottime->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
+ EFI_BOOT_SERVICES_DATA, 2, &page1);
if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePages failed\n");
return EFI_ST_FAILURE;
}
- ret = boottime->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
- EFI_BOOT_SERVICES_DATA, 3, &page2);
+ ret = st_boottime->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
+ EFI_BOOT_SERVICES_DATA, 3, &page2);
if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePages failed\n");
return EFI_ST_FAILURE;
@@ -182,8 +176,8 @@ static int execute(void)
{
efi_status_t ret;
- ret = runtime->set_virtual_address_map(map_size, desc_size,
- desc_version, memory_map);
+ ret = st_runtime->set_virtual_address_map(map_size, desc_size,
+ desc_version, memory_map);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVirtualAddressMap failed\n");
return EFI_ST_FAILURE;
diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c
index 3d5f38c6897..976eee8dcef 100644
--- a/lib/efi_selftest/efi_selftest_variables.c
+++ b/lib/efi_selftest/efi_selftest_variables.c
@@ -13,8 +13,6 @@
#define EFI_ST_MAX_DATA_SIZE 16
#define EFI_ST_MAX_VARNAME_SIZE 80
-static struct efi_boot_services *boottime;
-static struct efi_runtime_services *runtime;
static const efi_guid_t guid_vendor0 =
EFI_GUID(0x67029eb5, 0x0af2, 0xf6b1,
0xda, 0x53, 0xfc, 0xb5, 0x66, 0xdd, 0x1c, 0xe6);
@@ -23,21 +21,6 @@ static const efi_guid_t guid_vendor1 =
0x8f, 0xb1, 0x32, 0xf9, 0x0c, 0xa0, 0x42, 0xea);
/*
- * Setup unit test.
- *
- * @handle handle of the loaded image
- * @systable system table
- */
-static int setup(const efi_handle_t img_handle,
- const struct efi_system_table *systable)
-{
- boottime = systable->boottime;
- runtime = systable->runtime;
-
- return EFI_ST_SUCCESS;
-}
-
-/*
* Execute unit test.
*/
static int execute(void)
@@ -53,24 +36,23 @@ static int execute(void)
efi_guid_t guid;
int test_ret;
- test_ret = efi_st_query_variable_common(runtime,
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ test_ret = efi_st_query_variable_common(EFI_VARIABLE_BOOTSERVICE_ACCESS);
if (test_ret != EFI_ST_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
/* Set variable 0 */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS,
- 3, v + 4);
+ ret = st_runtime->set_variable(u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS, 3,
+ v + 4);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
data[3] = 0xff;
len = 3;
- ret = runtime->get_variable(u"efi_st_var0", &guid_vendor0,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_st_var0", &guid_vendor0, &attr,
+ &len, data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -84,16 +66,15 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Set variable 1 */
- ret = runtime->set_variable(u"efi_st_var1", &guid_vendor1,
- EFI_VARIABLE_BOOTSERVICE_ACCESS,
- 8, v);
+ ret = st_runtime->set_variable(u"efi_st_var1", &guid_vendor1,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS, 8, v);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_st_var1", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_st_var1", &guid_vendor1, &attr,
+ &len, data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -108,17 +89,17 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Append variable 1 */
- ret = runtime->set_variable(u"efi_st_var1", &guid_vendor1,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_APPEND_WRITE,
- 7, v + 8);
+ ret = st_runtime->set_variable(u"efi_st_var1", &guid_vendor1,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE,
+ 7, v + 8);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable(APPEND_WRITE) failed\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_st_var1", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_st_var1", &guid_vendor1, &attr,
+ &len, data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -130,34 +111,35 @@ static int execute(void)
efi_st_todo("GetVariable returned wrong value\n");
/* Append variable 2, write to non-existent variable with datasize=0 */
- ret = runtime->set_variable(u"efi_none", &guid_vendor1,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_APPEND_WRITE,
- 0, v);
+ ret = st_runtime->set_variable(u"efi_none", &guid_vendor1,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE,
+ 0, v);
if (ret != EFI_SUCCESS) {
efi_st_error(
"SetVariable(APPEND_WRITE) with size 0 to non-existent variable returns wrong code\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_none", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_none", &guid_vendor1, &attr, &len,
+ data);
if (ret != EFI_NOT_FOUND) {
efi_st_error("Variable must not be created\n");
return EFI_ST_FAILURE;
}
/* Append variable 2, write to non-existent variable with valid data size*/
- ret = runtime->set_variable(u"efi_none", &guid_vendor1,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_APPEND_WRITE,
- 15, v);
+ ret = st_runtime->set_variable(u"efi_none", &guid_vendor1,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE,
+ 15, v);
if (ret != EFI_SUCCESS) {
- efi_st_error("SetVariable(APPEND_WRITE) with valid size and data to non-existent variable must be succcessful\n");
+ efi_st_error(
+ "SetVariable(APPEND_WRITE) with valid size and data to non-existent variable must be succcessful\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_none", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_none", &guid_vendor1, &attr, &len,
+ data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -168,61 +150,60 @@ static int execute(void)
if (memcmp(data, v, len))
efi_st_todo("GetVariable returned wrong value\n");
/* Delete variable efi_none */
- ret = runtime->set_variable(u"efi_none", &guid_vendor1,
- 0, 0, NULL);
+ ret = st_runtime->set_variable(u"efi_none", &guid_vendor1, 0, 0, NULL);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_none", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_none", &guid_vendor1, &attr, &len,
+ data);
if (ret != EFI_NOT_FOUND) {
efi_st_error("Variable was not deleted\n");
return EFI_ST_FAILURE;
}
/* Enumerate variables */
- ret = runtime->get_next_variable_name(NULL, u"efi_st_var1", &guid);
+ ret = st_runtime->get_next_variable_name(NULL, u"efi_st_var1", &guid);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("GetNextVariableName missing parameter check\n");
return EFI_ST_FAILURE;
}
len = 24;
- ret = runtime->get_next_variable_name(&len, NULL, &guid);
+ ret = st_runtime->get_next_variable_name(&len, NULL, &guid);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("GetNextVariableName missing parameter check\n");
return EFI_ST_FAILURE;
}
len = 24;
- ret = runtime->get_next_variable_name(&len, u"efi_st_var1", NULL);
+ ret = st_runtime->get_next_variable_name(&len, u"efi_st_var1", NULL);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("GetNextVariableName missing parameter check\n");
return EFI_ST_FAILURE;
}
len = 1;
- ret = runtime->get_next_variable_name(&len, u"", &guid);
+ ret = st_runtime->get_next_variable_name(&len, u"", &guid);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("GetNextVariableName missing parameter check\n");
return EFI_ST_FAILURE;
}
len = 16;
- ret = runtime->get_next_variable_name(&len, u"efi_st_var1", &guid);
+ ret = st_runtime->get_next_variable_name(&len, u"efi_st_var1", &guid);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("GetNextVariableName missing parameter check\n");
return EFI_ST_FAILURE;
}
- boottime->set_mem(&guid, 16, 0);
+ st_boottime->set_mem(&guid, 16, 0);
*varname = 0;
flag = 0;
for (;;) {
len = EFI_ST_MAX_VARNAME_SIZE;
- ret = runtime->get_next_variable_name(&len, varname, &guid);
+ ret = st_runtime->get_next_variable_name(&len, varname, &guid);
if (ret == EFI_NOT_FOUND)
break;
if (ret != EFI_SUCCESS) {
@@ -234,8 +215,9 @@ static int execute(void)
!efi_st_strcmp_16_8(varname, "efi_st_var0")) {
flag |= 1;
if (len != 24) {
- efi_st_error("GetNextVariableName report wrong length %u, expected 24\n",
- (unsigned int)len);
+ efi_st_error(
+ "GetNextVariableName report wrong length %u, expected 24\n",
+ (unsigned int)len);
return EFI_ST_FAILURE;
}
}
@@ -249,29 +231,29 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Delete variable 1 */
- ret = runtime->set_variable(u"efi_st_var1", &guid_vendor1,
- 0, 0, NULL);
+ ret = st_runtime->set_variable(u"efi_st_var1", &guid_vendor1, 0, 0,
+ NULL);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_st_var1", &guid_vendor1,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_st_var1", &guid_vendor1, &attr,
+ &len, data);
if (ret != EFI_NOT_FOUND) {
efi_st_error("Variable was not deleted\n");
return EFI_ST_FAILURE;
}
/* Delete variable 0 */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- 0, 0, NULL);
+ ret = st_runtime->set_variable(u"efi_st_var0", &guid_vendor0, 0, 0,
+ NULL);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"efi_st_var0", &guid_vendor0,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"efi_st_var0", &guid_vendor0, &attr,
+ &len, data);
if (ret != EFI_NOT_FOUND) {
efi_st_error("Variable was not deleted\n");
return EFI_ST_FAILURE;
@@ -283,6 +265,5 @@ static int execute(void)
EFI_UNIT_TEST(variables) = {
.name = "variables",
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
- .setup = setup,
.execute = execute,
};
diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c
index 453bc8709a6..704da016c6d 100644
--- a/lib/efi_selftest/efi_selftest_variables_common.c
+++ b/lib/efi_selftest/efi_selftest_variables_common.c
@@ -11,15 +11,13 @@
#define EFI_INVALID_ATTR BIT(30)
-int efi_st_query_variable_common(struct efi_runtime_services *runtime,
- u32 attributes)
+int efi_st_query_variable_common(u32 attributes)
{
efi_status_t ret;
u64 max_storage, rem_storage, max_size;
- ret = runtime->query_variable_info(attributes,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(attributes, &max_storage,
+ &rem_storage, &max_size);
if (ret != EFI_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
@@ -28,58 +26,54 @@ int efi_st_query_variable_common(struct efi_runtime_services *runtime,
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS,
+ &max_storage, &rem_storage,
+ &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(attributes,
- NULL, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(attributes, NULL, &rem_storage,
+ &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(attributes,
- &max_storage, NULL,
- &max_size);
+ ret = st_runtime->query_variable_info(attributes, &max_storage, NULL,
+ &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(attributes,
- &max_storage, &rem_storage,
- NULL);
+ ret = st_runtime->query_variable_info(attributes, &max_storage,
+ &rem_storage, NULL);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(0, &max_storage, &rem_storage,
+ &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(attributes |
- EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(
+ attributes | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ &max_storage, &rem_storage, &max_size);
if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
- ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
+ &max_storage, &rem_storage,
+ &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
@@ -89,10 +83,9 @@ int efi_st_query_variable_common(struct efi_runtime_services *runtime,
* Use a mix existing/non-existing attribute bits from the
* UEFI spec
*/
- ret = runtime->query_variable_info(attributes | EFI_INVALID_ATTR |
- EFI_VARIABLE_NON_VOLATILE,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(
+ attributes | EFI_INVALID_ATTR | EFI_VARIABLE_NON_VOLATILE,
+ &max_storage, &rem_storage, &max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c
index 379c4f9c47b..0886b4894b8 100644
--- a/lib/efi_selftest/efi_selftest_variables_runtime.c
+++ b/lib/efi_selftest/efi_selftest_variables_runtime.c
@@ -16,26 +16,9 @@
#define EFI_ST_MAX_DATA_SIZE 16
#define EFI_ST_MAX_VARNAME_SIZE 40
-static struct efi_boot_services *boottime;
-static struct efi_runtime_services *runtime;
static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;
static const efi_guid_t __efi_runtime_data efi_rt_var_guid =
- U_BOOT_EFI_RT_VAR_FILE_GUID;
-
-/*
- * Setup unit test.
- *
- * @handle handle of the loaded image
- * @systable system table
- */
-static int setup(const efi_handle_t img_handle,
- const struct efi_system_table *systable)
-{
- boottime = systable->boottime;
- runtime = systable->runtime;
-
- return EFI_ST_SUCCESS;
-}
+ U_BOOT_EFI_RT_VAR_FILE_GUID;
/**
* execute() - execute unit test
@@ -60,26 +43,27 @@ static int execute(void)
memset(v2, 0x1, sizeof(v2));
if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) {
- test_ret = efi_st_query_variable_common(runtime, EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS);
+ test_ret = efi_st_query_variable_common(
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS);
if (test_ret != EFI_ST_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
} else {
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
- &max_storage, &rem_storage,
- &max_size);
+ ret = st_runtime->query_variable_info(
+ EFI_VARIABLE_BOOTSERVICE_ACCESS, &max_storage,
+ &rem_storage, &max_size);
if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
}
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- 3, v + 4);
+ ret = st_runtime->set_variable(u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS,
+ 3, v + 4);
if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) {
efi_uintn_t prev_len, delta;
struct efi_var_entry *var;
@@ -91,20 +75,21 @@ static int execute(void)
return EFI_ST_FAILURE;
}
- /* runtime atttribute must be set */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- 3, v + 4);
+ /* runtime attribute must be set */
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ 3, v + 4);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = sizeof(data);
- ret = runtime->get_variable(u"RTStorageVolatile",
- &efi_rt_var_guid,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"RTStorageVolatile",
+ &efi_rt_var_guid, &attr, &len,
+ data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -118,8 +103,8 @@ static int execute(void)
}
len = sizeof(data2);
- ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
- &attr, &len, data2);
+ ret = st_runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
+ &attr, &len, data2);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -129,12 +114,12 @@ static int execute(void)
* Store it now, we'll use it later
*/
prev_len = len;
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- sizeof(v2),
- v2);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ sizeof(v2), v2);
/*
* This will try to update VarToFile as well and must fail,
* without changing or deleting VarToFile
@@ -144,60 +129,64 @@ static int execute(void)
return EFI_ST_FAILURE;
}
len = sizeof(data2);
- ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
- &attr, &len, data2);
+ ret = st_runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
+ &attr, &len, data2);
if (ret != EFI_SUCCESS || prev_len != len) {
efi_st_error("Get/SetVariable failed\n");
return EFI_ST_FAILURE;
}
/* Add an 8byte aligned variable */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- sizeof(v), v);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ sizeof(v), v);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
/* Delete it by setting the attrs to 0 */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- 0, sizeof(v), v);
+ ret = st_runtime->set_variable(u"efi_st_var0", &guid_vendor0, 0,
+ sizeof(v), v);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
/* Add it back */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- sizeof(v), v);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ sizeof(v), v);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
/* Delete it again by setting the size to 0 */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- 0, NULL);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ 0, NULL);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
/* Delete it again and make sure it's not there */
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- 0, NULL);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ 0, NULL);
if (ret != EFI_NOT_FOUND) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
@@ -207,11 +196,12 @@ static int execute(void)
* Add a non-aligned variable
* VarToFile updates must include efi_st_var0
*/
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- 9, v + 4);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ 9, v + 4);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
@@ -223,8 +213,8 @@ static int execute(void)
}
delta = efi_var_entry_len(var);
len = sizeof(data2);
- ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
- &attr, &len, data2);
+ ret = st_runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
+ &attr, &len, data2);
if (ret != EFI_SUCCESS || prev_len + delta != len) {
efi_st_error("Get/SetVariable failed\n");
return EFI_ST_FAILURE;
@@ -237,25 +227,27 @@ static int execute(void)
*/
prev_len = len;
avail = efi_var_entry_len(var) -
- (sizeof(u16) * (u16_strlen(var->name) + 1) + sizeof(*var)) -
+ (sizeof(u16) * (u16_strlen(var->name) + 1) +
+ sizeof(*var)) -
var->length;
if (avail >= append_len)
delta = 0;
else
delta = ALIGN(append_len - avail, 8);
- ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_APPEND_WRITE |
- EFI_VARIABLE_NON_VOLATILE,
- append_len, v2);
+ ret = st_runtime->set_variable(
+ u"efi_st_var0", &guid_vendor0,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE |
+ EFI_VARIABLE_NON_VOLATILE,
+ append_len, v2);
if (ret != EFI_SUCCESS) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
len = sizeof(data2);
- ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
- &attr, &len, data2);
+ ret = st_runtime->get_variable(u"VarToFile", &efi_rt_var_guid,
+ &attr, &len, data2);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -267,20 +259,22 @@ static int execute(void)
/* Make sure that variable contains a valid file */
hdr = (struct efi_var_file *)data2;
- if (hdr->magic != EFI_VAR_FILE_MAGIC ||
- len != hdr->length ||
- hdr->crc32 != crc32(0, (u8 *)((uintptr_t)data2 + sizeof(struct efi_var_file)),
+ if (hdr->magic != EFI_VAR_FILE_MAGIC || len != hdr->length ||
+ hdr->crc32 != crc32(0,
+ (u8 *)((uintptr_t)data2 +
+ sizeof(struct efi_var_file)),
len - sizeof(struct efi_var_file))) {
efi_st_error("VarToFile invalid header\n");
return EFI_ST_FAILURE;
}
/* Variables that are BS, RT and volatile are RO after EBS */
- ret = runtime->set_variable(u"VarToFile", &efi_rt_var_guid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE,
- sizeof(v), v);
+ ret = st_runtime->set_variable(
+ u"VarToFile", &efi_rt_var_guid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE,
+ sizeof(v), v);
if (ret != EFI_WRITE_PROTECTED) {
efi_st_error("Get/SetVariable failed\n");
return EFI_ST_FAILURE;
@@ -292,8 +286,8 @@ static int execute(void)
}
}
len = EFI_ST_MAX_DATA_SIZE;
- ret = runtime->get_variable(u"PlatformLangCodes", &guid_vendor0,
- &attr, &len, data);
+ ret = st_runtime->get_variable(u"PlatformLangCodes", &guid_vendor0,
+ &attr, &len, data);
if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
@@ -301,7 +295,7 @@ static int execute(void)
memset(&guid, 0, 16);
*varname = 0;
len = 2 * EFI_ST_MAX_VARNAME_SIZE;
- ret = runtime->get_next_variable_name(&len, varname, &guid);
+ ret = st_runtime->get_next_variable_name(&len, varname, &guid);
if (ret != EFI_SUCCESS) {
efi_st_error("GetNextVariableName failed\n");
return EFI_ST_FAILURE;
@@ -313,6 +307,5 @@ static int execute(void)
EFI_UNIT_TEST(variables_run) = {
.name = "variables at runtime",
.phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
- .setup = setup,
.execute = execute,
};