efi_event.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef TCG_EFI_EVENT_H
  3. #define TCG_EFI_EVENT_H 1
  4. #include <uuid/uuid.h>
  5. #include <uchar.h>
  6. #include <tss2/tss2_tpm2_types.h>
  7. /*
  8. * Log event types. These are spread out over 2 specs:
  9. * "TCG EFI Protocol Specification For TPM Family 1.1 or 1.2" and
  10. * "TCG PC Client Specific Implementation Specification for Conventional BIOS"
  11. */
  12. #define EV_PREBOOT_CERT 0x0
  13. #define EV_POST_CODE 0x1
  14. #define EV_UNUSED 0x2
  15. #define EV_NO_ACTION 0x3
  16. #define EV_SEPARATOR 0x4
  17. #define EV_ACTION 0x5
  18. #define EV_EVENT_TAG 0x6
  19. #define EV_S_CRTM_CONTENTS 0x7
  20. #define EV_S_CRTM_VERSION 0x8
  21. #define EV_CPU_MICROCODE 0x9
  22. #define EV_PLATFORM_CONFIG_FLAGS 0xa
  23. #define EV_TABLE_OF_DEVICES 0xb
  24. #define EV_COMPACT_HASH 0xc
  25. #define EV_IPL 0xd
  26. #define EV_IPL_PARTITION_DATA 0xe
  27. #define EV_NONHOST_CODE 0xf
  28. #define EV_NONHOST_CONFIG 0x10
  29. #define EV_NONHOST_INFO 0x11
  30. #define EV_OMIT_BOOT_DEVICE_EVENTS 0x12
  31. /* TCG EFI Platform Specification For TPM Family 1.1 or 1.2 */
  32. #define EV_EFI_EVENT_BASE 0x80000000
  33. #define EV_EFI_VARIABLE_DRIVER_CONFIG EV_EFI_EVENT_BASE + 0x1
  34. #define EV_EFI_VARIABLE_BOOT EV_EFI_EVENT_BASE + 0x2
  35. #define EV_EFI_BOOT_SERVICES_APPLICATION EV_EFI_EVENT_BASE + 0x3
  36. #define EV_EFI_BOOT_SERVICES_DRIVER EV_EFI_EVENT_BASE + 0x4
  37. #define EV_EFI_RUNTIME_SERVICES_DRIVER EV_EFI_EVENT_BASE + 0x5
  38. #define EV_EFI_GPT_EVENT EV_EFI_EVENT_BASE + 0x6
  39. #define EV_EFI_ACTION EV_EFI_EVENT_BASE + 0x7
  40. #define EV_EFI_PLATFORM_FIRMWARE_BLOB EV_EFI_EVENT_BASE + 0x8
  41. #define EV_EFI_HANDOFF_TABLES EV_EFI_EVENT_BASE + 0x9
  42. #define EV_EFI_VARIABLE_AUTHORITY EV_EFI_EVENT_BASE + 0xe0
  43. #ifndef PACKED
  44. #define PACKED __attribute__((__packed__))
  45. #endif
  46. typedef struct {
  47. UINT16 AlgorithmId;
  48. UINT8 Digest[];
  49. } PACKED TCG_DIGEST2;
  50. typedef struct {
  51. UINT32 EventSize;
  52. UINT8 Event [];
  53. } PACKED TCG_EVENT2;
  54. typedef struct {
  55. UINT32 PCRIndex;
  56. UINT32 EventType;
  57. UINT32 DigestCount;
  58. TCG_DIGEST2 Digests [];
  59. /* TCG_EVENT2 comes next */
  60. } PACKED TCG_EVENT_HEADER2;
  61. typedef struct {
  62. uuid_t VariableName;
  63. UINT64 UnicodeNameLength;
  64. UINT64 VariableDataLength;
  65. char16_t UnicodeName[];
  66. /* INT8 VariableData[] comes next */
  67. } PACKED UEFI_VARIABLE_DATA;
  68. typedef UINT64 UEFI_PHYSICAL_ADDRESS;
  69. typedef struct {
  70. UEFI_PHYSICAL_ADDRESS BlobBase;
  71. UINT64 BlobLength;
  72. } PACKED UEFI_PLATFORM_FIRMWARE_BLOB;
  73. typedef struct {
  74. UINT32 pcrIndex;
  75. UINT32 eventType;
  76. BYTE digest[20];
  77. UINT32 eventDataSize;
  78. BYTE event[];
  79. } PACKED TCG_EVENT;
  80. typedef struct {
  81. UINT16 algorithmId;
  82. UINT16 digestSize;
  83. } PACKED TCG_SPECID_ALG;
  84. typedef struct {
  85. UINT8 vendorInfoSize;
  86. BYTE vendorInfo[];
  87. } PACKED TCG_VENDOR_INFO;
  88. typedef struct {
  89. BYTE Signature[16];
  90. UINT32 platformClass;
  91. UINT8 specVersionMinor;
  92. UINT8 specVersionMajor;
  93. UINT8 specErrata;
  94. UINT8 uintnSize;
  95. UINT32 numberOfAlgorithms;
  96. TCG_SPECID_ALG digestSizes[];
  97. /* then TCG_VendorStuff */
  98. } PACKED TCG_SPECID_EVENT;
  99. typedef struct {
  100. UEFI_PHYSICAL_ADDRESS ImageLocationInMemory;
  101. UINT64 ImageLengthInMemory;
  102. UINT64 ImageLinkTimeAddress;
  103. UINT64 LengthOfDevicePath;
  104. BYTE DevicePath[];
  105. } PACKED UEFI_IMAGE_LOAD_EVENT;
  106. /*
  107. These structs represent a GUID Partition Table, and are defined in the TGC PC
  108. Client Platform Firmware Profile Specification Revision 1.04 Section 9.4.
  109. The struct members are defined in the UEFI Specification Version 2.8
  110. Section 5.3
  111. */
  112. typedef struct {
  113. UINT64 Signature;
  114. UINT32 Revision;
  115. UINT32 HeaderSize;
  116. UINT32 HeaderCRC32;
  117. UINT32 Reserved;
  118. UINT64 MyLBA;
  119. UINT64 AlternateLBA;
  120. UINT64 FirstUsableLBA;
  121. UINT64 LastUsableLBA;
  122. BYTE DiskGUID[16];
  123. UINT64 PartitionEntryLBA;
  124. UINT32 NumberOfPartitionEntries;
  125. UINT32 SizeOfPartitionEntry;
  126. UINT32 PartitionEntryArrayCRC32;
  127. } PACKED UEFI_PARTITION_TABLE_HEADER;
  128. typedef struct {
  129. BYTE PartitionTypeGUID[16];
  130. BYTE UniquePartitionGUID[16];
  131. UINT64 StartingLBA;
  132. UINT64 EndingLBA;
  133. UINT64 Attributes;
  134. BYTE PartitionName[72];
  135. } PACKED UEFI_PARTITION_ENTRY;
  136. typedef struct {
  137. UEFI_PARTITION_TABLE_HEADER UEFIPartitionHeader;
  138. UINT64 NumberOfPartitions;
  139. UEFI_PARTITION_ENTRY Partitions[];
  140. } PACKED UEFI_GPT_DATA;
  141. /*
  142. * An UEFI signature database is represented as a concatenated list of
  143. * EFI_SIGNATURE_LIST, which contains one or more EFI_SIGNATURE_DATA. These
  144. * structs are described in more details in UEFI Spec Section 32.4.1
  145. */
  146. typedef struct {
  147. BYTE SignatureType[16];
  148. UINT32 SignatureListSize;
  149. UINT32 SignatureHeaderSize;
  150. UINT32 SignatureSize;
  151. // BYTE SignatureHeader[SignatureHeaderSize];
  152. // BYTE Signatures[][SignatureSize];
  153. } PACKED EFI_SIGNATURE_LIST;
  154. typedef struct {
  155. BYTE SignatureOwner[16];
  156. BYTE SignatureData[];
  157. } PACKED EFI_SIGNATURE_DATA;
  158. /*
  159. * EFI_LOAD_OPTION describes a load option variable. This struct is described
  160. * in more details in UEFI Spec Section 3.1.3
  161. */
  162. typedef struct {
  163. UINT32 Attributes;
  164. UINT16 FilePathListLength;
  165. UINT16 Description[];
  166. // EFI_DEVICE_PATH_PROTOCOL FilePathList[];
  167. // UINT8 OptionalData[];
  168. } PACKED EFI_LOAD_OPTION;
  169. #endif