Simplify retrieving FDT from SBI in S-Mode
Subsystems (2)
v2 cover Simplify retrieving FDT from SBI in S-Mode
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/[email protected]/
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
Signature · 1 line
2.48.1
PATCH v2 1/4 riscv: lib: Add a default implementation of board_fdt_blob_setup
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.
--- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/board.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 arch/riscv/lib/board.c
arch/riscv/lib/Makefile +1 -0
@@ -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
arch/riscv/lib/board.c new file +19 -0
@@ -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 ; +}
Signature · 1 line
2.48.1
Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
Quoted 11 lines · 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_setupto make use of it by default, avoiding copy-pasting similar functions among boards.Signed-off-by Yao Zi <[email protected]>--- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/board.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 arch/riscv/lib/board.c
Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
In reply to Yao ZiHi Yao,
Quoted 35 lines · 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_setupto make use of it by default, avoiding copy-pasting similar functions among boards.Signed-off-by Yao Zi <[email protected]>Reviewed-by Leo Yu-Chi Liang <[email protected]>--- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/board.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 arch/riscv/lib/board.carch/riscv/lib/Makefile +1
-0@@ -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-strongarch/riscv/lib/board.c new file +4
-0@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* RISC-V-specific handling of firmware FDT +*/
arch/riscv/lib/board.c line 14
Quoted 10 lines
arch/riscv/lib/board.c new file +10
-0+ +#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.
arch/riscv/lib/board.c line 16
Quoted 2 lines
arch/riscv/lib/board.c new file +2
-0+ + *fdtp = (void *)gd->arch.firmware_fdt_addr;
We should add proper casting to suppress compile warning for 32 bit.
Best regards,
Leo
Quoted 3 lines
arch/riscv/lib/board.c new file +3
-0+ +return 0 ; +}
Re: [PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup
In reply to Yao ZiHi Yao,
Quoted 37 lines · 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_setupto make use of it by default, avoiding copy-pasting similar functions among boards.Signed-off-by Yao Zi <[email protected]>Reviewed-by Leo Yu-Chi Liang <[email protected]>--- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/board.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 arch/riscv/lib/board.carch/riscv/lib/Makefile +1
-0@@ -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-strongarch/riscv/lib/board.c new file +6
-0@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* RISC-V-specific handling of firmware FDT +*/ + +#include <asm/global_data.h>
arch/riscv/lib/board.c line 16
Quoted 10 lines
arch/riscv/lib/board.c new file +10
-0+#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
Quoted 3 lines
arch/riscv/lib/board.c new file +3
-0+ +return 0 ; +}
PATCH v2 2/4 board: qemu: riscv: Remove duplicated board_fdt_blob_setup
In reply to Yao ZiThe default version should work for RISC-V QEMU.
--- board/emulation/qemu-riscv/qemu-riscv.c | 8 -------- 1 file changed, 8 deletions(-)
board/emulation/qemu-riscv/qemu-riscv.c +0 -8
@@ -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 ; -}
Signature · 1 line
2.48.1
PATCH v2 3/4 board: starfive: Remove duplicated board_fdt_blob_setup
In reply to Yao ZiThe default version should work for Starfive VisionFive 2.
--- board/starfive/visionfive2/starfive_visionfive2.c | 10 ---------- 1 file changed, 10 deletions(-)
board/starfive/visionfive2/starfive_visionfive2.c +0 -10
@@ -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);
Signature · 1 line
2.48.1
PATCH v2 4/4 board: sifive: Remove dead board_fdt_blob_setup
In reply to Yao ZiCONFIG_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.
--- board/sifive/unleashed/unleashed.c | 11 ----------- board/sifive/unmatched/unmatched.c | 10 ---------- 2 files changed, 21 deletions(-)
board/sifive/unleashed/unleashed.c +0 -11
@@ -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 */
board/sifive/unmatched/unmatched.c +0 -10
@@ -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 */
Signature · 1 line
2.48.1