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