efiffs.h 5.9 KB

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