TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgEventLogRecordLib.c
Go to the documentation of this file.
1
9#include <Uefi/UefiBaseType.h>
10#include <Pi/PiFirmwareVolume.h>
11
13#include <Library/DebugLib.h>
15#include <Library/PcdLib.h>
16#include <Library/PrintLib.h>
19
21
33VOID *
36 IN UINT64 FvLength
37 )
38{
41
42 if (FvBase >= MAX_ADDRESS) {
43 return NULL;
44 }
45
46 if (FvLength >= MAX_ADDRESS - FvBase) {
47 return NULL;
48 }
49
50 if (FvLength < sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {
51 return NULL;
52 }
53
54 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvBase;
55 if (FvHeader->Signature != EFI_FVH_SIGNATURE) {
56 return NULL;
57 }
58
59 if (FvHeader->ExtHeaderOffset < sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {
60 return NULL;
61 }
62
63 if (FvHeader->ExtHeaderOffset + sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER) > FvLength) {
64 return NULL;
65 }
66
67 FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(UINTN)(FvBase + FvHeader->ExtHeaderOffset);
68
69 return &FvExtHeader->FvName;
70}
71
86EFIAPI
88 IN UINT32 PcrIndex,
89 IN CHAR8 *Description OPTIONAL,
90 IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase,
91 IN UINT64 FirmwareBlobLength
92 )
93{
96 VOID *FvName;
97 UINT32 EventType;
98 VOID *EventLog;
99 UINT32 EventLogSize;
100 EFI_STATUS Status;
101
102 FvName = TpmMeasurementGetFvName (FirmwareBlobBase, FirmwareBlobLength);
103
104 if (((Description != NULL) || (FvName != NULL)) &&
105 (PcdGet32 (PcdTcgPfpMeasurementRevision) >= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2_REV_105))
106 {
107 if (Description != NULL) {
108 AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "%a", Description);
109 } else {
110 AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "Fv(%g)", FvName);
111 }
112
113 FvBlob2.BlobDescriptionSize = sizeof (FvBlob2.BlobDescription);
114 FvBlob2.BlobBase = FirmwareBlobBase;
115 FvBlob2.BlobLength = FirmwareBlobLength;
116
117 EventType = EV_EFI_PLATFORM_FIRMWARE_BLOB2;
118 EventLog = &FvBlob2;
119 EventLogSize = sizeof (FvBlob2);
120 } else {
121 FvBlob.BlobBase = FirmwareBlobBase;
122 FvBlob.BlobLength = FirmwareBlobLength;
123
124 EventType = EV_EFI_PLATFORM_FIRMWARE_BLOB;
125 EventLog = &FvBlob;
126 EventLogSize = sizeof (FvBlob);
127 }
128
129 Status = TpmMeasureAndLogData (
130 PcrIndex,
131 EventType,
132 EventLog,
133 EventLogSize,
134 (VOID *)(UINTN)FirmwareBlobBase,
135 FirmwareBlobLength
136 );
137
138 return Status;
139}
140
156EFIAPI
158 IN UINT32 PcrIndex,
159 IN CHAR8 *Description OPTIONAL,
160 IN EFI_GUID *TableGuid,
161 IN VOID *TableAddress,
162 IN UINTN TableLength
163 )
164{
165 EFI_HANDOFF_TABLE_POINTERS HandoffTables;
166 HANDOFF_TABLE_POINTERS2_STRUCT HandoffTables2;
167 UINT32 EventType;
168 VOID *EventLog;
169 UINT32 EventLogSize;
170 EFI_STATUS Status;
171
172 if ((Description != NULL) &&
173 (PcdGet32 (PcdTcgPfpMeasurementRevision) >= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2_REV_105))
174 {
175 AsciiSPrint ((CHAR8 *)HandoffTables2.TableDescription, sizeof (HandoffTables2.TableDescription), "%a", Description);
176
177 HandoffTables2.TableDescriptionSize = sizeof (HandoffTables2.TableDescription);
178 HandoffTables2.NumberOfTables = 1;
179 CopyGuid (&(HandoffTables2.TableEntry[0].VendorGuid), TableGuid);
180 HandoffTables2.TableEntry[0].VendorTable = TableAddress;
181
182 EventType = EV_EFI_HANDOFF_TABLES2;
183 EventLog = &HandoffTables2;
184 EventLogSize = sizeof (HandoffTables2);
185 } else {
186 HandoffTables.NumberOfTables = 1;
187 CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), TableGuid);
188 HandoffTables.TableEntry[0].VendorTable = TableAddress;
189
190 EventType = EV_EFI_HANDOFF_TABLES;
191 EventLog = &HandoffTables;
192 EventLogSize = sizeof (HandoffTables);
193 }
194
195 Status = TpmMeasureAndLogData (
196 PcrIndex,
197 EventType,
198 EventLog,
199 EventLogSize,
200 TableAddress,
201 TableLength
202 );
203 return Status;
204}
UINT64 UINTN
#define MAX_ADDRESS
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
EFI_STATUS EFIAPI MeasureHandoffTable(IN UINT32 PcrIndex, IN CHAR8 *Description OPTIONAL, IN EFI_GUID *TableGuid, IN VOID *TableAddress, IN UINTN TableLength)
VOID * TpmMeasurementGetFvName(IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
EFI_STATUS EFIAPI MeasureFirmwareBlob(IN UINT32 PcrIndex, IN CHAR8 *Description OPTIONAL, IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase, IN UINT64 FirmwareBlobLength)
EFI_STATUS EFIAPI TpmMeasureAndLogData(IN UINT32 PcrIndex, IN UINT32 EventType, IN VOID *EventLog, IN UINT32 LogLen, IN VOID *HashData, IN UINT64 HashDataLen)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
Definition: Base.h:213