OLD | NEW |
1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 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 |
11 #include "boot_device.h" | 11 #include "boot_device.h" |
12 #include "cgptlib.h" | 12 #include "cgptlib.h" |
13 #include "cgptlib_internal.h" | 13 #include "cgptlib_internal.h" |
14 #include "gbb_header.h" | 14 #include "gbb_header.h" |
15 #include "load_kernel_fw.h" | 15 #include "load_kernel_fw.h" |
16 #include "rollback_index.h" | 16 #include "rollback_index.h" |
17 #include "utility.h" | 17 #include "utility.h" |
18 #include "vboot_common.h" | 18 #include "vboot_common.h" |
19 | 19 |
20 #define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */ | 20 #define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */ |
| 21 #define LOWEST_TPM_VERSION 0xffffffff |
21 | 22 |
22 typedef enum BootMode { | 23 typedef enum BootMode { |
23 kBootNormal, /* Normal firmware */ | 24 kBootNormal, /* Normal firmware */ |
24 kBootDev, /* Dev firmware AND dev switch is on */ | 25 kBootDev, /* Dev firmware AND dev switch is on */ |
25 kBootRecovery /* Recovery firmware, regardless of dev switch position */ | 26 kBootRecovery /* Recovery firmware, regardless of dev switch position */ |
26 } BootMode; | 27 } BootMode; |
27 | 28 |
28 | 29 |
29 /* Allocates and reads GPT data from the drive. The sector_bytes and | 30 /* Allocates and reads GPT data from the drive. The sector_bytes and |
30 * drive_sectors fields should be filled on input. The primary and | 31 * drive_sectors fields should be filled on input. The primary and |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 VbPublicKey* kernel_subkey; | 126 VbPublicKey* kernel_subkey; |
126 GptData gpt; | 127 GptData gpt; |
127 uint64_t part_start, part_size; | 128 uint64_t part_start, part_size; |
128 uint64_t blba; | 129 uint64_t blba; |
129 uint64_t kbuf_sectors; | 130 uint64_t kbuf_sectors; |
130 uint8_t* kbuf = NULL; | 131 uint8_t* kbuf = NULL; |
131 int found_partitions = 0; | 132 int found_partitions = 0; |
132 int good_partition = -1; | 133 int good_partition = -1; |
133 int good_partition_key_block_valid = 0; | 134 int good_partition_key_block_valid = 0; |
134 uint32_t tpm_version = 0; | 135 uint32_t tpm_version = 0; |
135 uint64_t lowest_version = 0xFFFFFFFF; | 136 uint64_t lowest_version = LOWEST_TPM_VERSION; |
136 int rec_switch, dev_switch; | 137 int rec_switch, dev_switch; |
137 BootMode boot_mode; | 138 BootMode boot_mode; |
138 uint32_t test_err = 0; | 139 uint32_t test_err = 0; |
139 uint32_t status; | 140 uint32_t status; |
140 | 141 |
141 /* TODO: differentiate between finding an invalid kernel (found_partitions>0) | 142 /* TODO: differentiate between finding an invalid kernel (found_partitions>0) |
142 * and not finding one at all. Right now we treat them the same, and return | 143 * and not finding one at all. Right now we treat them the same, and return |
143 * LOAD_KERNEL_INVALID for both. */ | 144 * LOAD_KERNEL_INVALID for both. */ |
144 int retval = LOAD_KERNEL_INVALID; | 145 int retval = LOAD_KERNEL_INVALID; |
145 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; | 146 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (kBootDev != boot_mode) | 374 if (kBootDev != boot_mode) |
374 goto bad_kernel; | 375 goto bad_kernel; |
375 } | 376 } |
376 } | 377 } |
377 | 378 |
378 VBDEBUG(("Kernel preamble is good.\n")); | 379 VBDEBUG(("Kernel preamble is good.\n")); |
379 | 380 |
380 /* Check for lowest version from a valid header. */ | 381 /* Check for lowest version from a valid header. */ |
381 if (key_block_valid && lowest_version > combined_version) | 382 if (key_block_valid && lowest_version > combined_version) |
382 lowest_version = combined_version; | 383 lowest_version = combined_version; |
| 384 else { |
| 385 VBDEBUG(("Key block valid: %d\n", key_block_valid)); |
| 386 VBDEBUG(("Combined version: %" PRIu64 "\n", combined_version)); |
| 387 } |
383 | 388 |
384 /* If we already have a good kernel, no need to read another | 389 /* If we already have a good kernel, no need to read another |
385 * one; we only needed to look at the versions to check for | 390 * one; we only needed to look at the versions to check for |
386 * rollback. So skip to the next kernel preamble. */ | 391 * rollback. So skip to the next kernel preamble. */ |
387 if (-1 != good_partition) | 392 if (-1 != good_partition) |
388 continue; | 393 continue; |
389 | 394 |
390 /* Verify body load address matches what we expect */ | 395 /* Verify body load address matches what we expect */ |
391 if ((preamble->body_load_address != (size_t)params->kernel_buffer) && | 396 if ((preamble->body_load_address != (size_t)params->kernel_buffer) && |
392 !(params->boot_flags & BOOT_FLAG_SKIP_ADDR_CHECK)) { | 397 !(params->boot_flags & BOOT_FLAG_SKIP_ADDR_CHECK)) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 VBDEBUG(("Good_partition >= 0\n")); | 504 VBDEBUG(("Good_partition >= 0\n")); |
500 | 505 |
501 /* See if we need to update the TPM */ | 506 /* See if we need to update the TPM */ |
502 if (kBootRecovery != boot_mode && good_partition_key_block_valid) { | 507 if (kBootRecovery != boot_mode && good_partition_key_block_valid) { |
503 /* We only update the TPM in normal and developer boot modes. In | 508 /* We only update the TPM in normal and developer boot modes. In |
504 * developer mode, we only advanced lowest_version for kernels with valid | 509 * developer mode, we only advanced lowest_version for kernels with valid |
505 * key blocks, and didn't count self-signed key blocks. In recovery | 510 * key blocks, and didn't count self-signed key blocks. In recovery |
506 * mode, the TPM stays PP-unlocked, so anything we write gets blown away | 511 * mode, the TPM stays PP-unlocked, so anything we write gets blown away |
507 * by the firmware when we go back to normal mode. */ | 512 * by the firmware when we go back to normal mode. */ |
508 VBDEBUG(("Boot_flags = not recovery\n")); | 513 VBDEBUG(("Boot_flags = not recovery\n")); |
509 if (lowest_version > tpm_version) { | 514 |
| 515 if ((lowest_version > tpm_version) && |
| 516 (lowest_version != LOWEST_TPM_VERSION)) { |
510 status = RollbackKernelWrite((uint32_t)lowest_version); | 517 status = RollbackKernelWrite((uint32_t)lowest_version); |
511 if (0 != status) { | 518 if (0 != status) { |
512 VBDEBUG(("Error writing kernel versions to TPM.\n")); | 519 VBDEBUG(("Error writing kernel versions to TPM.\n")); |
513 if (status == TPM_E_MUST_REBOOT) | 520 if (status == TPM_E_MUST_REBOOT) |
514 retval = LOAD_KERNEL_REBOOT; | 521 retval = LOAD_KERNEL_REBOOT; |
515 else | 522 else |
516 recovery = VBNV_RECOVERY_RW_TPM_ERROR; | 523 recovery = VBNV_RECOVERY_RW_TPM_ERROR; |
517 goto LoadKernelExit; | 524 goto LoadKernelExit; |
518 } | 525 } |
519 } | 526 } |
(...skipping 26 matching lines...) Expand all Loading... |
546 VbNvSet(vnc, VBNV_RECOVERY_REQUEST, LOAD_KERNEL_RECOVERY == retval ? | 553 VbNvSet(vnc, VBNV_RECOVERY_REQUEST, LOAD_KERNEL_RECOVERY == retval ? |
547 recovery : VBNV_RECOVERY_NOT_REQUESTED); | 554 recovery : VBNV_RECOVERY_NOT_REQUESTED); |
548 VbNvTeardown(vnc); | 555 VbNvTeardown(vnc); |
549 | 556 |
550 /* Store how much shared data we used, if any */ | 557 /* Store how much shared data we used, if any */ |
551 if (shared) | 558 if (shared) |
552 params->shared_data_size = shared->data_used; | 559 params->shared_data_size = shared->data_used; |
553 | 560 |
554 return retval; | 561 return retval; |
555 } | 562 } |
OLD | NEW |