Documente Academic
Documente Profesional
Documente Cultură
Techniques
Kishon Vijay Abraham I and Basak Partha
Agenda
Introduction
USB Generic Linux System Architecture
USB Mass Storage Architecture
Challenges in debugging
USB Debugging Techniques (sysfs, usbmon, dynamic debug interface,
tracepoint, protocol analyzer)
Gadget Zero
Other profiling tools
Introduction
Widespread use of USB in embedded space
HOST MODE:
To connect Ethernet/Hub
To connect Modem
To connect mass storage devices
DEVICE MODE
Acts as mass storage device
USB Speakers
USB serial device
USB webcam
Introduction
Ease of use
Hot pluggable
Speed
Reliability
Power devices from the bus
Bus expansion using hub
USB On-The-Go
DEVICE
libusb
Gadget Driver
VFS
UDC
Class Driver
HCD/usbcore
Firmware Driver
Firmware Driver
Device Controller
ulpi/utmi
PHY
Device
HOST
HSIC/TLL
Host Controller
ulpi/utmi
PHY
Host
SWcomp
HWcomp
Block Layer
Backing Store
VFS
VFS
Mass Storage
Function Driver
SCSI
Block Layer
UDC
Mass storage
Class driver
HCD/usbcore
Firmware Driver
Firmware Driver
Device Controller
ulpi/utmi
HSIC
/TLL
File System
SWcomp
Host Controller
ulpi/utmi
PHY
PHY
Device
Host
HWcomp
Challenges in debugging
Data on the bus is encoded
Timing issues
Out-of spec signaling errors
Protocol errors
Multiple layers makes it difficult to identify where exactly the problem
originates
Too many formatted prints lead to skewed results
USB debugging
Using linux kernel facilities
sysfs/debugfs
usbmon
Dynamic debug interface
Tracepoints
Using debug tools and Analyzers
Elisys/Lecroy/total Phase analyzer tools
ETM
TheDocumentationinformationforthisentrycanbeobtainedfrom
http://www.linuxusb.org/FAQ.html#i6
T:Bus=01Lev=00Prnt=00Port=00Cnt=00Dev#=1Spd=480MxCh=3
B:Alloc=0/800us(0%),#Int=1,#Iso=0
D:Ver=2.00Cls=09(hub)Sub=00Prot=00MxPS=64#Cfgs=1
P:Vendor=1d6bProdID=0002Rev=3.06
S:Manufacturer=Linux3.7.0rc2next2012102600003g72580a5ehci_hcd
S:Product=OMAPEHCIHostController
S:SerialNumber=ehciomap.0
C:*#Ifs=1Cfg#=1Atr=e0MxPwr=0mA
I:*If#=0Alt=0#EPs=1Cls=09(hub)Sub=00Prot=00Driver=hub
E:Ad=81(I)Atr=03(Int.)MxPS=4Ivl=256ms
T:Bus=01Lev=01Prnt=01Port=00Cnt=01Dev#=2Spd=480MxCh=5
D:Ver=2.00Cls=09(hub)Sub=00Prot=02MxPS=64#Cfgs=1
P:Vendor=0424ProdID=9514Rev=2.00
C:*#Ifs=1Cfg#=1Atr=e0MxPwr=2mA
I:If#=0Alt=0#EPs=1Cls=09(hub)Sub=00Prot=01Driver=hub
E:Ad=81(I)Atr=03(Int.)MxPS=1Ivl=256ms
I:*If#=0Alt=1#EPs=1Cls=09(hub)Sub=00Prot=02Driver=hub
E:Ad=81(I)Atr=03(Int.)MxPS=1Ivl=256ms
TheDocumentationinformationforthisentrycanbeobtainedfrom
Documentation/usb/proc_usb_info.txt
10
TheDocumentationinformationforthisentrycanbeobtainedfrom
Documentation/usb/proc_usb_info.txt
11
12
DWC3WRAPPER
DWC3CORE
interupt
HWWrite
MPU
SWRead
EVENTBUFFER
Configuration Diagram
13
WorkingRegdump
(BeforeSuspend)
NonWorkingRegdump
(AfterResume)
After going to OFF mode and coming back, DEVTEN register lost the
contents.
DEVTEN controls the generation of device specific events.
The fix is to restore the contents of DEVTEN after coming back from
OFF mode.
14
usbmon
Facility in kernel to be used to collect URB traces
USB monitoring facilities for Linux consists of a kernel part and user
part
Reports requests made by peripheral-specific drivers to Host
Controller Drivers (HCD)
Requires a reliable working HCD
Has a "text" and "binary" API
15
usbmon Architecture
binary
Character device
(for each host
controller)
usbmon main
urb_submit/
urb_complete/
add/remove bus
HCD
/dev/usbmonX
text
Debugfs entry
(for each host
controller)
/sys/kernel/debug/
/usb/usbmon/Xu
tcpdump
vusb-analyzer
wireshark
Linuxkernelcomp
Userspacetools
16
17
18
Time
stamp
Urb
Event
d2263780
469874560
wValue
wIndex
wLength
URB
Address
Time
stamp
d2263780
469875939
Urb
Event
C
Transfer
Bus
&
Number
Direction
Ci
Transfer
Bus
&
Number
Direction
Ci
Device
Number
003
Device
Number
003
Endpoint
URB
Number
Status
0
Endpoint
URB
Number
Status
0
bmRequest bRequest
type
80
Length
06
data
= 12010002
ef020140
19
catusb_nw.mon|grep2:011>usb_nw_dev.mon
catusb_w.mon|grep1:019>usb_w_dev.mon
./vusbanalyzerusb_nw_dev.monusb_w_dev.mon
The non working log has some additional commands compared to
working log
20
NONWORKINGLOG
From the diff, there are additional commands in the non-working case
like the UDISK shown in the command
Then the URB return status shows broken PIPE error.
The host sends CLEAR ENDPOINT HALT and this happens again and
again
So it's concluded some user space program send bogus commands
causing the issue.
21
catusb2.mon|grep1:006>usb2_nw.mon
catusb3.mon|grep3:003>usb3_w.mon
./vusbanalyzerusb2_nw.monusb3_w.mon
22
NONWorkingusbmonlog
Workingusbmonlog
Both traces show that the webcam stopped being used for a short time
and was suspended
when it was resumed again, it worked okay in USB3 but did not work in
USB-2
The workaround was to disable auto-suspend (and debug the device)
23
26
Protocol Analyzer
A protocol analyzer decodes, filters, and displays USB data
Some analyzers also have an exerciser along with it that can generate
data on the bus
PROTOCOLANALYZER
SWPC
PROTOCOLANALYZER
UsbDevice
UsbHost
27
NonWorking(OMAP5)
Working(OMAP4)
28
29
tracepoint
Used to record data at a specific point in the kernel for later retrieval
Light weight hooks added to the kernel
Two types: static tracepoint and dynamic tracepoint
can be used by a number of tools for kernel debugging and
performance problem diagnosis
They have zero overhead when disabled and minimal overhead when
enabled
30
34
Tracepoint Sample
Patch to log usb_request from gadget layer
http://gitorious.org/linux-usb/linux-usb/commit/a7e7fb69808c
Patch to log every read/write in dwc3
http://comments.gmane.org/gmane.linux.usb.general/64821
([PATCH] usb: dwc3: add trace support)
35
Gadget Zero
Obtain performance characteristics
Two configuration device
sinks and sources bulk data
loops back a configurable number of transfers
A kernel driver (host), drivers/usb/misc/usbtest.c, where the
actual test cases live
Userland software to call that driver, such as testusb.c and
test.sh
Can't be used for class or vendor-specific functionality
36
38
39
References
Documentation/usb/*
Documentation/trace/*
Drivers/usb/*
lwn.net
Bootstrap Yourself with Linux-USB Stack
linux-usb list
http://vusb-analyzer.sourceforge.net/
40
THANK YOU
For Queries and Feedback
kishon@ti.com, kishonvijayabraham@gmail.com
partha_basak2000@yahoo.com
41