Posts: 3
Joined: Sat Oct 12, 2019 10:29 am

RPi4 changes - JTAG, UART and OpenOCD not working

Sat Oct 12, 2019 11:07 am

Hi all,

The main problem we are facing is that the Raspberry Pi 4 seems to have a different way of configuring and using JTAG and UART than the Raspberry Pi versions before. When succeeding in configuring JTAG using Videocore boot configurations, it is still not possible to use OpenOCD for some unclear reason. And thus it is very hard and tedious to debug the UART problem. Maybe somebody has already a running OpenOCD setup and can share this or knows how to deal with these problems.

Let's start with a bit background of how we started out. When we are working with the Raspberry Pi 3, it is possible to boot up simple bare metal code to set up the GPIO pins for the alternate functions UART TX and RX and JTAG in a standard way. We combined code from different sources and adjusted it a bit and it works well for what we need. The code we use is this: ... -jtag-boot.
(It is probably the same with the versions before, modulo the different peripheral base addresses, but we did not try this approach on a previous version.)

Now we first looked at existing bare metal code bases that work with RPi4 so that we don't miss some basic configuration that we are not aware of. We tried with this one for example and out RPi4 blinks the LED as this code suggests: ... -2/armc-09

After getting a stable boot environment from this code, we added code to setup the UART and JTAG pins accordingly and also (later) took into account the new way of configuring pull-up/down resistors and used code from this repository for the job:

At this point, OpenOCD could still not connect to the ARMv8 cores. In fact, it could even not even detect a JTAG chain. So we digged more and finally found this blogpost which uses the Videocore boot config.txt to enable JTAG (enable_jtag_gpio=1) and a comment refers to the correct core addresses: ... i-3b-jtag/

Now OpenOCD can connect but it shows "Mode: Failed" when a core is halted and it behaves weirdly. When disconnecting and reconnecting OpenOCD at this point, it does not connect properly again until the board is rebooted. This also indicates that something is wrong. When looking and more verbose OpenOCD outputs, it comes clear that the debug interface's response to a halt command is already uncomplete or similar.

Our questions are the following:
  • Did somebody already use gdb to debug the Raspberry Pi 4 over JTAG? Or with properly working OpenOCD? If yes, how? This would resolve half of the issue I guess. :)
  • What is different about RPi4 when it comes to enabling JTAG such that it requires intervention of the videocore? Are we missing something?
  • Did somebody get one of the UARTs to talk by using bare metal code on RPi4? If yes, how?
  • Does the RPi4 miss the mini UART identified as UART1? Are now all UARTs in the system of type PL011 like UART0 used to be? Or are we just missing a setup step similar to JTAG before?
Best Regards.
Posts: 3
Joined: Sat Oct 12, 2019 10:29 am

Re: RPi4 changes - JTAG, UART and OpenOCD not working

Sun Nov 10, 2019 6:59 am

It's solved now and works for us with a bit help of some existing resources and a lot of digging and trial and error. Network booting helped the trial and error process also. Here's a summary in case somebody is interested:

OpenOCD was reporting errors due to (apparently) wrong or unsuitable configurations in config.txt. We use UART0 now - no need to mess with the miniUART.

The conclusion is the source code here ... /rpi4-boot, and the sd card files here ... /rpi4-boot. We use the currently latest EEPROM setup for network boot according to the documentation on GitHub.

Posts: 3
Joined: Sat Jun 06, 2020 5:23 pm

Re: RPi4 changes - JTAG, UART and OpenOCD not working

Sat Jun 06, 2020 5:35 pm

I had been using a JTAG and OpenOCD with the original (July 2019) firmware on my Pi 4 for many months.

I found that newer firmware never worked for me. Unfortunately, I just purchased the 8 GB board, and found I need to upgrade the firmware to use it. (By "firmware", I mean the files on the MSDOS partition on the SD Card).

On both the new and old board, with the latest firmware, I find the CoreSight JTAG chip misidentifies itself. For example

Code: Select all

Info : JTAG tap: rpi4.tap tap/device found: 0xa3a00477 (mfg: 0x23b (ARM Ltd.), part: 0x3a00, ver: 0xa)
Warn : JTAG tap: rpi4.tap       UNEXPECTED: 0xa3a00477 (mfg: 0x23b (ARM Ltd.), part: 0x3a00, ver: 0xa)
Error: JTAG tap: rpi4.tap  expected 1 of 1: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
0x4ba00477 is the correct IDCODE for the Cortex-A72, according to Arm. Has the identifier changed? Google does not find any hits for the 0xa3a00477 identifier at all.

