]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Pi/PiFirmwareFile.h
MdePkg/PiFirmwareFile: express IS_SECTION2 in terms of SECTION_SIZE
[mirror_edk2.git] / MdePkg / Include / Pi / PiFirmwareFile.h
1 /** @file
2 The firmware file related definitions in PI.
3
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Revision Reference:
8 PI Version 1.6.
9
10 **/
11
12
13 #ifndef __PI_FIRMWARE_FILE_H__
14 #define __PI_FIRMWARE_FILE_H__
15
16 #pragma pack(1)
17 ///
18 /// Used to verify the integrity of the file.
19 ///
20 typedef union {
21 struct {
22 ///
23 /// The IntegrityCheck.Checksum.Header field is an 8-bit checksum of the file
24 /// header. The State and IntegrityCheck.Checksum.File fields are assumed
25 /// to be zero and the checksum is calculated such that the entire header sums to zero.
26 ///
27 UINT8 Header;
28 ///
29 /// If the FFS_ATTRIB_CHECKSUM (see definition below) bit of the Attributes
30 /// field is set to one, the IntegrityCheck.Checksum.File field is an 8-bit
31 /// checksum of the file data.
32 /// If the FFS_ATTRIB_CHECKSUM bit of the Attributes field is cleared to zero,
33 /// the IntegrityCheck.Checksum.File field must be initialized with a value of
34 /// 0xAA. The IntegrityCheck.Checksum.File field is valid any time the
35 /// EFI_FILE_DATA_VALID bit is set in the State field.
36 ///
37 UINT8 File;
38 } Checksum;
39 ///
40 /// This is the full 16 bits of the IntegrityCheck field.
41 ///
42 UINT16 Checksum16;
43 } EFI_FFS_INTEGRITY_CHECK;
44
45 ///
46 /// FFS_FIXED_CHECKSUM is the checksum value used when the
47 /// FFS_ATTRIB_CHECKSUM attribute bit is clear.
48 ///
49 #define FFS_FIXED_CHECKSUM 0xAA
50
51 typedef UINT8 EFI_FV_FILETYPE;
52 typedef UINT8 EFI_FFS_FILE_ATTRIBUTES;
53 typedef UINT8 EFI_FFS_FILE_STATE;
54
55 ///
56 /// File Types Definitions
57 ///
58 #define EFI_FV_FILETYPE_ALL 0x00
59 #define EFI_FV_FILETYPE_RAW 0x01
60 #define EFI_FV_FILETYPE_FREEFORM 0x02
61 #define EFI_FV_FILETYPE_SECURITY_CORE 0x03
62 #define EFI_FV_FILETYPE_PEI_CORE 0x04
63 #define EFI_FV_FILETYPE_DXE_CORE 0x05
64 #define EFI_FV_FILETYPE_PEIM 0x06
65 #define EFI_FV_FILETYPE_DRIVER 0x07
66 #define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER 0x08
67 #define EFI_FV_FILETYPE_APPLICATION 0x09
68 #define EFI_FV_FILETYPE_MM 0x0A
69 #define EFI_FV_FILETYPE_SMM EFI_FV_FILETYPE_MM
70 #define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B
71 #define EFI_FV_FILETYPE_COMBINED_MM_DXE 0x0C
72 #define EFI_FV_FILETYPE_COMBINED_SMM_DXE EFI_FV_FILETYPE_COMBINED_MM_DXE
73 #define EFI_FV_FILETYPE_MM_CORE 0x0D
74 #define EFI_FV_FILETYPE_SMM_CORE EFI_FV_FILETYPE_MM_CORE
75 #define EFI_FV_FILETYPE_MM_STANDALONE 0x0E
76 #define EFI_FV_FILETYPE_MM_CORE_STANDALONE 0x0F
77 #define EFI_FV_FILETYPE_OEM_MIN 0xc0
78 #define EFI_FV_FILETYPE_OEM_MAX 0xdf
79 #define EFI_FV_FILETYPE_DEBUG_MIN 0xe0
80 #define EFI_FV_FILETYPE_DEBUG_MAX 0xef
81 #define EFI_FV_FILETYPE_FFS_MIN 0xf0
82 #define EFI_FV_FILETYPE_FFS_MAX 0xff
83 #define EFI_FV_FILETYPE_FFS_PAD 0xf0
84 ///
85 /// FFS File Attributes.
86 ///
87 #define FFS_ATTRIB_LARGE_FILE 0x01
88 #define FFS_ATTRIB_DATA_ALIGNMENT_2 0x02
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_MM_DEPEX 0x1C
220 #define EFI_SECTION_SMM_DEPEX EFI_SECTION_MM_DEPEX
221
222 ///
223 /// Common section header.
224 ///
225 typedef struct {
226 ///
227 /// A 24-bit unsigned integer that contains the total size of the section in bytes,
228 /// including the EFI_COMMON_SECTION_HEADER.
229 ///
230 UINT8 Size[3];
231 EFI_SECTION_TYPE Type;
232 ///
233 /// Declares the section type.
234 ///
235 } EFI_COMMON_SECTION_HEADER;
236
237 typedef struct {
238 ///
239 /// A 24-bit unsigned integer that contains the total size of the section in bytes,
240 /// including the EFI_COMMON_SECTION_HEADER.
241 ///
242 UINT8 Size[3];
243
244 EFI_SECTION_TYPE Type;
245
246 ///
247 /// If Size is 0xFFFFFF, then ExtendedSize contains the size of the section. If
248 /// Size is not equal to 0xFFFFFF, then this field does not exist.
249 ///
250 UINT32 ExtendedSize;
251 } EFI_COMMON_SECTION_HEADER2;
252
253 ///
254 /// Leaf section type that contains an
255 /// IA-32 16-bit executable image.
256 ///
257 typedef EFI_COMMON_SECTION_HEADER EFI_COMPATIBILITY16_SECTION;
258 typedef EFI_COMMON_SECTION_HEADER2 EFI_COMPATIBILITY16_SECTION2;
259
260 ///
261 /// CompressionType of EFI_COMPRESSION_SECTION.
262 ///
263 #define EFI_NOT_COMPRESSED 0x00
264 #define EFI_STANDARD_COMPRESSION 0x01
265 ///
266 /// An encapsulation section type in which the
267 /// section data is compressed.
268 ///
269 typedef struct {
270 ///
271 /// Usual common section header. CommonHeader.Type = EFI_SECTION_COMPRESSION.
272 ///
273 EFI_COMMON_SECTION_HEADER CommonHeader;
274 ///
275 /// The UINT32 that indicates the size of the section data after decompression.
276 ///
277 UINT32 UncompressedLength;
278 ///
279 /// Indicates which compression algorithm is used.
280 ///
281 UINT8 CompressionType;
282 } EFI_COMPRESSION_SECTION;
283
284 typedef struct {
285 ///
286 /// Usual common section header. CommonHeader.Type = EFI_SECTION_COMPRESSION.
287 ///
288 EFI_COMMON_SECTION_HEADER2 CommonHeader;
289 ///
290 /// UINT32 that indicates the size of the section data after decompression.
291 ///
292 UINT32 UncompressedLength;
293 ///
294 /// Indicates which compression algorithm is used.
295 ///
296 UINT8 CompressionType;
297 } EFI_COMPRESSION_SECTION2;
298
299 ///
300 /// An encapsulation section type in which the section data is disposable.
301 /// A disposable section is an encapsulation section in which the section data may be disposed of during
302 /// the process of creating or updating a firmware image without significant impact on the usefulness of
303 /// the file. The Type field in the section header is set to EFI_SECTION_DISPOSABLE. This
304 /// allows optional or descriptive data to be included with the firmware file which can be removed in
305 /// order to conserve space. The contents of this section are implementation specific, but might contain
306 /// debug data or detailed integration instructions.
307 ///
308 typedef EFI_COMMON_SECTION_HEADER EFI_DISPOSABLE_SECTION;
309 typedef EFI_COMMON_SECTION_HEADER2 EFI_DISPOSABLE_SECTION2;
310
311 ///
312 /// The leaf section which could be used to determine the dispatch order of DXEs.
313 ///
314 typedef EFI_COMMON_SECTION_HEADER EFI_DXE_DEPEX_SECTION;
315 typedef EFI_COMMON_SECTION_HEADER2 EFI_DXE_DEPEX_SECTION2;
316
317 ///
318 /// The leaf section which contains a PI FV.
319 ///
320 typedef EFI_COMMON_SECTION_HEADER EFI_FIRMWARE_VOLUME_IMAGE_SECTION;
321 typedef EFI_COMMON_SECTION_HEADER2 EFI_FIRMWARE_VOLUME_IMAGE_SECTION2;
322
323 ///
324 /// The leaf section which contains a single GUID.
325 ///
326 typedef struct {
327 ///
328 /// Common section header. CommonHeader.Type = EFI_SECTION_FREEFORM_SUBTYPE_GUID.
329 ///
330 EFI_COMMON_SECTION_HEADER CommonHeader;
331 ///
332 /// This GUID is defined by the creator of the file. It is a vendor-defined file type.
333 ///
334 EFI_GUID SubTypeGuid;
335 } EFI_FREEFORM_SUBTYPE_GUID_SECTION;
336
337 typedef struct {
338 ///
339 /// The common section header. CommonHeader.Type = EFI_SECTION_FREEFORM_SUBTYPE_GUID.
340 ///
341 EFI_COMMON_SECTION_HEADER2 CommonHeader;
342 ///
343 /// This GUID is defined by the creator of the file. It is a vendor-defined file type.
344 ///
345 EFI_GUID SubTypeGuid;
346 } EFI_FREEFORM_SUBTYPE_GUID_SECTION2;
347
348 ///
349 /// Attributes of EFI_GUID_DEFINED_SECTION.
350 ///
351 #define EFI_GUIDED_SECTION_PROCESSING_REQUIRED 0x01
352 #define EFI_GUIDED_SECTION_AUTH_STATUS_VALID 0x02
353 ///
354 /// The leaf section which is encapsulation defined by specific GUID.
355 ///
356 typedef struct {
357 ///
358 /// The common section header. CommonHeader.Type = EFI_SECTION_GUID_DEFINED.
359 ///
360 EFI_COMMON_SECTION_HEADER CommonHeader;
361 ///
362 /// The GUID that defines the format of the data that follows. It is a vendor-defined section type.
363 ///
364 EFI_GUID SectionDefinitionGuid;
365 ///
366 /// Contains the offset in bytes from the beginning of the common header to the first byte of the data.
367 ///
368 UINT16 DataOffset;
369 ///
370 /// The bit field that declares some specific characteristics of the section contents.
371 ///
372 UINT16 Attributes;
373 } EFI_GUID_DEFINED_SECTION;
374
375 typedef struct {
376 ///
377 /// The common section header. CommonHeader.Type = EFI_SECTION_GUID_DEFINED.
378 ///
379 EFI_COMMON_SECTION_HEADER2 CommonHeader;
380 ///
381 /// The GUID that defines the format of the data that follows. It is a vendor-defined section type.
382 ///
383 EFI_GUID SectionDefinitionGuid;
384 ///
385 /// Contains the offset in bytes from the beginning of the common header to the first byte of the data.
386 ///
387 UINT16 DataOffset;
388 ///
389 /// The bit field that declares some specific characteristics of the section contents.
390 ///
391 UINT16 Attributes;
392 } EFI_GUID_DEFINED_SECTION2;
393
394 ///
395 /// The leaf section which contains PE32+ image.
396 ///
397 typedef EFI_COMMON_SECTION_HEADER EFI_PE32_SECTION;
398 typedef EFI_COMMON_SECTION_HEADER2 EFI_PE32_SECTION2;
399
400 ///
401 /// The leaf section used to determine the dispatch order of PEIMs.
402 ///
403 typedef EFI_COMMON_SECTION_HEADER EFI_PEI_DEPEX_SECTION;
404 typedef EFI_COMMON_SECTION_HEADER2 EFI_PEI_DEPEX_SECTION2;
405
406 ///
407 /// A leaf section type that contains a position-independent-code (PIC) image.
408 /// A PIC image section is a leaf section that contains a position-independent-code (PIC) image.
409 /// In addition to normal PE32+ images that contain relocation information, PEIM executables may be
410 /// PIC and are referred to as PIC images. A PIC image is the same as a PE32+ image except that all
411 /// relocation information has been stripped from the image and the image can be moved and will
412 /// execute correctly without performing any relocation or other fix-ups. EFI_PIC_SECTION2 must
413 /// be used if the section is 16MB or larger.
414 ///
415 typedef EFI_COMMON_SECTION_HEADER EFI_PIC_SECTION;
416 typedef EFI_COMMON_SECTION_HEADER2 EFI_PIC_SECTION2;
417
418 ///
419 /// The leaf section which constains the position-independent-code image.
420 ///
421 typedef EFI_COMMON_SECTION_HEADER EFI_TE_SECTION;
422 typedef EFI_COMMON_SECTION_HEADER2 EFI_TE_SECTION2;
423
424 ///
425 /// The leaf section which contains an array of zero or more bytes.
426 ///
427 typedef EFI_COMMON_SECTION_HEADER EFI_RAW_SECTION;
428 typedef EFI_COMMON_SECTION_HEADER2 EFI_RAW_SECTION2;
429
430 ///
431 /// The SMM dependency expression section is a leaf section that contains a dependency expression that
432 /// is used to determine the dispatch order for SMM drivers. Before the SMRAM invocation of the
433 /// SMM driver's entry point, this dependency expression must evaluate to TRUE. See the Platform
434 /// Initialization Specification, Volume 2, for details regarding the format of the dependency expression.
435 /// The dependency expression may refer to protocols installed in either the UEFI or the SMM protocol
436 /// database. EFI_SMM_DEPEX_SECTION2 must be used if the section is 16MB or larger.
437 ///
438 typedef EFI_COMMON_SECTION_HEADER EFI_SMM_DEPEX_SECTION;
439 typedef EFI_COMMON_SECTION_HEADER2 EFI_SMM_DEPEX_SECTION2;
440
441 ///
442 /// The leaf section which contains a unicode string that
443 /// is human readable file name.
444 ///
445 typedef struct {
446 EFI_COMMON_SECTION_HEADER CommonHeader;
447
448 ///
449 /// Array of unicode string.
450 ///
451 CHAR16 FileNameString[1];
452 } EFI_USER_INTERFACE_SECTION;
453
454 typedef struct {
455 EFI_COMMON_SECTION_HEADER2 CommonHeader;
456 CHAR16 FileNameString[1];
457 } EFI_USER_INTERFACE_SECTION2;
458
459 ///
460 /// The leaf section which contains a numeric build number and
461 /// an optional unicode string that represents the file revision.
462 ///
463 typedef struct {
464 EFI_COMMON_SECTION_HEADER CommonHeader;
465 UINT16 BuildNumber;
466
467 ///
468 /// Array of unicode string.
469 ///
470 CHAR16 VersionString[1];
471 } EFI_VERSION_SECTION;
472
473 typedef struct {
474 EFI_COMMON_SECTION_HEADER2 CommonHeader;
475 ///
476 /// A UINT16 that represents a particular build. Subsequent builds have monotonically
477 /// increasing build numbers relative to earlier builds.
478 ///
479 UINT16 BuildNumber;
480 CHAR16 VersionString[1];
481 } EFI_VERSION_SECTION2;
482
483 #define SECTION_SIZE(SectionHeaderPtr) \
484 ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) (UINTN) SectionHeaderPtr)->Size) & 0x00ffffff))
485
486 #define IS_SECTION2(SectionHeaderPtr) \
487 (SECTION_SIZE (SectionHeaderPtr) == 0x00ffffff)
488
489 #define SECTION2_SIZE(SectionHeaderPtr) \
490 (((EFI_COMMON_SECTION_HEADER2 *) (UINTN) SectionHeaderPtr)->ExtendedSize)
491
492 #pragma pack()
493
494 #endif
495