From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, mtr@pengutronix.de
Subject: [RFC PATCH 00/17] Switch RISC-V to declarative entry points
Date: Tue, 27 Oct 2026 08:24:33 +0100 [thread overview]
Message-ID: <20261027074014.3280396-1-a.fatoum@barebox.org> (raw)
Every board currently open-codes its PBL entry point: set up the stack,
relocate, call setup_c(), do the lowlevel init and so on, all in C code
that runs before the C environment is ready.
This is error-prone, because board code authors need to be aware of some
very subtle details: global_variable_offset vs get_runtime_offset,
not accessing global variables before relocation, using noinline
functions as compiler barriers, no spilling to stack when ENTRY_FUNCTION
is used with no stack set up...
For the last point, we already had a solution in the form of
ENTRY_FUNCTION_WITHSTACK, which takes a stack pointer and places it
into a well-known location that a generic assembly entry point can read
and use to set up the stack before branching into C code.
That approach is not generic enough however: It only accepts a single
stack pointer when we really want one per execution level and even on
ARM32, it's still implemented using __naked, which precludes use with
clang as clang doesn't allow arbitrary C code there.
Address all of this by generalizing the idea behind
ENTRY_FUNCTION_WITHSTACK into a new ENTRY_POINT macro:
Instead of a board having one board-specific entry point function and a
single stack, it now has a struct of different callbacks and metadata:
struct pbl_stage {
unsigned long stacktop; /* stack top or PBL_STACKTOP_* */
unsigned long relocaddr; /* 0: don't relocate to specific addr */
/*
* Memory the stage runs from: barebox proper starts out with
* mem_minsz, mem_maxsz (default: mem_minsz) is only used to find
* the stage by PC.
*/
unsigned long mem_start;
unsigned long mem_minsz;
unsigned long mem_maxsz;
void *board_data;
pbl_board_fn_t prereloc_cpu_init;
pbl_board_fn_t soc_init;
void (*board_init)(unsigned long entry_data);
void (*soc_chainload)(void *board_data);
};
struct pbl_board_info {
unsigned int soc_type; /* see pbl_set_soc_type() */
/* Called without a stack, so it must not spill */
pbl_locate_pc_fn_t assembly_locate_pc;
struct pbl_stage rom_stage; /* PBL_STAGE_ROM */
struct pbl_stage first_stage; /* PBL_STAGE_OCRAM */
struct pbl_stage second_stage; /* PBL_STAGE_DRAM */
};
A board can now fill this out, define its own callbacks. Common
functionality like the soc_chainload can be shared between boards of the
same SoC. The hairy parts that can not be robustly done in C can be
defined declaratively as data that will be acted upon by the assembly
code. Code that must be written in assembly or run pre-relocation is
explicitly marked as such.
This can get quite verbose, so the idea is that SoC support will define
a macro with DEFAULTS that fills out the common bits that can be
extended (and overridden if needed) by the board code. See the last few
patches for how this looks like.
To make discussion easier, I am switching over all of RISC-V first in
this series. If we reach consensus and this is merged, I will follow-up
by doing the same on ARM.
This applies on top of next (PR #93 is prerequisite)
Ahmad Fatoum (17):
asm-generic: add registers.h with a pc_inside() helper
RISC-V: add call_with_stack() helper
RISC-V: implement relocate_to_adr_full()
PBL: add SoC type declaration and handoff support
PBL: introduce board info based entry point framework
PBL: describe the console in the board info and report the stage
RISC-V: make barebox_riscv_entry() non-naked
RISC-V: add PBL heads for the board info stage dispatch
RISC-V: board-dt-2nd: migrate to board info entry point
RISC-V: hifive: migrate to board info entry point
RISC-V: allow relocating the PBL more than once
RISC-V: nmon: preserve s1-s3 for the caller
RISC-V: beaglev: migrate to board info entry point
RISC-V: allwinner-d1: migrate to board info entry point
RISC-V: erizo: migrate to board info entry point
RISC-V: litex-linux: migrate to board info entry point
Documentation: porting: describe the board info entry point
Documentation/devel/porting.rst | 124 +++++++++++-
Documentation/devel/troubleshooting.rst | 6 +
arch/Kconfig | 28 +++
arch/riscv/Kconfig | 2 +
arch/riscv/boards/allwinner-d1/lowlevel.c | 18 +-
arch/riscv/boards/beaglev/lowlevel.c | 30 ++-
arch/riscv/boards/erizo/lowlevel.c | 32 +--
arch/riscv/boards/hifive/lowlevel.c | 30 +--
arch/riscv/boards/litex-linux/lowlevel.c | 30 +--
arch/riscv/boot/Makefile | 4 +-
arch/riscv/boot/board-dt-2nd-head.S | 36 ++++
arch/riscv/boot/board-dt-2nd.c | 89 ++++-----
arch/riscv/boot/entry.c | 33 +---
arch/riscv/boot/entry_ll.S | 15 ++
arch/riscv/boot/head.S | 198 +++++++++++++++++++
arch/riscv/boot/nmon_entry.S | 7 +
arch/riscv/include/asm/barebox-riscv.h | 36 +++-
arch/riscv/include/asm/reloc.h | 1 +
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/asm-offsets.c | 27 +++
arch/riscv/lib/call_with_stack.S | 12 ++
arch/riscv/lib/pbl.lds.S | 13 +-
arch/riscv/lib/reloc.c | 6 +-
arch/riscv/lib/setupc.S | 16 +-
include/asm-generic/registers.h | 33 ++++
include/linux/compiler-clang.h | 21 ++
include/linux/compiler-gcc.h | 3 +
include/linux/compiler_types.h | 10 +
include/mach/sifive/entry.h | 32 +++
include/pbl.h | 6 +
include/pbl/entry.h | 175 ++++++++++++++++
include/pbl/handoff-data.h | 15 ++
include/pbl/soc-type.h | 170 ++++++++++++++++
pbl/Makefile | 2 +
pbl/entry.c | 230 ++++++++++++++++++++++
pbl/handoff-data.c | 2 +
pbl/soc-type.c | 71 +++++++
37 files changed, 1418 insertions(+), 146 deletions(-)
create mode 100644 arch/riscv/boot/board-dt-2nd-head.S
create mode 100644 arch/riscv/boot/entry_ll.S
create mode 100644 arch/riscv/boot/head.S
create mode 100644 arch/riscv/lib/call_with_stack.S
create mode 100644 include/asm-generic/registers.h
create mode 100644 include/mach/sifive/entry.h
create mode 100644 include/pbl/entry.h
create mode 100644 include/pbl/soc-type.h
create mode 100644 pbl/entry.c
create mode 100644 pbl/soc-type.c
--
2.47.3
next reply other threads:[~2026-10-27 7:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 7:24 Ahmad Fatoum [this message]
2026-10-27 7:24 ` [RFC PATCH 01/17] asm-generic: add registers.h with a pc_inside() helper Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 02/17] RISC-V: add call_with_stack() helper Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 03/17] RISC-V: implement relocate_to_adr_full() Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 04/17] PBL: add SoC type declaration and handoff support Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 05/17] PBL: introduce board info based entry point framework Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 06/17] PBL: describe the console in the board info and report the stage Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 07/17] RISC-V: make barebox_riscv_entry() non-naked Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 08/17] RISC-V: add PBL heads for the board info stage dispatch Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 09/17] RISC-V: board-dt-2nd: migrate to board info entry point Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 10/17] RISC-V: hifive: " Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 11/17] RISC-V: allow relocating the PBL more than once Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 12/17] RISC-V: nmon: preserve s1-s3 for the caller Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 13/17] RISC-V: beaglev: migrate to board info entry point Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 14/17] RISC-V: allwinner-d1: " Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 15/17] RISC-V: erizo: " Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 16/17] RISC-V: litex-linux: " Ahmad Fatoum
2026-10-27 7:24 ` [RFC PATCH 17/17] Documentation: porting: describe the " Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027074014.3280396-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=mfe@pengutronix.de \
--cc=mtr@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox