* [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode
@ 2025-03-07 13:13 Yao Zi
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Yao Zi @ 2025-03-07 13:13 UTC (permalink / raw)
To: Rick Chen, Leo, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt
Cc: u-boot, Yao Zi
A typical bootflow of S-Mode RISC-V U-Boot looks like,
------- ------- ----------
| SPL | -> | SBI | -> | U-Boot |
------- ------- ----------
|
M-Mode | S-Mode
|
Both the most popular SBI implementation, OpenSBI, and U-Boot require a
FDT to function. The common solution is to pick an appropriate
devicetree at SPL stage and pass it to OpenSBI, which is also capable of
passing its (possibly modified) devicetree to the next stage (proper
U-Boot here) program.
The problem is although we retrieve the FDT passed by SBI in RISC-V's
start.S, a custom board_fdt_blob_setup is still required to make use of
it, resulting in duplicated similar functions in board-level code.
This series provides a weak version of board_fdt_blob_setup to setup the
SBI-passed FDT, serving as fallback on RISC-V platforms to eliminate the
duplication.
Tested on
- Milk-V Duo (milkv_duo_defconfig)
- Starfive VisionFive 2 (starfive_visionfive2_defconfig)
- QEMU VM (qemu-riscv64_smode_defconfig, sifive_unleashed_defconfig).
Changed from v1
- make the default implementation bail out in XPL stage
- correct commit message of sifive platform chagnes
- don't enable OF_HAS_PRIOR_STAGE by default on all SBI-capable RISC-V
platforms, as it may break the binman configuration
- Link to v1: https://lore.kernel.org/u-boot/20250227144734.61458-1-ziyao@disroot.org/
Yao Zi (4):
riscv: lib: Add a default implementation of board_fdt_blob_setup
board: qemu: riscv: Remove duplicated board_fdt_blob_setup
board: starfive: Remove duplicated board_fdt_blob_setup
board: sifive: Remove dead board_fdt_blob_setup
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/board.c | 19 +++++++++++++++++++
board/emulation/qemu-riscv/qemu-riscv.c | 8 --------
board/sifive/unleashed/unleashed.c | 11 -----------
board/sifive/unmatched/unmatched.c | 10 ----------
.../visionfive2/starfive_visionfive2.c | 10 ----------
6 files changed, 20 insertions(+), 39 deletions(-)
create mode 100644 arch/riscv/lib/board.c
--
2.48.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
2025-03-07 13:13 [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode Yao Zi
@ 2025-03-07 13:13 ` Yao Zi
2025-03-25 3:43 ` Leo Liang
` (2 more replies)
2025-03-07 13:13 ` [PATCH v2 2/4] board: qemu: riscv: Remove duplicated board_fdt_blob_setup Yao Zi
` (2 subsequent siblings)
3 siblings, 3 replies; 8+ messages in thread
From: Yao Zi @ 2025-03-07 13:13 UTC (permalink / raw)
To: Rick Chen, Leo, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt
Cc: u-boot, Yao Zi
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>
---
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/board.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 arch/riscv/lib/board.c
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 268116f3757..b33f9c646dd 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(XPL_)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
index 00000000000..1630355b2b1
--- /dev/null
+++ b/arch/riscv/lib/board.c
@@ -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 (IS_ENABLED(CONFIG_XPL_BUILD) || !gd->arch.firmware_fdt_addr)
+ return -EEXIST;
+
+ *fdtp = (void *)gd->arch.firmware_fdt_addr;
+
+ return 0;
+}
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] board: qemu: riscv: Remove duplicated board_fdt_blob_setup
2025-03-07 13:13 [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode Yao Zi
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
@ 2025-03-07 13:13 ` Yao Zi
2025-03-07 13:13 ` [PATCH v2 3/4] board: starfive: " Yao Zi
2025-03-07 13:13 ` [PATCH v2 4/4] board: sifive: Remove dead board_fdt_blob_setup Yao Zi
3 siblings, 0 replies; 8+ messages in thread
From: Yao Zi @ 2025-03-07 13:13 UTC (permalink / raw)
To: Rick Chen, Leo, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt
Cc: u-boot, Yao Zi
The default version should work for RISC-V QEMU.
Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
board/emulation/qemu-riscv/qemu-riscv.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
index a90222ea6a4..70190ebe8fc 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -63,11 +63,3 @@ int board_fit_config_name_match(const char *name)
return 0;
}
#endif
-
-int board_fdt_blob_setup(void **fdtp)
-{
- /* Stored the DTB address there during our init */
- *fdtp = (void *)(ulong)gd->arch.firmware_fdt_addr;
-
- return 0;
-}
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] board: starfive: Remove duplicated board_fdt_blob_setup
2025-03-07 13:13 [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode Yao Zi
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
2025-03-07 13:13 ` [PATCH v2 2/4] board: qemu: riscv: Remove duplicated board_fdt_blob_setup Yao Zi
@ 2025-03-07 13:13 ` Yao Zi
2025-03-07 13:13 ` [PATCH v2 4/4] board: sifive: Remove dead board_fdt_blob_setup Yao Zi
3 siblings, 0 replies; 8+ messages in thread
From: Yao Zi @ 2025-03-07 13:13 UTC (permalink / raw)
To: Rick Chen, Leo, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt
Cc: u-boot, Yao Zi
The default version should work for Starfive VisionFive 2.
Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
board/starfive/visionfive2/starfive_visionfive2.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c
index 3940d45b13f..96fb8dfe934 100644
--- a/board/starfive/visionfive2/starfive_visionfive2.c
+++ b/board/starfive/visionfive2/starfive_visionfive2.c
@@ -115,16 +115,6 @@ int board_late_init(void)
return 0;
}
-int board_fdt_blob_setup(void **fdtp)
-{
- if (gd->arch.firmware_fdt_addr) {
- *fdtp = (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
- return 0;
- }
-
- return -EEXIST;
-}
-
int ft_board_setup(void *blob, struct bd_info *bd)
{
return fdt_fixup_memory(blob, 0x40000000, gd->ram_size);
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] board: sifive: Remove dead board_fdt_blob_setup
2025-03-07 13:13 [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode Yao Zi
` (2 preceding siblings ...)
2025-03-07 13:13 ` [PATCH v2 3/4] board: starfive: " Yao Zi
@ 2025-03-07 13:13 ` Yao Zi
3 siblings, 0 replies; 8+ messages in thread
From: Yao Zi @ 2025-03-07 13:13 UTC (permalink / raw)
To: Rick Chen, Leo, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt
Cc: u-boot, Yao Zi
CONFIG_OF_BOARD isn't enabled on SiFive Unleashed and Unmatched, thus
board_fdt_blob_setup is actually dead code on these platforms. Let's
remove it.
Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
board/sifive/unleashed/unleashed.c | 11 -----------
board/sifive/unmatched/unmatched.c | 10 ----------
2 files changed, 21 deletions(-)
diff --git a/board/sifive/unleashed/unleashed.c b/board/sifive/unleashed/unleashed.c
index c1c374610c3..f5da289b836 100644
--- a/board/sifive/unleashed/unleashed.c
+++ b/board/sifive/unleashed/unleashed.c
@@ -114,17 +114,6 @@ int misc_init_r(void)
#endif
-int board_fdt_blob_setup(void **fdtp)
-{
- if (gd->arch.firmware_fdt_addr) {
- *fdtp = (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
-
- return 0;
- }
-
- return -EEXIST;
-}
-
int board_init(void)
{
/* enable all cache ways */
diff --git a/board/sifive/unmatched/unmatched.c b/board/sifive/unmatched/unmatched.c
index 23e03e145ee..a57ce1f10fe 100644
--- a/board/sifive/unmatched/unmatched.c
+++ b/board/sifive/unmatched/unmatched.c
@@ -10,16 +10,6 @@
#include <dm.h>
#include <asm/sections.h>
-int board_fdt_blob_setup(void **fdtp)
-{
- if (gd->arch.firmware_fdt_addr) {
- *fdtp = (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
- return 0;
- }
-
- return -EEXIST;
-}
-
int board_init(void)
{
/* enable all cache ways */
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
@ 2025-03-25 3:43 ` Leo Liang
2025-03-25 10:08 ` Leo Liang
2025-04-25 8:19 ` Leo Liang
2 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-03-25 3:43 UTC (permalink / raw)
To: Yao Zi
Cc: Rick Chen, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt, u-boot
On Fri, Mar 07, 2025 at 01:13:41PM +0000, Yao Zi wrote:
> 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>
> ---
> arch/riscv/lib/Makefile | 1 +
> arch/riscv/lib/board.c | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 arch/riscv/lib/board.c
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
2025-03-25 3:43 ` Leo Liang
@ 2025-03-25 10:08 ` Leo Liang
2025-04-25 8:19 ` Leo Liang
2 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-03-25 10:08 UTC (permalink / raw)
To: Yao Zi
Cc: Rick Chen, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt, u-boot
Hi Yao,
On Fri, Mar 07, 2025 at 01:13:41PM +0000, Yao Zi wrote:
> 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 | 1 +
> arch/riscv/lib/board.c | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 arch/riscv/lib/board.c
>
> diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
> index 268116f3757..b33f9c646dd 100644
> --- a/arch/riscv/lib/Makefile
> +++ b/arch/riscv/lib/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_$(XPL_)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
> index 00000000000..1630355b2b1
> --- /dev/null
> +++ b/arch/riscv/lib/board.c
> @@ -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 (IS_ENABLED(CONFIG_XPL_BUILD) || !gd->arch.firmware_fdt_addr)
> + return -EEXIST;
We don't need this check "CONFIG_XPL_BUILD", do we?
We do need this setup function for SPL and adding this would fail CI test.
> +
> + *fdtp = (void *)gd->arch.firmware_fdt_addr;
We should add proper casting to suppress compile warning for 32 bit.
Best regards,
Leo
> +
> + return 0;
> +}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
2025-03-25 3:43 ` Leo Liang
2025-03-25 10:08 ` Leo Liang
@ 2025-04-25 8:19 ` Leo Liang
2 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-04-25 8:19 UTC (permalink / raw)
To: Yao Zi
Cc: Rick Chen, Tom Rini, Bin Meng, Paul Walmsley, Palmer Dabbelt,
Anup Patel, Atish Patra, Green Wan, Minda Chen, Simon Glass,
Angelo Dureghello, Ilias Apalodimas, Heinrich Schuchardt, u-boot
Hi Yao,
On Fri, Mar 07, 2025 at 01:13:41PM +0000, Yao Zi wrote:
> 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 | 1 +
> arch/riscv/lib/board.c | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 arch/riscv/lib/board.c
>
> diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
> index 268116f3757..b33f9c646dd 100644
> --- a/arch/riscv/lib/Makefile
> +++ b/arch/riscv/lib/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_$(XPL_)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
> index 00000000000..1630355b2b1
> --- /dev/null
> +++ b/arch/riscv/lib/board.c
> @@ -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 (IS_ENABLED(CONFIG_XPL_BUILD) || !gd->arch.firmware_fdt_addr)
> + return -EEXIST;
> +
> + *fdtp = (void *)gd->arch.firmware_fdt_addr;
I could fix the 'CONFIG_XPL_BUILD' check and add casting when merging.
Thanks for the patch!
Best regards,
Leo
> +
> + return 0;
> +}
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-04-25 8:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07 13:13 [PATCH v2 0/4] Simplify retrieving FDT from SBI in S-Mode Yao Zi
2025-03-07 13:13 ` [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup Yao Zi
2025-03-25 3:43 ` Leo Liang
2025-03-25 10:08 ` Leo Liang
2025-04-25 8:19 ` Leo Liang
2025-03-07 13:13 ` [PATCH v2 2/4] board: qemu: riscv: Remove duplicated board_fdt_blob_setup Yao Zi
2025-03-07 13:13 ` [PATCH v2 3/4] board: starfive: " Yao Zi
2025-03-07 13:13 ` [PATCH v2 4/4] board: sifive: Remove dead board_fdt_blob_setup Yao Zi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox