RZ-G/RZG2 Kernel Debugging with Eclipse and OpenOCD

From Renesas.info
Revision as of 07:49, 7 May 2024 by MicBis (talk | contribs) (Bran new page for Linux kernel debugging using OpenOCD)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

It is possible to use OpenOCD and Eclipse to source level debug the Linux kernel. This means kernel space (device drivers), not application space. For application space, you need to use traditional gdb, not JTAG. The reason is that Linux applications run in virtual address space, so the settings of the MMU must be considered. However, while the Linux kernel also runs at a virtual address, the address space is fixed so it is possible to use openOCD and JTAG.

General Considerations:

Here are some considerations to think

  • It is possible to debug a multi-core system [TBA link to the section] but it may be simply easier to disable all other cores.
  • This works best for debugging device drivers on bootup.
  • It is possible to use gdb from the Yocto SDK, however it is advisable to install a more recent version of the Arm toolchain (e.g. 13.2.Rel1)

Kernel Build Options:

You must build the kernel with the following configuration options. Not that =y means they must be enabled, and =n means they just be disabled. Please use menuconfig to confirm each one.

  • CONFIG_DEBUG_INFO=y
  • CONFIG_DEBUG_INFO_REDUCED=n
  • CONFIG_DEBUG_INFO_SPLIT=n
  • CONFIG_RANDOMIZE_BASE=n
  • CONFIG_UNMAP_KERNEL_AT_EL0=n

Note that some of these configurations can only be enabled if EXPERT=y.

To debug modules:

  • CONFIG_KALLSYMS=y

To make sure the HW breakpoint resources are not touched during boot:

  • PERF_EVENTS=n

Because of the default compiler optimization level (-O2), stepping thru the code may be problematic / unpredictable. Using menuconfig you can only select between -O2 and -Os (CC_OPTIMIZE_FOR_PERFORMANCE, CC_OPTIMIZE_FOR_SIZE). There's also a relatively new CC_OPTIMIZE_FOR_PERFORMANCE_O3 to select -O3 but no real way to choose a lower optimization level. It is not mandatory but to get a code flow that is easier to follow, you can manually hack the Makefile and turn -O2 into -O1:

image kernel c opt O1.png

Kernel Boot Arguments:

You need to add the follow to your kernel boot arguments:

  • nohlt pti=0 maxcpus=1

The "maxcpus=1" make sure that even in a multi-core system, only one core is used.

OpenOCD dedicated plugin

It is assumed that Arm Trusted Firmware and u-boot are working and programmed into the chosen boot medium (QSPI, eMMC or SD). It may also be convenient to set-up u-boot to load and boot the kernel via the network (tftp) to make sure that the symbols loaded in gdb always match the kernel that is executed / under debug (in fact the kernel binary is not loaded via JTAG).

First you need to import the kernel as makefile project (you can also clone and import, similarly to what is documented here)