From 1600f2058ea3c199673a8bebe498a6a1372fd2b9 Mon Sep 17 00:00:00 2001 From: Inochi Amaoto Date: Thu, 16 Apr 2026 10:15:51 +0800 Subject: [PATCH 1/5] buildroot: Update to latest OpenSBI Signed-off-by: Inochi Amaoto --- buildroot/Config.in | 1 - buildroot/README.md | 7 +- .../boards/naxriscv_sim/linux/linux_raw.dts | 91 +++--- .../boards/naxriscv_sim/opensbi/config_raw.mk | 30 -- .../boards/naxriscv_sim/opensbi/objects.mk | 12 - .../boards/naxriscv_sim/opensbi/platform.c | 156 ---------- buildroot/configs/naxriscv_sim_raw_defconfig | 11 +- buildroot/configs/rv32ima.sh | 6 +- buildroot/configs/rv32imac.sh | 6 +- buildroot/configs/rv64ima.sh | 6 +- buildroot/configs/rv64imac.sh | 6 +- buildroot/configs/rv64imafdc.sh | 6 +- buildroot/external.mk | 2 +- buildroot/makefile | 3 +- buildroot/naxriscv_sim_setup.sh | 3 +- buildroot/package/opensbi-ext/Config.in | 8 - buildroot/package/opensbi-ext/opensbi-ext.mk | 8 - .../0001-spinal-sim-related-device.patch | 268 ++++++++++++++++++ 18 files changed, 354 insertions(+), 276 deletions(-) delete mode 100644 buildroot/boards/naxriscv_sim/opensbi/config_raw.mk delete mode 100644 buildroot/boards/naxriscv_sim/opensbi/objects.mk delete mode 100644 buildroot/boards/naxriscv_sim/opensbi/platform.c delete mode 100644 buildroot/package/opensbi-ext/Config.in delete mode 100644 buildroot/package/opensbi-ext/opensbi-ext.mk create mode 100644 buildroot/patches/opensbi/0001-spinal-sim-related-device.patch diff --git a/buildroot/Config.in b/buildroot/Config.in index 1618825..8b13789 100644 --- a/buildroot/Config.in +++ b/buildroot/Config.in @@ -1,2 +1 @@ -source "$BR2_EXTERNAL_NAXRISCV_SIM_PATH/package/opensbi-ext/Config.in" diff --git a/buildroot/README.md b/buildroot/README.md index a1def2d..230c339 100644 --- a/buildroot/README.md +++ b/buildroot/README.md @@ -15,10 +15,11 @@ make ## Opensbi ``` -git clone https://github.com/riscv-software-src/opensbi.git --branch v0.8 +git clone https://github.com/riscv-software-src/opensbi.git --branch v1.8.1 cd opensbi +git am $NAX_SOFTWARE/buildroot/opensbi/0001-spinal-sim-related-device.patch export CROSS_COMPILE=riscv64-unknown-elf- -make PLATFORM_RISCV_XLEN=64 PLATFORM_RISCV_ABI=lp64d PLATFORM_RISCV_ISA=rv64gc PLATFORM=out-of-tree +make PLATFORM_RISCV_XLEN=64 PLATFORM_RISCV_ABI=lp64d BUILD_INFO=y DEBUG=1 FW_PIC=y PLATFORM=generic FW_TEXT_START=0x80000000 FW_JUMP_ADDR=0x80400000 FW_JUMP_FDT_ADDR=0x80F80000 ``` ## How to run sim @@ -33,4 +34,4 @@ Follow the readme to build the simulator, then --load-bin $LINUX_IMAGES/rootfs.cpio,0x81000000 ``` -<3 \ No newline at end of file +<3 diff --git a/buildroot/boards/naxriscv_sim/linux/linux_raw.dts b/buildroot/boards/naxriscv_sim/linux/linux_raw.dts index 9703723..e8a3956 100644 --- a/buildroot/boards/naxriscv_sim/linux/linux_raw.dts +++ b/buildroot/boards/naxriscv_sim/linux/linux_raw.dts @@ -3,43 +3,62 @@ ##include ##include +/ { + compatible = "spinal,vexiiriscv"; + ##address-cells = <1>; + ##size-cells = <1>; + chosen { + bootargs = "rootwait console=hvc0 earlycon=sbi root=/dev/ram0 init=/sbin/init"; + linux,initrd-start = <0x81000000>; + linux,initrd-end = <0x81800000>; + }; -/ { - ##address-cells = <0x1>; - ##size-cells = <0x1>; - compatible = "spinal,naxriscv"; - model = "spinal,naxriscv_sim"; - - chosen { - bootargs = "rootwait console=hvc0 earlycon=sbi root=/dev/ram0 init=/sbin/init"; - linux,initrd-start = <0x81000000>; - linux,initrd-end = <0x81800000>; - }; - - cpus { - ##address-cells = <0x1>; - ##size-cells = <0x0>; - timebase-frequency = <100000000>; - cpu@0 { - device_type = "cpu"; - compatible = "riscv"; - riscv,isa = ISA_STR; - mmu-type = MMU_TYPE; - reg = <0>; - status = "okay"; - L0: interrupt-controller { - ##interrupt-cells = <0x00000001>; - interrupt-controller; - compatible = "riscv,cpu-intc"; - }; - }; - }; - - memory@80000000 { - device_type = "memory"; - reg = <0x80400000 0x0FC00000>; - }; -}; + cpus { + ##address-cells = <1>; + ##size-cells = <0>; + timebase-frequency = <100000000>; + + cpu@0 { + compatible = "spinal,vexiiriscv", "riscv"; + reg = <0>; + device_type = "cpu"; + mmu-type = MMU_TYPE; + riscv,isa-base = ISA_BASE; + riscv,isa-extensions = ISA_STR; + + cpu0_intc: interrupt-controller { + compatible = "riscv,cpu-intc"; + interrupt-controller; + ##interrupt-cells = <1>; + }; + }; + }; + memory@80000000 { + device_type = "memory"; + reg = <0x80000000 0x40000000>; + }; + soc { + compatible = "simple-bus"; + ##address-cells = <1>; + ##size-cells = <1>; + ranges; + + serial0: serial@10000000 { + compatible = "spinal,vexiiriscv-uart"; + reg = <0x10000000 0x1000>; + }; + + clint: timer@10010000 { + compatible = "sifive,clint0"; + reg = <0x10010000 0x10000>; + interrupts-extended = <&cpu0_intc 3>, <&cpu0_intc 7>; + }; + }; + + poweroff { + compatible = "spinal-poweroff"; + }; +}; diff --git a/buildroot/boards/naxriscv_sim/opensbi/config_raw.mk b/buildroot/boards/naxriscv_sim/opensbi/config_raw.mk deleted file mode 100644 index 4185a7f..0000000 --- a/buildroot/boards/naxriscv_sim/opensbi/config_raw.mk +++ /dev/null @@ -1,30 +0,0 @@ -## -## SPDX-License-Identifier: BSD-2-Clause -## -## Copyright (c) 2019 Western Digital Corporation or its affiliates. -## -## Authors: -## Anup Patel -## - -## Compiler flags -platform-cppflags-y = -platform-cflags-y = -platform-asflags-y = -platform-ldflags-y = - -## Command for platform specific "make run" -platform-runcmd = echo Bitconnneeect - -PLATFORM_RISCV_XLEN = XLEN -PLATFORM_RISCV_ABI = ABI -PLATFORM_RISCV_ISA = ISA -PLATFORM_RISCV_CODE_MODEL = medany - -## Blobs to build -FW_DYNAMIC=y -FW_TEXT_START=0x80000000 -FW_PAYLOAD=n -FW_JUMP=y -FW_JUMP_ADDR=0x80400000 -FW_JUMP_FDT_ADDR=0x80F80000 diff --git a/buildroot/boards/naxriscv_sim/opensbi/objects.mk b/buildroot/boards/naxriscv_sim/opensbi/objects.mk deleted file mode 100644 index a3d51e4..0000000 --- a/buildroot/boards/naxriscv_sim/opensbi/objects.mk +++ /dev/null @@ -1,12 +0,0 @@ -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2019 Western Digital Corporation or its affiliates. -# -# Authors: -# Anup Patel -# - -platform-objs-y += platform.o -platform-genflags-y += "-I$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/boards/naxriscv_sim/opensbi" - diff --git a/buildroot/boards/naxriscv_sim/opensbi/platform.c b/buildroot/boards/naxriscv_sim/opensbi/platform.c deleted file mode 100644 index e14088a..0000000 --- a/buildroot/boards/naxriscv_sim/opensbi/platform.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2019 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - * Nick Kossifidis - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* clang-format off */ - -#define NAX_HART_COUNT 8 -#define NAX_PLATFORM_FEATURES \ - (SBI_PLATFORM_HAS_TIMER_VALUE | SBI_PLATFORM_HAS_MFAULTS_DELEGATION) - -#define NAX_HART_STACK_SIZE 4096 - - - -#define BASE 0x10000000 -#define PUTC BASE -#define PUT_HEX (BASE + 0x8) -#define CLINT_BASE (BASE + 0x10000) -#define CLINT_CMP (CLINT_BASE + 0x4000) -#define CLINT_TIME (CLINT_BASE + 0x0BFF8) -#define MACHINE_EXTERNAL_INTERRUPT_CTRL (BASE+0x10) -#define SUPERVISOR_EXTERNAL_INTERRUPT_CTRL (BASE + 0x18) -#define GETC (BASE + 0x40) - - -#define NAX_CLINT_ADDR CLINT_BASE -#define NAX_PUTC PUTC -#define NAX_GETC GETC - - -/* clang-format on */ - -static struct clint_data clint = {NAX_CLINT_ADDR, 0, NAX_HART_COUNT, true}; - -static int nax_final_init(bool cold_boot) -{ - return 0; -} - -static u32 nax_pmp_region_count(u32 hartid) -{ - return 0; -} - -static int nax_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr, - ulong *log2size) -{ - int ret = 0; - - switch (index) { - default: - ret = -1; - break; - }; - - return ret; -} - - -void nax_putc(char ch){ - writel(ch, (void*)NAX_PUTC); -} - -int nax_getc(void){ - return readl((void*)NAX_GETC); -} - -static int nax_console_init(void) -{ - return 0; -} - -static int nax_irqchip_init(bool cold_boot) -{ - return 0; -} - -static int nax_ipi_init(bool cold_boot) -{ - int rc; - - if (cold_boot) { - rc = clint_cold_ipi_init(&clint); - if (rc) - return rc; - } - - return clint_warm_ipi_init(); -} - -static int nax_timer_init(bool cold_boot) -{ - int rc; - if (cold_boot) { - rc = clint_cold_timer_init(&clint, NULL); /* Timer has no reference */ - if (rc) - return rc; - } - - return clint_warm_timer_init(); -} - -static int nax_system_reset(u32 type) -{ - /* Tell the "finisher" that the simulation - * was successful so that QEMU exits - */ - - return 0; -} - -const struct sbi_platform_operations platform_ops = { - .pmp_region_count = nax_pmp_region_count, - .pmp_region_info = nax_pmp_region_info, - .final_init = nax_final_init, - .console_putc = nax_putc, - .console_getc = nax_getc, - .console_init = nax_console_init, - .irqchip_init = nax_irqchip_init, - .ipi_send = clint_ipi_send, - .ipi_clear = clint_ipi_clear, - .ipi_init = nax_ipi_init, - .timer_value = clint_timer_value, - .timer_event_stop = clint_timer_event_stop, - .timer_event_start = clint_timer_event_start, - .timer_init = nax_timer_init, - .system_reset = nax_system_reset -}; - -const struct sbi_platform platform = { - .opensbi_version = OPENSBI_VERSION, - .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), - .name = "NaxRiscv", - .features = NAX_PLATFORM_FEATURES, - .hart_count = NAX_HART_COUNT, - .hart_stack_size = NAX_HART_STACK_SIZE, - .platform_ops_addr = (unsigned long)&platform_ops -}; - - diff --git a/buildroot/configs/naxriscv_sim_raw_defconfig b/buildroot/configs/naxriscv_sim_raw_defconfig index fed6116..7f7d411 100644 --- a/buildroot/configs/naxriscv_sim_raw_defconfig +++ b/buildroot/configs/naxriscv_sim_raw_defconfig @@ -29,7 +29,7 @@ BR2_RISCV_ABI_LP64=y ## Patches -##BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/patches" +BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/patches" ## GCC BR2_GCC_VERSION_10_X=y @@ -42,8 +42,13 @@ BR2_LINUX_KERNEL_CUSTOM_DTS_PATH="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/boards/naxri ## OpenSBI BR2_TARGET_OPENSBI=y -BR2_TARGET_OPENSBI_PLAT="out-of-tree" -BR2_TARGET_OPENSBI_PLAT_PATH="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/boards/naxriscv_sim/opensbi" +BR2_TARGET_OPENSBI_CUSTOM_VERSION=y +BR2_TARGET_OPENSBI_CUSTOM_VERSION_VALUE="1.8.1" +BR2_TARGET_OPENSBI_PLAT="generic" +BR2_TARGET_OPENSBI_INSTALL_PAYLOAD_IMG=y +BR2_TARGET_OPENSBI_INSTALL_JUMP_IMG=y +BR2_TARGET_OPENSBI_LINUX_PAYLOAD=y +BR2_TARGET_OPENSBI_ADDITIONAL_VARIABLES="BUILD_INFO=y DEBUG=1 FW_PIC=y PLATFORM=generic FW_TEXT_START=0x80000000 FW_JUMP_ADDR=0x80400000 FW_JUMP_FDT_ADDR=0x80F80000 FW_FDT_PATH=$(BINARIES_DIR)/linux.dtb" ## Filesystem BR2_TARGET_ROOTFS_CPIO=y diff --git a/buildroot/configs/rv32ima.sh b/buildroot/configs/rv32ima.sh index 67f0094..b2ff51c 100755 --- a/buildroot/configs/rv32ima.sh +++ b/buildroot/configs/rv32ima.sh @@ -1,9 +1,9 @@ #!/bin/bash -FLAGS+=" -DISA=rv32ima" -FLAGS+=" -DISA_STR=\"rv32ima\"" +ISA=(i m a zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv32i\"" FLAGS+=" -DXLEN=32" FLAGS+=" -DABI=ilp32" FLAGS+=" -DMMU_TYPE=\"riscv,sv32\"" FLAGS+=" -DRV32" -FLAGS+=" -DRVC=n" \ No newline at end of file +FLAGS+=" -DRVC=n" diff --git a/buildroot/configs/rv32imac.sh b/buildroot/configs/rv32imac.sh index f4a569d..04d6e69 100755 --- a/buildroot/configs/rv32imac.sh +++ b/buildroot/configs/rv32imac.sh @@ -1,9 +1,9 @@ #!/bin/bash -FLAGS+=" -DISA=rv32imac" -FLAGS+=" -DISA_STR=\"rv32imac\"" +ISA=(i m a c zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv32i\"" FLAGS+=" -DXLEN=32" FLAGS+=" -DABI=ilp32" FLAGS+=" -DMMU_TYPE=\"riscv,sv32\"" FLAGS+=" -DRV32" -FLAGS+=" -DRVC=y" \ No newline at end of file +FLAGS+=" -DRVC=y" diff --git a/buildroot/configs/rv64ima.sh b/buildroot/configs/rv64ima.sh index fc158e5..d16ae59 100755 --- a/buildroot/configs/rv64ima.sh +++ b/buildroot/configs/rv64ima.sh @@ -1,9 +1,9 @@ #!/bin/bash -FLAGS+=" -DISA=rv64ima" -FLAGS+=" -DISA_STR=\"rv64ima\"" +ISA=(i m a zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv64i\"" FLAGS+=" -DXLEN=64" FLAGS+=" -DABI=lp64" FLAGS+=" -DMMU_TYPE=\"riscv,sv39\"" FLAGS+=" -DRV64" -FLAGS+=" -DRVC=n" \ No newline at end of file +FLAGS+=" -DRVC=n" diff --git a/buildroot/configs/rv64imac.sh b/buildroot/configs/rv64imac.sh index 9c91d02..cc06fbf 100755 --- a/buildroot/configs/rv64imac.sh +++ b/buildroot/configs/rv64imac.sh @@ -1,9 +1,9 @@ #!/bin/bash -FLAGS+=" -DISA=rv64imac" -FLAGS+=" -DISA_STR=\"rv64imac\"" +ISA=(i m a c zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv64i\"" FLAGS+=" -DXLEN=64" FLAGS+=" -DABI=lp64" FLAGS+=" -DMMU_TYPE=\"riscv,sv39\"" FLAGS+=" -DRV64" -FLAGS+=" -DRVC=y" \ No newline at end of file +FLAGS+=" -DRVC=y" diff --git a/buildroot/configs/rv64imafdc.sh b/buildroot/configs/rv64imafdc.sh index b89bcdb..ecb97f3 100755 --- a/buildroot/configs/rv64imafdc.sh +++ b/buildroot/configs/rv64imafdc.sh @@ -1,10 +1,10 @@ #!/bin/bash -FLAGS+=" -DISA=rv64imafdc" -FLAGS+=" -DISA_STR=\"rv64imafdc\"" +ISA=(i m a f d c zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv64i\"" FLAGS+=" -DXLEN=64" FLAGS+=" -DABI=lp64d" FLAGS+=" -DMMU_TYPE=\"riscv,sv39\"" FLAGS+=" -DRV64" FLAGS+=" -DRVC=y" -FLAGS+=" -DFPU=y" \ No newline at end of file +FLAGS+=" -DFPU=y" diff --git a/buildroot/external.mk b/buildroot/external.mk index 37d9dc4..aa3f661 100644 --- a/buildroot/external.mk +++ b/buildroot/external.mk @@ -1,2 +1,2 @@ -include $(sort $(wildcard $(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/package/*/*.mk)) +-include $(sort $(wildcard $(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/package/*/*.mk)) diff --git a/buildroot/makefile b/buildroot/makefile index 9439a0c..27fe834 100644 --- a/buildroot/makefile +++ b/buildroot/makefile @@ -1,7 +1,6 @@ FILES=configs/naxriscv_sim_raw_defconfig \ boards/naxriscv_sim/linux/linux_raw.config\ - boards/naxriscv_sim/linux/linux_raw.dts \ - boards/naxriscv_sim/opensbi/config_raw.mk + boards/naxriscv_sim/linux/linux_raw.dts %: %_raw diff --git a/buildroot/naxriscv_sim_setup.sh b/buildroot/naxriscv_sim_setup.sh index 2ef62e7..dd14f4b 100755 --- a/buildroot/naxriscv_sim_setup.sh +++ b/buildroot/naxriscv_sim_setup.sh @@ -4,6 +4,8 @@ FLAGS="-undef" SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" source $SCRIPTPATH/configs/$1.sh +ISA_EXTENION_STR="$(echo "${ISA[*]}" | sed "s/ /\",\"/g")" +FLAGS+=" -DISA_STR=\"$ISA_EXTENION_STR\"" doit() { cpp -E -P $FLAGS $1 | sed -e 's/##/#/' > $2 @@ -12,4 +14,3 @@ doit() { doit $SCRIPTPATH/configs/naxriscv_sim_raw_defconfig $SCRIPTPATH/configs/naxriscv_sim_defconfig doit $SCRIPTPATH/boards/naxriscv_sim/linux/linux_raw.config $SCRIPTPATH/boards/naxriscv_sim/linux/linux.config doit $SCRIPTPATH/boards/naxriscv_sim/linux/linux_raw.dts $SCRIPTPATH/boards/naxriscv_sim/linux/linux.dts -doit $SCRIPTPATH/boards/naxriscv_sim/opensbi/config_raw.mk $SCRIPTPATH/boards/naxriscv_sim/opensbi/config.mk diff --git a/buildroot/package/opensbi-ext/Config.in b/buildroot/package/opensbi-ext/Config.in deleted file mode 100644 index c39f842..0000000 --- a/buildroot/package/opensbi-ext/Config.in +++ /dev/null @@ -1,8 +0,0 @@ - -config BR2_TARGET_OPENSBI_PLAT_PATH - string "OpenSBI Out of tree plateform" - default "" - help - Enable OpenSBI Out of tree plateform - - diff --git a/buildroot/package/opensbi-ext/opensbi-ext.mk b/buildroot/package/opensbi-ext/opensbi-ext.mk deleted file mode 100644 index 4692432..0000000 --- a/buildroot/package/opensbi-ext/opensbi-ext.mk +++ /dev/null @@ -1,8 +0,0 @@ -define OPENSBI_NAX_PLATFORM_COPY - cp -r $(BR2_TARGET_OPENSBI_PLAT_PATH) $(BUILD_DIR)/opensbi-$(OPENSBI_VERSION)/platform/$(BR2_TARGET_OPENSBI_PLAT) -endef - -ifneq ($(BR2_TARGET_OPENSBI_PLAT_PATH),) -OPENSBI_PRE_BUILD_HOOKS += OPENSBI_NAX_PLATFORM_COPY -endif - diff --git a/buildroot/patches/opensbi/0001-spinal-sim-related-device.patch b/buildroot/patches/opensbi/0001-spinal-sim-related-device.patch new file mode 100644 index 0000000..0b704a0 --- /dev/null +++ b/buildroot/patches/opensbi/0001-spinal-sim-related-device.patch @@ -0,0 +1,268 @@ +From b6bc48c67cfd17e713ab93b9c125c73f2b1ac5dc Mon Sep 17 00:00:00 2001 +From: Inochi Amaoto +Date: Mon, 23 Mar 2026 09:26:38 +0800 +Subject: [PATCH] spinal sim related device + +Signed-off-by: Inochi Amaoto +--- + include/sbi_utils/serial/spinal-uart.h | 23 ++++++++ + lib/utils/reset/fdt_reset_spinal.c | 61 +++++++++++++++++++++ + lib/utils/reset/objects.mk | 3 ++ + lib/utils/serial/fdt_serial_spinalhdl.c | 36 +++++++++++++ + lib/utils/serial/objects.mk | 4 ++ + lib/utils/serial/spinal-uart.c | 72 +++++++++++++++++++++++++ + 6 files changed, 199 insertions(+) + create mode 100644 include/sbi_utils/serial/spinal-uart.h + create mode 100644 lib/utils/reset/fdt_reset_spinal.c + create mode 100644 lib/utils/serial/fdt_serial_spinalhdl.c + create mode 100644 lib/utils/serial/spinal-uart.c + +diff --git a/include/sbi_utils/serial/spinal-uart.h b/include/sbi_utils/serial/spinal-uart.h +new file mode 100644 +index 00000000..6387801e +--- /dev/null ++++ b/include/sbi_utils/serial/spinal-uart.h +@@ -0,0 +1,23 @@ ++/* ++ * SPDX-License-Identifier: BSD-2-Clause ++ * ++ * Copyright (c) 2019 Western Digital Corporation or its affiliates. ++ * ++ * Authors: ++ * Anup Patel ++ */ ++ ++#ifndef __SERIAL_UART8250_H__ ++#define __SERIAL_UART8250_H__ ++ ++#include ++ ++#define UART_CAP_UUE BIT(0) /* Check UUE capability for XScale PXA UARTs */ ++ ++struct spinal_uart_device { ++ volatile char *base; ++}; ++ ++int spinal_uart_init(unsigned long base); ++ ++#endif +diff --git a/lib/utils/reset/fdt_reset_spinal.c b/lib/utils/reset/fdt_reset_spinal.c +new file mode 100644 +index 00000000..9a9b4c23 +--- /dev/null ++++ b/lib/utils/reset/fdt_reset_spinal.c +@@ -0,0 +1,61 @@ ++/* ++ * SPDX-License-Identifier: BSD-2-Clause ++ * ++ * Copyright (c) 2023 Ventana Micro Systems Inc. ++ * ++ * Authors: ++ * Anup Patel ++ */ ++ ++#include "sbi/riscv_asm.h" ++#include "sbi/sbi_types.h" ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++__noreturn void spinal_do_poweroff_pass(void) ++{ ++ while (1) ++ wfi(); ++ ++ __builtin_unreachable(); ++} ++ ++static int spinal_poweroff_check(u32 type, u32 reason) ++{ ++ return 1; ++} ++ ++static void spinal_do_poweroff(u32 type, u32 reason) ++{ ++ spinal_do_poweroff_pass(); ++} ++ ++static struct sbi_system_reset_device spinal_poweroff = { ++ .name = "spinal-poweroff", ++ .system_reset_check = spinal_poweroff_check, ++ .system_reset = spinal_do_poweroff ++}; ++ ++static int spinal_reset_init(const void *fdt, int nodeoff, ++ const struct fdt_match *match) ++{ ++ sbi_system_reset_add_device(&spinal_poweroff); ++ ++ return 0; ++} ++ ++static const struct fdt_match spinal_poweroff_match[] = { ++ { .compatible = "spinal-poweroff", .data = (const void *)false }, ++ { }, ++}; ++ ++const struct fdt_driver fdt_reset_spinal = { ++ .match_table = spinal_poweroff_match, ++ .init = spinal_reset_init, ++}; +diff --git a/lib/utils/reset/objects.mk b/lib/utils/reset/objects.mk +index ac38b49d..fae2cec3 100644 +--- a/lib/utils/reset/objects.mk ++++ b/lib/utils/reset/objects.mk +@@ -29,3 +29,6 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_SYSCON) += reset/fdt_reset_syscon.o + + carray-fdt_early_drivers-$(CONFIG_FDT_RESET_RPMI) += fdt_reset_rpmi + libsbiutils-objs-$(CONFIG_FDT_RESET_RPMI) += reset/fdt_reset_rpmi.o ++ ++carray-fdt_early_drivers-y += fdt_reset_spinal ++libsbiutils-objs-y += reset/fdt_reset_spinal.o +diff --git a/lib/utils/serial/fdt_serial_spinalhdl.c b/lib/utils/serial/fdt_serial_spinalhdl.c +new file mode 100644 +index 00000000..9c209c78 +--- /dev/null ++++ b/lib/utils/serial/fdt_serial_spinalhdl.c +@@ -0,0 +1,36 @@ ++/* ++ * SPDX-License-Identifier: BSD-2-Clause ++ * ++ * Copyright (c) 2020 Western Digital Corporation or its affiliates. ++ * ++ * Authors: ++ * Anup Patel ++ */ ++ ++#include ++#include ++#include ++ ++ ++static int serial_spinal_uart_init(const void *fdt, int nodeoff, ++ const struct fdt_match *match) ++{ ++ struct platform_uart_data uart = { 0 }; ++ int rc; ++ ++ rc = fdt_parse_uart_node(fdt, nodeoff, &uart); ++ if (rc) ++ return rc; ++ ++ return spinal_uart_init(uart.addr); ++} ++ ++static const struct fdt_match serial_spinal_uart_match[] = { ++ { .compatible = "spinal,vexiiriscv-uart" }, ++ { }, ++}; ++ ++const struct fdt_driver fdt_serial_spinalhdl = { ++ .match_table = serial_spinal_uart_match, ++ .init = serial_spinal_uart_init, ++}; +diff --git a/lib/utils/serial/objects.mk b/lib/utils/serial/objects.mk +index 7c973c83..a9154fec 100644 +--- a/lib/utils/serial/objects.mk ++++ b/lib/utils/serial/objects.mk +@@ -37,6 +37,9 @@ libsbiutils-objs-$(CONFIG_FDT_SERIAL_UART8250) += serial/fdt_serial_uart8250.o + carray-fdt_serial_drivers-$(CONFIG_FDT_SERIAL_XILINX_UARTLITE) += fdt_serial_xlnx_uartlite + libsbiutils-objs-$(CONFIG_FDT_SERIAL_XILINX_UARTLITE) += serial/fdt_serial_xlnx_uartlite.o + ++carray-fdt_serial_drivers-y += fdt_serial_spinalhdl ++libsbiutils-objs-y += serial/fdt_serial_spinalhdl.o ++ + libsbiutils-objs-$(CONFIG_SERIAL_CADENCE) += serial/cadence-uart.o + libsbiutils-objs-$(CONFIG_SERIAL_GAISLER) += serial/gaisler-uart.o + libsbiutils-objs-$(CONFIG_SERIAL_RENESAS_SCIF) += serial/renesas_scif.o +@@ -46,3 +49,4 @@ libsbiutils-objs-$(CONFIG_SERIAL_LITEX) += serial/litex-uart.o + libsbiutils-objs-$(CONFIG_SERIAL_UART8250) += serial/uart8250.o + libsbiutils-objs-$(CONFIG_SERIAL_XILINX_UARTLITE) += serial/xlnx-uartlite.o + libsbiutils-objs-$(CONFIG_SERIAL_SEMIHOSTING) += serial/semihosting.o ++libsbiutils-objs-y += serial/spinal-uart.o +diff --git a/lib/utils/serial/spinal-uart.c b/lib/utils/serial/spinal-uart.c +new file mode 100644 +index 00000000..7fcd1b1e +--- /dev/null ++++ b/lib/utils/serial/spinal-uart.c +@@ -0,0 +1,72 @@ ++/* ++ * SPDX-License-Identifier: BSD-2-Clause ++ * ++ * Copyright (c) 2019 Western Digital Corporation or its affiliates. ++ * ++ * Authors: ++ * Anup Patel ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++/* clang-format off */ ++ ++#define UART_PUTC_OFFSET 0x0 ++#define UART_GETC_OFFSET 0x40 ++#define UART_GETC_EMPTY_OFFSET 0x44 ++ ++/* clang-format on */ ++ ++static struct spinal_uart_device spinal_uart_dev; ++ ++void spinal_uart_device_putc(struct spinal_uart_device *dev, char ch) ++{ ++ writel(ch, (void*)dev->base + UART_PUTC_OFFSET); ++} ++ ++static void spinal_uart_putc(char ch) ++{ ++ return spinal_uart_device_putc(&spinal_uart_dev, ch); ++} ++ ++int spinal_uart_device_getc(struct spinal_uart_device *dev) ++{ ++ int ret; ++ ++ if (readl(dev->base + UART_GETC_EMPTY_OFFSET)) { ++ return -1; ++ } ++ ++ ret = readl(dev->base + UART_GETC_OFFSET); ++ ++ return ret; ++} ++ ++static int spinal_uart_getc(void) ++{ ++ return spinal_uart_device_getc(&spinal_uart_dev); ++} ++ ++static struct sbi_console_device spinal_uart_console = { ++ .name = "spinal", ++ .console_putc = spinal_uart_putc, ++ .console_getc = spinal_uart_getc ++}; ++ ++static void spinal_uart_device_init(struct spinal_uart_device *dev, unsigned long base) ++{ ++ dev->base = (volatile char *)base; ++} ++ ++int spinal_uart_init(unsigned long base) ++{ ++ spinal_uart_device_init(&spinal_uart_dev, base); ++ ++ sbi_console_set_device(&spinal_uart_console); ++ ++ return 0; ++} +-- +2.53.0 + From cf40c730b3cf6e7215f4c3c7a7395b98ab005987 Mon Sep 17 00:00:00 2001 From: Inochi Amaoto Date: Fri, 24 Apr 2026 10:07:15 +0800 Subject: [PATCH 2/5] buildroot: Add RVH based build file and configuration Signed-off-by: Inochi Amaoto --- buildroot/boards/naxriscv_sim/linux/linux_raw.config | 5 +++++ buildroot/configs/naxriscv_sim_raw_defconfig | 7 ++++--- buildroot/configs/rv64imafdch.sh | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100755 buildroot/configs/rv64imafdch.sh diff --git a/buildroot/boards/naxriscv_sim/linux/linux_raw.config b/buildroot/boards/naxriscv_sim/linux/linux_raw.config index 1c3b593..1b7eb58 100644 --- a/buildroot/boards/naxriscv_sim/linux/linux_raw.config +++ b/buildroot/boards/naxriscv_sim/linux/linux_raw.config @@ -2,6 +2,7 @@ CONFIG_SECTION_MISMATCH_WARN_ONLY=y ## Architecture CONFIG_ARCH_DEFCONFIG="arch/riscv/configs/defconfig" +CONFIG_NONPORTABLE=y #ifdef RV32 CONFIG_ARCH_RV32I=y #endif @@ -17,6 +18,10 @@ CONFIG_FPU=y #else CONFIG_FPU=n #endif +#ifdef RVH +CONFIG_VIRTUALIZATION=y +CONFIG_KVM=y +#endif CONFIG_SMP=y CONFIG_STRICT_KERNEL_RWX=n CONFIG_EFI=n diff --git a/buildroot/configs/naxriscv_sim_raw_defconfig b/buildroot/configs/naxriscv_sim_raw_defconfig index 7f7d411..af1da1c 100644 --- a/buildroot/configs/naxriscv_sim_raw_defconfig +++ b/buildroot/configs/naxriscv_sim_raw_defconfig @@ -69,6 +69,7 @@ BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/boards/naxriscv_sim/linux/ BR2_PACKAGE_DHRYSTONE=y BR2_PACKAGE_MICROPYTHON=y - - - +#ifdef RVH +BR2_PACKAGE_KVMTOOL=y +BR2_PACKAGE_KVM_UNIT_TESTS=y +#endif diff --git a/buildroot/configs/rv64imafdch.sh b/buildroot/configs/rv64imafdch.sh new file mode 100755 index 0000000..9ed58c8 --- /dev/null +++ b/buildroot/configs/rv64imafdch.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +ISA=(i m a f d c h zicsr zifence) +FLAGS+=" -DISA_BASE=\"rv64i\"" +FLAGS+=" -DXLEN=64" +FLAGS+=" -DABI=lp64d" +FLAGS+=" -DMMU_TYPE=\"riscv,sv39\"" +FLAGS+=" -DRV64" +FLAGS+=" -DRVC=y" +FLAGS+=" -DFPU=y" +FLAGS+=" -DRVH=y" From a43442583fbcd52689308922262a5ccf92b57a7a Mon Sep 17 00:00:00 2001 From: Inochi Amaoto Date: Fri, 24 Apr 2026 10:29:13 +0800 Subject: [PATCH 3/5] buildroot: Fix GCC version and ISA options Signed-off-by: Inochi Amaoto --- buildroot/configs/naxriscv_sim_raw_defconfig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buildroot/configs/naxriscv_sim_raw_defconfig b/buildroot/configs/naxriscv_sim_raw_defconfig index af1da1c..640c2e8 100644 --- a/buildroot/configs/naxriscv_sim_raw_defconfig +++ b/buildroot/configs/naxriscv_sim_raw_defconfig @@ -13,12 +13,12 @@ BR2_RISCV_64=y ## Instruction Set Extensions BR2_riscv_custom=y -BR2_RISCV_ISA_CUSTOM_RVM=y -BR2_RISCV_ISA_CUSTOM_RVA=y -BR2_RISCV_ISA_CUSTOM_RVC=RVC +BR2_RISCV_ISA_RVM=y +BR2_RISCV_ISA_RVA=y +BR2_RISCV_ISA_RVC=RVC #ifdef FPU -BR2_RISCV_ISA_CUSTOM_RVF=y -BR2_RISCV_ISA_CUSTOM_RVD=y +BR2_RISCV_ISA_RVF=y +BR2_RISCV_ISA_RVD=y #endif #ifdef RV32 BR2_RISCV_ABI_ILP32=y @@ -32,7 +32,7 @@ BR2_RISCV_ABI_LP64=y BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_NAXRISCV_SIM_PATH)/patches" ## GCC -BR2_GCC_VERSION_10_X=y +BR2_GCC_VERSION_15_X=y ## System BR2_TARGET_GENERIC_GETTY=y From 70a7e0d181ee20f9c26eee6a93c5d9943f4dc7eb Mon Sep 17 00:00:00 2001 From: Inochi Amaoto Date: Fri, 24 Apr 2026 13:50:27 +0800 Subject: [PATCH 4/5] buildroot: Use upstream linux Signed-off-by: Inochi Amaoto --- buildroot/configs/naxriscv_sim_raw_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildroot/configs/naxriscv_sim_raw_defconfig b/buildroot/configs/naxriscv_sim_raw_defconfig index 640c2e8..ed378af 100644 --- a/buildroot/configs/naxriscv_sim_raw_defconfig +++ b/buildroot/configs/naxriscv_sim_raw_defconfig @@ -55,7 +55,7 @@ BR2_TARGET_ROOTFS_CPIO=y ## Kernel (litex-rebase branch) BR2_LINUX_KERNEL=y -BR2_LINUX_KERNEL_CUSTOM_GIT=y +BR2_LINUX_KERNEL_CUSTOM_GIT=n BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/SpinalHDL/linux.git" BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="dev" BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y From addf0fb12217b43f120587a15d44ef0c2264d8ab Mon Sep 17 00:00:00 2001 From: Inochi Amaoto Date: Fri, 24 Apr 2026 17:41:28 +0800 Subject: [PATCH 5/5] buildroot: Update build instruction Signed-off-by: Inochi Amaoto --- buildroot/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildroot/README.md b/buildroot/README.md index 230c339..8ee309f 100644 --- a/buildroot/README.md +++ b/buildroot/README.md @@ -4,9 +4,8 @@ ``` cd $NAXRISCV/.. export NAX_SOFTWARE=$NAXRISCV/ext/NaxSoftware -git clone https://github.com/buildroot/buildroot.git --branch master +git clone https://github.com/buildroot/buildroot.git --branch 2026.02.x cd buildroot -git checkout 9ef54b7d $NAX_SOFTWARE/buildroot/naxriscv_sim_setup.sh rv32ima make BR2_EXTERNAL=$NAX_SOFTWARE/buildroot/ naxriscv_sim_defconfig make