-
Notifications
You must be signed in to change notification settings - Fork 5.1k
bsp: k230: support canmv-k230 #10221
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
Conversation
651d29e
to
255edf0
Compare
There was a problem hiding this 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 updates the BSP for the K230 platform to support the more widely used CanMV-K230 board, along with various code cleanups and synchronizations with the latest mainline. Key changes include:
- Modification of toolchain and build configuration in rtconfig.py, including enhanced RTT_ROOT resolution and updated compiler paths.
- Updates to kernel configuration settings in rtconfig.h (e.g. version, memory layout, and new driver options).
- Driver updates (especially in the UART driver) and board memory map adjustments to better reflect the CanMV-K230 hardware.
- Enhancements in the SConstruct build script to generate the linker script automatically.
Reviewed Changes
Copilot reviewed 8 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
bsp/k230/rtconfig.py | Updates to toolchain paths, environment variable fallback, and build configuration logic |
bsp/k230/rtconfig.h | Kernel configuration updates and new options for klibc, memory management, and drivers |
bsp/k230/drivers/interdrv/uart/drv_uart.c | Improvements in UART initialization, hardware mapping, and safety checks in ISR |
bsp/k230/board/mem_layout.h | Addition of detailed memory layout definitions for the board |
bsp/k230/board/board.h & board.c | Expanded board hardware definitions and a modified static assert check with a FIXME hint |
bsp/k230/SConstruct | Revised linker script generation logic replacing the manual stack linker script generation |
bsp/k230/README.md | Detailed and updated user instructions for building and flashing the BSP for different setups |
Files not reviewed (4)
- bsp/k230/.config: Language not supported
- bsp/k230/.gitignore: Language not supported
- bsp/k230/link.lds: Language not supported
- bsp/k230/link_stacksize.lds: Language not supported
Comments suppressed due to low confidence (1)
bsp/k230/drivers/interdrv/uart/drv_uart.c:142
- [nitpick] The condition enforcing a minimum value for 'dll' is critical for baud rate calculation but may not be immediately clear. Consider extracting the minimum value condition into a well-named constant or helper function for improved clarity.
if((dlh == 0) && (dll < 1))
bsp/k230/board/board.c
Outdated
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == 0xffffffc000020000); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static assert now uses a hack (with a FIXME comment) to bypass proper bootloader alignment validation. Consider revisiting this check to implement a robust validation that accurately reflects the production board requirements.
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == 0xffffffc000020000); | |
#define EXPECTED_BOOTLOADER_ALIGNMENT 0xffffffc000020000 /* Replace with dynamic calculation if possible */ | |
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == EXPECTED_BOOTLOADER_ALIGNMENT); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 ASSERT 没有必要,可以删除。
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a list of arguments for subprocess.Popen instead of string concatenation with shell=True to improve cross-platform reliability and reduce potential security risks.
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么改无法解决问题,这个问题以前也提过,see #10202 (comment)
bsp/k230/rtconfig.py
Outdated
|
||
# toolchains options | ||
ARCH ='risc-v' | ||
VENDOR ='t-head' | ||
CPU ='c908' | ||
CROSS_TOOL ='gcc' | ||
|
||
RTT_ROOT = os.getenv('RTT_ROOT', r'../..') | ||
RTT_ROOT = os.getenv('RTT_ROOT', r'../..') or os.path.join(os.getcwd(),'..','..') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using os.getcwd() as a fallback for RTT_ROOT may lead to inconsistent paths if the current working directory isn’t as expected. Consider adding documentation or explicit error handling when RTT_ROOT is not set.
RTT_ROOT = os.getenv('RTT_ROOT', r'../..') or os.path.join(os.getcwd(),'..','..') | |
RTT_ROOT = os.getenv('RTT_ROOT') | |
if not RTT_ROOT: | |
raise EnvironmentError("RTT_ROOT environment variable is not set. Please set it to the root directory of the project.") |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这行代码的修改有问题,已经恢复原来的写法。
Some changes to support canmv board, such as: - Address constant, some may need be set as configuration later. - link script - build script Signed-off-by: Wang Chen <unicorn_wang@outlook.com>
Signed-off-by: Wang Chen <unicorn_wang@outlook.com>
KERNEL_VADDR_START changed to 0xffffffc000020000. __STACKSIZE__ changed to 65536. Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
For linker script, use constant macro defined from rtconfig.h, not immediate value. Also cleanup the link_statksize.lds, it is also not needed when using new mechanism. Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
不同的板卡是否用不同的设备树即可? |
The original code used immediate values directly when it came to memory layout, which was not a good programming habit. Now we use macros and try to be compatible with SDK configuration values in the SDK compilation environment. The main changes are to clean up board.h, and extract some memory layout constants to define a new header file mem_layout.h. Also update KERNEL_VADDR_START to the default value for Smart, so we can use it as base to calculate other mapping address. Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
255edf0
to
d5cca2a
Compare
暂时没有精力支持设备树,目前主要的精力是希望先将 canaan 内部的 vendor bsp 先移植升级到最新的主线,他们的代码没有实现设备树,所以对设备树的支持要计划放在下一阶段考虑了。 另外对于不同 canmv-k230 的板卡支持,目前的方案实际上是有计划兼容 canaan 的 rtos-only sdk 的,具体看 commit “bsp: k230: use configuration instead of immediate value” 的描述。或者看 在没有和 SDK 集成之前,和 canaan 开发组讨论后,决定在 RTT 主线仓库中先只支持默认的 01Studio 512MB。 |
⭐ ⭐ ⭐ 本 PR 包含了 7 个 commit,建议 merge 时不要压缩,保留这 7 个修改记录。
这 7 个 commit 是故意保留的,不是临时的修改记录,一方面方便 review,另一方面方便回溯和 rollback。
原先的 bsp/k230 支持的是 evb 评估版,并不适合社区,现在改为 canmv-k230,并默认支持目前市面上比较常见的 01Studio CanMV-K230 这款板子。
其他是一些代码清理以及和最新的主线同步,为后面增加支持更多的驱动做准备。
更新了 README,详细描述了如何快速烧写。
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up