debugging linux with linuxscope-jtd - ultsol.com€¦ · board bringup we will use a method of...

22
Page 1 of 22 © 2011 Ultimate Solutions, Inc. #07-001 Application Notes for Professional Developers of Embedded Systems Debugging Linux With LinuxScope-JTD OVERVIEW The purpose of this Application Note is to show the user a general method for using LinuxScope to debug a Linux kernel. It is assumed that the reader has gone over the LinuxScope manual and has read the ‘Debugging Linux with the BDI & bdiGDB’ Application Note from the USI website at http://www.ultsol.com/pdfs/Tool_Talk_04-002_Rev1.2.pdf . It is also assumed that the user is already familiar with using the BDI and has setup the BDI properly based on the BDI manual and the recommendations given in the ‘Debugging Linux with the BDI & bdiGDB’ Application Note. It is also assumed that the customer has installed LinuxScope and at least knows how to bring up the main LinuxScope GUI; (See the LinuxScope Install Guide and User Manual for details). SYSTEM INFORMATION The target board used for debugging was the Analogue & Micro (A&M) Rattler 8250 PCI board. The Linux kernel was provided by A&M, version 2.6.13; no source changes were made to the base Kernel provided by A&M. As noted in the ‘Debugging Linux with the BDI & bdiGDB’ Application Note the CONFIG_BDI_SWITCH and CONFIG_DEBUG_KERNEL were enabled in the kernel configuration to make a build of the kernel that allowed debugging the kernel with the BDI probe. A stripped version of this kernel was moved to our tftp server to download into the Rattler board. The configuration file used for the BDI probe was provided by A&M with their tools and was setup with the MMU XLAT and PTBASE options enabled. The kernel was compiled on a RH9 computer but was later moved to WindowsXP. The host system used in this Application Note is WindowsXP. BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will first let U-Boot bring up your board. Attach the BDI probe to the Rattler board and power up the board. Issue a ‘reset run’ command to the BDI. View the serial output of the Rattler board and confirm that redboot has come up all the way. From the terminal prompt of the Rattler board, issue commands to download the kernel into RAM. The Rattler board has a jffs ramdisk in the flash so there is no need to download the ramdisk.

Upload: others

Post on 30-May-2020

49 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 1 of 22 © 2011 Ultimate Solutions, Inc.

#07-001

Application Notes for Professional Developers of Embedded Systems

Debugging Linux With LinuxScope-JTD

OVERVIEW The purpose of this Application Note is to show the user a general method for using LinuxScope to debug a Linux kernel. It is assumed that the reader has gone over the LinuxScope manual and has read the ‘Debugging Linux with the BDI & bdiGDB’ Application Note from the USI website at http://www.ultsol.com/pdfs/Tool_Talk_04-002_Rev1.2.pdf. It is also assumed that the user is already familiar with using the BDI and has setup the BDI properly based on the BDI manual and the recommendations given in the ‘Debugging Linux with the BDI & bdiGDB’ Application Note. It is also assumed that the customer has installed LinuxScope and at least knows how to bring up the main LinuxScope GUI; (See the LinuxScope Install Guide and User Manual for details). SYSTEM INFORMATION The target board used for debugging was the Analogue & Micro (A&M) Rattler 8250 PCI board. The Linux kernel was provided by A&M, version 2.6.13; no source changes were made to the base Kernel provided by A&M. As noted in the ‘Debugging Linux with the BDI & bdiGDB’ Application Note the CONFIG_BDI_SWITCH and CONFIG_DEBUG_KERNEL were enabled in the kernel configuration to make a build of the kernel that allowed debugging the kernel with the BDI probe. A stripped version of this kernel was moved to our tftp server to download into the Rattler board. The configuration file used for the BDI probe was provided by A&M with their tools and was setup with the MMU XLAT and PTBASE options enabled. The kernel was compiled on a RH9 computer but was later moved to WindowsXP. The host system used in this Application Note is WindowsXP. BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will first let U-Boot bring up your board. Attach the BDI probe to the Rattler board and power up the board. Issue a ‘reset run’ command to the BDI. View the serial output of the Rattler board and confirm that redboot has come up all the way. From the terminal prompt of the Rattler board, issue commands to download the kernel into RAM. The Rattler board has a jffs ramdisk in the flash so there is no need to download the ramdisk.

