How to develop and debug Linux kernel project on a remote target

This document describes How to develop and debug Linux Kernel Project on a remote target.

To develop and debug Linux Kernel in TimeStorm, please refer to the following sections.

  1. Creating a kernel project
    1. Manage Kernel Sources
    2. Specify Kernel Build Settings
    3. Manage kernel Build Output
  2. Configuring the kernel
  3. Building and deploying the kernel
  4. Debugging the kernel

1. Creating a kernel project:

To create a kernel project, open the New Project wizard by clicking File --> New --> Other from the main menu. Select Kernel --> Linux Kernel Project and click ‘Next’ to continue, as shown below.

Project Page:

The Project page shown below allows you to enter a name for the project name field, You can create a kernel project using the kernel sources included in the SDK (Factory/Yocto/Other), or kernel sources you have in an archive file or directory.

When you select the SDK, the ‘Kernel Source Path’, ‘Kernel Config Path’, architecture, toolchain and other details required for building the kernel project are filled in for you on this and next pages automatically.

Kernel Source Management:

Kernel Source Management page allows you to choose how you want to manage your kernel sources. You can create the project in your kernel source location or at a different location. You can also choose to create the project in TimeStorm workspace or at a different location as shown below. You can either make a copy of your existing kernel sources or use a link to your kernel source directory.

Kernel Build Settings:

Kernel Build Settings page shown below allows you to enter the Architecture, Default make target, Load-address, Parallel Make. If the SDK selected on the previous page has this information then these values are filled in.

The cross-compile prefix for the kernel build is set based on the selected SDK.

Architecture and Load-address are mandatory; and ‘Default Make Target’ and ‘Parallel Make’ are optional.

You can choose whether to build the kernel modules along with the kernel.

Build Output

Build Output page allows you to manage the kernel build output. You can save the kernel build output in a project, or in a subdirectory in the kernel project, or an external directory.

Click Finish to create the kernel project. Copying the kernel sources takes some time and you may notice a delay in creating the project.

Please note that to conserve memory and CPU resources, indexing is turned off for kernel projects. The side effect of this is you may see errors / warnings when you open kernel sources in an editor.

2. Configuring the Kernel:

You can configure the kernel by right clicking on the kernel project, clicking TimeStorm Configure Kernel and then clicking MenuConfig or XConfig. TimeStorm launches the menuconfig or xconfig editor outside TimeStorm. You can configure the kernel and save your changes.

Please note that for running menuconfig, you should have libncurses5-dev and xterm package installed, and for running xconfig, you should have qt3-dev-tools or qt4-dev-tools package and xterm installed.

Menuconfig editor is shown below.

The XConfig editor is shown below.

3. Building and Deploying the Kernel:

To build a kernel project right click on the project and click on build project. The build progress is displayed in the console view.

Linux kernel can be built in a variety of ways. These are defined as targets. For information about make targets, please follow the https://www.kernel.org/doc/makehelp.txt

To launch the Make Targets window, right click on the kernel project and click on Make Targets > Build …, and the make targets window will display as shown below.

  • uImage - an image file that has a U-Boot wrapper (installed by the mkimage utility) that includes the OS type and loader information
  • vmlinux - Build the bare kernel
  • modules - Build all modules
  • mrproper - cleans the build directory by removing all generated files + config + various backup file
  • oldconfig - Update current config utilising a provided .config as bases

While building the kernel, sometimes you may see build issues and the debug message suggest to run mrproper In that case, you can run mrproper by using the make targets included with TimeStorm kernel project.

To run a make target, select the target from the list and click Build.

Booting the board with the kernel image that is built is specific to the board. Please refer to the getting started guide for your board for instructions on how to deploy the kernel image and boot the board. TimeStorm does not include any features for deploying the kernel and booting the board.

4. Debugging the kernel:

To debug a kernel, you have to:

  1. Configure the kernel for debugging
  2. Build the kernel
  3. Boot the board with the kernel using the right boot arguments
  4. Debug the kernel from TimeStorm using gdb

1. Configure the Kernel for Debugging:

To configure the kernel for debugging, open menuconfig or xconfig for the kernel project and:

2. Build the kernel:

After configuring the kernel for debugging, save the kernel configuration and build the kernel by clicking on ‘Build Project’ in the project context menu.

3. Boot the board with the kernel using the right boot arguments:

The additional boot arguments passed to the kernel include the gdb and kgdb communication setting, and instructing the kernel to wait for the gdb connection. Gdb communicates to kgdb over serial connection and you set the serial device and the baud rate as the boot arguments.

For kernel debugging append these arguments to your boot arguments.

  kgdboc=<serial_device&gt,<baud> kgdbwait

For additional information on the boot arguments, refer to https://mirrors.edge.kernel.org/pub/linux/kernel/people/jwessel/kdb/kgdbKernelArgs.html

When you boot the kernel with these boot arguments, kgdb registers the kgdboc driver and waits for a remote gdb connection, as shown below.

When you boot the kernel with these boot arguments, kgdb registers the kgdboc driver and waits for a remote gdb connection, as shown below.

4. Debug the kernel from TimeStorm using gdb

To debug a kernel,

  1. Set a breakpoint :
    1. Open the kernel source you want to debug in the source editor.
    2. Set a breakpoint by either double clicking at the far left end of the line in the source editor or by right clicking at the far left end of the line in the source editor and click “Add Breakpoint”.
    1. Create a debug launch configuration and start debugging.
      1. Click and select the kernel project you want to debug
      2. Right click on the kernel project and click on TimeStorm Kernel/Driver → Debug Kernel to open the Debug Configurations dialog.
      3. Click New launch configuration icon in the top left corner. This will create a new debug launch configuration for the kernel project and the launch configuration tabs are displayed in the right panel as shown below. For a kernel that is already built, most of the entries in all the fields are already filled in and you may not have to change any entries for debugging. You have to set the gdb connection settings in the “Connection tab” in the “Debugger” tab.

    1. Main tab: Enter a name for the debug launch configuration. Enter the kernel project to debug by your workspace by clicking the browse button. Select and enter the vmlinux file in your kernel project.
    2. Debugger Tab: If you want to change the gdb used to debug the kernel, then you can select the SDK Type and choose SDK from the dropdown box at the top of the tab.
      1. Main tab: The gdb in the toolchain is filled in the GDB debugger text field. If you want to change the gdb, you can do so by clicking the Browse button next to the gdb debugger text field. If you wish not to run any commands when gdb launches, you can clear “.init” entry in the gdb command file text field.
      2. Shared Libraries Tab: You can manage the directories the debugger searches to find the shared libraries (with debug symbols) on the “Shared Libraries” tab in the Debugger tab. By default the debugger will automatically search the paths specified in the project’s build settings.
      3. “Load shared library symbols automatically” check box is selected by default and this will allow the debugger to hit breakpoints in the shared library. Select the “Stop on shared library events” if you want the debugger to stop on shared library events, even before it hits breakpoints in source code.

      4. Connection Tab: kgdb works only over serial port. So select Serial as the connection type, enter the host serial device that is connected to the target board and the baud rate. This baud rate should match the baud entered in the kernel boot argument.
      5. Click the debug button to start debugging. TimeStorm will switch to debug perspective and the debugger will stop at the first break point. You will be able to step in, step over and resume through the kernel source code.