st-flash write dirtyjtag.bluepill.noloader.bin 0x08000000I have also used OpenOCD along with the ST-link v2 to do some debugging. I was shocked and amazed to discover that I could use openOCD along with gdb and single step my way through bootrom code.
I am now interested in learning what I can do with openOCD on my Zynq based boards (like the Ebaz-4205 and the Zeboard). Can I single step through the bootrom code? Can I download and run executables? How useful is OpenOCD without also using gdb along with it?
I am using "Versaloon" as a USB to JTAG "adapter" for the Zynq boards. I also have a XVC (Xilinx Virtual Cable) available via an xvc-pico adapter. The latter works fine with Vivado, but it is unclear how or if it can be used with OpenOCD.
The STM32F103 is a popular $2 board commonly known as the "blue pill".
I used to flash code to it as follows (these days I use st-flash):
openocd $(OCDCFG) -c "program blink.elf verify reset exit"This would typically be part of a Makefile, and I may as well just show that here:
OCDCFG = -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg flash: blink.elf openocd $(OCDCFG) -c "program blink.elf verify reset exit" old_flash: @echo "type: flash write_image erase blink.bin 0x08000000" telnet localhost 4444 gdb: $(GDB) --eval-command="target remote localhost:3333" blink.elf gdbtui: $(GDB) -tui --eval-command="target remote localhost:3333" blink.elfThe OCDCFG variable has the pointers to the startup script needed to tell OpenOCD what adapter I want to use. Note the "old_flash" entry which coaches me what to type to the telnet connection it then launches. Finally we have entries to launch gdb in two flavors, first the plain command line, and second using the "-tui" (text user interface) option. Using gdb presumes that I already have an OpenOCD process running, which I would start in another window by typing this:
openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg
arm-none-eabi-gdbThis used to be conveniently provided as a Fedora package (like all of the other parts of the ARM toolchain). Somewhere along the line this vanished. It is now (at least circa Fedora 39) available from a COPR (cool other projects repository), which is nice.
If you are using some other distribution, you may not have this headache, or maybe you will have worse headaches.
I will point out that chapter 23 of the OpenOCD manual is a "Tcl Crash course". So far my use of OpenOCD has not required me to work with Tcl, but I suppose the day is coming and the painful experiences of my past may be of benefit.
The OpenOCD manual tells us that it incorporates "Jim-Tcl" which is a small and stripped down version of the Tcl language. I am cool with all of this but ignoring it at the present time.
I'll also note in passing that Xilinx also uses Tcl as a "glue language" in much the same way as a part of many of their tools. So you have a choice between using their GUI interfaces or doing command line work and dealing with Tcl. Good to know and someday may be very useful.
I connect my Versaloon adapter to the 14 pin JTAG connector on my EBAZ board, plug in the USB cable and then do this in one windows to start the OpenOCD server:
openocd -f versaloon.cfg Open On-Chip Debugger 0.12.0Then in another window, I do this:
telnet localhost 4444 Open On-Chip Debugger > scan_chain TapName Enabled IdCode Expected IrLen IrCap IrMask -- ------------------- -------- ---------- ---------- ----- ----- ------ 0 auto0.tap Y 0x13722093 0x00000000 2 0x01 0x03 1 auto1.tap Y 0x4ba00477 0x00000000 2 0x01 0x03This is Fedora 39 and I got OpenOCD from the standard fedora packages.
adapter driver vsllink vsllink usb_vid 0x0483 vsllink usb_pid 0xA038 adapter speed 100 transport select jtagNote that the speed is in kHz units, so this asks for an adapter speed of 100 kHz.
Info : clock speed 100 kHz
I originally thought this was 100 Hz and was deeply concerned. It may be possible to go fast once other clocks are set up. The guideline is that the JTAG clock can be 1/6 of the CPU clock (or less).
This all works as far as me typing the "scan_chain" command, but going further requires me to learn more, which is exactly why we are here.
Note that I could rename versaloon.cfg to openocd.cfg and as long as I start openocd in my project directory, I won't need any arguments to openocd.
/usr/share/openocd/scripts/interface /usr/share/openocd/scripts/board /usr/share/openocd/scripts/targetIn my case, I see:
/usr/share/openocd/scripts/interface/vsllink.cfg /usr/share/openocd/scripts/board/digilent_zedboard.cfg /usr/share/openocd/scripts/target/zynq_7000.cfgI should probably take a look at these files, but for now I am just pressing on with my versaloon.cfg script.
I gave this a brief try, but it got all kinds of errors:
cp /usr/share/openocd/scripts/target/zynq_7000.cfg zynq.cfg openocd -f versaloon.cfg -f zynq.cfgClearly I am getting ahead of myself.
Page 70 of the manual is "Autoprobing" and openOCD does this without you asking apparently when you launch it and at least get it using the correct adapter driver. And it spits out the result of autoprobing right in the mess of startup messages that you and I have been simply ignoring:
Info : clock speed 100 kHz Warn : There are no enabled taps. AUTO PROBING MIGHT NOT WORK!! Info : JTAG tap: auto0.tap tap/device found: 0x13722093 (mfg: 0x049 (Xilinx), part: 0x3722, ver: 0x1) Info : JTAG tap: auto1.tap tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4) Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -irlen 2 -expected-id 0x13722093" Warn : AUTO auto1.tap - use "jtag newtap auto1 tap -irlen 2 -expected-id 0x4ba00477" Warn : gdb services need one or more targets definedAt least one useful bit of information is that "auto0.tap" is Xilinx, so it is probably the PL section of the Zynq (the FPGA). The other, "auto1.tap" is ARM, so that is probably the PS section of the Zynq (the dual core ARM).
So, I have tried playing with it, and now even after a power cycle of both the Ebaz and the versaloon I get:
Info : clock speed 100 kHz Info : JTAG tap: auto1.tap tap/device found: 0x13722093 (mfg: 0x049 (Xilinx), part: 0x3722, ver: 0x1) Warn : JTAG tap: auto1.tap UNEXPECTED: 0x13722093 (mfg: 0x049 (Xilinx), part: 0x3722, ver: 0x1) Error: JTAG tap: auto1.tap expected 1 of 1: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4) Info : JTAG tap: auto0.tap tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4)No longer does it tell me there are no enabled taps. Perhaps there is a way to command a JTAG reset,
Note that Versaloon controls neither SRST or RRST, which is certainly a liability.
Tom's Computer Info / tom@mmto.org