riscv: spl: OpenSBI OS boot mode
cover riscv: spl: OpenSBI OS boot mode
Introduce a shortcut boot mode for RISC-V.
As we know, in ARM architecture has the Falcon mode to do the shortcut boot to the Linux kernel. (by enabling CONFIG_SPL_OS_BOOT) ARM Falcon mode boot flow would be as follows:
u-boot SPL -> Linux kernel
But for RISC-V, OpenSBI is required to allows the supervisor to execute some privileged operations.
The RISC-V Normal boot flow as follows:
u-boot SPL -> OpenSBI -> u-boot proper -> Linux kernel
Quoting the same ideas as ARM's Falcon mode,
OpenSBI OS boot flow as follows:
u-boot SPL -> OpenSBI -> Linux kernel
An important part of OpenSBI OS boot mode is to prepare the device tree. A normal U-Boot does FDT fixups when booting Linux.
For OpenSBI OS boot mode, Linux boots directly from SPL, skipping the normal U-Boot.
The device tree has to be prepared in advance.
The device tree in memory is the one needed for OpenSBI OS boot mode.
The Linux kernel image will also need to be provided for the generation of the FIT file.
Randolph (7):
riscv: dts: Introduce SPL_LOAD_FIT_CONFIG symbol
riscv: dts: add binman_linux.dtsi for opensbi os boot mode
spl: riscv: opensbi: change the default os_type as varible
riscv: dts: introduce SPL_LOAD_FIT_OPENSBI_OS_BOOT symbol
spl: riscv: add os type for next booting stage
andes: config: add riscv falcon mode for ae350 platform
riscv: spl: andes: Move the DTB in front of kernel
arch/riscv/Kconfig | 16 +++++ arch/riscv/dts/ae350-u-boot.dtsi | 1 + arch/riscv/dts/ae350_32.dts | 1 - arch/riscv/dts/ae350_64.dts | 1 - arch/riscv/dts/binman_linux.dtsi | 79 +++++++++++++++++++++++++ board/AndesTech/ae350/ae350.c | 25 ++++++++ common/spl/spl_fit.c | 4 ++ common/spl/spl_opensbi.c | 31 ++++++---- configs/ae350_rv32_falcon_defconfig | 60 +++++++++++++++++++ configs/ae350_rv32_falcon_xip_defconfig | 61 +++++++++++++++++++ configs/ae350_rv64_falcon_defconfig | 60 +++++++++++++++++++ configs/ae350_rv64_falcon_xip_defconfig | 61 +++++++++++++++++++ 12 files changed, 388 insertions(+), 12 deletions(-) create mode 100644 arch/riscv/dts/binman_linux.dtsi create mode 100644 configs/ae350_rv32_falcon_defconfig create mode 100644 configs/ae350_rv32_falcon_xip_defconfig create mode 100644 configs/ae350_rv64_falcon_defconfig create mode 100644 configs/ae350_rv64_falcon_xip_defconfig
Signature · 1 line
2.34.1
PATCH 1/7 riscv: dts: Introduce SPL_LOAD_FIT_CONFIG symbol
Introduce common Kconfig symbol for riscv architecture This symbol SPL_LOAD_FIT_CONFIG for binman itb layout selection Default is using binman.dtsi
--- arch/riscv/Kconfig | 7 +++++++ arch/riscv/dts/ae350-u-boot.dtsi | 1 + arch/riscv/dts/ae350_32.dts | 1 - arch/riscv/dts/ae350_64.dts | 1 - 4 files changed, 8 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +7 -0
@@ -422,4 +422,11 @@ config TPL_USE_ARCH_MEMSET endmenu +config SPL_LOAD_FIT_CONFIG + string "Default FIT configuration for SPL" + default "binman.dtsi" + depends on SPL_LOAD_FIT + help + Specify corresponding FIT configuration for SPL modes. + endmenu
arch/riscv/dts/ae350-u-boot.dtsi +1 -0
@@ -1,4 +1,5 @@ // SPDX-License-Identifier: (GPL-2.0 OR MIT) +#include CONFIG_SPL_LOAD_FIT_CONFIG / { cpus {
arch/riscv/dts/ae350_32.dts +0 -1
@@ -2,7 +2,6 @@ /dts-v1/; -#include "binman.dtsi" #include "ae350-u-boot.dtsi" / {
arch/riscv/dts/ae350_64.dts +0 -1
@@ -2,7 +2,6 @@ /dts-v1/; -#include "binman.dtsi" #include "ae350-u-boot.dtsi" / {
Signature · 1 line
2.34.1
PATCH 2/7 riscv: dts: add binman_linux.dtsi for opensbi os boot mode
In reply to RandolphThe binman_linux.dtsi is a fork of binman.dtsi, just change the first section image from the "u-boot" to "linux". Note that the filename is also changed. In binman.dtsi, the filename of u-boot section filename is called "u-boot-nodtb.bin". In binman_linux.dtsi, the filename should be called "Image", which is located in linux/arch/riscv/boot.
--- arch/riscv/dts/binman_linux.dtsi | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 arch/riscv/dts/binman_linux.dtsi
arch/riscv/dts/binman_linux.dtsi new file +79 -0
@@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021, Bin Meng <[email protected]> + */ + +#include <config.h> + +/ { + binman: binman { + multiple-images; + }; +}; + +&binman { + itb { + filename = "linux.itb"; + + fit { + description = "Configuration to load OpenSBI before Linux"; + #address-cells = <1>; + fit,fdt-list = "of-list"; + + images { + linux { + description = "Linux"; + type = "standalone"; + os = "Linux"; + arch = "riscv"; + compression = "none"; + load = <CONFIG_TEXT_BASE>; + + linux_blob: blob-ext { + filename = "Image"; + }; + }; + + opensbi { + description = "OpenSBI fw_dynamic Firmware"; + type = "firmware"; + os = "opensbi"; + arch = "riscv"; + compression = "none"; + load = <CONFIG_SPL_OPENSBI_LOAD_ADDR>; + entry = <CONFIG_SPL_OPENSBI_LOAD_ADDR>; + + opensbi_blob: opensbi { + filename = "fw_dynamic.bin"; + missing-msg = "opensbi"; + }; + }; + +#ifndef CONFIG_OF_BOARD + @fdt-SEQ { + description = "NAME"; + type = "flat_dt"; + compression = "none"; + }; +#endif + }; + + configurations { + default = "conf-1"; + +#ifndef CONFIG_OF_BOARD + @conf-SEQ { +#else + conf-1 { +#endif + description = "NAME"; + firmware = "opensbi"; + loadables = "linux"; +#ifndef CONFIG_OF_BOARD + fdt = "fdt-SEQ"; +#endif + }; + }; + }; + }; +};
Signature · 1 line
2.34.1
PATCH 3/7 spl: riscv: opensbi: change the default os_type as varible
In reply to RandolphIn order to introduce the Opensbi OS boot mode, the next stage boot image of OpenSBI should be configurable.
--- common/spl/spl_opensbi.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
common/spl/spl_opensbi.c +16 -10
@@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR;struct fw_dynamic_info opensbi_info; -static int spl_opensbi_find_uboot_node (void *blob,int *uboot_node) +static int spl_opensbi_find_os_node (void *blob,int *uboot_node,int os_type) {int fit_images_node, node;const char *fit_os;
@@ -34,7 +34,7 @@ static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)if (!fit_os)continue ; -if (genimg_get_os_id (fit_os) ==IH_OS_U_BOOT ) { +if (genimg_get_os_id (fit_os) == os_type) { *uboot_node = node;return 0 ; }
@@ -45,8 +45,9 @@ static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)void __noreturn spl_invoke_opensbi (struct spl_image_info *spl_image) { -int ret, uboot_node; -ulong uboot_entry; +int ret, os_node; +ulong os_entry; +int os_type;typedef void __noreturn (*opensbi_entry_t )(ulong hartid,ulong dtb,ulong info);opensbi_entry_t opensbi_entry;
@@ -55,22 +56,27 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)hang (); } -/* Find U-Boot image in /fit-images */ - ret =spl_opensbi_find_uboot_node (spl_image->fdt_addr, &uboot_node); +/* +* Find next os image in /fit-images +* The next os image default is u-boot proper +*/ + os_type =IH_OS_U_BOOT ; + ret =spl_opensbi_find_os_node (spl_image->fdt_addr, &os_node, os_type);if (ret) { -pr_err ("Can't find U-Boot node, %d\n" , ret); +pr_err ("Can't find %s node for opensbi, %d\n" , +genimg_get_os_name (os_type), ret);hang (); }/* Get U-Boot entry point */ - ret =fit_image_get_entry (spl_image->fdt_addr, uboot_node, &uboot_entry); + ret =fit_image_get_entry (spl_image->fdt_addr, os_node, &os_entry);if (ret) - ret =fit_image_get_load (spl_image->fdt_addr, uboot_node, &uboot_entry); + ret =fit_image_get_load (spl_image->fdt_addr, os_node, &os_entry);/* Prepare opensbi_info object */ opensbi_info.magic =FW_DYNAMIC_INFO_MAGIC_VALUE ; opensbi_info.version =FW_DYNAMIC_INFO_VERSION ; - opensbi_info.next_addr = uboot_entry; + opensbi_info.next_addr = os_entry; opensbi_info.next_mode =FW_DYNAMIC_INFO_NEXT_MODE_S ; opensbi_info.options =CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS ; opensbi_info.boot_hart = gd->arch.boot_hart;
Signature · 1 line
2.34.1
PATCH 4/7 riscv: dts: introduce SPL_LOAD_FIT_OPENSBI_OS_BOOT symbol
In reply to RandolphIntroduce common Kconfig symbol for riscv architecture. This symbol SPL_LOAD_FIT_OPENSBI_OS_BOOT is like falcon mode on ARM, the Falcon boot is a shortcut boot method for SD/eMMC targets. It skips the loading the RAM version U-Boot. Instead, it will loads the FIT image and boots directly to Linux.
When SPL_OPENSBI_OS_BOOT is enabled, linux.itb is created after compilation instead of the default u-boot.itb. It initialises memory with the U-Boot SPL at the first stage, just as a normal boot process does at the beginning. Instead of jumping to the U-Boot proper from OpenSBI before booting the Linux kernel, the RISC-V falcon mode process jumps directly to the Linux kernel to gain shorter booting time.
When SPL_OPENSBI_OS_BOOT is enabled, it will change the default FIT configure file "binman.dtsi" to "binman_linux.dtsi" Default is not enabled.
--- arch/riscv/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/riscv/Kconfig +9 -0
@@ -422,8 +422,17 @@ config TPL_USE_ARCH_MEMSET endmenu +config SPL_LOAD_FIT_OPENSBI_OS_BOOT + bool "Enable SPL (OpenSBI OS boot mode) applying linux from FIT" + depends on SPL_LOAD_FIT + help + Use fw_dynamic from the FIT image, and u-boot SPL will invoke it directly. + This is a shortcut boot flow, from u-boot SPL -> OpenSBI -> u-boot proper + -> linux to u-boot SPL -> OpenSBI -> linux. + config SPL_LOAD_FIT_CONFIG string "Default FIT configuration for SPL" + default "binman_linux.dtsi" if SPL_LOAD_FIT_OPENSBI_OS_BOOT default "binman.dtsi" depends on SPL_LOAD_FIT help
Signature · 1 line
2.34.1
PATCH 5/7 spl: riscv: add os type for next booting stage
In reply to RandolphIf SPL_LOAD_FIT_OPENSBI_OS_BOOT is enabled, the function spl_invoke_opensbi should change the target OS type to IH_OS_LINUX. OpenSBI will load the Linux image as the next boot stage. The os_takes_devicetree function returns a value of true or false depending on whether or not SPL_LOAD_FIT_OPENSBI_OS_BOOT is enabled.
--- common/spl/spl_fit.c | 4 ++++ common/spl/spl_opensbi.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
common/spl/spl_fit.c +4 -0
@@ -351,7 +351,11 @@ static bool os_takes_devicetree(uint8_t os)case IH_OS_U_BOOT :return true;case IH_OS_LINUX : +#ifdef CONFIG_RISCV +return IS_ENABLED (CONFIG_SPL_LOAD_FIT_OPENSBI_OS_BOOT ); +#else return IS_ENABLED (CONFIG_SPL_OS_BOOT ); +#endif default :return false; }
common/spl/spl_opensbi.c +6 -1
@@ -58,9 +58,14 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)/* * Find next os image in /fit-images -* The next os image default is u-boot proper +* The next os image default is u-boot proper, once enable +* OpenSBI OS boot mode, the OS image should be linux. */ +#if CONFIG_IS_ENABLED (LOAD_FIT_OPENSBI_OS_BOOT ) + os_type =IH_OS_LINUX ; +#else os_type =IH_OS_U_BOOT ; +#endif ret =spl_opensbi_find_os_node (spl_image->fdt_addr, &os_node, os_type);if (ret) { pr_err("Can't find %s node for opensbi, %d\n",
Signature · 1 line
2.34.1
PATCH 6/7 andes: config: add riscv falcon mode for ae350 platform
In reply to RandolphFork from ae350_rv[32/64]_spl_[xip]_defconfig and
append CONFIG_SPL_LOAD_FIT_OPENSBI_OS_BOOT=y
--- configs/ae350_rv32_falcon_defconfig | 60 ++++++++++++++++++++++++ configs/ae350_rv32_falcon_xip_defconfig | 61 +++++++++++++++++++++++++ configs/ae350_rv64_falcon_defconfig | 60 ++++++++++++++++++++++++ configs/ae350_rv64_falcon_xip_defconfig | 61 +++++++++++++++++++++++++ 4 files changed, 242 insertions(+) create mode 100644 configs/ae350_rv32_falcon_defconfig create mode 100644 configs/ae350_rv32_falcon_xip_defconfig create mode 100644 configs/ae350_rv64_falcon_defconfig create mode 100644 configs/ae350_rv64_falcon_xip_defconfig
configs/ae350_rv32_falcon_defconfig new file +60 -0
@@ -0,0 +1,60 @@ +CONFIG_RISCV=y +CONFIG_TEXT_BASE=0x01800000 +CONFIG_SYS_MALLOC_LEN=0x80000 +CONFIG_NR_DRAM_BANKS=2 +CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y +CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x10000000 +CONFIG_ENV_SECT_SIZE=0x1000 +CONFIG_DEFAULT_DEVICE_TREE="ae350_32" +CONFIG_SYS_PROMPT="RISC-V # " +CONFIG_SYS_MONITOR_LEN=786432 +CONFIG_SPL_SYS_MALLOC_F_LEN=0x2000000 +CONFIG_SPL=y +CONFIG_SYS_LOAD_ADDR=0x100000 +CONFIG_TARGET_ANDES_AE350=y +CONFIG_RISCV_SMODE=y +# CONFIG_AVAILABLE_HARTS is not set +CONFIG_FIT=y +CONFIG_SPL_LOAD_FIT_ADDRESS=0x10000000 +CONFIG_SYS_MONITOR_BASE=0x88000000 +CONFIG_DISTRO_DEFAULTS=y +CONFIG_BOOTDELAY=3 +CONFIG_DISPLAY_CPUINFO=y +CONFIG_DISPLAY_BOARDINFO=y +CONFIG_BOARD_EARLY_INIT_F=y +CONFIG_SPL_MAX_SIZE=0x100000 +CONFIG_SPL_BSS_START_ADDR=0x400000 +CONFIG_SPL_BOARD_INIT=y +CONFIG_SPL_CACHE=y +CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0 +CONFIG_SYS_PBSIZE=1050 +CONFIG_SYS_BOOTM_LEN=0x4000000 +CONFIG_CMD_IMLS=y +CONFIG_CMD_MMC=y +CONFIG_CMD_SF_TEST=y +# CONFIG_CMD_SETEXPR is not set +CONFIG_BOOTP_PREFER_SERVERIP=y +CONFIG_CMD_CACHE=y +CONFIG_ENV_OVERWRITE=y +CONFIG_ENV_IS_IN_SPI_FLASH=y +CONFIG_NET_RETRY_COUNT=50 +CONFIG_BOOTP_SEND_HOSTNAME=y +CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_MMC=y +CONFIG_FTSDC010=y +CONFIG_FTSDC010_SDIO=y +CONFIG_MTD_NOR_FLASH=y +CONFIG_FLASH_CFI_DRIVER=y +CONFIG_SYS_FLASH_CFI_WIDTH_16BIT=y +CONFIG_FLASH_SHOW_PROGRESS=0 +CONFIG_SYS_CFI_FLASH_STATUS_POLL=y +CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y +CONFIG_SYS_FLASH_CFI=y +CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_FTMAC100=y +CONFIG_BAUDRATE=38400 +CONFIG_SYS_NS16550=y +CONFIG_SPI=y +CONFIG_ATCSPI200_SPI=y +# CONFIG_BINMAN_FDT is not set +CONFIG_SPL_LOAD_FIT_OPENSBI_OS_BOOT=y
configs/ae350_rv32_falcon_xip_defconfig new file +61 -0
62 lines not on this page · raw message
configs/ae350_rv64_falcon_defconfig new file +60 -0
61 lines not on this page · raw message
configs/ae350_rv64_falcon_xip_defconfig new file +61 -0
62 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/7 riscv: spl: andes: Move the DTB in front of kernel
In reply to RandolphOriginally, u-boot SPL will place the DTB directly after the kernel, but the size of the kernel does not include the BSS section, This means that u-boot SPL places the DTB in the kernel BSS section causing the DTB to be cleared by the kernel BSS initialisation.
Moving the DTB in front of the kernel can avoid this error.
--- board/AndesTech/ae350/ae350.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
board/AndesTech/ae350/ae350.c +25 -0
@@ -19,6 +19,8 @@#include <fdtdec.h> #include <dm.h> #include <spl.h> +#include <mapmem.h> +#include <hang.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -26,6 +28,29 @@ DECLARE_GLOBAL_DATA_PTR;* Miscellaneous platform dependent initializations */ +#if CONFIG_IS_ENABLED (LOAD_FIT ) ||CONFIG_IS_ENABLED (LOAD_FIT_FULL ) +#define ANDES_SPL_FDT_ADDR (CONFIG_TEXT_BASE - 0x100000) +void spl_perform_fixups (struct spl_image_info *spl_image) +{ +/* +* Originally, u-boot-spl will place DTB directly after the kernel, +* but the size of the kernel did not include the BSS section, which +* means u-boot-spl will place the DTB in the kernel BSS section +* causing the DTB to be cleared by kernel BSS initializtion. +* Moving DTB in front of the kernel can avoid the error. +*/ +if (ANDES_SPL_FDT_ADDR <0 ) { +printf ("%s: CONFIG_TEXT_BASE needs to be larger than 0x100000\n" , + __func__); +hang (); + } + +memcpy ((void *)ANDES_SPL_FDT_ADDR , spl_image->fdt_addr, +fdt_totalsize (spl_image->fdt_addr)); + spl_image->fdt_addr =map_sysmem (ANDES_SPL_FDT_ADDR ,0 ); +} +#endif +int board_init (void ) { gd->bd->bi_boot_params =PHYS_SDRAM_0 +0x400 ;
Signature · 1 line
2.34.1