| 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 * Functions for querying, manipulating and locking rollback indices | 5 * Functions for querying, manipulating and locking rollback indices |
| 6 * stored in the TPM NVRAM. | 6 * stored in the TPM NVRAM. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "rollback_index.h" | 9 #include "rollback_index.h" |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 #include <stdio.h> | |
| 13 #include <tss/tcs.h> | 12 #include <tss/tcs.h> |
| 14 | 13 |
| 14 #include "utility.h" |
| 15 #include "tlcl.h" | 15 #include "tlcl.h" |
| 16 | 16 |
| 17 uint16_t g_firmware_key_version = 0; | 17 uint16_t g_firmware_key_version = 0; |
| 18 uint16_t g_firmware_version = 0; | 18 uint16_t g_firmware_version = 0; |
| 19 uint16_t g_kernel_key_version = 0; | 19 uint16_t g_kernel_key_version = 0; |
| 20 uint16_t g_kernel_version = 0; | 20 uint16_t g_kernel_version = 0; |
| 21 | 21 |
| 22 static void InitializeSpaces(void) { | 22 static void InitializeSpaces(void) { |
| 23 uint16_t zero = 0; | 23 uint16_t zero = 0; |
| 24 uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE; | 24 uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE; |
| 25 | 25 |
| 26 fprintf(stderr, "Initializing spaces\n"); | 26 debug("Initializing spaces\n"); |
| 27 TlclSetNvLocked(); /* useful only the first time */ | 27 TlclSetNvLocked(); /* useful only the first time */ |
| 28 | 28 |
| 29 TlclDefineSpace(FIRMWARE_KEY_VERSION_NV_INDEX, perm, sizeof(uint16_t)); | 29 TlclDefineSpace(FIRMWARE_KEY_VERSION_NV_INDEX, perm, sizeof(uint16_t)); |
| 30 TlclWrite(FIRMWARE_KEY_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); | 30 TlclWrite(FIRMWARE_KEY_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); |
| 31 | 31 |
| 32 TlclDefineSpace(FIRMWARE_VERSION_NV_INDEX, perm, sizeof(uint16_t)); | 32 TlclDefineSpace(FIRMWARE_VERSION_NV_INDEX, perm, sizeof(uint16_t)); |
| 33 TlclWrite(FIRMWARE_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); | 33 TlclWrite(FIRMWARE_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); |
| 34 | 34 |
| 35 TlclDefineSpace(KERNEL_KEY_VERSION_NV_INDEX, perm, sizeof(uint16_t)); | 35 TlclDefineSpace(KERNEL_KEY_VERSION_NV_INDEX, perm, sizeof(uint16_t)); |
| 36 TlclWrite(KERNEL_KEY_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); | 36 TlclWrite(KERNEL_KEY_VERSION_NV_INDEX, (uint8_t*) &zero, sizeof(uint16_t)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 /* TODO(gauravsh): The call to self test should probably be deferred. | 71 /* TODO(gauravsh): The call to self test should probably be deferred. |
| 72 * As per semenzato@chromium.org - | 72 * As per semenzato@chromium.org - |
| 73 * TlclStartup should be called before the firmware initializes the memory | 73 * TlclStartup should be called before the firmware initializes the memory |
| 74 * controller, so the selftest can run in parallel with that. Here we should | 74 * controller, so the selftest can run in parallel with that. Here we should |
| 75 * just call TlclSelftestFull to make sure the self test has | 75 * just call TlclSelftestFull to make sure the self test has |
| 76 * completed---unless we want to rely on the NVRAM operations being available | 76 * completed---unless we want to rely on the NVRAM operations being available |
| 77 * before the selftest completes. */ | 77 * before the selftest completes. */ |
| 78 TlclSelftestfull(); | 78 TlclSelftestfull(); |
| 79 TlclAssertPhysicalPresence(); | 79 TlclAssertPhysicalPresence(); |
| 80 if (!GetTPMRollbackIndices()) { | 80 if (!GetTPMRollbackIndices()) { |
| 81 fprintf(stderr, "Ho Ho Ho! We must jump to recovery."); | 81 debug("Ho Ho Ho! We must jump to recovery."); |
| 82 EnterRecovery(); | 82 EnterRecovery(); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 uint16_t GetStoredVersion(int type) { | 87 uint16_t GetStoredVersion(int type) { |
| 88 switch (type) { | 88 switch (type) { |
| 89 case FIRMWARE_KEY_VERSION: | 89 case FIRMWARE_KEY_VERSION: |
| 90 return g_firmware_key_version; | 90 return g_firmware_key_version; |
| 91 break; | 91 break; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 TlclWriteLock(FIRMWARE_VERSION_NV_INDEX); | 140 TlclWriteLock(FIRMWARE_VERSION_NV_INDEX); |
| 141 break; | 141 break; |
| 142 case KERNEL_KEY_VERSION: | 142 case KERNEL_KEY_VERSION: |
| 143 TlclWriteLock(KERNEL_KEY_VERSION_NV_INDEX); | 143 TlclWriteLock(KERNEL_KEY_VERSION_NV_INDEX); |
| 144 break; | 144 break; |
| 145 case KERNEL_VERSION: | 145 case KERNEL_VERSION: |
| 146 TlclWriteLock(KERNEL_VERSION_NV_INDEX); | 146 TlclWriteLock(KERNEL_VERSION_NV_INDEX); |
| 147 break; | 147 break; |
| 148 } | 148 } |
| 149 } | 149 } |
| OLD | NEW |