efiffs.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. efiffs.h
  9. Abstract:
  10. This header contains definitions for the EFI Firmware File System.
  11. Author:
  12. Evan Green 6-Mar-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. #include "efiimg.h"
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // Define a macro to test attribute bits, using the correct bits depending on
  23. // the erase polarity.
  24. //
  25. #define EFI_TEST_FFS_ATTRIBUTES_BIT(_Attributes, _TestAttributes, _Bit) \
  26. ((BOOLEAN)((_Attributes & EFI_FVB_ERASE_POLARITY) ? \
  27. (((~_TestAttributes) & _Bit) == _Bit) : \
  28. ((_TestAttributes & _Bit) == _Bit))
  29. //
  30. // This macro determines if the given header is an FFS2 file.
  31. //
  32. #define EFI_IS_FFS_FILE2(_FileHeader) \
  33. (((((EFI_FFS_FILE_HEADER *)(UINTN)_FileHeader)->Attributes) & \
  34. FFS_ATTRIB_LARGE_FILE) == FFS_ATTRIB_LARGE_FILE)
  35. //
  36. // These macros return the file size given the FFS file header.
  37. //
  38. #define EFI_FFS_FILE_SIZE(_FileHeader) \
  39. (((UINT32)((_FileHeader)->Size[0])) | \
  40. (((UINT32)((_FileHeader)->Size[1])) << 8) | \
  41. (((UINT32)((_FileHeader)->Size[2])) << 16))
  42. #define EFI_FFS_FILE2_SIZE(_FileHeader) \
  43. (((EFI_FFS_FILE_HEADER2 *)(UINTN)_FileHeader)->ExtendedSize)
  44. //
  45. // ---------------------------------------------------------------- Definitions
  46. //
  47. //
  48. // Define FFS GUIDs.
  49. //
  50. #define EFI_FIRMWARE_FILE_SYSTEM_GUID \
  51. { \
  52. 0x7A9354D9, 0x0468, 0x444A, \
  53. {0x81, 0xCE, 0x0B, 0xF6, 0x17, 0xD8, 0x90, 0xDF} \
  54. }
  55. #define EFI_FIRMWARE_FILE_SYSTEM2_GUID \
  56. { \
  57. 0x8C8CE578, 0x8A3D, 0x4F1C, \
  58. {0x99, 0x35, 0x89, 0x61, 0x85, 0xC3, 0x2D, 0xD3} \
  59. }
  60. #define EFI_FIRMWARE_FILE_SYSTEM3_GUID \
  61. { \
  62. 0x5473C07A, 0x3DCB, 0x4DCA, \
  63. {0xBD, 0x6F, 0x1E, 0x96, 0x89, 0xE7, 0x34, 0x9A} \
  64. }
  65. #define EFI_FFS_VOLUME_TOP_FILE_GUID \
  66. { \
  67. 0x1BA0062E, 0xC779, 0x4582, \
  68. {0x85, 0x66, 0x33, 0x6A, 0xE8, 0xF7, 0x8F, 0x9} \
  69. }
  70. //
  71. // Define FFS File Attributes.
  72. //
  73. #define FFS_ATTRIB_LARGE_FILE 0x01
  74. #define FFS_ATTRIB_TAIL_PRESENT 0x01
  75. #define FFS_ATTRIB_RECOVERY 0x02
  76. #define FFS_ATTRIB_FIXED 0x04
  77. #define FFS_ATTRIB_DATA_ALIGNMENT 0x38
  78. #define FFS_ATTRIB_CHECKSUM 0x40
  79. //
  80. // Define firmware volume types.
  81. //
  82. #define EFI_FV_FILETYPE_ALL 0x00
  83. #define EFI_FV_FILETYPE_RAW 0x01
  84. #define EFI_FV_FILETYPE_FREEFORM 0x02
  85. #define EFI_FV_FILETYPE_SECURITY_CORE 0x03
  86. #define EFI_FV_FILETYPE_PEI_CORE 0x04
  87. #define EFI_FV_FILETYPE_DXE_CORE 0x05
  88. #define EFI_FV_FILETYPE_PEIM 0x06
  89. #define EFI_FV_FILETYPE_DRIVER 0x07
  90. #define EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER 0x08
  91. #define EFI_FV_FILETYPE_APPLICATION 0x09
  92. #define EFI_FV_FILETYPE_SMM 0x0A
  93. #define EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE 0x0B
  94. #define EFI_FV_FILETYPE_COMBINED_SMM_DXE 0x0C
  95. #define EFI_FV_FILETYPE_SMM_CORE 0x0D
  96. #define EFI_FV_FILETYPE_OEM_MIN 0xC0
  97. #define EFI_FV_FILETYPE_OEM_MAX 0xDF
  98. #define EFI_FV_FILETYPE_DEBUG_MIN 0xE0
  99. #define EFI_FV_FILETYPE_DEBUG_MAX 0xEF
  100. #define EFI_FV_FILETYPE_FFS_MIN 0xF0
  101. #define EFI_FV_FILETYPE_FFS_MAX 0xFF
  102. #define EFI_FV_FILETYPE_FFS_PAD 0xF0
  103. //
  104. // Define the fixed checksum value used when checksum bit is clear. Defined in
  105. // PI 1.2.
  106. //
  107. #define FFS_FIXED_CHECKSUM 0xAA
  108. //
  109. // Define file state bits.
  110. //
  111. #define EFI_FILE_HEADER_CONSTRUCTION 0x01
  112. #define EFI_FILE_HEADER_VALID 0x02
  113. #define EFI_FILE_DATA_VALID 0x04
  114. #define EFI_FILE_MARKED_FOR_UPDATE 0x08
  115. #define EFI_FILE_DELETED 0x10
  116. #define EFI_FILE_HEADER_INVALID 0x20
  117. #define EFI_FILE_ALL_STATE_BITS (EFI_FILE_HEADER_CONSTRUCTION | \
  118. EFI_FILE_HEADER_VALID | \
  119. EFI_FILE_DATA_VALID | \
  120. EFI_FILE_MARKED_FOR_UPDATE | \
  121. EFI_FILE_DELETED | \
  122. EFI_FILE_HEADER_INVALID)
  123. #define MAX_FFS_SIZE 0x1000000
  124. #define MAX_SECTION_SIZE 0x1000000
  125. //
  126. // ------------------------------------------------------ Data Type Definitions
  127. //
  128. typedef UINT16 EFI_FFS_FILE_TAIL, *PEFI_FFS_FILE_TAIL;
  129. typedef UINT8 EFI_FFS_FILE_ATTRIBUTES, *PEFI_FFS_FILE_ATTRIBUTES;
  130. typedef UINT8 EFI_FFS_FILE_STATE, *PEFI_FFS_FILE_STATE;
  131. typedef union _EFI_FFS_INTEGRITY_CHECK {
  132. struct {
  133. UINT8 Header;
  134. UINT8 File;
  135. } Checksum;
  136. UINT16 Checksum16;
  137. } EFI_FFS_INTEGRITY_CHECK, *PEFI_FFS_INTEGRITY_CHECK;
  138. typedef struct _EFI_FFS_FILE_HEADER {
  139. EFI_GUID Name;
  140. EFI_FFS_INTEGRITY_CHECK IntegrityCheck;
  141. EFI_FV_FILETYPE Type;
  142. EFI_FFS_FILE_ATTRIBUTES Attributes;
  143. UINT8 Size[3];
  144. EFI_FFS_FILE_STATE State;
  145. } EFI_FFS_FILE_HEADER, *PEFI_FFS_FILE_HEADER;
  146. typedef struct _EFI_FFS_FILE_HEADER2 {
  147. EFI_GUID Name;
  148. EFI_FFS_INTEGRITY_CHECK IntegrityCheck;
  149. EFI_FV_FILETYPE Type;
  150. EFI_FFS_FILE_ATTRIBUTES Attributes;
  151. UINT8 Size[3];
  152. EFI_FFS_FILE_STATE State;
  153. UINT32 ExtendedSize;
  154. } EFI_FFS_FILE_HEADER2, *PEFI_FFS_FILE_HEADER2;
  155. //
  156. // -------------------------------------------------------------------- Globals
  157. //
  158. //
  159. // -------------------------------------------------------- Function Prototypes
  160. //