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 * Data structure definitions for verified boot, for on-disk / in-eeprom | 5 * Data structure definitions for verified boot, for on-disk / in-eeprom |
6 * data. | 6 * data. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef VBOOT_REFERENCE_VBOOT_STRUCT_H_ | 9 #ifndef VBOOT_REFERENCE_VBOOT_STRUCT_H_ |
10 #define VBOOT_REFERENCE_VBOOT_STRUCT_H_ | 10 #define VBOOT_REFERENCE_VBOOT_STRUCT_H_ |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 VbSignature body_signature; /* Signature for the kernel body */ | 124 VbSignature body_signature; /* Signature for the kernel body */ |
125 } __attribute__((packed)) VbKernelPreambleHeader; | 125 } __attribute__((packed)) VbKernelPreambleHeader; |
126 /* This should be followed by: | 126 /* This should be followed by: |
127 * 2) The signature data for the kernel body, pointed to by | 127 * 2) The signature data for the kernel body, pointed to by |
128 * body_signature.sig_offset. | 128 * body_signature.sig_offset. |
129 * 3) The signature data for (VBFirmwarePreambleHeader + body signature | 129 * 3) The signature data for (VBFirmwarePreambleHeader + body signature |
130 * data), pointed to by preamble_signature.sig_offset. */ | 130 * data), pointed to by preamble_signature.sig_offset. */ |
131 | 131 |
132 #define EXPECTED_VBKERNELPREAMBLEHEADER_SIZE 96 | 132 #define EXPECTED_VBKERNELPREAMBLEHEADER_SIZE 96 |
133 | 133 |
| 134 /* Constants and sub-structures for VbSharedDataHeader */ |
| 135 |
| 136 /* Magic number for recognizing VbSharedDataHeader ("VbSD") */ |
| 137 #define VB_SHARED_DATA_MAGIC 0x44536256 |
| 138 |
134 /* Minimum and recommended size of shared_data_blob in bytes. */ | 139 /* Minimum and recommended size of shared_data_blob in bytes. */ |
135 #define VB_SHARED_DATA_MIN_SIZE 3072 | 140 #define VB_SHARED_DATA_MIN_SIZE 3072 |
136 #define VB_SHARED_DATA_REC_SIZE 16384 | 141 #define VB_SHARED_DATA_REC_SIZE 16384 |
137 | 142 |
| 143 /* Flags for VbSharedDataHeader */ |
| 144 /* LoadFirmware() tried firmware B because of VbNvStorage firmware B tries */ |
| 145 #define VBSD_FWB_TRIED 0x00000001 |
| 146 /* LoadKernel() verified the good kernel keyblock using the kernel subkey from |
| 147 * the firmware. If this flag is not present, it just used the hash of the |
| 148 * kernel keyblock. */ |
| 149 #define VBSD_KERNEL_KEY_VERIFIED 0x00000002 |
| 150 /* LoadFirmware() was told the developer switch was on */ |
| 151 #define VBSD_LF_DEV_SWITCH_ON 0x00000004 |
| 152 |
| 153 /* Result codes for VbSharedDataHeader.check_fw_a_result (and b_result) */ |
| 154 #define VBSD_LF_CHECK_NOT_DONE 0 |
| 155 #define VBSD_LF_CHECK_DEV_MISMATCH 1 |
| 156 #define VBSD_LF_CHECK_REC_MISMATCH 2 |
| 157 #define VBSD_LF_CHECK_VERIFY_KEYBLOCK 3 |
| 158 #define VBSD_LF_CHECK_KEY_ROLLBACK 4 |
| 159 #define VBSD_LF_CHECK_DATA_KEY_PARSE 5 |
| 160 #define VBSD_LF_CHECK_VERIFY_PREAMBLE 6 |
| 161 #define VBSD_LF_CHECK_FW_ROLLBACK 7 |
| 162 #define VBSD_LF_CHECK_HEADER_VALID 8 |
| 163 #define VBSD_LF_CHECK_GET_FW_BODY 9 |
| 164 #define VBSD_LF_CHECK_HASH_WRONG_SIZE 10 |
| 165 #define VBSD_LF_CHECK_VERIFY_BODY 11 |
| 166 #define VBSD_LF_CHECK_VALID 12 |
| 167 |
| 168 /* Boot mode for VbSharedDataHeader.lk_boot_mode */ |
| 169 #define VBSD_LK_BOOT_MODE_RECOVERY 0 |
| 170 #define VBSD_LK_BOOT_MODE_NORMAL 1 |
| 171 #define VBSD_LK_BOOT_MODE_DEVELOPER 2 |
| 172 |
| 173 /* Flags for VbSharedDataKernelPart.flags */ |
| 174 #define VBSD_LKP_FLAG_KEY_BLOCK_VALID 0x01 |
| 175 |
| 176 /* Result codes for VbSharedDataKernelPart.check_result */ |
| 177 #define VBSD_LKP_CHECK_NOT_DONE 0 |
| 178 #define VBSD_LKP_CHECK_TOO_SMALL 1 |
| 179 #define VBSD_LKP_CHECK_READ_START 2 |
| 180 #define VBSD_LKP_CHECK_KEY_BLOCK_SIG 3 |
| 181 #define VBSD_LKP_CHECK_KEY_BLOCK_HASH 4 |
| 182 #define VBSD_LKP_CHECK_DEV_MISMATCH 5 |
| 183 #define VBSD_LKP_CHECK_REC_MISMATCH 6 |
| 184 #define VBSD_LKP_CHECK_KEY_ROLLBACK 7 |
| 185 #define VBSD_LKP_CHECK_DATA_KEY_PARSE 8 |
| 186 #define VBSD_LKP_CHECK_VERIFY_PREAMBLE 9 |
| 187 #define VBSD_LKP_CHECK_KERNEL_ROLLBACK 10 |
| 188 #define VBSD_LKP_CHECK_PREAMBLE_VALID 11 |
| 189 #define VBSD_LKP_CHECK_BODY_ADDRESS 12 |
| 190 #define VBSD_LKP_CHECK_BODY_OFFSET 13 |
| 191 #define VBSD_LKP_CHECK_BODY_EXCEEDS_MEM 15 |
| 192 #define VBSD_LKP_CHECK_BODY_EXCEEDS_PART 16 |
| 193 #define VBSD_LKP_CHECK_READ_DATA 17 |
| 194 #define VBSD_LKP_CHECK_VERIFY_DATA 18 |
| 195 #define VBSD_LKP_CHECK_KERNEL_GOOD 19 |
| 196 |
| 197 |
| 198 /* Information about a single kernel partition check in LoadKernel() */ |
| 199 typedef struct VbSharedDataKernelPart { |
| 200 uint64_t sector_start; /* Start sector of partition */ |
| 201 uint64_t sector_count; /* Sector count of partition */ |
| 202 uint32_t combined_version; /* Combined key+kernel version */ |
| 203 uint8_t gpt_index; /* Index of partition in GPT */ |
| 204 uint8_t check_result; /* Check result; see VBSD_LKP_CHECK_* */ |
| 205 uint8_t flags; /* Flags (see VBSD_LKP_FLAG_* */ |
| 206 uint8_t reserved0; /* Reserved for padding */ |
| 207 } VbSharedDataKernelPart; |
| 208 |
| 209 /* Number of kernel partitions to track per call. Must be power of 2. */ |
| 210 #define VBSD_MAX_KERNEL_PARTS 8 |
| 211 |
| 212 /* Flags for VbSharedDataKernelCall.flags */ |
| 213 /* Error initializing TPM in recovery mode */ |
| 214 #define VBSD_LK_FLAG_REC_TPM_INIT_ERROR 0x00000001 |
| 215 |
| 216 /* Result codes for VbSharedDataKernelCall.check_result */ |
| 217 #define VBSD_LKC_CHECK_NOT_DONE 0 |
| 218 #define VBSD_LKC_CHECK_DEV_SWITCH_MISMATCH 1 |
| 219 #define VBSD_LKC_CHECK_GPT_READ_ERROR 2 |
| 220 #define VBSD_LKC_CHECK_GPT_PARSE_ERROR 3 |
| 221 #define VBSD_LKC_CHECK_GOOD_PARTITION 4 |
| 222 #define VBSD_LKC_CHECK_INVALID_PARTITIONS 5 |
| 223 #define VBSD_LKC_CHECK_NO_PARTITIONS 6 |
| 224 |
| 225 /* Information about a single call to LoadKernel() */ |
| 226 typedef struct VbSharedDataKernelCall { |
| 227 uint32_t boot_flags; /* Bottom 32 bits of flags passed in |
| 228 * LoadKernelParams.boot_flags */ |
| 229 uint32_t flags; /* Debug flags; see VBSD_LK_FLAG_* */ |
| 230 uint64_t sector_count; /* Number of sectors on drive */ |
| 231 uint32_t sector_size; /* Sector size in bytes */ |
| 232 uint8_t check_result; /* Check result; see VBSD_LKC_CHECK_* */ |
| 233 uint8_t boot_mode; /* Boot mode for LoadKernel(); see |
| 234 * VBSD_LK_BOOT_MODE_* constants */ |
| 235 uint8_t test_error_num; /* Test error number, if non-zero */ |
| 236 uint8_t return_code; /* Return code from LoadKernel() */ |
| 237 uint8_t kernel_parts_found; /* Number of kernel partitions found */ |
| 238 uint8_t reserved0[7]; /* Reserved for padding */ |
| 239 VbSharedDataKernelPart parts[VBSD_MAX_KERNEL_PARTS]; /* Data on kernels */ |
| 240 } VbSharedDataKernelCall; |
| 241 |
| 242 /* Number of kernel calls to track. Must be power of 2. */ |
| 243 #define VBSD_MAX_KERNEL_CALLS 4 |
| 244 |
138 /* Data shared between LoadFirmware(), LoadKernel(), and OS. | 245 /* Data shared between LoadFirmware(), LoadKernel(), and OS. |
139 * | 246 * |
140 * The boot process is: | 247 * The boot process is: |
141 * 1) Caller allocates buffer, at least VB_SHARED_DATA_MIN bytes, ideally | 248 * 1) Caller allocates buffer, at least VB_SHARED_DATA_MIN bytes, ideally |
142 * VB_SHARED_DATA_REC_SIZE bytes. | 249 * VB_SHARED_DATA_REC_SIZE bytes. |
143 * 2) If non-recovery boot, this is passed to LoadFirmware(), which | 250 * 2) If non-recovery boot, this is passed to LoadFirmware(), which |
144 * initializes the buffer, adding this header and some data. | 251 * initializes the buffer, adding this header and some data. |
145 * 3) Buffer is passed to LoadKernel(). If this is a recovery boot, | 252 * 3) Buffer is passed to LoadKernel(). If this is a recovery boot, |
146 * LoadKernel() initializes the buffer, adding this header. Regardless | 253 * LoadKernel() initializes the buffer, adding this header. Regardless |
147 * of boot type, LoadKernel() adds some data to the buffer. | 254 * of boot type, LoadKernel() adds some data to the buffer. |
148 * 4) Caller makes data available to the OS in a platform-dependent manner. | 255 * 4) Caller makes data available to the OS in a platform-dependent manner. |
149 * For example, via ACPI or ATAGs. */ | 256 * For example, via ACPI or ATAGs. */ |
150 typedef struct VbSharedDataHeader { | 257 typedef struct VbSharedDataHeader { |
151 /* Fields present in version 1 */ | 258 /* Fields present in version 1 */ |
| 259 uint32_t magic; /* Magic number for struct |
| 260 * (VB_SHARED_DATA_MAGIC) */ |
152 uint32_t struct_version; /* Version of this structure */ | 261 uint32_t struct_version; /* Version of this structure */ |
153 uint64_t struct_size; /* Size of this structure in bytes */ | 262 uint64_t struct_size; /* Size of this structure in bytes */ |
154 uint64_t data_size; /* Size of shared data buffer in bytes */ | 263 uint64_t data_size; /* Size of shared data buffer in bytes */ |
155 uint64_t data_used; /* Amount of shared data used so far */ | 264 uint64_t data_used; /* Amount of shared data used so far */ |
| 265 uint32_t flags; /* Flags */ |
| 266 uint32_t reserved0; /* Reserved for padding */ |
156 | 267 |
157 VbPublicKey kernel_subkey; /* Kernel subkey, from firmware */ | 268 VbPublicKey kernel_subkey; /* Kernel subkey, from firmware */ |
158 uint64_t kernel_subkey_data_offset; /* Offset of kernel subkey data from | 269 uint64_t kernel_subkey_data_offset; /* Offset of kernel subkey data from |
159 * start of this struct */ | 270 * start of this struct */ |
160 uint64_t kernel_subkey_data_size; /* Offset of kernel subkey data */ | 271 uint64_t kernel_subkey_data_size; /* Size of kernel subkey data */ |
161 | 272 |
162 uint64_t flags; /* Flags */ | 273 /* Timer values from VbGetTimer(). Unused values are set to 0. If a |
| 274 * function is called mutiple times, these are the times from the |
| 275 * most recent call. */ |
| 276 uint64_t timer_load_firmware_start_enter; /* LoadFirmwareStart() - enter */ |
| 277 uint64_t timer_load_firmware_start_exit; /* LoadFirmwareStart() - exit */ |
| 278 uint64_t timer_load_firmware_enter; /* LoadFirmware() - enter */ |
| 279 uint64_t timer_load_firmware_exit; /* LoadFirmware() - exit */ |
| 280 uint64_t timer_load_kernel_enter; /* LoadKernel() - enter */ |
| 281 uint64_t timer_load_kernel_exit; /* LoadKernel() - exit */ |
| 282 |
| 283 /* Information stored in TPM, as retrieved by firmware */ |
| 284 uint32_t fw_version_tpm; /* Current firmware version in TPM */ |
| 285 uint32_t kernel_version_tpm; /* Current kernel version in TPM */ |
| 286 |
| 287 /* Debugging information from LoadFirmware() */ |
| 288 uint8_t check_fw_a_result; /* Result of checking RW firmware A */ |
| 289 uint8_t check_fw_b_result; /* Result of checking RW firmware B */ |
| 290 uint8_t firmware_index; /* Firmware index returned by |
| 291 * LoadFirmware() or 0xFF if failure */ |
| 292 uint8_t reserved1; /* Reserved for padding */ |
| 293 uint32_t fw_version_tpm_start; /* Firmware TPM version at start of |
| 294 * LoadFirmware() */ |
| 295 uint32_t fw_version_lowest; /* Firmware lowest version found */ |
| 296 |
| 297 /* Debugging information from LoadKernel() */ |
| 298 uint32_t lk_call_count; /* Number of times LoadKernel() called */ |
| 299 VbSharedDataKernelCall lk_calls[VBSD_MAX_KERNEL_CALLS]; /* Info on calls */ |
| 300 |
| 301 /* Offset and size of supplemental kernel data. Reserve space for these |
| 302 * fields now, so that future LoadKernel() versions can store information |
| 303 * there without needing to shift down whatever data the original |
| 304 * LoadFirmware() might have put immediately following its |
| 305 * VbSharedDataHeader. */ |
| 306 uint64_t kernel_supplemental_offset; |
| 307 uint64_t kernel_supplemental_size; |
163 | 308 |
164 /* After read-only firmware which uses version 1 is released, any additional | 309 /* After read-only firmware which uses version 1 is released, any additional |
165 * fields must be added below, and the struct version must be increased. | 310 * fields must be added below, and the struct version must be increased. |
166 * Before reading/writing those fields, make sure that the struct being | 311 * Before reading/writing those fields, make sure that the struct being |
167 * accessed is at least version 2. | 312 * accessed is at least version 2. |
168 * | 313 * |
169 * It's always ok for an older firmware to access a newer struct, since all | 314 * It's always ok for an older firmware to access a newer struct, since all |
170 * the fields it knows about are present. Newer firmware needs to use | 315 * the fields it knows about are present. Newer firmware needs to use |
171 * reasonable defaults when accessing older structs. */ | 316 * reasonable defaults when accessing older structs. */ |
172 | 317 |
173 } __attribute__((packed)) VbSharedDataHeader; | 318 } __attribute__((packed)) VbSharedDataHeader; |
174 | 319 |
175 #define VB_SHARED_DATA_VERSION 1 /* Version for struct_version */ | 320 #define VB_SHARED_DATA_VERSION 1 /* Version for struct_version */ |
176 | 321 |
177 __pragma(pack(pop)) /* Support packing for MSVC. */ | 322 __pragma(pack(pop)) /* Support packing for MSVC. */ |
178 | 323 |
179 #endif /* VBOOT_REFERENCE_VBOOT_STRUCT_H_ */ | 324 #endif /* VBOOT_REFERENCE_VBOOT_STRUCT_H_ */ |
OLD | NEW |