How to Use Segger JLink GDBServer with TimeStorm

Segger JTAG devices can emulate a gdbserver instance, allowing debugging with gdb before a gdbserver could normally be started on the target. Using a Timesys support target board, a compatible Segger JTAG, and the JLink software, this guide will provide steps for debugging pre-userspace code like a bootloader or the kernel itself.

Prerequisites

  • Target Board
  • Segger JTAG compatible with target board board
  • JLink GDBServer Software for Windows
  • Linux Host with a Timesys Cross-Toolchain and Timestorm
  • Windows Host on the same network as the aforementioned Linux Workstation

Setup Procedure

At time of writing, the JLink GDBServer software for Linux is in beta and was found to be less stable and functional than the Windows version, so for this tutorial we will use both a Linux and Windows workstation, or a Linux VM on a Windows Host

Windows Machine Setup

  1. Attach the Segger JTAG to the target board and the Windows machine.
  2. Install and start the JLink GDBServer on the Windows machine, uncheck the "Localhost Only" option and restart the GDBServer1.
  3. After confirming the GDBServer instance has found the JTAG and is running, return to the Linux workstation and start Timestorm.

Linux Machine Setup

In Timestorm, create a debugging profile to target the remote GDBServer. Select the Debug Icon Dropdown->Debug Configurations dialog from the main Timestorm toolbar and double click C/C++ Local Application. Name the Configuration "Segger GDBServer" for easy recognition among other debugging configurations. On this first tab choose the Timestorm project to be targeted for debugging and the executable built from this project that is to be run on the target2. On the Debugger tab choose gdbserver Debugger, uncheck Stop at main and select the cross-gdb from a Timesys Toolchain for the "GDB Debugger:" field. If using a toolchain from a Desktop Factory build, it will be located at <your/factory/directory>/build*/toolchain/bin/<your-toolchain-prefix>-gdb.

To target the remote GDBServer session, click the Connection tab of the "Debugger Options" and under Type select TCP. For "Host name or IP address" enter the IP of the Windows machine running the GDBServer. This IP can be found by running ipconfig in the Windows command prompt. For "Port number" enter 2331

Click Apply, and close the Debug Configuration window.

Debugging Procedure

  1. When ready to Debug, restart the target board by removing power from it and then reconnecting the power source with the JTAG attached. Your board should halt at the beginning of it's boot process.
  2. Attach the gdb debugger by running your Segger GDBServer debug configuration in Timestorm
  3. gdb will stop at any breakpoints you have set in your code, or you can press the Pause button in the Timestorm Debugging perspective to halt execution and inspect the system.

If using script to help in your debugging process, browse to this script at the Debug Configurations->Debugger->GDB Command File dialog. Replacing the default script requires you to manually target the GDBServer instance, so place the following commands at the head of the script

target remote <windows ip>:2331
monitor speed 100
monitor reset 4
monitor waithalt 1000
monitor speed adaptive

Notes

1 The "Init Regs on Start" option in the JLink GDBServer application will not work with these instructions, please keep it unselected.

2 For example, when debugging the Kernel the "vmlinux" file located at <factory>/build*/linux-2.6.*/vmlinux will be the target executable.

Additional Resources