Tools and Techniques for Debugging Embedded Linux Systems
Tools and Techniques for Debugging Embedded Linux Systems
1
Making Wireless
Overview
• Debugging with prints
• Logging to circular buffers
• SW trace tools
• ETM
• Observability and GPIOs
• JTAG
• Register dumps and decoders
2
Making Wireless
Printf debugging
• Basic debugging technique
• Simple to use
3
Making Wireless
printk loglevels
• From KERN_EMERG to KERN_DEBUG
– pr_emerg to pr_debug
• Can change on the kernel command line
– loglevel= parameter
• Can change after bootup
– /proc/sys/kernel/printk
– /proc/sysrq-trigger
4
Making Wireless
5
Making Wireless
6
Making Wireless
• http://elinux.org/Kernel_Debugging_Tips
7
Making Wireless
• Why?
8
Making Wireless
9
Making Wireless
Throughput (Mbps)
Debug
Level Prints to console disabled Prints to console enabled
TX RX TX RX
1 169 65
3 161 32 1.25 0.16
5 113 18 0.49 0.07
Notes:
Debug level 3 adds 19 lines of print per transfer for TX and 40 for RX
Debug level 5 adds 37 and 92 respectively
10
Making Wireless
Dynamic printks
• CONFIG_DYNAMIC_DEBUG
– Introduced in 2.6.30
• Operates on pr_debug/dev_dbg
• More info
– Documentation/dynamic-debug-howto.txt
– http://lwn.net/Articles/434833/
11
Making Wireless
Circular buffers
• Useful when you want to capture the last few
things that were going on in the system
• In some cases, single character circular buffers
are all that you can afford (DSP SW…)
12
Making Wireless
13
Making Wireless
14
Making Wireless
• Bingo!
– Hit the failure, and still have a good trace of the
program flow
– Now we know where to look
15
Making Wireless
16
Making Wireless
SW Trace Tools
• Tracepoints and markers
• Ftrace
• LTTng
• Perf
17
Making Wireless
Protocol Analyzers
• USBMON
• Wireshark
18
Making Wireless
HW trace – ETM/ETB
• What is ETM
– Embedded Trace Macrocell
• The ETM can capture the program counter value
upon certain events (waypoints)
– A waypoint is a point where instruction execution may
change the program flow
• Branch instructions
• Exceptions
19
Making Wireless
HW trace – ETM/ETB
• ETB
– ETB is on SoC buffer
– ETB buffer is usually small – 2k to 8k
• (about 10-30k lines of code)
• ETM
– Streaming same trace content to an external trace port
– Needs to be continuously read by an ‘external trace
receiver’
20
Making Wireless
HW trace – ETM/ETB
• ETM
– Needs JTAG Debugger
– Needs external trace receiver
• ETB
– Can be dumped using just a JTAG debugger
– Can be dumped using software
• See kernel driver for ETB/ETM
– arch/arm/kernel/etm.c
• Analysis software:
– https://github.com/virtuoso/etm2human
21
Making Wireless
HW trace – ETM/ETB
• Why is it useful
– Very accurate profiling
– No need to instrument the code
– Can be used to reconstruct program flow
– Can step back in code
• How?
22
Making Wireless
ETM - Example
23
Making Wireless
ETM - Example
24
Making Wireless
25
Making Wireless
128 32
CORE MUX i
WKUP MUX i
HW_DBG_i
i = 0..17
26
Making Wireless
– Tie high
– Tie low
• Useful to check if the pin muxing and other settings are
configured correctly
• and to check if you’re actually observing the correct line
GPIO markers
• Toggle GPIOs at interesting points in the code
– Observe with a scope (or even better, a logic analyzer)
28
Making Wireless
• Disadvantages
– Cannot get values of variables/parameters
– No framework - easy for debugger to make mistakes?
– May not have enough spare pins
• Sometimes pads are not accessible on near-production boards
– Scope/LA are expensive
• especially the good ones
29
Making Wireless
30
Making Wireless
31
Making Wireless
• Heartbeat LEDs
– (don’t enable in production – they drain power)
32
Making Wireless
JTAG
• Examples:
– Lauterbach Power Debug
– ARM Realview ICE, ARM DS/5
– XDS560
– Flyswatter
– OpenOCD
33
Making Wireless
34
Making Wireless
35
Making Wireless
36
Making Wireless
Register decoders
• Example
– pxaregs
37
Making Wireless
Register decoders
• Exporting register info in debugfs
• Example - MUSB in debugfs
38