| 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 * Temporary fix for running the TPM selftest and other essential | 5 * Temporary fix for running the TPM selftest and other essential |
| 6 * intializations that we forgot to put in the BIOS. | 6 * intializations that we forgot to put in the BIOS. |
| 7 * | 7 * |
| 8 * This works in a very specific situation: we assume TPM_Startup has been | 8 * This works in a very specific situation: we assume TPM_Startup has been |
| 9 * executed, but we don't know if the self test has run. On a ST TPM version | 9 * executed, but we don't know if the self test has run. On a ST TPM version |
| 10 * 1.2.7.0, GetCapabilities fails before the self test has run, so we use that | 10 * 1.2.7.0, GetCapabilities fails before the self test has run, so we use that |
| 11 * to check if we need to run it. | 11 * to check if we need to run it. |
| 12 * | 12 * |
| 13 * This also enables the TPM if it is disabled, and activates it if it is | 13 * This also enables the TPM if it is disabled, and activates it if it is |
| 14 * deactivated. | 14 * deactivated. |
| 15 * | 15 * |
| 16 * Exit status: 0 for normal, 1 for errors (see syslog), 2 for normal but needs | 16 * Exit status always 0. Prints "reboot" to request reboot, "fail" for errors, |
| 17 * reboot. | 17 * "success" when everything worked. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include <stdio.h> |
| 21 #include <syslog.h> |
| 22 |
| 20 #include "tlcl.h" | 23 #include "tlcl.h" |
| 21 | 24 |
| 22 #include <syslog.h> | |
| 23 | |
| 24 int main(int argc, char* argv[]) { | 25 int main(int argc, char* argv[]) { |
| 25 uint32_t result; | 26 uint32_t result; |
| 26 uint8_t disable, deactivated; | 27 uint8_t disable, deactivated; |
| 27 int pri = LOG_USER | LOG_ERR; | 28 int pri = LOG_USER | LOG_ERR; |
| 28 | 29 |
| 29 TlclLibInit(); | 30 TlclLibInit(); |
| 30 TlclStartup(); /* ignore result */ | 31 TlclStartup(); /* ignore result */ |
| 31 result = TlclGetFlags(NULL, NULL, NULL); | 32 result = TlclGetFlags(NULL, NULL, NULL); |
| 32 if (result != 0) { | 33 if (result != 0) { |
| 33 result = TlclSelfTestFull(); | 34 result = TlclSelfTestFull(); |
| 34 if (result != 0) { | 35 if (result != 0) { |
| 35 syslog(pri, "TPM selftest failed with code 0x%x\n", result); | 36 syslog(pri, "TPM selftest failed with code 0x%x\n", result); |
| 36 return 1; | 37 printf("fail\n"); |
| 38 return 0; |
| 37 } | 39 } |
| 38 } | 40 } |
| 39 /* Optional one-time enabling of TPM. */ | 41 /* Optional one-time enabling of TPM. */ |
| 40 result = TlclAssertPhysicalPresence(); | 42 result = TlclAssertPhysicalPresence(); |
| 41 if (result != 0) { | 43 if (result != 0) { |
| 42 syslog(pri, "TPM assertpp failed with code 0x%x\n", result); | 44 syslog(pri, "TPM assertpp failed with code 0x%x\n", result); |
| 43 return 1; | 45 printf("fail\n"); |
| 46 return 0; |
| 44 } | 47 } |
| 45 result = TlclGetFlags(&disable, &deactivated, NULL); | 48 result = TlclGetFlags(&disable, &deactivated, NULL); |
| 46 if (result != 0) { | 49 if (result != 0) { |
| 47 syslog(pri, "TPM getflags failed with code 0x%x\n", result); | 50 syslog(pri, "TPM getflags failed with code 0x%x\n", result); |
| 48 return 1; | 51 printf("fail\n"); |
| 52 return 0; |
| 49 } | 53 } |
| 50 if (disable) { | 54 if (disable) { |
| 51 result = TlclSetEnable(); | 55 result = TlclSetEnable(); |
| 52 if (result != 0) { | 56 if (result != 0) { |
| 53 syslog(pri, "TPM physical enable failed with code 0x%x\n", result); | 57 syslog(pri, "TPM physical enable failed with code 0x%x\n", result); |
| 54 return 1; | 58 printf("fail\n"); |
| 59 return 0; |
| 55 } | 60 } |
| 56 } | 61 } |
| 57 if (deactivated) { | 62 if (deactivated) { |
| 58 result = TlclSetDeactivated(0); | 63 result = TlclSetDeactivated(0); |
| 59 if (result != 0) { | 64 if (result != 0) { |
| 60 syslog(pri, "TPM physical activate failed with code 0x%x\n", result); | 65 syslog(pri, "TPM physical activate failed with code 0x%x\n", result); |
| 61 return 1; | 66 printf("fail\n"); |
| 67 } else { |
| 68 printf("reboot\n"); |
| 62 } | 69 } |
| 63 return 2; /* needs reboot */ | 70 return 0; /* needs reboot */ |
| 64 } | 71 } |
| 72 printf("success\n"); |
| 65 return 0; | 73 return 0; |
| 66 } | 74 } |
| OLD | NEW |