riscv: lib: Add a default implementation of board_fdt_blob_setup
authorYao Zi <ziyao@disroot.org>
Fri, 7 Mar 2025 13:13:41 +0000 (13:13 +0000)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Fri, 25 Apr 2025 08:30:54 +0000 (16:30 +0800)
It's common for S-Mode proper U-Boot to retrieve a FDT blob along with
taking control from SBI firmware. Add a weak version of
board_fdt_blob_setup to make use of it by default, avoiding copy-pasting
similar functions among boards.

Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
arch/riscv/lib/Makefile
arch/riscv/lib/board.c [new file with mode: 0644]

index 22b675f..189b35c 100644 (file)
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(PHASE_)SMP) += smp.o
 obj-$(CONFIG_XPL_BUILD)        += spl.o
 obj-y   += fdt_fixup.o
 obj-$(CONFIG_$(SPL)CMD_BDI) += bdinfo.o
+obj-$(CONFIG_OF_BOARD) += board.o
 
 # For building EFI apps
 CFLAGS_NON_EFI := -fstack-protector-strong
diff --git a/arch/riscv/lib/board.c b/arch/riscv/lib/board.c
new file mode 100644 (file)
index 0000000..624c4ea
--- /dev/null
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * RISC-V-specific handling of firmware FDT
+ */
+
+#include <asm/global_data.h>
+#include <linux/errno.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+__weak int board_fdt_blob_setup(void **fdtp)
+{
+       if (!gd->arch.firmware_fdt_addr)
+               return -EEXIST;
+
+       *fdtp = (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
+
+       return 0;
+}