1*4f2df630SAndroid Build Coastguard Worker# Case Closed Debugging (CCD) 2*4f2df630SAndroid Build Coastguard Worker 3*4f2df630SAndroid Build Coastguard WorkerCase closed debugging is a feature of the EC codebase that can bridge UART 4*4f2df630SAndroid Build Coastguard Workerconsoles and SPI buses from a DUT (Device Under Test) to the host machine via 5*4f2df630SAndroid Build Coastguard WorkerUSB. This allows the host to access and update much of the DUT's state. Use 6*4f2df630SAndroid Build Coastguard Workercases include automated hardware testing as well as simplified debug console 7*4f2df630SAndroid Build Coastguard Workeraccess and firmware flashing for kernel and system developers. 8*4f2df630SAndroid Build Coastguard Worker 9*4f2df630SAndroid Build Coastguard Worker[TOC] 10*4f2df630SAndroid Build Coastguard Worker 11*4f2df630SAndroid Build Coastguard Worker## Prerequisites 12*4f2df630SAndroid Build Coastguard Worker 13*4f2df630SAndroid Build Coastguard Worker### Supported Devices 14*4f2df630SAndroid Build Coastguard Worker 15*4f2df630SAndroid Build Coastguard WorkerWe have added CCD support for two chip families: stm32 and gchips. Ryu, 16*4f2df630SAndroid Build Coastguard Worker[`servo_micro`], and [`servo_v4`] use the stm32 support. Cr50 uses gchips 17*4f2df630SAndroid Build Coastguard Workersupport. All boards with Cr50 have support for case closed debugging. 18*4f2df630SAndroid Build Coastguard Worker 19*4f2df630SAndroid Build Coastguard Worker### Suzy-Q 20*4f2df630SAndroid Build Coastguard Worker 21*4f2df630SAndroid Build Coastguard Worker[Suzy-Q] is a Type-C dongle that exposes USB2.0/3.0 on a Type-A socket, case 22*4f2df630SAndroid Build Coastguard Workerclosed debugging over SBU1/2 on a micro Type-B socket, and charging over a 23*4f2df630SAndroid Build Coastguard WorkerType-C socket. You will need one to access the case closed debugging USB 24*4f2df630SAndroid Build Coastguard Workerinterface. Full details, including where to buy and how to make your own are in 25*4f2df630SAndroid Build Coastguard Workerthe [Suzy-Q docs][Suzy-Q]. 26*4f2df630SAndroid Build Coastguard Worker 27*4f2df630SAndroid Build Coastguard Worker### Chromium OS flashrom 28*4f2df630SAndroid Build Coastguard Worker 29*4f2df630SAndroid Build Coastguard WorkerThe functionality to flash the AP firmware image over case closed debugging is 30*4f2df630SAndroid Build Coastguard Workercurrently only supported by the ChromiumOS version of flashrom, so you will need 31*4f2df630SAndroid Build Coastguard Workerto have that built. The easiest way to do so is to just setup the Chromium OS 32*4f2df630SAndroid Build Coastguard WorkerSDK. 33*4f2df630SAndroid Build Coastguard Worker 34*4f2df630SAndroid Build Coastguard Worker### Udev rules file 35*4f2df630SAndroid Build Coastguard Worker 36*4f2df630SAndroid Build Coastguard WorkerThere is a udev rules file, `extra/usb_serial/51-google-serial.rules` that 37*4f2df630SAndroid Build Coastguard Workershould be installed in `/etc/udev/rules.d/` and udev should be told to reread 38*4f2df630SAndroid Build Coastguard Workerits rules. This rules file can be installed using the `extra/usb_serial/install` 39*4f2df630SAndroid Build Coastguard Workerscript. 40*4f2df630SAndroid Build Coastguard Worker 41*4f2df630SAndroid Build Coastguard Worker### Kernel module 42*4f2df630SAndroid Build Coastguard Worker 43*4f2df630SAndroid Build Coastguard WorkerA trivial Linux kernel module that identifies case closed debug capable USB 44*4f2df630SAndroid Build Coastguard Workerinterfaces can be found in `extra/usb_serial`. This module is also built and 45*4f2df630SAndroid Build Coastguard Workerinstalled using the `extra/usb_serial/install` script. 46*4f2df630SAndroid Build Coastguard Worker 47*4f2df630SAndroid Build Coastguard Worker### Chromium OS chroot 48*4f2df630SAndroid Build Coastguard Worker 49*4f2df630SAndroid Build Coastguard WorkerThis is really only a requirement for using flashrom. If you only need access to 50*4f2df630SAndroid Build Coastguard Workerthe serial consoles then a checkout of the EC firmware repository should be 51*4f2df630SAndroid Build Coastguard Workersufficient. 52*4f2df630SAndroid Build Coastguard Worker 53*4f2df630SAndroid Build Coastguard Worker## Setup 54*4f2df630SAndroid Build Coastguard Worker 55*4f2df630SAndroid Build Coastguard Worker### Device Under Test (DUT) 56*4f2df630SAndroid Build Coastguard Worker 57*4f2df630SAndroid Build Coastguard WorkerIf the DUT doesn't have a new enough PD firmware you will need to update the 58*4f2df630SAndroid Build Coastguard Workerfirmware using a Servo, `ectool`, or MCU specific DFU mode, all of which are 59*4f2df630SAndroid Build Coastguard Workeroutside the scope of this document. 60*4f2df630SAndroid Build Coastguard Worker 61*4f2df630SAndroid Build Coastguard WorkerMake sure your DUT is charged up, because while using [Suzy-Q] you can't 62*4f2df630SAndroid Build Coastguard Workercurrently charge the device. 63*4f2df630SAndroid Build Coastguard Worker 64*4f2df630SAndroid Build Coastguard Worker### Suzy-Q 65*4f2df630SAndroid Build Coastguard Worker 66*4f2df630SAndroid Build Coastguard Worker[Suzy-Q] should be connected to the DUT using the Type-C cable and connector 67*4f2df630SAndroid Build Coastguard Workerintegrated into [Suzy-Q]. This connector may need to be flipped to make case 68*4f2df630SAndroid Build Coastguard Workerclosed debugging work because the SBU lines that are used to expose the PD MCU's 69*4f2df630SAndroid Build Coastguard WorkerUSB interface are not orientation invariant. Only one port on the DUT will 70*4f2df630SAndroid Build Coastguard Workersupport CCD. Try using the other port if the CCD device doesn't appear. [Suzy-Q] 71*4f2df630SAndroid Build Coastguard Workershould be connected to the Host with a Type-A (Host) to Micro Type-B ([Suzy-Q]) 72*4f2df630SAndroid Build Coastguard Workercable. Look for the device [`vendor:product ID`](#Troubleshooting) to your host 73*4f2df630SAndroid Build Coastguard Workersees the CCD device. 74*4f2df630SAndroid Build Coastguard Worker 75*4f2df630SAndroid Build Coastguard Worker### Host 76*4f2df630SAndroid Build Coastguard Worker 77*4f2df630SAndroid Build Coastguard WorkerDepending on your kernel version the consoles may exist at `/dev/ttyUSB*`. If 78*4f2df630SAndroid Build Coastguard Workerusing those works for you, you don't need to install any drivers or Udev rules. 79*4f2df630SAndroid Build Coastguard Worker 80*4f2df630SAndroid Build Coastguard WorkerIf you want your host to generate useful symlinks for the different CCD 81*4f2df630SAndroid Build Coastguard Workerconsoles, install the Udev rule. It will generate symlinks in 82*4f2df630SAndroid Build Coastguard Worker`/dev/google/<device name>/serial/<console name>` for each serial console that a 83*4f2df630SAndroid Build Coastguard Workerdevice exports. It will also mark the DUT as incompatible with ModemManager. 84*4f2df630SAndroid Build Coastguard WorkerThis last part ensures that ModemManager doesn't attempt to open and manipulate 85*4f2df630SAndroid Build Coastguard Workerthe various serial consoles exported by the device. 86*4f2df630SAndroid Build Coastguard Worker 87*4f2df630SAndroid Build Coastguard WorkerThe kernel module in `extra/usb_serial` should be compiled and installed in the 88*4f2df630SAndroid Build Coastguard Workerrunning kernel. It just adds an entry into the `usbserial` module's driver table 89*4f2df630SAndroid Build Coastguard Workerthat causes `usbserial` to recognize any case closed debugging serial console as 90*4f2df630SAndroid Build Coastguard Workera simple USB serial device. This addition has already made its way into the 91*4f2df630SAndroid Build Coastguard Workerupstream kernel (v3.19), so eventually this module can be removed. The 92*4f2df630SAndroid Build Coastguard Worker`extra/usb_serial/install` script will build and install the kernel module as 93*4f2df630SAndroid Build Coastguard Workerwell as install the udev rules file. 94*4f2df630SAndroid Build Coastguard Worker 95*4f2df630SAndroid Build Coastguard WorkerIf for some reason you can't or don't want to use the kernel module the install 96*4f2df630SAndroid Build Coastguard Workerscript provides a `--fallback` option that will install a udev rules file and 97*4f2df630SAndroid Build Coastguard Workerhelper script instead that will add each new CCD capable device that is attached 98*4f2df630SAndroid Build Coastguard Workerto the host to the list of devices that usbserial will handle. The disadvantage 99*4f2df630SAndroid Build Coastguard Workerof this method is that it will generate `/dev/ttyUSB*` entries for any USB 100*4f2df630SAndroid Build Coastguard Workerinterface on the device that has an IN/OUT pair of bulk endpoints. This results 101*4f2df630SAndroid Build Coastguard Workerin extra `/dev/ttyUSB*` entries that should not be used because they are 102*4f2df630SAndroid Build Coastguard Workeractually I2C or SPI bridges. 103*4f2df630SAndroid Build Coastguard Worker 104*4f2df630SAndroid Build Coastguard WorkerThe raiden module solves this by identifying a CCD serial port by the subclass 105*4f2df630SAndroid Build Coastguard Workerand protocol numbers of the USB device interface. This means that there does not 106*4f2df630SAndroid Build Coastguard Workerneed to be a list of CCD capable device IDs anywhere. 107*4f2df630SAndroid Build Coastguard Worker 108*4f2df630SAndroid Build Coastguard Worker## Basic CCD 109*4f2df630SAndroid Build Coastguard Worker 110*4f2df630SAndroid Build Coastguard WorkerHere's the basic information for how to use CCD. Cr50 restricts debugging 111*4f2df630SAndroid Build Coastguard Workerfeatures to try and ensure only the device owner can use CCD. For information on 112*4f2df630SAndroid Build Coastguard Workerhow to get access to Cr50 CCD see the [Cr50 specific CCD doc][Cr50 CCD]. 113*4f2df630SAndroid Build Coastguard Worker 114*4f2df630SAndroid Build Coastguard Worker### Consoles 115*4f2df630SAndroid Build Coastguard Worker 116*4f2df630SAndroid Build Coastguard WorkerThe serial consoles exposed by case closed debugging can be found in 117*4f2df630SAndroid Build Coastguard Worker`/dev/ttyUSB*` or `/dev/google/<device name>/serial/<console name>` if you 118*4f2df630SAndroid Build Coastguard Workerinstalled the Udev rules. The consoles can be opened with any program that you 119*4f2df630SAndroid Build Coastguard Workerwould normally use to open a TTY character device such as minicom or screen. 120*4f2df630SAndroid Build Coastguard Worker 121*4f2df630SAndroid Build Coastguard WorkerIf you installed the Udev rules, the console path will be determined based on 122*4f2df630SAndroid Build Coastguard Workerthe device and USB bus. The `<device name>` field is generated from the DUT's 123*4f2df630SAndroid Build Coastguard WorkerUSB descriptor `iProduct` field as well as the USB bus index and device path on 124*4f2df630SAndroid Build Coastguard Workerthat bus (the list of port numbers for the hub connections between the Host and 125*4f2df630SAndroid Build Coastguard WorkerDUT). As such it is unique to a particular setup and won't change across reboots 126*4f2df630SAndroid Build Coastguard Workerof either the Host or the DUT. The `<console name>` field is just the 127*4f2df630SAndroid Build Coastguard Worker`iInterface` USB descriptor field from the particular USB interface that is 128*4f2df630SAndroid Build Coastguard Workerassociated with this console device. This allows a single DUT to expose multiple 129*4f2df630SAndroid Build Coastguard Workerserial consoles in a discoverable and consistent manner. 130*4f2df630SAndroid Build Coastguard Worker 131*4f2df630SAndroid Build Coastguard WorkerIf you're using the consoles at `/dev/ttyUSB*`, you can just check which console 132*4f2df630SAndroid Build Coastguard Workerit is by running a few commands like `version`. 133*4f2df630SAndroid Build Coastguard Worker 134*4f2df630SAndroid Build Coastguard Worker### Flash AP 135*4f2df630SAndroid Build Coastguard Worker 136*4f2df630SAndroid Build Coastguard WorkerProgramming the AP SPI flash with a new firmware image can be done with flashrom 137*4f2df630SAndroid Build Coastguard Workerusing the command: 138*4f2df630SAndroid Build Coastguard Worker 139*4f2df630SAndroid Build Coastguard Worker```bash 140*4f2df630SAndroid Build Coastguard Worker(chroot) $ sudo /usr/sbin/flashrom -p raiden_debug_spi -w /build/<board>/firmware/image.bin 141*4f2df630SAndroid Build Coastguard Worker``` 142*4f2df630SAndroid Build Coastguard Worker 143*4f2df630SAndroid Build Coastguard WorkerIf there are more than one case closed debug capable devices connected to the 144*4f2df630SAndroid Build Coastguard Workerhost you will have to disambiguate the DUT with additional programmer 145*4f2df630SAndroid Build Coastguard Workerparameters. Flashrom will list all DUTs that are found along with programmer 146*4f2df630SAndroid Build Coastguard Workerparameters that can be used to identify the intended DUT. Flashrom programmer 147*4f2df630SAndroid Build Coastguard Workeradded to the programmer name (the `-p` argument) by appending a colon and then a 148*4f2df630SAndroid Build Coastguard Workercolon and then a comma separated list of `key=value` pairs. The `serial` 149*4f2df630SAndroid Build Coastguard Workerparameter is best for this. 150*4f2df630SAndroid Build Coastguard Worker 151*4f2df630SAndroid Build Coastguard Worker```bash 152*4f2df630SAndroid Build Coastguard Worker(chroot) $ sudo /usr/sbin/flashrom -p raiden_debug_spi:serial=${SERIAL} -w /build/<board>/firmware/image.bin 153*4f2df630SAndroid Build Coastguard Worker``` 154*4f2df630SAndroid Build Coastguard Worker 155*4f2df630SAndroid Build Coastguard WorkerCr50 can be used to flash the AP or EC. You will need to specify the AP as the 156*4f2df630SAndroid Build Coastguard Workertarget device, so cr50 knows to flash the AP. 157*4f2df630SAndroid Build Coastguard Worker 158*4f2df630SAndroid Build Coastguard Worker```bash 159*4f2df630SAndroid Build Coastguard Worker(chroot) $ sudo flashrom -p raiden_debug_spi:target=AP -w image.bin 160*4f2df630SAndroid Build Coastguard Worker``` 161*4f2df630SAndroid Build Coastguard Worker 162*4f2df630SAndroid Build Coastguard Worker### Flash EC 163*4f2df630SAndroid Build Coastguard Worker 164*4f2df630SAndroid Build Coastguard WorkerYou can use `util/flash_ec` to flash the EC. Steps for flashing the EC are more 165*4f2df630SAndroid Build Coastguard Workercomplex and board specific than flashing the AP. This script will handle all the 166*4f2df630SAndroid Build Coastguard Workerboard specific setup. 167*4f2df630SAndroid Build Coastguard Worker 168*4f2df630SAndroid Build Coastguard Worker## Known Issues 169*4f2df630SAndroid Build Coastguard Worker 170*4f2df630SAndroid Build Coastguard Worker1. Charge and the use of the Type-A port on [Suzy-Q] do not work, so for now if 171*4f2df630SAndroid Build Coastguard Worker you need to attach a flash drive, or use Fastboot/adb you'll need to swap 172*4f2df630SAndroid Build Coastguard Worker cables. 173*4f2df630SAndroid Build Coastguard Worker 174*4f2df630SAndroid Build Coastguard Worker2. Ryu implementation: software sync of the EC/PD processor and the jump from 175*4f2df630SAndroid Build Coastguard Worker RO to RW versions will cause the case closed debugging USB device to 176*4f2df630SAndroid Build Coastguard Worker disconnect and reconnect. This can be prevented by disabling software sync. 177*4f2df630SAndroid Build Coastguard Worker This is done by setting the `GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC` and 178*4f2df630SAndroid Build Coastguard Worker `GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC` flags with`gbb_utility. 179*4f2df630SAndroid Build Coastguard Worker 180*4f2df630SAndroid Build Coastguard Worker## Troubleshooting 181*4f2df630SAndroid Build Coastguard Worker 182*4f2df630SAndroid Build Coastguard WorkerCheck for the CCD device using the following `vendor:product` IDs 183*4f2df630SAndroid Build Coastguard Worker 184*4f2df630SAndroid Build Coastguard WorkerDevice | VID:PID 185*4f2df630SAndroid Build Coastguard Worker--------------- | ----------- 186*4f2df630SAndroid Build Coastguard Worker[`servo_micro`] | `18d1:501a` 187*4f2df630SAndroid Build Coastguard Worker[`servo_v4`] | `18d1:501b` 188*4f2df630SAndroid Build Coastguard Worker[`servo_v2`] | `18d1:5002` 189*4f2df630SAndroid Build Coastguard Worker`ryu` | `18d1:500f` 190*4f2df630SAndroid Build Coastguard Worker`cr50` | `18d1:5014` 191*4f2df630SAndroid Build Coastguard Worker 192*4f2df630SAndroid Build Coastguard WorkerSee the [`SERVO_PID_DEFAULTS`] in the servo code for all values. 193*4f2df630SAndroid Build Coastguard Worker 194*4f2df630SAndroid Build Coastguard Worker### Can't see the CCD device on the host 195*4f2df630SAndroid Build Coastguard Worker 196*4f2df630SAndroid Build Coastguard Worker1. Type-C cable from [Suzy-Q] to the DUT may be upside down. The SBU lines used 197*4f2df630SAndroid Build Coastguard Worker for case closed debugging are not orientation invariant. 198*4f2df630SAndroid Build Coastguard Worker1. You may be using the wrong device port. Try using the other port. 199*4f2df630SAndroid Build Coastguard Worker1. The device may not be charged enough to boot. [Suzy-Q] can't charge the 200*4f2df630SAndroid Build Coastguard Worker device or supply enough power for the DUT to boot. Make sure the device is 201*4f2df630SAndroid Build Coastguard Worker somewhat charged. 202*4f2df630SAndroid Build Coastguard Worker 203*4f2df630SAndroid Build Coastguard Worker### No console interfaces are available in the "/dev/google/<name>" directory 204*4f2df630SAndroid Build Coastguard Worker 205*4f2df630SAndroid Build Coastguard Worker1. Kernel module may not be loaded. 206*4f2df630SAndroid Build Coastguard Worker1. Udev rules file might not be installed correctly. 207*4f2df630SAndroid Build Coastguard Worker1. PD firmware version may be too old. 208*4f2df630SAndroid Build Coastguard Worker1. Type-C cable from [Suzy-Q] to the DUT may be upside down. The SBU lines used 209*4f2df630SAndroid Build Coastguard Worker for case closed debugging are not orientation invariant. 210*4f2df630SAndroid Build Coastguard Worker 211*4f2df630SAndroid Build Coastguard Worker### Garbage messages (AT command set) show up on one or more consoles 212*4f2df630SAndroid Build Coastguard Worker 213*4f2df630SAndroid Build Coastguard Worker1. ModemManager has claimed the interface, Udev rules file may not be installed 214*4f2df630SAndroid Build Coastguard Worker correctly. 215*4f2df630SAndroid Build Coastguard Worker 216*4f2df630SAndroid Build Coastguard Worker### Console interfaces appear and then quickly disappear 217*4f2df630SAndroid Build Coastguard Worker 218*4f2df630SAndroid Build Coastguard Worker1. Software sync from the AP has replaced the PD firmware with a version that 219*4f2df630SAndroid Build Coastguard Worker is not compatible with case closed debugging. 220*4f2df630SAndroid Build Coastguard Worker 221*4f2df630SAndroid Build Coastguard Worker[`servo_v4`]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/servo_v4.md 222*4f2df630SAndroid Build Coastguard Worker[`servo_v2`]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/servo_v2.md 223*4f2df630SAndroid Build Coastguard Worker[`servo_micro`]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/servo_micro.md 224*4f2df630SAndroid Build Coastguard Worker[Cr50 CCD]: ./case_closed_debugging_gsc.md 225*4f2df630SAndroid Build Coastguard Worker[Suzy-Q]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/main/docs/ccd.md#suzyq-suzyqable 226*4f2df630SAndroid Build Coastguard Worker[`SERVO_PID_DEFAULTS`]: https://chromium.googlesource.com/chromiumos/third_party/hdctools/+/ff8e96686ef3d9ad2e26125ca8268cb7f7666f6c/servo/interface/ftdi_common.py#28 227