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

Side by Side Diff: src/platform/tpm_lite/src/testsuite/readonly.c

Issue 870004: Many upgrades to tpm_lite. (Closed)
Patch Set: Fix makefile comment. Created 10 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
« no previous file with comments | « src/platform/tpm_lite/src/testsuite/Makefile ('k') | src/platform/tpm_lite/src/tlcl/Makefile » ('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 5
6 /* This program mimicks the TPM usage from read-only firmware. It exercises 6 /* This program mimicks the TPM usage from read-only firmware. It exercises
7 * the TPM functionality needed in the read-only firmware. It is meant to be 7 * the TPM functionality needed in the read-only firmware. It is meant to be
8 * integrated with the rest of the read-only firmware. It is also provided as 8 * integrated with the rest of the read-only firmware. It is also provided as
9 * a test. 9 * a test.
10 */ 10 */
(...skipping 17 matching lines...) Expand all
28 28
29 /* This is called once at initialization time. It may be called again from 29 /* This is called once at initialization time. It may be called again from
30 * recovery mode to rebuild the spaces if something incomprehensible happened 30 * recovery mode to rebuild the spaces if something incomprehensible happened
31 * and the spaces are gone or messed up. This is called after TPM_Startup and 31 * and the spaces are gone or messed up. This is called after TPM_Startup and
32 * before the spaces are write-locked, so there is a chance that they can be 32 * before the spaces are write-locked, so there is a chance that they can be
33 * recreated (but who knows---if anything can happen, there are plenty of ways 33 * recreated (but who knows---if anything can happen, there are plenty of ways
34 * of making this FUBAR). 34 * of making this FUBAR).
35 */ 35 */
36 void InitializeSpaces(void) { 36 void InitializeSpaces(void) {
37 uint32_t zero = 0; 37 uint32_t zero = 0;
38 uint32_t perm = TPM_NV_PER_WRITE_STCLEAR;
38 39
40 printf("Initializing spaces\n");
39 TlclSetNvLocked(); /* useful only the first time */ 41 TlclSetNvLocked(); /* useful only the first time */
40 42
41 TlclDefineSpace(INDEX0, TPM_NV_PER_WRITE_STCLEAR, 4); 43 TlclDefineSpace(INDEX0, perm, 4);
42 TlclWrite(INDEX0, (uint8_t *) &zero, 4); 44 TlclWrite(INDEX0, (uint8_t *) &zero, 4);
43 TlclDefineSpace(INDEX1, TPM_NV_PER_WRITE_STCLEAR, 4); 45 TlclDefineSpace(INDEX1, perm, 4);
44 TlclWrite(INDEX1, (uint8_t *) &zero, 4); 46 TlclWrite(INDEX1, (uint8_t *) &zero, 4);
45 TlclDefineSpace(INDEX2, TPM_NV_PER_WRITE_STCLEAR, 4); 47 TlclDefineSpace(INDEX2, perm, 4);
46 TlclWrite(INDEX2, (uint8_t *) &zero, 4); 48 TlclWrite(INDEX2, (uint8_t *) &zero, 4);
47 TlclDefineSpace(INDEX3, TPM_NV_PER_WRITE_STCLEAR, 4); 49 TlclDefineSpace(INDEX3, perm, 4);
48 TlclWrite(INDEX3, (uint8_t *) &zero, 4); 50 TlclWrite(INDEX3, (uint8_t *) &zero, 4);
49 51
50 TlclDefineSpace(INDEX_INITIALIZED, TPM_NV_PER_READ_STCLEAR, 1); 52 perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
51 TlclReadLock(INDEX_INITIALIZED); 53 TPM_NV_PER_PPWRITE;
54 TlclDefineSpace(INDEX_INITIALIZED, perm, 1);
52 } 55 }
53 56
54 57
55 void EnterRecoveryMode(void) { 58 void EnterRecoveryMode(void) {
56 printf("entering recovery mode"); 59 printf("entering recovery mode");
57 exit(0); 60 exit(0);
58 } 61 }
59 62
60 63
61 int main(void) { 64 int main(void) {
62 uint8_t c; 65 uint8_t c;
63 uint32_t index_0, index_1, index_2, index_3; 66 uint32_t index_0, index_1, index_2, index_3;
64 67
65 TlclLibinit(); 68 TlclLibinit();
66 69
67 #if 0 70 #if 0
68 TlclStartup(); 71 TlclStartup();
69 TlclSelftestfull(); 72 TlclSelftestfull();
70 #endif 73 #endif
71 74
72 TlclAssertPhysicalPresence(); 75 TlclAssertPhysicalPresence();
73 76
74 /* Checks if initialization has completed. 77 /* Checks if initialization has completed by trying to read-lock a space
78 * that's created at the end of initialization.
75 */ 79 */
76 if (TlclRead(INDEX_INITIALIZED, &c, 1) != TPM_E_DISABLED_CMD) { 80 if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) {
77 /* The initialization did not complete. 81 /* The initialization did not complete.
78 */ 82 */
79 InitializeSpaces(); 83 InitializeSpaces();
80 } 84 }
81 85
82 /* Checks if spaces are OK or messed up. 86 /* Checks if spaces are OK or messed up.
83 */ 87 */
84 if (TlclRead(INDEX0, (uint8_t *) &index_0, sizeof(index_0)) != TPM_SUCCESS || 88 if (TlclRead(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) != TPM_SUCCESS ||
85 TlclRead(INDEX1, (uint8_t *) &index_1, sizeof(index_1)) != TPM_SUCCESS || 89 TlclRead(INDEX1, (uint8_t*) &index_1, sizeof(index_1)) != TPM_SUCCESS ||
86 TlclRead(INDEX2, (uint8_t *) &index_2, sizeof(index_2)) != TPM_SUCCESS || 90 TlclRead(INDEX2, (uint8_t*) &index_2, sizeof(index_2)) != TPM_SUCCESS ||
87 TlclRead(INDEX3, (uint8_t *) &index_3, sizeof(index_3)) != TPM_SUCCESS) { 91 TlclRead(INDEX3, (uint8_t*) &index_3, sizeof(index_3)) != TPM_SUCCESS) {
88 EnterRecoveryMode(); 92 EnterRecoveryMode();
89 } 93 }
90 94
95 /* Writes space, and locks it. Then attempts to write again. I really wish
96 * I could use the imperative.
97 */
98 index_0 += 1;
99 if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0) != TPM_SUCCESS)) {
100 error("could not write index 0\n");
101 }
102 TlclWriteLock(INDEX0);
103 if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) == TPM_SUCCESS) {
104 error("index 0 is not locked\n");
105 }
106
91 /* Done for now. 107 /* Done for now.
92 */ 108 */
109 printf("Test completed successfully\n");
93 exit(0); 110 exit(0);
94 } 111 }
95
OLDNEW
« no previous file with comments | « src/platform/tpm_lite/src/testsuite/Makefile ('k') | src/platform/tpm_lite/src/tlcl/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698