Skip to content

[BSP][K230] Add soft-fpu option for k230 #10400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BernardXiong
Copy link
Member

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

当前内核是使用双精度浮点,V指令集扩展方式编译。加入Soft-FPU的选项,以兼容到类似qemu-riscv64的方式。

你的解决方案是什么 (what is your solution)

在Kconfig中加入对Soft-FPU的选项,同时在SConstruct文件中对Soft-FPU情况下,调整编译参数为 -march=rv64imafdc -mabi=lp64

请提供验证的bsp和config (provide the config and bsp)

  • BSP: k230
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

@BernardXiong BernardXiong requested review from Copilot and unicornx June 17, 2025 00:32
@github-actions github-actions bot added the BSP label Jun 17, 2025
Copy link

📌 Code Review Assignment

🏷️ Tag: bsp_k230

Path: bsp/k230
Reviewers: @unicornx

Changed Files (Click to expand)
  • bsp/k230/Kconfig
  • bsp/k230/SConstruct

📊 Current Review Status (Last Updated: 2025-06-17 00:32 UTC)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a soft-FPU option for the k230 board by updating compiler flag settings in the SConstruct file and introducing new FPU configuration options in the Kconfig file.

  • Updated the SConstruct to adjust compiler flags when the soft-FPU option is enabled.
  • Modified the Kconfig to rename a board configuration and add a choice for FPU precision (software vs. double-precision).

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
bsp/k230/SConstruct Added soft-FPU conditional logic that updates compile flags.
bsp/k230/Kconfig Updated board configuration naming and introduced a new choice block for FPU options.
Comments suppressed due to low confidence (1)

bsp/k230/Kconfig:42

  • [nitpick] Consider adding inline comments in the choice block to explain the differences and implications of selecting the software FPU versus double-precision options, to help users make an informed decision.
choice BSP_RISCV_USING_FPU

Comment on lines +41 to +45
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')

Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated use of replace() across multiple flags (DEVICE, CFLAGS, LFLAGS, AFLAGS) could be refactored into a helper function to improve maintainability and reduce duplication.

