OLD | NEW |
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 Loading... |
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 uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE; |
39 | 39 |
40 printf("Initializing spaces\n"); | 40 printf("Initializing spaces\n"); |
41 TlclSetNvLocked(); /* useful only the first time */ | 41 TlclSetNvLocked(); /* useful only the first time */ |
42 | 42 |
43 TlclDefineSpace(INDEX0, perm, 4); | 43 TlclDefineSpace(INDEX0, perm, 4); |
44 TlclWrite(INDEX0, (uint8_t *) &zero, 4); | 44 TlclWrite(INDEX0, (uint8_t *) &zero, 4); |
45 TlclDefineSpace(INDEX1, perm, 4); | 45 TlclDefineSpace(INDEX1, perm, 4); |
46 TlclWrite(INDEX1, (uint8_t *) &zero, 4); | 46 TlclWrite(INDEX1, (uint8_t *) &zero, 4); |
47 TlclDefineSpace(INDEX2, perm, 4); | 47 TlclDefineSpace(INDEX2, perm, 4); |
48 TlclWrite(INDEX2, (uint8_t *) &zero, 4); | 48 TlclWrite(INDEX2, (uint8_t *) &zero, 4); |
(...skipping 11 matching lines...) Expand all Loading... |
60 exit(0); | 60 exit(0); |
61 } | 61 } |
62 | 62 |
63 | 63 |
64 int main(void) { | 64 int main(void) { |
65 uint8_t c; | 65 uint8_t c; |
66 uint32_t index_0, index_1, index_2, index_3; | 66 uint32_t index_0, index_1, index_2, index_3; |
67 | 67 |
68 TlclLibinit(); | 68 TlclLibinit(); |
69 | 69 |
70 #if 0 | |
71 TlclStartup(); | 70 TlclStartup(); |
72 TlclSelftestfull(); | 71 TlclSelftestfull(); |
73 #endif | |
74 | 72 |
75 TlclAssertPhysicalPresence(); | 73 TlclAssertPhysicalPresence(); |
76 | 74 |
77 /* Checks if initialization has completed by trying to read-lock a space | 75 /* Checks if initialization has completed by trying to read-lock a space |
78 * that's created at the end of initialization. | 76 * that's created at the end of initialization. |
79 */ | 77 */ |
80 if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) { | 78 if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) { |
81 /* The initialization did not complete. | 79 /* The initialization did not complete. |
82 */ | 80 */ |
83 InitializeSpaces(); | 81 InitializeSpaces(); |
(...skipping 18 matching lines...) Expand all Loading... |
102 TlclWriteLock(INDEX0); | 100 TlclWriteLock(INDEX0); |
103 if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) == TPM_SUCCESS) { | 101 if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) == TPM_SUCCESS) { |
104 error("index 0 is not locked\n"); | 102 error("index 0 is not locked\n"); |
105 } | 103 } |
106 | 104 |
107 /* Done for now. | 105 /* Done for now. |
108 */ | 106 */ |
109 printf("Test completed successfully\n"); | 107 printf("Test completed successfully\n"); |
110 exit(0); | 108 exit(0); |
111 } | 109 } |
OLD | NEW |