| 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 /* Test of recovery when we hit the NVRAM write limit for an unowned TPM. | 6 /* Test of recovery when we hit the NVRAM write limit for an unowned TPM. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 | 12 |
| 13 #include "tlcl.h" | 13 #include "tlcl.h" |
| 14 #include "tlcl_tests.h" |
| 14 #include "utility.h" | 15 #include "utility.h" |
| 15 | 16 |
| 16 #define INDEX0 0xda70 | |
| 17 #define TPM_MAX_NV_WRITES_NOOWNER 64 | 17 #define TPM_MAX_NV_WRITES_NOOWNER 64 |
| 18 | 18 |
| 19 int main(int argc, char** argv) { | 19 int main(int argc, char** argv) { |
| 20 int i; | 20 int i; |
| 21 |
| 21 uint32_t result; | 22 uint32_t result; |
| 22 uint8_t disable, deactivated; /* the TPM specs use these exact names */ | |
| 23 | 23 |
| 24 TlclLibInit(); | 24 TlclLibInit(); |
| 25 | 25 |
| 26 TlclStartup(); | 26 TPM_CHECK(TlclStartupIfNeeded()); |
| 27 TlclSelfTestFull(); | 27 TPM_CHECK(TlclSelfTestFull()); |
| 28 | 28 TPM_CHECK(TlclAssertPhysicalPresence()); |
| 29 TlclAssertPhysicalPresence(); | 29 TPM_CHECK(TlclForceClear()); |
| 30 | 30 TPM_CHECK(TlclSetEnable()); |
| 31 result = TlclGetFlags(&disable, &deactivated, NULL); | 31 TPM_CHECK(TlclSetDeactivated(0)); |
| 32 printf("disable is %d, deactivated is %d\n", disable, deactivated); | |
| 33 | |
| 34 if (disable || deactivated) { | |
| 35 TlclSetEnable(); | |
| 36 (void) TlclSetDeactivated(0); | |
| 37 printf("TPM will be active after next reboot\n"); | |
| 38 exit(0); | |
| 39 } | |
| 40 | 32 |
| 41 for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) { | 33 for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) { |
| 42 printf("writing %d\n", i); | 34 printf("writing %d\n", i); |
| 43 if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) { | 35 if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) { |
| 44 switch (result) { | 36 switch (result) { |
| 45 case TPM_E_MAXNVWRITES: | 37 case TPM_E_MAXNVWRITES: |
| 46 printf("Max NV writes exceeded - forcing clear\n"); | 38 assert(i >= TPM_MAX_NV_WRITES_NOOWNER); |
| 47 TlclForceClear(); | |
| 48 printf("Please reboot and run this program again\n"); | |
| 49 exit(0); | |
| 50 default: | 39 default: |
| 51 error("unexpected error code %d (0x%x)\n"); | 40 error("unexpected error code %d (0x%x)\n", result, result); |
| 52 } | 41 } |
| 53 } | 42 } |
| 54 } | 43 } |
| 55 | 44 |
| 56 /* Done for now. | 45 /* Reset write count */ |
| 57 */ | 46 TPM_CHECK(TlclForceClear()); |
| 58 printf("Test completed successfully\n"); | 47 TPM_CHECK(TlclSetEnable()); |
| 48 TPM_CHECK(TlclSetDeactivated(0)); |
| 49 |
| 50 /* Try writing again. */ |
| 51 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))); |
| 52 |
| 53 printf("TEST SUCCEEDED\n"); |
| 59 exit(0); | 54 exit(0); |
| 60 } | 55 } |
| OLD | NEW |