Page 2: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 2 of 22 © 2011 Ultimate Solutions, Inc.

The ‘ex’ command is used to start booting the kernel but it is not issued yet. First we have to start LinuxScope and set a breakpoint. LINUXSCOPE SETUP Start up LinuxScope and get to the main GUI. If you are using LinuxScope for the first time you will be greeted with the Blue Welcome screen.

Page 3: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 3 of 22 © 2011 Ultimate Solutions, Inc.

Go to ‘Window Open Perspective JTAG Debug’ to open the JTAG Debugging perspective.

If your GUI has changed due to prior use then go to ‘Window Reset Perspective’ to reset the view. The main LinuxScope GUI should now come up and will look like below.

Click on ‘File New LinuxScope-JTD C Project’

Page 4: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 4 of 22 © 2011 Ultimate Solutions, Inc.

The New Project dialog box will now pop up. Name your project anything you like then click ‘Finish’.

Page 5: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 5 of 22 © 2011 Ultimate Solutions, Inc.

Click on Run Debug

Page 6: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 6 of 22 © 2011 Ultimate Solutions, Inc.

Create a new JTD session.

Assign a name to this debug session and select an existing project. You should have created a project already during startup or the previous step. The Executable/Image should point to the vmlinux file located at the top of your kernel tree; this file has debug symbols built in when compiled correctly. This is the most important file needed to make LinuxScope work correctly and recognize all the symbols and source files.

Page 7: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 7 of 22 © 2011 Ultimate Solutions, Inc.

Click on the debugger tab be sure that the ‘Hostname’ is set properly to point to the BDI.

Page 8: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 8 of 22 © 2011 Ultimate Solutions, Inc.

GDB executables are automatically installed with LinuxScope, click browse next to ‘GDB debugger’ and select the right one.

Page 9: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 9 of 22 © 2011 Ultimate Solutions, Inc.

Page 10: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 10 of 22 © 2011 Ultimate Solutions, Inc.

Next click on the startup tab and select ‘breakpoint type’ as soft, disable ‘Attach to JTAG target on startup’.

Click Apply then Debug. The bottom control tabs should output the following information.

From the top left control tabs select ‘JTD Modules’

Page 11: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 11 of 22 © 2011 Ultimate Solutions, Inc.

Browse the shown directory tree to find a source file. Double click on a file to open it. In our case since this kernel has been moved from Linux to Windows the source paths do not match. Hence the source does not open. Most users will not have to go through this step since the sources will open without any tinkering. The source window outputs an option to ‘Edit source lookup path’, click on this button.

Page 12: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 12 of 22 © 2011 Ultimate Solutions, Inc.

The ‘Edit Source Lookup Path’ box opens up with only the default entries. Click on ‘Add’.

Page 13: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 13 of 22 © 2011 Ultimate Solutions, Inc.

The ‘Add Source’ dialog box comes up, select Path Mapping and click ‘ok’.

This takes us back to the ‘Edit Source Lookup Path’ dialog box, a new entry has appeared called ‘Path Mapping: New Mapping’, select this new entry and click ‘Edit’.

Page 14: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 14 of 22 © 2011 Ultimate Solutions, Inc.

From the ‘Path Mappings’ dialog box give this new mapping a name such as ‘root’ and click on ‘Add’

For my Kernel I moved the sources from my Linux path ‘/home/linux-rattler8250_8250pci_8280pci/linuxppc-2.6’ to ‘C:\cygwin\home\linux-rattler8250_8250pci_8280pci\linuxppc-2.6’. By observing the paths we see that for my source tree the Linux root ‘/’ points to ‘C:\cygwin’, hence this is the path mapping I will use. The compilation path is ‘\’ and the ‘Local file system path’ is ‘C:\cygwin’. Note that the JTD Modules view tells you what the compilation paths are. Click ‘ok’ to accept the changes.

