usb3-debug-port.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ===============
  2. USB3 debug port
  3. ===============
  4. :Author: Lu Baolu <[email protected]>
  5. :Date: March 2017
  6. GENERAL
  7. =======
  8. This is a HOWTO for using the USB3 debug port on x86 systems.
  9. Before using any kernel debugging functionality based on USB3
  10. debug port, you need to::
  11. 1) check whether any USB3 debug port is available in
  12. your system;
  13. 2) check which port is used for debugging purposes;
  14. 3) have a USB 3.0 super-speed A-to-A debugging cable.
  15. INTRODUCTION
  16. ============
  17. The xHCI debug capability (DbC) is an optional but standalone
  18. functionality provided by the xHCI host controller. The xHCI
  19. specification describes DbC in the section 7.6.
  20. When DbC is initialized and enabled, it will present a debug
  21. device through the debug port (normally the first USB3
  22. super-speed port). The debug device is fully compliant with
  23. the USB framework and provides the equivalent of a very high
  24. performance full-duplex serial link between the debug target
  25. (the system under debugging) and a debug host.
  26. EARLY PRINTK
  27. ============
  28. DbC has been designed to log early printk messages. One use for
  29. this feature is kernel debugging. For example, when your machine
  30. crashes very early before the regular console code is initialized.
  31. Other uses include simpler, lockless logging instead of a full-
  32. blown printk console driver and klogd.
  33. On the debug target system, you need to customize a debugging
  34. kernel with CONFIG_EARLY_PRINTK_USB_XDBC enabled. And, add below
  35. kernel boot parameter::
  36. "earlyprintk=xdbc"
  37. If there are multiple xHCI controllers in your system, you can
  38. append a host contoller index to this kernel parameter. This
  39. index starts from 0.
  40. Current design doesn't support DbC runtime suspend/resume. As
  41. the result, you'd better disable runtime power management for
  42. USB subsystem by adding below kernel boot parameter::
  43. "usbcore.autosuspend=-1"
  44. Before starting the debug target, you should connect the debug
  45. port to a USB port (root port or port of any external hub) on
  46. the debug host. The cable used to connect these two ports
  47. should be a USB 3.0 super-speed A-to-A debugging cable.
  48. During early boot of the debug target, DbC will be detected and
  49. initialized. After initialization, the debug host should be able
  50. to enumerate the debug device in debug target. The debug host
  51. will then bind the debug device with the usb_debug driver module
  52. and create the /dev/ttyUSB device.
  53. If the debug device enumeration goes smoothly, you should be able
  54. to see below kernel messages on the debug host::
  55. # tail -f /var/log/kern.log
  56. [ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using xhci_hcd
  57. [ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM.
  58. [ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, idProduct=0004
  59. [ 1815.999902] usb 4-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
  60. [ 1815.999903] usb 4-3: Product: Remote GDB
  61. [ 1815.999904] usb 4-3: Manufacturer: Linux
  62. [ 1815.999905] usb 4-3: SerialNumber: 0001
  63. [ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected
  64. [ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0
  65. You can use any communication program, for example minicom, to
  66. read and view the messages. Below simple bash scripts can help
  67. you to check the sanity of the setup.
  68. .. code-block:: sh
  69. ===== start of bash scripts =============
  70. #!/bin/bash
  71. while true ; do
  72. while [ ! -d /sys/class/tty/ttyUSB0 ] ; do
  73. :
  74. done
  75. cat /dev/ttyUSB0
  76. done
  77. ===== end of bash scripts ===============
  78. Serial TTY
  79. ==========
  80. The DbC support has been added to the xHCI driver. You can get a
  81. debug device provided by the DbC at runtime.
  82. In order to use this, you need to make sure your kernel has been
  83. configured to support USB_XHCI_DBGCAP. A sysfs attribute under
  84. the xHCI device node is used to enable or disable DbC. By default,
  85. DbC is disabled::
  86. root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
  87. disabled
  88. Enable DbC with the following command::
  89. root@target:/sys/bus/pci/devices/0000:00:14.0# echo enable > dbc
  90. You can check the DbC state at anytime::
  91. root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
  92. enabled
  93. Connect the debug target to the debug host with a USB 3.0 super-
  94. speed A-to-A debugging cable. You can see /dev/ttyDBC0 created
  95. on the debug target. You will see below kernel message lines::
  96. root@target: tail -f /var/log/kern.log
  97. [ 182.730103] xhci_hcd 0000:00:14.0: DbC connected
  98. [ 191.169420] xhci_hcd 0000:00:14.0: DbC configured
  99. [ 191.169597] xhci_hcd 0000:00:14.0: DbC now attached to /dev/ttyDBC0
  100. Accordingly, the DbC state has been brought up to::
  101. root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
  102. configured
  103. On the debug host, you will see the debug device has been enumerated.
  104. You will see below kernel message lines::
  105. root@host: tail -f /var/log/kern.log
  106. [ 79.454780] usb 2-2.1: new SuperSpeed USB device number 3 using xhci_hcd
  107. [ 79.475003] usb 2-2.1: LPM exit latency is zeroed, disabling LPM.
  108. [ 79.475389] usb 2-2.1: New USB device found, idVendor=1d6b, idProduct=0010
  109. [ 79.475390] usb 2-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
  110. [ 79.475391] usb 2-2.1: Product: Linux USB Debug Target
  111. [ 79.475392] usb 2-2.1: Manufacturer: Linux Foundation
  112. [ 79.475393] usb 2-2.1: SerialNumber: 0001
  113. The debug device works now. You can use any communication or debugging
  114. program to talk between the host and the target.