blob: 6dd6c93d128b0548b48bb84746b5cb73b6e54489 [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 Spangler7adcc602011-06-24 16:11:45 -070013#include "vboot_api.h"
Randall Spangler9e162cd2011-02-22 13:06:53 -080014#include "vboot_nvstorage.h"
Randall Spangler102bfba2010-05-24 15:14:33 -070015
16/* Interface provided by verified boot library to BDS */
17
18/* Return codes for LoadKernel() */
Randall Spanglerc1a9f4d2010-06-07 15:15:00 -070019#define LOAD_KERNEL_SUCCESS 0 /* Success; good kernel found on device */
20#define LOAD_KERNEL_NOT_FOUND 1 /* No kernel found on device */
21#define LOAD_KERNEL_INVALID 2 /* Only invalid kernels found on device */
22#define LOAD_KERNEL_RECOVERY 3 /* Internal error; reboot to recovery mode */
Randall Spangler7a786b72010-07-08 13:29:42 -070023#define LOAD_KERNEL_REBOOT 4 /* Internal error; reboot to current mode */
24
Randall Spangler102bfba2010-05-24 15:14:33 -070025
Randall Spanglerd1836442010-06-10 09:59:04 -070026/* Boot flags for LoadKernel().boot_flags */
Randall Spanglera8e0f942011-02-14 11:12:09 -080027/* Developer switch is on */
28#define BOOT_FLAG_DEVELOPER UINT64_C(0x01)
29/* In recovery mode */
30#define BOOT_FLAG_RECOVERY UINT64_C(0x02)
31/* Skip check of kernel buffer address */
32#define BOOT_FLAG_SKIP_ADDR_CHECK UINT64_C(0x04)
33/* Active main firmware is developer-type, not normal-type or recovery-type. */
34#define BOOT_FLAG_DEV_FIRMWARE UINT64_C(0x08)
Randall Spangler0ff6fea2010-05-27 18:36:02 -070035
Randall Spangler102bfba2010-05-24 15:14:33 -070036typedef struct LoadKernelParams {
37 /* Inputs to LoadKernel() */
Randall Spangler95c40312011-03-09 15:54:16 -080038 void* shared_data_blob; /* Buffer for data shared between
39 * LoadFirmware() and LoadKernel(). Pass the
40 * same buffer which was passed to
41 * LoadFirmware(). */
42 uint64_t shared_data_size; /* Size of shared data blob buffer, in bytes.
43 * On output, this will contain the actual
44 * data size placed into the buffer. */
45 void* gbb_data; /* Pointer to GBB data */
46 uint64_t gbb_size; /* Size of GBB data in bytes */
Randall Spangler7adcc602011-06-24 16:11:45 -070047
48 VbExDiskHandle_t disk_handle; /* Disk handle for current device */
Randall Spangler102bfba2010-05-24 15:14:33 -070049 uint64_t bytes_per_lba; /* Bytes per lba sector on current device */
50 uint64_t ending_lba; /* Last addressable lba sector on current
51 * device */
Randall Spangler7adcc602011-06-24 16:11:45 -070052
Randall Spangler9e162cd2011-02-22 13:06:53 -080053 void* kernel_buffer; /* Destination buffer for kernel
Randall Spangler102bfba2010-05-24 15:14:33 -070054 * (normally at 0x100000) */
55 uint64_t kernel_buffer_size; /* Size of kernel buffer in bytes */
Randall Spanglerd1836442010-06-10 09:59:04 -070056 uint64_t boot_flags; /* Boot flags */
Randall Spangler9e162cd2011-02-22 13:06:53 -080057 VbNvContext* nv_context; /* Context for NV storage. nv_context->raw
58 * must be filled before calling
59 * LoadKernel(). On output, check
60 * nv_context->raw_changed to see if
61 * nv_context->raw has been modified and
62 * needs saving. */
Randall Spangler102bfba2010-05-24 15:14:33 -070063
64 /* Outputs from LoadKernel(); valid only if LoadKernel() returns
65 * LOAD_KERNEL_SUCCESS */
66 uint64_t partition_number; /* Partition number to boot on current device
67 * (1...M) */
Randall Spangler19d13132010-06-03 09:43:43 -070068 uint64_t bootloader_address; /* Address of bootloader image in RAM */
Randall Spangler102bfba2010-05-24 15:14:33 -070069 uint64_t bootloader_size; /* Size of bootloader image in bytes */
Bill Richardson5deb67f2010-07-23 17:22:25 -070070 uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
Randall Spangler102bfba2010-05-24 15:14:33 -070071} LoadKernelParams;
72
Randall Spangler0ff6fea2010-05-27 18:36:02 -070073int LoadKernel(LoadKernelParams* params);
Randall Spangler102bfba2010-05-24 15:14:33 -070074/* Attempts to load the kernel from the current device.
75 *
76 * Returns LOAD_KERNEL_SUCCESS if successful, error code on failure. */
77
78
79typedef struct KernelBootloaderOptions {
80 /* The bootloader is loaded using the EFI LoadImage() and StartImage()
81 * calls. Pass this struct via loaded_image->load_options. */
82 uint64_t drive_number; /* Drive number of boot device (0...N) */
83 uint64_t partition_number; /* Partition number, as returned from
84 * LoadKernel() in
85 * LoadKernelParams.partition_number */
86 uint64_t original_address; /* Absolute bootloader start adddress,
87 * as returned from LoadKernel() in
88 * LoadKernelParams.bootloader_start */
Bill Richardson5deb67f2010-07-23 17:22:25 -070089 uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */
Randall Spangler102bfba2010-05-24 15:14:33 -070090} KernelBootloaderOptions;
91
92
93#endif /* VBOOT_REFERENCE_LOAD_KERNEL_FW_H_ */