Difference between revisions of "Linux Debug"

From ArmadeusWiki
Jump to: navigation, search
(Examples:)
m (Observing systems clocks)
 
(33 intermediate revisions by 8 users not shown)
Line 1: Line 1:
** Tips to do debug under linux **
+
Tips to do debugging under Linux.
  
===Introduction===
+
==Introduction==
  
On this page, you will find usefull informations for debugging Armadeus under Linux
+
On this page, you will find usefull informations for debugging your Linux kernel/drivers.
  
===Testing Linux kernel===
+
==Testing your custom Linux kernel before flashing it==
  
You can test a linux kernel you've generated without to have to reflash your board and destroy your currently working image.
+
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 RAM:
+
Indeed Linux kernel images can be loaded and started from SDRAM with U-Boot:
  BIOS> tftpboot 0x08800000 linux-kernel-2.6.16-arm.bin
+
<pre class="apf">
BIOS> bootm 0x08800000
+
  BIOS> run download_kernel
 +
MAC: 00:1e:ac:00:00:02
 +
operating at 100M full duplex mode
 +
Using dm9000 device
 +
TFTP from server 192.168.0.104; our IP address is 192.168.0.10
 +
Filename 'apf9328-linux.bin'.
 +
Load address: 0x8000000
 +
Loading: #################################################################
 +
#################################################################
 +
#################################################################
 +
#################################################################
 +
#################################################################
 +
########
 +
done
 +
Bytes transferred = 1703940 (1a0004 hex)
 +
BIOS> bootm
 +
## Booting kernel from Legacy Image at 08000000 ...
 +
</pre>
  
===imxregs===
+
==Changing processor registers from Linux user space with imxregs==
  
This tool allows you to access iMX registers from linux userspace/console. This way you debug your driver or access iMX hardware functionnalities
+
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.
directly from Linux console.
+
  
First, you have enable this tool in Buildroot:
+
In recent releases (>= 3.0) you should find this tool in ''/usr/bin/'' on your board.
$ make menuconfig
+
  
