summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arch/riscv/Makefile.mk1
-rw-r--r--src/arch/riscv/opensbi.c56
2 files changed, 34 insertions, 23 deletions
diff --git a/src/arch/riscv/Makefile.mk b/src/arch/riscv/Makefile.mk
index d5defea0e7..6754c2202d 100644
--- a/src/arch/riscv/Makefile.mk
+++ b/src/arch/riscv/Makefile.mk
@@ -180,7 +180,6 @@ cbfs-files-y += $(OPENSBI_CBFS)
check-ramstage-overlap-files += $(OPENSBI_CBFS)
-CPPFLAGS_common += -I$(OPENSBI_SOURCE)/include
ramstage-y += opensbi.c
endif #CONFIG_RISCV_OPENSBI
diff --git a/src/arch/riscv/opensbi.c b/src/arch/riscv/opensbi.c
index bf26b2279e..36f2951559 100644
--- a/src/arch/riscv/opensbi.c
+++ b/src/arch/riscv/opensbi.c
@@ -1,13 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-/* OpenSBI wants to make its own definitions for some of our compiler.h macros. */
-#undef __packed
-#undef __noreturn
-#undef __aligned
-
-#include <sbi/fw_dynamic.h>
#include <arch/boot.h>
-/* DO NOT INCLUDE COREBOOT HEADERS HERE */
+#include <arch/encoding.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#define FW_DYNAMIC_INFO_VERSION_2 2
+#define FW_DYNAMIC_INFO_MAGIC_VALUE 0x4942534f // "OSBI"
+
+/*
+ * structure passed to OpenSBI as 3rd argument
+ * NOTE: This structure may need to be updated when the OpenSBI submodule is updated.
+ */
+static struct __packed fw_dynamic_info {
+ unsigned long magic; // magic value "OSBI"
+ unsigned long version; // version number (2)
+ unsigned long next_addr; // Next booting stage address (payload address)
+ unsigned long next_mode; // Next booting stage mode (usually supervisor mode)
+ unsigned long options; // options for OpenSBI library
+ unsigned long boot_hart; // usually CONFIG_RISCV_WORKING_HARTID
+} info;
void run_opensbi(const int hart_id,
const void *fdt,
@@ -15,21 +27,21 @@ void run_opensbi(const int hart_id,
const void *payload,
const int payload_mode)
{
- struct fw_dynamic_info info = {
- .magic = FW_DYNAMIC_INFO_MAGIC_VALUE,
- .version = FW_DYNAMIC_INFO_VERSION_MAX,
- .next_mode = payload_mode,
- .next_addr = (uintptr_t)payload,
- .options = 0,
- .boot_hart = CONFIG_OPENSBI_FW_DYNAMIC_BOOT_HART,
- };
+ info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE,
+ info.version = FW_DYNAMIC_INFO_VERSION_2,
+ info.next_mode = payload_mode,
+ info.next_addr = (uintptr_t)payload,
+ info.options = 0,
+ info.boot_hart = CONFIG_OPENSBI_FW_DYNAMIC_BOOT_HART,
- csr_write(mepc, opensbi);
+ write_csr(mepc, opensbi); // set program counter to OpenSBI (jumped to with mret)
asm volatile (
- "mv a0, %0\n\t"
- "mv a1, %1\n\t"
- "mv a2, %2\n\t"
- "mret" :
- : "r"(hart_id), "r"(fdt), "r"(&info)
- : "a0", "a1", "a2");
+ "mv a0, %0\n\t"
+ "mv a1, %1\n\t"
+ "mv a2, %2\n\t"
+ "mret"
+ :
+ : "r"(hart_id), "r"(fdt), "r"(&info)
+ : "a0", "a1", "a2"
+ );
}