mbox series

[0/5] Simplifiy retrieving FDT from SBI in S-Mode

Message ID 20250227144734.61458-1-ziyao@disroot.org
Headers show
Series Simplifiy retrieving FDT from SBI in S-Mode | expand

Message

Yao Zi Feb. 27, 2025, 2:47 p.m. UTC
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. We also select OF_HAS_PRIOR_STAGE by default on RISC-V
platforms if SBI is enabled, which is the usual configuration.

Tested on
 - Milk-V Duo (milkv_duo_defconfig)
 - Starfive VisionFive 2 (starfive_visionfive2_defconfig)
 - QEMU VM (qemu-riscv64_smode_defconfig).

Yao Zi (5):
  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 duplicated board_fdt_blob_setup
  riscv: select OF_HAS_PRIOR_STAGE by default if SBI is enabled

 arch/riscv/Kconfig                            |  1 +
 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 ----------
 7 files changed, 21 insertions(+), 39 deletions(-)
 create mode 100644 arch/riscv/lib/board.c