2 This module implements Tcg2 Protocol.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/Acpi.h>
17 #include <IndustryStandard/PeImage.h>
18 #include <IndustryStandard/TcpaAcpi.h>
20 #include <Guid/GlobalVariable.h>
21 #include <Guid/HobList.h>
22 #include <Guid/TcgEventHob.h>
23 #include <Guid/EventGroup.h>
24 #include <Guid/EventExitBootServiceFailed.h>
25 #include <Guid/ImageAuthentication.h>
26 #include <Guid/TpmInstance.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/MpService.h>
30 #include <Protocol/VariableWrite.h>
31 #include <Protocol/Tcg2Protocol.h>
32 #include <Protocol/TrEEProtocol.h>
34 #include <Library/DebugLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/UefiRuntimeServicesTableLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/HobLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/BaseLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/PrintLib.h>
43 #include <Library/Tpm2CommandLib.h>
44 #include <Library/PcdLib.h>
45 #include <Library/UefiLib.h>
46 #include <Library/Tpm2DeviceLib.h>
47 #include <Library/HashLib.h>
48 #include <Library/PerformanceLib.h>
49 #include <Library/ReportStatusCodeLib.h>
50 #include <Library/Tcg2PhysicalPresenceLib.h>
52 #define PERF_ID_TCG2_DXE 0x3120
59 #define TCG2_DEFAULT_MAX_COMMAND_SIZE 0x1000
60 #define TCG2_DEFAULT_MAX_RESPONSE_SIZE 0x1000
64 EFI_TCG2_EVENT_LOG_FORMAT LogFormat
;
65 } TCG2_EVENT_INFO_STRUCT
;
67 TCG2_EVENT_INFO_STRUCT mTcg2EventInfo
[] = {
68 {&gTcgEventEntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
},
69 {&gTcgEvent2EntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
},
72 #define TCG_EVENT_LOG_AREA_COUNT_MAX 2
75 EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
;
76 EFI_PHYSICAL_ADDRESS Lasa
;
80 BOOLEAN EventLogStarted
;
81 BOOLEAN EventLogTruncated
;
82 } TCG_EVENT_LOG_AREA_STRUCT
;
84 typedef struct _TCG_DXE_DATA
{
85 EFI_TCG2_BOOT_SERVICE_CAPABILITY BsCap
;
86 TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
87 BOOLEAN GetEventLogCalled
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
88 TCG_EVENT_LOG_AREA_STRUCT FinalEventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
89 EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
92 TCG_DXE_DATA mTcgDxeData
= {
94 sizeof (EFI_TCG2_BOOT_SERVICE_CAPABILITY
), // Size
95 { 1, 1 }, // StructureVersion
96 { 1, 1 }, // ProtocolVersion
97 EFI_TCG2_BOOT_HASH_ALG_SHA1
, // HashAlgorithmBitmap
98 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
, // SupportedEventLogs
99 TRUE
, // TPMPresentFlag
100 TCG2_DEFAULT_MAX_COMMAND_SIZE
, // MaxCommandSize
101 TCG2_DEFAULT_MAX_RESPONSE_SIZE
, // MaxResponseSize
103 0, // NumberOfPCRBanks
108 UINTN mBootAttempts
= 0;
109 CHAR16 mBootVarName
[] = L
"BootOrder";
111 VARIABLE_TYPE mVariableType
[] = {
112 {EFI_SECURE_BOOT_MODE_NAME
, &gEfiGlobalVariableGuid
},
113 {EFI_PLATFORM_KEY_NAME
, &gEfiGlobalVariableGuid
},
114 {EFI_KEY_EXCHANGE_KEY_NAME
, &gEfiGlobalVariableGuid
},
115 {EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
},
116 {EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
},
119 EFI_HANDLE mImageHandle
;
122 Measure PE image into TPM log based on the authenticode image hashing in
123 PE/COFF Specification 8.0 Appendix A.
125 Caution: This function may receive untrusted input.
126 PE/COFF image is external input, so this function will validate its data structure
127 within this image buffer before use.
129 @param[in] PCRIndex TPM PCR index
130 @param[in] ImageAddress Start address of image buffer.
131 @param[in] ImageSize Image size
132 @param[out] DigestList Digeest list of this image.
134 @retval EFI_SUCCESS Successfully measure image.
135 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
136 @retval other error value
139 MeasurePeImageAndExtend (
141 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
143 OUT TPML_DIGEST_VALUES
*DigestList
148 This function dump raw data.
151 @param Size raw data size
161 for (Index
= 0; Index
< Size
; Index
++) {
162 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
168 This function dump raw data with colume format.
171 @param Size raw data size
184 #define COLUME_SIZE (16 * 2)
186 Count
= Size
/ COLUME_SIZE
;
187 Left
= Size
% COLUME_SIZE
;
188 for (Index
= 0; Index
< Count
; Index
++) {
189 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
190 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
191 DEBUG ((EFI_D_INFO
, "\n"));
195 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
196 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
197 DEBUG ((EFI_D_INFO
, "\n"));
202 Check if buffer is all zero.
204 @param[in] Buffer Buffer to be checked.
205 @param[in] BufferSize Size of buffer to be checked.
207 @retval TRUE Buffer is all zero.
208 @retval FALSE Buffer is not all zero.
220 for (Index
= 0; Index
< BufferSize
; Index
++) {
221 if (BufferData
[Index
] != 0) {
229 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
230 Caller is responsible to free LocationBuf.
232 @param[out] LocationBuf Returns Processor Location Buffer.
233 @param[out] Num Returns processor number.
235 @retval EFI_SUCCESS Operation completed successfully.
236 @retval EFI_UNSUPPORTED MpService protocol not found.
240 GetProcessorsCpuLocation (
241 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
246 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
248 UINTN EnabledProcessorNum
;
249 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
250 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
253 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
254 if (EFI_ERROR (Status
)) {
256 // MP protocol is not installed
258 return EFI_UNSUPPORTED
;
261 Status
= MpProtocol
->GetNumberOfProcessors(
266 if (EFI_ERROR(Status
)){
270 Status
= gBS
->AllocatePool(
272 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
273 (VOID
**) &ProcessorLocBuf
275 if (EFI_ERROR(Status
)){
280 // Get each processor Location info
282 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
283 Status
= MpProtocol
->GetProcessorInfo(
288 if (EFI_ERROR(Status
)){
289 FreePool(ProcessorLocBuf
);
294 // Get all Processor Location info & measure
297 &ProcessorLocBuf
[Index
],
298 &ProcessorInfo
.Location
,
299 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
303 *LocationBuf
= ProcessorLocBuf
;
310 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
311 capability information and state information.
313 @param[in] This Indicates the calling context
314 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
315 structure and sets the size field to the size of the structure allocated.
316 The callee fills in the fields with the EFI protocol capability information
317 and the current EFI TCG2 state information up to the number of fields which
318 fit within the size of the structure passed in.
320 @retval EFI_SUCCESS Operation completed successfully.
321 @retval EFI_DEVICE_ERROR The command was unsuccessful.
322 The ProtocolCapability variable will not be populated.
323 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
324 The ProtocolCapability variable will not be populated.
325 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
326 It will be partially populated (required Size field will be set).
331 IN EFI_TCG2_PROTOCOL
*This
,
332 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
335 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability ...\n"));
337 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
338 return EFI_INVALID_PARAMETER
;
341 DEBUG ((EFI_D_INFO
, "Size - 0x%x\n", ProtocolCapability
->Size
));
342 DEBUG ((EFI_D_INFO
, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)));
344 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
346 // Handle the case that firmware support 1.1 but OS only support 1.0.
348 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
349 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
350 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
351 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
352 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
353 ProtocolCapability
->StructureVersion
.Major
= 1;
354 ProtocolCapability
->StructureVersion
.Minor
= 0;
355 ProtocolCapability
->ProtocolVersion
.Major
= 1;
356 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
357 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
361 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
362 return EFI_BUFFER_TOO_SMALL
;
365 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
366 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
371 This function dump PCR event.
373 @param[in] EventHdr TCG PCR event structure.
377 IN TCG_PCR_EVENT_HDR
*EventHdr
382 DEBUG ((EFI_D_INFO
, " Event:\n"));
383 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
384 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
385 DEBUG ((EFI_D_INFO
, " Digest - "));
386 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
387 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
389 DEBUG ((EFI_D_INFO
, "\n"));
390 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
391 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
395 This function dump TCG_EfiSpecIDEventStruct.
397 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
400 DumpTcgEfiSpecIdEventStruct (
401 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
404 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
406 UINT8
*VendorInfoSize
;
408 UINT32 NumberOfAlgorithms
;
410 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
411 DEBUG ((EFI_D_INFO
, " signature - '"));
412 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
413 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
415 DEBUG ((EFI_D_INFO
, "'\n"));
416 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
417 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
418 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
420 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
421 DEBUG ((EFI_D_INFO
, " NumberOfAlgorithms - 0x%08x\n", NumberOfAlgorithms
));
423 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
424 for (Index
= 0; Index
< NumberOfAlgorithms
; Index
++) {
425 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
426 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", DigestSize
[Index
].algorithmId
));
427 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", DigestSize
[Index
].digestSize
));
429 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
430 DEBUG ((EFI_D_INFO
, " VendorInfoSize - 0x%02x\n", *VendorInfoSize
));
431 VendorInfo
= VendorInfoSize
+ 1;
432 DEBUG ((EFI_D_INFO
, " VendorInfo - "));
433 for (Index
= 0; Index
< *VendorInfoSize
; Index
++) {
434 DEBUG ((EFI_D_INFO
, "%02x ", VendorInfo
[Index
]));
436 DEBUG ((EFI_D_INFO
, "\n"));
440 This function get size of TCG_EfiSpecIDEventStruct.
442 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
445 GetTcgEfiSpecIdEventStructSize (
446 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
449 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
450 UINT8
*VendorInfoSize
;
451 UINT32 NumberOfAlgorithms
;
453 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
455 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
456 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
457 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (NumberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*VendorInfoSize
);
461 This function dump PCR event 2.
463 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
467 IN TCG_PCR_EVENT2
*TcgPcrEvent2
473 TPMI_ALG_HASH HashAlgo
;
479 DEBUG ((EFI_D_INFO
, " Event:\n"));
480 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
481 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
483 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
485 DigestCount
= TcgPcrEvent2
->Digest
.count
;
486 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
487 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
488 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
489 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
490 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
491 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
492 for (Index
= 0; Index
< DigestSize
; Index
++) {
493 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
495 DEBUG ((EFI_D_INFO
, "\n"));
499 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
500 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
502 DEBUG ((EFI_D_INFO
, "\n"));
503 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
505 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
506 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
507 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
508 InternalDumpHex (EventBuffer
, EventSize
);
512 This function returns size of TCG PCR event 2.
514 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
516 @return size of TCG PCR event 2.
520 IN TCG_PCR_EVENT2
*TcgPcrEvent2
525 TPMI_ALG_HASH HashAlgo
;
531 DigestCount
= TcgPcrEvent2
->Digest
.count
;
532 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
533 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
534 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
535 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
539 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
540 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
542 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
544 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
545 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
547 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
551 This function dump event log.
553 @param[in] EventLogFormat The type of the event log for which the information is requested.
554 @param[in] EventLogLocation A pointer to the memory address of the event log.
555 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
556 address of the start of the last entry in the event log in memory.
557 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
561 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
562 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
563 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
564 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
567 TCG_PCR_EVENT_HDR
*EventHdr
;
568 TCG_PCR_EVENT2
*TcgPcrEvent2
;
569 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
570 UINTN NumberOfEvents
;
572 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
574 switch (EventLogFormat
) {
575 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
576 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
577 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
578 DumpEvent (EventHdr
);
579 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
581 if (FinalEventsTable
== NULL
) {
582 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
584 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
585 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
586 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
588 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
589 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
590 DumpEvent (EventHdr
);
591 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
595 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
599 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
600 DumpEvent (EventHdr
);
602 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
603 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
605 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
606 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
607 DumpEvent2 (TcgPcrEvent2
);
608 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
611 if (FinalEventsTable
== NULL
) {
612 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
614 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
615 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
616 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
618 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
619 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
620 DumpEvent2 (TcgPcrEvent2
);
621 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
631 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
632 retrieve the address of a given event log and its last entry.
634 @param[in] This Indicates the calling context
635 @param[in] EventLogFormat The type of the event log for which the information is requested.
636 @param[out] EventLogLocation A pointer to the memory address of the event log.
637 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
638 address of the start of the last entry in the event log in memory.
639 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
640 have exceeded the area allocated for events, this value is set to TRUE.
641 Otherwise, the value will be FALSE and the Event Log will be complete.
643 @retval EFI_SUCCESS Operation completed successfully.
644 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
645 (e.g. asking for an event log whose format is not supported).
650 IN EFI_TCG2_PROTOCOL
*This
,
651 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
652 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
653 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
654 OUT BOOLEAN
*EventLogTruncated
659 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
662 return EFI_INVALID_PARAMETER
;
665 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
666 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
671 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
672 return EFI_INVALID_PARAMETER
;
675 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
676 return EFI_INVALID_PARAMETER
;
679 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
680 if (EventLogLocation
!= NULL
) {
681 *EventLogLocation
= 0;
683 if (EventLogLastEntry
!= NULL
) {
684 *EventLogLastEntry
= 0;
686 if (EventLogTruncated
!= NULL
) {
687 *EventLogTruncated
= FALSE
;
692 if (EventLogLocation
!= NULL
) {
693 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
694 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
697 if (EventLogLastEntry
!= NULL
) {
698 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
699 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
701 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
703 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
706 if (EventLogTruncated
!= NULL
) {
707 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
708 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
711 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
713 // Dump Event Log for debug purpose
714 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
715 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
719 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
720 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
722 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
728 Add a new entry to the Event Log.
730 @param[in, out] EventLogPtr Pointer to the Event Log data.
731 @param[in, out] LogSize Size of the Event Log.
732 @param[in] MaxSize Maximum size of the Event Log.
733 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
734 @param[in] NewEventHdrSize New event header size.
735 @param[in] NewEventData Pointer to the new event data.
736 @param[in] NewEventSize New event data size.
738 @retval EFI_SUCCESS The new event log entry was added.
739 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
744 IN OUT UINT8
**EventLogPtr
,
745 IN OUT UINTN
*LogSize
,
747 IN VOID
*NewEventHdr
,
748 IN UINT32 NewEventHdrSize
,
749 IN UINT8
*NewEventData
,
750 IN UINT32 NewEventSize
755 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
756 return EFI_OUT_OF_RESOURCES
;
759 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
761 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
762 return EFI_OUT_OF_RESOURCES
;
765 if (NewLogSize
+ *LogSize
> MaxSize
) {
766 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
767 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
768 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
769 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
770 return EFI_OUT_OF_RESOURCES
;
773 *EventLogPtr
+= *LogSize
;
774 *LogSize
+= NewLogSize
;
775 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
777 *EventLogPtr
+ NewEventHdrSize
,
785 Add a new entry to the Event Log.
787 @param[in] EventLogFormat The type of the event log for which the information is requested.
788 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
789 @param[in] NewEventHdrSize New event header size.
790 @param[in] NewEventData Pointer to the new event data.
791 @param[in] NewEventSize New event data size.
793 @retval EFI_SUCCESS The new event log entry was added.
794 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
799 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
800 IN VOID
*NewEventHdr
,
801 IN UINT32 NewEventHdrSize
,
802 IN UINT8
*NewEventData
,
803 IN UINT32 NewEventSize
808 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
810 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
811 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
816 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
817 return EFI_INVALID_PARAMETER
;
820 if (!mTcgDxeData
.GetEventLogCalled
[Index
]) {
821 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
823 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
826 if (EventLogAreaStruct
->EventLogTruncated
) {
827 return EFI_VOLUME_FULL
;
830 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
831 Status
= TcgCommLogEvent (
832 &EventLogAreaStruct
->LastEvent
,
833 &EventLogAreaStruct
->EventLogSize
,
834 (UINTN
)EventLogAreaStruct
->Laml
,
841 if (Status
== EFI_DEVICE_ERROR
) {
842 return EFI_DEVICE_ERROR
;
843 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
844 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
845 return EFI_VOLUME_FULL
;
846 } else if (Status
== EFI_SUCCESS
) {
847 EventLogAreaStruct
->EventLogStarted
= TRUE
;
848 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
849 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
857 This function get digest from digest list.
859 @param HashAlg digest algorithm
860 @param DigestList digest list
863 @retval EFI_SUCCESS Sha1Digest is found and returned.
864 @retval EFI_NOT_FOUND Sha1Digest is not found.
867 Tpm2GetDigestFromDigestList (
868 IN TPMI_ALG_HASH HashAlg
,
869 IN TPML_DIGEST_VALUES
*DigestList
,
876 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
877 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
878 if (DigestList
->digests
[Index
].hashAlg
== HashAlg
) {
881 &DigestList
->digests
[Index
].digest
,
888 return EFI_NOT_FOUND
;
892 Get TPML_DIGEST_VALUES data size.
894 @param[in] DigestList TPML_DIGEST_VALUES data.
896 @return TPML_DIGEST_VALUES data size.
900 IN TPML_DIGEST_VALUES
*DigestList
907 TotalSize
= sizeof(DigestList
->count
);
908 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
909 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
910 TotalSize
+= sizeof(DigestList
->digests
[Index
].hashAlg
) + DigestSize
;
917 Get TPML_DIGEST_VALUES compact binary buffer size.
919 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
921 @return TPML_DIGEST_VALUES compact binary buffer size.
924 GetDigestListBinSize (
925 IN VOID
*DigestListBin
932 TPMI_ALG_HASH HashAlg
;
934 Count
= ReadUnaligned32 (DigestListBin
);
935 TotalSize
= sizeof(Count
);
936 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
937 for (Index
= 0; Index
< Count
; Index
++) {
938 HashAlg
= ReadUnaligned16 (DigestListBin
);
939 TotalSize
+= sizeof(HashAlg
);
940 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
942 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
943 TotalSize
+= DigestSize
;
944 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
951 Return if hash alg is supported in TPM PCR bank.
953 @param HashAlg Hash algorithm to be checked.
955 @retval TRUE Hash algorithm is supported.
956 @retval FALSE Hash algorithm is not supported.
959 IsHashAlgSupportedInPcrBank (
960 IN TPMI_ALG_HASH HashAlg
965 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
970 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
975 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
980 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
984 case TPM_ALG_SM3_256
:
985 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
995 Copy TPML_DIGEST_VALUES into a buffer
997 @param[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
998 @param[in] DigestList TPML_DIGEST_VALUES to be copied.
1000 @return The end of buffer to hold TPML_DIGEST_VALUES.
1003 CopyDigestListToBuffer (
1004 IN OUT VOID
*Buffer
,
1005 IN TPML_DIGEST_VALUES
*DigestList
1011 CopyMem (Buffer
, &DigestList
->count
, sizeof(DigestList
->count
));
1012 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->count
);
1013 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
1014 if (!IsHashAlgSupportedInPcrBank (DigestList
->digests
[Index
].hashAlg
)) {
1015 DEBUG ((EFI_D_ERROR
, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList
->digests
[Index
].hashAlg
));
1018 CopyMem (Buffer
, &DigestList
->digests
[Index
].hashAlg
, sizeof(DigestList
->digests
[Index
].hashAlg
));
1019 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->digests
[Index
].hashAlg
);
1020 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
1021 CopyMem (Buffer
, &DigestList
->digests
[Index
].digest
, DigestSize
);
1022 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
1029 Add a new entry to the Event Log.
1031 @param[in] DigestList A list of digest.
1032 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1033 @param[in] NewEventData Pointer to the new event data.
1035 @retval EFI_SUCCESS The new event log entry was added.
1036 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1039 TcgDxeLogHashEvent (
1040 IN TPML_DIGEST_VALUES
*DigestList
,
1041 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1042 IN UINT8
*NewEventData
1048 EFI_STATUS RetStatus
;
1049 TCG_PCR_EVENT2 TcgPcrEvent2
;
1050 UINT8
*DigestBuffer
;
1052 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
1054 RetStatus
= EFI_SUCCESS
;
1055 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1056 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1057 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
1058 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1059 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1060 Status
= Tpm2GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
1061 if (!EFI_ERROR (Status
)) {
1063 // Enter critical region
1065 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1066 Status
= TcgDxeLogEvent (
1067 mTcg2EventInfo
[Index
].LogFormat
,
1069 sizeof(TCG_PCR_EVENT_HDR
),
1071 NewEventHdr
->EventSize
1073 if (Status
!= EFI_SUCCESS
) {
1076 gBS
->RestoreTPL (OldTpl
);
1078 // Exit critical region
1082 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1083 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1084 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1085 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1086 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1087 DigestBuffer
= CopyDigestListToBuffer (DigestBuffer
, DigestList
);
1088 CopyMem (DigestBuffer
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1089 DigestBuffer
= DigestBuffer
+ sizeof(NewEventHdr
->EventSize
);
1092 // Enter critical region
1094 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1095 Status
= TcgDxeLogEvent (
1096 mTcg2EventInfo
[Index
].LogFormat
,
1098 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListSize (DigestList
) + sizeof(TcgPcrEvent2
.EventSize
),
1100 NewEventHdr
->EventSize
1102 if (Status
!= EFI_SUCCESS
) {
1105 gBS
->RestoreTPL (OldTpl
);
1107 // Exit critical region
1118 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1119 and add an entry to the Event Log.
1121 @param[in] Flags Bitmap providing additional information.
1122 @param[in] HashData Physical address of the start of the data buffer
1123 to be hashed, extended, and logged.
1124 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1125 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1126 @param[in] NewEventData Pointer to the new event data.
1128 @retval EFI_SUCCESS Operation completed successfully.
1129 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1130 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1134 TcgDxeHashLogExtendEvent (
1137 IN UINT64 HashDataLen
,
1138 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1139 IN UINT8
*NewEventData
1143 TPML_DIGEST_VALUES DigestList
;
1145 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1146 return EFI_DEVICE_ERROR
;
1149 Status
= HashAndExtend (
1150 NewEventHdr
->PCRIndex
,
1155 if (!EFI_ERROR (Status
)) {
1156 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1157 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1161 if (Status
== EFI_DEVICE_ERROR
) {
1162 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1163 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1164 REPORT_STATUS_CODE (
1165 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1166 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1174 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1175 an opportunity to extend and optionally log events without requiring
1176 knowledge of actual TPM commands.
1177 The extend operation will occur even if this function cannot create an event
1178 log entry (e.g. due to the event log being full).
1180 @param[in] This Indicates the calling context
1181 @param[in] Flags Bitmap providing additional information.
1182 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1183 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1184 @param[in] Event Pointer to data buffer containing information about the event.
1186 @retval EFI_SUCCESS Operation completed successfully.
1187 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1188 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1189 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1190 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1194 Tcg2HashLogExtendEvent (
1195 IN EFI_TCG2_PROTOCOL
*This
,
1197 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1198 IN UINT64 DataToHashLen
,
1199 IN EFI_TCG2_EVENT
*Event
1203 TCG_PCR_EVENT_HDR NewEventHdr
;
1204 TPML_DIGEST_VALUES DigestList
;
1206 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent ...\n"));
1208 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1209 return EFI_INVALID_PARAMETER
;
1212 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1213 return EFI_DEVICE_ERROR
;
1216 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1217 return EFI_INVALID_PARAMETER
;
1220 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1221 return EFI_INVALID_PARAMETER
;
1224 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1225 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1226 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1227 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1228 Status
= MeasurePeImageAndExtend (
1229 NewEventHdr
.PCRIndex
,
1231 (UINTN
)DataToHashLen
,
1234 if (!EFI_ERROR (Status
)) {
1235 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1236 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1239 if (Status
== EFI_DEVICE_ERROR
) {
1240 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status
));
1241 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1242 REPORT_STATUS_CODE (
1243 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1244 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1248 Status
= TcgDxeHashLogExtendEvent (
1250 (UINT8
*) (UINTN
) DataToHash
,
1256 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1261 This service enables the sending of commands to the TPM.
1263 @param[in] This Indicates the calling context
1264 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1265 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1266 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1267 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1269 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1270 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1271 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1272 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1277 IN EFI_TCG2_PROTOCOL
*This
,
1278 IN UINT32 InputParameterBlockSize
,
1279 IN UINT8
*InputParameterBlock
,
1280 IN UINT32 OutputParameterBlockSize
,
1281 IN UINT8
*OutputParameterBlock
1286 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1288 if ((This
== NULL
) ||
1289 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1290 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1291 return EFI_INVALID_PARAMETER
;
1294 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1295 return EFI_DEVICE_ERROR
;
1298 if (InputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxCommandSize
) {
1299 return EFI_INVALID_PARAMETER
;
1301 if (OutputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxResponseSize
) {
1302 return EFI_INVALID_PARAMETER
;
1305 Status
= Tpm2SubmitCommand (
1306 InputParameterBlockSize
,
1307 InputParameterBlock
,
1308 &OutputParameterBlockSize
,
1309 OutputParameterBlock
1311 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1316 This service returns the currently active PCR banks.
1318 @param[in] This Indicates the calling context
1319 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1321 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1322 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1326 Tcg2GetActivePCRBanks (
1327 IN EFI_TCG2_PROTOCOL
*This
,
1328 OUT UINT32
*ActivePcrBanks
1331 if (ActivePcrBanks
== NULL
) {
1332 return EFI_INVALID_PARAMETER
;
1334 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1339 This service sets the currently active PCR banks.
1341 @param[in] This Indicates the calling context
1342 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1344 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1345 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1349 Tcg2SetActivePCRBanks (
1350 IN EFI_TCG2_PROTOCOL
*This
,
1351 IN UINT32 ActivePcrBanks
1357 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1359 if (ActivePcrBanks
== 0) {
1360 return EFI_INVALID_PARAMETER
;
1362 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1363 return EFI_INVALID_PARAMETER
;
1365 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1367 // Need clear previous SET_PCR_BANKS setting
1369 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1371 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1374 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1375 Status
= EFI_SUCCESS
;
1376 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1377 Status
= EFI_OUT_OF_RESOURCES
;
1378 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1379 Status
= EFI_UNSUPPORTED
;
1381 Status
= EFI_DEVICE_ERROR
;
1384 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1390 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1392 @param[in] This Indicates the calling context
1393 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1394 @param[out] Response The response from the SetActivePcrBank request.
1396 @retval EFI_SUCCESS The result value could be returned.
1397 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1401 Tcg2GetResultOfSetActivePcrBanks (
1402 IN EFI_TCG2_PROTOCOL
*This
,
1403 OUT UINT32
*OperationPresent
,
1404 OUT UINT32
*Response
1409 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1410 return EFI_INVALID_PARAMETER
;
1413 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1414 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1417 return EFI_UNSUPPORTED
;
1421 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1424 Tcg2HashLogExtendEvent
,
1426 Tcg2GetActivePCRBanks
,
1427 Tcg2SetActivePCRBanks
,
1428 Tcg2GetResultOfSetActivePcrBanks
,
1432 Initialize the Event Log and log events passed from the PEI phase.
1434 @retval EFI_SUCCESS Operation completed successfully.
1435 @retval EFI_OUT_OF_RESOURCES Out of memory.
1445 EFI_PEI_HOB_POINTERS GuidHob
;
1446 EFI_PHYSICAL_ADDRESS Lasa
;
1448 UINT32 DigestListBinSize
;
1450 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1451 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1452 TCG_PCR_EVENT_HDR FirstPcrEvent
;
1453 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
1454 TCG_EfiSpecIdEventAlgorithmSize
*TempDigestSize
;
1455 UINT8
*VendorInfoSize
;
1456 UINT32 NumberOfAlgorithms
;
1458 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1461 // 1. Create Log Area
1463 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1464 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1465 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1466 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1467 Status
= gBS
->AllocatePages (
1470 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen
)),
1473 if (EFI_ERROR (Status
)) {
1476 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1477 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcgLogAreaMinLen
);
1479 // To initialize them as 0xFF is recommended
1480 // because the OS can know the last entry for that.
1482 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcgLogAreaMinLen
), 0xFF);
1484 // Create first entry for Log Header Entry Data
1486 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1488 // TcgEfiSpecIdEventStruct
1490 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1491 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1492 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1493 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1494 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1495 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1496 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1497 NumberOfAlgorithms
= 0;
1498 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
1499 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1500 TempDigestSize
= DigestSize
;
1501 TempDigestSize
+= NumberOfAlgorithms
;
1502 TempDigestSize
->algorithmId
= TPM_ALG_SHA1
;
1503 TempDigestSize
->digestSize
= SHA1_DIGEST_SIZE
;
1504 NumberOfAlgorithms
++;
1506 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1507 TempDigestSize
= DigestSize
;
1508 TempDigestSize
+= NumberOfAlgorithms
;
1509 TempDigestSize
->algorithmId
= TPM_ALG_SHA256
;
1510 TempDigestSize
->digestSize
= SHA256_DIGEST_SIZE
;
1511 NumberOfAlgorithms
++;
1513 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1514 TempDigestSize
= DigestSize
;
1515 TempDigestSize
+= NumberOfAlgorithms
;
1516 TempDigestSize
->algorithmId
= TPM_ALG_SHA384
;
1517 TempDigestSize
->digestSize
= SHA384_DIGEST_SIZE
;
1518 NumberOfAlgorithms
++;
1520 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1521 TempDigestSize
= DigestSize
;
1522 TempDigestSize
+= NumberOfAlgorithms
;
1523 TempDigestSize
->algorithmId
= TPM_ALG_SHA512
;
1524 TempDigestSize
->digestSize
= SHA512_DIGEST_SIZE
;
1525 NumberOfAlgorithms
++;
1527 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1528 TempDigestSize
= DigestSize
;
1529 TempDigestSize
+= NumberOfAlgorithms
;
1530 TempDigestSize
->algorithmId
= TPM_ALG_SM3_256
;
1531 TempDigestSize
->digestSize
= SM3_256_DIGEST_SIZE
;
1532 NumberOfAlgorithms
++;
1534 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &NumberOfAlgorithms
, sizeof(NumberOfAlgorithms
));
1535 TempDigestSize
= DigestSize
;
1536 TempDigestSize
+= NumberOfAlgorithms
;
1537 VendorInfoSize
= (UINT8
*)TempDigestSize
;
1538 *VendorInfoSize
= 0;
1543 FirstPcrEvent
.PCRIndex
= 0;
1544 FirstPcrEvent
.EventType
= EV_NO_ACTION
;
1545 ZeroMem (&FirstPcrEvent
.Digest
, sizeof(FirstPcrEvent
.Digest
));
1546 FirstPcrEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1551 Status
= TcgDxeLogEvent (
1552 mTcg2EventInfo
[Index
].LogFormat
,
1554 sizeof(FirstPcrEvent
),
1555 (UINT8
*)TcgEfiSpecIdEventStruct
,
1556 FirstPcrEvent
.EventSize
1563 // 2. Create Final Log Area
1565 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1566 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1567 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1568 Status
= gBS
->AllocatePages (
1571 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen
)),
1574 if (EFI_ERROR (Status
)) {
1577 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcg2FinalLogAreaLen
), 0xFF);
1582 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1583 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1584 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1586 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1587 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1588 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcg2FinalLogAreaLen
) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1589 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1590 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1591 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1592 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1594 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1596 // Install to configuration table
1598 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[1]);
1599 if (EFI_ERROR (Status
)) {
1607 // 3. Sync data from PEI to DXE
1609 Status
= EFI_SUCCESS
;
1610 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1611 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1612 GuidHob
.Raw
= GetHobList ();
1613 Status
= EFI_SUCCESS
;
1614 while (!EFI_ERROR (Status
) &&
1615 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1616 TcgEvent
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1617 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1618 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1619 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1620 Status
= TcgDxeLogEvent (
1621 mTcg2EventInfo
[Index
].LogFormat
,
1623 sizeof(TCG_PCR_EVENT_HDR
),
1624 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1625 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1628 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1629 DigestListBinSize
= GetDigestListBinSize ((UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
));
1630 CopyMem (&EventSize
, (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
, sizeof(UINT32
));
1631 Status
= TcgDxeLogEvent (
1632 mTcg2EventInfo
[Index
].LogFormat
,
1634 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1635 (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1648 Measure and log an action string, and extend the measurement result into PCR[5].
1650 @param[in] String A specific string that indicates an Action event.
1652 @retval EFI_SUCCESS Operation completed successfully.
1653 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1661 TCG_PCR_EVENT_HDR TcgEvent
;
1663 TcgEvent
.PCRIndex
= 5;
1664 TcgEvent
.EventType
= EV_EFI_ACTION
;
1665 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1666 return TcgDxeHashLogExtendEvent (
1676 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1678 @retval EFI_SUCCESS Operation completed successfully.
1679 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1683 MeasureHandoffTables (
1688 TCG_PCR_EVENT_HDR TcgEvent
;
1689 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1691 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1693 ProcessorLocBuf
= NULL
;
1694 Status
= EFI_SUCCESS
;
1696 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1699 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1701 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1703 if (!EFI_ERROR(Status
)){
1704 TcgEvent
.PCRIndex
= 1;
1705 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1706 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1708 HandoffTables
.NumberOfTables
= 1;
1709 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1710 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1712 Status
= TcgDxeHashLogExtendEvent (
1714 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1715 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1717 (UINT8
*)&HandoffTables
1720 FreePool(ProcessorLocBuf
);
1728 Measure and log Separator event, and extend the measurement result into a specific PCR.
1730 @param[in] PCRIndex PCR index.
1732 @retval EFI_SUCCESS Operation completed successfully.
1733 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1737 MeasureSeparatorEvent (
1738 IN TPM_PCRINDEX PCRIndex
1741 TCG_PCR_EVENT_HDR TcgEvent
;
1744 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1747 TcgEvent
.PCRIndex
= PCRIndex
;
1748 TcgEvent
.EventType
= EV_SEPARATOR
;
1749 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1750 return TcgDxeHashLogExtendEvent (
1752 (UINT8
*)&EventData
,
1760 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1762 @param[in] PCRIndex PCR Index.
1763 @param[in] EventType Event type.
1764 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1765 @param[in] VendorGuid A unique identifier for the vendor.
1766 @param[in] VarData The content of the variable data.
1767 @param[in] VarSize The size of the variable data.
1769 @retval EFI_SUCCESS Operation completed successfully.
1770 @retval EFI_OUT_OF_RESOURCES Out of memory.
1771 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1776 IN TPM_PCRINDEX PCRIndex
,
1777 IN TCG_EVENTTYPE EventType
,
1779 IN EFI_GUID
*VendorGuid
,
1785 TCG_PCR_EVENT_HDR TcgEvent
;
1786 UINTN VarNameLength
;
1787 EFI_VARIABLE_DATA_TREE
*VarLog
;
1789 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1790 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1792 VarNameLength
= StrLen (VarName
);
1793 TcgEvent
.PCRIndex
= PCRIndex
;
1794 TcgEvent
.EventType
= EventType
;
1796 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1797 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1799 VarLog
= (EFI_VARIABLE_DATA_TREE
*)AllocatePool (TcgEvent
.EventSize
);
1800 if (VarLog
== NULL
) {
1801 return EFI_OUT_OF_RESOURCES
;
1804 VarLog
->VariableName
= *VendorGuid
;
1805 VarLog
->UnicodeNameLength
= VarNameLength
;
1806 VarLog
->VariableDataLength
= VarSize
;
1808 VarLog
->UnicodeName
,
1810 VarNameLength
* sizeof (*VarName
)
1812 if (VarSize
!= 0 && VarData
!= NULL
) {
1814 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1820 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1822 // Digest is the event data (EFI_VARIABLE_DATA)
1824 Status
= TcgDxeHashLogExtendEvent (
1832 Status
= TcgDxeHashLogExtendEvent (
1845 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1847 @param[in] PCRIndex PCR Index.
1848 @param[in] EventType Event type.
1849 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1850 @param[in] VendorGuid A unique identifier for the vendor.
1851 @param[out] VarSize The size of the variable data.
1852 @param[out] VarData Pointer to the content of the variable.
1854 @retval EFI_SUCCESS Operation completed successfully.
1855 @retval EFI_OUT_OF_RESOURCES Out of memory.
1856 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1860 ReadAndMeasureVariable (
1861 IN TPM_PCRINDEX PCRIndex
,
1862 IN TCG_EVENTTYPE EventType
,
1864 IN EFI_GUID
*VendorGuid
,
1871 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1872 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1873 if (EFI_ERROR (Status
)) {
1875 // It is valid case, so we need handle it.
1882 // if status error, VarData is freed and set NULL by GetVariable2
1884 if (EFI_ERROR (Status
)) {
1885 return EFI_NOT_FOUND
;
1889 Status
= MeasureVariable (
1901 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1903 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1904 @param[in] VendorGuid A unique identifier for the vendor.
1905 @param[out] VarSize The size of the variable data.
1906 @param[out] VarData Pointer to the content of the variable.
1908 @retval EFI_SUCCESS Operation completed successfully.
1909 @retval EFI_OUT_OF_RESOURCES Out of memory.
1910 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1914 ReadAndMeasureBootVariable (
1916 IN EFI_GUID
*VendorGuid
,
1921 return ReadAndMeasureVariable (
1923 EV_EFI_VARIABLE_BOOT
,
1932 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1934 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1935 @param[in] VendorGuid A unique identifier for the vendor.
1936 @param[out] VarSize The size of the variable data.
1937 @param[out] VarData Pointer to the content of the variable.
1939 @retval EFI_SUCCESS Operation completed successfully.
1940 @retval EFI_OUT_OF_RESOURCES Out of memory.
1941 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1945 ReadAndMeasureSecureVariable (
1947 IN EFI_GUID
*VendorGuid
,
1952 return ReadAndMeasureVariable (
1954 EV_EFI_VARIABLE_DRIVER_CONFIG
,
1963 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
1965 The EFI boot variables are BootOrder and Boot#### variables.
1967 @retval EFI_SUCCESS Operation completed successfully.
1968 @retval EFI_OUT_OF_RESOURCES Out of memory.
1969 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1973 MeasureAllBootVariables (
1984 Status
= ReadAndMeasureBootVariable (
1986 &gEfiGlobalVariableGuid
,
1988 (VOID
**) &BootOrder
1990 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
1994 if (EFI_ERROR (Status
)) {
1996 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
1998 FreePool (BootOrder
);
2002 BootCount
/= sizeof (*BootOrder
);
2003 for (Index
= 0; Index
< BootCount
; Index
++) {
2004 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
2005 Status
= ReadAndMeasureBootVariable (
2007 &gEfiGlobalVariableGuid
,
2011 if (!EFI_ERROR (Status
)) {
2012 FreePool (BootVarData
);
2016 FreePool (BootOrder
);
2021 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2023 The EFI boot variables are BootOrder and Boot#### variables.
2025 @retval EFI_SUCCESS Operation completed successfully.
2026 @retval EFI_OUT_OF_RESOURCES Out of memory.
2027 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2031 MeasureAllSecureVariables (
2040 Status
= EFI_NOT_FOUND
;
2041 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2042 Status
= ReadAndMeasureSecureVariable (
2043 mVariableType
[Index
].VariableName
,
2044 mVariableType
[Index
].VendorGuid
,
2048 if (!EFI_ERROR (Status
)) {
2059 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2061 @retval EFI_SUCCESS Operation completed successfully.
2062 @retval EFI_OUT_OF_RESOURCES Out of memory.
2063 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2067 MeasureLaunchOfFirmwareDebugger (
2071 TCG_PCR_EVENT_HDR TcgEvent
;
2073 TcgEvent
.PCRIndex
= 7;
2074 TcgEvent
.EventType
= EV_EFI_ACTION
;
2075 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2076 return TcgDxeHashLogExtendEvent (
2078 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2079 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2081 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2086 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2088 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2089 - The contents of the SecureBoot variable
2090 - The contents of the PK variable
2091 - The contents of the KEK variable
2092 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2093 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2095 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2097 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2098 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2100 @param[in] Event Event whose notification function is being invoked
2101 @param[in] Context Pointer to the notification function's context
2105 MeasureSecureBootPolicy (
2113 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2114 if (EFI_ERROR (Status
)) {
2118 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2119 Status
= MeasureLaunchOfFirmwareDebugger ();
2120 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2123 Status
= MeasureAllSecureVariables ();
2124 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2127 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2128 // and ImageVerification (Authority)
2129 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2130 // the Authority measurement happen before ReadToBoot event.
2132 Status
= MeasureSeparatorEvent (7);
2133 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2138 Ready to Boot Event notification handler.
2140 Sequence of OS boot events is measured in this event notification handler.
2142 @param[in] Event Event whose notification function is being invoked
2143 @param[in] Context Pointer to the notification function's context
2154 TPM_PCRINDEX PcrIndex
;
2156 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2157 if (mBootAttempts
== 0) {
2160 // Measure handoff tables.
2162 Status
= MeasureHandoffTables ();
2163 if (EFI_ERROR (Status
)) {
2164 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2168 // Measure BootOrder & Boot#### variables.
2170 Status
= MeasureAllBootVariables ();
2171 if (EFI_ERROR (Status
)) {
2172 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2176 // 1. This is the first boot attempt.
2178 Status
= TcgMeasureAction (
2179 EFI_CALLING_EFI_APPLICATION
2181 if (EFI_ERROR (Status
)) {
2182 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2186 // 2. Draw a line between pre-boot env and entering post-boot env.
2187 // PCR[7] is already done.
2189 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2190 Status
= MeasureSeparatorEvent (PcrIndex
);
2191 if (EFI_ERROR (Status
)) {
2192 DEBUG ((EFI_D_ERROR
, "Seperator Event not Measured. Error!\n"));
2197 // 3. Measure GPT. It would be done in SAP driver.
2201 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2205 // 5. Read & Measure variable. BootOrder already measured.
2209 // 6. Not first attempt, meaning a return from last attempt
2211 Status
= TcgMeasureAction (
2212 EFI_RETURNING_FROM_EFI_APPLICATOIN
2214 if (EFI_ERROR (Status
)) {
2215 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2219 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2221 // Increase boot attempt counter.
2224 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2228 Exit Boot Services Event notification handler.
2230 Measure invocation and success of ExitBootServices.
2232 @param[in] Event Event whose notification function is being invoked
2233 @param[in] Context Pointer to the notification function's context
2238 OnExitBootServices (
2246 // Measure invocation of ExitBootServices,
2248 Status
= TcgMeasureAction (
2249 EFI_EXIT_BOOT_SERVICES_INVOCATION
2251 if (EFI_ERROR (Status
)) {
2252 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2256 // Measure success of ExitBootServices
2258 Status
= TcgMeasureAction (
2259 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2261 if (EFI_ERROR (Status
)) {
2262 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2267 Exit Boot Services Failed Event notification handler.
2269 Measure Failure of ExitBootServices.
2271 @param[in] Event Event whose notification function is being invoked
2272 @param[in] Context Pointer to the notification function's context
2277 OnExitBootServicesFailed (
2285 // Measure Failure of ExitBootServices,
2287 Status
= TcgMeasureAction (
2288 EFI_EXIT_BOOT_SERVICES_FAILED
2290 if (EFI_ERROR (Status
)) {
2291 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2297 The function install Tcg2 protocol.
2299 @retval EFI_SUCCESS Tcg2 protocol is installed.
2300 @retval other Some error occurs.
2311 Status
= gBS
->InstallMultipleProtocolInterfaces (
2313 &gEfiTcg2ProtocolGuid
,
2321 The driver's entry point. It publishes EFI Tcg2 Protocol.
2323 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2324 @param[in] SystemTable A pointer to the EFI System Table.
2326 @retval EFI_SUCCESS The entry point is executed successfully.
2327 @retval other Some error occurs when executing this entry point.
2332 IN EFI_HANDLE ImageHandle
,
2333 IN EFI_SYSTEM_TABLE
*SystemTable
2339 UINT32 MaxCommandSize
;
2340 UINT32 MaxResponseSize
;
2341 TPML_PCR_SELECTION Pcrs
;
2343 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2344 UINT32 ActivePCRBanks
;
2345 UINT32 NumberOfPCRBanks
;
2347 mImageHandle
= ImageHandle
;
2349 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2350 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2351 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2352 return EFI_UNSUPPORTED
;
2355 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2356 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2357 return EFI_DEVICE_ERROR
;
2360 Status
= Tpm2RequestUseTpm ();
2361 if (EFI_ERROR (Status
)) {
2362 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2369 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2371 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2372 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2373 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2374 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2375 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2377 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2378 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2380 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2381 if (EFI_ERROR (Status
)) {
2382 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2384 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2388 UINT32 FirmwareVersion1
;
2389 UINT32 FirmwareVersion2
;
2391 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2392 if (EFI_ERROR (Status
)) {
2393 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2395 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2399 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2400 if (EFI_ERROR (Status
)) {
2401 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2403 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2404 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2405 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2409 // Get supported PCR and current Active PCRs
2411 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
2412 if (EFI_ERROR (Status
)) {
2413 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityPcrs fail!\n"));
2414 TpmHashAlgorithmBitmap
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2415 NumberOfPCRBanks
= 1;
2416 ActivePCRBanks
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2418 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityPcrs Count - %08x\n", Pcrs
.count
));
2419 NumberOfPCRBanks
= 0;
2420 TpmHashAlgorithmBitmap
= 0;
2422 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
2423 DEBUG ((EFI_D_INFO
, "hash - %x\n", Pcrs
.pcrSelections
[Index
].hash
));
2424 switch (Pcrs
.pcrSelections
[Index
].hash
) {
2426 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2427 NumberOfPCRBanks
++;
2428 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2429 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2432 case TPM_ALG_SHA256
:
2433 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2434 NumberOfPCRBanks
++;
2435 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2436 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2439 case TPM_ALG_SHA384
:
2440 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2441 NumberOfPCRBanks
++;
2442 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2443 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2446 case TPM_ALG_SHA512
:
2447 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2448 NumberOfPCRBanks
++;
2449 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2450 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2453 case TPM_ALG_SM3_256
:
2454 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2455 NumberOfPCRBanks
++;
2456 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2457 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2463 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2464 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2466 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2467 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2469 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2470 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2471 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2472 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2476 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2477 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) == 0) {
2479 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2481 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
;
2484 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2485 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2486 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2487 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2489 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2491 // Setup the log area and copy event log from hob list to it
2493 Status
= SetupEventLog ();
2494 ASSERT_EFI_ERROR (Status
);
2497 // Measure handoff tables, Boot#### variables etc.
2499 Status
= EfiCreateEventReadyToBootEx (
2506 Status
= gBS
->CreateEventEx (
2511 &gEfiEventExitBootServicesGuid
,
2516 // Measure Exit Boot Service failed
2518 Status
= gBS
->CreateEventEx (
2521 OnExitBootServicesFailed
,
2523 &gEventExitBootServicesFailedGuid
,
2528 // Create event callback, because we need access variable on SecureBootPolicyVariable
2529 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2530 // may update SecureBoot value based on last setting.
2532 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2536 // Install Tcg2Protocol
2538 Status
= InstallTcg2 ();
2539 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));