From 52dc7ae74918d01fa55ca103841a0eaa0dfa7409 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Tue, 18 Aug 2020 01:09:20 -0700 Subject: [PATCH 1/6] riscv: fu540: Use correct API to get L2 cache controller base address At present fdtdec_get_addr() is used to get L2 cache controller base address. This only works for a fixed #address-cells and #size-cells. Change to use fdtdec_get_addr_size_auto_parent() instead. Signed-off-by: Bin Meng Reviewed-by: Rick Chen Reviewed-by: Pragnesh Patel --- arch/riscv/cpu/fu540/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/cpu/fu540/cache.c b/arch/riscv/cpu/fu540/cache.c index 54de14238cc..78f5ad9d602 100644 --- a/arch/riscv/cpu/fu540/cache.c +++ b/arch/riscv/cpu/fu540/cache.c @@ -35,7 +35,8 @@ int cache_enable_ways(void) if (node < 0) return node; - base = fdtdec_get_addr(blob, node, "reg"); + base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0, + NULL, false); if (base == FDT_ADDR_T_NONE) return FDT_ADDR_T_NONE; From 3ab260105214d56a419c84e6dacbb8ae514548f1 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Tue, 18 Aug 2020 01:09:21 -0700 Subject: [PATCH 2/6] ram: sifive: Fix compiler warnings for 32-bit priv->info.size is of type 'size_t' but the length modifier is l. Fix this by casting priv->info.size. Note 'z' cannot be used as the modifier as SPL does not support that. Signed-off-by: Bin Meng Reviewed-by: Rick Chen Reviewed-by: Pragnesh Patel --- drivers/ram/sifive/fu540_ddr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ram/sifive/fu540_ddr.c b/drivers/ram/sifive/fu540_ddr.c index 2eef1e75658..5ff88692a81 100644 --- a/drivers/ram/sifive/fu540_ddr.c +++ b/drivers/ram/sifive/fu540_ddr.c @@ -316,12 +316,12 @@ static int fu540_ddr_setup(struct udevice *dev) priv->info.size = get_ram_size((long *)priv->info.base, ddr_size); - debug("%s : %lx\n", __func__, priv->info.size); + debug("%s : %lx\n", __func__, (uintptr_t)priv->info.size); /* check memory access for all memory */ if (priv->info.size != ddr_size) { printf("DDR invalid size : 0x%lx, expected 0x%lx\n", - priv->info.size, (uintptr_t)ddr_size); + (uintptr_t)priv->info.size, (uintptr_t)ddr_size); return -EINVAL; } From 183f1e27123769c41b3a73b92839497d4812f790 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 28 Jul 2020 17:52:23 +0200 Subject: [PATCH 3/6] clk: kendryte/pll.h: do not redefine nop() The kendryte PLL code uses nop as barrier. The macro is not defined for the sandbox on x86 but is defined on RISC-V. Signed-off-by: Heinrich Schuchardt Reviewed-by: Sean Anderson Reviewed-by: Bin Meng --- include/kendryte/pll.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/kendryte/pll.h b/include/kendryte/pll.h index c8e3200799e..55a40b9c979 100644 --- a/include/kendryte/pll.h +++ b/include/kendryte/pll.h @@ -7,6 +7,7 @@ #include #include +#include #define K210_PLL_CLKR GENMASK(3, 0) #define K210_PLL_CLKF GENMASK(9, 4) @@ -43,9 +44,13 @@ struct k210_pll_config { #ifdef CONFIG_UNIT_TEST TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, struct k210_pll_config *best); + +#ifndef nop #define nop() #endif +#endif + extern const struct clk_ops k210_pll_ops; struct clk *k210_register_pll_struct(const char *name, const char *parent_name, From 092f15aee5bdebc010ad99120bab96162d9c64c8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Aug 2020 09:49:26 +0200 Subject: [PATCH 4/6] riscv: fix building with CONFIG_SPL_SMP=n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building with CONFIG_SPL_SMP=n results in: arch/riscv/lib/spl.c: In function ‘jump_to_image_no_args’: arch/riscv/lib/spl.c:33:6: error: unused variable ‘ret’ [-Werror=unused-variable] 33 | int ret; | ^~~ Define the variable ret as __maybe_unused. Fixes: 191636e44898 ("riscv: Introduce SPL_SMP Kconfig option for U-Boot SPL") Fixes: 8c59f2023cc8 ("riscv: add SPL support") Signed-off-by: Heinrich Schuchardt Reviewed-by: Bin Meng Reviewed-by: Simon Glass Reviewed-by: Rick Chen Reviewed-by: Pragnesh Patel --- arch/riscv/lib/spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/lib/spl.c b/arch/riscv/lib/spl.c index e24ec5a46c0..5e19d0f36ab 100644 --- a/arch/riscv/lib/spl.c +++ b/arch/riscv/lib/spl.c @@ -39,7 +39,7 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) { typedef void __noreturn (*image_entry_riscv_t)(ulong hart, void *dtb); void *fdt_blob; - int ret; + __maybe_unused int ret; #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL) fdt_blob = spl_image->fdt_addr; From 27cef4e4a3ba791078534fda1dbeb814bd530ad5 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 17 Aug 2020 12:35:39 +0200 Subject: [PATCH 5/6] configs: defconfig for Sipeed Maix in S-mode Provide a defconfig that can be used to build U-Boot for the Maix boards running upon OpenSBI. Update the documentation. Signed-off-by: Heinrich Schuchardt Reviewed-by: Bin Meng Reviewed-by: Sean Anderson --- board/sipeed/maix/MAINTAINERS | 2 +- configs/sipeed_maix_smode_defconfig | 10 ++++++ doc/board/sipeed/maix.rst | 49 +++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 configs/sipeed_maix_smode_defconfig diff --git a/board/sipeed/maix/MAINTAINERS b/board/sipeed/maix/MAINTAINERS index e7bb9ec4330..0778af7a552 100644 --- a/board/sipeed/maix/MAINTAINERS +++ b/board/sipeed/maix/MAINTAINERS @@ -4,7 +4,7 @@ S: Maintained F: arch/riscv/dts/k210.dtsi F: arch/riscv/dts/k210-maix-bit.dts F: board/sipeed/maix/ -F: configs/sipeed_maix_bitm_defconfig +F: configs/sipeed_maix*_defconfig F: doc/board/sipeed/ F: include/configs/sipeed-maix.h F: include/dt-bindings/*/k210-sysctl.h diff --git a/configs/sipeed_maix_smode_defconfig b/configs/sipeed_maix_smode_defconfig new file mode 100644 index 00000000000..2516bb72582 --- /dev/null +++ b/configs/sipeed_maix_smode_defconfig @@ -0,0 +1,10 @@ +CONFIG_RISCV=y +CONFIG_SYS_TEXT_BASE=0x80020000 +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_ARCH_RV64I=y +CONFIG_RISCV_SMODE=y +CONFIG_STACK_SIZE=0x100000 +# CONFIG_NET is not set +# CONFIG_INPUT is not set +# CONFIG_DM_ETH is not set +# CONFIG_EFI_UNICODE_CAPITALIZATION is not set diff --git a/doc/board/sipeed/maix.rst b/doc/board/sipeed/maix.rst index b1894f3a6fa..efcde9aebf7 100644 --- a/doc/board/sipeed/maix.rst +++ b/doc/board/sipeed/maix.rst @@ -75,6 +75,49 @@ console shall be opened immediately. Boot output should look like the following: Err: serial@38000000 => +OpenSBI +^^^^^^^ + +OpenSBI is an open source supervisor execution environment implementing the +RISC-V Supervisor Binary Interface Specification [1]. One of its features is +to intercept run-time exceptions, e.g. for unaligned access or illegal +instructions, and to emulate the failing instructions. + +The OpenSBI source can be downloaded via: + +.. code-block:: bash + + git clone https://github.com/riscv/opensbi + +As OpenSBI will be loaded at 0x80000000 we have to adjust the U-Boot text base. +Furthermore we have to enable building U-Boot for S-mode:: + + CONFIG_SYS_TEXT_BASE=0x80020000 + CONFIG_RISCV_SMODE=y + +Both settings are contained in sipeed_maix_smode_defconfig so we can build +U-Boot with: + +.. code-block:: bash + + make sipeed_maix_smode_defconfig + make + +To build OpenSBI with U-Boot as a payload: + +.. code-block:: bash + + cd opensbi + make \ + PLATFORM=kendryte/k210 \ + FW_PAYLOAD=y \ + FW_PAYLOAD_OFFSET=0x20000 \ + FW_PAYLOAD_PATH=/u-boot-dtb.bin + +The value of FW_PAYLOAD_OFFSET must match CONFIG_SYS_TEXT_BASE - 0x80000000. + +The file to flash is build/platform/kendryte/k210/firmware/fw_payload.bin. + Loading Images ^^^^^^^^^^^^^^ @@ -363,3 +406,9 @@ Address Size Description interrupts) 0x8801f000 0x1000 credits ========== ========= =========== + +Links +----- + +[1] https://github.com/riscv/riscv-sbi-doc + RISC-V Supervisor Binary Interface Specification From c92b50a44b95e706b9c0c97544bd7504fe6d36e9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 20 Aug 2020 19:43:39 +0200 Subject: [PATCH 6/6] cmd: provide command sbi Provide a command to display information about the SBI implementation. The output might look like: => sbi SBI 0.2 OpenSBI Extensions: sbi_set_timer sbi_console_putchar sbi_console_getchar sbi_clear_ipi sbi_send_ipi sbi_remote_fence_i sbi_remote_sfence_vma sbi_remote_sfence_vma_asid sbi_shutdown SBI Base Functionality Timer Extension IPI Extension RFENCE Extension Hart State Management Extension The command can be used to construct a unit test checking that the communication with the SEE is working. Signed-off-by: Heinrich Schuchardt Reviewed-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Pragnesh Patel Tested-by: Pragnesh Patel Reviewed-by: Rick Chen Tested-by: Rick Chen --- arch/riscv/include/asm/sbi.h | 2 + arch/riscv/lib/sbi.c | 36 ++++++++++++++++ cmd/Kconfig | 6 +++ cmd/riscv/Makefile | 1 + cmd/riscv/sbi.c | 82 ++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 cmd/riscv/sbi.c diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 08e1ac0c0e2..53ca316180e 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -115,6 +115,8 @@ void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long asid); #endif void sbi_set_timer(uint64_t stime_value); +long sbi_get_spec_version(void); +int sbi_get_impl_id(void); int sbi_probe_extension(int ext); #endif diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c index 8fbc23839dd..77845a73ca3 100644 --- a/arch/riscv/lib/sbi.c +++ b/arch/riscv/lib/sbi.c @@ -53,6 +53,42 @@ void sbi_set_timer(uint64_t stime_value) #endif } +/** + * sbi_get_spec_version() - get current SBI specification version + * + * Return: version id + */ +long sbi_get_spec_version(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION, + 0, 0, 0, 0, 0, 0); + if (!ret.error) + if (ret.value) + return ret.value; + + return -ENOTSUPP; +} + +/** + * sbi_get_impl_id() - get SBI implementation ID + * + * Return: implementation ID + */ +int sbi_get_impl_id(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_ID, + 0, 0, 0, 0, 0, 0); + if (!ret.error) + if (ret.value) + return ret.value; + + return -ENOTSUPP; +} + /** * sbi_probe_extension() - Check if an SBI extension ID is supported or not. * @extid: The extension ID to be probed. diff --git a/cmd/Kconfig b/cmd/Kconfig index 9ad511aa176..30c26b5d2bc 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -270,6 +270,12 @@ config SPL_CMD_TLV_EEPROM help Read system EEPROM data block in ONIE Tlvinfo format from SPL. +config CMD_SBI + bool "sbi" + depends on RISCV_SMODE && SBI_V02 + help + Display information about the SBI implementation. + endmenu menu "Boot commands" diff --git a/cmd/riscv/Makefile b/cmd/riscv/Makefile index 24df023ece9..1e6ac364e34 100644 --- a/cmd/riscv/Makefile +++ b/cmd/riscv/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-$(CONFIG_CMD_EXCEPTION) += exception.o +obj-$(CONFIG_CMD_SBI) += sbi.o diff --git a/cmd/riscv/sbi.c b/cmd/riscv/sbi.c new file mode 100644 index 00000000000..e66fc8e41d2 --- /dev/null +++ b/cmd/riscv/sbi.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'sbi' command displays information about the SBI implementation. + * + * Copyright (c) 2020, Heinrich Schuchardt + */ + +#include +#include +#include + +struct sbi_ext { + const u32 id; + const char *name; +}; + +static struct sbi_ext extensions[] = { + { 0x00000000, "sbi_set_timer" }, + { 0x00000001, "sbi_console_putchar" }, + { 0x00000002, "sbi_console_getchar" }, + { 0x00000003, "sbi_clear_ipi" }, + { 0x00000004, "sbi_send_ipi" }, + { 0x00000005, "sbi_remote_fence_i" }, + { 0x00000006, "sbi_remote_sfence_vma" }, + { 0x00000007, "sbi_remote_sfence_vma_asid" }, + { 0x00000008, "sbi_shutdown" }, + { 0x00000010, "SBI Base Functionality" }, + { 0x54494D45, "Timer Extension" }, + { 0x00735049, "IPI Extension" }, + { 0x52464E43, "RFENCE Extension" }, + { 0x0048534D, "Hart State Management Extension" }, +}; + +static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int i; + long ret; + + ret = sbi_get_spec_version(); + if (ret >= 0) + printf("SBI %ld.%ld\n", ret >> 24, ret & 0xffffff); + ret = sbi_get_impl_id(); + if (ret >= 0) { + switch (ret) { + case 0: + printf("Berkeley Boot Loader (BBL)\n"); + break; + case 1: + printf("OpenSBI\n"); + break; + case 2: + printf("Xvisor\n"); + break; + case 3: + printf("KVM\n"); + break; + default: + printf("Unknown implementation\n"); + break; + } + } + printf("Extensions:\n"); + for (i = 0; i < ARRAY_SIZE(extensions); ++i) { + ret = sbi_probe_extension(extensions[i].id); + if (ret > 0) + printf(" %s\n", extensions[i].name); + } + return 0; +} + +#ifdef CONFIG_SYS_LONGHELP +static char sbi_help_text[] = + "- display SBI spec version, implementation, and available extensions"; + +#endif + +U_BOOT_CMD_COMPLETE( + sbi, 1, 0, do_sbi, + "display SBI information", + sbi_help_text, NULL +);