当前位置:网站首页>USB driver -debug

USB driver -debug

2022-06-26 03:21:00 Be good to me

1. debugfs

If the system is not automatically mounted debugfs , You need to mount manually with the following command :

mount -t debugfs none /sys/kernel/debug/		##  Default mount 
mount -t debugfs kernel_debug /data/			##  Custom mount 

During system startup , initialization usb modular :

// \linux-5.10\drivers\usb\core\usb.c
static int __init usb_init(void)
{
    
	usb_debugfs_init();		//debugfs  initialization , namely /sys/kernel/debug/(mount -t debugfs none /sys/kernel/debug/)

	retval = bus_register(&usb_bus_type);		// register usb  Bus 

	retval = usb_register(&usbfs_driver);		// register usb_driver: usbfs

	retval = usb_devio_init();					//usbfs  initialization , namely /sys/kernel/debug/usb/

	retval = usb_hub_init();					// initialization usb_driver: hub

	retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);	//generic  drive 
}

usb_register(&usbfs_driver)usb_devio_init() All are usbfs Related initialization .
usbfs It provides us with direct access in user space usb Interface of hardware equipment , But it needs strong support from the kernel ,usbfs_driver(\drivers\usb\core\devio.c) Is used to complete this glorious task .

1.1 trace

Linux The system comes with a kind of trace, be located /sys/kernel/tracing/ or /sys/kernel/debug/tracing/, Print :

trace_dwc3_gadget_ep_cmd(dep, cmd, params, cmd_status);

(1)dwc3 trace

echo 1 > /sys/kernel/tracing/instances/usb/events/dwc3/enable	# open dwc3 Of tracing
cat /sys/kernel/tracing/instances/usb/trace > /data/out.txt  	# preservation trace

Note: To reduce the number of log events we can disable logging for dwc3_readl/writel.

echo 0 > /sys/kernel/debug/tracing/instances/usb/events/dwc3/dwc3_readl/enable
echo 0 > /sys/kernel/debug/tracing/instances/usb/events/dwc3/dwc3_writel/enable

(2)xhci trace

echo 1 > /sys/kernel/tracing/instances/usb/events/xhci-hcd/enable
cat /sys/kernel/tracing/instances/usb/trace_pipe > /data/trace_pipe.txt &

(3)trace Main switch :

echo 1 > /sys/kernel/tracing/tracing_on		# Open all trace
cat /sys/kernel/tracing/trace_pipe

1.2 ipc_logging

Qualcomm A kind of self added log, For tracking mdwc3 act .

cat /d/ipc_logging/4e00000.dwc3/log

or

cat /sys/kernel/debug/ipc_logging/4e00000.dwc3/log

1.3 strace

strace ./yavta -f YUYV -s 1280x720 -t 1/60 -c100 /dev/video0 > logcat.log

1.4 Switch usb Pattern

echo none > /sys/bus/platform/devices/6a00000.ssusb/mode   			# To break off USB
echo peripheral > /sys/bus/platform/devices/6a00000.ssusb/mode   	#device mode
echo host > /sys/bus/platform/devices/6a00000.ssusb/mode   			#host mode

2. procfs

(1) see IO Memory allocation

cat /proc/iomem		# see IO Memory allocation 
sm6150:/ # cat /proc/iomem
00100000-002effff : cc_base
007c4000-007c4fff : hc_mem
007c8000-007cffff : /soc/[email protected]
00884000-00887fff : /soc/[email protected]						#i2c
0088c000-0088ffff : /soc/[email protected]
008c0000-008c5fff : /soc/qcom,[email protected]
00a84000-00a87fff : /soc/[email protected]
00ac0000-00ac5fff : /soc/qcom,[email protected]
01d90000-01d97fff : /soc/[email protected]
01fcb244-01fcb247 : vls_clamp_reg
01fed000-01fed027 : /soc/[email protected]
03000000-03dc1fff : pinctrl
...
08804000-08804fff : hc_mem
088e0000-088e1fff : eud_base
088e2000-088e217f : qusb_phy_base					#usb phy
088e3000-088e317f : qusb_phy_base				
090cc000-090cc2ff : lagg-base
0a60c100-0a60ccff : /soc/[email protected]/[email protected]		#usb0
0a800000-0a807fff : /soc/[email protected]/[email protected]		#usb1
...

(2) View the device and master device number registered in the system :

sm6150:/ # cat /proc/devices | grep usb
180 usb
189 usb_device
494 ccid_usb
495 msm_usb_bridge
506 gsi_usb

3. host

(1) see USB Insert device information , Print all device information under the bus ( Contains descriptor information ).

cat /sys/kernel/debug/usb/devices

(2) see usb Under the bus device:

ls /sys/bus/usb/devices/
1-0:1.0 2-0:1.0 3-0:1.0 usb1 usb2 usb3

analysis :

1-0:1.0		1-0( A hub 1- Hub port number 0):1( The first configuration ).0( First interface )
usb1		dummy root hub、USB Host controller 、USB Bus 1;
usb2		2.0 root hub、USB host 2.0 controller 、USB Bus 2;
usb3		3.0 root hub、USB host 3.0 controller 、USB Bus 3;

Insert U disc ( There is one more device interface :2-1:1.0)

1-0:1.0 2-0:1.0 2-1 2-1:1.0 3-0:1.0 usb1 usb2 usb3

analysis ;

2-1			u Disk equipment 
2-1:1.0		2-1( A hub 2- Hub port number 1):1( The first configuration ).0( First interface )

(3) View the device tree node architecture :

ls /sys/devices/platform/soc/4e00000.ssusb/4e00000.dwc3/xhci-hcd.2.auto/usb2/2-1/2-1:1.0

analysis :

soc					# Child nodes of the root node of the device tree , As platform device It is parsed by the system 
4e00000.ssusb 		# because soc have compatible Of bus attribute , Its child nodes act as platform Device registration , Qualcomm defined mdwc
4e00000.dwc3		#dwc3 usb core Subsystem , By mdwc  register 
xhci-hcd.2.auto		# Host controller xhci
usb2				#usb2.0 controller ,usb Bus 2
2-1					#usb equipment ( Such as U disc )
2-1:1.0				#usb Interface device 
原网站

版权声明
本文为[Be good to me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260251291375.html