Suggested change
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')
def update_flag(flag_name, old_value, new_value):
setattr(rtconfig, flag_name, getattr(rtconfig, flag_name).replace(old_value, new_value))
update_flag('DEVICE', '-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
update_flag('CFLAGS', '-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
update_flag('LFLAGS', '-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')
update_flag('AFLAGS', '-march=rv64imafdcv -mabi=lp64d', '-march=rv64imafdc -mabi=lp64')

Copilot uses AI. Check for mistakes.

@unicornx
Copy link
Contributor

加入Soft-FPU的选项,以兼容到类似qemu-riscv64的方式。

请问这个所谓兼容是指将工具链切换到 https://download.rt-thread.org/download/rt-smart/toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2 的意思吗?
也就是说如果需要使用上述工具链,那么需要编译时手动选择 “FPU precision (Software floating-point)” 对吗?

@unicornx
Copy link
Contributor

我尝试应用该补丁后,menuconfig 换成 ”FPU precision (Software floating-point)“ ,工具链换成 ”riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest“, 编译报错:

scons: Reading SConscript files ...
scons: Entering directory `/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
riscv64-linux-musleabi-gcc -o vdso_sys.os -c -mcmodel=medany -march=rv64imafdcv -mabi=lp64d -Wall -Wno-cpp -std=gnu99 -fdiagnostics-color=always -fPIC -O2 -I . -I /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v/../../.. -fPIC vdso_sys.c
riscv64-linux-musleabi-gcc -o /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/build/libvdso.so -mcmodel=medany -march=rv64imafdcv -mabi=lp64d -Bsymbolic -Wl,--gc-sections -T /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v/vdso.lds -shared vdso_sys.os
/home/u/ws/test-rtt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../lib/gcc/riscv64-linux-musleabi/12.2.0/../../../../riscv64-linux-musleabi/bin/ld: vdso_sys.os: can't link double-float modules with soft-float modules
/home/u/ws/test-rtt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../lib/gcc/riscv64-linux-musleabi/12.2.0/../../../../riscv64-linux-musleabi/bin/ld: failed to merge target specific data of file vdso_sys.os
collect2: error: ld returned 1 exit status
scons: *** [/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/build/libvdso.so] Error 1
scons: building terminated because of errors.
CalledProcessError: Command '['scons', '-C', '/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v']' returned non-zero exit status 2.:
  File "/home/u/ws/canaan/rt-thread/bsp/k230/SConstruct", line 61:
    objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  File "/home/u/ws/canaan/rt-thread/bsp/k230/../../tools/building.py", line 408:
    objs.extend(SConscript(Rtt_Root + '/components/SConscript',
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/SConscript", line 15:
    objs = objs + SConscript(os.path.join(item, 'SConscript'))
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/lwp/SConscript", line 57:
    group = group + SConscript(os.path.join('vdso', 'SConscript'))
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/lwp/vdso/SConscript", line 41:
    result = subprocess.run(command, env=process_env, check=True)
  File "/usr/lib/python3.10/subprocess.py", line 526:
    raise CalledProcessError(retcode, process.args,

看上去编译选项并没有修改成功。简单跟踪了一下代码,感觉 if soft_fpu: 还是判断成功了的。

@BernardXiong
Copy link
Member Author

我尝试应用该补丁后,menuconfig 换成 ”FPU precision (Software floating-point)“ ,工具链换成 ”riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest“, 编译报错:

scons: Reading SConscript files ...
scons: Entering directory `/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
riscv64-linux-musleabi-gcc -o vdso_sys.os -c -mcmodel=medany -march=rv64imafdcv -mabi=lp64d -Wall -Wno-cpp -std=gnu99 -fdiagnostics-color=always -fPIC -O2 -I . -I /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v/../../.. -fPIC vdso_sys.c
riscv64-linux-musleabi-gcc -o /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/build/libvdso.so -mcmodel=medany -march=rv64imafdcv -mabi=lp64d -Bsymbolic -Wl,--gc-sections -T /home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v/vdso.lds -shared vdso_sys.os
/home/u/ws/test-rtt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../lib/gcc/riscv64-linux-musleabi/12.2.0/../../../../riscv64-linux-musleabi/bin/ld: vdso_sys.os: can't link double-float modules with soft-float modules
/home/u/ws/test-rtt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/../lib/gcc/riscv64-linux-musleabi/12.2.0/../../../../riscv64-linux-musleabi/bin/ld: failed to merge target specific data of file vdso_sys.os
collect2: error: ld returned 1 exit status
scons: *** [/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/build/libvdso.so] Error 1
scons: building terminated because of errors.
CalledProcessError: Command '['scons', '-C', '/home/u/ws/canaan/rt-thread/components/lwp/vdso/user/arch/risc-v']' returned non-zero exit status 2.:
  File "/home/u/ws/canaan/rt-thread/bsp/k230/SConstruct", line 61:
    objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  File "/home/u/ws/canaan/rt-thread/bsp/k230/../../tools/building.py", line 408:
    objs.extend(SConscript(Rtt_Root + '/components/SConscript',
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/SConscript", line 15:
    objs = objs + SConscript(os.path.join(item, 'SConscript'))
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/lwp/SConscript", line 57:
    group = group + SConscript(os.path.join('vdso', 'SConscript'))
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/u/ws/canaan/rt-thread/components/lwp/vdso/SConscript", line 41:
    result = subprocess.run(command, env=process_env, check=True)
  File "/usr/lib/python3.10/subprocess.py", line 526:
    raise CalledProcessError(retcode, process.args,

看上去编译选项并没有修改成功。简单跟踪了一下代码,感觉 if soft_fpu: 还是判断成功了的。

唔,是vdso那边有些问题,会默认绑定rtconfig.py中的配置,而不认动态修改的。所以目前按soft-fpu方式使用,需要关闭vdso才行。

@unicornx
Copy link
Contributor

唔,是vdso那边有些问题,会默认绑定rtconfig.py中的配置,而不认动态修改的。所以目前按soft-fpu方式使用,需要关闭vdso才行。

你是准备继续修改这个问题,还是说打算让用户自己配置解决?

如果是配置,是否可以在 enable soft-fpu 时联动解决,否则如果要用户自己手动配置,则还要改 readme

@unicornx
Copy link
Contributor

加入Soft-FPU的选项,以兼容到类似qemu-riscv64的方式。

请问这个所谓兼容是指将工具链切换到 https://download.rt-thread.org/download/rt-smart/toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2 的意思吗? 也就是说如果需要使用上述工具链,那么需要编译时手动选择 “FPU precision (Software floating-point)” 对吗?

这个问题是否有回复?

@BernardXiong
Copy link
Member Author

加入Soft-FPU的选项,以兼容到类似qemu-riscv64的方式。

请问这个所谓兼容是指将工具链切换到 https://download.rt-thread.org/download/rt-smart/toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2 的意思吗? 也就是说如果需要使用上述工具链,那么需要编译时手动选择 “FPU precision (Software floating-point)” 对吗?

这个问题是否有回复?

是的,当使用soft-fpu时,就对应上面的这个工具链(riscv64-linux-musleabi-)。这个也是目前smart build中用的工具链。

@BernardXiong
Copy link
Member Author

唔,是vdso那边有些问题,会默认绑定rtconfig.py中的配置,而不认动态修改的。所以目前按soft-fpu方式使用,需要关闭vdso才行。

你是准备继续修改这个问题,还是说打算让用户自己配置解决?

如果是配置,是否可以在 enable soft-fpu 时联动解决,否则如果要用户自己手动配置,则还要改 readme

这个暂时需要用户手动配置下。后续在vdso那边,想办法修复下。

@unicornx
Copy link
Contributor

这个暂时需要用户手动配置下。后续在vdso那边,想办法修复下

还有办法在 kconfig 中确保当我们选择 BSP_RISCV_FPU_D 时自动强制 disable RT_USING_VDSO?我没有找到好的办法。

如果没有办法确保配置自动 disable,请在这个 PR 中补充 README 文件说明需要人工操作。等后续 vdso 那边修复了再删除。

Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

见上面的评论,如果不能自动配置实现,需要更新 readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants