blob: 738c47691f8684ea11827b2fba0243e914bfcaaf [file] [log] [blame]
Randall Spangler1b1998d2011-07-01 16:12:47 -07001/* 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
3 * found in the LICENSE file.
4 *
5 * High-level firmware wrapper API - entry points for kernel selection
6 */
7
8#include "gbb_header.h"
9#include "load_kernel_fw.h"
10#include "utility.h"
11#include "vboot_api.h"
12#include "vboot_common.h"
13#include "vboot_nvstorage.h"
14
15
16/* Global variables */
17static uint32_t disp_current_screen = VB_SCREEN_BLANK;
18static uint32_t disp_width = 0, disp_height = 0;
19static VbNvContext vnc;
20
21
22#ifdef CHROMEOS_ENVIRONMENT
23/* Global variable accessors for unit tests */
24VbNvContext* VbApiKernelGetVnc(void) {
25 return &vnc;
26}
27#endif
28
29
30/* Set recovery request */
31static void VbSetRecoveryRequest(uint32_t recovery_request) {
32 VBDEBUG(("VbSetRecoveryRequest(%d)\n", (int)recovery_request));
33
34 VbNvSetup(&vnc);
35 VbNvSet(&vnc, VBNV_RECOVERY_REQUEST, recovery_request);
36 VbNvTeardown(&vnc);
37 if (vnc.raw_changed)
38 VbExNvStorageWrite(vnc.raw);
39}
40
41
42/* Get the number of localizations in the GBB bitmap data. */
43static VbError_t VbGetLocalizationCount(VbCommonParams* cparams,
44 uint32_t* count) {
45 GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data;
46 BmpBlockHeader* hdr;
47
48 /* Default to 0 on error */
49 *count = 0;
50
51 /* Make sure the bitmap data is inside the GBB and is non-zero in size */
52 if (0 == gbb->bmpfv_size ||
53 gbb->bmpfv_offset > cparams->gbb_size ||
54 gbb->bmpfv_offset + gbb->bmpfv_size > cparams->gbb_size) {
55 return 1;
56 }
57
58 /* Sanity-check the bitmap block header */
59 hdr = (BmpBlockHeader *)(((uint8_t*)gbb) + gbb->bmpfv_offset);
60 if ((0 != Memcmp(hdr->signature, BMPBLOCK_SIGNATURE,
61 BMPBLOCK_SIGNATURE_SIZE)) ||
62 (hdr->major_version > BMPBLOCK_MAJOR_VERSION) ||
63 ((hdr->major_version == BMPBLOCK_MAJOR_VERSION) &&
64 (hdr->minor_version > BMPBLOCK_MINOR_VERSION))) {
65 return 1;
66 }
67
68 *count = hdr->number_of_localizations;
69 return VBERROR_SUCCESS;
70}
71
72
73/* Display a screen from the GBB. */
74static VbError_t VbDisplayScreenFromGBB(VbCommonParams* cparams,
75 uint32_t screen) {
76 GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data;
77 uint8_t* bmpfv = NULL;
78 BmpBlockHeader* hdr;
79 ScreenLayout* layout;
80 ImageInfo* image_info;
81 uint32_t screen_index;
82 uint32_t localization = 0;
83 VbError_t retval = 1; /* Assume error until proven successful */
84 uint32_t offset;
85 uint32_t i;
86
87 /* Make sure the bitmap data is inside the GBB and is non-zero in size */
88 if (0 == gbb->bmpfv_size ||
89 gbb->bmpfv_offset > cparams->gbb_size ||
90 gbb->bmpfv_offset + gbb->bmpfv_size > cparams->gbb_size) {
91 VBDEBUG(("VbDisplayScreenFromGBB(): invalid bmpfv offset/size\n"));
92 return 1;
93 }
94
95 /* Copy bitmap data from GBB into RAM for speed */
96 bmpfv = (uint8_t*)VbExMalloc(gbb->bmpfv_size);
97 Memcpy(bmpfv, ((uint8_t*)gbb) + gbb->bmpfv_offset, gbb->bmpfv_size);
98
99 /* Sanity-check the bitmap block header */
100 hdr = (BmpBlockHeader *)bmpfv;
101 if ((0 != Memcmp(hdr->signature, BMPBLOCK_SIGNATURE,
102 BMPBLOCK_SIGNATURE_SIZE)) ||
103 (hdr->major_version > BMPBLOCK_MAJOR_VERSION) ||
104 ((hdr->major_version == BMPBLOCK_MAJOR_VERSION) &&
105 (hdr->minor_version > BMPBLOCK_MINOR_VERSION))) {
106 VBDEBUG(("VbDisplayScreenFromGBB(): invalid/too new bitmap header\n"));
107 goto VbDisplayScreenFromGBB_exit;
108 }
109
110 /* Translate screen ID into index. Note that not all screens are in the
111 * GBB. */
112 /* TODO: ensure screen IDs match indices? Having this translation
113 * here is awful. */
114 switch (screen) {
115 case VB_SCREEN_DEVELOPER_WARNING:
116 screen_index = 0;
117 break;
118 case VB_SCREEN_RECOVERY_REMOVE:
119 screen_index = 1;
120 break;
121 case VB_SCREEN_RECOVERY_NO_GOOD:
122 screen_index = 2;
123 break;
124 case VB_SCREEN_RECOVERY_INSERT:
125 screen_index = 3;
126 break;
127 case VB_SCREEN_BLANK:
128 case VB_SCREEN_DEVELOPER_EGG:
129 default:
130 /* Screens which aren't in the GBB */
131 VBDEBUG(("VbDisplayScreenFromGBB(): screen %d not in the GBB\n",
132 (int)screen));
133 goto VbDisplayScreenFromGBB_exit;
134 }
135 if (screen_index >= hdr->number_of_screenlayouts) {
136 VBDEBUG(("VbDisplayScreenFromGBB(): screen %d index %d not in the GBB\n",
137 (int)screen, (int)screen_index));
138 goto VbDisplayScreenFromGBB_exit;
139 }
140
141 /* Clip localization to the number of localizations present in the GBB */
142 VbNvSetup(&vnc);
143 VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &localization);
144 if (localization >= hdr->number_of_localizations) {
145 localization = 0;
146 VbNvSet(&vnc, VBNV_LOCALIZATION_INDEX, localization);
147 }
148 VbNvTeardown(&vnc);
149 if (vnc.raw_changed)
150 VbExNvStorageWrite(vnc.raw);
151
152 /* Calculate offset of screen layout = start of screen stuff +
153 * correct locale + correct screen. */
154 offset = sizeof(BmpBlockHeader) +
155 localization * hdr->number_of_screenlayouts * sizeof(ScreenLayout) +
156 screen_index * sizeof(ScreenLayout);
157 VBDEBUG(("VbDisplayScreenFromGBB(): scr_%d_%d at offset 0x%x\n",
158 localization, screen_index, offset));
159 layout = (ScreenLayout*)(bmpfv + offset);
160
161 /* Display all bitmaps for the image */
162 for (i = 0; i < MAX_IMAGE_IN_LAYOUT; i++) {
163 if (layout->images[i].image_info_offset) {
164 offset = layout->images[i].image_info_offset;
165 image_info = (ImageInfo*)(bmpfv + offset);
166 VBDEBUG(("VbDisplayScreenFromGBB: image %d: %dx%d+%d+%d %d/%d"
167 "tag %d at 0x%x\n",
168 i, image_info->width, image_info->height,
169 layout->images[i].x, layout->images[i].y,
170 image_info->compressed_size, image_info->original_size,
171 image_info->tag, offset));
172
173 retval = VbExDisplayImage(layout->images[i].x, layout->images[i].y,
174 image_info, bmpfv + offset + sizeof(ImageInfo));
175 if (VBERROR_SUCCESS != retval)
176 goto VbDisplayScreenFromGBB_exit;
177 }
178 }
179
180 /* Successful if all bitmaps displayed */
181 retval = VBERROR_SUCCESS;
182
183VbDisplayScreenFromGBB_exit:
184
185 /* Free the bitmap data copy */
186 VbExFree(bmpfv);
187 return retval;
188}
189
190
191/* Display a screen, initializing the display if necessary. If force!=0,
192 * redisplays the screen even if it's the same as the current screen. */
193static VbError_t VbDisplayScreen(VbCommonParams* cparams, uint32_t screen,
194 int force) {
195
196 VBDEBUG(("VbDisplayScreen(%d, %d)\n", (int)screen, force));
197
198 /* Initialize display if necessary */
199 if (!disp_width) {
200 if (VBERROR_SUCCESS != VbExDisplayInit(&disp_width, &disp_height))
201 return 1;
202 }
203
204 /* If the requested screen is the same as the current one, we're done. */
205 if (disp_current_screen == screen && 0 == force)
206 return VBERROR_SUCCESS;
207
208 /* If the screen is blank, turn off the backlight; else turn it on. */
209 VbExDisplayBacklight(VB_SCREEN_BLANK == screen ? 0 : 1);
210
211 /* Request the screen */
212 disp_current_screen = screen;
213
214 /* Look in the GBB first */
215 if (VBERROR_SUCCESS == VbDisplayScreenFromGBB(cparams, screen))
216 return VBERROR_SUCCESS;
217
218 /* If the screen wasn't in the GBB bitmaps, fall back to a default screen. */
219 return VbExDisplayScreen(screen);
220}
221
Randall Spangler96191122011-07-08 14:01:54 -0700222#define DEBUG_INFO_SIZE 512
Randall Spangler1b1998d2011-07-01 16:12:47 -0700223
224static VbError_t VbCheckDisplayKey(VbCommonParams* cparams, uint32_t key) {
Randall Spangler96191122011-07-08 14:01:54 -0700225 VbSharedDataHeader* shared = (VbSharedDataHeader*)cparams->shared_data_blob;
226 GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data;
Randall Spangler1b1998d2011-07-01 16:12:47 -0700227
228 if ('\t' == key) {
229 /* Tab = display debug info */
Randall Spangler96191122011-07-08 14:01:54 -0700230 char buf[DEBUG_INFO_SIZE] = "";
231 uint32_t used = 0;
232 uint32_t i;
Randall Spangler1b1998d2011-07-01 16:12:47 -0700233
234 /* Redisplay the current screen, to overwrite any previous debug output */
235 VbDisplayScreen(cparams, disp_current_screen, 1);
236
Randall Spangler96191122011-07-08 14:01:54 -0700237 /* Add hardware ID */
238 used += Strncat(buf + used, "HWID: ", DEBUG_INFO_SIZE - used);
239 if (0 == gbb->hwid_size ||
240 gbb->hwid_offset > cparams->gbb_size ||
241 gbb->hwid_offset + gbb->hwid_size > cparams->gbb_size) {
242 VBDEBUG(("VbCheckDisplayKey(): invalid hwid offset/size\n"));
243 used += Strncat(buf + used, "(INVALID)", DEBUG_INFO_SIZE - used);
244 } else {
245 used += Strncat(buf + used, (char*)((uint8_t*)gbb + gbb->hwid_offset),
246 DEBUG_INFO_SIZE - used);
247 }
248
249 /* Add recovery request */
250 used += Strncat(buf + used, "\nrecovery_request: 0x",
251 DEBUG_INFO_SIZE - used);
252 used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
253 shared->recovery_reason, 16, 2);
254
255 /* Add VbSharedData flags */
256 used += Strncat(buf + used, "\nVbSD.flags: 0x", DEBUG_INFO_SIZE - used);
257 used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
258 shared->flags, 16, 8);
259
260 /* Add raw contents of VbNvStorage */
261 used += Strncat(buf + used, "\nVbNv.raw:", DEBUG_INFO_SIZE - used);
262 for (i = 0; i < VBNV_BLOCK_SIZE; i++) {
263 used += Strncat(buf + used, " ", DEBUG_INFO_SIZE - used);
264 used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
265 vnc.raw[i], 16, 2);
266 }
267
268 used += Strncat(buf + used, "\n", DEBUG_INFO_SIZE - used);
269
270 /* TODO: add more interesting data:
271 * - TPM firmware and kernel versions. In the current code, they're
272 * only filled into VbSharedData by LoadFirmware() and LoadKernel(), and
273 * since neither of those is called in the recovery path this isn't
274 * feasible yet.
275 * - SHA1 of kernel subkey (assuming we always set it in VbSelectFirmware,
276 * even in recovery mode, where we just copy it from the root key)
Randall Spangler1b1998d2011-07-01 16:12:47 -0700277 * - Information on current disks
Randall Spangler96191122011-07-08 14:01:54 -0700278 * - Anything else interesting from VbNvStorage */
279
280 buf[DEBUG_INFO_SIZE - 1] = '\0';
281 VBDEBUG(("VbCheckDisplayKey() wants to show '%s'\n", buf));
282 return VbExDisplayDebugInfo(buf);
Randall Spangler1b1998d2011-07-01 16:12:47 -0700283
284 } else if (VB_KEY_LEFT == key || VB_KEY_RIGHT == key) {
285 /* Arrow keys = change localization */
286 uint32_t loc = 0;
287 uint32_t count = 0;
288
289 /* Get localization count */
290 VbGetLocalizationCount(cparams, &count);
291
292 /* Change localization */
293 VbNvSetup(&vnc);
294 VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &loc);
295 if (VB_KEY_RIGHT == key)
296 loc = (loc < count - 1 ? loc + 1 : 0);
297 else
298 loc = (loc > 0 ? loc - 1 : count - 1);
299 VBDEBUG(("VbCheckDisplayKey() - change localization to %d\n", (int)loc));
300 VbNvSet(&vnc, VBNV_LOCALIZATION_INDEX, loc);
301 VbNvTeardown(&vnc);
302 if (vnc.raw_changed)
303 VbExNvStorageWrite(vnc.raw);
304
305 /* Force redraw of current screen */
306 return VbDisplayScreen(cparams, disp_current_screen, 1);
307 }
308
309 return VBERROR_SUCCESS;
310}
311
312
313/* Return codes fof VbTryLoadKernel, in addition to VBERROR_SUCCESS */
314enum VbTryLoadKernelError_t {
315 /* No disks found */
316 VBERROR_TRY_LOAD_NO_DISKS = 1,
317 /* Need to reboot to same mode/recovery reason as this boot */
318 VBERROR_TRY_LOAD_REBOOT = 2,
319 /* Some other error; go to recovery mode if this was the only hope to boot */
320 VBERROR_TRY_LOAD_RECOVERY = 3,
321};
322
323
324/* Attempt loading a kernel from the specified type(s) of disks. If
325 * successful, sets p->disk_handle to the disk for the kernel. See
326 * VBERROR_TRY_LOAD_* for additional return codes. */
327uint32_t VbTryLoadKernel(VbCommonParams* cparams, LoadKernelParams* p,
328 uint32_t get_info_flags) {
329 VbSharedDataHeader* shared = (VbSharedDataHeader*)cparams->shared_data_blob;
330 int retval = VBERROR_TRY_LOAD_NO_DISKS;
331 VbDiskInfo* disk_info = NULL;
332 uint32_t disk_count = 0;
333 uint32_t i;
334
335 VBDEBUG(("VbTryLoadKernel() start, get_info_flags=0x%x\n",
336 (int)get_info_flags));
337
338 p->disk_handle = NULL;
339
340 /* Find disks */
341 if (VBERROR_SUCCESS != VbExDiskGetInfo(&disk_info, &disk_count,
342 get_info_flags))
343 disk_count = 0;
344
345 VBDEBUG(("VbTryLoadKernel() found %d disks\n", (int)disk_count));
346 if (0 == disk_count) {
347 VbSetRecoveryRequest(VBNV_RECOVERY_RW_NO_DISK);
348 return VBERROR_TRY_LOAD_NO_DISKS;
349 }
350
351 /* Loop over disks */
352 for (i = 0; i < disk_count; i++) {
353 VBDEBUG(("VbTryLoadKernel() trying disk %d\n", (int)i));
354 p->disk_handle = disk_info[i].handle;
355 p->bytes_per_lba = disk_info[i].bytes_per_lba;
356 p->ending_lba = disk_info[i].lba_count - 1;
357 retval = LoadKernel(p);
358 VBDEBUG(("VbTryLoadKernel() LoadKernel() returned %d\n", retval));
359
360 /* Stop now if we found a kernel or we need to reboot */
361 /* TODO: If recovery requested, should track the farthest we get, instead
362 * of just returning the value from the last disk attempted. */
363 if (LOAD_KERNEL_SUCCESS == retval || LOAD_KERNEL_REBOOT == retval)
364 break;
365 }
366
367 /* If we didn't succeed, don't return a disk handle */
368 if (LOAD_KERNEL_SUCCESS != retval)
369 p->disk_handle = NULL;
370
371 VbExDiskFreeInfo(disk_info, p->disk_handle);
372
373 /* Translate return codes */
374 switch (retval) {
375 case LOAD_KERNEL_SUCCESS:
376 return VBERROR_SUCCESS;
377 case LOAD_KERNEL_REBOOT:
378 /* Reboot to same mode, so reuse the current recovery reason */
379 VbSetRecoveryRequest(shared->recovery_reason);
380 return VBERROR_TRY_LOAD_REBOOT;
381 case LOAD_KERNEL_NOT_FOUND:
382 VbSetRecoveryRequest(VBNV_RECOVERY_RW_NO_OS);
383 return VBERROR_TRY_LOAD_RECOVERY;
384 case LOAD_KERNEL_INVALID:
385 VbSetRecoveryRequest(VBNV_RECOVERY_RW_INVALID_OS);
386 return VBERROR_TRY_LOAD_RECOVERY;
387 case LOAD_KERNEL_RECOVERY:
388 return VBERROR_TRY_LOAD_RECOVERY;
389 default:
390 VbSetRecoveryRequest(VBNV_RECOVERY_RW_UNSPECIFIED);
391 return VBERROR_TRY_LOAD_RECOVERY;
392 }
393}
394
395
396/* Handle a normal boot from fixed drive only. */
397VbError_t VbBootNormal(VbCommonParams* cparams, LoadKernelParams* p) {
398 return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED);
399}
400
401
402#ifdef BUILD_FVDEVELOPER
403/* Developer mode delays. All must be multiples of DEV_DELAY_INCREMENT */
404#define DEV_DELAY_INCREMENT 250 /* Delay each loop, in msec */
405#define DEV_DELAY_BEEP1 20000 /* Beep for first time at this time */
406#define DEV_DELAY_BEEP2 21000 /* Beep for second time at this time */
407#define DEV_DELAY_TIMEOUT 30000 /* Give up at this time */
408
409/* Handle a developer-mode boot */
410VbError_t VbBootDeveloper(VbCommonParams* cparams, LoadKernelParams* p) {
411 uint32_t delay_time = 0;
412
413 /* Show the dev mode warning screen */
414 VbDisplayScreen(cparams, VB_SCREEN_DEVELOPER_WARNING, 0);
415
416 /* Loop for dev mode warning delay */
417 for (delay_time = 0; delay_time < DEV_DELAY_TIMEOUT;
418 delay_time += DEV_DELAY_INCREMENT) {
419 uint32_t key;
420
421 if (VbExIsShutdownRequested())
422 return 1;
423
424 if (DEV_DELAY_BEEP1 == delay_time || DEV_DELAY_BEEP2 == delay_time)
425 VbExBeep(DEV_DELAY_INCREMENT, 400);
426 else
427 VbExSleepMs(DEV_DELAY_INCREMENT);
428
429 /* Handle keypress */
430 key = VbExKeyboardRead();
431 switch (key) {
432 case '\r':
433 case ' ':
434 case 0x1B:
435 /* Enter, space, or ESC = reboot to recovery */
436 VBDEBUG(("VbBootDeveloper() - user pressed ENTER/SPACE/ESC"));
437 VbSetRecoveryRequest(VBNV_RECOVERY_RW_DEV_SCREEN);
438 return 1;
439 case 0x04:
440 /* Ctrl+D = dismiss warning; advance to timeout */
441 VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+D; skip delay\n"));
442 delay_time = DEV_DELAY_TIMEOUT;
443 break;
444 case 0x15:
445 /* Ctrl+U = try USB boot, or beep if failure */
446 VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+U; try USB\n"));
447 if (VBERROR_SUCCESS == VbTryLoadKernel(cparams, p,
448 VB_DISK_FLAG_REMOVABLE)) {
449 VBDEBUG(("VbBootDeveloper() - booting USB\n"));
450 return VBERROR_SUCCESS;
451 } else {
452 VBDEBUG(("VbBootDeveloper() - no kernel found on USB\n"));
453 VbExBeep(DEV_DELAY_INCREMENT, 400);
454 }
455 break;
456 default:
457 VbCheckDisplayKey(cparams, key);
458 break;
459 /* TODO: xyzzy easter egg check */
460 }
461 }
462
463 /* Timeout or Ctrl+D; attempt loading from fixed disk */
464 VBDEBUG(("VbBootDeveloper() - trying fixed disk\n"));
465 return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED);
466}
467
468#endif /* BUILD_FVDEVELOPER */
469
470
471/* Delay between disk checks in recovery mode */
472#define REC_DELAY_INCREMENT 250
473
474/* Handle a recovery-mode boot */
475VbError_t VbBootRecovery(VbCommonParams* cparams, LoadKernelParams* p) {
476 VbSharedDataHeader* shared = (VbSharedDataHeader*)cparams->shared_data_blob;
477 uint32_t retval;
478 int i;
479
480 VBDEBUG(("VbBootRecovery() start\n"));
481
482 /* If dev mode switch is off, require removal of all external media. */
483 if (!(shared->flags & VBSD_BOOT_DEV_SWITCH_ON)) {
484 VbDiskInfo* disk_info = NULL;
485 uint32_t disk_count = 0;
486
487 VBDEBUG(("VbBootRecovery() forcing device removal\n"));
488
489 while (1) {
490 if (VBERROR_SUCCESS != VbExDiskGetInfo(&disk_info, &disk_count,
491 VB_DISK_FLAG_REMOVABLE))
492 disk_count = 0;
493 VbExDiskFreeInfo(disk_info, NULL);
494
495 if (0 == disk_count) {
496 VbDisplayScreen(cparams, VB_SCREEN_BLANK, 0);
497 break;
498 }
499
500 VBDEBUG(("VbBootRecovery() waiting for %d disks to be removed\n",
501 (int)disk_count));
502
503 VbDisplayScreen(cparams, VB_SCREEN_RECOVERY_REMOVE, 0);
504
505 /* Scan keyboard more frequently than media, since x86 platforms
506 * don't like to scan USB too rapidly. */
507 for (i = 0; i < 4; i++) {
508 VbCheckDisplayKey(cparams, VbExKeyboardRead());
509 if (VbExIsShutdownRequested())
510 return 1;
511 VbExSleepMs(REC_DELAY_INCREMENT);
512 }
513 }
514 }
515
516 /* Loop and wait for a recovery image */
517 while (1) {
518 VBDEBUG(("VbBootRecovery() attempting to load kernel\n"));
519 retval = VbTryLoadKernel(cparams, p, VB_DISK_FLAG_REMOVABLE);
520
521 if (VBERROR_SUCCESS == retval)
522 break; /* Found a recovery kernel */
523 else if (VBERROR_TRY_LOAD_REBOOT == retval)
524 return 1; /* Must reboot (back into recovery mode) */
525
526 VbDisplayScreen(cparams, VBERROR_TRY_LOAD_NO_DISKS == retval ?
527 VB_SCREEN_RECOVERY_INSERT : VB_SCREEN_RECOVERY_NO_GOOD, 0);
528
529 /* Scan keyboard more frequently than media, since x86 platforms don't like
530 * to scan USB too rapidly. */
531 for (i = 0; i < 4; i++) {
532 VbCheckDisplayKey(cparams, VbExKeyboardRead());
533 if (VbExIsShutdownRequested())
534 return 1;
535 VbExSleepMs(REC_DELAY_INCREMENT);
536 }
537 }
538
539 return VBERROR_SUCCESS;
540}
541
542
543VbError_t VbSelectAndLoadKernel(VbCommonParams* cparams,
544 VbSelectAndLoadKernelParams* kparams) {
545 VbSharedDataHeader* shared = (VbSharedDataHeader*)cparams->shared_data_blob;
546 VbError_t retval;
547 LoadKernelParams p;
548
549 VBDEBUG(("VbSelectAndLoadKernel() start\n"));
550
Randall Spangler96191122011-07-08 14:01:54 -0700551 /* Start timer */
552 shared->timer_vb_select_and_load_kernel_enter = VbExGetTimer();
553
Randall Spangler1b1998d2011-07-01 16:12:47 -0700554 VbExNvStorageRead(vnc.raw);
555 vnc.raw_changed = 0;
556
557 /* Clear output params in case we fail */
558 kparams->disk_handle = NULL;
559 kparams->partition_number = 0;
560 kparams->bootloader_address = 0;
561 kparams->bootloader_size = 0;
562 Memset(kparams->partition_guid, 0, sizeof(kparams->partition_guid));
563
564 /* Fill in params for calls to LoadKernel() */
565 p.shared_data_blob = cparams->shared_data_blob;
566 p.shared_data_size = cparams->shared_data_size;
567 p.gbb_data = cparams->gbb_data;
568 p.gbb_size = cparams->gbb_size;
569 p.kernel_buffer = kparams->kernel_buffer;
570 p.kernel_buffer_size = kparams->kernel_buffer_size;
571 p.nv_context = &vnc;
572 p.boot_flags = 0;
573 if (shared->flags & VBSD_BOOT_DEV_SWITCH_ON)
574 p.boot_flags |= BOOT_FLAG_DEVELOPER;
575
576 /* Select boot path */
577 if (shared->recovery_reason) {
578 /* Recovery boot */
579 p.boot_flags |= BOOT_FLAG_RECOVERY;
580 retval = VbBootRecovery(cparams, &p);
581 VbDisplayScreen(cparams, VB_SCREEN_BLANK, 0);
582 } else {
583 /* TODO: vboot compiler define for developer mode; this is the H2C one */
584#ifdef BUILD_FVDEVELOPER
585 /* Developer boot */
586 p.boot_flags |= BOOT_FLAG_DEV_FIRMWARE;
587 retval = VbBootDeveloper(cparams, &p);
588 VbDisplayScreen(cparams, VB_SCREEN_BLANK, 0);
589#else
590 /* Normal boot */
591 retval = VbBootNormal(cparams, &p);
592#endif
593 }
594
595 if (VBERROR_SUCCESS == retval) {
596 /* Save disk parameters */
597 kparams->disk_handle = p.disk_handle;
598 kparams->partition_number = (uint32_t)p.partition_number;
599 kparams->bootloader_address = p.bootloader_address;
600 kparams->bootloader_size = (uint32_t)p.bootloader_size;
601 Memcpy(kparams->partition_guid, p.partition_guid,
602 sizeof(kparams->partition_guid));
603
604 /* Since we did find something to boot, clear recovery request, if any,
605 * resulting from disk checks during developer or recovery mode. */
606 VbSetRecoveryRequest(VBNV_RECOVERY_NOT_REQUESTED);
607 }
608
609 if (vnc.raw_changed)
610 VbExNvStorageWrite(vnc.raw);
611
Randall Spangler96191122011-07-08 14:01:54 -0700612 /* Stop timer */
613 shared->timer_vb_select_and_load_kernel_exit = VbExGetTimer();
614
Randall Spangler1b1998d2011-07-01 16:12:47 -0700615 VBDEBUG(("VbSelectAndLoadKernel() returning %d\n", (int)retval));
616
617 /* Pass through return value from boot path */
618 return retval;
619}