From 9da6943bd951cecd4bcd193123331d18e674dce3 Mon Sep 17 00:00:00 2001 From: bernard Date: Tue, 17 Jun 2025 08:28:54 +0800 Subject: [PATCH 1/3] [BSP][K230] Add soft-fpu option for k230 --- bsp/k230/Kconfig | 18 ++++++++++++++++-- bsp/k230/SConstruct | 11 +++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bsp/k230/Kconfig b/bsp/k230/Kconfig index 93af5a32488..3ddee1c468c 100644 --- a/bsp/k230/Kconfig +++ b/bsp/k230/Kconfig @@ -10,14 +10,14 @@ source "$RTT_DIR/Kconfig" source "$PKGS_DIR/Kconfig" rsource "board/Kconfig" -config BOARD_fpgac908 +config BOARD_C908 bool select ARCH_RISCV64 select RT_USING_COMPONENTS_INIT select RT_USING_USER_MAIN select RT_USING_CACHE select ARCH_MM_MMU - select ARCH_RISCV_FPU_D + select ARCH_RISCV_FPU select ARCH_REMAP_KERNEL if RT_USING_SMART default y @@ -38,3 +38,17 @@ choice BSP_ROOTFS_TYPE select RT_USING_DFS_CROMFS select PKG_USING_ZLIB endchoice + +choice BSP_RISCV_USING_FPU + prompt "FPU precision" + default BSP_RISCV_FPU_D + + config BSP_RISCV_FPU_SOFT + bool "Software floating-point" + select ARCH_RISCV_FPU + + config BSP_RISCV_FPU_D + bool "Double-precision floating-point with Vector" + select ARCH_RISCV_FPU_D + select ARCH_RISCV_VECTOR +endchoice diff --git a/bsp/k230/SConstruct b/bsp/k230/SConstruct index fdb0d5eb872..d12a8ff8e1b 100644 --- a/bsp/k230/SConstruct +++ b/bsp/k230/SConstruct @@ -8,7 +8,6 @@ from rtconfig import RTT_ROOT import sys def generate_ldscript(input, output): - if not os.path.exists(input): print('Error: file', input, 'not found') return @@ -30,12 +29,20 @@ def generate_ldscript(input, output): print(output, 'is generated from', input) - sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] from building import * TARGET = 'rtthread.' + rtconfig.TARGET_EXT +# apply soft-FPU config +options = LocalOptions("rtconfig.h") +soft_fpu = GetLocalDepend(options, 'BSP_RISCV_FPU_SOFT') +if soft_fpu: + rtconfig.DEVICE = rtconfig.DEVICE.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64') + rtconfig.CFLAGS = rtconfig.CFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64') + rtconfig.LFLAGS = rtconfig.LFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64') + rtconfig.AFLAGS = rtconfig.AFLAGS.replace('-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64') + DefaultEnvironment(tools=[]) env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, From 62b6cb10d5eb5ff82f5833d38469d18739969d2d Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Mon, 23 Jun 2025 23:42:31 +0800 Subject: [PATCH 2/3] [vdso] use the default arch/abi flags in risc-v vDSO building. --- .../lwp/vdso/user/arch/risc-v/SConstruct | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/components/lwp/vdso/user/arch/risc-v/SConstruct b/components/lwp/vdso/user/arch/risc-v/SConstruct index 6613239bf2b..2f0838eeade 100644 --- a/components/lwp/vdso/user/arch/risc-v/SConstruct +++ b/components/lwp/vdso/user/arch/risc-v/SConstruct @@ -1,5 +1,6 @@ import os import sys +import subprocess arguments = sys.argv[2] vdso_usr = arguments @@ -7,7 +8,32 @@ vdso_path = os.path.join(vdso_usr, '..', '..', '..') EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin' PREFIX = os.getenv('RTT_CC_PREFIX') or 'riscv64-none-elf-' -DEVICE = os.getenv('RTT_DEVICE') or ' -march=rv64imafdc -mabi=lp64' + +def get_riscv64_default_arch_abi(gcc_bin): + try: + result = subprocess.check_output( + [gcc_bin, '-Q', '--help=target'], + universal_newlines=True + ) + arch = None + abi = None + for line in result.splitlines(): + if '-march=' in line and '[default]' in line: + arch = line.strip().split()[0] + if '-mabi=' in line and '[default]' in line: + abi = line.strip().split()[0] + return arch, abi + except Exception as e: + print("Error getting arch/abi:", e) + return None, None + +# get the gcc path +CC_BIN = PREFIX + 'gcc' +arch, abi = get_riscv64_default_arch_abi(CC_BIN) +if arch and abi: + DEVICE = f' {arch} {abi} ' +else: + DEVICE = ' -march=rv64imafdc -mabi=lp64' # fallback CC = PREFIX + 'gcc' CPP = PREFIX + 'cpp' From 96688d1496bd0341ea142ab48c1624ddd10e517f Mon Sep 17 00:00:00 2001 From: bernard Date: Wed, 25 Jun 2025 23:33:22 +0800 Subject: [PATCH 3/3] [vdso] fix the arch/abi flag issue. --- components/lwp/vdso/user/arch/risc-v/SConstruct | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/lwp/vdso/user/arch/risc-v/SConstruct b/components/lwp/vdso/user/arch/risc-v/SConstruct index 2f0838eeade..4680384ca08 100644 --- a/components/lwp/vdso/user/arch/risc-v/SConstruct +++ b/components/lwp/vdso/user/arch/risc-v/SConstruct @@ -18,10 +18,11 @@ def get_riscv64_default_arch_abi(gcc_bin): arch = None abi = None for line in result.splitlines(): - if '-march=' in line and '[default]' in line: - arch = line.strip().split()[0] - if '-mabi=' in line and '[default]' in line: - abi = line.strip().split()[0] + if '-march=' in line: + arch = line.strip().split()[1] + arch = arch.split('_')[0] # Get the base architecture, e.g., rv64imafdc + if '-mabi=' in line and 'option' not in line: + abi = line.strip().split()[1] return arch, abi except Exception as e: print("Error getting arch/abi:", e) @@ -31,7 +32,7 @@ def get_riscv64_default_arch_abi(gcc_bin): CC_BIN = PREFIX + 'gcc' arch, abi = get_riscv64_default_arch_abi(CC_BIN) if arch and abi: - DEVICE = f' {arch} {abi} ' + DEVICE = f' -march={arch} -mabi={abi} ' else: DEVICE = ' -march=rv64imafdc -mabi=lp64' # fallback