OLD | NEW |
1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * High-level firmware API for loading and verifying rewritable firmware. | 5 * High-level firmware API for loading and verifying rewritable firmware. |
6 * (Firmware portion) | 6 * (Firmware portion) |
7 */ | 7 */ |
8 | 8 |
9 #include "gbb_header.h" | 9 #include "gbb_header.h" |
10 #include "load_firmware_fw.h" | 10 #include "load_firmware_fw.h" |
11 #include "rollback_index.h" | 11 #include "rollback_index.h" |
| 12 #include "tpm_bootmode.h" |
12 #include "utility.h" | 13 #include "utility.h" |
13 #include "vboot_common.h" | 14 #include "vboot_common.h" |
14 #include "vboot_nvstorage.h" | 15 #include "vboot_nvstorage.h" |
15 | 16 |
16 /* Static variables for UpdateFirmwareBodyHash(). It's less than | 17 /* Static variables for UpdateFirmwareBodyHash(). It's less than |
17 * optimal to have static variables in a library, but in UEFI the | 18 * optimal to have static variables in a library, but in UEFI the |
18 * caller is deep inside a different firmware stack and doesn't have a | 19 * caller is deep inside a different firmware stack and doesn't have a |
19 * good way to pass the params struct back to us. */ | 20 * good way to pass the params struct back to us. */ |
20 typedef struct VbLoadFirmwareInternal { | 21 typedef struct VbLoadFirmwareInternal { |
21 DigestContext body_digest_context; | 22 DigestContext body_digest_context; |
(...skipping 22 matching lines...) Expand all Loading... |
44 GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)params->gbb_data; | 45 GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)params->gbb_data; |
45 VbPublicKey* root_key; | 46 VbPublicKey* root_key; |
46 VbLoadFirmwareInternal* lfi; | 47 VbLoadFirmwareInternal* lfi; |
47 VbNvContext* vnc = params->nv_context; | 48 VbNvContext* vnc = params->nv_context; |
48 | 49 |
49 uint32_t try_b_count; | 50 uint32_t try_b_count; |
50 uint32_t tpm_version = 0; | 51 uint32_t tpm_version = 0; |
51 uint64_t lowest_version = 0xFFFFFFFF; | 52 uint64_t lowest_version = 0xFFFFFFFF; |
52 uint32_t status; | 53 uint32_t status; |
53 int good_index = -1; | 54 int good_index = -1; |
| 55 int boot_fw_keyblock_flags = 0; |
54 int is_dev; | 56 int is_dev; |
55 int index; | 57 int index; |
56 int i; | 58 int i; |
57 | 59 |
58 int retval = LOAD_FIRMWARE_RECOVERY; | 60 int retval = LOAD_FIRMWARE_RECOVERY; |
59 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; | 61 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; |
60 | 62 |
61 /* Clear output params in case we fail */ | 63 /* Clear output params in case we fail */ |
62 params->firmware_index = 0; | 64 params->firmware_index = 0; |
63 | 65 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (0 != VbSharedDataSetKernelKey(shared, &preamble->kernel_subkey)) { | 246 if (0 != VbSharedDataSetKernelKey(shared, &preamble->kernel_subkey)) { |
245 VBDEBUG(("Unable to save kernel subkey to shared data.\n")); | 247 VBDEBUG(("Unable to save kernel subkey to shared data.\n")); |
246 continue; /* The firmware signature was good, but the public | 248 continue; /* The firmware signature was good, but the public |
247 * key was bigger that the caller can handle. */ | 249 * key was bigger that the caller can handle. */ |
248 } | 250 } |
249 | 251 |
250 /* Save the good index, now that we're sure we can actually use | 252 /* Save the good index, now that we're sure we can actually use |
251 * this firmware. That's the one we'll boot. */ | 253 * this firmware. That's the one we'll boot. */ |
252 good_index = index; | 254 good_index = index; |
253 params->firmware_index = index; | 255 params->firmware_index = index; |
| 256 /* Since we now know which firmware to boot, we can update the |
| 257 * bootable firmware key block mode. */ |
| 258 boot_fw_keyblock_flags = key_block->key_block_flags; |
254 | 259 |
255 /* If the good firmware's key version is the same as the tpm, | 260 /* If the good firmware's key version is the same as the tpm, |
256 * then the TPM doesn't need updating; we can stop now. | 261 * then the TPM doesn't need updating; we can stop now. |
257 * Otherwise, we'll check all the other headers to see if they | 262 * Otherwise, we'll check all the other headers to see if they |
258 * contain a newer key. */ | 263 * contain a newer key. */ |
259 if (combined_version == tpm_version) | 264 if (combined_version == tpm_version) |
260 break; | 265 break; |
261 } | 266 } |
262 } | 267 } |
263 | 268 |
| 269 /* At this point, we have a good idea of how we are going to boot. Update the |
| 270 * TPM with this state information. |
| 271 */ |
| 272 status = SetTPMBootModeState(is_dev, 0, boot_fw_keyblock_flags); |
| 273 if (0 != status) { |
| 274 VBDEBUG(("Unable to update the TPM with boot mode information.\n")); |
| 275 if (status == TPM_E_MUST_REBOOT) |
| 276 retval = LOAD_FIRMWARE_REBOOT; |
| 277 else |
| 278 recovery = VBNV_RECOVERY_RO_TPM_ERROR; |
| 279 goto LoadFirmwareExit; |
| 280 } |
| 281 |
264 /* Free internal data */ | 282 /* Free internal data */ |
265 Free(lfi); | 283 Free(lfi); |
266 params->load_firmware_internal = NULL; | 284 params->load_firmware_internal = NULL; |
267 | 285 |
268 /* Handle finding good firmware */ | 286 /* Handle finding good firmware */ |
269 if (good_index >= 0) { | 287 if (good_index >= 0) { |
270 | 288 |
271 /* Update TPM if necessary */ | 289 /* Update TPM if necessary */ |
272 if (lowest_version > tpm_version) { | 290 if (lowest_version > tpm_version) { |
273 VBPERFSTART("VB_TPMU"); | 291 VBPERFSTART("VB_TPMU"); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 uint32_t status = RollbackS3Resume(); | 342 uint32_t status = RollbackS3Resume(); |
325 | 343 |
326 /* If we can't resume, just do a full reboot. No need to go to recovery | 344 /* If we can't resume, just do a full reboot. No need to go to recovery |
327 * mode here, since if the TPM is really broken we'll catch it on the | 345 * mode here, since if the TPM is really broken we'll catch it on the |
328 * next boot. */ | 346 * next boot. */ |
329 if (status == TPM_SUCCESS) | 347 if (status == TPM_SUCCESS) |
330 return LOAD_FIRMWARE_SUCCESS; | 348 return LOAD_FIRMWARE_SUCCESS; |
331 else | 349 else |
332 return LOAD_FIRMWARE_REBOOT; | 350 return LOAD_FIRMWARE_REBOOT; |
333 } | 351 } |
OLD | NEW |