[PATCH v2 1/4] riscv: lib: Add a default implementation of board_fdt_blob_setup

Leo Liang ycliang at andestech.com
Tue Mar 25 11:08:59 CET 2025


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 at disroot.org>
> Reviewed-by: Leo Yu-Chi Liang <ycliang at 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;
> +}


More information about the U-Boot mailing list