1*4f2df630SAndroid Build Coastguard Worker# Controlling GSC Without Servod 2*4f2df630SAndroid Build Coastguard Worker[TOC] 3*4f2df630SAndroid Build Coastguard WorkerThis write up describes an alternative method of controlling GSC and Chrome 4*4f2df630SAndroid Build Coastguard WorkerOS devices using Servo Micro or C2D2 called `adapters` below. 5*4f2df630SAndroid Build Coastguard Worker 6*4f2df630SAndroid Build Coastguard WorkerThe version you are looking at might be not the latest and greatest, [this 7*4f2df630SAndroid Build Coastguard Workerlink](https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/gsc_utils/docs/gsc_without_servod.md) 8*4f2df630SAndroid Build Coastguard Workerpoints to the most updated copy. 9*4f2df630SAndroid Build Coastguard Worker 10*4f2df630SAndroid Build Coastguard WorkerIn a typical setup these `adapters` are controlled by the `servod` utility. 11*4f2df630SAndroid Build Coastguard WorkerThis a very powerful tool, it allows to control the huge amount of various 12*4f2df630SAndroid Build Coastguard WorkerChrome OS devices, accounting for numerous differences between devices and 13*4f2df630SAndroid Build Coastguard Worker`adapters`, providing endless configuration options, etc. 14*4f2df630SAndroid Build Coastguard Worker 15*4f2df630SAndroid Build Coastguard WorkerThis comes at a hefty price: the user must set up Chrome OS chroot, keep the 16*4f2df630SAndroid Build Coastguard Workerchroot in sync, periodically update the servod application, run `servod` 17*4f2df630SAndroid Build Coastguard Workerpassing it the appropriate command line options depending on the 18*4f2df630SAndroid Build Coastguard Worker`adapter`type, etc., etc. Troubleshooting situations when `servod` fails to 19*4f2df630SAndroid Build Coastguard Workerstart or reports errors during operation requires high level of expertise and 20*4f2df630SAndroid Build Coastguard Workeroften is pretty time consuming. 21*4f2df630SAndroid Build Coastguard Worker 22*4f2df630SAndroid Build Coastguard WorkerLuckily all this complexity could be easily avoided when working with the 23*4f2df630SAndroid Build Coastguard Worker`adapters` directly. In each case connecting the `adapter` to the DUT and to 24*4f2df630SAndroid Build Coastguard Workerthe workstation provides necessary communication channels to access GSC, AP, 25*4f2df630SAndroid Build Coastguard Workerand EC console and perform the `rescue` operation when GSC RW firmware needs to 26*4f2df630SAndroid Build Coastguard Workerbe updated. 27*4f2df630SAndroid Build Coastguard Worker 28*4f2df630SAndroid Build Coastguard Worker## Common One Time Setup 29*4f2df630SAndroid Build Coastguard Worker 30*4f2df630SAndroid Build Coastguard WorkerWhen the setup is connected (the `adapter` is attached to the DUT and connected 31*4f2df630SAndroid Build Coastguard Workerto a USB port on the workstation), four `/dev/ttyUSBx` devices are created on 32*4f2df630SAndroid Build Coastguard Workerthe workstation, which allow access to all consoles of the `adapter` and of the 33*4f2df630SAndroid Build Coastguard WorkerDUT. 34*4f2df630SAndroid Build Coastguard Worker 35*4f2df630SAndroid Build Coastguard WorkerTwo helpful scripts available in `../util` in the Chrome OS Cr50 tree are 36*4f2df630SAndroid Build Coastguard Worker`maptty.sh` which shows how the TTY devices map to the `adapter(s)` and 37*4f2df630SAndroid Build Coastguard Worker`brescue.sh` which takes care of invoking `rescue` with proper command line 38*4f2df630SAndroid Build Coastguard Workerparameters (see below information about recovering from botched GSC updates). 39*4f2df630SAndroid Build Coastguard Worker 40*4f2df630SAndroid Build Coastguard WorkerIf you don't have Chrome OS chroot, to access the scripts you can clone the EC 41*4f2df630SAndroid Build Coastguard Workertree as follows: 42*4f2df630SAndroid Build Coastguard Worker 43*4f2df630SAndroid Build Coastguard Worker``` 44*4f2df630SAndroid Build Coastguard Worker$ git clone https://chromium.googlesource.com/chromiumos/platform/ec 45*4f2df630SAndroid Build Coastguard Worker$ cd ec 46*4f2df630SAndroid Build Coastguard Worker$ git checkout -b gsc origin/gsc_utils 47*4f2df630SAndroid Build Coastguard Worker$ ls util/{maptty,brescue}.sh 48*4f2df630SAndroid Build Coastguard Workerutil/brescue.sh* util/maptty.sh* 49*4f2df630SAndroid Build Coastguard Worker``` 50*4f2df630SAndroid Build Coastguard Worker 51*4f2df630SAndroid Build Coastguard Worker## Controlling DUT With Servo Micro 52*4f2df630SAndroid Build Coastguard Worker 53*4f2df630SAndroid Build Coastguard WorkerTo find the TTY devices created by Servo Micro run: 54*4f2df630SAndroid Build Coastguard Worker``` 55*4f2df630SAndroid Build Coastguard Worker$ ../util/maptty.sh | grep Servo_Micro 56*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB0 /dev/serial/by-id/usb-Google_Inc._Servo_Micro_CMO653-00166-040489J04128-if00-port0 57*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB1 /dev/serial/by-id/usb-Google_Inc._Servo_Micro_CMO653-00166-040489J04128-if03-port0 58*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB2 /dev/serial/by-id/usb-Google_Inc._Servo_Micro_CMO653-00166-040489J04128-if05-port0 59*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB3 /dev/serial/by-id/usb-Google_Inc._Servo_Micro_CMO653-00166-040489J04128-if06-port0 60*4f2df630SAndroid Build Coastguard Worker``` 61*4f2df630SAndroid Build Coastguard WorkerThe actual device names could be different depending on what is connected to 62*4f2df630SAndroid Build Coastguard Workeryour workstation, but the order is fixed: the lowest index TTY device 63*4f2df630SAndroid Build Coastguard Worker(`/dev/ttyUSB0` in the above example) is the GSC console, the next device is 64*4f2df630SAndroid Build Coastguard Workerthe Sevo Micro console, the next one is the AP console and the last one is the 65*4f2df630SAndroid Build Coastguard WorkerEC console. 66*4f2df630SAndroid Build Coastguard Worker 67*4f2df630SAndroid Build Coastguard WorkerRun `version` command on the Servo Micro console to confirm that you are 68*4f2df630SAndroid Build Coastguard Workerconnected to it, you should see something similar to: 69*4f2df630SAndroid Build Coastguard Worker``` 70*4f2df630SAndroid Build Coastguard Worker> version 71*4f2df630SAndroid Build Coastguard WorkerChip: stm stm32f07x 72*4f2df630SAndroid Build Coastguard WorkerBoard: 0 73*4f2df630SAndroid Build Coastguard WorkerRO: servo_micro_v2.0.10865+f8e42df1 74*4f2df630SAndroid Build Coastguard Worker servo_micro_14307.0.21_10_31 75*4f2df630SAndroid Build Coastguard WorkerRW: servo_micro_v2.0.10865+f8e42df1 76*4f2df630SAndroid Build Coastguard Worker servo_micro_14307.0.21_10_31 77*4f2df630SAndroid Build Coastguard Worker... 78*4f2df630SAndroid Build Coastguard Worker``` 79*4f2df630SAndroid Build Coastguard Worker### Reset GSC Using Servo Micro 80*4f2df630SAndroid Build Coastguard WorkerServo Micro allows to power up the GSC even if the DUT is not powered, it has 81*4f2df630SAndroid Build Coastguard Workera dedicated GPIO for that. The GSC reset signal is connected to one of the 82*4f2df630SAndroid Build Coastguard Workeroutputs of TCA6416ARTWR GPIO expander, controlled through I2C. The expander is 83*4f2df630SAndroid Build Coastguard Workerattached to I2C port 0 and is configured to respond to bus address 0x20. 84*4f2df630SAndroid Build Coastguard Worker 85*4f2df630SAndroid Build Coastguard WorkerRun the following commands on the Servo Micro console to set it up to control the GSC: 86*4f2df630SAndroid Build Coastguard Worker``` 87*4f2df630SAndroid Build Coastguard Worker> gpioset SPI1_VREF_33 1 88*4f2df630SAndroid Build Coastguard Worker> i2cxfer w 0 0x20 3 0x1f 89*4f2df630SAndroid Build Coastguard Worker``` 90*4f2df630SAndroid Build Coastguard WorkerNow you can generate a GSC reset pulse by running 91*4f2df630SAndroid Build Coastguard Worker``` 92*4f2df630SAndroid Build Coastguard Worker> i2cxfer w 0 0x20 7 0x1f 93*4f2df630SAndroid Build Coastguard Worker> i2cxfer w 0 0x20 7 0x5f 94*4f2df630SAndroid Build Coastguard Worker``` 95*4f2df630SAndroid Build Coastguard WorkerThis is all there is to it. 96*4f2df630SAndroid Build Coastguard Worker 97*4f2df630SAndroid Build Coastguard Worker## Controlling DUT With C2D2 98*4f2df630SAndroid Build Coastguard Worker 99*4f2df630SAndroid Build Coastguard WorkerUsing C2D2 is even simpler. The same `maptty.sh` script will show the TTY 100*4f2df630SAndroid Build Coastguard Workerdevices connected when C2D2 is attached: 101*4f2df630SAndroid Build Coastguard Worker``` 102*4f2df630SAndroid Build Coastguard Worker$ ../util/maptty.sh | grep C2D2 103*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB4 /dev/serial/by-id/usb-Google_Inc._C2D2_C2103110780-if00-port0 104*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB5 /dev/serial/by-id/usb-Google_Inc._C2D2_C2103110780-if03-port0 105*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB6 /dev/serial/by-id/usb-Google_Inc._C2D2_C2103110780-if05-port0 106*4f2df630SAndroid Build Coastguard Worker/dev/ttyUSB7 /dev/serial/by-id/usb-Google_Inc._C2D2_C2103110780-if06-port0 107*4f2df630SAndroid Build Coastguard Worker``` 108*4f2df630SAndroid Build Coastguard Worker 109*4f2df630SAndroid Build Coastguard WorkerTTY device assignment order is the same as in case of Servo Micro, this is how 110*4f2df630SAndroid Build Coastguard WorkerC2D2 `version` command looks like: 111*4f2df630SAndroid Build Coastguard Worker``` 112*4f2df630SAndroid Build Coastguard Worker> version 113*4f2df630SAndroid Build Coastguard WorkerChip: stm stm32f07x 114*4f2df630SAndroid Build Coastguard WorkerBoard: 0 115*4f2df630SAndroid Build Coastguard WorkerRO: c2d2_v2.4.35-f1113c92b 116*4f2df630SAndroid Build Coastguard WorkerRW: c2d2_v2.4.35-f1113c92b 117*4f2df630SAndroid Build Coastguard Worker... 118*4f2df630SAndroid Build Coastguard Worker``` 119*4f2df630SAndroid Build Coastguard Worker### Reset GSC Using C2D2 120*4f2df630SAndroid Build Coastguard WorkerC2D2 does not allow to power up the GSC (DUT power is required), but has a 121*4f2df630SAndroid Build Coastguard Workerdedicated console command for resetiing the GSC: 122*4f2df630SAndroid Build Coastguard Worker``` 123*4f2df630SAndroid Build Coastguard Worker> h1_reset 1 124*4f2df630SAndroid Build Coastguard Worker> h1_reset 0 125*4f2df630SAndroid Build Coastguard Worker``` 126*4f2df630SAndroid Build Coastguard WorkerAnd this is all there is to using C2D2. 127*4f2df630SAndroid Build Coastguard Worker 128*4f2df630SAndroid Build Coastguard Worker## GSC Rescue 129*4f2df630SAndroid Build Coastguard Worker 130*4f2df630SAndroid Build Coastguard WorkerGSC Rescue operation allows to recover from a corrupted GSC RW, when it is not 131*4f2df630SAndroid Build Coastguard Workerpossible to update it using `gsctool`. Very few people outside of GSC firmware 132*4f2df630SAndroid Build Coastguard Workerteam would need to use this regularly, but it might come handy in situations 133*4f2df630SAndroid Build Coastguard Workerlike updating early DT chips. 134*4f2df630SAndroid Build Coastguard Worker 135*4f2df630SAndroid Build Coastguard WorkerRescue procedure requires a utility, which can communicate with the GSC over 136*4f2df630SAndroid Build Coastguard WorkerUART, the utility is called `rescue`. 137*4f2df630SAndroid Build Coastguard Worker 138*4f2df630SAndroid Build Coastguard WorkerIf you have Chrome OS chroot the utility can be generated by running `sudo 139*4f2df630SAndroid Build Coastguard Workeremerge cr50-utils` and it becomes available as `/usr/bin/cr50-rescue`. 140*4f2df630SAndroid Build Coastguard Worker 141*4f2df630SAndroid Build Coastguard Worker### Building Your Own Rescue Utility Outside Chroot 142*4f2df630SAndroid Build Coastguard Worker 143*4f2df630SAndroid Build Coastguard WorkerIf you are working outside chroot you can build your own `rescue` executable 144*4f2df630SAndroid Build Coastguard Workeras follows (these instructions are for a recent Debian Mint environment, 145*4f2df630SAndroid Build Coastguard Workerinstalling necessary packages could require different commands on different 146*4f2df630SAndroid Build Coastguard WorkerLinux distributions): 147*4f2df630SAndroid Build Coastguard Worker``` 148*4f2df630SAndroid Build Coastguard Worker$ git clone https://chrome-internal.googlesource.com/chromeos/platform/cr50-utils 149*4f2df630SAndroid Build Coastguard Worker$ cd cr50-utils/software/tools/SPI 150*4f2df630SAndroid Build Coastguard Worker$ sudo apt-get install libc6 libelf-dev libgcc-s1 libssl-dev libstdc++6 libudev1 libusb-1.0-0-dev zlib1g 151*4f2df630SAndroid Build Coastguard Worker$ make rescue 152*4f2df630SAndroid Build Coastguard Worker``` 153*4f2df630SAndroid Build Coastguard WorkerThis will create the `rescue` utility in the local directory, place it 154*4f2df630SAndroid Build Coastguard Workersomewhere to make it available through `PATH`. 155*4f2df630SAndroid Build Coastguard Worker 156*4f2df630SAndroid Build Coastguard Worker### Performing GSC Rescue Procedure 157*4f2df630SAndroid Build Coastguard Worker 158*4f2df630SAndroid Build Coastguard WorkerTo rescue H1 or DT chip which has a corrupted RW but is still 'alive', i.e. 159*4f2df630SAndroid Build Coastguard Workerreacts with the RO boot console output to reset pulse generated by the 160*4f2df630SAndroid Build Coastguard Worker`adapter`, first obtain a firmware image to rescue it to. If you have a chroot 161*4f2df630SAndroid Build Coastguard Workeryou can run `sudo emerge chromeos-[ti|cr]50` and find the latest released 162*4f2df630SAndroid Build Coastguard Workerimage in 163*4f2df630SAndroid Build Coastguard Worker``` 164*4f2df630SAndroid Build Coastguard Worker/opt/google/[cr|ti]50/firmware/[cr|ti]50.bin.prepvt 165*4f2df630SAndroid Build Coastguard Worker``` 166*4f2df630SAndroid Build Coastguard Workeror you can see the Care and Feeding document for your board of ask your 167*4f2df630SAndroid Build Coastguard Workercolleagues where to get a GSC image to use. 168*4f2df630SAndroid Build Coastguard Worker 169*4f2df630SAndroid Build Coastguard WorkerThen to rescue the GSC chip, do the following: 170*4f2df630SAndroid Build Coastguard Worker 171*4f2df630SAndroid Build Coastguard Worker - disconnect terminal from the GSC console TTY device 172*4f2df630SAndroid Build Coastguard Worker - invoke `brescue.sh <path to the firmware image> <GSC console TTY device>` 173*4f2df630SAndroid Build Coastguard Worker - generate GSC reset pulse using instructions based on the adapter used to 174*4f2df630SAndroid Build Coastguard Worker connect to the GSC ([Servo Micro](#reset-gsc-using-servo-micro) or 175*4f2df630SAndroid Build Coastguard Worker [C2D2](#reset-gsc-using-c2d2)). Another way to reset the GSC is to 176*4f2df630SAndroid Build Coastguard Worker disconnect/reconnect the battery. 177*4f2df630SAndroid Build Coastguard Worker 178*4f2df630SAndroid Build Coastguard Worker**Note that resetting Dauntless using the key combo will not trigger a rescue 179*4f2df630SAndroid Build Coastguard Worker attempt.** 180*4f2df630SAndroid Build Coastguard Worker 181*4f2df630SAndroid Build Coastguard WorkerHere is an example of a Ti50 rescue session: 182*4f2df630SAndroid Build Coastguard Worker``` 183*4f2df630SAndroid Build Coastguard Worker$ ../util/brescue.sh <path to>/ti50.bin.prepvt /dev/ttyUSB4 184*4f2df630SAndroid Build Coastguard Workercarved out binary /tmp/brescue.sh.y1uXW/rw.bin mapped to 0x88000 185*4f2df630SAndroid Build Coastguard Workerconverted to /tmp/brescue.sh.y1uXW/rw.hex, waiting for target reset 186*4f2df630SAndroid Build Coastguard Workerflash_start_: 00008000 flash_end_: 00018000 187*4f2df630SAndroid Build Coastguard Workerlow 00088000, high 000fffff 188*4f2df630SAndroid Build Coastguard Workerbase 00088000, size 00078000 189*4f2df630SAndroid Build Coastguard Worker..maxAdr 0x00100000 190*4f2df630SAndroid Build Coastguard Worker..dropped to 0x000f08e8 191*4f2df630SAndroid Build Coastguard Worker..skipping from 0x00084000 to 0x00088000 192*4f2df630SAndroid Build Coastguard Worker435 frames 193*4f2df630SAndroid Build Coastguard Worker(waiting for "Bldr |") 194*4f2df630SAndroid Build Coastguard WorkerRavn4|00100000 7f4bdb+ 195*4f2df630SAndroid Build Coastguard WorkerHimg =DE83C230..A01206DE : 1 196*4f2df630SAndroid Build Coastguard WorkerHfss =3F08D3AE..015B326D : 1 197*4f2df630SAndroid Build Coastguard WorkerHinf =00CFE4A6..B4FEEEDC : 1 198*4f2df630SAndroid Build Coastguard Workerjump @00100400 199*4f2df630SAndroid Build Coastguard Worker 200*4f2df630SAndroid Build Coastguard WorkerBldr |(waiting for "oops?|")694539 76b844 201*4f2df630SAndroid Build Coastguard Workeroops?|0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204.205.206.207.208.209.210.211.212.213.214.215.216.217.218.219.220.221.222.223.224.225.226.227.228.229.230.231.232.233.234.235.236.237.238.239.240.241.242.243.244.245.246.247.248.249.250.251.252.253.254.255.256.257.258.259.260.261.262.263.264.265.266.267.268.269.270.271.272.273.274.275.276.277.278.279.280.281.282.283.284.285.286.287.288.289.290.291.292.293.294.295.296.297.298.299.300.301.302.303.304.305.306.307.308.309.310.311.312.313.314.315.316.317.318.319.320.321.322.323.324.325.326.327.328.329.330.331.332.333.334.335.336.337.338.339.340.341.342.343.344.345.346.347.348.349.350.351.352.353.354.355.356.357.358.359.360.361.362.363.364.365.366.367.368.369.370.371.372.373.374.375.376.377.378.379.380.381.382.383.384.385.386.387.388.389.390.391.392.393.394.395.396.397.398.399.400.401.402.403.404.405.406.407.408.409.410.411.412.413.414.415.416.417.418.419.420.421.422.423.424.425.426.427.428.429.430.431.432.433.434.done! 202*4f2df630SAndroid Build Coastguard Worker``` 203*4f2df630SAndroid Build Coastguard Worker### Rescue Troubleshooting 204*4f2df630SAndroid Build Coastguard Worker 205*4f2df630SAndroid Build Coastguard WorkerSometimes after a successful rescue where the GSC starts the RW successfully and 206*4f2df630SAndroid Build Coastguard Workershows up on CCD, the ChromeOS device still fails to boot and falls into 207*4f2df630SAndroid Build Coastguard Workerrecovery. This could be due to stale TPM data. 208*4f2df630SAndroid Build Coastguard Worker 209*4f2df630SAndroid Build Coastguard WorkerIf your device continuously falls into recovery on reboots after rescue, boot to 210*4f2df630SAndroid Build Coastguard Workeran OS test image via USB through the recovery screen. Once booted in the OS test 211*4f2df630SAndroid Build Coastguard Workerimage, issue the `crossystem clear_tpm_owner_request=1` command on the kernel 212*4f2df630SAndroid Build Coastguard Workerconsole. Reboot and allow the OS on disk to boot. 213