| 1 | /* Copyright 2013 The ChromiumOS Authors |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | * VbSharedDataHeader definition, for sharing with OS. |
| 6 | */ |
| 7 | |
| 8 | #ifndef VBOOT_REFERENCE_VBOOT_STRUCT_H_ |
| 9 | #define VBOOT_REFERENCE_VBOOT_STRUCT_H_ |
| 10 | |
| 11 | #include <stdint.h> |
| 12 | |
| 13 | #include "2sysincludes.h" |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif /* __cplusplus */ |
| 18 | |
| 19 | /* Constants and sub-structures for VbSharedDataHeader */ |
| 20 | |
| 21 | /* Magic number for recognizing VbSharedDataHeader ("VbSD") */ |
| 22 | #define VB_SHARED_DATA_MAGIC 0x44536256 |
| 23 | |
| 24 | /* Version for struct_version */ |
| 25 | #define VB_SHARED_DATA_VERSION 3 |
| 26 | |
| 27 | /* |
| 28 | * Flags for VbSharedDataHeader |
| 29 | * |
| 30 | * TODO(b:124141368): Move these constants into crossystem once they are |
| 31 | * no longer needed in vboot2 code. |
| 32 | */ |
| 33 | |
| 34 | /* LoadFirmware() tried firmware B because of VbNvStorage firmware B tries; |
| 35 | Deprecated as part of b:172342538. */ |
| 36 | #define VBSD_DEPRECATED_FWB_TRIED 0x00000001 |
| 37 | /* |
| 38 | * vb2api_load_kernel() verified the good kernel keyblock using the kernel |
| 39 | * subkey from the firmware. If this flag is not present, it just used the |
| 40 | * hash of the kernel keyblock. |
| 41 | */ |
| 42 | #define VBSD_KERNEL_KEY_VERIFIED 0x00000002 |
| 43 | /* Developer switch was enabled at boot time */ |
| 44 | #define VBSD_BOOT_DEV_SWITCH_ON 0x00000010 |
| 45 | /* Recovery switch was enabled at boot time */ |
| 46 | #define VBSD_BOOT_REC_SWITCH_ON 0x00000020 |
| 47 | /* Firmware write protect was enabled at boot time */ |
| 48 | #define VBSD_BOOT_FIRMWARE_WP_ENABLED 0x00000040 |
| 49 | /* VbInit() was told the system supports EC software sync */ |
| 50 | #define VBSD_EC_SOFTWARE_SYNC 0x00000800 |
| 51 | /* Firmware used vboot2 for firmware selection */ |
| 52 | #define VBSD_BOOT_FIRMWARE_VBOOT2 0x00008000 |
| 53 | /* NvStorage uses 64-byte record, not 16-byte */ |
| 54 | #define VBSD_NVDATA_V2 0x00100000 |
| 55 | |
| 56 | /* Data shared to OS. */ |
| 57 | typedef struct VbSharedDataHeader { |
| 58 | /* Fields present in version 1 */ |
| 59 | /* Magic number for struct (VB_SHARED_DATA_MAGIC) */ |
| 60 | uint32_t magic; |
| 61 | /* Version of this structure */ |
| 62 | uint32_t struct_version; |
| 63 | /* Size of this structure in bytes */ |
| 64 | uint64_t struct_size; |
| 65 | /* Size of shared data buffer in bytes */ |
| 66 | uint64_t data_size; |
| 67 | /* Amount of shared data used so far */ |
| 68 | uint64_t data_used; |
| 69 | /* Flags */ |
| 70 | uint32_t flags; |
| 71 | /* Reserved for padding */ |
| 72 | uint32_t reserved0; |
| 73 | /* Previously, kernel subkey, from firmware (struct vb2_packed_key). |
| 74 | Now we use vboot2 workbuf for storage. */ |
| 75 | uint8_t reserved1[32]; |
| 76 | /* Offset of kernel subkey data from start of this struct */ |
| 77 | uint64_t kernel_subkey_data_offset; |
| 78 | /* Size of kernel subkey data */ |
| 79 | uint64_t kernel_subkey_data_size; |
| 80 | |
| 81 | /* |
| 82 | * These timer values are all deprecated. coreboot tstamp_table should |
| 83 | * be used instead. See crosbug.com/1014102. |
| 84 | */ |
| 85 | /* VbInit() enter/exit */ |
| 86 | uint64_t timer_vb_init_enter; |
| 87 | uint64_t timer_vb_init_exit; |
| 88 | /* VbSelectFirmware() enter/exit */ |
| 89 | uint64_t timer_vb_select_firmware_enter; |
| 90 | uint64_t timer_vb_select_firmware_exit; |
| 91 | /* VbSelectAndLoadKernel() enter/exit */ |
| 92 | uint64_t timer_vb_select_and_load_kernel_enter; |
| 93 | uint64_t timer_vb_select_and_load_kernel_exit; |
| 94 | |
| 95 | /* The active firmware version */ |
| 96 | uint32_t fw_version_act; |
| 97 | /* Current kernel version in TPM */ |
| 98 | uint32_t kernel_version_tpm; |
| 99 | |
| 100 | /* Debugging information from LoadFirmware() */ |
| 101 | /* Result of checking RW firmware A and B */ |
| 102 | uint8_t check_fw_a_result; |
| 103 | uint8_t check_fw_b_result; |
| 104 | /* Firmware index returned by LoadFirmware() or 0xFF if failure */ |
| 105 | uint8_t firmware_index; |
| 106 | /* Reserved for padding */ |
| 107 | uint8_t reserved2; |
| 108 | /* Current firmware version in TPM */ |
| 109 | uint32_t fw_version_tpm; |
| 110 | /* Firmware lowest version found */ |
| 111 | uint32_t fw_version_lowest; |
| 112 | |
| 113 | /* Reserved for padding */ |
| 114 | uint8_t reserved3[916]; |
| 115 | |
| 116 | /* |
| 117 | * Fields added in version 2. Before accessing, make sure that |
| 118 | * struct_version >= 2 |
| 119 | */ |
| 120 | /* Recovery reason for current boot */ |
| 121 | uint8_t recovery_reason; |
| 122 | /* Reserved for padding */ |
| 123 | uint8_t reserved4[7]; |
| 124 | /* Flags from firmware keyblock */ |
| 125 | uint64_t fw_keyblock_flags; |
| 126 | /* |
| 127 | * The active kernel version |
| 128 | * this field only available in struct_version >= 3 |
| 129 | */ |
| 130 | uint32_t kernel_version_act; |
| 131 | /* Kernel lowest version found */ |
| 132 | uint32_t kernel_version_lowest; |
| 133 | |
| 134 | } __attribute__((packed)) VbSharedDataHeader; |
| 135 | |
| 136 | /* Size of VbSharedDataheader for each version */ |
| 137 | #define VB_SHARED_DATA_HEADER_SIZE_V1 1072 |
| 138 | #define VB_SHARED_DATA_HEADER_SIZE_V2 1096 |
| 139 | |
| 140 | _Static_assert(VB_SHARED_DATA_HEADER_SIZE_V1 |
| 141 | == offsetof(VbSharedDataHeader, recovery_reason), |
| 142 | "VB_SHARED_DATA_HEADER_SIZE_V1 incorrect"); |
| 143 | |
| 144 | _Static_assert(VB_SHARED_DATA_HEADER_SIZE_V2 == sizeof(VbSharedDataHeader), |
| 145 | "VB_SHARED_DATA_HEADER_SIZE_V2 incorrect"); |
| 146 | |
| 147 | #ifdef __cplusplus |
| 148 | } |
| 149 | #endif /* __cplusplus */ |
| 150 | |
| 151 | #endif /* VBOOT_REFERENCE_VBOOT_STRUCT_H_ */ |