Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: firmware/lib/vboot_firmware.c

Issue 3041005: Add lots of debugging to TPM library. (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Fix TPM unit tests Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « firmware/lib/tpm_lite/tlcl.c ('k') | firmware/lib/vboot_kernel.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 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 "load_firmware_fw.h" 9 #include "load_firmware_fw.h"
10 #include "rollback_index.h" 10 #include "rollback_index.h"
(...skipping 23 matching lines...) Expand all
34 int LoadFirmware(LoadFirmwareParams* params) { 34 int LoadFirmware(LoadFirmwareParams* params) {
35 35
36 VbPublicKey* root_key = (VbPublicKey*)params->firmware_root_key_blob; 36 VbPublicKey* root_key = (VbPublicKey*)params->firmware_root_key_blob;
37 VbLoadFirmwareInternal* lfi; 37 VbLoadFirmwareInternal* lfi;
38 38
39 uint16_t tpm_key_version = 0; 39 uint16_t tpm_key_version = 0;
40 uint16_t tpm_fw_version = 0; 40 uint16_t tpm_fw_version = 0;
41 uint64_t lowest_key_version = 0xFFFF; 41 uint64_t lowest_key_version = 0xFFFF;
42 uint64_t lowest_fw_version = 0xFFFF; 42 uint64_t lowest_fw_version = 0xFFFF;
43 uint32_t status; 43 uint32_t status;
44 int is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0);
44 int good_index = -1; 45 int good_index = -1;
45 int index; 46 int index;
46 47
47 /* Clear output params in case we fail */ 48 /* Clear output params in case we fail */
48 params->firmware_index = 0; 49 params->firmware_index = 0;
49 50
50 VBDEBUG(("LoadFirmware started...\n")); 51 VBDEBUG(("LoadFirmware started...\n"));
51 52
52 if (params->kernel_sign_key_size < sizeof(VbPublicKey)) { 53 if (params->kernel_sign_key_size < sizeof(VbPublicKey)) {
53 VBDEBUG(("Kernel sign key buffer too small\n")); 54 VBDEBUG(("Kernel sign key buffer too small\n"));
54 return LOAD_FIRMWARE_RECOVERY; 55 return LOAD_FIRMWARE_RECOVERY;
55 } 56 }
56 57
57 /* Must have a root key */ 58 /* Must have a root key */
58 if (!root_key) { 59 if (!root_key) {
59 VBDEBUG(("No root key\n")); 60 VBDEBUG(("No root key\n"));
60 return LOAD_FIRMWARE_RECOVERY; 61 return LOAD_FIRMWARE_RECOVERY;
61 } 62 }
62 63
63 /* Initialize the TPM and read rollback indices. */ 64 /* Initialize the TPM and read rollback indices. */
64 status = RollbackFirmwareSetup(params->boot_flags & BOOT_FLAG_DEVELOPER); 65 if (!is_dev) {
65 if (0 != status) { 66 /* TODO: should use the TPM all the time; for now, only use when
66 VBDEBUG(("Unable to setup TPM.\n")); 67 * not in developer mode. */
67 return (status == TPM_E_MUST_REBOOT ? 68 status = RollbackFirmwareSetup(params->boot_flags & BOOT_FLAG_DEVELOPER);
68 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY); 69 if (0 != status) {
69 } 70 VBDEBUG(("Unable to setup TPM.\n"));
70 status = RollbackFirmwareRead(&tpm_key_version, &tpm_fw_version); 71 return (status == TPM_E_MUST_REBOOT ?
71 if (0 != status) { 72 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY);
72 VBDEBUG(("Unable to read stored versions.\n")); 73 }
73 return (status == TPM_E_MUST_REBOOT ? 74 status = RollbackFirmwareRead(&tpm_key_version, &tpm_fw_version);
74 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY); 75 if (0 != status) {
76 VBDEBUG(("Unable to read stored versions.\n"));
77 return (status == TPM_E_MUST_REBOOT ?
78 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY);
79 }
75 } 80 }
76 81
77 /* Allocate our internal data */ 82 /* Allocate our internal data */
78 lfi = (VbLoadFirmwareInternal*)Malloc(sizeof(VbLoadFirmwareInternal)); 83 lfi = (VbLoadFirmwareInternal*)Malloc(sizeof(VbLoadFirmwareInternal));
79 if (!lfi) 84 if (!lfi)
80 return LOAD_FIRMWARE_RECOVERY; 85 return LOAD_FIRMWARE_RECOVERY;
81 params->load_firmware_internal = (uint8_t*)lfi; 86 params->load_firmware_internal = (uint8_t*)lfi;
82 87
83 /* Loop over indices */ 88 /* Loop over indices */
84 for (index = 0; index < 2; index++) { 89 for (index = 0; index < 2; index++) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 params->load_firmware_internal = NULL; 223 params->load_firmware_internal = NULL;
219 224
220 /* Handle finding good firmware */ 225 /* Handle finding good firmware */
221 if (good_index >= 0) { 226 if (good_index >= 0) {
222 227
223 /* Update TPM if necessary */ 228 /* Update TPM if necessary */
224 if ((lowest_key_version > tpm_key_version) || 229 if ((lowest_key_version > tpm_key_version) ||
225 (lowest_key_version == tpm_key_version && 230 (lowest_key_version == tpm_key_version &&
226 lowest_fw_version > tpm_fw_version)) { 231 lowest_fw_version > tpm_fw_version)) {
227 232
233 if (!is_dev) {
234 /* TODO: should use the TPM all the time; for now, only use
235 * when not in developer mode. */
236 status = RollbackFirmwareWrite((uint16_t)lowest_key_version,
237 (uint16_t)lowest_fw_version);
238 if (0 != status) {
239 VBDEBUG(("Unable to write stored versions.\n"));
240 return (status == TPM_E_MUST_REBOOT ?
241 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY);
242 }
243 }
244 }
228 245
229 status = RollbackFirmwareWrite((uint16_t)lowest_key_version, 246 if (!is_dev) {
230 (uint16_t)lowest_fw_version); 247 /* TODO: should use the TPM all the time; for now, only use
248 * when not in developer mode. */
249 /* Lock firmware versions in TPM */
250 status = RollbackFirmwareLock();
231 if (0 != status) { 251 if (0 != status) {
232 VBDEBUG(("Unable to write stored versions.\n")); 252 VBDEBUG(("Unable to lock firmware versions.\n"));
233 return (status == TPM_E_MUST_REBOOT ? 253 return (status == TPM_E_MUST_REBOOT ?
234 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY); 254 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY);
235 } 255 }
236 } 256 }
237 257
238 /* Lock firmware versions in TPM */
239 status = RollbackFirmwareLock();
240 if (0 != status) {
241 VBDEBUG(("Unable to lock firmware versions.\n"));
242 return (status == TPM_E_MUST_REBOOT ?
243 LOAD_FIRMWARE_REBOOT : LOAD_FIRMWARE_RECOVERY);
244 }
245
246 /* Success */ 258 /* Success */
247 VBDEBUG(("Will boot firmware index %d\n", (int)params->firmware_index)); 259 VBDEBUG(("Will boot firmware index %d\n", (int)params->firmware_index));
248 return LOAD_FIRMWARE_SUCCESS; 260 return LOAD_FIRMWARE_SUCCESS;
249 } 261 }
250 262
251 /* If we're still here, no good firmware, so go to recovery mode. */ 263 /* If we're still here, no good firmware, so go to recovery mode. */
252 VBDEBUG(("Alas, no good firmware.\n")); 264 VBDEBUG(("Alas, no good firmware.\n"));
253 return LOAD_FIRMWARE_RECOVERY; 265 return LOAD_FIRMWARE_RECOVERY;
254 } 266 }
OLDNEW
« no previous file with comments | « firmware/lib/tpm_lite/tlcl.c ('k') | firmware/lib/vboot_kernel.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698