【MACOS(M1)编译Risc-v版OpenOCD】

准备1

  • Installing the Mac OSX Command Line Tools, 输入:
xcode-select --install 
  • Install autoconf, automake, pkg-config, libtool and texinfo.
brew install autoconf automake pkg-config libtool texinfo 

下载代码:

git clone --recursive https://github.com/riscv/riscv-openocd.git

执行顺序

进入到riscv-openocd目录下,执行:

./bootstrap
./configure
make
make install

常见问题

问题1: AC_PROG_CC_C99 告警2

在执行./bootstrap的时候可能会报warning

+ aclocal --warnings=all
+ glibtoolize --automake --copy
+ autoconf --warnings=all
+ autoheader --warnings=all
+ automake --warnings=all --gnu --add-missing --copy
Setting up submodules
Generating build system...
configure.ac:38: warning: The macro `AC_PROG_CC_C99' is obsolete.
configure.ac:38: You should run autoupdate.
./lib/autoconf/c.m4:1659: AC_PROG_CC_C99 is expanded from...
configure.ac:38: the top level
Bootstrap complete. Quick build instructions:
./configure ....

这里提示configure.ac第38行有告警。开始以为是当前目录下的configure.ac文件有不兼容的问题。其实注释掉openocd-code/src/jtag/drivers/libjaylink/configure.ac.文件的第38行就可以了。

修改后重新执行,log显示不再有告警:

+ aclocal --warnings=all
+ glibtoolize --automake --copy
+ autoconf --warnings=all
+ autoheader --warnings=all
+ automake --warnings=all --gnu --add-missing --copy
Setting up submodules
Generating build system...
Bootstrap complete. Quick build instructions:
./configure ....

问题2: texinfo 版本不匹配

brew install texinfo 后执行
export PATH=“/opt/homebrew/opt/texinfo/bin:$PATH”

问题2: libtool版本不匹配

系统目录下/usr/bin/libtool版本较旧,我的是2.4.6
用brew install libtool后会安装新的libtool,版本2.4.7,需要用环境变量执行新安装的目录。

执行下面命令可以看到安装后的信息。

> brew info libtool
...
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
  PATH="/opt/homebrew/opt/libtool/libexec/gnubin:$PATH"

注意添加path后立即执行make是不生效的。原因是在config阶段会copy libtool到当前目录下,后面make阶段调用的都是当前目录下的libtool。这时需要手动删除当前目录下的libtool,然后重新执行./configure

问题3: 编译错误

编译产生如下错误:

src/flash/nor/dsp5680xx_flash.c:48:11: error: variable 'offset' set but not used [-Werror,-Wunused-but-set-variable]
        uint32_t offset = HFM_FLASH_BASE_ADDR;
                 ^
1 error generated.

看起来是可以waive掉的问题。打开configure.ac文件,找到Werror的地方,注释的这个选项。如下:

AS_IF([test "x${gcc_werror}" = "xyes"], [
   #GCC_WARNINGS="${GCC_WARNINGS} -Werror"
   GCC_WARNINGS="${GCC_WARNINGS}"
 ])

验证一下

> openocd --version
Open On-Chip Debugger 0.11.0+dev-02377-g911d68ef2-dirty (2022-09-15-09:24)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html

显示已经安装成功了。


  1. https://www.mail-archive.com/autoconf@gnu.org/msg24261.html ↩︎

  2. https://www.mobilefish.com/developer/riscv/riscv_quickguide_build_riscv_openocd.html#:~:text=%20How%20to%20build%20RISC-V%20OpenOCD%20on%20macOS.,The%20following%20tools%20are%20required%3A%0Aautoconf%2C%20automake%2C…%20More%20 ↩︎


版权声明:本文为poena原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。