Skip to content

OpenOCD

Carlos Moratelli edited this page Apr 6, 2017 · 25 revisions

This section will introduce OpenOCD and guide you through its installation.

What is OpenOCD?

From OpenOCD documentation:

OpenOCD provides on-chip programming and debugging support with a layered architecture of JTAG interface and TAP support including:

  • (X)SVF playback to faciliate automated boundary scan and FPGA/CPLD programming;
  • debug target support (e.g. ARM, MIPS): single-stepping, breakpoints/watchpoints, gprof profiling, etc;
  • flash chip drivers (e.g. CFI, NAND, internal flash);
  • embedded TCL interpreter for easy scripting.

Several network interfaces are available for interacting with OpenOCD: telnet, TCL, and GDB. The GDB server enables OpenOCD to function as a "remote target" for source-level debugging of embedded systems using the GNU GDB program (and the others who talk GDB protocol, e.g. IDA Pro).

The OpenOCD supports:

  • MIPS processors;
  • Cheaper hardware debuggers, like the Bus Blaster V3c;
  • GDB.

These features make it a complete solution for embedded MIPS debugging.

OpenOCD source code

While debugging you need to be able to stop the target execution at a specific address or function, for example, to read the value of the variables, or to execute step-by-step. For this, you should configure breakpoints to make it stop when desired. You can use source code symbols, like function names or line numbers, to specify a breakpoint. However, at a low level, the debugger probe will use the virtual address corresponding to your symbol. In a typical virtualized environment, different guests will have different symbols conflicting at the same virtual addresses. Of course, this is not a problem for virtualization since the hypervisor keeps the guests at a different physical address using the virtual memory to map physical to virtual addresses. However, to debug in a virtualized environment, it is necessary to associate the breakpoint's virtual address to the guest that will be debugged. Otherwise, the target will be stopped every time that the virtual address is reached, it doesn't matter who the guest is.

In the MIPS-VZ architecture, the guest ID is a number that identifies the guest that is running. During the context-switching, the hypervisor writes the guest ID to the guestCtl1 register. Thus, by combining the guest ID with a virtual address it is possible to create breakpoints for a specific guest.

The GDB allows for the creation of conditional breakpoints, where the target will be stopped only when the conditions match these specifications. Thus, GDB needs the ability to read the guestctl1 register to match the guest ID field. The original version of OpenOCD does not return the guestctl1 for GDB inspection. Thus, a modified version of OpenOCD is required.

You can see the modified OpenOCD version on GitHub.

Installing OpenOCD

  • If you still don't have libtool, automake and libusb packages installed on your host, please install them:
sudo apt-get install libtool automake libusb-1.0-0-dev
  • Clone the git repository.
git clone https://github.com/crmoratelli/OpenOCD-0.10.0.git
  • In OpenOCD-0.10.0 folder, configure and compile the code.
./bootstrap
./configure --enable-ftdi --disable-werror
make
  • Install it in your system.
sudo make install

Detecting your Bus Blater V3c probe

Connect the BB probe to a USB port on your host machine. Use the dmesg shell command to read your system’s log. It should detect the BB probe:

usb 2-2: new high-speed USB device number 2 using ehci-pci
usb 2-2: New USB device found, idVendor=0403, idProduct=7780
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: BUSBLASTERv3c
usb 2-2: Manufacturer: FTDI
usb 2-2: SerialNumber: FTZ5VTI4

In the prplHypervisor source code, go to the Chipkit Wi-Fire platform folder and open the dp_busblaster.cfg file:

prpl-hypervisor/platform/pic32mz_chipkit_Wifire/debug/dp_busblaster.cfg

Make sure that the ftdi_device_desc property corresponds to the Product number from your system’s log. Additionally, the ftdi_vid_pid must correspond to the idVendor and idProduct. Otherwise, OpenOCD will not detect the BB probe.

Now, execute OpenOCD with root privileges.

 sudo openocd -f debug/dp_busblaster.cfg -f debug/wifire.cfg -c "init"

Note: You should be at the prpl-hypervisor/platform/pic32mz_chipkit_Wifire folder.

As a result, you should see the following output from OpenOCD:

Open On-Chip Debugger 0.10.0-IMG-g6f296b8 (2017-01-31-09:32)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : If you need SWD support, flash KT-Link buffer from https://github.com/bharrisau/busblaster and use dp_busblaster_kt-link.cfg instead
adapter_nsrst_delay: 100
Info : auto-selecting first available session transport "jtag". To override use 'transport select '.
jtag_ntrst_delay: 100
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
adapter speed: 5000 kHz
scan delay: 20000000 nsec
running in legacy mode
reb (Setup for an EJTAGBOOT indicated reset.)
rnb (Setup for a NORNALBOOT indicated reset.)
rnb
Info : clock speed 5000 kHz
Info : JTAG tap: pic32mz.cpu tap/device found: 0x1720e053 (mfg: 0x029 (MicrochipTechnology), part: 0x720e, ver: 0x1)

OpenOCD executes as a system daemon and you need to connect to it using telnet or GDB. See instructions for GDB debugging here.