Randall Spangler | 95c4031 | 2011-03-09 15:54:16 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 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 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 Spangler | f302905 | 2010-06-16 13:42:58 -0700 | [diff] [blame] | 12 | #include "sysincludes.h" |
Randall Spangler | 7adcc60 | 2011-06-24 16:11:45 -0700 | [diff] [blame] | 13 | #include "vboot_api.h" |
Randall Spangler | 9e162cd | 2011-02-22 13:06:53 -0800 | [diff] [blame] | 14 | #include "vboot_nvstorage.h" |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 15 | |
| 16 | /* Interface provided by verified boot library to BDS */ |
| 17 | |
| 18 | /* Return codes for LoadKernel() */ |
Randall Spangler | c1a9f4d | 2010-06-07 15:15:00 -0700 | [diff] [blame] | 19 | #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 Spangler | 7a786b7 | 2010-07-08 13:29:42 -0700 | [diff] [blame] | 23 | #define LOAD_KERNEL_REBOOT 4 /* Internal error; reboot to current mode */ |
| 24 | |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 25 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 26 | /* Boot flags for LoadKernel().boot_flags */ |
Randall Spangler | a8e0f94 | 2011-02-14 11:12:09 -0800 | [diff] [blame] | 27 | /* 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 Spangler | 0ff6fea | 2010-05-27 18:36:02 -0700 | [diff] [blame] | 35 | |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 36 | typedef struct LoadKernelParams { |
| 37 | /* Inputs to LoadKernel() */ |
Randall Spangler | 95c4031 | 2011-03-09 15:54:16 -0800 | [diff] [blame] | 38 | 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 Spangler | 7adcc60 | 2011-06-24 16:11:45 -0700 | [diff] [blame] | 47 | |
| 48 | VbExDiskHandle_t disk_handle; /* Disk handle for current device */ |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 49 | 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 Spangler | 7adcc60 | 2011-06-24 16:11:45 -0700 | [diff] [blame] | 52 | |
Randall Spangler | 9e162cd | 2011-02-22 13:06:53 -0800 | [diff] [blame] | 53 | void* kernel_buffer; /* Destination buffer for kernel |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 54 | * (normally at 0x100000) */ |
| 55 | uint64_t kernel_buffer_size; /* Size of kernel buffer in bytes */ |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 56 | uint64_t boot_flags; /* Boot flags */ |
Randall Spangler | 9e162cd | 2011-02-22 13:06:53 -0800 | [diff] [blame] | 57 | 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 Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 63 | |
| 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 Spangler | 19d1313 | 2010-06-03 09:43:43 -0700 | [diff] [blame] | 68 | uint64_t bootloader_address; /* Address of bootloader image in RAM */ |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 69 | uint64_t bootloader_size; /* Size of bootloader image in bytes */ |
Bill Richardson | 5deb67f | 2010-07-23 17:22:25 -0700 | [diff] [blame] | 70 | uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */ |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 71 | } LoadKernelParams; |
| 72 | |
Randall Spangler | 0ff6fea | 2010-05-27 18:36:02 -0700 | [diff] [blame] | 73 | int LoadKernel(LoadKernelParams* params); |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 74 | /* Attempts to load the kernel from the current device. |
| 75 | * |
| 76 | * Returns LOAD_KERNEL_SUCCESS if successful, error code on failure. */ |
| 77 | |
| 78 | |
| 79 | typedef 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 Richardson | 5deb67f | 2010-07-23 17:22:25 -0700 | [diff] [blame] | 89 | uint8_t partition_guid[16]; /* UniquePartitionGuid for boot partition */ |
Randall Spangler | 102bfba | 2010-05-24 15:14:33 -0700 | [diff] [blame] | 90 | } KernelBootloaderOptions; |
| 91 | |
| 92 | |
| 93 | #endif /* VBOOT_REFERENCE_LOAD_KERNEL_FW_H_ */ |