sean.lawless
Posts: 6
Joined: Thu Jun 06, 2019 6:07 pm

OpenOCD BCM2835 GPIO JTAG bitbang driver

Thu Jun 06, 2019 7:10 pm

Thank you for having such a great forum to ask questions. Based on other online tutorials I created a procedure to use one RPi running Raspbian to act as a OpenOCD JTAG controller to debug a different RPi executing bare metal software.

When I follow the procedure below, the OpenOCD BCM2835 GPIO JTAG bitbang driver executing on Raspbian works better with GDB on some versions of RPI hardware than others. The RPI running Raspbian was an RPI 2 or 3 B+ and there was no difference in functionality between them. The RPI used for the bare metal target system does matter however. The RPI B+ has full GDB support over the OpenOCD BCM2835 bitbang driver. The RPI 2 as a target system could not be debugged with OpenOCD and GDB, while the RPI 3 B+ had limited debugging functionality.

Has anyone had success with debugging RPI 2 or 3 B+ with OpenOCD 0.10 and BCM2835 GPIO bitbang driver? I read that OpenOCD 0.10 has issues with ARM cortex and to use OpenOCD 0.9, but that version does not have the BCM2835 bitbang driver... I would love to resolve this so no matter the RPi it can be debugged with this GPIO JTAG controller and GDB using another RPi. Is anyone else doing this and heard of any work arounds (BCM2835 bitbang for 0.9?). The procedure to use OpenOCD BCM2835 GPIO bitbang driver on Raspbian is cut and pasted from the book to this post below. It is available free of charge (and easier to read) in Chapter 4, click Read Free Sample on the bottom left of this link (https://leanpub.com/computersystems_lab_rpi).

Below is the link to the repository that contains the configuration files linked below.
https://github.com/sean-lawless/computersystems

4.9 GDB and OpenOCD

The GCC ecosystem has GDB (GNU De-Bugger) for debugging executables over a remote JTAG connection to the RPI. On PC development systems it is required to purchase, configure and use a JTAG controller that supports the RPI (ARM) hardware and Windows/Linux OS. JTAG controller procedures are product specific and beyond the scope of this document and some tutorials exist that demonstrate JTAG debugging with the RPI using different off the shelf commercial JTAG compatible controllers. For Linux development PCs, especially for an RPI development PC running Raspbian, there is a unique solution that allows us to use OpenOCD and wire the GPIOs directly between the RPI’s similar to the UART connection. Regardless of the JTAG adapter and physical connection from the development PC to the remote target RPI, the development PC must have the bare metal (arm-none-eabi) version of GDB installed. On Linux this can be accomplished with the following command.

$ sudo apt-get install gdb-arm-none-eabi

OpenOCD, or the Open On-Chip Debugger, is a open source tool that supports JTAG and GDB. A BCM2835 GPIO JTAG bit bang driver was created that allows an RPI development PC to use the GPIOs on the RPI board to bit bang a JTAG controller. This effectively turns the development PC into a JTAG controller at the same time it runs Raspbian. This BCM2835 driver for OpenOCD is still in development but is functional enough to be highly recommended as it requires no additional hardware to purchase. The BCM2835 driver is not included in the OpenOCD official release but can be built into the project at compile time. The following procedure will download the OpenOCD source tree, configure it for the BCM2835 GPIO driver, build the OpenOCD software and then install it on the Raspbian development PC.

First, be sure your Raspbian development PC is up to date.

$ sudo apt-get update
$ sudo apt-get upgrade -y
$ sudo apt-get dist-upgrade -y

Next be sure the dependencies necessary to build OpenOCD are installed before using Git to clone OpenOCD and prepare it for building.

$ sudo apt-get install git autoconf libtool pkg-config libusb-1.0-0 libusb-1.0-0-dev
$ git clone git://git.code.sf.net/p/openocd/code openocd
$ cd openocd
$ ./bootstrap

Now configure, make and install the OpenOCD software on the Raspbian development PC.

$ ./configure --enable-bcm2835gpio --enable-sysfsgpio
$ make
$ sudo make install

4.10 Wiring and Configuring JTAG

With the OpenOCD BCM2835 GPIO JTAG controller installed from the previous chapter, we only need to wire together the RPI development PC with the remote system RPI to enable debugging. The JTAG GPIOs on the RPI are defined beginning with ARM_ in Section 6.2 (page 102) of the BCM2835-ARM-Peripherals.pdf document. This page shows the complete GPIO map for the Raspberry Pi, including all the alternate functions. The JTAG pins are designated through alternate 4 (Alt 4) of GPIO 22 (ARM_TRST), 23 (ARM_RTCK), 24 (ARM_TDO), 25 (ARM_TCK), 26 (ARM_TDI) and 27 (ARM_TMS). These GPIOs map to pin numbers in the picture created by Jamie Bainbridge that shows the all GPIOs of the RPi as exposed by the male pins. The target system software must configure these GPIOs to use select alternate 4 and then physically connect the GPIOs above to the development system PC.

Reference:
https://github.com/sean-lawless/compute ... Lab4%20LED

Fig 4: Raspberry Pi GPIO pinout

For the RPI development PC running Raspbian and using the OpenOCD bit bang JTAG controller, the default configuration file uses the following RPI GPIOs for the JTAG signals, GPIO 7 (ARM_TRST), ? (ARM_RTCK), 9 (ARM_TDO), 11 (ARM_- TCK), 10 (ARM_TDI) and 25 (ARM_TMS). The following table shows the JTAG wiring between the RPI development PC (left) and the remote target RPI (right).

Fig 1: JTAG pin map for RPI development PC to RPI target
GPIO Pin Pin GPIO JTAG Signal
7 24 15 22 ARM_TRST
? ? 16 23 ARM_RTCK*
9 21 18 24 ARM_TDO
11 23 22 25 ARM_TCK
10 37 15 26 ARM_TDI
25 22 13 27 ARM_TMS
- 14 14 - Ground
- 20 39 - Ground
- 25 20 - Ground

Warning
Both RPIs should be powered down before connecting the JTAG GPIOs.

Finally double check all the wiring and execute the created software on the remote system by copying the kernel.img file to the SD card boot folder as previously described in detail in Chapter 3. With the latest LED application executing and the JTAG wired to the remote system, it is now time to test the OpenOCD bit bang JTAG controller. Create file boards/rpi/openocd_rpi_jtag.cfg and add the following
lines of configuration.

https://github.com/sean-lawless/compute ... i_jtag.cfg

This configuration tells the OpenOCD driver the information it needs to control the JTAG signals on the GPIO lines that were previously connected. The final piece of the puzzle is to create the OpenOCD configuration file for the remote system. The following example is for the RPI 1, other configuraiton files exist in the companion files of the laboratory. Let us create boards/rpi/rpi1_jtag.cfg.

https://github.com/sean-lawless/compute ... 1_jtag.cfg

Now start OpenOCD JTAG controller.
$ sudo openocd -f ./openocd_rpi_jtag.cfg -f ./rpi1_jtag.cfg

This always works but functionality of GDB depends on the type of the RPI of the remote target.

Return to “Bare metal, Assembly language”