efi_selftest: check executing in EL2
UEFI binaries should be executed in EL2 or EL1 even if U-Boot is started in EL3. Provide a unit test. Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
@@ -51,6 +51,7 @@ efi_selftest_variables_runtime.o \
|
|||||||
efi_selftest_watchdog.o
|
efi_selftest_watchdog.o
|
||||||
|
|
||||||
obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o
|
obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o
|
||||||
|
obj-$(CONFIG_ARM64) += efi_selftest_el.o
|
||||||
obj-$(CONFIG_NETDEVICES) += efi_selftest_snp.o
|
obj-$(CONFIG_NETDEVICES) += efi_selftest_snp.o
|
||||||
obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_http.o
|
obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_http.o
|
||||||
obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_ipconfig.o
|
obj-$(CONFIG_EFI_HTTP_PROTOCOL) += efi_selftest_ipconfig.o
|
||||||
|
46
lib/efi_selftest/efi_selftest_el.c
Normal file
46
lib/efi_selftest/efi_selftest_el.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Check current exception level on ARMv8.
|
||||||
|
*/
|
||||||
|
#include <efi_loader.h>
|
||||||
|
#include <efi_selftest.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current_exception_level()
|
||||||
|
*
|
||||||
|
* Return: current exception level, 0 - 3
|
||||||
|
*/
|
||||||
|
static unsigned int current_exception_level(void)
|
||||||
|
{
|
||||||
|
unsigned long el;
|
||||||
|
|
||||||
|
asm volatile (
|
||||||
|
"MRS %0, CurrentEL"
|
||||||
|
: "=r" (el) : : );
|
||||||
|
|
||||||
|
return (el >> 2) & 0x3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute() - execute test
|
||||||
|
*
|
||||||
|
* Check that the exception level is not EL3.
|
||||||
|
*/
|
||||||
|
static int execute(void)
|
||||||
|
{
|
||||||
|
unsigned int el = current_exception_level();
|
||||||
|
|
||||||
|
efi_st_printf("Exception level EL%u\n", el);
|
||||||
|
if (el != 1 && el != 2) {
|
||||||
|
efi_st_error("EL1 or EL2 expected");
|
||||||
|
return EFI_ST_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_ST_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_UNIT_TEST(el) = {
|
||||||
|
.name = "exception level",
|
||||||
|
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
|
||||||
|
.execute = execute,
|
||||||
|
};
|
Reference in New Issue
Block a user