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

Side by Side Diff: firmware/lib/tpm_lite/tlcl.c

Issue 6667051: Move ContinueSelfTest to a later point to save time. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: WIP Created 9 years, 9 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 | Annotate | Revision Log
« firmware/lib/rollback_index.c ('K') | « firmware/lib/rollback_index.c ('k') | no next file » | 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-2011 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010-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 5
6 /* A lightweight TPM command library. 6 /* A lightweight TPM command library.
7 * 7 *
8 * The general idea is that TPM commands are array of bytes whose 8 * The general idea is that TPM commands are array of bytes whose
9 * fields are mostly compile-time constant. The goal is to build much 9 * fields are mostly compile-time constant. The goal is to build much
10 * of the commands at compile time (or build time) and change some of 10 * of the commands at compile time (or build time) and change some of
(...skipping 26 matching lines...) Expand all
37 uint32_t code; 37 uint32_t code;
38 FromTpmUint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code); 38 FromTpmUint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
39 return code; 39 return code;
40 } 40 }
41 41
42 /* Gets the return code field of a TPM result. */ 42 /* Gets the return code field of a TPM result. */
43 static INLINE int TpmReturnCode(const uint8_t* buffer) { 43 static INLINE int TpmReturnCode(const uint8_t* buffer) {
44 return TpmCommandCode(buffer); 44 return TpmCommandCode(buffer);
45 } 45 }
46 46
47 /* Sends a TPM command and gets a response. Returns 0 if success or the TPM 47 /* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or
48 * error code if error. */ 48 * DOING_SELFTEST errors are returned.
49 static uint32_t TlclSendReceive(const uint8_t* request, uint8_t* response, 49 */
50 int max_length) { 50 static uint32_t TlclSendReceiveNoRetry(const uint8_t* request,
51 51 uint8_t* response, int max_length) {
52 uint32_t result; 52 uint32_t result;
53 53
54 #ifdef EXTRA_LOGGING 54 #ifdef EXTRA_LOGGING
55 VBDEBUG(("TPM: command: %x%x %x%x%x%x %x%x%x%x\n", 55 VBDEBUG(("TPM: command: %x%x %x%x%x%x %x%x%x%x\n",
56 request[0], request[1], 56 request[0], request[1],
57 request[2], request[3], request[4], request[5], 57 request[2], request[3], request[4], request[5],
58 request[6], request[7], request[8], request[9])); 58 request[6], request[7], request[8], request[9]));
59 #endif 59 #endif
60 60
61 result = TlclStubSendReceive(request, TpmCommandSize(request), 61 result = TlclStubSendReceive(request, TpmCommandSize(request),
(...skipping 14 matching lines...) Expand all
76 response[6], response[7], response[8], response[9])); 76 response[6], response[7], response[8], response[9]));
77 #endif 77 #endif
78 78
79 VBDEBUG(("TPM: command 0x%x returned 0x%x\n", 79 VBDEBUG(("TPM: command 0x%x returned 0x%x\n",
80 TpmCommandCode(request), result)); 80 TpmCommandCode(request), result));
81 81
82 return result; 82 return result;
83 } 83 }
84 84
85 85
86 /* Sends a TPM command and gets a response. Returns 0 if success or the TPM
87 * error code if error. Waits for self test to complete if needed. */
88 static uint32_t TlclSendReceive(const uint8_t* request, uint8_t* response,
89 int max_length) {
90 uint32_t result = TlclSendReceiveNoRetry(request, response, max_length);
91 if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
92 result = TlclContinueSelfTest();
93 if (result != TPM_SUCCESS) {
94 return result;
95 }
96 #ifdef TPM_BLOCKING_CONTINUESELFTEST
97 result = TlclSendReceiveNoRetry(request, response, max_length);
98 #else
99 /* This needs serious testing. The TPM specification says: iii. The caller
100 * MUST wait for the actions of TPM_ContinueSelfTest to complete before
101 * reissuing the command C1. But, how do we know that the actions have
102 * completed other than trying again? */
103 do {
104 result = TlclSendReceiveNoRetry(request, response, max_length);
105 } while (result == TPM_E_DOING_SELFTEST);
Randall Spangler 2011/03/16 19:23:06 If the TPM gets in a wonky state, this could block
Luigi Semenzato 2011/03/16 20:51:59 Ah, now I remember, that's why we wanted the compi
106 #endif
107 }
108 return result;
109 }
110
86 /* Sends a command and returns the error code. */ 111 /* Sends a command and returns the error code. */
87 static uint32_t Send(const uint8_t* command) { 112 static uint32_t Send(const uint8_t* command) {
88 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; 113 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
89 return TlclSendReceive(command, response, sizeof(response)); 114 return TlclSendReceive(command, response, sizeof(response));
90 } 115 }
91 116
92 /* Exported functions. */ 117 /* Exported functions. */
93 118
94 uint32_t TlclLibInit(void) { 119 uint32_t TlclLibInit(void) {
95 return TlclStubInit(); 120 return TlclStubInit();
(...skipping 13 matching lines...) Expand all
109 VBDEBUG(("TPM: Resume\n")); 134 VBDEBUG(("TPM: Resume\n"));
110 return Send(tpm_resume_cmd.buffer); 135 return Send(tpm_resume_cmd.buffer);
111 } 136 }
112 137
113 uint32_t TlclSelfTestFull(void) { 138 uint32_t TlclSelfTestFull(void) {
114 VBDEBUG(("TPM: Self test full\n")); 139 VBDEBUG(("TPM: Self test full\n"));
115 return Send(tpm_selftestfull_cmd.buffer); 140 return Send(tpm_selftestfull_cmd.buffer);
116 } 141 }
117 142
118 uint32_t TlclContinueSelfTest(void) { 143 uint32_t TlclContinueSelfTest(void) {
144 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
119 VBDEBUG(("TPM: Continue self test\n")); 145 VBDEBUG(("TPM: Continue self test\n"));
120 return Send(tpm_continueselftest_cmd.buffer); 146 /* Call the No Retry version of SendReceive to avoid recursion. */
147 return TlclSendReceiveNoRetry(tpm_continueselftest_cmd.buffer,
148 response, sizeof(response));
121 } 149 }
122 150
123 uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size) { 151 uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size) {
124 struct s_tpm_nv_definespace_cmd cmd; 152 struct s_tpm_nv_definespace_cmd cmd;
125 VBDEBUG(("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size)); 153 VBDEBUG(("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size));
126 Memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd)); 154 Memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd));
127 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.index, index); 155 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.index, index);
128 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm); 156 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm);
129 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.size, size); 157 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.size, size);
130 return Send(cmd.buffer); 158 return Send(cmd.buffer);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd)); 352 Memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd));
325 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index); 353 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index);
326 result = TlclSendReceive(cmd.buffer, response, sizeof(response)); 354 result = TlclSendReceive(cmd.buffer, response, sizeof(response));
327 if (result != TPM_SUCCESS) 355 if (result != TPM_SUCCESS)
328 return result; 356 return result;
329 357
330 nvdata = response + kTpmResponseHeaderLength + sizeof(size); 358 nvdata = response + kTpmResponseHeaderLength + sizeof(size);
331 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); 359 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions);
332 return result; 360 return result;
333 } 361 }
OLDNEW
« firmware/lib/rollback_index.c ('K') | « firmware/lib/rollback_index.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698