AR# 66853

2016.1 PetaLinux - How to set up Kernel debug using PetaLinux


KERNEL_DEBUG_INFO and KERNEL_DEBUGGING must be enabled to debug Linux Kernel Modules with Xilinx SDK. This Answer Record covers how to do it with PetaLinux.


There are some specific configurations that need to be set in order to get PetaLinux based kernel debugging working.

These steps complement the Linux Kernel Debug Steps mentioned in SDK help:

SDK Help > Xilinx Software Development Kit (SDK) User Guide > Working with Xilinx System Debugger > System Debugger Supported Design Flows > Attach and Debug using Xilinx System Debugger.

Below are the steps involved in debugging a PetaLinux based Linux kernel:

1) Create a Zynq template project in Vivado and export hardware to SDK.

2) Create a Linux Application in SDK with the Hello World Example and close the SDK project to continue with the PetaLinux project.

3) Create a PetaLinux project with the following command:

petalinux-create --type project --template <CPU_TYPE> --name <PROJECT_NAME>

4) Go to the PetaLinux project directory and run the following command:

petalinux-config --get-hw-description=<path-to-directory-which-contains-hardwaredescription-file>

point the hw-description to the directory containing the .hdf file (the <project_name>.sdk directory in your previously created Vivado project.)


Figure 1 Petalinux menuconfig view opened with petalinux-config

5) Go to the Linux Components Selection  ---> and then to kernel (xlnx-4.0)  --->  

Select the remote option as show in figure 2 below:


Figure 2

6) Next we need to give the path of the full kernel source which can be found on the Xilinx GitHub page.

7) Go to Remote linux-kernel settings  ---> Remote linux-kernel git URL

Please copy the following link and paste it into the text box as shown in figure 3:



Figure 3

We need to have the full source code for xlnx-linux in order to debug kernel. Selecting a remote source automatically downloads the image from GitHub into your PetaLinux project during the config stage.

8) Next we need to set the address offset for loading the bootimage. Go to u-boot Configuration  ---> and set the netboot offset to 0x04000000 as shown in figure below.

For more information refer to (Xilinx Answer 59853) 

The image size from this setup is going to be large and does not fit the u-boot temporary scratch area overflows. 

To avoid a failed boot you need to make changes as follows:


Figure 4

9) You are now finished in petalinux-config. Save the changes in the default config path prepopulated in the <Save> button and exit.

10) Next go to the kernel setup:

Set the options below, as mentioned in the SDK Help point 1 in the PetaLinux tool:



To do this, go to petalinux-config -c kernel which opens the config for the kernel component:


Figure 5 Kernel Config panel with Kernel Hacking Selected

11) Go to Kernel Hacking ---> and make sure that Kernel Debugging is selected as shown in Figure 6.


Figure 6 Kernel Debugging enabled in menuconfig


12) Next go to Compile-time checks and compiler options ---> and enable the Compile the kernel with debug info in the next panel.


Figure 7 DEBUG_INFO enabled from PetaLinux GUI

13) Save and quit the kernel debug.

14) Now you need to turn on the TCF agent that will be active in the Linux kernel on board, and will give you access to the hardware during kernel debugging.

15) Open petalinux-config -c rootfs inside the petalinux project directory. You should see this dialog:


Figure 8

16) Go to Debugging  ---> and make sure [*] build debugable applications is enabled.

Next go to Filesystem Packages  ---> and then to base  ---> and tcf-agent  ---> and enable

[*] tcf-agent  


Figure 9

17) Save and Exit the menuconfig for rootfs.

18) Save and close the file. You are almost set with your Kernel Debug.

For more information refer to (Xilinx Answer 61332) 

19) Finally, go to your PetaLinux project root directory and build your PetaLinux project with petalinux-build. Also, build your BOOT.bin using the zynq_fsbl.elf file in images/linux directory using the following command:

petalinux-package --boot --fsbl <FSBL image> --fpga <FPGA bitstream> --u-boot < U-boot.elf>

20) For next steps, follow along the SDK Kernel Debugging section in SDK Help as previously mentioned.

AR# 66853
Date 05/21/2018
Status Active
Type General Article
Boards & Kits