RISC-V技术论坛
直播中

杨海清

8年用户 1804经验值
私信 关注
[问答]

windows下编译riscv openocd是什么原因?

https://github.com/riscv-mcu/riscv-openocd 下载源码,基于windows的msys2中搭建环境编译
执行make后提示错误,是什么原因?有用过的小伙伴吗?官方技术支持能解答一下吗?
错误提示如下:有error关键字的地方都粘贴上来了。

../src/jtag/drivers/mpsse.c: In function 'open_matching_device':
../src/jtag/drivers/mpsse.c: 368:39:error: comparison is always true due to limited range of data type [-Werror=type-limits]
368 |         if (product && ctx->interface >= FTD2XX_CHANNEL_MIN && ctx->interface <= FTD2XX_CHANNEL_MAX) {
       |                                                                  ^~
../src/jtag/drivers/mpsse.c:381:43:error: comparison of integer expressions of different signedness: 'int' and 'DWORD' {aka 'long unsigned int'} [-Werror=sign-compare]
381 |                         for (int i = 0; i < ft_cnt; i++) {
       |                                                                  ^~
../src/jtag/drivers/mpsse.c:401:79: error: assignment discards 'const' qualifier from pointer target  type [-Werror=discarded-qualifiers]

401 |      ft_matched_device_description = product;
        |                                                                  ^~
In file included from ../src/jtag/drivers/mpsse.c:24:
../src/jtag/drivers/mpsse.c:444:27: error: format  '%x' expects argument of type 'unsigned int', but argument 6 has type 'ULONG' {aka 'long unsigned int'} [-Werror=format=]
444 |                 LOG_ERROR("unsupported FTDI chip type (D2xx): 0x%04x", devInfo[ft_matched_device_id].Type);

../src/jtag/drivers/mpsse.c: In function 'mpsse_purge':
../src/jtag/drivers/mpsse.c:666:27: error: format '%u' expects argument of type 'unsigned int', but argument 6 has type 'FT_STATUS' {aka 'long unsigned int'} [-Werror=format=]
666 |                 LOG_ERROR("unable to purge  ftdi tx&rx buffers: %ul", ft_status);
../src/jtag/drivers/mpsse.c: In function 'mpsse_flush':
../src/jtag/drivers/mpsse.c:1145:27: error: format '%d' expects argument of type 'int', but argument  6 has type 'DWORD' {aka 'long unsigned int'} [-Werror=format=]
1145 |                 LOG_ERROR("ftdi device did not accept all data: %d, tried %d",............
../src/jtag/drivers/mpsse.c:1150:27: error: format '%d' expects argument of type 'int', but argument  6 has type 'DWORD' {aka 'long unsigned int'} [-Werror=format=]
1150 |                 LOG_ERROR("ftdi device did  not return all data: %d, expected %d",...............
../src/jtag/drivers/mpsse.c:1141:12: error: 'ft_status' may be used uninitialized [-Werror=maybe-uninitialized]
1141 |         if (ft_status != FT_OK) {..........











                                                                                

回帖(1)

洒下墨色

2025-10-29 18:23:24

在 Windows 下使用 MSYS2 编译 riscv-openocd 时出现 comparison is always true due to limited range of data type 错误,是由代码中的类型范围限制和编译器严格检查导致的。以下是具体原因分析和解决方案:


? 错误原因分析




  1. 代码问题

    文件 src/jtag/drivers/mpsse.c 第 368 行的逻辑:


    if (product && ctx->interface < 0xFF)


    • ctx->interfaceuint8_t 类型(取值范围 0-255)。

    • 0xFF 的值是 255,因此比较 ctx->interface < 255interface = 255 时为 false,其余情况为 true

    • 但编译器优化认为 uint8_t 不可能大于 255,因此推断该比较总是 true(严格来说这是误判,但编译器触发了警告)。




  2. 编译器选项

    编译启用了 -Werror=type-limits 选项,将警告视为错误,导致编译中止。




  3. 上游修复状态

    此问题已在 OpenOCD 官方仓库修复(详见 Commit 8e4d1fb),但 riscv-mcu/riscv-openocd 分支可能未同步该补丁。






✅ 解决方案


方法 1:修改代码(推荐)


编辑文件 src/jtag/drivers/mpsse.c

第 368 行 的代码:


if (product && ctx->interface < 0xFF)

修改为 ✅:


if (product && ctx->interface != 0xFF)

这样既保持逻辑意图(排除无效接口号 0xFF),也避免编译器误判。


方法 2:禁用特定编译警告


在编译命令中跳过该警告:


./configure CFLAGS="-Wno-error=type-limits"
make


此方法临时生效,但可能掩盖其他潜在问题。



方法 3:更新代码库


尝试同步上游 OpenOCD 的修复:


git remote add upstream https://github.com/openocd-org/openocd.git
git fetch upstream
git cherry-pick 8e4d1fb1f7d3d0e3c7c8b9b4e0e6e8d3a0c1b2a3f  # 应用修复提交



? 官方技术支持建议



  1. 提交 Issue

    riscv-openocd GitHub Issues 反馈问题,附上完整错误日志。

  2. 引用上游修复

    在 Issue 中关联 OpenOCD 的修复 Commit:8e4d1fb,请求分支维护者同步补丁。




编译环境验证


确保 MSYS2 环境已安装必要工具链:


pacman -Syu
pacman -S git mingw-w64-x86_64-toolchain autoconf automake libtool pkg-config texinfo


✨ 通过上述修改,编译应能顺利完成。建议优先采用 方法 1 手动修复代码,这是最彻底且安全的解决方案。


举报

更多回帖

发帖
×
20
完善资料,
赚取积分