Once done, compile it:
+
===Unlock registers access===
$ make
+
{{Note | On [[APF51]]/[[APF28]]/[[OPOS6UL]] you don't have to explicitly unlock registers in U-Boot to access them under Linux, like explained just above}}
  
The generated file is located in buildroot/build_arm_nofpu/imxregs-1.0/. Now you can copy it on your target.
+
* 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):
 
+
<pre class="apf">
To use it, you must clear PAR 1&2 registers (register access rights) before launching Linux kernel, so in U-Boot type:
+
 
  BIOS> mw.l 0x00200008 0
 
  BIOS> mw.l 0x00200008 0
 
  BIOS> mw.l 0x00210008 0
 
  BIOS> mw.l 0x00210008 0
 +
</pre>
 +
* on APF27:
 +
<pre class="apf">
 +
BIOS> mw 10000008 0
 +
BIOS> mw 10020008 0
 +
</pre>
  
Then in linux, launch it like that:
+
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:
  # imxregs REGISTER_NAME (give it the register name as printed in iMX Ref Manual or just the begining of the name)
+
<pre class="apf">
 +
BIOS> run unlock_regs
 +
BIOS> boot
 +
</pre>
 +
 
 +
===Usage===
 +
* Then in Linux console/terminal, launch ''imxregs'' like that:
 +
<pre class="apf">
 +
  # imxregs REGISTER_NAME   (give it the register name as printed in i.MX Ref Manual or just the begining of the name)
 +
</pre>
 
or
 
or
 +
<pre class="apf">
 
  # imxregs    (to dump all supported registers)
 
  # imxregs    (to dump all supported registers)
 +
</pre>
  
====Examples:====
+
===Examples===
Show OCR1 registers of each GPIO Port:
+
* Show OCR1 registers of each GPIO Port:
 +
<pre class="apf">
 
  # imxregs OCR1
 
  # imxregs OCR1
 +
</pre>
  
Write 123 to OCR1_D register:
+
* Write 0x00000123 to OCR1_D register:
 +
<pre class="apf">
 
  # imxregs OCR1_D 123
 
  # imxregs OCR1_D 123
 +
</pre>
 +
 +
==Changing FPGA IP's registers from Linux user space==
 +
 +
See [[FPGA_register|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===
 +
<pre class="apf">
 +
# mount -t debugfs none /sys/kernel/debug
 +
</pre>
 +
===Showing already allocated GPIOs===
 +
<pre class="apf">
 +
# 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
 +
....
 +
</pre>
 +
 +
===Showing clock tree===
 +
 +
<pre class="config">
 +
Device Drivers  --->
 +
    Common Clock Framework  --->
 +
        [*]  DebugFS representation of clock tree
 +
 +
| Creates a directory hierarchy in debugfs for visualizing the clk
 +
| tree structure.  Each directory contains read-only members
 +
| that export information specific to that clk node: clk_rate,
 +
| clk_flags, clk_prepare_count, clk_enable_count & clk_notifier_count.
 +
</pre>
 +
 +
all clocks are availables under ''/sys/kernel/debug/clk'':
 +
<pre class="apf">
 +
# mount -t debugfs none /sys/kernel/debug/
 +
# cat /sys/kernel/debug/clk/clk_summary
 +
</pre>
 +
 +
==Tracers==
 +
* http://lxr.linux.no/#linux+v3.0.22/Documentation/trace/ftrace.txt#L1016
 +
 +
===Function profiler===
 +
<pre class="host">
 +
$ make linux-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>
 +
 +
==Observing system clocks==
 +
 +
You can "export" and observe some clocks:
 +
* On OPOS6UL/L: signal CLKO1 is available on pad JTAG_TMS (pin 7 of J36) and signal CLKO2 is available on pad JTAG_TDO (pin 13 of J36).
 +
 +
Example on OPOS6UL/L:
 +
 +
Mux CLKO1 and CLKO2 signals on JTAG_TMS and JTAG_DO:
 +
<pre>
 +
# devmem 0x20E0048 32 3
 +
# devmem 0x20E004C 32 3
 +
</pre>
 +
 +
Export ARM clock (divided by 8) on CLKO2:
 +
<pre>
 +
# devmem 0x20C4060 32 0x1EA0001
 +
</pre>
  
===TBDL===
+
See the reference manual of the OPOS6UL/L for the others clocks "exportable".
  
===Links===
+
==Links==
http://www.armadeus.com
+
* http://www-users.cs.umn.edu/~boutcher/kprobes/
 +
* http://tree.celinuxforum.org/CelfPubWiki/PatchArchive

Latest revision as of 09:31, 3 May 2019

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> run download_kernel 
MAC: 00:1e:ac:00:00:02
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.0.104; our IP address is 192.168.0.10
Filename 'apf9328-linux.bin'.
Load address: 0x8000000
Loading: #################################################################
	 #################################################################
	 #################################################################
	 #################################################################
	 #################################################################
	 ########
done
Bytes transferred = 1703940 (1a0004 hex)
BIOS> bootm
## Booting kernel from Legacy Image at 08000000 ...

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/OPOS6UL 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
....

Showing clock tree

Device Drivers  --->
    Common Clock Framework  --->
        [*]   DebugFS representation of clock tree

| Creates a directory hierarchy in debugfs for visualizing the clk
| tree structure.  Each directory contains read-only members
| that export information specific to that clk node: clk_rate,
| clk_flags, clk_prepare_count, clk_enable_count & clk_notifier_count. 

all clocks are availables under /sys/kernel/debug/clk:

# mount -t debugfs none /sys/kernel/debug/
# cat /sys/kernel/debug/clk/clk_summary

Tracers

Function profiler

$ make linux-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.

Observing system clocks

You can "export" and observe some clocks:

  • On OPOS6UL/L: signal CLKO1 is available on pad JTAG_TMS (pin 7 of J36) and signal CLKO2 is available on pad JTAG_TDO (pin 13 of J36).

Example on OPOS6UL/L:

Mux CLKO1 and CLKO2 signals on JTAG_TMS and JTAG_DO:

# devmem 0x20E0048 32 3
# devmem 0x20E004C 32 3

Export ARM clock (divided by 8) on CLKO2:

# devmem 0x20C4060 32 0x1EA0001

See the reference manual of the OPOS6UL/L for the others clocks "exportable".

Links