| 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 loading a kernel from disk. | 5 * Functions for loading a kernel from disk. |
| 6 * (Firmware portion) | 6 * (Firmware portion) |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "vboot_kernel.h" | 9 #include "vboot_kernel.h" |
| 10 | 10 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 int is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0); | 129 int is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0); |
| 130 int is_rec = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0); | 130 int is_rec = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0); |
| 131 int is_normal = (!is_dev && !is_rec); | 131 int is_normal = (!is_dev && !is_rec); |
| 132 uint32_t status; | 132 uint32_t status; |
| 133 | 133 |
| 134 /* Clear output params in case we fail */ | 134 /* Clear output params in case we fail */ |
| 135 params->partition_number = 0; | 135 params->partition_number = 0; |
| 136 params->bootloader_address = 0; | 136 params->bootloader_address = 0; |
| 137 params->bootloader_size = 0; | 137 params->bootloader_size = 0; |
| 138 | 138 |
| 139 /* Let the TPM know if we're in recovery mode */ | 139 if (!is_dev) { |
| 140 if (is_rec) { | 140 /* TODO: should use the TPM all the time; for now, only use when |
| 141 if (0 != RollbackKernelRecovery(is_dev ? 1 : 0)) { | 141 * not in developer mode. */ |
| 142 VBDEBUG(("Error setting up TPM for recovery kernel\n")); | 142 /* Let the TPM know if we're in recovery mode */ |
| 143 /* Ignore return code, since we need to boot recovery mode to | 143 if (is_rec) { |
| 144 * fix the TPM. */ | 144 if (0 != RollbackKernelRecovery(is_dev ? 1 : 0)) { |
| 145 VBDEBUG(("Error setting up TPM for recovery kernel\n")); |
| 146 /* Ignore return code, since we need to boot recovery mode to |
| 147 * fix the TPM. */ |
| 148 } |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 | 151 |
| 148 if (is_normal) { | 152 if (is_normal) { |
| 149 /* Read current kernel key index from TPM. Assumes TPM is already | 153 /* Read current kernel key index from TPM. Assumes TPM is already |
| 150 * initialized. */ | 154 * initialized. */ |
| 151 status = RollbackKernelRead(&tpm_key_version, &tpm_kernel_version); | 155 status = RollbackKernelRead(&tpm_key_version, &tpm_kernel_version); |
| 152 if (0 != status) { | 156 if (0 != status) { |
| 153 VBDEBUG(("Unable to get kernel versions from TPM\n")); | 157 VBDEBUG(("Unable to get kernel versions from TPM\n")); |
| 154 return (status == TPM_E_MUST_REBOOT ? | 158 return (status == TPM_E_MUST_REBOOT ? |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 status = RollbackKernelWrite((uint16_t)lowest_key_version, | 378 status = RollbackKernelWrite((uint16_t)lowest_key_version, |
| 375 (uint16_t)lowest_kernel_version); | 379 (uint16_t)lowest_kernel_version); |
| 376 if (0 != status) { | 380 if (0 != status) { |
| 377 VBDEBUG(("Error writing kernel versions to TPM.\n")); | 381 VBDEBUG(("Error writing kernel versions to TPM.\n")); |
| 378 return (status == TPM_E_MUST_REBOOT ? | 382 return (status == TPM_E_MUST_REBOOT ? |
| 379 LOAD_KERNEL_REBOOT : LOAD_KERNEL_RECOVERY); | 383 LOAD_KERNEL_REBOOT : LOAD_KERNEL_RECOVERY); |
| 380 } | 384 } |
| 381 } | 385 } |
| 382 } | 386 } |
| 383 | 387 |
| 384 /* Lock the kernel versions */ | 388 if (!is_dev) { |
| 385 status = RollbackKernelLock(); | 389 /* TODO: should use the TPM all the time; for now, only use when |
| 386 if (0 != status) { | 390 * not in developer mode. */ |
| 387 VBDEBUG(("Error locking kernel versions.\n")); | 391 /* Lock the kernel versions */ |
| 388 /* Don't reboot to recovery mode if we're already there */ | 392 status = RollbackKernelLock(); |
| 389 if (!is_rec) | 393 if (0 != status) { |
| 390 return (status == TPM_E_MUST_REBOOT ? | 394 VBDEBUG(("Error locking kernel versions.\n")); |
| 391 LOAD_KERNEL_REBOOT : LOAD_KERNEL_RECOVERY); | 395 /* Don't reboot to recovery mode if we're already there */ |
| 396 if (!is_rec) |
| 397 return (status == TPM_E_MUST_REBOOT ? |
| 398 LOAD_KERNEL_REBOOT : LOAD_KERNEL_RECOVERY); |
| 399 } |
| 392 } | 400 } |
| 393 | 401 |
| 394 /* Success! */ | 402 /* Success! */ |
| 395 return LOAD_KERNEL_SUCCESS; | 403 return LOAD_KERNEL_SUCCESS; |
| 396 } | 404 } |
| 397 | 405 |
| 398 // Handle error cases | 406 // Handle error cases |
| 399 if (found_partitions) | 407 if (found_partitions) |
| 400 return LOAD_KERNEL_INVALID; | 408 return LOAD_KERNEL_INVALID; |
| 401 else | 409 else |
| 402 return LOAD_KERNEL_NOT_FOUND; | 410 return LOAD_KERNEL_NOT_FOUND; |
| 403 } | 411 } |
| OLD | NEW |