Also, OpenOCD times out while trying to establish the connection to the debug access port. Has something changed in the firmware?

Code: Select all

Error: 422 601 core.c:1439 jtag_init_inner(): Trying to use configured scan chain anyway...
Debug: 423 601 core.c:1190 jtag_validate_ircapture(): IR capture validation scan
Debug: 424 601 core.c:1248 jtag_validate_ircapture(): rpi4.tap: IR capture 0x01
Warn : 425 601 core.c:1462 jtag_init_inner(): Bypassing JTAG setup events due to errors
Debug: 426 601 command.c:143 script_debug(): command - dap dap init
Debug: 428 602 arm_dap.c:105 dap_init_all(): Initializing all DAPs ...
Debug: 429 602 arm_adi_v5.c:653 dap_dp_init(): rpi4.dap
Debug: 430 602 arm_adi_v5.c:698 dap_dp_init(): DAP: wait CDBGPWRUPACK
Debug: 431 602 arm_adi_v5.h:467 dap_dp_poll_register(): DAP: poll 4, mask 0x20000000, value 0x20000000
Debug: 432 718 arm_adi_v5.h:480 dap_dp_poll_register(): DAP: poll 4 timeout
Debug: 433 718 command.c:630 run_command(): Command 'dap init' failed with error code -5
For what it's worth, my OpenOCD script is

Code: Select all

transport select jtag

reset_config trst_and_srst

adapter_khz 1000
jtag_ntrst_delay 500

if { [info exists CHIPNAME] } {
} else {
  set _CHIPNAME rpi4

if { [info exists DAP_TAPID] } {
} else {
#    set _DAP_TAPID 0xa3a00477
   set _DAP_TAPID 0x4ba00477

jtag newtap $_CHIPNAME tap -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_DAP_TAPID -enable
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.tap


set DBGBASE {0x80410000 0x80510000 0x80610000 0x80710000}
set CTIBASE {0x80420000 0x80520000 0x80620000 0x80720000}
set _cores 4

for { set _core 0 } { $_core < $_cores } { incr _core } {
    cti create $_CTINAME.$_core -dap $_CHIPNAME.dap -ap-num 0 \
        -ctibase [lindex $CTIBASE $_core]

    target create $_TARGETNAME.$_core aarch64 \
        -dap $_CHIPNAME.dap -coreid $_core \
        -dbgbase [lindex $DBGBASE $_core] -cti $_CTINAME.$_core

    $_TARGETNAME.$_core configure -event reset-assert-post "aarch64 dbginit"
    $_TARGETNAME.$_core configure -rtos hwthread


Posts: 3
Joined: Sat Jun 06, 2020 5:23 pm

Re: RPi4 changes - JTAG, UART and OpenOCD not working

Sun Jun 07, 2020 11:47 pm

I figured it out.

The ARM documentation is clear that the RTCK signal is not required for CoreSight debugging, and all the posts I can find online discussing Raspberry Pi debugging omit connecting the RTCK wire. I always left it unconnected with previous firmware revisions. However, that is apparently wrong with the latest firmware.

Connecting RTCK resolved all the problems. It's the blue wire on the common USB FTDI FT232H, goes to pin 16 on the board. Also doesn't hurt to connect ground (black), which is usually omitted in what I found in online guides.

Posts: 2
Joined: Tue Jun 09, 2020 8:53 am

Re: RPi4 changes - JTAG, UART and OpenOCD not working

Tue Jun 09, 2020 9:01 am

I upload a Youtube concering using OpenOCD for debugging BareMetal Program in Raspberry Pi 4. But sorry for using Korean. I modified conventional raspberry pi 3tutorial source code and build with "-g" compile option and debug with OpenOCD.
Follow is the youtube website

I hope this will help for those who want to program and debug baremetal firmware C program for Raspberry Pi 4.

Posts: 21
Joined: Thu Jun 06, 2019 6:07 pm

Re: RPi4 changes - JTAG, UART and OpenOCD not working

Thu Aug 27, 2020 6:18 pm

This book/repo supports RPi 4 and OpenOCD debugging over JTAG. One potentially overlooked issue is that the pull up/pull down GPIO configuration registers have changed on RPi 4. The PU/PD need to be turned off for all JTAG GPIOs.

Return to “Bare metal, Assembly language”