Difference between revisions of "Linux Debug"

From ArmadeusWiki
Jump to: navigation, search
m (Changing FPGA IP's registers from Linux user space with fpgaregs)
(Using DebugFS)
Line 80: Line 80:
 
  gpio-8  (LCD                ) in  lo
 
  gpio-8  (LCD                ) in  lo
 
....
 
....
 +
</pre>
 +
 +
==Tracers==
 +
* http://lxr.linux.no/#linux+v3.0.22/Documentation/trace/ftrace.txt#L1016
 +
 +
===Function profiler===
 +
<pre class="host">
 +
$ make linux26-menuconfig
 +
</pre>
 +
 +
<pre class="config">
 +
Kernel hacking  --->
 +
    [*] Tracers  --->
 +
        [*]  Kernel Function Tracer
 +
        ...
 +
        [*]  Kernel function profiler
 +
 +
 +
This option enables the kernel function profiler. A file is created
 +
in debugfs called function_profile_enabled which defaults to zero.
 +
When a 1 is echoed into this file profiling begins, and when a
 +
zero is entered, profiling stops. A "functions" file is created in
 +
the trace_stats directory; this file shows the list of functions that
 +
have been hit and their counters.
 
</pre>
 
</pre>
  

Revision as of 11:05, 28 February 2012

Tips to do debugging under Linux.

Introduction

On this page, you will find usefull informations for debugging your Linux kernel/drivers.

Testing your custom Linux kernel before flashing it

You can test a linux kernel you've generated without having to reflash your board and destroy your currently working image. Indeed Linux kernel images can be loaded and started from SDRAM with U-Boot:

 BIOS> tftp ${loadaddr} ${board_name}-linux.bin
 BIOS> bootm ${loadaddr}

Changing processor registers from Linux user space with imxregs

This tool allows you to access i.MX registers from Linux userspace/console. This way you can debug your driver or access i.MX hardware functionnalities directly from Linux console.

In recent releases (>= 3.0) you should find this tool in /usr/bin/ on your board.

Unlock registers access

Note Note: On APF51 & APF28 you don't have to explicitly unlock registers in U-Boot to access them under Linux, like explained just above


  • To use it, you must clear i.MX PAR_1 & PAR_2 registers (registers access rights) before launching Linux kernel, so in U-Boot type (example here is for APF9328):
 BIOS> mw.l 0x00200008 0
 BIOS> mw.l 0x00210008 0
  • on APF27:
 BIOS> mw 10000008 0
 BIOS> mw 10020008 0

If you use it frequently, a small script unlock_regs has been defined in U-Boot, and you can call it before booting your board:

 BIOS> run unlock_regs
 BIOS> boot

Usage

  • Then in Linux console/terminal, launch imxregs like that:
 # imxregs REGISTER_NAME    (give it the register name as printed in i.MX Ref Manual or just the begining of the name)

or

 # imxregs    (to dump all supported registers)

Examples

  • Show OCR1 registers of each GPIO Port:
 # imxregs OCR1
  • Write 0x00000123 to OCR1_D register:
 # imxregs OCR1_D 123

Changing FPGA IP's registers from Linux user space

See fpgaregs tool.

Using DebugFS

DebugFS is a in-kernel filesystem, similar to procfs or sysfs, that allows Linux driver to easily communicate debug informations to user space. Full documentation: http://lxr.linux.no/linux+v2.6.32/Documentation/filesystems/debugfs.txt or http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch09s07.html

Mounting it

# mount -t debugfs none /sys/kernel/debug

Showing already allocated GPIOs

# cat /sys/kernel/debug/gpio
GPIOs 0-31, gpio-0:          
 gpio-5   (LCD                 ) in  lo
 gpio-6   (LCD                 ) in  lo
 gpio-7   (LCD                 ) in  lo
 gpio-8   (LCD                 ) in  lo
....

Tracers

Function profiler

$ make linux26-menuconfig
Kernel hacking  --->
    [*] Tracers  --->
        [*]   Kernel Function Tracer
        ...
        [*]   Kernel function profiler


 This option enables the kernel function profiler. A file is created
 in debugfs called function_profile_enabled which defaults to zero.
 When a 1 is echoed into this file profiling begins, and when a
 zero is entered, profiling stops. A "functions" file is created in
 the trace_stats directory; this file shows the list of functions that
 have been hit and their counters.

Links