1 /** @file 2 The firmware file related definitions in PI. 3 4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials are licensed and made available under 6 the terms and conditions of the BSD License that accompanies this distribution. 7 The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 @par Revision Reference: 14 PI Version 1.4. 15 16 **/ 17 18 19 #ifndef __PI_FIRMWARE_FILE_H__ 20 #define __PI_FIRMWARE_FILE_H__ 21 22 #pragma pack(1) 23 /// 24 /// Used to verify the integrity of the file. 25 /// 26 typedef union { 27 struct { 28 /// 29 /// The IntegrityCheck.Checksum.Header field is an 8-bit checksum of the file 30 /// header. The State and IntegrityCheck.Checksum.File fields are assumed 31 /// to be zero and the checksum is calculated such that the entire header sums to zero. 32 /// 33 UINT8 Header; 34 /// 35 /// If the FFS_ATTRIB_CHECKSUM (see definition below) bit of the Attributes 36 /// field is set to one, the IntegrityCheck.Checksum.File field is an 8-bit 37 /// checksum of the file data. 38 /// If the FFS_ATTRIB_CHECKSUM bit of the Attributes field is cleared to zero, 39 /// the IntegrityCheck.Checksum.File field must be initialized with a value of 40 /// 0xAA. The IntegrityCheck.Checksum.File field is valid any time the 41 /// EFI_FILE_DATA_VALID bit is set in the State field. 42 /// 43 UINT8 File; 44 } Checksum; 45 /// 46 /// This is the full 16 bits of the IntegrityCheck field. 47 /// 48 UINT16 Checksum16; 49 } EFI_FFS_INTEGRITY_CHECK; 50 51 /// 52 /// FFS_FIXED_CHECKSUM is the checksum value used when the 53 /// FFS_ATTRIB_CHECKSUM attribute bit is clear. 54 /// 55 #define FFS_FIXED_CHECKSUM 0xAA 56 57 typedef UINT8 EFI_FV_FILETYPE; 58 typedef UINT8 EFI_FFS_FILE_ATTRIBUTES; 59 typedef UINT8 EFI_FFS_FILE_STATE; 60 61 /// 62 /// File Types Definitions 63 /// 64 #define EFI_FV_FILETYPE_ALL 0x00 65 #define EFI_FV_FILETYPE_RAW 0x01 66 #define EFI_FV_FILETYPE_FREEFORM 0x02 67 #define EFI_FV_FILETYPE_SECURITY_CORE 0x03 68 #define EFI_FV_FILETYPE_PEI_CORE 0x04 69 #define EFI_FV_FILETYPE_DXE_CORE 0x05 70 #define EFI_FV_FILETYPE_PEIM 0x06 71 #define EFI_FV_FILETYPE_DRIVER 0x07 72 #define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER 0x08 73 #define EFI_FV_FILETYPE_APPLICATION 0x09 74 #define EFI_FV_FILETYPE_SMM 0x0A 75 #define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B 76 #define EFI_FV_FILETYPE_COMBINED_SMM_DXE 0x0C 77 #define EFI_FV_FILETYPE_SMM_CORE 0x0D 78 #define EFI_FV_FILETYPE_OEM_MIN 0xc0 79 #define EFI_FV_FILETYPE_OEM_MAX 0xdf 80 #define EFI_FV_FILETYPE_DEBUG_MIN 0xe0 81 #define EFI_FV_FILETYPE_DEBUG_MAX 0xef 82 #define EFI_FV_FILETYPE_FFS_MIN 0xf0 83 #define EFI_FV_FILETYPE_FFS_MAX 0xff 84 #define EFI_FV_FILETYPE_FFS_PAD 0xf0 85 /// 86 /// FFS File Attributes. 87 /// 88 #define FFS_ATTRIB_LARGE_FILE 0x01 89 #define FFS_ATTRIB_FIXED 0x04 90 #define FFS_ATTRIB_DATA_ALIGNMENT 0x38 91 #define FFS_ATTRIB_CHECKSUM 0x40 92 93 /// 94 /// FFS File State Bits. 95 /// 96 #define EFI_FILE_HEADER_CONSTRUCTION 0x01 97 #define EFI_FILE_HEADER_VALID 0x02 98 #define EFI_FILE_DATA_VALID 0x04 99 #define EFI_FILE_MARKED_FOR_UPDATE 0x08 100 #define EFI_FILE_DELETED 0x10 101 #define EFI_FILE_HEADER_INVALID 0x20 102 103 104 /// 105 /// Each file begins with the header that describe the 106 /// contents and state of the files. 107 /// 108 typedef struct { 109 /// 110 /// This GUID is the file name. It is used to uniquely identify the file. 111 /// 112 EFI_GUID Name; 113 /// 114 /// Used to verify the integrity of the file. 115 /// 116 EFI_FFS_INTEGRITY_CHECK IntegrityCheck; 117 /// 118 /// Identifies the type of file. 119 /// 120 EFI_FV_FILETYPE Type; 121 /// 122 /// Declares various file attribute bits. 123 /// 124 EFI_FFS_FILE_ATTRIBUTES Attributes; 125 /// 126 /// The length of the file in bytes, including the FFS header. 127 /// 128 UINT8 Size[3]; 129 /// 130 /// Used to track the state of the file throughout the life of the file from creation to deletion. 131 /// 132 EFI_FFS_FILE_STATE State; 133 } EFI_FFS_FILE_HEADER; 134 135 typedef struct { 136 /// 137 /// This GUID is the file name. It is used to uniquely identify the file. There may be only 138 /// one instance of a file with the file name GUID of Name in any given firmware 139 /// volume, except if the file type is EFI_FV_FILETYPE_FFS_PAD. 140 /// 141 EFI_GUID Name; 142 143 /// 144 /// Used to verify the integrity of the file. 145 /// 146 EFI_FFS_INTEGRITY_CHECK IntegrityCheck; 147 148 /// 149 /// Identifies the type of file. 150 /// 151 EFI_FV_FILETYPE Type; 152 153 /// 154 /// Declares various file attribute bits. 155 /// 156 EFI_FFS_FILE_ATTRIBUTES Attributes; 157 158 /// 159 /// The length of the file in bytes, including the FFS header. 160 /// The length of the file data is either (Size - sizeof(EFI_FFS_FILE_HEADER)). This calculation means a 161 /// zero-length file has a Size of 24 bytes, which is sizeof(EFI_FFS_FILE_HEADER). 162 /// Size is not required to be a multiple of 8 bytes. Given a file F, the next file header is 163 /// located at the next 8-byte aligned firmware volume offset following the last byte of the file F. 164 /// 165 UINT8 Size[3]; 166 167 /// 168 /// Used to track the state of the file throughout the life of the file from creation to deletion. 169 /// 170 EFI_FFS_FILE_STATE State; 171 172 /// 173 /// If FFS_ATTRIB_LARGE_FILE is set in Attributes, then ExtendedSize exists and Size must be set to zero. 174 /// If FFS_ATTRIB_LARGE_FILE is not set then EFI_FFS_FILE_HEADER is used. 175 /// 176 UINT64 ExtendedSize; 177 } EFI_FFS_FILE_HEADER2; 178 179 #define IS_FFS_FILE2(FfsFileHeaderPtr) \ 180 (((((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Attributes) & FFS_ATTRIB_LARGE_FILE) == FFS_ATTRIB_LARGE_FILE) 181 182 #define FFS_FILE_SIZE(FfsFileHeaderPtr) \ 183 ((UINT32) (*((UINT32 *) ((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Size) & 0x00ffffff)) 184 185 #define FFS_FILE2_SIZE(FfsFileHeaderPtr) \ 186 ((UINT32) (((EFI_FFS_FILE_HEADER2 *) (UINTN) FfsFileHeaderPtr)->ExtendedSize)) 187 188 typedef UINT8 EFI_SECTION_TYPE; 189 190 /// 191 /// Pseudo type. It is used as a wild card when retrieving sections. 192 /// The section type EFI_SECTION_ALL matches all section types. 193 /// 194 #define EFI_SECTION_ALL 0x00 195 196 /// 197 /// Encapsulation section Type values. 198 /// 199 #define EFI_SECTION_COMPRESSION 0x01 200 201 #define EFI_SECTION_GUID_DEFINED 0x02 202 203 #define EFI_SECTION_DISPOSABLE 0x03 204 205 /// 206 /// Leaf section Type values. 207 /// 208 #define EFI_SECTION_PE32 0x10 209 #define EFI_SECTION_PIC 0x11 210 #define EFI_SECTION_TE 0x12 211 #define EFI_SECTION_DXE_DEPEX 0x13 212 #define EFI_SECTION_VERSION 0x14 213 #define EFI_SECTION_USER_INTERFACE 0x15 214 #define EFI_SECTION_COMPATIBILITY16 0x16 215 #define EFI_SECTION_FIRMWARE_VOLUME_IMAGE 0x17 216 #define EFI_SECTION_FREEFORM_SUBTYPE_GUID 0x18 217 #define EFI_SECTION_RAW 0x19 218 #define EFI_SECTION_PEI_DEPEX 0x1B 219 #define EFI_SECTION_SMM_DEPEX 0x1C 220 221 /// 222 /// Common section header. 223 /// 224 typedef struct { 225 /// 226 /// A 24-bit unsigned integer that contains the total size of the section in bytes, 227 /// including the EFI_COMMON_SECTION_HEADER. 228 /// 229 UINT8 Size[3]; 230 EFI_SECTION_TYPE Type; 231 /// 232 /// Declares the section type. 233 /// 234 } EFI_COMMON_SECTION_HEADER; 235 236 typedef struct { 237 /// 238 /// A 24-bit unsigned integer that contains the total size of the section in bytes, 239 /// including the EFI_COMMON_SECTION_HEADER. 240 /// 241 UINT8 Size[3]; 242 243 EFI_SECTION_TYPE Type; 244 245 /// 246 /// If Size is 0xFFFFFF, then ExtendedSize contains the size of the section. If 247 /// Size is not equal to 0xFFFFFF, then this field does not exist. 248 /// 249 UINT32 ExtendedSize; 250 } EFI_COMMON_SECTION_HEADER2; 251 252 /// 253 /// Leaf section type that contains an 254 /// IA-32 16-bit executable image. 255 /// 256 typedef EFI_COMMON_SECTION_HEADER EFI_COMPATIBILITY16_SECTION; 257 typedef EFI_COMMON_SECTION_HEADER2 EFI_COMPATIBILITY16_SECTION2; 258 259 /// 260 /// CompressionType of EFI_COMPRESSION_SECTION. 261 /// 262 #define EFI_NOT_COMPRESSED 0x00 263 #define EFI_STANDARD_COMPRESSION 0x01 264 /// 265 /// An encapsulation section type in which the 266 /// section data is compressed. 267 /// 268 typedef struct { 269 /// 270 /// Usual common section header. CommonHeader.Type = EFI_SECTION_COMPRESSION. 271 /// 272 EFI_COMMON_SECTION_HEADER CommonHeader; 273 /// 274 /// The UINT32 that indicates the size of the section data after decompression. 275 /// 276 UINT32 UncompressedLength; 277 /// 278 /// Indicates which compression algorithm is used. 279 /// 280 UINT8 CompressionType; 281 } EFI_COMPRESSION_SECTION; 282 283 typedef struct { 284 /// 285 /// Usual common section header. CommonHeader.Type = EFI_SECTION_COMPRESSION. 286 /// 287 EFI_COMMON_SECTION_HEADER2 CommonHeader; 288 /// 289 /// UINT32 that indicates the size of the section data after decompression. 290 /// 291 UINT32 UncompressedLength; 292 /// 293 /// Indicates which compression algorithm is used. 294 /// 295 UINT8 CompressionType; 296 } EFI_COMPRESSION_SECTION2; 297 298 /// 299 /// An encapsulation section type in which the section data is disposable. 300 /// A disposable section is an encapsulation section in which the section data may be disposed of during 301 /// the process of creating or updating a firmware image without significant impact on the usefulness of 302 /// the file. The Type field in the section header is set to EFI_SECTION_DISPOSABLE. This 303 /// allows optional or descriptive data to be included with the firmware file which can be removed in 304 /// order to conserve space. The contents of this section are implementation specific, but might contain 305 /// debug data or detailed integration instructions. 306 /// 307 typedef EFI_COMMON_SECTION_HEADER EFI_DISPOSABLE_SECTION; 308 typedef EFI_COMMON_SECTION_HEADER2 EFI_DISPOSABLE_SECTION2; 309 310 /// 311 /// The leaf section which could be used to determine the dispatch order of DXEs. 312 /// 313 typedef EFI_COMMON_SECTION_HEADER EFI_DXE_DEPEX_SECTION; 314 typedef EFI_COMMON_SECTION_HEADER2 EFI_DXE_DEPEX_SECTION2; 315 316 /// 317 /// The leaf section which contains a PI FV. 318 /// 319 typedef EFI_COMMON_SECTION_HEADER EFI_FIRMWARE_VOLUME_IMAGE_SECTION; 320 typedef EFI_COMMON_SECTION_HEADER2 EFI_FIRMWARE_VOLUME_IMAGE_SECTION2; 321 322 /// 323 /// The leaf section which contains a single GUID. 324 /// 325 typedef struct { 326 /// 327 /// Common section header. CommonHeader.Type = EFI_SECTION_FREEFORM_SUBTYPE_GUID. 328 /// 329 EFI_COMMON_SECTION_HEADER CommonHeader; 330 /// 331 /// This GUID is defined by the creator of the file. It is a vendor-defined file type. 332 /// 333 EFI_GUID SubTypeGuid; 334 } EFI_FREEFORM_SUBTYPE_GUID_SECTION; 335 336 typedef struct { 337 /// 338 /// The common section header. CommonHeader.Type = EFI_SECTION_FREEFORM_SUBTYPE_GUID. 339 /// 340 EFI_COMMON_SECTION_HEADER2 CommonHeader; 341 /// 342 /// This GUID is defined by the creator of the file. It is a vendor-defined file type. 343 /// 344 EFI_GUID SubTypeGuid; 345 } EFI_FREEFORM_SUBTYPE_GUID_SECTION2; 346 347 /// 348 /// Attributes of EFI_GUID_DEFINED_SECTION. 349 /// 350 #define EFI_GUIDED_SECTION_PROCESSING_REQUIRED 0x01 351 #define EFI_GUIDED_SECTION_AUTH_STATUS_VALID 0x02 352 /// 353 /// The leaf section which is encapsulation defined by specific GUID. 354 /// 355 typedef struct { 356 /// 357 /// The common section header. CommonHeader.Type = EFI_SECTION_GUID_DEFINED. 358 /// 359 EFI_COMMON_SECTION_HEADER CommonHeader; 360 /// 361 /// The GUID that defines the format of the data that follows. It is a vendor-defined section type. 362 /// 363 EFI_GUID SectionDefinitionGuid; 364 /// 365 /// Contains the offset in bytes from the beginning of the common header to the first byte of the data. 366 /// 367 UINT16 DataOffset; 368 /// 369 /// The bit field that declares some specific characteristics of the section contents. 370 /// 371 UINT16 Attributes; 372 } EFI_GUID_DEFINED_SECTION; 373 374 typedef struct { 375 /// 376 /// The common section header. CommonHeader.Type = EFI_SECTION_GUID_DEFINED. 377 /// 378 EFI_COMMON_SECTION_HEADER2 CommonHeader; 379 /// 380 /// The GUID that defines the format of the data that follows. It is a vendor-defined section type. 381 /// 382 EFI_GUID SectionDefinitionGuid; 383 /// 384 /// Contains the offset in bytes from the beginning of the common header to the first byte of the data. 385 /// 386 UINT16 DataOffset; 387 /// 388 /// The bit field that declares some specific characteristics of the section contents. 389 /// 390 UINT16 Attributes; 391 } EFI_GUID_DEFINED_SECTION2; 392 393 /// 394 /// The leaf section which contains PE32+ image. 395 /// 396 typedef EFI_COMMON_SECTION_HEADER EFI_PE32_SECTION; 397 typedef EFI_COMMON_SECTION_HEADER2 EFI_PE32_SECTION2; 398 399 /// 400 /// The leaf section used to determine the dispatch order of PEIMs. 401 /// 402 typedef EFI_COMMON_SECTION_HEADER EFI_PEI_DEPEX_SECTION; 403 typedef EFI_COMMON_SECTION_HEADER2 EFI_PEI_DEPEX_SECTION2; 404 405 /// 406 /// A leaf section type that contains a position-independent-code (PIC) image. 407 /// A PIC image section is a leaf section that contains a position-independent-code (PIC) image. 408 /// In addition to normal PE32+ images that contain relocation information, PEIM executables may be 409 /// PIC and are referred to as PIC images. A PIC image is the same as a PE32+ image except that all 410 /// relocation information has been stripped from the image and the image can be moved and will 411 /// execute correctly without performing any relocation or other fix-ups. EFI_PIC_SECTION2 must 412 /// be used if the section is 16MB or larger. 413 /// 414 typedef EFI_COMMON_SECTION_HEADER EFI_PIC_SECTION; 415 typedef EFI_COMMON_SECTION_HEADER2 EFI_PIC_SECTION2; 416 417 /// 418 /// The leaf section which constains the position-independent-code image. 419 /// 420 typedef EFI_COMMON_SECTION_HEADER EFI_TE_SECTION; 421 typedef EFI_COMMON_SECTION_HEADER2 EFI_TE_SECTION2; 422 423 /// 424 /// The leaf section which contains an array of zero or more bytes. 425 /// 426 typedef EFI_COMMON_SECTION_HEADER EFI_RAW_SECTION; 427 typedef EFI_COMMON_SECTION_HEADER2 EFI_RAW_SECTION2; 428 429 /// 430 /// The SMM dependency expression section is a leaf section that contains a dependency expression that 431 /// is used to determine the dispatch order for SMM drivers. Before the SMRAM invocation of the 432 /// SMM driver's entry point, this dependency expression must evaluate to TRUE. See the Platform 433 /// Initialization Specification, Volume 2, for details regarding the format of the dependency expression. 434 /// The dependency expression may refer to protocols installed in either the UEFI or the SMM protocol 435 /// database. EFI_SMM_DEPEX_SECTION2 must be used if the section is 16MB or larger. 436 /// 437 typedef EFI_COMMON_SECTION_HEADER EFI_SMM_DEPEX_SECTION; 438 typedef EFI_COMMON_SECTION_HEADER2 EFI_SMM_DEPEX_SECTION2; 439 440 /// 441 /// The leaf section which contains a unicode string that 442 /// is human readable file name. 443 /// 444 typedef struct { 445 EFI_COMMON_SECTION_HEADER CommonHeader; 446 447 /// 448 /// Array of unicode string. 449 /// 450 CHAR16 FileNameString[1]; 451 } EFI_USER_INTERFACE_SECTION; 452 453 typedef struct { 454 EFI_COMMON_SECTION_HEADER2 CommonHeader; 455 CHAR16 FileNameString[1]; 456 } EFI_USER_INTERFACE_SECTION2; 457 458 /// 459 /// The leaf section which contains a numeric build number and 460 /// an optional unicode string that represents the file revision. 461 /// 462 typedef struct { 463 EFI_COMMON_SECTION_HEADER CommonHeader; 464 UINT16 BuildNumber; 465 466 /// 467 /// Array of unicode string. 468 /// 469 CHAR16 VersionString[1]; 470 } EFI_VERSION_SECTION; 471 472 typedef struct { 473 EFI_COMMON_SECTION_HEADER2 CommonHeader; 474 /// 475 /// A UINT16 that represents a particular build. Subsequent builds have monotonically 476 /// increasing build numbers relative to earlier builds. 477 /// 478 UINT16 BuildNumber; 479 CHAR16 VersionString[1]; 480 } EFI_VERSION_SECTION2; 481 482 #define IS_SECTION2(SectionHeaderPtr) \ 483 ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) (UINTN) SectionHeaderPtr)->Size) & 0x00ffffff) == 0x00ffffff) 484 485 #define SECTION_SIZE(SectionHeaderPtr) \ 486 ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) (UINTN) SectionHeaderPtr)->Size) & 0x00ffffff)) 487 488 #define SECTION2_SIZE(SectionHeaderPtr) \ 489 (((EFI_COMMON_SECTION_HEADER2 *) (UINTN) SectionHeaderPtr)->ExtendedSize) 490 491 #pragma pack() 492 493 #endif 494 495