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 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 uint64_t blba; | 128 uint64_t blba; |
129 uint64_t kbuf_sectors; | 129 uint64_t kbuf_sectors; |
130 uint8_t* kbuf = NULL; | 130 uint8_t* kbuf = NULL; |
131 int found_partitions = 0; | 131 int found_partitions = 0; |
132 int good_partition = -1; | 132 int good_partition = -1; |
133 int good_partition_key_block_valid = 0; | 133 int good_partition_key_block_valid = 0; |
134 uint32_t tpm_version = 0; | 134 uint32_t tpm_version = 0; |
135 uint64_t lowest_version = 0xFFFFFFFF; | 135 uint64_t lowest_version = 0xFFFFFFFF; |
136 int rec_switch, dev_switch; | 136 int rec_switch, dev_switch; |
137 BootMode boot_mode; | 137 BootMode boot_mode; |
| 138 uint32_t test_err = 0; |
138 uint32_t status; | 139 uint32_t status; |
139 | 140 |
140 /* TODO: differentiate between finding an invalid kernel (found_partitions>0) | 141 /* TODO: differentiate between finding an invalid kernel (found_partitions>0) |
141 * and not finding one at all. Right now we treat them the same, and return | 142 * and not finding one at all. Right now we treat them the same, and return |
142 * LOAD_KERNEL_INVALID for both. */ | 143 * LOAD_KERNEL_INVALID for both. */ |
143 int retval = LOAD_KERNEL_INVALID; | 144 int retval = LOAD_KERNEL_INVALID; |
144 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; | 145 int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; |
145 | 146 |
146 /* Setup NV storage */ | 147 /* Setup NV storage */ |
147 VbNvSetup(vnc); | 148 VbNvSetup(vnc); |
148 | 149 |
149 /* Sanity Checks */ | 150 /* Sanity Checks */ |
150 if (!params || | 151 if (!params || |
151 !params->bytes_per_lba || | 152 !params->bytes_per_lba || |
152 !params->ending_lba || | 153 !params->ending_lba || |
153 !params->kernel_buffer || | 154 !params->kernel_buffer || |
154 !params->kernel_buffer_size) { | 155 !params->kernel_buffer_size) { |
155 VBDEBUG(("LoadKernel() called with invalid params\n")); | 156 VBDEBUG(("LoadKernel() called with invalid params\n")); |
156 goto LoadKernelExit; | 157 goto LoadKernelExit; |
157 } | 158 } |
158 | 159 |
| 160 /* Handle test errors */ |
| 161 VbNvGet(vnc, VBNV_TEST_ERROR_FUNC, &test_err); |
| 162 if (VBNV_TEST_ERROR_LOAD_KERNEL == test_err) { |
| 163 /* Get error code */ |
| 164 VbNvGet(vnc, VBNV_TEST_ERROR_NUM, &test_err); |
| 165 /* Clear test params so we don't repeat the error */ |
| 166 VbNvSet(vnc, VBNV_TEST_ERROR_FUNC, 0); |
| 167 VbNvSet(vnc, VBNV_TEST_ERROR_NUM, 0); |
| 168 /* Handle error codes */ |
| 169 switch (test_err) { |
| 170 case LOAD_KERNEL_RECOVERY: |
| 171 recovery = VBNV_RECOVERY_RW_TEST_LK; |
| 172 goto LoadKernelExit; |
| 173 case LOAD_KERNEL_NOT_FOUND: |
| 174 case LOAD_KERNEL_INVALID: |
| 175 case LOAD_KERNEL_REBOOT: |
| 176 retval = test_err; |
| 177 goto LoadKernelExit; |
| 178 default: |
| 179 break; |
| 180 } |
| 181 } |
| 182 |
159 /* Initialization */ | 183 /* Initialization */ |
160 blba = params->bytes_per_lba; | 184 blba = params->bytes_per_lba; |
161 kbuf_sectors = KBUF_SIZE / blba; | 185 kbuf_sectors = KBUF_SIZE / blba; |
162 if (0 == kbuf_sectors) { | 186 if (0 == kbuf_sectors) { |
163 VBDEBUG(("LoadKernel() called with sector size > KBUF_SIZE\n")); | 187 VBDEBUG(("LoadKernel() called with sector size > KBUF_SIZE\n")); |
164 goto LoadKernelExit; | 188 goto LoadKernelExit; |
165 } | 189 } |
166 | 190 |
167 rec_switch = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0); | 191 rec_switch = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0); |
168 dev_switch = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0); | 192 dev_switch = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 VbNvSet(vnc, VBNV_RECOVERY_REQUEST, LOAD_KERNEL_RECOVERY == retval ? | 546 VbNvSet(vnc, VBNV_RECOVERY_REQUEST, LOAD_KERNEL_RECOVERY == retval ? |
523 recovery : VBNV_RECOVERY_NOT_REQUESTED); | 547 recovery : VBNV_RECOVERY_NOT_REQUESTED); |
524 VbNvTeardown(vnc); | 548 VbNvTeardown(vnc); |
525 | 549 |
526 /* Store how much shared data we used, if any */ | 550 /* Store how much shared data we used, if any */ |
527 if (shared) | 551 if (shared) |
528 params->shared_data_size = shared->data_used; | 552 params->shared_data_size = shared->data_used; |
529 | 553 |
530 return retval; | 554 return retval; |
531 } | 555 } |
OLD | NEW |