Page 15: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 15 of 22 © 2011 Ultimate Solutions, Inc.

The new path mapping appears in the ‘Path Mappings’ dialog box. Click ok to accept the new path mappings.

Close the previous source window and double click on a source file, it should now open up without any problems.

Page 16: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 16 of 22 © 2011 Ultimate Solutions, Inc.

CONNECT TO TARGET Now is a good time to have a look at the JTD command box at the top left of the JTG GUI below the Navigate drop down. From left to right are the following buttons: Download, Connect, Disconnect, Reset, Sync, Toggle Instruction Mode, Flash, Dump Memory, Resume, Suspend, Step-in, Step-over, Step-out.

We are now ready to connect to our target. Locate the ‘Connect to target’ button in the JTD command tool box, it is located to the top left of the JTG GUI below the Navigate drop down.

Provided your BDI is set up properly we will now attach to the BDI/A&M Rattler board. The disassembly will display the current instructions, the ‘debug’ window to the bottom left will show the stack list and will be sitting at the top of the stack. Note that at this point we are still in the boot loader.

Page 17: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 17 of 22 © 2011 Ultimate Solutions, Inc.

SETTING INITIAL BREAKPOINT Once again go to the ‘JTD Modules’ tab and right click on ‘Current GDB’ or ‘Functions’. Select ‘Find’

The Find dialog box opens up. We will set our initial breakpoint at ‘start_kernel’, type in ‘start_kernel’ and click on ok.

We are taken to the ‘Start_Kernel’ function in ‘main.c’. Right click and select ‘Set Hard Address Breakpoint’. Note that since ‘Start_Kernel’ is located after the MMU turns on, we have to use a hardware breakpoint.

Page 18: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 18 of 22 © 2011 Ultimate Solutions, Inc.

On the bottom control tabs select ‘breakpoint’ to verify that the breakpoint has indeed been set.

Page 19: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 19 of 22 © 2011 Ultimate Solutions, Inc.

DEBUGGING THE KERNEL From the ‘JTD Control Box’ Select the ‘Resume’ button to start running the target and hit our breakpoint. This button is also located at the bottom left ‘Debug’ window.

Note that we never told Redboot to start booting the kernel, we need to hit enter in the Rattler board’s serial console so that the ‘ex’ command can start booting the Linux Kernel. After we have done so we will hit our breakpoint at start_kernel. LinuxScope will open ‘main.c’ and take us to the proper line number. The disassembly view will show the assembly instructions around ‘start_kernel’.

The Debug view will show that we are at ‘start_kernel’ and the stack info. Note that during debugging you must always select the top of the stack to single step.

Page 20: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 20 of 22 © 2011 Ultimate Solutions, Inc.

Go back to the breakpoint view and remove the hardware breakpoint, since there are only a few hardware breakpoints in any given target we do not want to use them unless we have to.

We can now begin debugging our kernel. Scroll down in ‘main.c’ and set a breakpoint at the sched_init function. Right click on the line number beside sched_init to set this breakpoint.

A breakpoint indicator shows up beside the line number.

Page 21: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 21 of 22 © 2011 Ultimate Solutions, Inc.

The breakpoint also shows up in the breakpoints view.

Click on the ‘Resume’ button again and the target runs until it hits this breakpoint. Once again the PC has moved to sched_init and the disassembly shows instructions around sched_init.

You are now debugging the kernel. Play around with the JTD Command Box, use the Step-in, Step-out and Step-over buttons to navigate the source code and get familiar with their functionality.

Page 22: Debugging Linux With LinuxScope-JTD - ultsol.com€¦ · BOARD BRINGUP We will use a method of debugging the Linux Kernel that is as fool-proof as possible. For this reason we will

Page 22 of 22 © 2011 Ultimate Solutions, Inc.

Authored by: Fahd Abidi Field Application Engineer with Ultimate Solutions, Inc.

10 Clever Lane

Tewksbury, MA 01876-1580 USA Ph: 866.455.3383 Fx: 978.926.3091

Email: [email protected] Web: www.ultsol.com