aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_selftest/efi_selftest_fdt.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-02-05 08:45:55 +0100
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-02-05 20:20:01 +0100
commitb9b4cecf9bd5208269bd706965be8ceb215cdcaf (patch)
treef5126c85365ea9007579beb70e89bda3bb88a0d7 /lib/efi_selftest/efi_selftest_fdt.c
parent8efefcec00240c982ff4f4c7437f0f89829a5ab6 (diff)
downloadu-boot-b9b4cecf9bd5208269bd706965be8ceb215cdcaf.zip
u-boot-b9b4cecf9bd5208269bd706965be8ceb215cdcaf.tar.gz
u-boot-b9b4cecf9bd5208269bd706965be8ceb215cdcaf.tar.bz2
efi_selftest: merge FDT and RISC-V tests
The test for the RISCV_EFI_BOOT_PROTOCOL retrieves the boot hart id via the protocol and compares it to the value of the boot hart id in the device tree. The boot hart id is already retrieved from the device tree in the FDT test. Merge the two tests to avoid code duplication. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'lib/efi_selftest/efi_selftest_fdt.c')
-rw-r--r--lib/efi_selftest/efi_selftest_fdt.c72
1 files changed, 57 insertions, 15 deletions
diff --git a/lib/efi_selftest/efi_selftest_fdt.c b/lib/efi_selftest/efi_selftest_fdt.c
index f4a7fcb..114ac58 100644
--- a/lib/efi_selftest/efi_selftest_fdt.c
+++ b/lib/efi_selftest/efi_selftest_fdt.c
@@ -1,15 +1,14 @@
// SPDX-License-Identifier: GPL-2.0+
/*
- * efi_selftest_pos
+ * efi_selftest_fdt
*
* Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
+ * Copyright (c) 2022 Ventana Micro Systems Inc
*
- * Test the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.
- *
- * The following services are tested:
- * OutputString, TestString, SetAttribute.
+ * Check the device tree, test the RISCV_EFI_BOOT_PROTOCOL.
*/
+#include <efi_riscv.h>
#include <efi_selftest.h>
#include <linux/libfdt.h>
@@ -22,6 +21,8 @@ static const char *fdt;
static const efi_guid_t fdt_guid = EFI_FDT_GUID;
static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
+static const efi_guid_t riscv_efi_boot_protocol_guid =
+ RISCV_EFI_BOOT_PROTOCOL_GUID;
/**
* f2h() - convert FDT value to host endianness.
@@ -189,6 +190,29 @@ static int setup(const efi_handle_t img_handle,
return EFI_ST_SUCCESS;
}
+__maybe_unused static efi_status_t get_boot_hartid(efi_uintn_t *efi_hartid)
+{
+ efi_status_t ret;
+ struct riscv_efi_boot_protocol *prot;
+
+ /* Get RISC-V boot protocol */
+ ret = boottime->locate_protocol(&riscv_efi_boot_protocol_guid, NULL,
+ (void **)&prot);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("RISC-V Boot Protocol not available\n");
+ return EFI_ST_FAILURE;
+ }
+
+ /* Get boot hart ID from EFI protocol */
+ ret = prot->get_boot_hartid(prot, efi_hartid);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("Could not retrieve boot hart ID\n");
+ return EFI_ST_FAILURE;
+ }
+
+ return EFI_ST_SUCCESS;
+}
+
/*
* Execute unit test.
*
@@ -220,19 +244,37 @@ static int execute(void)
return EFI_ST_FAILURE;
}
}
- str = get_property(u"boot-hartid", u"chosen");
if (IS_ENABLED(CONFIG_RISCV)) {
- if (str) {
- efi_st_printf("boot-hartid: %u\n",
- f2h(*(fdt32_t *)str));
- ret = boottime->free_pool(str);
- if (ret != EFI_SUCCESS) {
- efi_st_error("FreePool failed\n");
+ u32 fdt_hartid;
+
+ str = get_property(u"boot-hartid", u"chosen");
+ if (!str) {
+ efi_st_error("boot-hartid missing in devicetree\n");
+ return EFI_ST_FAILURE;
+ }
+ fdt_hartid = f2h(*(fdt32_t *)str);
+ efi_st_printf("boot-hartid: %u\n", fdt_hartid);
+
+ ret = boottime->free_pool(str);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("FreePool failed\n");
+ return EFI_ST_FAILURE;
+ }
+
+ if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) {
+ efi_uintn_t efi_hartid;
+ int r;
+
+ r = get_boot_hartid(&efi_hartid);
+ if (r != EFI_ST_SUCCESS)
+ return r;
+ /* Boot hart ID should be same */
+ if (efi_hartid != fdt_hartid) {
+ efi_st_error("boot-hartid differs: prot 0x%p, DT 0x%.8x\n",
+ (void *)(uintptr_t)efi_hartid,
+ fdt_hartid);
return EFI_ST_FAILURE;
}
- } else {
- efi_st_error("boot-hartid not found\n");
- return EFI_ST_FAILURE;
}
}