1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */ 2 3 #ifndef _CBFS_SERIALIZED_H_ 4 #define _CBFS_SERIALIZED_H_ 5 6 #include <stdint.h> 7 #include <vb2_sha.h> 8 9 enum cbfs_compression { 10 CBFS_COMPRESS_NONE = 0, 11 CBFS_COMPRESS_LZMA = 1, 12 CBFS_COMPRESS_LZ4 = 2, 13 }; 14 15 enum cbfs_type { 16 /* QUERY is an alias for DELETED that can be passed to CBFS APIs to 17 inquire about the type of a file, rather than constrain it. */ 18 CBFS_TYPE_QUERY = 0, 19 CBFS_TYPE_DELETED = 0x00000000, 20 CBFS_TYPE_NULL = 0xffffffff, 21 CBFS_TYPE_BOOTBLOCK = 0x01, 22 CBFS_TYPE_CBFSHEADER = 0x02, 23 CBFS_TYPE_LEGACY_STAGE = 0x10, 24 CBFS_TYPE_STAGE = 0x11, 25 CBFS_TYPE_SELF = 0x20, 26 CBFS_TYPE_FIT_PAYLOAD = 0x21, 27 CBFS_TYPE_OPTIONROM = 0x30, 28 CBFS_TYPE_BOOTSPLASH = 0x40, 29 CBFS_TYPE_RAW = 0x50, 30 CBFS_TYPE_VSA = 0x51, 31 CBFS_TYPE_MBI = 0x52, 32 CBFS_TYPE_MICROCODE = 0x53, 33 CBFS_TYPE_INTEL_FIT = 0x54, 34 CBFS_TYPE_FSP = 0x60, 35 CBFS_TYPE_MRC = 0x61, 36 CBFS_TYPE_MMA = 0x62, 37 CBFS_TYPE_EFI = 0x63, 38 CBFS_TYPE_STRUCT = 0x70, 39 CBFS_TYPE_AMDFW = 0x80, 40 CBFS_TYPE_CMOS_DEFAULT = 0xaa, 41 CBFS_TYPE_SPD = 0xab, 42 CBFS_TYPE_MRC_CACHE = 0xac, 43 CBFS_TYPE_CMOS_LAYOUT = 0x01aa, 44 }; 45 46 #define CBFS_HEADER_MAGIC 0x4F524243 /* BE: 'ORBC' */ 47 #define CBFS_HEADER_VERSION1 0x31313131 /* BE: '1111' */ 48 #define CBFS_HEADER_VERSION2 0x31313132 /* BE: '1112' */ 49 #define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2 50 51 /* this is the master cbfs header - it must be located somewhere available 52 * to bootblock (to load romstage). The last 4 bytes in the image contain its 53 * relative offset from the end of the image (as a 32-bit signed integer). */ 54 55 struct cbfs_header { 56 uint32_t magic; 57 uint32_t version; 58 uint32_t romsize; 59 uint32_t bootblocksize; 60 uint32_t align; /* fixed to 64 bytes */ 61 uint32_t offset; 62 uint32_t architecture; 63 uint32_t pad[1]; 64 } __packed; 65 66 /* this used to be flexible, but wasn't ever set to something different. */ 67 #define CBFS_ALIGNMENT 64 68 69 /* "Unknown" refers to CBFS headers version 1, 70 * before the architecture was defined (i.e., x86 only). 71 */ 72 enum cbfs_architecture { 73 CBFS_ARCHITECTURE_UNKNOWN = 0xFFFFFFFF, 74 CBFS_ARCHITECTURE_X86 = 0x00000001, 75 CBFS_ARCHITECTURE_ARM = 0x00000010, 76 CBFS_ARCHITECTURE_AARCH64 = 0x0000aa64, 77 CBFS_ARCHITECTURE_MIPS = 0x00000100, /* deprecated */ 78 CBFS_ARCHITECTURE_RISCV = 0xc001d0de, 79 CBFS_ARCHITECTURE_PPC64 = 0x407570ff, 80 }; 81 82 /** This is a component header - every entry in the CBFS 83 will have this header. 84 85 This is how the component is arranged in the ROM: 86 87 -------------- <- 0 88 component header 89 -------------- <- sizeof(struct component) 90 component name 91 -------------- <- offset 92 data 93 ... 94 -------------- <- offset + len 95 */ 96 97 #define CBFS_FILE_MAGIC "LARCHIVE" 98 #define CBFS_METADATA_MAX_SIZE 256 99 100 struct cbfs_file { 101 char magic[8]; 102 uint32_t len; 103 uint32_t type; 104 uint32_t attributes_offset; 105 uint32_t offset; 106 char filename[]; 107 } __packed; 108 109 #if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 110 _Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch"); 111 #endif 112 113 /* The common fields of extended cbfs file attributes. 114 Attributes are expected to start with tag/len, then append their 115 specific fields. */ 116 struct cbfs_file_attribute { 117 uint32_t tag; 118 /* len covers the whole structure, incl. tag and len */ 119 uint32_t len; 120 uint8_t data[]; 121 } __packed; 122 123 /* All attribute sizes must be divisible by this! */ 124 #define CBFS_ATTRIBUTE_ALIGN 4 125 126 /* Depending on how the header was initialized, it may be backed with 0x00 or 127 * 0xff. Support both. */ 128 enum cbfs_file_attr_tag { 129 CBFS_FILE_ATTR_TAG_UNUSED = 0, 130 CBFS_FILE_ATTR_TAG_UNUSED2 = 0xffffffff, 131 CBFS_FILE_ATTR_TAG_COMPRESSION = 0x42435a4c, /* BE: 'BCZL' */ 132 CBFS_FILE_ATTR_TAG_HASH = 0x68736148, /* BE: 'hsaH' */ 133 CBFS_FILE_ATTR_TAG_POSITION = 0x42435350, /* BE: 'BCSP' */ 134 CBFS_FILE_ATTR_TAG_ALIGNMENT = 0x42434c41, /* BE: 'BCLA' */ 135 CBFS_FILE_ATTR_TAG_IBB = 0x32494242, /* BE: '2IBB' */ 136 CBFS_FILE_ATTR_TAG_PADDING = 0x47444150, /* BE: 'GNDP' */ 137 CBFS_FILE_ATTR_TAG_STAGEHEADER = 0x53746748, /* BE: 'StgH' */ 138 }; 139 140 struct cbfs_file_attr_compression { 141 uint32_t tag; 142 uint32_t len; 143 /* whole file compression format. 0 if no compression. */ 144 uint32_t compression; 145 uint32_t decompressed_size; 146 } __packed; 147 148 /* Actual size in CBFS may be larger/smaller than struct size! */ 149 struct cbfs_file_attr_hash { 150 uint32_t tag; 151 uint32_t len; 152 struct vb2_hash hash; 153 } __packed; 154 155 struct cbfs_file_attr_position { 156 uint32_t tag; 157 uint32_t len; 158 uint32_t position; 159 } __packed; 160 161 struct cbfs_file_attr_align { 162 uint32_t tag; 163 uint32_t len; 164 uint32_t alignment; 165 } __packed; 166 167 struct cbfs_file_attr_stageheader { 168 uint32_t tag; 169 uint32_t len; 170 uint64_t loadaddr; /* Memory address to load the code to. */ 171 uint32_t entry_offset; /* Offset of entry point from loadaddr. */ 172 uint32_t memlen; /* Total length (including BSS) in memory. */ 173 } __packed; 174 175 176 /*** Component sub-headers ***/ 177 178 /* Following are component sub-headers for the "standard" 179 component types */ 180 181 /** this is the sub-header for payload components. Payloads 182 are loaded by coreboot at the end of the boot process */ 183 184 struct cbfs_payload_segment { 185 uint32_t type; 186 uint32_t compression; 187 uint32_t offset; 188 uint64_t load_addr; 189 uint32_t len; 190 uint32_t mem_len; 191 } __packed; 192 193 struct cbfs_payload { 194 struct cbfs_payload_segment segments; 195 }; 196 197 enum cbfs_payload_segment_type { 198 PAYLOAD_SEGMENT_CODE = 0x434F4445, /* BE: 'CODE' */ 199 PAYLOAD_SEGMENT_DATA = 0x44415441, /* BE: 'DATA' */ 200 PAYLOAD_SEGMENT_BSS = 0x42535320, /* BE: 'BSS ' */ 201 PAYLOAD_SEGMENT_ENTRY = 0x454E5452, /* BE: 'ENTR' */ 202 203 /* PARAMS for PAYLOAD_INFO feature. Broken since 2012, removed 2024. */ 204 PAYLOAD_SEGMENT_DEPRECATED_PARAMS = 0x50415241, /* BE: 'PARA' */ 205 }; 206 207 struct cbfs_optionrom { 208 uint32_t compression; 209 uint32_t len; 210 } __packed; 211 212 #endif /* _CBFS_SERIALIZED_H_ */ 213