2 This module implements Tcg2 Protocol.
4 Copyright (c) 2015, 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/SmBios.h>
19 #include <IndustryStandard/TcpaAcpi.h>
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/SmBios.h>
23 #include <Guid/HobList.h>
24 #include <Guid/TcgEventHob.h>
25 #include <Guid/EventGroup.h>
26 #include <Guid/EventExitBootServiceFailed.h>
27 #include <Guid/ImageAuthentication.h>
28 #include <Guid/TpmInstance.h>
30 #include <Protocol/DevicePath.h>
31 #include <Protocol/MpService.h>
32 #include <Protocol/VariableWrite.h>
33 #include <Protocol/Tcg2Protocol.h>
34 #include <Protocol/TrEEProtocol.h>
36 #include <Library/DebugLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/UefiRuntimeServicesTableLib.h>
39 #include <Library/UefiDriverEntryPoint.h>
40 #include <Library/HobLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/BaseLib.h>
43 #include <Library/MemoryAllocationLib.h>
44 #include <Library/PrintLib.h>
45 #include <Library/Tpm2CommandLib.h>
46 #include <Library/PcdLib.h>
47 #include <Library/UefiLib.h>
48 #include <Library/Tpm2DeviceLib.h>
49 #include <Library/HashLib.h>
50 #include <Library/PerformanceLib.h>
51 #include <Library/ReportStatusCodeLib.h>
52 #include <Library/Tcg2PhysicalPresenceLib.h>
54 #define PERF_ID_TCG2_DXE 0x3120
61 #define EFI_TCG_LOG_AREA_SIZE 0x10000
62 #define EFI_TCG_FINAL_LOG_AREA_SIZE 0x1000
64 #define TCG2_DEFAULT_MAX_COMMAND_SIZE 0x1000
65 #define TCG2_DEFAULT_MAX_RESPONSE_SIZE 0x1000
69 EFI_TCG2_EVENT_LOG_FORMAT LogFormat
;
70 } TCG2_EVENT_INFO_STRUCT
;
72 TCG2_EVENT_INFO_STRUCT mTcg2EventInfo
[] = {
73 {&gTcgEventEntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
},
74 {&gTcgEvent2EntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
},
77 #define TCG_EVENT_LOG_AREA_COUNT_MAX 2
80 EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
;
81 EFI_PHYSICAL_ADDRESS Lasa
;
85 BOOLEAN EventLogStarted
;
86 BOOLEAN EventLogTruncated
;
87 } TCG_EVENT_LOG_AREA_STRUCT
;
89 typedef struct _TCG_DXE_DATA
{
90 EFI_TCG2_BOOT_SERVICE_CAPABILITY BsCap
;
91 TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
92 BOOLEAN GetEventLogCalled
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
93 TCG_EVENT_LOG_AREA_STRUCT FinalEventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
94 EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
97 TCG_DXE_DATA mTcgDxeData
= {
99 sizeof (EFI_TCG2_BOOT_SERVICE_CAPABILITY
), // Size
100 { 1, 1 }, // StructureVersion
101 { 1, 1 }, // ProtocolVersion
102 EFI_TCG2_BOOT_HASH_ALG_SHA1
, // HashAlgorithmBitmap
103 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
, // SupportedEventLogs
104 TRUE
, // TPMPresentFlag
105 TCG2_DEFAULT_MAX_COMMAND_SIZE
, // MaxCommandSize
106 TCG2_DEFAULT_MAX_RESPONSE_SIZE
, // MaxResponseSize
108 0, // NumberOfPCRBanks
113 UINTN mBootAttempts
= 0;
114 CHAR16 mBootVarName
[] = L
"BootOrder";
116 VARIABLE_TYPE mVariableType
[] = {
117 {EFI_SECURE_BOOT_MODE_NAME
, &gEfiGlobalVariableGuid
},
118 {EFI_PLATFORM_KEY_NAME
, &gEfiGlobalVariableGuid
},
119 {EFI_KEY_EXCHANGE_KEY_NAME
, &gEfiGlobalVariableGuid
},
120 {EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
},
121 {EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
},
124 EFI_HANDLE mImageHandle
;
127 Measure PE image into TPM log based on the authenticode image hashing in
128 PE/COFF Specification 8.0 Appendix A.
130 Caution: This function may receive untrusted input.
131 PE/COFF image is external input, so this function will validate its data structure
132 within this image buffer before use.
134 @param[in] PCRIndex TPM PCR index
135 @param[in] ImageAddress Start address of image buffer.
136 @param[in] ImageSize Image size
137 @param[out] DigestList Digeest list of this image.
139 @retval EFI_SUCCESS Successfully measure image.
140 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
141 @retval other error value
144 MeasurePeImageAndExtend (
146 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
148 OUT TPML_DIGEST_VALUES
*DigestList
153 This function dump raw data.
156 @param Size raw data size
166 for (Index
= 0; Index
< Size
; Index
++) {
167 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
173 This function dump raw data with colume format.
176 @param Size raw data size
189 #define COLUME_SIZE (16 * 2)
191 Count
= Size
/ COLUME_SIZE
;
192 Left
= Size
% COLUME_SIZE
;
193 for (Index
= 0; Index
< Count
; Index
++) {
194 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
195 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
196 DEBUG ((EFI_D_INFO
, "\n"));
200 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
201 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
202 DEBUG ((EFI_D_INFO
, "\n"));
207 Check if buffer is all zero.
209 @param[in] Buffer Buffer to be checked.
210 @param[in] BufferSize Size of buffer to be checked.
212 @retval TRUE Buffer is all zero.
213 @retval FALSE Buffer is not all zero.
225 for (Index
= 0; Index
< BufferSize
; Index
++) {
226 if (BufferData
[Index
] != 0) {
234 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
235 Caller is responsible to free LocationBuf.
237 @param[out] LocationBuf Returns Processor Location Buffer.
238 @param[out] Num Returns processor number.
240 @retval EFI_SUCCESS Operation completed successfully.
241 @retval EFI_UNSUPPORTED MpService protocol not found.
245 GetProcessorsCpuLocation (
246 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
251 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
253 UINTN EnabledProcessorNum
;
254 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
255 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
258 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
259 if (EFI_ERROR (Status
)) {
261 // MP protocol is not installed
263 return EFI_UNSUPPORTED
;
266 Status
= MpProtocol
->GetNumberOfProcessors(
271 if (EFI_ERROR(Status
)){
275 Status
= gBS
->AllocatePool(
277 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
278 (VOID
**) &ProcessorLocBuf
280 if (EFI_ERROR(Status
)){
285 // Get each processor Location info
287 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
288 Status
= MpProtocol
->GetProcessorInfo(
293 if (EFI_ERROR(Status
)){
294 FreePool(ProcessorLocBuf
);
299 // Get all Processor Location info & measure
302 &ProcessorLocBuf
[Index
],
303 &ProcessorInfo
.Location
,
304 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
308 *LocationBuf
= ProcessorLocBuf
;
315 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
316 capability information and state information.
318 @param[in] This Indicates the calling context
319 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
320 structure and sets the size field to the size of the structure allocated.
321 The callee fills in the fields with the EFI protocol capability information
322 and the current EFI TCG2 state information up to the number of fields which
323 fit within the size of the structure passed in.
325 @retval EFI_SUCCESS Operation completed successfully.
326 @retval EFI_DEVICE_ERROR The command was unsuccessful.
327 The ProtocolCapability variable will not be populated.
328 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
329 The ProtocolCapability variable will not be populated.
330 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
331 It will be partially populated (required Size field will be set).
336 IN EFI_TCG2_PROTOCOL
*This
,
337 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
340 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability ...\n"));
342 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
343 return EFI_INVALID_PARAMETER
;
346 DEBUG ((EFI_D_INFO
, "Size - 0x%x\n", ProtocolCapability
->Size
));
347 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
)));
349 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
351 // Handle the case that firmware support 1.1 but OS only support 1.0.
353 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
354 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
355 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
356 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
357 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
358 ProtocolCapability
->StructureVersion
.Major
= 1;
359 ProtocolCapability
->StructureVersion
.Minor
= 0;
360 ProtocolCapability
->ProtocolVersion
.Major
= 1;
361 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
362 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
366 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
367 return EFI_BUFFER_TOO_SMALL
;
370 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
371 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
376 This function dump PCR event.
378 @param[in] EventHdr TCG PCR event structure.
382 IN TCG_PCR_EVENT_HDR
*EventHdr
387 DEBUG ((EFI_D_INFO
, " Event:\n"));
388 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
389 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
390 DEBUG ((EFI_D_INFO
, " Digest - "));
391 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
392 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
394 DEBUG ((EFI_D_INFO
, "\n"));
395 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
396 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
400 This function dump TCG_EfiSpecIDEventStruct.
402 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
405 DumpTcgEfiSpecIdEventStruct (
406 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
409 TCG_EfiSpecIdEventAlgorithmSize
*digestSize
;
411 UINT8
*vendorInfoSize
;
413 UINT32 numberOfAlgorithms
;
415 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
416 DEBUG ((EFI_D_INFO
, " signature - '"));
417 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
418 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
420 DEBUG ((EFI_D_INFO
, "'\n"));
421 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
422 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
423 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
425 CopyMem (&numberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(numberOfAlgorithms
));
426 DEBUG ((EFI_D_INFO
, " numberOfAlgorithms - 0x%08x\n", numberOfAlgorithms
));
428 digestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(numberOfAlgorithms
));
429 for (Index
= 0; Index
< numberOfAlgorithms
; Index
++) {
430 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
431 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", digestSize
[Index
].algorithmId
));
432 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", digestSize
[Index
].digestSize
));
434 vendorInfoSize
= (UINT8
*)&digestSize
[numberOfAlgorithms
];
435 DEBUG ((EFI_D_INFO
, " vendorInfoSize - 0x%02x\n", *vendorInfoSize
));
436 vendorInfo
= vendorInfoSize
+ 1;
437 DEBUG ((EFI_D_INFO
, " vendorInfo - "));
438 for (Index
= 0; Index
< *vendorInfoSize
; Index
++) {
439 DEBUG ((EFI_D_INFO
, "%02x ", vendorInfo
[Index
]));
441 DEBUG ((EFI_D_INFO
, "\n"));
445 This function get size of TCG_EfiSpecIDEventStruct.
447 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
450 GetTcgEfiSpecIdEventStructSize (
451 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
454 TCG_EfiSpecIdEventAlgorithmSize
*digestSize
;
455 UINT8
*vendorInfoSize
;
456 UINT32 numberOfAlgorithms
;
458 CopyMem (&numberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(numberOfAlgorithms
));
460 digestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(numberOfAlgorithms
));
461 vendorInfoSize
= (UINT8
*)&digestSize
[numberOfAlgorithms
];
462 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (numberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*vendorInfoSize
);
466 This function dump PCR event 2.
468 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
472 IN TCG_PCR_EVENT2
*TcgPcrEvent2
478 TPMI_ALG_HASH HashAlgo
;
484 DEBUG ((EFI_D_INFO
, " Event:\n"));
485 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
486 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
488 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
490 DigestCount
= TcgPcrEvent2
->Digest
.count
;
491 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
492 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
493 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
494 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
495 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
496 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
497 for (Index
= 0; Index
< DigestSize
; Index
++) {
498 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
500 DEBUG ((EFI_D_INFO
, "\n"));
504 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
505 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
507 DEBUG ((EFI_D_INFO
, "\n"));
508 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
510 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
511 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
512 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
513 InternalDumpHex (EventBuffer
, EventSize
);
517 This function returns size of TCG PCR event 2.
519 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
521 @return size of TCG PCR event 2.
525 IN TCG_PCR_EVENT2
*TcgPcrEvent2
530 TPMI_ALG_HASH HashAlgo
;
536 DigestCount
= TcgPcrEvent2
->Digest
.count
;
537 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
538 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
539 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
540 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
544 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
545 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
547 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
549 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
550 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
552 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
556 This function dump event log.
558 @param[in] EventLogFormat The type of the event log for which the information is requested.
559 @param[in] EventLogLocation A pointer to the memory address of the event log.
560 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
561 address of the start of the last entry in the event log in memory.
562 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
566 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
567 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
568 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
569 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
572 TCG_PCR_EVENT_HDR
*EventHdr
;
573 TCG_PCR_EVENT2
*TcgPcrEvent2
;
574 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
575 UINTN NumberOfEvents
;
577 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
579 switch (EventLogFormat
) {
580 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
581 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
582 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
583 DumpEvent (EventHdr
);
584 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
586 if (FinalEventsTable
== NULL
) {
587 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
589 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
590 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
591 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
593 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
594 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
595 DumpEvent (EventHdr
);
596 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
600 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
604 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
605 DumpEvent (EventHdr
);
607 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
608 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
610 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
611 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
612 DumpEvent2 (TcgPcrEvent2
);
613 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
616 if (FinalEventsTable
== NULL
) {
617 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
619 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
620 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
621 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
623 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
624 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
625 DumpEvent2 (TcgPcrEvent2
);
626 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
636 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
637 retrieve the address of a given event log and its last entry.
639 @param[in] This Indicates the calling context
640 @param[in] EventLogFormat The type of the event log for which the information is requested.
641 @param[out] EventLogLocation A pointer to the memory address of the event log.
642 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
643 address of the start of the last entry in the event log in memory.
644 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
645 have exceeded the area allocated for events, this value is set to TRUE.
646 Otherwise, the value will be FALSE and the Event Log will be complete.
648 @retval EFI_SUCCESS Operation completed successfully.
649 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
650 (e.g. asking for an event log whose format is not supported).
655 IN EFI_TCG2_PROTOCOL
*This
,
656 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
657 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
658 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
659 OUT BOOLEAN
*EventLogTruncated
664 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
667 return EFI_INVALID_PARAMETER
;
670 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
671 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
676 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
677 return EFI_INVALID_PARAMETER
;
680 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
681 return EFI_INVALID_PARAMETER
;
684 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
685 if (EventLogLocation
!= NULL
) {
686 *EventLogLocation
= 0;
688 if (EventLogLastEntry
!= NULL
) {
689 *EventLogLastEntry
= 0;
691 if (EventLogTruncated
!= NULL
) {
692 *EventLogTruncated
= FALSE
;
697 if (EventLogLocation
!= NULL
) {
698 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
699 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
702 if (EventLogLastEntry
!= NULL
) {
703 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
704 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
706 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
708 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
711 if (EventLogTruncated
!= NULL
) {
712 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
713 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
716 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
718 // Dump Event Log for debug purpose
719 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
720 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
724 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
725 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
727 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
733 Add a new entry to the Event Log.
735 @param[in, out] EventLogPtr Pointer to the Event Log data.
736 @param[in, out] LogSize Size of the Event Log.
737 @param[in] MaxSize Maximum size of the Event Log.
738 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
739 @param[in] NewEventHdrSize New event header size.
740 @param[in] NewEventData Pointer to the new event data.
741 @param[in] NewEventSize New event data size.
743 @retval EFI_SUCCESS The new event log entry was added.
744 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
749 IN OUT UINT8
**EventLogPtr
,
750 IN OUT UINTN
*LogSize
,
752 IN VOID
*NewEventHdr
,
753 IN UINT32 NewEventHdrSize
,
754 IN UINT8
*NewEventData
,
755 IN UINT32 NewEventSize
760 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
761 return EFI_OUT_OF_RESOURCES
;
764 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
766 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
767 return EFI_OUT_OF_RESOURCES
;
770 if (NewLogSize
+ *LogSize
> MaxSize
) {
771 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
772 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
773 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
774 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
775 return EFI_OUT_OF_RESOURCES
;
778 *EventLogPtr
+= *LogSize
;
779 *LogSize
+= NewLogSize
;
780 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
782 *EventLogPtr
+ NewEventHdrSize
,
790 Add a new entry to the Event Log.
792 @param[in] EventLogFormat The type of the event log for which the information is requested.
793 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
794 @param[in] NewEventHdrSize New event header size.
795 @param[in] NewEventData Pointer to the new event data.
796 @param[in] NewEventSize New event data size.
798 @retval EFI_SUCCESS The new event log entry was added.
799 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
804 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
805 IN VOID
*NewEventHdr
,
806 IN UINT32 NewEventHdrSize
,
807 IN UINT8
*NewEventData
,
808 IN UINT32 NewEventSize
813 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
815 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
816 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
821 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
822 return EFI_INVALID_PARAMETER
;
825 if (!mTcgDxeData
.GetEventLogCalled
[Index
]) {
826 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
828 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
831 if (EventLogAreaStruct
->EventLogTruncated
) {
832 return EFI_VOLUME_FULL
;
835 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
836 Status
= TcgCommLogEvent (
837 &EventLogAreaStruct
->LastEvent
,
838 &EventLogAreaStruct
->EventLogSize
,
839 (UINTN
)EventLogAreaStruct
->Laml
,
846 if (Status
== EFI_DEVICE_ERROR
) {
847 return EFI_DEVICE_ERROR
;
848 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
849 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
850 return EFI_VOLUME_FULL
;
851 } else if (Status
== EFI_SUCCESS
) {
852 EventLogAreaStruct
->EventLogStarted
= TRUE
;
853 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
854 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
862 This function get digest from digest list.
864 @param HashAlg digest algorithm
865 @param DigestList digest list
868 @retval EFI_SUCCESS Sha1Digest is found and returned.
869 @retval EFI_NOT_FOUND Sha1Digest is not found.
872 Tpm2GetDigestFromDigestList (
873 IN TPMI_ALG_HASH HashAlg
,
874 IN TPML_DIGEST_VALUES
*DigestList
,
881 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
882 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
883 if (DigestList
->digests
[Index
].hashAlg
== HashAlg
) {
886 &DigestList
->digests
[Index
].digest
,
893 return EFI_NOT_FOUND
;
897 Get TPML_DIGEST_VALUES data size.
899 @param[in] DigestList TPML_DIGEST_VALUES data.
901 @return TPML_DIGEST_VALUES data size.
905 IN TPML_DIGEST_VALUES
*DigestList
912 TotalSize
= sizeof(DigestList
->count
);
913 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
914 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
915 TotalSize
+= sizeof(DigestList
->digests
[Index
].hashAlg
) + DigestSize
;
922 Get TPML_DIGEST_VALUES compact binary buffer size.
924 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
926 @return TPML_DIGEST_VALUES compact binary buffer size.
929 GetDigestListBinSize (
930 IN VOID
*DigestListBin
937 TPMI_ALG_HASH HashAlg
;
939 Count
= ReadUnaligned32 (DigestListBin
);
940 TotalSize
= sizeof(Count
);
941 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
942 for (Index
= 0; Index
< Count
; Index
++) {
943 HashAlg
= ReadUnaligned16 (DigestListBin
);
944 TotalSize
+= sizeof(HashAlg
);
945 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
947 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
948 TotalSize
+= DigestSize
;
949 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
956 Return if hash alg is supported in TPM PCR bank.
958 @param HashAlg Hash algorithm to be checked.
960 @retval TRUE Hash algorithm is supported.
961 @retval FALSE Hash algorithm is not supported.
964 IsHashAlgSupportedInPcrBank (
965 IN TPMI_ALG_HASH HashAlg
970 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
975 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
980 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
985 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
989 case TPM_ALG_SM3_256
:
990 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1000 Copy TPML_DIGEST_VALUES into a buffer
1002 @param[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
1003 @param[in] DigestList TPML_DIGEST_VALUES to be copied.
1005 @return The end of buffer to hold TPML_DIGEST_VALUES.
1008 CopyDigestListToBuffer (
1009 IN OUT VOID
*Buffer
,
1010 IN TPML_DIGEST_VALUES
*DigestList
1016 CopyMem (Buffer
, &DigestList
->count
, sizeof(DigestList
->count
));
1017 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->count
);
1018 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
1019 if (!IsHashAlgSupportedInPcrBank (DigestList
->digests
[Index
].hashAlg
)) {
1020 DEBUG ((EFI_D_ERROR
, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList
->digests
[Index
].hashAlg
));
1023 CopyMem (Buffer
, &DigestList
->digests
[Index
].hashAlg
, sizeof(DigestList
->digests
[Index
].hashAlg
));
1024 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->digests
[Index
].hashAlg
);
1025 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
1026 CopyMem (Buffer
, &DigestList
->digests
[Index
].digest
, DigestSize
);
1027 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
1034 Add a new entry to the Event Log.
1036 @param[in] DigestList A list of digest.
1037 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1038 @param[in] NewEventData Pointer to the new event data.
1040 @retval EFI_SUCCESS The new event log entry was added.
1041 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1044 TcgDxeLogHashEvent (
1045 IN TPML_DIGEST_VALUES
*DigestList
,
1046 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1047 IN UINT8
*NewEventData
1053 EFI_STATUS RetStatus
;
1054 TCG_PCR_EVENT2 TcgPcrEvent2
;
1055 UINT8
*DigestBuffer
;
1057 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
1059 RetStatus
= EFI_SUCCESS
;
1060 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1061 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1062 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
1063 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1064 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1065 Status
= Tpm2GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
1066 if (!EFI_ERROR (Status
)) {
1068 // Enter critical region
1070 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1071 Status
= TcgDxeLogEvent (
1072 mTcg2EventInfo
[Index
].LogFormat
,
1074 sizeof(TCG_PCR_EVENT_HDR
),
1076 NewEventHdr
->EventSize
1078 if (Status
!= EFI_SUCCESS
) {
1081 gBS
->RestoreTPL (OldTpl
);
1083 // Exit critical region
1087 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1088 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1089 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1090 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1091 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1092 DigestBuffer
= CopyDigestListToBuffer (DigestBuffer
, DigestList
);
1093 CopyMem (DigestBuffer
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1094 DigestBuffer
= DigestBuffer
+ sizeof(NewEventHdr
->EventSize
);
1097 // Enter critical region
1099 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1100 Status
= TcgDxeLogEvent (
1101 mTcg2EventInfo
[Index
].LogFormat
,
1103 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListSize (DigestList
) + sizeof(TcgPcrEvent2
.EventSize
),
1105 NewEventHdr
->EventSize
1107 if (Status
!= EFI_SUCCESS
) {
1110 gBS
->RestoreTPL (OldTpl
);
1112 // Exit critical region
1123 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1124 and add an entry to the Event Log.
1126 @param[in] Flags Bitmap providing additional information.
1127 @param[in] HashData Physical address of the start of the data buffer
1128 to be hashed, extended, and logged.
1129 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1130 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1131 @param[in] NewEventData Pointer to the new event data.
1133 @retval EFI_SUCCESS Operation completed successfully.
1134 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1135 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1139 TcgDxeHashLogExtendEvent (
1142 IN UINT64 HashDataLen
,
1143 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1144 IN UINT8
*NewEventData
1148 TPML_DIGEST_VALUES DigestList
;
1150 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1151 return EFI_DEVICE_ERROR
;
1154 Status
= HashAndExtend (
1155 NewEventHdr
->PCRIndex
,
1160 if (!EFI_ERROR (Status
)) {
1161 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1162 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1166 if (Status
== EFI_DEVICE_ERROR
) {
1167 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1168 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1169 REPORT_STATUS_CODE (
1170 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1171 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1179 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1180 an opportunity to extend and optionally log events without requiring
1181 knowledge of actual TPM commands.
1182 The extend operation will occur even if this function cannot create an event
1183 log entry (e.g. due to the event log being full).
1185 @param[in] This Indicates the calling context
1186 @param[in] Flags Bitmap providing additional information.
1187 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1188 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1189 @param[in] Event Pointer to data buffer containing information about the event.
1191 @retval EFI_SUCCESS Operation completed successfully.
1192 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1193 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1194 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1195 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1199 Tcg2HashLogExtendEvent (
1200 IN EFI_TCG2_PROTOCOL
*This
,
1202 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1203 IN UINT64 DataToHashLen
,
1204 IN EFI_TCG2_EVENT
*Event
1208 TCG_PCR_EVENT_HDR NewEventHdr
;
1209 TPML_DIGEST_VALUES DigestList
;
1211 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent ...\n"));
1213 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1214 return EFI_INVALID_PARAMETER
;
1217 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1218 return EFI_DEVICE_ERROR
;
1221 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1222 return EFI_INVALID_PARAMETER
;
1225 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1226 return EFI_INVALID_PARAMETER
;
1229 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1230 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1231 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1232 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1233 Status
= MeasurePeImageAndExtend (
1234 NewEventHdr
.PCRIndex
,
1236 (UINTN
)DataToHashLen
,
1239 if (!EFI_ERROR (Status
)) {
1240 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1241 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1244 if (Status
== EFI_DEVICE_ERROR
) {
1245 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status
));
1246 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1247 REPORT_STATUS_CODE (
1248 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1249 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1253 Status
= TcgDxeHashLogExtendEvent (
1255 (UINT8
*) (UINTN
) DataToHash
,
1261 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1266 This service enables the sending of commands to the TPM.
1268 @param[in] This Indicates the calling context
1269 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1270 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1271 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1272 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1274 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1275 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1276 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1277 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1282 IN EFI_TCG2_PROTOCOL
*This
,
1283 IN UINT32 InputParameterBlockSize
,
1284 IN UINT8
*InputParameterBlock
,
1285 IN UINT32 OutputParameterBlockSize
,
1286 IN UINT8
*OutputParameterBlock
1291 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1293 if ((This
== NULL
) ||
1294 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1295 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1296 return EFI_INVALID_PARAMETER
;
1299 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1300 return EFI_DEVICE_ERROR
;
1303 if (InputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxCommandSize
) {
1304 return EFI_INVALID_PARAMETER
;
1306 if (OutputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxResponseSize
) {
1307 return EFI_INVALID_PARAMETER
;
1310 Status
= Tpm2SubmitCommand (
1311 InputParameterBlockSize
,
1312 InputParameterBlock
,
1313 &OutputParameterBlockSize
,
1314 OutputParameterBlock
1316 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1321 This service returns the currently active PCR banks.
1323 @param[in] This Indicates the calling context
1324 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1326 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1327 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1331 Tcg2GetActivePCRBanks (
1332 IN EFI_TCG2_PROTOCOL
*This
,
1333 OUT UINT32
*ActivePcrBanks
1336 if (ActivePcrBanks
== NULL
) {
1337 return EFI_INVALID_PARAMETER
;
1339 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1344 This service sets the currently active PCR banks.
1346 @param[in] This Indicates the calling context
1347 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1349 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1350 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1354 Tcg2SetActivePCRBanks (
1355 IN EFI_TCG2_PROTOCOL
*This
,
1356 IN UINT32 ActivePcrBanks
1362 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1364 if (ActivePcrBanks
== 0) {
1365 return EFI_INVALID_PARAMETER
;
1367 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1368 return EFI_INVALID_PARAMETER
;
1370 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1372 // Need clear previous SET_PCR_BANKS setting
1374 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1376 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1379 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1380 Status
= EFI_SUCCESS
;
1381 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1382 Status
= EFI_OUT_OF_RESOURCES
;
1383 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1384 Status
= EFI_UNSUPPORTED
;
1386 Status
= EFI_DEVICE_ERROR
;
1389 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1395 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1397 @param[in] This Indicates the calling context
1398 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1399 @param[out] Response The response from the SetActivePcrBank request.
1401 @retval EFI_SUCCESS The result value could be returned.
1402 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1406 Tcg2GetResultOfSetActivePcrBanks (
1407 IN EFI_TCG2_PROTOCOL
*This
,
1408 OUT UINT32
*OperationPresent
,
1409 OUT UINT32
*Response
1414 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1415 return EFI_INVALID_PARAMETER
;
1418 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1419 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1422 return EFI_UNSUPPORTED
;
1426 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1429 Tcg2HashLogExtendEvent
,
1431 Tcg2GetActivePCRBanks
,
1432 Tcg2SetActivePCRBanks
,
1433 Tcg2GetResultOfSetActivePcrBanks
,
1437 Initialize the Event Log and log events passed from the PEI phase.
1439 @retval EFI_SUCCESS Operation completed successfully.
1440 @retval EFI_OUT_OF_RESOURCES Out of memory.
1450 EFI_PEI_HOB_POINTERS GuidHob
;
1451 EFI_PHYSICAL_ADDRESS Lasa
;
1453 UINT32 DigestListBinSize
;
1455 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1456 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1457 TCG_PCR_EVENT_HDR FirstPcrEvent
;
1458 TCG_EfiSpecIdEventAlgorithmSize
*digestSize
;
1459 UINT8
*vendorInfoSize
;
1460 UINT32 numberOfAlgorithms
;
1462 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1465 // 1. Create Log Area
1467 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1468 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1469 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1470 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1471 Status
= gBS
->AllocatePages (
1474 EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE
),
1477 if (EFI_ERROR (Status
)) {
1480 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1481 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= EFI_TCG_LOG_AREA_SIZE
;
1483 // To initialize them as 0xFF is recommended
1484 // because the OS can know the last entry for that.
1486 SetMem ((VOID
*)(UINTN
)Lasa
, EFI_TCG_LOG_AREA_SIZE
, 0xFF);
1488 // Create first entry for Log Header Entry Data
1490 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1492 // TcgEfiSpecIdEventStruct
1494 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1495 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1496 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1497 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1498 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1499 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1500 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1501 numberOfAlgorithms
= 0;
1502 digestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(numberOfAlgorithms
));
1503 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1504 digestSize
[numberOfAlgorithms
].algorithmId
= TPM_ALG_SHA1
;
1505 digestSize
[numberOfAlgorithms
].digestSize
= SHA1_DIGEST_SIZE
;
1506 numberOfAlgorithms
++;
1508 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1509 digestSize
[numberOfAlgorithms
].algorithmId
= TPM_ALG_SHA256
;
1510 digestSize
[numberOfAlgorithms
].digestSize
= SHA256_DIGEST_SIZE
;
1511 numberOfAlgorithms
++;
1513 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1514 digestSize
[numberOfAlgorithms
].algorithmId
= TPM_ALG_SHA384
;
1515 digestSize
[numberOfAlgorithms
].digestSize
= SHA384_DIGEST_SIZE
;
1516 numberOfAlgorithms
++;
1518 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1519 digestSize
[numberOfAlgorithms
].algorithmId
= TPM_ALG_SHA512
;
1520 digestSize
[numberOfAlgorithms
].digestSize
= SHA512_DIGEST_SIZE
;
1521 numberOfAlgorithms
++;
1523 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1524 digestSize
[numberOfAlgorithms
].algorithmId
= TPM_ALG_SM3_256
;
1525 digestSize
[numberOfAlgorithms
].digestSize
= SM3_256_DIGEST_SIZE
;
1526 numberOfAlgorithms
++;
1528 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &numberOfAlgorithms
, sizeof(numberOfAlgorithms
));
1529 vendorInfoSize
= (UINT8
*)&digestSize
[numberOfAlgorithms
];
1530 *vendorInfoSize
= 0;
1535 FirstPcrEvent
.PCRIndex
= 0;
1536 FirstPcrEvent
.EventType
= EV_NO_ACTION
;
1537 ZeroMem (&FirstPcrEvent
.Digest
, sizeof(FirstPcrEvent
.Digest
));
1538 FirstPcrEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1543 Status
= TcgDxeLogEvent (
1544 mTcg2EventInfo
[Index
].LogFormat
,
1546 sizeof(FirstPcrEvent
),
1547 (UINT8
*)TcgEfiSpecIdEventStruct
,
1548 FirstPcrEvent
.EventSize
1555 // 2. Create Final Log Area
1557 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1558 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1559 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1560 Status
= gBS
->AllocatePages (
1563 EFI_SIZE_TO_PAGES (EFI_TCG_FINAL_LOG_AREA_SIZE
),
1566 if (EFI_ERROR (Status
)) {
1569 SetMem ((VOID
*)(UINTN
)Lasa
, EFI_TCG_FINAL_LOG_AREA_SIZE
, 0xFF);
1574 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1575 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1576 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1578 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1579 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1580 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= EFI_TCG_FINAL_LOG_AREA_SIZE
- sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1581 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1582 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1583 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1584 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1586 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1588 // Install to configuration table
1590 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[1]);
1591 if (EFI_ERROR (Status
)) {
1599 // 3. Sync data from PEI to DXE
1601 Status
= EFI_SUCCESS
;
1602 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1603 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1604 GuidHob
.Raw
= GetHobList ();
1605 Status
= EFI_SUCCESS
;
1606 while (!EFI_ERROR (Status
) &&
1607 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1608 TcgEvent
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1609 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1610 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1611 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1612 Status
= TcgDxeLogEvent (
1613 mTcg2EventInfo
[Index
].LogFormat
,
1615 sizeof(TCG_PCR_EVENT_HDR
),
1616 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1617 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1620 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1621 DigestListBinSize
= GetDigestListBinSize ((UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
));
1622 CopyMem (&EventSize
, (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
, sizeof(UINT32
));
1623 Status
= TcgDxeLogEvent (
1624 mTcg2EventInfo
[Index
].LogFormat
,
1626 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1627 (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1640 Measure and log an action string, and extend the measurement result into PCR[5].
1642 @param[in] String A specific string that indicates an Action event.
1644 @retval EFI_SUCCESS Operation completed successfully.
1645 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1653 TCG_PCR_EVENT_HDR TcgEvent
;
1655 TcgEvent
.PCRIndex
= 5;
1656 TcgEvent
.EventType
= EV_EFI_ACTION
;
1657 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1658 return TcgDxeHashLogExtendEvent (
1668 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1670 @retval EFI_SUCCESS Operation completed successfully.
1671 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1675 MeasureHandoffTables (
1680 SMBIOS_TABLE_ENTRY_POINT
*SmbiosTable
;
1681 TCG_PCR_EVENT_HDR TcgEvent
;
1682 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1684 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1686 ProcessorLocBuf
= NULL
;
1689 // Measure SMBIOS with EV_EFI_HANDOFF_TABLES to PCR[1]
1691 Status
= EfiGetSystemConfigurationTable (
1692 &gEfiSmbiosTableGuid
,
1693 (VOID
**) &SmbiosTable
1696 if (!EFI_ERROR (Status
) && SmbiosTable
!= NULL
) {
1697 TcgEvent
.PCRIndex
= 1;
1698 TcgEvent
.EventType
= EV_EFI_HANDOFF_TABLES
;
1699 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1701 HandoffTables
.NumberOfTables
= 1;
1702 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiSmbiosTableGuid
;
1703 HandoffTables
.TableEntry
[0].VendorTable
= SmbiosTable
;
1705 DEBUG ((DEBUG_INFO
, "The Smbios Table starts at: 0x%x\n", SmbiosTable
->TableAddress
));
1706 DEBUG ((DEBUG_INFO
, "The Smbios Table size: 0x%x\n", SmbiosTable
->TableLength
));
1708 Status
= TcgDxeHashLogExtendEvent (
1710 (UINT8
*)(UINTN
)SmbiosTable
->TableAddress
,
1711 SmbiosTable
->TableLength
,
1713 (UINT8
*)&HandoffTables
1717 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1720 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1722 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1724 if (!EFI_ERROR(Status
)){
1725 TcgEvent
.PCRIndex
= 1;
1726 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1727 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1729 HandoffTables
.NumberOfTables
= 1;
1730 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1731 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1733 Status
= TcgDxeHashLogExtendEvent (
1735 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1736 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1738 (UINT8
*)&HandoffTables
1741 FreePool(ProcessorLocBuf
);
1749 Measure and log Separator event, and extend the measurement result into a specific PCR.
1751 @param[in] PCRIndex PCR index.
1753 @retval EFI_SUCCESS Operation completed successfully.
1754 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1758 MeasureSeparatorEvent (
1759 IN TPM_PCRINDEX PCRIndex
1762 TCG_PCR_EVENT_HDR TcgEvent
;
1765 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1768 TcgEvent
.PCRIndex
= PCRIndex
;
1769 TcgEvent
.EventType
= EV_SEPARATOR
;
1770 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1771 return TcgDxeHashLogExtendEvent (
1773 (UINT8
*)&EventData
,
1781 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1783 @param[in] PCRIndex PCR Index.
1784 @param[in] EventType Event type.
1785 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1786 @param[in] VendorGuid A unique identifier for the vendor.
1787 @param[in] VarData The content of the variable data.
1788 @param[in] VarSize The size of the variable data.
1790 @retval EFI_SUCCESS Operation completed successfully.
1791 @retval EFI_OUT_OF_RESOURCES Out of memory.
1792 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1797 IN TPM_PCRINDEX PCRIndex
,
1798 IN TCG_EVENTTYPE EventType
,
1800 IN EFI_GUID
*VendorGuid
,
1806 TCG_PCR_EVENT_HDR TcgEvent
;
1807 UINTN VarNameLength
;
1808 EFI_VARIABLE_DATA_TREE
*VarLog
;
1810 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1811 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1813 VarNameLength
= StrLen (VarName
);
1814 TcgEvent
.PCRIndex
= PCRIndex
;
1815 TcgEvent
.EventType
= EventType
;
1817 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1818 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1820 VarLog
= (EFI_VARIABLE_DATA_TREE
*)AllocatePool (TcgEvent
.EventSize
);
1821 if (VarLog
== NULL
) {
1822 return EFI_OUT_OF_RESOURCES
;
1825 VarLog
->VariableName
= *VendorGuid
;
1826 VarLog
->UnicodeNameLength
= VarNameLength
;
1827 VarLog
->VariableDataLength
= VarSize
;
1829 VarLog
->UnicodeName
,
1831 VarNameLength
* sizeof (*VarName
)
1833 if (VarSize
!= 0 && VarData
!= NULL
) {
1835 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1841 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1843 // Digest is the event data (EFI_VARIABLE_DATA)
1845 Status
= TcgDxeHashLogExtendEvent (
1853 Status
= TcgDxeHashLogExtendEvent (
1866 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1868 @param[in] PCRIndex PCR Index.
1869 @param[in] EventType Event type.
1870 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1871 @param[in] VendorGuid A unique identifier for the vendor.
1872 @param[out] VarSize The size of the variable data.
1873 @param[out] VarData Pointer to the content of the variable.
1875 @retval EFI_SUCCESS Operation completed successfully.
1876 @retval EFI_OUT_OF_RESOURCES Out of memory.
1877 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1881 ReadAndMeasureVariable (
1882 IN TPM_PCRINDEX PCRIndex
,
1883 IN TCG_EVENTTYPE EventType
,
1885 IN EFI_GUID
*VendorGuid
,
1892 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1893 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1894 if (EFI_ERROR (Status
)) {
1896 // It is valid case, so we need handle it.
1903 // if status error, VarData is freed and set NULL by GetVariable2
1905 if (EFI_ERROR (Status
)) {
1906 return EFI_NOT_FOUND
;
1910 Status
= MeasureVariable (
1922 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1924 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1925 @param[in] VendorGuid A unique identifier for the vendor.
1926 @param[out] VarSize The size of the variable data.
1927 @param[out] VarData Pointer to the content of the variable.
1929 @retval EFI_SUCCESS Operation completed successfully.
1930 @retval EFI_OUT_OF_RESOURCES Out of memory.
1931 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1935 ReadAndMeasureBootVariable (
1937 IN EFI_GUID
*VendorGuid
,
1942 return ReadAndMeasureVariable (
1944 EV_EFI_VARIABLE_BOOT
,
1953 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1955 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1956 @param[in] VendorGuid A unique identifier for the vendor.
1957 @param[out] VarSize The size of the variable data.
1958 @param[out] VarData Pointer to the content of the variable.
1960 @retval EFI_SUCCESS Operation completed successfully.
1961 @retval EFI_OUT_OF_RESOURCES Out of memory.
1962 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1966 ReadAndMeasureSecureVariable (
1968 IN EFI_GUID
*VendorGuid
,
1973 return ReadAndMeasureVariable (
1975 EV_EFI_VARIABLE_DRIVER_CONFIG
,
1984 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
1986 The EFI boot variables are BootOrder and Boot#### variables.
1988 @retval EFI_SUCCESS Operation completed successfully.
1989 @retval EFI_OUT_OF_RESOURCES Out of memory.
1990 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1994 MeasureAllBootVariables (
2005 Status
= ReadAndMeasureBootVariable (
2007 &gEfiGlobalVariableGuid
,
2009 (VOID
**) &BootOrder
2011 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
2015 if (EFI_ERROR (Status
)) {
2017 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
2019 FreePool (BootOrder
);
2023 BootCount
/= sizeof (*BootOrder
);
2024 for (Index
= 0; Index
< BootCount
; Index
++) {
2025 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
2026 Status
= ReadAndMeasureBootVariable (
2028 &gEfiGlobalVariableGuid
,
2032 if (!EFI_ERROR (Status
)) {
2033 FreePool (BootVarData
);
2037 FreePool (BootOrder
);
2042 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2044 The EFI boot variables are BootOrder and Boot#### variables.
2046 @retval EFI_SUCCESS Operation completed successfully.
2047 @retval EFI_OUT_OF_RESOURCES Out of memory.
2048 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2052 MeasureAllSecureVariables (
2061 Status
= EFI_NOT_FOUND
;
2062 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2063 Status
= ReadAndMeasureSecureVariable (
2064 mVariableType
[Index
].VariableName
,
2065 mVariableType
[Index
].VendorGuid
,
2069 if (!EFI_ERROR (Status
)) {
2080 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2082 @retval EFI_SUCCESS Operation completed successfully.
2083 @retval EFI_OUT_OF_RESOURCES Out of memory.
2084 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2088 MeasureLaunchOfFirmwareDebugger (
2092 TCG_PCR_EVENT_HDR TcgEvent
;
2094 TcgEvent
.PCRIndex
= 7;
2095 TcgEvent
.EventType
= EV_EFI_ACTION
;
2096 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2097 return TcgDxeHashLogExtendEvent (
2099 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2100 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2102 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2107 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2109 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2110 - The contents of the SecureBoot variable
2111 - The contents of the PK variable
2112 - The contents of the KEK variable
2113 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2114 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2116 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2118 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2119 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2121 @param[in] Event Event whose notification function is being invoked
2122 @param[in] Context Pointer to the notification function's context
2126 MeasureSecureBootPolicy (
2134 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2135 if (EFI_ERROR (Status
)) {
2139 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2140 Status
= MeasureLaunchOfFirmwareDebugger ();
2141 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2144 Status
= MeasureAllSecureVariables ();
2145 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2148 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2149 // and ImageVerification (Authority)
2150 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2151 // the Authority measurement happen before ReadToBoot event.
2153 Status
= MeasureSeparatorEvent (7);
2154 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2159 Ready to Boot Event notification handler.
2161 Sequence of OS boot events is measured in this event notification handler.
2163 @param[in] Event Event whose notification function is being invoked
2164 @param[in] Context Pointer to the notification function's context
2175 TPM_PCRINDEX PcrIndex
;
2177 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2178 if (mBootAttempts
== 0) {
2181 // Measure handoff tables.
2183 Status
= MeasureHandoffTables ();
2184 if (EFI_ERROR (Status
)) {
2185 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2189 // Measure BootOrder & Boot#### variables.
2191 Status
= MeasureAllBootVariables ();
2192 if (EFI_ERROR (Status
)) {
2193 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2197 // 1. This is the first boot attempt.
2199 Status
= TcgMeasureAction (
2200 EFI_CALLING_EFI_APPLICATION
2202 if (EFI_ERROR (Status
)) {
2203 DEBUG ((EFI_D_ERROR
, "%s not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2207 // 2. Draw a line between pre-boot env and entering post-boot env.
2208 // PCR[7] is already done.
2210 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2211 Status
= MeasureSeparatorEvent (PcrIndex
);
2212 if (EFI_ERROR (Status
)) {
2213 DEBUG ((EFI_D_ERROR
, "Seperator Event not Measured. Error!\n"));
2218 // 3. Measure GPT. It would be done in SAP driver.
2222 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2226 // 5. Read & Measure variable. BootOrder already measured.
2230 // 6. Not first attempt, meaning a return from last attempt
2232 Status
= TcgMeasureAction (
2233 EFI_RETURNING_FROM_EFI_APPLICATOIN
2235 if (EFI_ERROR (Status
)) {
2236 DEBUG ((EFI_D_ERROR
, "%s not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2240 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2242 // Increase boot attempt counter.
2245 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2249 Exit Boot Services Event notification handler.
2251 Measure invocation and success of ExitBootServices.
2253 @param[in] Event Event whose notification function is being invoked
2254 @param[in] Context Pointer to the notification function's context
2259 OnExitBootServices (
2267 // Measure invocation of ExitBootServices,
2269 Status
= TcgMeasureAction (
2270 EFI_EXIT_BOOT_SERVICES_INVOCATION
2272 if (EFI_ERROR (Status
)) {
2273 DEBUG ((EFI_D_ERROR
, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2277 // Measure success of ExitBootServices
2279 Status
= TcgMeasureAction (
2280 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2282 if (EFI_ERROR (Status
)) {
2283 DEBUG ((EFI_D_ERROR
, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2288 Exit Boot Services Failed Event notification handler.
2290 Measure Failure of ExitBootServices.
2292 @param[in] Event Event whose notification function is being invoked
2293 @param[in] Context Pointer to the notification function's context
2298 OnExitBootServicesFailed (
2306 // Measure Failure of ExitBootServices,
2308 Status
= TcgMeasureAction (
2309 EFI_EXIT_BOOT_SERVICES_FAILED
2311 if (EFI_ERROR (Status
)) {
2312 DEBUG ((EFI_D_ERROR
, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2318 The function install Tcg2 protocol.
2320 @retval EFI_SUCCESS Tcg2 protocol is installed.
2321 @retval other Some error occurs.
2332 Status
= gBS
->InstallMultipleProtocolInterfaces (
2334 &gEfiTcg2ProtocolGuid
,
2342 The driver's entry point. It publishes EFI Tcg2 Protocol.
2344 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2345 @param[in] SystemTable A pointer to the EFI System Table.
2347 @retval EFI_SUCCESS The entry point is executed successfully.
2348 @retval other Some error occurs when executing this entry point.
2353 IN EFI_HANDLE ImageHandle
,
2354 IN EFI_SYSTEM_TABLE
*SystemTable
2360 UINT32 MaxCommandSize
;
2361 UINT32 MaxResponseSize
;
2362 TPML_PCR_SELECTION Pcrs
;
2364 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2365 UINT32 ActivePCRBanks
;
2366 UINT32 NumberOfPCRBanks
;
2368 mImageHandle
= ImageHandle
;
2370 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2371 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2372 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2373 return EFI_UNSUPPORTED
;
2376 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2377 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2378 return EFI_DEVICE_ERROR
;
2381 Status
= Tpm2RequestUseTpm ();
2382 if (EFI_ERROR (Status
)) {
2383 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2390 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2392 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2393 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2394 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2395 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2396 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2398 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2399 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2401 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2402 if (EFI_ERROR (Status
)) {
2403 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2405 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2409 UINT32 FirmwareVersion1
;
2410 UINT32 FirmwareVersion2
;
2412 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2413 if (EFI_ERROR (Status
)) {
2414 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2416 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2420 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2421 if (EFI_ERROR (Status
)) {
2422 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2424 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2425 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2426 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2430 // Get supported PCR and current Active PCRs
2432 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
2433 if (EFI_ERROR (Status
)) {
2434 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityPcrs fail!\n"));
2435 TpmHashAlgorithmBitmap
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2436 NumberOfPCRBanks
= 1;
2437 ActivePCRBanks
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2439 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityPcrs Count - %08x\n", Pcrs
.count
));
2440 NumberOfPCRBanks
= 0;
2441 TpmHashAlgorithmBitmap
= 0;
2443 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
2444 DEBUG ((EFI_D_INFO
, "hash - %x\n", Pcrs
.pcrSelections
[Index
].hash
));
2445 switch (Pcrs
.pcrSelections
[Index
].hash
) {
2447 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2448 NumberOfPCRBanks
++;
2449 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2450 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2453 case TPM_ALG_SHA256
:
2454 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2455 NumberOfPCRBanks
++;
2456 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2457 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2460 case TPM_ALG_SHA384
:
2461 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2462 NumberOfPCRBanks
++;
2463 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2464 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2467 case TPM_ALG_SHA512
:
2468 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2469 NumberOfPCRBanks
++;
2470 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2471 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2474 case TPM_ALG_SM3_256
:
2475 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2476 NumberOfPCRBanks
++;
2477 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2478 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2484 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2485 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2487 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2488 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2490 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2491 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2492 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2493 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2497 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2498 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& TREE_BOOT_HASH_ALG_SHA1
) == 0) {
2500 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2502 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~TREE_EVENT_LOG_FORMAT_TCG_1_2
;
2505 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2506 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2507 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2508 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2510 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2512 // Setup the log area and copy event log from hob list to it
2514 Status
= SetupEventLog ();
2515 ASSERT_EFI_ERROR (Status
);
2518 // Measure handoff tables, Boot#### variables etc.
2520 Status
= EfiCreateEventReadyToBootEx (
2527 Status
= gBS
->CreateEventEx (
2532 &gEfiEventExitBootServicesGuid
,
2537 // Measure Exit Boot Service failed
2539 Status
= gBS
->CreateEventEx (
2542 OnExitBootServicesFailed
,
2544 &gEventExitBootServicesFailedGuid
,
2549 // Create event callback, because we need access variable on SecureBootPolicyVariable
2550 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2551 // may update SecureBoot value based on last setting.
2553 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2557 // Install Tcg2Protocol
2559 Status
= InstallTcg2 ();
2560 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));