162306a36Sopenharmony_ci=========================================================================== 262306a36Sopenharmony_ciUsing physical DMA provided by OHCI-1394 FireWire controllers for debugging 362306a36Sopenharmony_ci=========================================================================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciIntroduction 662306a36Sopenharmony_ci------------ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciBasically all FireWire controllers which are in use today are compliant 962306a36Sopenharmony_cito the OHCI-1394 specification which defines the controller to be a PCI 1062306a36Sopenharmony_cibus master which uses DMA to offload data transfers from the CPU and has 1162306a36Sopenharmony_cia "Physical Response Unit" which executes specific requests by employing 1262306a36Sopenharmony_ciPCI-Bus master DMA after applying filters defined by the OHCI-1394 driver. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciOnce properly configured, remote machines can send these requests to 1562306a36Sopenharmony_ciask the OHCI-1394 controller to perform read and write requests on 1662306a36Sopenharmony_ciphysical system memory and, for read requests, send the result of 1762306a36Sopenharmony_cithe physical memory read back to the requester. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciWith that, it is possible to debug issues by reading interesting memory 2062306a36Sopenharmony_cilocations such as buffers like the printk buffer or the process table. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciRetrieving a full system memory dump is also possible over the FireWire, 2362306a36Sopenharmony_ciusing data transfer rates in the order of 10MB/s or more. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciWith most FireWire controllers, memory access is limited to the low 4 GB 2662306a36Sopenharmony_ciof physical address space. This can be a problem on IA64 machines where 2762306a36Sopenharmony_cimemory is located mostly above that limit, but it is rarely a problem on 2862306a36Sopenharmony_cimore common hardware such as x86, x86-64 and PowerPC. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciAt least LSI FW643e and FW643e2 controllers are known to support access to 3162306a36Sopenharmony_ciphysical addresses above 4 GB, but this feature is currently not enabled by 3262306a36Sopenharmony_ciLinux. 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciTogether with a early initialization of the OHCI-1394 controller for debugging, 3562306a36Sopenharmony_cithis facility proved most useful for examining long debugs logs in the printk 3662306a36Sopenharmony_cibuffer on to debug early boot problems in areas like ACPI where the system 3762306a36Sopenharmony_cifails to boot and other means for debugging (serial port) are either not 3862306a36Sopenharmony_ciavailable (notebooks) or too slow for extensive debug information (like ACPI). 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciDrivers 4162306a36Sopenharmony_ci------- 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciThe firewire-ohci driver in drivers/firewire uses filtered physical 4462306a36Sopenharmony_ciDMA by default, which is more secure but not suitable for remote debugging. 4562306a36Sopenharmony_ciPass the remote_dma=1 parameter to the driver to get unfiltered physical DMA. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciBecause the firewire-ohci driver depends on the PCI enumeration to be 4862306a36Sopenharmony_cicompleted, an initialization routine which runs pretty early has been 4962306a36Sopenharmony_ciimplemented for x86. This routine runs long before console_init() can be 5062306a36Sopenharmony_cicalled, i.e. before the printk buffer appears on the console. 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciTo activate it, enable CONFIG_PROVIDE_OHCI1394_DMA_INIT (Kernel hacking menu: 5362306a36Sopenharmony_ciRemote debugging over FireWire early on boot) and pass the parameter 5462306a36Sopenharmony_ci"ohci1394_dma=early" to the recompiled kernel on boot. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciTools 5762306a36Sopenharmony_ci----- 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_cifirescope - Originally developed by Benjamin Herrenschmidt, Andi Kleen ported 6062306a36Sopenharmony_ciit from PowerPC to x86 and x86_64 and added functionality, firescope can now 6162306a36Sopenharmony_cibe used to view the printk buffer of a remote machine, even with live update. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciBernhard Kaindl enhanced firescope to support accessing 64-bit machines 6462306a36Sopenharmony_cifrom 32-bit firescope and vice versa: 6562306a36Sopenharmony_ci- http://v3.sk/~lkundrak/firescope/ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ciand he implemented fast system dump (alpha version - read README.txt): 6862306a36Sopenharmony_ci- http://halobates.de/firewire/firedump-0.1.tar.bz2 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciThere is also a gdb proxy for firewire which allows to use gdb to access 7162306a36Sopenharmony_cidata which can be referenced from symbols found by gdb in vmlinux: 7262306a36Sopenharmony_ci- http://halobates.de/firewire/fireproxy-0.33.tar.bz2 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciThe latest version of this gdb proxy (fireproxy-0.34) can communicate (not 7562306a36Sopenharmony_ciyet stable) with kgdb over an memory-based communication module (kgdbom). 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciGetting Started 7862306a36Sopenharmony_ci--------------- 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciThe OHCI-1394 specification regulates that the OHCI-1394 controller must 8162306a36Sopenharmony_cidisable all physical DMA on each bus reset. 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciThis means that if you want to debug an issue in a system state where 8462306a36Sopenharmony_ciinterrupts are disabled and where no polling of the OHCI-1394 controller 8562306a36Sopenharmony_cifor bus resets takes place, you have to establish any FireWire cable 8662306a36Sopenharmony_ciconnections and fully initialize all FireWire hardware __before__ the 8762306a36Sopenharmony_cisystem enters such state. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciStep-by-step instructions for using firescope with early OHCI initialization: 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci1) Verify that your hardware is supported: 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci Load the firewire-ohci module and check your kernel logs. 9462306a36Sopenharmony_ci You should see a line similar to:: 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci firewire_ohci 0000:15:00.1: added OHCI v1.0 device as card 2, 4 IR + 4 IT 9762306a36Sopenharmony_ci ... contexts, quirks 0x11 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci when loading the driver. If you have no supported controller, many PCI, 10062306a36Sopenharmony_ci CardBus and even some Express cards which are fully compliant to OHCI-1394 10162306a36Sopenharmony_ci specification are available. If it requires no driver for Windows operating 10262306a36Sopenharmony_ci systems, it most likely is. Only specialized shops have cards which are not 10362306a36Sopenharmony_ci compliant, they are based on TI PCILynx chips and require drivers for Windows 10462306a36Sopenharmony_ci operating systems. 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci The mentioned kernel log message contains the string "physUB" if the 10762306a36Sopenharmony_ci controller implements a writable Physical Upper Bound register. This is 10862306a36Sopenharmony_ci required for physical DMA above 4 GB (but not utilized by Linux yet). 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci2) Establish a working FireWire cable connection: 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci Any FireWire cable, as long at it provides electrically and mechanically 11362306a36Sopenharmony_ci stable connection and has matching connectors (there are small 4-pin and 11462306a36Sopenharmony_ci large 6-pin FireWire ports) will do. 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci If an driver is running on both machines you should see a line like:: 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci firewire_core 0000:15:00.1: created device fw1: GUID 00061b0020105917, S400 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci on both machines in the kernel log when the cable is plugged in 12162306a36Sopenharmony_ci and connects the two machines. 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci3) Test physical DMA using firescope: 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci On the debug host, make sure that /dev/fw* is accessible, 12662306a36Sopenharmony_ci then start firescope:: 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci $ firescope 12962306a36Sopenharmony_ci Port 0 (/dev/fw1) opened, 2 nodes detected 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci FireScope 13262306a36Sopenharmony_ci --------- 13362306a36Sopenharmony_ci Target : <unspecified> 13462306a36Sopenharmony_ci Gen : 1 13562306a36Sopenharmony_ci [Ctrl-T] choose target 13662306a36Sopenharmony_ci [Ctrl-H] this menu 13762306a36Sopenharmony_ci [Ctrl-Q] quit 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci ------> Press Ctrl-T now, the output should be similar to: 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci 2 nodes available, local node is: 0 14262306a36Sopenharmony_ci 0: ffc0, uuid: 00000000 00000000 [LOCAL] 14362306a36Sopenharmony_ci 1: ffc1, uuid: 00279000 ba4bb801 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci Besides the [LOCAL] node, it must show another node without error message. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci4) Prepare for debugging with early OHCI-1394 initialization: 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci 4.1) Kernel compilation and installation on debug target 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci Compile the kernel to be debugged with CONFIG_PROVIDE_OHCI1394_DMA_INIT 15262306a36Sopenharmony_ci (Kernel hacking: Provide code for enabling DMA over FireWire early on boot) 15362306a36Sopenharmony_ci enabled and install it on the machine to be debugged (debug target). 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci 4.2) Transfer the System.map of the debugged kernel to the debug host 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci Copy the System.map of the kernel be debugged to the debug host (the host 15862306a36Sopenharmony_ci which is connected to the debugged machine over the FireWire cable). 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci5) Retrieving the printk buffer contents: 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci With the FireWire cable connected, the OHCI-1394 driver on the debugging 16362306a36Sopenharmony_ci host loaded, reboot the debugged machine, booting the kernel which has 16462306a36Sopenharmony_ci CONFIG_PROVIDE_OHCI1394_DMA_INIT enabled, with the option ohci1394_dma=early. 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci Then, on the debugging host, run firescope, for example by using -A:: 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci firescope -A System.map-of-debug-target-kernel 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci Note: -A automatically attaches to the first non-local node. It only works 17162306a36Sopenharmony_ci reliably if only connected two machines are connected using FireWire. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci After having attached to the debug target, press Ctrl-D to view the 17462306a36Sopenharmony_ci complete printk buffer or Ctrl-U to enter auto update mode and get an 17562306a36Sopenharmony_ci updated live view of recent kernel messages logged on the debug target. 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci Call "firescope -h" to get more information on firescope's options. 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciNotes 18062306a36Sopenharmony_ci----- 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciDocumentation and specifications: http://halobates.de/firewire/ 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ciFireWire is a trademark of Apple Inc. - for more information please refer to: 18562306a36Sopenharmony_cihttps://en.wikipedia.org/wiki/FireWire 186