Building OpenOCD on Windows
Previously, I have enabled a GDB debug flow on RPi3. However, I find GDB can NOT access ALL system registers of A53. It is then inconvenient to debug/trace bare-metal applications, such as ATF.
Mete Balci in https://metebalci.com/blog/bare-metal-rpi3-programming/ has enabled this feature in telnet server of OpenOCD. Unfortunately, it is not merged to main stream yet. If I need the feature, I have to build my own OpenOCD and merge the patch.
Get Burst Accessing’s stories in your inbox
Join Medium for free to get updates from this writer.
I first installed MSYS2 as https://sourceforge.net/p/openocd/code/ci/master/tree/README.Windows suggested. The version I installed is msys2-x86_64–20190524.exe. First of all, follow MSYS2’s setup guide to update itself:
pacman -Syu
pacman -SuThen install required package to build OpenOCD. According to https://sourceforge.net/p/openocd/code/ci/master/tree/README:
pacman -S --disable-download-timeout make libtool pkg-config autoconf automake texinfo mingw-w64-x86_64-libusbSome tips:
- Add “disable-download-timeout” to prevent from timeout when retrieving packages.
- OpenOCD document only mentions that it needs libusb. But it can’t be simply found in MSYS2. Turns out the key word is “mingw-w64-x86_64-libusb”
More packages are required beyond OpenOCD document:
pacman -S --disable-download-timeout mingw-w64-x86_64-toolchain gitNotes:
- While installing package “gcc” is able to build OpenOCD, the conducted executable halts with a error message:
Error: error creating socket: No error. According to https://www.oipapio.com/question-3938433, using “mingw-w64-x86_64-toolchain” workaround the problem. - OpenOCD clones other projects during build process, therefore package “git” is required.
Finally I can start to build OpenOCD. I already cloned OpenOCD to “p:\openocd-code” on Windows:
cd /p/openocd-code
./bootstrap
./configure --enable-ftdi --disable-werror --disable-doxygen-html --disable-doxygen-pdf --disable-gccwarnings --disable-wextra --disable-stlink --disable-ti-icdi --disable-ulink --disable-usb-blaster-2 --disable-ft232r --disable-vsllink --disable-xds110 --disable-osbdm --disable-opendous --disable-jlink --disable-aiceNote that “disable-werror” is necessary, since there are some warnings in OpenOCD that break GCC compilation. “enable-ftdi” is also required for using FT4232. Others are just for reducing build time. Seeing messages like
OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices yes
ST-Link Programmer no
TI ICDI JTAG Programmer no
Keil ULINK JTAG Programmer no
Altera USB-Blaster II Compatible no
Bitbang mode of FT232R based devices no
Versaloon-Link JTAG Programmer no
TI XDS110 Debug Probe no
OSBDM (JTAG only) Programmer no
eStick/opendous JTAG Programmer no
Andes JTAG Programmer no
USBProg JTAG Programmer no
Raisonance RLink JTAG Programmer no
Olimex ARM-JTAG-EW Programmer no
CMSIS-DAP Compliant Debugger no
Cypress KitProg Programmer no
Altera USB-Blaster Compatible no
ASIX Presto Adapter no
OpenJTAG Adapter no
SEGGER J-Link Programmer nomeans OpenOCD build requirement is met. While applying
makeshould produce executable ./src/openocd.exe, I experienced errors:
...
copying selected object files to avoid basename conflicts...
libtool: link: ln src/flash/.libs/libflash.lax/libocdflashnand.a/core.o src/flash/.libs/libflash.lax/lt1-core.o || cp src/flash/.libs/libflash.lax/libocdflashnand.a/core.o src/flash/.libs/libflash.lax/lt1-core.o
libtool: link: ln src/flash/.libs/libflash.lax/libocdflashnand.a/tcl.o src/flash/.libs/libflash.lax/lt2-tcl.o || cp src/flash/.libs/libflash.lax/libocdflashnand.a/tcl.o src/flash/.libs/libflash.lax/lt2-tcl.o
libtool: link: ar cru src/flash/.libs/libflash.a src/flash/common.o src/flash/mflash.o ... /libocdflashnand.a/s3c6400.o src/flash/.libs/libflash.lax/lt2-tcl.o
ar: src/flash/.libs/libflash.lax/lt1-core.o: No such file or directory
make[2]: *** [Makefile:2119: src/flash/libflash.la] Error 1
...It seems some files are missing, while running following commands are okay:
# ls -l src/flash/.libs/libflash.lax/lt1-core.o
-rw-r--r-- 1 brxx Domain Users 56535 Jul 18 08:27 src/flash/.libs/libflash.lax/lt1-core.oMy best guess is some lateny between Windows, Samba, or Linux. Greping key words copying selected object files returns “libtool.” Adding 10 sec. delay after “ln … || cp …” seems workaround the problem:
echo “copying selected object files to avoid basename conflicts…”
gentop=$output_objdir/${outputname}x
...
func_show_eval “ln $obj $gentop/$newobj || cp $obj $gentop/$newobj”
func_show_eval “sleep 10”
func_append oldobjs “ $gentop/$newobj”
...After all, the build process is completed, and executable is generated. Successful running .\src\openocd.exe -f .\interface\ftdi\ft4232h.cfg -f .\target\rpi3.cfgmeans build okay. Apply patch and build again to enjoy full access of system registers
$ telnet localhost 4444
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
Open On-Chip Debugger
> halt
rpi3.a53.3 cluster 0 core 3 multi core
target halted in AArch64 state due to debug-request, current mode: EL3H
cpsr: 0x000003cd pc: 0x4
MMU: disabled, D-Cache: disabled, I-Cache: disabled
> aarch64 mrs SCTLR_EL3
SCTLR_EL3 [10_010_0000_0000_000]: 0x0000000000c50838
.DSSBS =0x0 =0b0
.ATA =0x0 =0b0
.TCF =0x0 =0b00
.ITFSB =0x0 =0b0
.BT =0x0 =0b0
.EnIA =0x0 =0b0
.EnIB =0x0 =0b0
.EnDA =0x0 =0b0
.EE =0x0 =0b0
.EIS =0x1 =0b1
.IESB =0x0 =0b0
.WXN =0x0 =0b0
.EnDB =0x0 =0b0
.I =0x0 =0b0
.EOS =0x1 =0b1
.nAA =0x0 =0b0
.SA =0x1 =0b1
.C =0x0 =0b0
.A =0x0 =0b0
.M =0x0 =0b0





