riscv-openocd-windows

介绍如何编译windows版本的openocd。

Environment

本文是介绍在Arch Linux系统上,进行交叉编译,得到最终的exe文件,再在windows下运行openocd的方法。

Host OS: Arch Linux WSL

Compiler: mingw-w64-gcc

Library: libusb-1.0.23, automake, autoconf

Openocd: riscv-openocd

Step by step:

Installation

1
2
3
4
5
6
7
$ cd ricv-openocd
$ rm jimtcl
$ mv ../jimtcl-51f65c6d38fbf86e1f0b036ad336761fd2ab7fa0 ./jimtcl
$ ./bootstrap nosubmodule
$ LIBUSB1_CFLAGS="-I/mnt/d/software/libusb-1.0.23/include/libusb-1.0" LIBUSB1_LIBS="-L/mnt/d/software/libusb-1.0.23/MinGW32/dll" ./configure --host=i686-w64-mingw32 --enable-ftdi
$ make CFLAGS='-Wno-implicit-fallthrough -Wno-tautological-compare'
$ make install

由于编译器比较新,有些错误,所以改了CFLAG。另外还改了下src/jtag/drivers/libjaylink/config.h

1
#define __USE_MINGW_ANSI_STDIO 1

=>

1
2
3
4
#ifdef __USE_MINGW_ANSI_STDIO
# undef __USE_MINGW_ANSI_STDIO
#endif
#define __USE_MINGW_ANSI_STDIO 1

如果一切顺利,在/usr/local下面生成目标文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ tree .
.
├── bin
│   └── openocd.exe
├── etc
├── games
├── include
├── lib
├── man
│   └── man1
│   └── openocd.1
├── sbin
├── share
│   ├── info
│   │   ├── dir
│   │   ├── openocd.info
│   │   ├── openocd.info-1
│   │   └── openocd.info-2
│   ├── man -> ../man
│   └── openocd

然后把它打包整个拷贝出来

1
2
$ tar czf ~/openocd.tar.gz /usr/local/
$ cp ~/openocd.tar.gz /mnt/d/software/

然后到windows把libusb的dll也拷贝到bin目录下

1
cp /mnt/d/software/libusb-1.0.23/MinGW32/dll/libusb-1.0.dll /mnt/d/software/openocd\usr\local\bin

然后到windows下面执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
D:\software\openocd\usr\local\bin>.\openocd.exe --help
Open On-Chip Debugger 0.10.0+dev-snapshot (2020-07-29-20:19)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Open On-Chip Debugger
Licensed under GNU GPL v2
--help | -h display this help
--version | -v display OpenOCD version
--file | -f use configuration file <name>
--search | -s dir to search for config files and scripts
--debug | -d set debug level to 3
| -d<n> set debug level to <level>
--log_output | -l redirect log output to file <name>
--command | -c run <command>

Download

编译好的可执行文件也可以在sifive官网下载。

https://static.dev.sifive.com/dev-tools/riscv-openocd-0.10.0-2020.04.6-x86_64-w64-mingw32.zip?_ga=2.194046829.1921518046.1596069236-38171805.1596069236

或者

https://www.sifive.com/boards#software