blob: 5815abfc4973795f4b134fb14d0b54d711fabc53 [file] [log] [blame]
Randall Spangler95c40312011-03-09 15:54:16 -08001/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Randall Spangler102bfba2010-05-24 15:14:33 -07002 * 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 API for loading and verifying kernel.
6 * (Firmware Portion)
7 */
8
9#ifndef VBOOT_REFERENCE_LOAD_KERNEL_FW_H_
10#define VBOOT_REFERENCE_LOAD_KERNEL_FW_H_
11
Randall Spanglerf3029052010-06-16 13:42:58 -070012#include "sysincludes.h"
Randall Spangler9e162cd2011-02-22 13:06:53 -080013#include "vboot_nvstorage.h"
Randall Spangler102bfba2010-05-24 15:14:33 -070014
15/* Interface provided by verified boot library to BDS */
16
17/* Return codes for LoadKernel() */
Randall Spanglerc1a9f4d2010-06-07 15:15:00 -070018#define LOAD_KERNEL_SUCCESS 0 /* Success; good kernel found on device */
19#define LOAD_KERNEL_NOT_FOUND 1 /* No kernel found on device */
20#define LOAD_KERNEL_INVALID 2 /* Only invalid kernels found on device */
21#define LOAD_KERNEL_RECOVERY 3 /* Internal error; reboot to recovery mode */
Randall Spangler7a786b72010-07-08 13:29:42 -070022#define LOAD_KERNEL_REBOOT 4 /* Internal error; reboot to current mode */
23
Randall Spangler102bfba2010-05-24 15:14:33 -070024
Randall Spanglerd1836442010-06-10 09:59:04 -070025/* Boot flags for LoadKernel().boot_flags */
Randall Spanglera8e0f942011-02-14 11:12:09 -080026/* Developer switch is on */
27#define BOOT_FLAG_DEVELOPER UINT64_C(0x01)
28/* In recovery mode */
29#define BOOT_FLAG_RECOVERY UINT64_C(0x02)
30/* Skip check of kernel buffer address */
31#define BOOT_FLAG_SKIP_ADDR_CHECK UINT64_C(0x04)
32/* Active main firmware is developer-type, not normal-type or recovery-type. */
33#define BOOT_FLAG_DEV_FIRMWARE UINT64_C(0x08)
Randall Spangler0ff6fea2010-05-27 18:36:02 -070034
Randall Spangler102bfba2010-05-24 15:14:33 -070035typedef struct LoadKernelParams {
36 /* Inputs to LoadKernel() */
Randall Spangler95c40312011-03-09 15:54:16 -080037 void* shared_data_blob; /* Buffer for data shared between
38 * LoadFirmware() and LoadKernel(). Pass the
39 * same buffer which was passed to
40 * LoadFirmware(). */
41 uint64_t shared_data_size; /* Size of shared data blob buffer, in bytes.
42 * On output, this will contain the actual
43 * data size placed into the buffer. */
44 void* gbb_data; /* Pointer to GBB data */
45 uint64_t gbb_size; /* Size of GBB data in bytes */
Randall Spangler102bfba2010-05-24 15:14:33 -070046 uint64_t bytes_per_lba; /* Bytes per lba sector on current device */
47 uint64_t ending_lba; /* Last addressable lba sector on current
48 * device */
Randall Spangler9e162cd2011-02-22 13:06:53 -080049 void* kernel_buffer; /* Destination buffer for kernel
Randall Spangler102bfba2010-05-24 15:14:33 -070050 * (normally at 0x100000) */
51 uint64_t kernel_buffer_size; /* Size of kernel buffer in bytes */
Randall Spanglerd1836442010-06-10 09:59:04 -070052 uint64_t boot_flags; /* Boot flags */
Randall Spangler9e162cd2011-02-22 13:06:53 -080053 VbNvContext* nv_context; /* Context for NV storage. nv_context->raw
54 * must be filled before calling
55 * LoadKernel(). On output, check
56 * nv_context->raw_changed to see if
57 * nv_context->raw has been modified and
58 * needs saving. */
Randall Spangler102bfba2010-05-24 15:14:33 -070059
60 /* Outputs from LoadKernel(); valid only if LoadKernel() returns
61 * LOAD_KERNEL_SUCCESS */
62 uint64_t partition_number; /* Partition number to boot on current device
63 * (1...M) */
Randall Spangler19d13132010-06-03 09:43:43 -070064 uint64_t bootloader_address; /* Address of bootloader image in RAM */
Randall Spangler102bfba2010-05-24 15:14:33 -070065 uint64_t bootloader_size; /* Size of bootloader image in bytes */
Bill Richardson5deb67f2010-07-23 17:22:25 -070066 uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
Randall Spangler102bfba2010-05-24 15:14:33 -070067} LoadKernelParams;
68
Randall Spangler0ff6fea2010-05-27 18:36:02 -070069int LoadKernel(LoadKernelParams* params);
Randall Spangler102bfba2010-05-24 15:14:33 -070070/* Attempts to load the kernel from the current device.
71 *
72 * Returns LOAD_KERNEL_SUCCESS if successful, error code on failure. */
73
74
75typedef struct KernelBootloaderOptions {
76 /* The bootloader is loaded using the EFI LoadImage() and StartImage()
77 * calls. Pass this struct via loaded_image->load_options. */
78 uint64_t drive_number; /* Drive number of boot device (0...N) */
79 uint64_t partition_number; /* Partition number, as returned from
80 * LoadKernel() in
81 * LoadKernelParams.partition_number */
82 uint64_t original_address; /* Absolute bootloader start adddress,
83 * as returned from LoadKernel() in
84 * LoadKernelParams.bootloader_start */
Bill Richardson5deb67f2010-07-23 17:22:25 -070085 uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
Randall Spangler102bfba2010-05-24 15:14:33 -070086} KernelBootloaderOptions;
87
88
89#endif /* VBOOT_REFERENCE_LOAD_KERNEL_FW_H_ */