1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============ 4*4882a593SmuzhiyunEarly Printk 5*4882a593Smuzhiyun============ 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunMini-HOWTO for using the earlyprintk=dbgp boot option with a 8*4882a593SmuzhiyunUSB2 Debug port key and a debug cable, on x86 systems. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunYou need two computers, the 'USB debug key' special gadget and 11*4882a593Smuzhiyuntwo USB cables, connected like this:: 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun [host/target] <-------> [USB debug key] <-------> [client/console] 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunHardware requirements 16*4882a593Smuzhiyun===================== 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun a) Host/target system needs to have USB debug port capability. 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun You can check this capability by looking at a 'Debug port' bit in 21*4882a593Smuzhiyun the lspci -vvv output:: 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun # lspci -vvv 24*4882a593Smuzhiyun ... 25*4882a593Smuzhiyun 00:1d.7 USB Controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #1 (rev 03) (prog-if 20 [EHCI]) 26*4882a593Smuzhiyun Subsystem: Lenovo ThinkPad T61 27*4882a593Smuzhiyun Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- 28*4882a593Smuzhiyun Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- 29*4882a593Smuzhiyun Latency: 0 30*4882a593Smuzhiyun Interrupt: pin D routed to IRQ 19 31*4882a593Smuzhiyun Region 0: Memory at fe227000 (32-bit, non-prefetchable) [size=1K] 32*4882a593Smuzhiyun Capabilities: [50] Power Management version 2 33*4882a593Smuzhiyun Flags: PMEClk- DSI- D1- D2- AuxCurrent=375mA PME(D0+,D1-,D2-,D3hot+,D3cold+) 34*4882a593Smuzhiyun Status: D0 PME-Enable- DSel=0 DScale=0 PME+ 35*4882a593Smuzhiyun Capabilities: [58] Debug port: BAR=1 offset=00a0 36*4882a593Smuzhiyun ^^^^^^^^^^^ <==================== [ HERE ] 37*4882a593Smuzhiyun Kernel driver in use: ehci_hcd 38*4882a593Smuzhiyun Kernel modules: ehci-hcd 39*4882a593Smuzhiyun ... 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun .. note:: 42*4882a593Smuzhiyun If your system does not list a debug port capability then you probably 43*4882a593Smuzhiyun won't be able to use the USB debug key. 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun b) You also need a NetChip USB debug cable/key: 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun http://www.plxtech.com/products/NET2000/NET20DC/default.asp 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun This is a small blue plastic connector with two USB connections; 50*4882a593Smuzhiyun it draws power from its USB connections. 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun c) You need a second client/console system with a high speed USB 2.0 port. 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun d) The NetChip device must be plugged directly into the physical 55*4882a593Smuzhiyun debug port on the "host/target" system. You cannot use a USB hub in 56*4882a593Smuzhiyun between the physical debug port and the "host/target" system. 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun The EHCI debug controller is bound to a specific physical USB 59*4882a593Smuzhiyun port and the NetChip device will only work as an early printk 60*4882a593Smuzhiyun device in this port. The EHCI host controllers are electrically 61*4882a593Smuzhiyun wired such that the EHCI debug controller is hooked up to the 62*4882a593Smuzhiyun first physical port and there is no way to change this via software. 63*4882a593Smuzhiyun You can find the physical port through experimentation by trying 64*4882a593Smuzhiyun each physical port on the system and rebooting. Or you can try 65*4882a593Smuzhiyun and use lsusb or look at the kernel info messages emitted by the 66*4882a593Smuzhiyun usb stack when you plug a usb device into various ports on the 67*4882a593Smuzhiyun "host/target" system. 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun Some hardware vendors do not expose the usb debug port with a 70*4882a593Smuzhiyun physical connector and if you find such a device send a complaint 71*4882a593Smuzhiyun to the hardware vendor, because there is no reason not to wire 72*4882a593Smuzhiyun this port into one of the physically accessible ports. 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun e) It is also important to note, that many versions of the NetChip 75*4882a593Smuzhiyun device require the "client/console" system to be plugged into the 76*4882a593Smuzhiyun right hand side of the device (with the product logo facing up and 77*4882a593Smuzhiyun readable left to right). The reason being is that the 5 volt 78*4882a593Smuzhiyun power supply is taken from only one side of the device and it 79*4882a593Smuzhiyun must be the side that does not get rebooted. 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunSoftware requirements 82*4882a593Smuzhiyun===================== 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun a) On the host/target system: 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun You need to enable the following kernel config option:: 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun CONFIG_EARLY_PRINTK_DBGP=y 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun And you need to add the boot command line: "earlyprintk=dbgp". 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun .. note:: 93*4882a593Smuzhiyun If you are using Grub, append it to the 'kernel' line in 94*4882a593Smuzhiyun /etc/grub.conf. If you are using Grub2 on a BIOS firmware system, 95*4882a593Smuzhiyun append it to the 'linux' line in /boot/grub2/grub.cfg. If you are 96*4882a593Smuzhiyun using Grub2 on an EFI firmware system, append it to the 'linux' 97*4882a593Smuzhiyun or 'linuxefi' line in /boot/grub2/grub.cfg or 98*4882a593Smuzhiyun /boot/efi/EFI/<distro>/grub.cfg. 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun On systems with more than one EHCI debug controller you must 101*4882a593Smuzhiyun specify the correct EHCI debug controller number. The ordering 102*4882a593Smuzhiyun comes from the PCI bus enumeration of the EHCI controllers. The 103*4882a593Smuzhiyun default with no number argument is "0" or the first EHCI debug 104*4882a593Smuzhiyun controller. To use the second EHCI debug controller, you would 105*4882a593Smuzhiyun use the command line: "earlyprintk=dbgp1" 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun .. note:: 108*4882a593Smuzhiyun normally earlyprintk console gets turned off once the 109*4882a593Smuzhiyun regular console is alive - use "earlyprintk=dbgp,keep" to keep 110*4882a593Smuzhiyun this channel open beyond early bootup. This can be useful for 111*4882a593Smuzhiyun debugging crashes under Xorg, etc. 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun b) On the client/console system: 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun You should enable the following kernel config option:: 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun CONFIG_USB_SERIAL_DEBUG=y 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun On the next bootup with the modified kernel you should 120*4882a593Smuzhiyun get a /dev/ttyUSBx device(s). 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun Now this channel of kernel messages is ready to be used: start 123*4882a593Smuzhiyun your favorite terminal emulator (minicom, etc.) and set 124*4882a593Smuzhiyun it up to use /dev/ttyUSB0 - or use a raw 'cat /dev/ttyUSBx' to 125*4882a593Smuzhiyun see the raw output. 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun c) On Nvidia Southbridge based systems: the kernel will try to probe 128*4882a593Smuzhiyun and find out which port has a debug device connected. 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunTesting 131*4882a593Smuzhiyun======= 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunYou can test the output by using earlyprintk=dbgp,keep and provoking 134*4882a593Smuzhiyunkernel messages on the host/target system. You can provoke a harmless 135*4882a593Smuzhiyunkernel message by for example doing:: 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun echo h > /proc/sysrq-trigger 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunOn the host/target system you should see this help line in "dmesg" output:: 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun SysRq : HELP : loglevel(0-9) reBoot Crashdump terminate-all-tasks(E) memory-full-oom-kill(F) kill-all-tasks(I) saK show-backtrace-all-active-cpus(L) show-memory-usage(M) nice-all-RT-tasks(N) powerOff show-registers(P) show-all-timers(Q) unRaw Sync show-task-states(T) Unmount show-blocked-tasks(W) dump-ftrace-buffer(Z) 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunOn the client/console system do:: 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun cat /dev/ttyUSB0 146*4882a593Smuzhiyun 147*4882a593SmuzhiyunAnd you should see the help line above displayed shortly after you've 148*4882a593Smuzhiyunprovoked it on the host system. 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunIf it does not work then please ask about it on the linux-kernel@vger.kernel.org 151*4882a593Smuzhiyunmailing list or contact the x86 maintainers. 152