debugging-via-ohci1394.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. ===========================================================================
  2. Using physical DMA provided by OHCI-1394 FireWire controllers for debugging
  3. ===========================================================================
  4. Introduction
  5. ------------
  6. Basically all FireWire controllers which are in use today are compliant
  7. to the OHCI-1394 specification which defines the controller to be a PCI
  8. bus master which uses DMA to offload data transfers from the CPU and has
  9. a "Physical Response Unit" which executes specific requests by employing
  10. PCI-Bus master DMA after applying filters defined by the OHCI-1394 driver.
  11. Once properly configured, remote machines can send these requests to
  12. ask the OHCI-1394 controller to perform read and write requests on
  13. physical system memory and, for read requests, send the result of
  14. the physical memory read back to the requester.
  15. With that, it is possible to debug issues by reading interesting memory
  16. locations such as buffers like the printk buffer or the process table.
  17. Retrieving a full system memory dump is also possible over the FireWire,
  18. using data transfer rates in the order of 10MB/s or more.
  19. With most FireWire controllers, memory access is limited to the low 4 GB
  20. of physical address space. This can be a problem on IA64 machines where
  21. memory is located mostly above that limit, but it is rarely a problem on
  22. more common hardware such as x86, x86-64 and PowerPC.
  23. At least LSI FW643e and FW643e2 controllers are known to support access to
  24. physical addresses above 4 GB, but this feature is currently not enabled by
  25. Linux.
  26. Together with a early initialization of the OHCI-1394 controller for debugging,
  27. this facility proved most useful for examining long debugs logs in the printk
  28. buffer on to debug early boot problems in areas like ACPI where the system
  29. fails to boot and other means for debugging (serial port) are either not
  30. available (notebooks) or too slow for extensive debug information (like ACPI).
  31. Drivers
  32. -------
  33. The firewire-ohci driver in drivers/firewire uses filtered physical
  34. DMA by default, which is more secure but not suitable for remote debugging.
  35. Pass the remote_dma=1 parameter to the driver to get unfiltered physical DMA.
  36. Because the firewire-ohci driver depends on the PCI enumeration to be
  37. completed, an initialization routine which runs pretty early has been
  38. implemented for x86. This routine runs long before console_init() can be
  39. called, i.e. before the printk buffer appears on the console.
  40. To activate it, enable CONFIG_PROVIDE_OHCI1394_DMA_INIT (Kernel hacking menu:
  41. Remote debugging over FireWire early on boot) and pass the parameter
  42. "ohci1394_dma=early" to the recompiled kernel on boot.
  43. Tools
  44. -----
  45. firescope - Originally developed by Benjamin Herrenschmidt, Andi Kleen ported
  46. it from PowerPC to x86 and x86_64 and added functionality, firescope can now
  47. be used to view the printk buffer of a remote machine, even with live update.
  48. Bernhard Kaindl enhanced firescope to support accessing 64-bit machines
  49. from 32-bit firescope and vice versa:
  50. - http://v3.sk/~lkundrak/firescope/
  51. and he implemented fast system dump (alpha version - read README.txt):
  52. - http://halobates.de/firewire/firedump-0.1.tar.bz2
  53. There is also a gdb proxy for firewire which allows to use gdb to access
  54. data which can be referenced from symbols found by gdb in vmlinux:
  55. - http://halobates.de/firewire/fireproxy-0.33.tar.bz2
  56. The latest version of this gdb proxy (fireproxy-0.34) can communicate (not
  57. yet stable) with kgdb over an memory-based communication module (kgdbom).
  58. Getting Started
  59. ---------------
  60. The OHCI-1394 specification regulates that the OHCI-1394 controller must
  61. disable all physical DMA on each bus reset.
  62. This means that if you want to debug an issue in a system state where
  63. interrupts are disabled and where no polling of the OHCI-1394 controller
  64. for bus resets takes place, you have to establish any FireWire cable
  65. connections and fully initialize all FireWire hardware __before__ the
  66. system enters such state.
  67. Step-by-step instructions for using firescope with early OHCI initialization:
  68. 1) Verify that your hardware is supported:
  69. Load the firewire-ohci module and check your kernel logs.
  70. You should see a line similar to::
  71. firewire_ohci 0000:15:00.1: added OHCI v1.0 device as card 2, 4 IR + 4 IT
  72. ... contexts, quirks 0x11
  73. when loading the driver. If you have no supported controller, many PCI,
  74. CardBus and even some Express cards which are fully compliant to OHCI-1394
  75. specification are available. If it requires no driver for Windows operating
  76. systems, it most likely is. Only specialized shops have cards which are not
  77. compliant, they are based on TI PCILynx chips and require drivers for Windows
  78. operating systems.
  79. The mentioned kernel log message contains the string "physUB" if the
  80. controller implements a writable Physical Upper Bound register. This is
  81. required for physical DMA above 4 GB (but not utilized by Linux yet).
  82. 2) Establish a working FireWire cable connection:
  83. Any FireWire cable, as long at it provides electrically and mechanically
  84. stable connection and has matching connectors (there are small 4-pin and
  85. large 6-pin FireWire ports) will do.
  86. If an driver is running on both machines you should see a line like::
  87. firewire_core 0000:15:00.1: created device fw1: GUID 00061b0020105917, S400
  88. on both machines in the kernel log when the cable is plugged in
  89. and connects the two machines.
  90. 3) Test physical DMA using firescope:
  91. On the debug host, make sure that /dev/fw* is accessible,
  92. then start firescope::
  93. $ firescope
  94. Port 0 (/dev/fw1) opened, 2 nodes detected
  95. FireScope
  96. ---------
  97. Target : <unspecified>
  98. Gen : 1
  99. [Ctrl-T] choose target
  100. [Ctrl-H] this menu
  101. [Ctrl-Q] quit
  102. ------> Press Ctrl-T now, the output should be similar to:
  103. 2 nodes available, local node is: 0
  104. 0: ffc0, uuid: 00000000 00000000 [LOCAL]
  105. 1: ffc1, uuid: 00279000 ba4bb801
  106. Besides the [LOCAL] node, it must show another node without error message.
  107. 4) Prepare for debugging with early OHCI-1394 initialization:
  108. 4.1) Kernel compilation and installation on debug target
  109. Compile the kernel to be debugged with CONFIG_PROVIDE_OHCI1394_DMA_INIT
  110. (Kernel hacking: Provide code for enabling DMA over FireWire early on boot)
  111. enabled and install it on the machine to be debugged (debug target).
  112. 4.2) Transfer the System.map of the debugged kernel to the debug host
  113. Copy the System.map of the kernel be debugged to the debug host (the host
  114. which is connected to the debugged machine over the FireWire cable).
  115. 5) Retrieving the printk buffer contents:
  116. With the FireWire cable connected, the OHCI-1394 driver on the debugging
  117. host loaded, reboot the debugged machine, booting the kernel which has
  118. CONFIG_PROVIDE_OHCI1394_DMA_INIT enabled, with the option ohci1394_dma=early.
  119. Then, on the debugging host, run firescope, for example by using -A::
  120. firescope -A System.map-of-debug-target-kernel
  121. Note: -A automatically attaches to the first non-local node. It only works
  122. reliably if only connected two machines are connected using FireWire.
  123. After having attached to the debug target, press Ctrl-D to view the
  124. complete printk buffer or Ctrl-U to enter auto update mode and get an
  125. updated live view of recent kernel messages logged on the debug target.
  126. Call "firescope -h" to get more information on firescope's options.
  127. Notes
  128. -----
  129. Documentation and specifications: http://halobates.de/firewire/
  130. FireWire is a trademark of Apple Inc. - for more information please refer to:
  131. https://en.wikipedia.org/wiki/FireWire