PiFirmwareFile.h 16KB

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