xref: /aosp_15_r20/external/gsc-utils/docs/cr50_vboot_troubleshooting.md (revision 4f2df630800bdcf1d4f0decf95d8a1cb87344f5f)
1*4f2df630SAndroid Build Coastguard Worker# Cr50 And Chrome OS Verified Boot Troubleshooting
2*4f2df630SAndroid Build Coastguard Worker
3*4f2df630SAndroid Build Coastguard WorkerH1 is a Google security chip installed on most Chrome OS devices. Cr50 is the
4*4f2df630SAndroid Build Coastguard Workerfirmware running on the H1. A high level overview of hardware and firmware can
5*4f2df630SAndroid Build Coastguard Workerbe found in [this
6*4f2df630SAndroid Build Coastguard Workerpresentation](https://2018.osfc.io/uploads/talk/paper/7/gsc_copy.pdf).
7*4f2df630SAndroid Build Coastguard Worker
8*4f2df630SAndroid Build Coastguard WorkerThis write-up is an attempt to explain how Cr50 participates in the Chrome OS
9*4f2df630SAndroid Build Coastguard Workerdevice boot process, and what are possible reasons for the dreaded "Chrome OS
10*4f2df630SAndroid Build Coastguard WorkerMissing Or Damaged" screen showing up when Chrome OS device reboots.
11*4f2df630SAndroid Build Coastguard Worker
12*4f2df630SAndroid Build Coastguard Worker## Basic overview
13*4f2df630SAndroid Build Coastguard Worker
14*4f2df630SAndroid Build Coastguard WorkerThe H1 controls reset lines of the EC (embedded controller) and the AP
15*4f2df630SAndroid Build Coastguard Worker(application processor, or SOC). During normal Chromebook operation H1 is
16*4f2df630SAndroid Build Coastguard Workeralways powered up as long as battery retains even a minimal amount of charge.
17*4f2df630SAndroid Build Coastguard WorkerIn Chromeboxes H1 powers on with the rest of the system.
18*4f2df630SAndroid Build Coastguard Worker
19*4f2df630SAndroid Build Coastguard WorkerOne of the important functions of H1 in the system is a subset of TPM (Trusted
20*4f2df630SAndroid Build Coastguard WorkerPlatform Module) functionality. The TPM stores verified boot information, this
21*4f2df630SAndroid Build Coastguard Workeris why any **problems communicating with the TPM during the boot up process**
22*4f2df630SAndroid Build Coastguard Workerresult in the Chrome OS device falling into **recovery mode**.
23*4f2df630SAndroid Build Coastguard Worker
24*4f2df630SAndroid Build Coastguard WorkerAnother important function of the H1 in the system is CCD ([closed case
25*4f2df630SAndroid Build Coastguard Workerdebugging](https://chromium.googlesource.com/chromiumos/platform/ec/+/fe6ca90e/docs/case_closed_debugging_gsc.md#))
26*4f2df630SAndroid Build Coastguard Worker
27*4f2df630SAndroid Build Coastguard Worker## H1 power states and CCD
28*4f2df630SAndroid Build Coastguard Worker
29*4f2df630SAndroid Build Coastguard WorkerDuring periods of inactivity H1 could enter a *sleep* or *deep sleep* state.
30*4f2df630SAndroid Build Coastguard WorkerIn *sleep* state most of the clocks are turned off and power consumption is
31*4f2df630SAndroid Build Coastguard Workerminimized, but SRAM contents and the CPU state are maintained. In *deep sleep*
32*4f2df630SAndroid Build Coastguard Workerstate the H1 is practically shut down.
33*4f2df630SAndroid Build Coastguard Worker
34*4f2df630SAndroid Build Coastguard WorkerThe H1 never enters the *deep sleep* state during the Chrome OS boot process,
35*4f2df630SAndroid Build Coastguard Workerbut could enter the *sleep* state if the Chrome OS device boot process is
36*4f2df630SAndroid Build Coastguard Workerdelayed for whatever reason, and **only when CCD is not active**. This could
37*4f2df630SAndroid Build Coastguard Workerbe one of the reasons that there are boot failures when CCD is not connected,
38*4f2df630SAndroid Build Coastguard Workerbut the failures go away if CCD is on (the debug cable is plugged in).
39*4f2df630SAndroid Build Coastguard Worker
40*4f2df630SAndroid Build Coastguard WorkerTo make sure the H1 exits the *sleep* state the AP triggers a wake up event,
41*4f2df630SAndroid Build Coastguard Workerdetails of which are described below.
42*4f2df630SAndroid Build Coastguard Worker
43*4f2df630SAndroid Build Coastguard Worker## H1 communications with the AP
44*4f2df630SAndroid Build Coastguard Worker
45*4f2df630SAndroid Build Coastguard WorkerThe H1 could be connected to the AP over the I2C or SPI bus. The same Cr50
46*4f2df630SAndroid Build Coastguard Workerfirmware is used in both cases, the decision which of the two interfaces to
47*4f2df630SAndroid Build Coastguard Workeruse is made based on resistor straps the Cr50 reads at startup.
48*4f2df630SAndroid Build Coastguard Worker
49*4f2df630SAndroid Build Coastguard WorkerBoth I2C and SPI interfaces do not fully comply with their respective bus
50*4f2df630SAndroid Build Coastguard Workerstandards: the I2C controller does not support clock stretching, and the SPI
51*4f2df630SAndroid Build Coastguard Workercontroller can not be clocked faster than 2 MHz.
52*4f2df630SAndroid Build Coastguard Worker
53*4f2df630SAndroid Build Coastguard WorkerLook for a text line like the following in the Cr50 console output right after
54*4f2df630SAndroid Build Coastguard Workerpower up
55*4f2df630SAndroid Build Coastguard Worker
56*4f2df630SAndroid Build Coastguard Worker> [0.005657 Valid strap: 0xa properties: 0x41]
57*4f2df630SAndroid Build Coastguard Worker
58*4f2df630SAndroid Build Coastguard Workerto confirm that the straps were read properly.
59*4f2df630SAndroid Build Coastguard Worker
60*4f2df630SAndroid Build Coastguard WorkerA Cr50 console command allows to see which interface is used to communicate
61*4f2df630SAndroid Build Coastguard Workerwith the AP:
62*4f2df630SAndroid Build Coastguard Worker
63*4f2df630SAndroid Build Coastguard Worker> \> brdpprop<br>
64*4f2df630SAndroid Build Coastguard Worker> properties = 0x1141
65*4f2df630SAndroid Build Coastguard Worker
66*4f2df630SAndroid Build Coastguard WorkerIf the least significant bit of the value is set, the H1 is using the SPI
67*4f2df630SAndroid Build Coastguard Workerinterface, if the bit is cleared the H1 is using the I2C interface.
68*4f2df630SAndroid Build Coastguard Worker
69*4f2df630SAndroid Build Coastguard WorkerUsing H1 imposes additional requirements on the AP interface - the H1 might
70*4f2df630SAndroid Build Coastguard Workerhave to be waken up from sleep, and flow controls the AP using an additional
71*4f2df630SAndroid Build Coastguard Worker`AP_INT_L` signal, both described in more details below.
72*4f2df630SAndroid Build Coastguard Worker
73*4f2df630SAndroid Build Coastguard Worker## TPM reset
74*4f2df630SAndroid Build Coastguard Worker
75*4f2df630SAndroid Build Coastguard WorkerThe H1 is staying up until power is removed, unless it falls into deep sleep.
76*4f2df630SAndroid Build Coastguard WorkerTPM is just one of the components of the Cr50 firmware, and the TPM must be
77*4f2df630SAndroid Build Coastguard Workerreset when the AP resets.
78*4f2df630SAndroid Build Coastguard Worker
79*4f2df630SAndroid Build Coastguard WorkerThere are differences between ARM and X86 reset circuit architectures. ARM
80*4f2df630SAndroid Build Coastguard WorkerSOCs have a bidirectional reset signal called `SYS_RST_L`. They (or, rather,
81*4f2df630SAndroid Build Coastguard Workermost of them, but let's not worry about the outliers) generate a pulse on this
82*4f2df630SAndroid Build Coastguard Workerline when the SOC reboots. External device can toggle this line to reset the
83*4f2df630SAndroid Build Coastguard WorkerSOC asynchronously, which is what the Cr50 does to reset ARM SOCs.
84*4f2df630SAndroid Build Coastguard Worker
85*4f2df630SAndroid Build Coastguard WorkerThe X86 SOCs have two separate signals, one output `PLT_RST_L` which is held
86*4f2df630SAndroid Build Coastguard Workerlow, while the AP is in reset or in low power mode, and one input,
87*4f2df630SAndroid Build Coastguard Worker`SYS_RST_ODL` which Cr50 toggles to reset the SOC.
88*4f2df630SAndroid Build Coastguard Worker
89*4f2df630SAndroid Build Coastguard WorkerIn case of X86, when `PLT_RST_L` is held low longer than a second, the Cr50
90*4f2df630SAndroid Build Coastguard Workerconsiders this an indication of the AP going into a low power mode (S5 or
91*4f2df630SAndroid Build Coastguard Workerlower), which means that the AP will start from the reset vector when it wakes
92*4f2df630SAndroid Build Coastguard Workerup, so Cr50 can take H1 into *deep sleep* mode as well.
93*4f2df630SAndroid Build Coastguard Worker
94*4f2df630SAndroid Build Coastguard WorkerOn top of that ARM based Chrome OS devices have some additional logic which
95*4f2df630SAndroid Build Coastguard Workerforces the `SYS_RST_L` behave similar to `PLT_RST_L` - it stays low when
96*4f2df630SAndroid Build Coastguard Workerthe SOC is in a low power mode and will resume operation from the reset
97*4f2df630SAndroid Build Coastguard Workervector. This allows H1 to enter deep sleep on ARM devices as well.
98*4f2df630SAndroid Build Coastguard Worker
99*4f2df630SAndroid Build Coastguard WorkerResistor bootstraps tell the Cr50 which kind of reset architecture to expect,
100*4f2df630SAndroid Build Coastguard Workerthe SOC reset indication is used both to reset the TPM component and to enter
101*4f2df630SAndroid Build Coastguard Workerthe *deep sleep* mode as appropriate.
102*4f2df630SAndroid Build Coastguard Worker
103*4f2df630SAndroid Build Coastguard WorkerIn the `brdprop` command output bit D5 when set signifies `SYS_RST_L`
104*4f2df630SAndroid Build Coastguard Worker('regular' ARM devices) and bit D6 - `PLT_RST_L` (X86 and modified ARM) type
105*4f2df630SAndroid Build Coastguard Workerof reset.
106*4f2df630SAndroid Build Coastguard Worker
107*4f2df630SAndroid Build Coastguard WorkerBoot problems can arise when the AP reboots, without cr50 seeing a pulse on
108*4f2df630SAndroid Build Coastguard Workerthe `SYS_RST_L` or `PLT_RST_L` signal: in this case the very first TPM_Startup
109*4f2df630SAndroid Build Coastguard Workercommand sent by coreboot returns an error, and the Chrome OS device falls into
110*4f2df630SAndroid Build Coastguard Workerrecovery mode.
111*4f2df630SAndroid Build Coastguard Worker
112*4f2df630SAndroid Build Coastguard Worker
113*4f2df630SAndroid Build Coastguard Worker## Cr50 operations synchronization
114*4f2df630SAndroid Build Coastguard Worker
115*4f2df630SAndroid Build Coastguard WorkerThe H1 microcontroller is very slow (clocked at 24 MHz), the AP is usually
116*4f2df630SAndroid Build Coastguard Workerhundreds of times faster, there is a need to slow down the AP when it tries to
117*4f2df630SAndroid Build Coastguard Workertalk to the TPM during boot up process. The issue is complicated by the
118*4f2df630SAndroid Build Coastguard Workerinability of the I2C controller of stretching the clock.
119*4f2df630SAndroid Build Coastguard Worker
120*4f2df630SAndroid Build Coastguard WorkerIn both I2C and SPI modes the AP\_INT\_L H1 output signal is used to indicate
121*4f2df630SAndroid Build Coastguard Workerto the AP that the H1 is ready for the next I2C or SPI transaction. By default
122*4f2df630SAndroid Build Coastguard Workerthis signal is a 4+ us long low pulse. Some X86 platforms require a pulse of
123*4f2df630SAndroid Build Coastguard Worker100+ us, this pulse extension mode can be configured by setting a bit in a TPM
124*4f2df630SAndroid Build Coastguard Workerregister (I2C register address 0x1c or SPI register address 0xfe0).
125*4f2df630SAndroid Build Coastguard Worker
126*4f2df630SAndroid Build Coastguard WorkerIn any case it is important that the AP firmware is properly configuring the
127*4f2df630SAndroid Build Coastguard Workerpin where the AP\_INT\_L signal is connected as an edge sensitive GPIO, which
128*4f2df630SAndroid Build Coastguard Workerlatches on either falling or rising edge of the signal.
129*4f2df630SAndroid Build Coastguard Worker
130*4f2df630SAndroid Build Coastguard WorkerAP firmware missing these synchronization pulses results in boot process
131*4f2df630SAndroid Build Coastguard Workertaking very long time and the AP firmware log including messages
132*4f2df630SAndroid Build Coastguard Worker
133*4f2df630SAndroid Build Coastguard Worker> Timeout wait for TPM IRQ!
134*4f2df630SAndroid Build Coastguard Worker
135*4f2df630SAndroid Build Coastguard Workerin case of SPI or
136*4f2df630SAndroid Build Coastguard Worker
137*4f2df630SAndroid Build Coastguard Worker> Cr50 i2c TPM IRQ timeout!
138*4f2df630SAndroid Build Coastguard Worker
139*4f2df630SAndroid Build Coastguard Workerin case of I2C.
140*4f2df630SAndroid Build Coastguard Worker
141*4f2df630SAndroid Build Coastguard Worker## Waking H1 up from sleep
142*4f2df630SAndroid Build Coastguard Worker
143*4f2df630SAndroid Build Coastguard WorkerThe I2C Start sequence is sufficient for the H1 to resume operation, the AP
144*4f2df630SAndroid Build Coastguard Workerdoes not have to do anything special. In case of SPI the matters are more
145*4f2df630SAndroid Build Coastguard Workercomplicated.
146*4f2df630SAndroid Build Coastguard Worker
147*4f2df630SAndroid Build Coastguard WorkerTechnically speaking the assertion of the CS SPI bus signal is enough to wake
148*4f2df630SAndroid Build Coastguard Workerup the H1, but it takes time for it to become fully operational, the AP could
149*4f2df630SAndroid Build Coastguard Workerbe already transmitting the message by the time the H1 SPI controller is
150*4f2df630SAndroid Build Coastguard Workerready. This is why in case the previous SPI transaction was a second or more
151*4f2df630SAndroid Build Coastguard Workerago, the SPI driver is required to first issue a CS pulse without transferring
152*4f2df630SAndroid Build Coastguard Workerany data, just to wake up the H1, then wait for 100 us to let the H1 wake up,
153*4f2df630SAndroid Build Coastguard Workerand then continue with a regular SPI transaction.
154*4f2df630SAndroid Build Coastguard Worker
155*4f2df630SAndroid Build Coastguard WorkerIf the AP does not follow this protocol and starts transmitting before H1 is
156*4f2df630SAndroid Build Coastguard Workerready, communications failures are likely, resulting in the Chrome OS device
157*4f2df630SAndroid Build Coastguard Workerfalling into recovery. This often happens when the device took a long time to
158*4f2df630SAndroid Build Coastguard Workerfind the kernel to boot, and then the AP is trying to lock the TPM state
159*4f2df630SAndroid Build Coastguard Workerbefore starting up the kernel, but fails, because the H1 was asleep by this
160*4f2df630SAndroid Build Coastguard Workertime and was not properly woken up.
161*4f2df630SAndroid Build Coastguard Worker
162*4f2df630SAndroid Build Coastguard Worker## SPI Message Synchronization
163*4f2df630SAndroid Build Coastguard Worker
164*4f2df630SAndroid Build Coastguard WorkerSPI interface is synchronous, and either read or write accesses happen within
165*4f2df630SAndroid Build Coastguard Workera single transaction. The Trusted Computing Group (TCG) came up with a
166*4f2df630SAndroid Build Coastguard Workerhardware protocol on top of SPI specification to allow the slow device to flow
167*4f2df630SAndroid Build Coastguard Workercontrol the fast host controller.
168*4f2df630SAndroid Build Coastguard Worker
169*4f2df630SAndroid Build Coastguard WorkerThe base idea is that each time the AP wants to read or write a TPM register,
170*4f2df630SAndroid Build Coastguard Workerit sends a SPI packet, which consists of the header and data fields.
171*4f2df630SAndroid Build Coastguard Worker
172*4f2df630SAndroid Build Coastguard WorkerThe header field is always present, it is 4 bytes in size, and includes the
173*4f2df630SAndroid Build Coastguard Workeroperation type (read or write), data length and register address.
174*4f2df630SAndroid Build Coastguard Worker
175*4f2df630SAndroid Build Coastguard WorkerThe header is sent out as soon as the SPI transaction starts, then the AP
176*4f2df630SAndroid Build Coastguard Workerstarts monitoring the MOSI line, one byte at a time, paying attention to bit
177*4f2df630SAndroid Build Coastguard WorkerD0. The Cr50 keeps sending zeros on that bit, until ready to proceed with the
178*4f2df630SAndroid Build Coastguard Workeroperation requested in the transaction header. Once the Cr50 is ready, it
179*4f2df630SAndroid Build Coastguard Workerresponds with a byte with bit D0 set to one. At this point the AP knows that
180*4f2df630SAndroid Build Coastguard Workerstarting with the next byte the actual data of the transaction can be flowing,
181*4f2df630SAndroid Build Coastguard Workerso it either sends the data in case of write or reads it from the TPM in case
182*4f2df630SAndroid Build Coastguard Workerof reads.
183*4f2df630SAndroid Build Coastguard Worker
184*4f2df630SAndroid Build Coastguard WorkerThis is described in details in [TCG PC Client Platform TPM Profile (PTP)
185*4f2df630SAndroid Build Coastguard WorkerSpecification Family "2.0" Level 00 Revision
186*4f2df630SAndroid Build Coastguard Worker00.43](https://drive.google.com/file/d/16r1vDhf1fnggI4BkOBuTXPqOQt4LaFvk/view?usp=sharing)
187*4f2df630SAndroid Build Coastguard Workerin section "6.4 Spi Hardware Protocol".
188*4f2df630SAndroid Build Coastguard Worker
189*4f2df630SAndroid Build Coastguard WorkerThe AP ignoring this flow control mechanism is yet another common problem
190*4f2df630SAndroid Build Coastguard Workercausing failures to boot, because the driver starts sending or receiving data
191*4f2df630SAndroid Build Coastguard Workerbefore TPM is ready. This failure is more likely to happen when developing new
192*4f2df630SAndroid Build Coastguard WorkerSPI drivers.
193*4f2df630SAndroid Build Coastguard Worker
194*4f2df630SAndroid Build Coastguard Worker## Boot up process examples
195*4f2df630SAndroid Build Coastguard Worker
196*4f2df630SAndroid Build Coastguard WorkerA trace of a typical Chrome OS device boot process was collected using the
197*4f2df630SAndroid Build Coastguard Worker[Saleae](https://www.saleae.com/) Logic Pro 16 logic analyzer.
198*4f2df630SAndroid Build Coastguard Worker
199*4f2df630SAndroid Build Coastguard WorkerThe [full trace](./images/bobba_boot.sal) can be examined in details using the
200*4f2df630SAndroid Build Coastguard WorkerSaleae application in the trace analysis mode.
201*4f2df630SAndroid Build Coastguard Worker
202*4f2df630SAndroid Build Coastguard WorkerA few detailed snapshots of this trace are shown below (click to expand):
203*4f2df630SAndroid Build Coastguard Worker
204*4f2df630SAndroid Build Coastguard Worker### Full boot sequence
205*4f2df630SAndroid Build Coastguard Worker
206*4f2df630SAndroid Build Coastguard Worker[![Full boot sequence](./images/typical_boot.png)][1] shows communications
207*4f2df630SAndroid Build Coastguard Workerbetween AP an H1 during a typical Chrome OS boot: first a flurry of
208*4f2df630SAndroid Build Coastguard Workercommunications between Coreboot and the H1, then some time spent verifying and
209*4f2df630SAndroid Build Coastguard Workerloading various firmware stages, then a block of communications between
210*4f2df630SAndroid Build Coastguard WorkerDepthcarge and the H1.
211*4f2df630SAndroid Build Coastguard Worker
212*4f2df630SAndroid Build Coastguard Worker### Typical read sequence
213*4f2df630SAndroid Build Coastguard Worker
214*4f2df630SAndroid Build Coastguard Worker[![Typical read sequence](./images/typical_read.png)][2] shows the 4 byte
215*4f2df630SAndroid Build Coastguard Workerheader where the read of four bytes from register address 0xd40f00 is
216*4f2df630SAndroid Build Coastguard Workerrequested. The TPM is not ready and sends all zeros on the MISO line for three
217*4f2df630SAndroid Build Coastguard Workercycles, then sends a byte of 01 and then the AP reads four bytes of the actual
218*4f2df630SAndroid Build Coastguard Workerregister value (0xe01a2800). Then, after H1 is ready to accept the next SPI
219*4f2df630SAndroid Build Coastguard Workertransaction it generates a pulse on AP\_INT\_L.
220*4f2df630SAndroid Build Coastguard Worker
221*4f2df630SAndroid Build Coastguard Worker### Read with wake pulse sequence
222*4f2df630SAndroid Build Coastguard Worker
223*4f2df630SAndroid Build Coastguard Worker[![Read with wake pulse](./images/read_with_wake_pulse.png)][3] is an example
224*4f2df630SAndroid Build Coastguard Workerof a case where the AP toggles the CS line first, without sending any data,
225*4f2df630SAndroid Build Coastguard Workerand then in 100 us starts the actual SPI transaction completed with the
226*4f2df630SAndroid Build Coastguard WorkerAP\_INT\_L pulse.
227*4f2df630SAndroid Build Coastguard Worker
228*4f2df630SAndroid Build Coastguard Worker[1]:https://drive.google.com/file/d/16Z_Nw1e6z5akUnyLZyI8ivfT5frxKPQh/view
229*4f2df630SAndroid Build Coastguard Worker[2]:https://drive.google.com/file/d/1weBd6kBiXoQ0I3TGmbpiHZm0dimByYnI/view
230*4f2df630SAndroid Build Coastguard Worker[3]:https://drive.google.com/file/d/13ZSP3up4leG0Etqo4A_gkFK1MeptGDCw/view
231