RZ Debugging Bootloaders with OpenOCD

RZ Debugging Bootloaders with OpenOCD

Page Contents


Introduction

This page describes how to debug bootloaders and Flash Writer using:

  • User interface

    • Microsoft Visual Studio Code (VS Code)

    • Eclipse IDE

    • GDB Text User Interface

  • OpenOCD

  • RZ/G3E SMARC Module with Carrier Board and Breakout Adaptor (JTAG)

  • Segger J-Link debugger

  • RZ Build scripts (Debugging in Yocto environment is also possible)

  • QSPI boot mode.

The following table shows how the images are loaded. You can verify this by checking the image timestamps on console.

 

Loading BL2

Loading BL31

Loading BL33

 

Loading BL2

Loading BL31

Loading BL33

Debugging BL2

Debugger

Flash

Flash

Debugging BL31

Debugger

Debugger

Flash

Debugging BL33

Flash

Flash

Debugger

Bootloader debugging requires modified startup behavior to ensure that the debugger can reliably attach before execution proceeds. So, the ROM bootloader loads a prepared BL2 from QSPI flash, which stays in a loop, so that the debugger can safely attach.

BL2

The ROM code copies the BL2 from the flash to RAM. While executing the delay loop, the debugger can attach, halt the execution, copy the BL2 to RAM, and restart from the entry point.

BL2

The ROM code copies the BL2 from the flash to RAM. While executing the delay loop, the debugger can attach, halt the execution, copy the BL2 to RAM, and restart from the entry point.

BL31

The startup of BL2 is the same as in previous section. At the end of BL2 executuion, the BL31 is overwritten by the debugger.

BL33

The debugger sets a breakpoint at the BL33 entry point; when this breakpoint is hit, U‑Boot is overwritten in RAM by the debugger and symbols are loaded, followed by a breakpoint on relocate_code. When relocate_code is reached, U‑Boot relocates itself and the debugger reloads symbols with the relocation offset so that normal source‑level debugging works correctly.

Software Installation

  • For Installation of VS Code or Eclipse please see below.

  • Install OpenOCD, see here.

  • Install Arm GNU toolchain from here.

Prepare a Special BL2 Bootloader

For debugging BL2, BL31 and BL33 a delay loop is added to the entrypoint of BL2 to allow the debugger to attach at a defined stage after power-on or reset. Execution can then be halted to start debugging.

Open the file ./atf4ubootdebug/rzg_trusted-firmware-a/bl2/aarch64/bl2_el3_entrypoint.S
and add the following code at the beginning of the function bl2_entrypoint:

func bl2_entrypoint /* Save arguments x0-x3 from previous Boot loader */ mov x20, x0 mov x21, x1 mov x22, x2 mov x23, x3 #if 1 // Software loop is only needed for debugging. mov x1, #0 movz x2, #0x0000 movk x2, #0x1000, LSL #16 software_loop: adds x1, x1, #1 cmp x1, x2 b.ne software_loop #endif …

Build the BL2 and write it with the FIP image to the QSPI flash according to Startup Guide.

The loop above delays startup by approximately 1-2 seconds, sufficient time to attach the debugger before starting execution.

Configure the RZ/G3E Board

  • Set boot mode to QSPI: SW_MODE[1..3] = 000b
    Set DIP switch BOOT[1] to OFF (JTAG Debug is enabled)

  • Connect Breakout Adaptor and Debugger according to the RZ/G3E SMARC Module Board - User’s Manual: Hardware

 

The following sub-articles describe the debugging workflow for specific user interfaces:

https://renesas-wiki.atlassian.net/wiki/pages/resumedraft.action?draftId=807043073&draftShareId=81b4d260-99f3-4a51-998e-f69d895c8aab&atlOrigin=eyJpIjoiMzYwMDI0NTBiOTQ3NGY2YmJiOWIwZGZhMGY0ODdmODIiLCJwIjoiYyJ9

https://renesas-wiki.atlassian.net/wiki/pages/resumedraft.action?draftId=805863453&draftShareId=80aa9ca1-4a2f-41fc-a66d-ebdda4b19c9f&atlOrigin=eyJpIjoiNDk0Y2RkZjAxMGZjNDFmOGE1ZGFiZWU2ZDk1NzBkNzciLCJwIjoiYyJ9

https://renesas-wiki.atlassian.net/wiki/pages/resumedraft.action?draftId=807010305&draftShareId=e83c3129-95c2-4d5a-9a9d-fa3be1d4e091&atlOrigin=eyJpIjoiMjIyNmY1ZDMwYWU1NGM5ZDlkYzc1Y2Y3N2UyYTA2ZjciLCJwIjoiYyJ9