2 This module implements Tcg2 Protocol.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <IndustryStandard/Acpi.h>
18 #include <IndustryStandard/PeImage.h>
19 #include <IndustryStandard/TcpaAcpi.h>
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/HobList.h>
23 #include <Guid/TcgEventHob.h>
24 #include <Guid/EventGroup.h>
25 #include <Guid/EventExitBootServiceFailed.h>
26 #include <Guid/ImageAuthentication.h>
27 #include <Guid/TpmInstance.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/MpService.h>
31 #include <Protocol/VariableWrite.h>
32 #include <Protocol/Tcg2Protocol.h>
33 #include <Protocol/TrEEProtocol.h>
35 #include <Library/DebugLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/HobLib.h>
40 #include <Library/UefiBootServicesTableLib.h>
41 #include <Library/BaseLib.h>
42 #include <Library/MemoryAllocationLib.h>
43 #include <Library/PrintLib.h>
44 #include <Library/Tpm2CommandLib.h>
45 #include <Library/PcdLib.h>
46 #include <Library/UefiLib.h>
47 #include <Library/Tpm2DeviceLib.h>
48 #include <Library/HashLib.h>
49 #include <Library/PerformanceLib.h>
50 #include <Library/ReportStatusCodeLib.h>
51 #include <Library/Tcg2PhysicalPresenceLib.h>
53 #define PERF_ID_TCG2_DXE 0x3120
60 #define TCG2_DEFAULT_MAX_COMMAND_SIZE 0x1000
61 #define TCG2_DEFAULT_MAX_RESPONSE_SIZE 0x1000
65 EFI_TCG2_EVENT_LOG_FORMAT LogFormat
;
66 } TCG2_EVENT_INFO_STRUCT
;
68 TCG2_EVENT_INFO_STRUCT mTcg2EventInfo
[] = {
69 {&gTcgEventEntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
},
70 {&gTcgEvent2EntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
},
73 #define TCG_EVENT_LOG_AREA_COUNT_MAX 2
76 EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
;
77 EFI_PHYSICAL_ADDRESS Lasa
;
81 BOOLEAN EventLogStarted
;
82 BOOLEAN EventLogTruncated
;
83 } TCG_EVENT_LOG_AREA_STRUCT
;
85 typedef struct _TCG_DXE_DATA
{
86 EFI_TCG2_BOOT_SERVICE_CAPABILITY BsCap
;
87 TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
88 BOOLEAN GetEventLogCalled
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
89 TCG_EVENT_LOG_AREA_STRUCT FinalEventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
90 EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
93 TCG_DXE_DATA mTcgDxeData
= {
95 sizeof (EFI_TCG2_BOOT_SERVICE_CAPABILITY
), // Size
96 { 1, 1 }, // StructureVersion
97 { 1, 1 }, // ProtocolVersion
98 EFI_TCG2_BOOT_HASH_ALG_SHA1
, // HashAlgorithmBitmap
99 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
, // SupportedEventLogs
100 TRUE
, // TPMPresentFlag
101 TCG2_DEFAULT_MAX_COMMAND_SIZE
, // MaxCommandSize
102 TCG2_DEFAULT_MAX_RESPONSE_SIZE
, // MaxResponseSize
104 0, // NumberOfPCRBanks
109 UINTN mBootAttempts
= 0;
110 CHAR16 mBootVarName
[] = L
"BootOrder";
112 VARIABLE_TYPE mVariableType
[] = {
113 {EFI_SECURE_BOOT_MODE_NAME
, &gEfiGlobalVariableGuid
},
114 {EFI_PLATFORM_KEY_NAME
, &gEfiGlobalVariableGuid
},
115 {EFI_KEY_EXCHANGE_KEY_NAME
, &gEfiGlobalVariableGuid
},
116 {EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
},
117 {EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
},
118 {EFI_IMAGE_SECURITY_DATABASE2
, &gEfiImageSecurityDatabaseGuid
},
121 EFI_HANDLE mImageHandle
;
124 Measure PE image into TPM log based on the authenticode image hashing in
125 PE/COFF Specification 8.0 Appendix A.
127 Caution: This function may receive untrusted input.
128 PE/COFF image is external input, so this function will validate its data structure
129 within this image buffer before use.
131 Notes: PE/COFF image is checked by BasePeCoffLib PeCoffLoaderGetImageInfo().
133 @param[in] PCRIndex TPM PCR index
134 @param[in] ImageAddress Start address of image buffer.
135 @param[in] ImageSize Image size
136 @param[out] DigestList Digeest list of this image.
138 @retval EFI_SUCCESS Successfully measure image.
139 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
140 @retval other error value
143 MeasurePeImageAndExtend (
145 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
147 OUT TPML_DIGEST_VALUES
*DigestList
152 This function dump raw data.
155 @param Size raw data size
165 for (Index
= 0; Index
< Size
; Index
++) {
166 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
172 This function dump raw data with colume format.
175 @param Size raw data size
188 #define COLUME_SIZE (16 * 2)
190 Count
= Size
/ COLUME_SIZE
;
191 Left
= Size
% COLUME_SIZE
;
192 for (Index
= 0; Index
< Count
; Index
++) {
193 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
194 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
195 DEBUG ((EFI_D_INFO
, "\n"));
199 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
200 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
201 DEBUG ((EFI_D_INFO
, "\n"));
206 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
207 Caller is responsible to free LocationBuf.
209 @param[out] LocationBuf Returns Processor Location Buffer.
210 @param[out] Num Returns processor number.
212 @retval EFI_SUCCESS Operation completed successfully.
213 @retval EFI_UNSUPPORTED MpService protocol not found.
217 GetProcessorsCpuLocation (
218 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
223 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
225 UINTN EnabledProcessorNum
;
226 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
227 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
230 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
231 if (EFI_ERROR (Status
)) {
233 // MP protocol is not installed
235 return EFI_UNSUPPORTED
;
238 Status
= MpProtocol
->GetNumberOfProcessors(
243 if (EFI_ERROR(Status
)){
247 Status
= gBS
->AllocatePool(
249 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
250 (VOID
**) &ProcessorLocBuf
252 if (EFI_ERROR(Status
)){
257 // Get each processor Location info
259 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
260 Status
= MpProtocol
->GetProcessorInfo(
265 if (EFI_ERROR(Status
)){
266 FreePool(ProcessorLocBuf
);
271 // Get all Processor Location info & measure
274 &ProcessorLocBuf
[Index
],
275 &ProcessorInfo
.Location
,
276 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
280 *LocationBuf
= ProcessorLocBuf
;
287 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
288 capability information and state information.
290 @param[in] This Indicates the calling context
291 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
292 structure and sets the size field to the size of the structure allocated.
293 The callee fills in the fields with the EFI protocol capability information
294 and the current EFI TCG2 state information up to the number of fields which
295 fit within the size of the structure passed in.
297 @retval EFI_SUCCESS Operation completed successfully.
298 @retval EFI_DEVICE_ERROR The command was unsuccessful.
299 The ProtocolCapability variable will not be populated.
300 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
301 The ProtocolCapability variable will not be populated.
302 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
303 It will be partially populated (required Size field will be set).
308 IN EFI_TCG2_PROTOCOL
*This
,
309 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
312 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability ...\n"));
314 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
315 return EFI_INVALID_PARAMETER
;
318 DEBUG ((DEBUG_VERBOSE
, "Size - 0x%x\n", ProtocolCapability
->Size
));
319 DEBUG ((DEBUG_VERBOSE
, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)));
321 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
323 // Handle the case that firmware support 1.1 but OS only support 1.0.
325 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
326 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
327 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
328 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
329 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
330 ProtocolCapability
->StructureVersion
.Major
= 1;
331 ProtocolCapability
->StructureVersion
.Minor
= 0;
332 ProtocolCapability
->ProtocolVersion
.Major
= 1;
333 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
334 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
338 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
339 return EFI_BUFFER_TOO_SMALL
;
342 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
343 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
348 This function dump PCR event.
350 @param[in] EventHdr TCG PCR event structure.
354 IN TCG_PCR_EVENT_HDR
*EventHdr
359 DEBUG ((EFI_D_INFO
, " Event:\n"));
360 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
361 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
362 DEBUG ((EFI_D_INFO
, " Digest - "));
363 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
364 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
366 DEBUG ((EFI_D_INFO
, "\n"));
367 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
368 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
372 This function dump TCG_EfiSpecIDEventStruct.
374 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
377 DumpTcgEfiSpecIdEventStruct (
378 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
381 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
383 UINT8
*VendorInfoSize
;
385 UINT32 NumberOfAlgorithms
;
387 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
388 DEBUG ((EFI_D_INFO
, " signature - '"));
389 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
390 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
392 DEBUG ((EFI_D_INFO
, "'\n"));
393 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
394 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
395 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
397 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
398 DEBUG ((EFI_D_INFO
, " NumberOfAlgorithms - 0x%08x\n", NumberOfAlgorithms
));
400 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
401 for (Index
= 0; Index
< NumberOfAlgorithms
; Index
++) {
402 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
403 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", DigestSize
[Index
].algorithmId
));
404 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", DigestSize
[Index
].digestSize
));
406 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
407 DEBUG ((EFI_D_INFO
, " VendorInfoSize - 0x%02x\n", *VendorInfoSize
));
408 VendorInfo
= VendorInfoSize
+ 1;
409 DEBUG ((EFI_D_INFO
, " VendorInfo - "));
410 for (Index
= 0; Index
< *VendorInfoSize
; Index
++) {
411 DEBUG ((EFI_D_INFO
, "%02x ", VendorInfo
[Index
]));
413 DEBUG ((EFI_D_INFO
, "\n"));
417 This function get size of TCG_EfiSpecIDEventStruct.
419 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
422 GetTcgEfiSpecIdEventStructSize (
423 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
426 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
427 UINT8
*VendorInfoSize
;
428 UINT32 NumberOfAlgorithms
;
430 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
432 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
433 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
434 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (NumberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*VendorInfoSize
);
438 This function dump PCR event 2.
440 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
444 IN TCG_PCR_EVENT2
*TcgPcrEvent2
450 TPMI_ALG_HASH HashAlgo
;
456 DEBUG ((EFI_D_INFO
, " Event:\n"));
457 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
458 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
460 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
462 DigestCount
= TcgPcrEvent2
->Digest
.count
;
463 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
464 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
465 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
466 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
467 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
468 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
469 for (Index
= 0; Index
< DigestSize
; Index
++) {
470 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
472 DEBUG ((EFI_D_INFO
, "\n"));
476 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
477 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
479 DEBUG ((EFI_D_INFO
, "\n"));
480 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
482 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
483 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
484 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
485 InternalDumpHex (EventBuffer
, EventSize
);
489 This function returns size of TCG PCR event 2.
491 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
493 @return size of TCG PCR event 2.
497 IN TCG_PCR_EVENT2
*TcgPcrEvent2
502 TPMI_ALG_HASH HashAlgo
;
508 DigestCount
= TcgPcrEvent2
->Digest
.count
;
509 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
510 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
511 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
512 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
516 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
517 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
519 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
521 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
522 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
524 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
528 This function dump event log.
530 @param[in] EventLogFormat The type of the event log for which the information is requested.
531 @param[in] EventLogLocation A pointer to the memory address of the event log.
532 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
533 address of the start of the last entry in the event log in memory.
534 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
538 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
539 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
540 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
541 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
544 TCG_PCR_EVENT_HDR
*EventHdr
;
545 TCG_PCR_EVENT2
*TcgPcrEvent2
;
546 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
547 UINTN NumberOfEvents
;
549 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
551 switch (EventLogFormat
) {
552 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
553 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
554 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
555 DumpEvent (EventHdr
);
556 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
558 if (FinalEventsTable
== NULL
) {
559 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
561 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
562 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
563 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
565 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
566 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
567 DumpEvent (EventHdr
);
568 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
572 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
576 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
577 DumpEvent (EventHdr
);
579 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
580 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
582 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
583 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
584 DumpEvent2 (TcgPcrEvent2
);
585 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
588 if (FinalEventsTable
== NULL
) {
589 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
591 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
592 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
593 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
595 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
596 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
597 DumpEvent2 (TcgPcrEvent2
);
598 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
608 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
609 retrieve the address of a given event log and its last entry.
611 @param[in] This Indicates the calling context
612 @param[in] EventLogFormat The type of the event log for which the information is requested.
613 @param[out] EventLogLocation A pointer to the memory address of the event log.
614 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
615 address of the start of the last entry in the event log in memory.
616 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
617 have exceeded the area allocated for events, this value is set to TRUE.
618 Otherwise, the value will be FALSE and the Event Log will be complete.
620 @retval EFI_SUCCESS Operation completed successfully.
621 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
622 (e.g. asking for an event log whose format is not supported).
627 IN EFI_TCG2_PROTOCOL
*This
,
628 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
629 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
630 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
631 OUT BOOLEAN
*EventLogTruncated
636 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
639 return EFI_INVALID_PARAMETER
;
642 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
643 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
648 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
649 return EFI_INVALID_PARAMETER
;
652 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
653 return EFI_INVALID_PARAMETER
;
656 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
657 if (EventLogLocation
!= NULL
) {
658 *EventLogLocation
= 0;
660 if (EventLogLastEntry
!= NULL
) {
661 *EventLogLastEntry
= 0;
663 if (EventLogTruncated
!= NULL
) {
664 *EventLogTruncated
= FALSE
;
669 if (EventLogLocation
!= NULL
) {
670 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
671 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
674 if (EventLogLastEntry
!= NULL
) {
675 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
676 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
678 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
680 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
683 if (EventLogTruncated
!= NULL
) {
684 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
685 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
688 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
690 // Dump Event Log for debug purpose
691 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
692 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
696 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
697 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
699 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
705 Add a new entry to the Event Log.
707 @param[in, out] EventLogPtr Pointer to the Event Log data.
708 @param[in, out] LogSize Size of the Event Log.
709 @param[in] MaxSize Maximum size of the Event Log.
710 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
711 @param[in] NewEventHdrSize New event header size.
712 @param[in] NewEventData Pointer to the new event data.
713 @param[in] NewEventSize New event data size.
715 @retval EFI_SUCCESS The new event log entry was added.
716 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
721 IN OUT UINT8
**EventLogPtr
,
722 IN OUT UINTN
*LogSize
,
724 IN VOID
*NewEventHdr
,
725 IN UINT32 NewEventHdrSize
,
726 IN UINT8
*NewEventData
,
727 IN UINT32 NewEventSize
732 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
733 return EFI_OUT_OF_RESOURCES
;
736 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
738 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
739 return EFI_OUT_OF_RESOURCES
;
742 if (NewLogSize
+ *LogSize
> MaxSize
) {
743 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
744 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
745 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
746 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
747 return EFI_OUT_OF_RESOURCES
;
750 *EventLogPtr
+= *LogSize
;
751 *LogSize
+= NewLogSize
;
752 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
754 *EventLogPtr
+ NewEventHdrSize
,
762 Add a new entry to the Event Log.
764 @param[in] EventLogFormat The type of the event log for which the information is requested.
765 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
766 @param[in] NewEventHdrSize New event header size.
767 @param[in] NewEventData Pointer to the new event data.
768 @param[in] NewEventSize New event data size.
770 @retval EFI_SUCCESS The new event log entry was added.
771 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
776 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
777 IN VOID
*NewEventHdr
,
778 IN UINT32 NewEventHdrSize
,
779 IN UINT8
*NewEventData
,
780 IN UINT32 NewEventSize
785 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
787 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
788 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
793 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
794 return EFI_INVALID_PARAMETER
;
798 // Record to normal event log
800 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
802 if (EventLogAreaStruct
->EventLogTruncated
) {
803 return EFI_VOLUME_FULL
;
806 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
807 Status
= TcgCommLogEvent (
808 &EventLogAreaStruct
->LastEvent
,
809 &EventLogAreaStruct
->EventLogSize
,
810 (UINTN
)EventLogAreaStruct
->Laml
,
817 if (Status
== EFI_OUT_OF_RESOURCES
) {
818 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
819 return EFI_VOLUME_FULL
;
820 } else if (Status
== EFI_SUCCESS
) {
821 EventLogAreaStruct
->EventLogStarted
= TRUE
;
825 // If GetEventLog is called, record to FinalEventsTable, too.
827 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
828 if (mTcgDxeData
.FinalEventsTable
[Index
] == NULL
) {
830 // no need for FinalEventsTable
834 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
836 if (EventLogAreaStruct
->EventLogTruncated
) {
837 return EFI_VOLUME_FULL
;
840 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
841 Status
= TcgCommLogEvent (
842 &EventLogAreaStruct
->LastEvent
,
843 &EventLogAreaStruct
->EventLogSize
,
844 (UINTN
)EventLogAreaStruct
->Laml
,
850 if (Status
== EFI_OUT_OF_RESOURCES
) {
851 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
852 return EFI_VOLUME_FULL
;
853 } else if (Status
== EFI_SUCCESS
) {
854 EventLogAreaStruct
->EventLogStarted
= TRUE
;
856 // Increase the NumberOfEvents in FinalEventsTable
858 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
859 DEBUG ((EFI_D_INFO
, "FinalEventsTable->NumberOfEvents - 0x%x\n", (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
));
860 DEBUG ((EFI_D_INFO
, " Size - 0x%x\n", (UINTN
)EventLogAreaStruct
->EventLogSize
));
868 Get TPML_DIGEST_VALUES compact binary buffer size.
870 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
872 @return TPML_DIGEST_VALUES compact binary buffer size.
875 GetDigestListBinSize (
876 IN VOID
*DigestListBin
883 TPMI_ALG_HASH HashAlg
;
885 Count
= ReadUnaligned32 (DigestListBin
);
886 TotalSize
= sizeof(Count
);
887 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
888 for (Index
= 0; Index
< Count
; Index
++) {
889 HashAlg
= ReadUnaligned16 (DigestListBin
);
890 TotalSize
+= sizeof(HashAlg
);
891 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
893 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
894 TotalSize
+= DigestSize
;
895 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
902 Copy TPML_DIGEST_VALUES compact binary into a buffer
904 @param[in,out] Buffer Buffer to hold copied TPML_DIGEST_VALUES compact binary.
905 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
906 @param[in] HashAlgorithmMask HASH bits corresponding to the desired digests to copy.
907 @param[out] HashAlgorithmMaskCopied Pointer to HASH bits corresponding to the digests copied.
909 @return The end of buffer to hold TPML_DIGEST_VALUES compact binary.
912 CopyDigestListBinToBuffer (
914 IN VOID
*DigestListBin
,
915 IN UINT32 HashAlgorithmMask
,
916 OUT UINT32
*HashAlgorithmMaskCopied
922 TPMI_ALG_HASH HashAlg
;
923 UINT32 DigestListCount
;
924 UINT32
*DigestListCountPtr
;
926 DigestListCountPtr
= (UINT32
*) Buffer
;
928 (*HashAlgorithmMaskCopied
) = 0;
930 Count
= ReadUnaligned32 (DigestListBin
);
931 Buffer
= (UINT8
*)Buffer
+ sizeof(Count
);
932 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
933 for (Index
= 0; Index
< Count
; Index
++) {
934 HashAlg
= ReadUnaligned16 (DigestListBin
);
935 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
936 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
938 if (IsHashAlgSupportedInHashAlgorithmMask(HashAlg
, HashAlgorithmMask
)) {
939 CopyMem (Buffer
, &HashAlg
, sizeof(HashAlg
));
940 Buffer
= (UINT8
*)Buffer
+ sizeof(HashAlg
);
941 CopyMem (Buffer
, DigestListBin
, DigestSize
);
942 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
944 (*HashAlgorithmMaskCopied
) |= GetHashMaskFromAlgo (HashAlg
);
946 DEBUG ((DEBUG_ERROR
, "WARNING: CopyDigestListBinToBuffer Event log has HashAlg unsupported by PCR bank (0x%x)\n", HashAlg
));
948 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
950 WriteUnaligned32 (DigestListCountPtr
, DigestListCount
);
956 Add a new entry to the Event Log.
958 @param[in] DigestList A list of digest.
959 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
960 @param[in] NewEventData Pointer to the new event data.
962 @retval EFI_SUCCESS The new event log entry was added.
963 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
967 IN TPML_DIGEST_VALUES
*DigestList
,
968 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
969 IN UINT8
*NewEventData
975 EFI_STATUS RetStatus
;
976 TCG_PCR_EVENT2 TcgPcrEvent2
;
978 UINT32
*EventSizePtr
;
980 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
982 RetStatus
= EFI_SUCCESS
;
983 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
984 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
985 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
986 switch (mTcg2EventInfo
[Index
].LogFormat
) {
987 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
988 Status
= GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
989 if (!EFI_ERROR (Status
)) {
991 // Enter critical region
993 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
994 Status
= TcgDxeLogEvent (
995 mTcg2EventInfo
[Index
].LogFormat
,
997 sizeof(TCG_PCR_EVENT_HDR
),
999 NewEventHdr
->EventSize
1001 if (Status
!= EFI_SUCCESS
) {
1004 gBS
->RestoreTPL (OldTpl
);
1006 // Exit critical region
1010 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1011 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1012 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1013 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1014 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1015 EventSizePtr
= CopyDigestListToBuffer (DigestBuffer
, DigestList
, mTcgDxeData
.BsCap
.ActivePcrBanks
);
1016 CopyMem (EventSizePtr
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1019 // Enter critical region
1021 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1022 Status
= TcgDxeLogEvent (
1023 mTcg2EventInfo
[Index
].LogFormat
,
1025 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListBinSize (DigestBuffer
) + sizeof(TcgPcrEvent2
.EventSize
),
1027 NewEventHdr
->EventSize
1029 if (Status
!= EFI_SUCCESS
) {
1032 gBS
->RestoreTPL (OldTpl
);
1034 // Exit critical region
1045 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1046 and add an entry to the Event Log.
1048 @param[in] Flags Bitmap providing additional information.
1049 @param[in] HashData Physical address of the start of the data buffer
1050 to be hashed, extended, and logged.
1051 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1052 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1053 @param[in] NewEventData Pointer to the new event data.
1055 @retval EFI_SUCCESS Operation completed successfully.
1056 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1057 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1061 TcgDxeHashLogExtendEvent (
1064 IN UINT64 HashDataLen
,
1065 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1066 IN UINT8
*NewEventData
1070 TPML_DIGEST_VALUES DigestList
;
1072 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1073 return EFI_DEVICE_ERROR
;
1076 Status
= HashAndExtend (
1077 NewEventHdr
->PCRIndex
,
1082 if (!EFI_ERROR (Status
)) {
1083 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1084 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1088 if (Status
== EFI_DEVICE_ERROR
) {
1089 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1090 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1091 REPORT_STATUS_CODE (
1092 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1093 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1101 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1102 an opportunity to extend and optionally log events without requiring
1103 knowledge of actual TPM commands.
1104 The extend operation will occur even if this function cannot create an event
1105 log entry (e.g. due to the event log being full).
1107 @param[in] This Indicates the calling context
1108 @param[in] Flags Bitmap providing additional information.
1109 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1110 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1111 @param[in] Event Pointer to data buffer containing information about the event.
1113 @retval EFI_SUCCESS Operation completed successfully.
1114 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1115 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1116 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1117 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1121 Tcg2HashLogExtendEvent (
1122 IN EFI_TCG2_PROTOCOL
*This
,
1124 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1125 IN UINT64 DataToHashLen
,
1126 IN EFI_TCG2_EVENT
*Event
1130 TCG_PCR_EVENT_HDR NewEventHdr
;
1131 TPML_DIGEST_VALUES DigestList
;
1133 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent ...\n"));
1135 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1136 return EFI_INVALID_PARAMETER
;
1139 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1140 return EFI_DEVICE_ERROR
;
1143 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1144 return EFI_INVALID_PARAMETER
;
1147 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1148 return EFI_INVALID_PARAMETER
;
1151 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1152 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1153 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1154 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1155 Status
= MeasurePeImageAndExtend (
1156 NewEventHdr
.PCRIndex
,
1158 (UINTN
)DataToHashLen
,
1161 if (!EFI_ERROR (Status
)) {
1162 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1163 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1166 if (Status
== EFI_DEVICE_ERROR
) {
1167 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %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
)
1175 Status
= TcgDxeHashLogExtendEvent (
1177 (UINT8
*) (UINTN
) DataToHash
,
1183 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1188 This service enables the sending of commands to the TPM.
1190 @param[in] This Indicates the calling context
1191 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1192 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1193 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1194 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1196 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1197 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1198 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1199 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1204 IN EFI_TCG2_PROTOCOL
*This
,
1205 IN UINT32 InputParameterBlockSize
,
1206 IN UINT8
*InputParameterBlock
,
1207 IN UINT32 OutputParameterBlockSize
,
1208 IN UINT8
*OutputParameterBlock
1213 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1215 if ((This
== NULL
) ||
1216 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1217 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1218 return EFI_INVALID_PARAMETER
;
1221 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1222 return EFI_DEVICE_ERROR
;
1225 if (InputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxCommandSize
) {
1226 return EFI_INVALID_PARAMETER
;
1228 if (OutputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxResponseSize
) {
1229 return EFI_INVALID_PARAMETER
;
1232 Status
= Tpm2SubmitCommand (
1233 InputParameterBlockSize
,
1234 InputParameterBlock
,
1235 &OutputParameterBlockSize
,
1236 OutputParameterBlock
1238 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1243 This service returns the currently active PCR banks.
1245 @param[in] This Indicates the calling context
1246 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1248 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1249 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1253 Tcg2GetActivePCRBanks (
1254 IN EFI_TCG2_PROTOCOL
*This
,
1255 OUT UINT32
*ActivePcrBanks
1258 if (ActivePcrBanks
== NULL
) {
1259 return EFI_INVALID_PARAMETER
;
1261 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1266 This service sets the currently active PCR banks.
1268 @param[in] This Indicates the calling context
1269 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1271 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1272 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1276 Tcg2SetActivePCRBanks (
1277 IN EFI_TCG2_PROTOCOL
*This
,
1278 IN UINT32 ActivePcrBanks
1284 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1286 if (ActivePcrBanks
== 0) {
1287 return EFI_INVALID_PARAMETER
;
1289 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1290 return EFI_INVALID_PARAMETER
;
1292 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1294 // Need clear previous SET_PCR_BANKS setting
1296 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1298 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1301 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1302 Status
= EFI_SUCCESS
;
1303 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1304 Status
= EFI_OUT_OF_RESOURCES
;
1305 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1306 Status
= EFI_UNSUPPORTED
;
1308 Status
= EFI_DEVICE_ERROR
;
1311 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1317 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1319 @param[in] This Indicates the calling context
1320 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1321 @param[out] Response The response from the SetActivePcrBank request.
1323 @retval EFI_SUCCESS The result value could be returned.
1324 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1328 Tcg2GetResultOfSetActivePcrBanks (
1329 IN EFI_TCG2_PROTOCOL
*This
,
1330 OUT UINT32
*OperationPresent
,
1331 OUT UINT32
*Response
1336 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1337 return EFI_INVALID_PARAMETER
;
1340 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1341 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1344 return EFI_UNSUPPORTED
;
1348 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1351 Tcg2HashLogExtendEvent
,
1353 Tcg2GetActivePCRBanks
,
1354 Tcg2SetActivePCRBanks
,
1355 Tcg2GetResultOfSetActivePcrBanks
,
1359 Initialize the Event Log and log events passed from the PEI phase.
1361 @retval EFI_SUCCESS Operation completed successfully.
1362 @retval EFI_OUT_OF_RESOURCES Out of memory.
1372 EFI_PEI_HOB_POINTERS GuidHob
;
1373 EFI_PHYSICAL_ADDRESS Lasa
;
1375 VOID
*DigestListBin
;
1376 TPML_DIGEST_VALUES TempDigestListBin
;
1377 UINT32 DigestListBinSize
;
1380 UINT32
*EventSizePtr
;
1381 UINT32 HashAlgorithmMaskCopied
;
1382 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1383 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1384 TCG_PCR_EVENT_HDR NoActionEvent
;
1385 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
1386 TCG_EfiSpecIdEventAlgorithmSize
*TempDigestSize
;
1387 UINT8
*VendorInfoSize
;
1388 UINT32 NumberOfAlgorithms
;
1389 TCG_EfiStartupLocalityEvent StartupLocalityEvent
;
1391 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1394 // 1. Create Log Area
1396 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1397 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1398 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1399 Status
= gBS
->AllocatePages (
1401 EfiBootServicesData
,
1402 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen
)),
1405 if (EFI_ERROR (Status
)) {
1408 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1409 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcgLogAreaMinLen
);
1411 // To initialize them as 0xFF is recommended
1412 // because the OS can know the last entry for that.
1414 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcgLogAreaMinLen
), 0xFF);
1416 // Create first entry for Log Header Entry Data
1418 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1420 // TcgEfiSpecIdEventStruct
1422 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1423 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1424 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1425 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1426 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1427 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1428 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1429 NumberOfAlgorithms
= 0;
1430 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
1431 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1432 TempDigestSize
= DigestSize
;
1433 TempDigestSize
+= NumberOfAlgorithms
;
1434 TempDigestSize
->algorithmId
= TPM_ALG_SHA1
;
1435 TempDigestSize
->digestSize
= SHA1_DIGEST_SIZE
;
1436 NumberOfAlgorithms
++;
1438 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1439 TempDigestSize
= DigestSize
;
1440 TempDigestSize
+= NumberOfAlgorithms
;
1441 TempDigestSize
->algorithmId
= TPM_ALG_SHA256
;
1442 TempDigestSize
->digestSize
= SHA256_DIGEST_SIZE
;
1443 NumberOfAlgorithms
++;
1445 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1446 TempDigestSize
= DigestSize
;
1447 TempDigestSize
+= NumberOfAlgorithms
;
1448 TempDigestSize
->algorithmId
= TPM_ALG_SHA384
;
1449 TempDigestSize
->digestSize
= SHA384_DIGEST_SIZE
;
1450 NumberOfAlgorithms
++;
1452 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1453 TempDigestSize
= DigestSize
;
1454 TempDigestSize
+= NumberOfAlgorithms
;
1455 TempDigestSize
->algorithmId
= TPM_ALG_SHA512
;
1456 TempDigestSize
->digestSize
= SHA512_DIGEST_SIZE
;
1457 NumberOfAlgorithms
++;
1459 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1460 TempDigestSize
= DigestSize
;
1461 TempDigestSize
+= NumberOfAlgorithms
;
1462 TempDigestSize
->algorithmId
= TPM_ALG_SM3_256
;
1463 TempDigestSize
->digestSize
= SM3_256_DIGEST_SIZE
;
1464 NumberOfAlgorithms
++;
1466 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &NumberOfAlgorithms
, sizeof(NumberOfAlgorithms
));
1467 TempDigestSize
= DigestSize
;
1468 TempDigestSize
+= NumberOfAlgorithms
;
1469 VendorInfoSize
= (UINT8
*)TempDigestSize
;
1470 *VendorInfoSize
= 0;
1472 NoActionEvent
.PCRIndex
= 0;
1473 NoActionEvent
.EventType
= EV_NO_ACTION
;
1474 ZeroMem (&NoActionEvent
.Digest
, sizeof(NoActionEvent
.Digest
));
1475 NoActionEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1478 // Log TcgEfiSpecIdEventStruct as the first Event
1479 // TCG PC Client PFP spec. Section 9.2 Measurement Event Entries and Log
1481 Status
= TcgDxeLogEvent (
1482 mTcg2EventInfo
[Index
].LogFormat
,
1484 sizeof(NoActionEvent
),
1485 (UINT8
*)TcgEfiSpecIdEventStruct
,
1486 NoActionEvent
.EventSize
1490 // EfiStartupLocalityEvent
1492 GuidHob
.Guid
= GetFirstGuidHob (&gTpm2StartupLocalityHobGuid
);
1493 if (GuidHob
.Guid
!= NULL
) {
1495 // Get Locality Indicator from StartupLocality HOB
1497 StartupLocalityEvent
.StartupLocality
= *(UINT8
*)(GET_GUID_HOB_DATA (GuidHob
.Guid
));
1498 CopyMem (StartupLocalityEvent
.Signature
, TCG_EfiStartupLocalityEvent_SIGNATURE
, sizeof(StartupLocalityEvent
.Signature
));
1500 NoActionEvent
.PCRIndex
= 0;
1501 NoActionEvent
.EventType
= EV_NO_ACTION
;
1502 ZeroMem (&NoActionEvent
.Digest
, sizeof(NoActionEvent
.Digest
));
1503 NoActionEvent
.EventSize
= sizeof(StartupLocalityEvent
);
1505 DEBUG ((DEBUG_INFO
, "SetupEventLog: Set Locality from HOB into StartupLocalityEvent 0x%02x\n", StartupLocalityEvent
.StartupLocality
));
1508 // Log EfiStartupLocalityEvent as the second Event
1509 // TCG PC Client PFP spec. Section 9.3.4.3 Startup Locality Event
1511 Status
= TcgDxeLogEvent (
1512 mTcg2EventInfo
[Index
].LogFormat
,
1514 sizeof(NoActionEvent
),
1515 (UINT8
*)&StartupLocalityEvent
,
1516 NoActionEvent
.EventSize
1524 // 2. Create Final Log Area
1526 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1527 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1528 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1529 Status
= gBS
->AllocatePages (
1532 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen
)),
1535 if (EFI_ERROR (Status
)) {
1538 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcg2FinalLogAreaLen
), 0xFF);
1543 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1544 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1545 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1547 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1548 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1549 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcg2FinalLogAreaLen
) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1550 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1551 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1552 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1553 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1556 // Install to configuration table for EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
1558 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[Index
]);
1559 if (EFI_ERROR (Status
)) {
1564 // No need to handle EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
1566 mTcgDxeData
.FinalEventsTable
[Index
] = NULL
;
1567 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1568 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= 0;
1569 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= 0;
1570 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1571 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= 0;
1572 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1573 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1579 // 3. Sync data from PEI to DXE
1581 Status
= EFI_SUCCESS
;
1582 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1583 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1584 GuidHob
.Raw
= GetHobList ();
1585 Status
= EFI_SUCCESS
;
1586 while (!EFI_ERROR (Status
) &&
1587 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1588 TcgEvent
= AllocateCopyPool (GET_GUID_HOB_DATA_SIZE (GuidHob
.Guid
), GET_GUID_HOB_DATA (GuidHob
.Guid
));
1589 ASSERT (TcgEvent
!= NULL
);
1590 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1591 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1592 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1593 Status
= TcgDxeLogEvent (
1594 mTcg2EventInfo
[Index
].LogFormat
,
1596 sizeof(TCG_PCR_EVENT_HDR
),
1597 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1598 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1601 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1602 DigestListBin
= (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
);
1603 DigestListBinSize
= GetDigestListBinSize (DigestListBin
);
1607 CopyMem (&EventSize
, (UINT8
*)DigestListBin
+ DigestListBinSize
, sizeof(UINT32
));
1608 Event
= (UINT8
*)DigestListBin
+ DigestListBinSize
+ sizeof(UINT32
);
1610 // Filter inactive digest in the event2 log from PEI HOB.
1612 CopyMem (&TempDigestListBin
, DigestListBin
, GetDigestListBinSize (DigestListBin
));
1613 EventSizePtr
= CopyDigestListBinToBuffer (
1616 mTcgDxeData
.BsCap
.ActivePcrBanks
,
1617 &HashAlgorithmMaskCopied
1619 if (HashAlgorithmMaskCopied
!= mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1622 "ERROR: The event2 log includes digest hash mask 0x%x, but required digest hash mask is 0x%x\n",
1623 HashAlgorithmMaskCopied
,
1624 mTcgDxeData
.BsCap
.ActivePcrBanks
1628 // Restore event size.
1630 CopyMem (EventSizePtr
, &EventSize
, sizeof(UINT32
));
1631 DigestListBinSize
= GetDigestListBinSize (DigestListBin
);
1633 Status
= TcgDxeLogEvent (
1634 mTcg2EventInfo
[Index
].LogFormat
,
1636 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1642 FreePool (TcgEvent
);
1651 Measure and log an action string, and extend the measurement result into PCR[5].
1653 @param[in] String A specific string that indicates an Action event.
1655 @retval EFI_SUCCESS Operation completed successfully.
1656 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1664 TCG_PCR_EVENT_HDR TcgEvent
;
1666 TcgEvent
.PCRIndex
= 5;
1667 TcgEvent
.EventType
= EV_EFI_ACTION
;
1668 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1669 return TcgDxeHashLogExtendEvent (
1679 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1681 @retval EFI_SUCCESS Operation completed successfully.
1682 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1686 MeasureHandoffTables (
1691 TCG_PCR_EVENT_HDR TcgEvent
;
1692 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1694 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1696 ProcessorLocBuf
= NULL
;
1697 Status
= EFI_SUCCESS
;
1699 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1702 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1704 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1706 if (!EFI_ERROR(Status
)){
1707 TcgEvent
.PCRIndex
= 1;
1708 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1709 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1711 HandoffTables
.NumberOfTables
= 1;
1712 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1713 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1715 Status
= TcgDxeHashLogExtendEvent (
1717 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1718 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1720 (UINT8
*)&HandoffTables
1723 FreePool(ProcessorLocBuf
);
1731 Measure and log Separator event, and extend the measurement result into a specific PCR.
1733 @param[in] PCRIndex PCR index.
1735 @retval EFI_SUCCESS Operation completed successfully.
1736 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1740 MeasureSeparatorEvent (
1741 IN TPM_PCRINDEX PCRIndex
1744 TCG_PCR_EVENT_HDR TcgEvent
;
1747 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1750 TcgEvent
.PCRIndex
= PCRIndex
;
1751 TcgEvent
.EventType
= EV_SEPARATOR
;
1752 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1753 return TcgDxeHashLogExtendEvent (
1755 (UINT8
*)&EventData
,
1763 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1765 @param[in] PCRIndex PCR Index.
1766 @param[in] EventType Event type.
1767 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1768 @param[in] VendorGuid A unique identifier for the vendor.
1769 @param[in] VarData The content of the variable data.
1770 @param[in] VarSize The size of the variable data.
1772 @retval EFI_SUCCESS Operation completed successfully.
1773 @retval EFI_OUT_OF_RESOURCES Out of memory.
1774 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1779 IN TPM_PCRINDEX PCRIndex
,
1780 IN TCG_EVENTTYPE EventType
,
1782 IN EFI_GUID
*VendorGuid
,
1788 TCG_PCR_EVENT_HDR TcgEvent
;
1789 UINTN VarNameLength
;
1790 UEFI_VARIABLE_DATA
*VarLog
;
1792 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1793 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1795 VarNameLength
= StrLen (VarName
);
1796 TcgEvent
.PCRIndex
= PCRIndex
;
1797 TcgEvent
.EventType
= EventType
;
1799 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1800 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1802 VarLog
= (UEFI_VARIABLE_DATA
*)AllocatePool (TcgEvent
.EventSize
);
1803 if (VarLog
== NULL
) {
1804 return EFI_OUT_OF_RESOURCES
;
1807 VarLog
->VariableName
= *VendorGuid
;
1808 VarLog
->UnicodeNameLength
= VarNameLength
;
1809 VarLog
->VariableDataLength
= VarSize
;
1811 VarLog
->UnicodeName
,
1813 VarNameLength
* sizeof (*VarName
)
1815 if (VarSize
!= 0 && VarData
!= NULL
) {
1817 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1823 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1825 // Digest is the event data (UEFI_VARIABLE_DATA)
1827 Status
= TcgDxeHashLogExtendEvent (
1835 ASSERT (VarData
!= NULL
);
1836 Status
= TcgDxeHashLogExtendEvent (
1849 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1851 @param[in] PCRIndex PCR Index.
1852 @param[in] EventType Event type.
1853 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1854 @param[in] VendorGuid A unique identifier for the vendor.
1855 @param[out] VarSize The size of the variable data.
1856 @param[out] VarData Pointer to the content of the variable.
1858 @retval EFI_SUCCESS Operation completed successfully.
1859 @retval EFI_OUT_OF_RESOURCES Out of memory.
1860 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1864 ReadAndMeasureVariable (
1865 IN TPM_PCRINDEX PCRIndex
,
1866 IN TCG_EVENTTYPE EventType
,
1868 IN EFI_GUID
*VendorGuid
,
1875 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1876 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1877 if (EFI_ERROR (Status
)) {
1879 // It is valid case, so we need handle it.
1886 // if status error, VarData is freed and set NULL by GetVariable2
1888 if (EFI_ERROR (Status
)) {
1889 return EFI_NOT_FOUND
;
1893 Status
= MeasureVariable (
1905 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1907 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1908 @param[in] VendorGuid A unique identifier for the vendor.
1909 @param[out] VarSize The size of the variable data.
1910 @param[out] VarData Pointer to the content of the variable.
1912 @retval EFI_SUCCESS Operation completed successfully.
1913 @retval EFI_OUT_OF_RESOURCES Out of memory.
1914 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1918 ReadAndMeasureBootVariable (
1920 IN EFI_GUID
*VendorGuid
,
1925 return ReadAndMeasureVariable (
1927 EV_EFI_VARIABLE_BOOT
,
1936 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1938 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1939 @param[in] VendorGuid A unique identifier for the vendor.
1940 @param[out] VarSize The size of the variable data.
1941 @param[out] VarData Pointer to the content of the variable.
1943 @retval EFI_SUCCESS Operation completed successfully.
1944 @retval EFI_OUT_OF_RESOURCES Out of memory.
1945 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1949 ReadAndMeasureSecureVariable (
1951 IN EFI_GUID
*VendorGuid
,
1956 return ReadAndMeasureVariable (
1958 EV_EFI_VARIABLE_DRIVER_CONFIG
,
1967 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
1969 The EFI boot variables are BootOrder and Boot#### variables.
1971 @retval EFI_SUCCESS Operation completed successfully.
1972 @retval EFI_OUT_OF_RESOURCES Out of memory.
1973 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1977 MeasureAllBootVariables (
1988 Status
= ReadAndMeasureBootVariable (
1990 &gEfiGlobalVariableGuid
,
1992 (VOID
**) &BootOrder
1994 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
1998 if (EFI_ERROR (Status
)) {
2000 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
2002 FreePool (BootOrder
);
2006 BootCount
/= sizeof (*BootOrder
);
2007 for (Index
= 0; Index
< BootCount
; Index
++) {
2008 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
2009 Status
= ReadAndMeasureBootVariable (
2011 &gEfiGlobalVariableGuid
,
2015 if (!EFI_ERROR (Status
)) {
2016 FreePool (BootVarData
);
2020 FreePool (BootOrder
);
2025 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2027 The EFI boot variables are BootOrder and Boot#### variables.
2029 @retval EFI_SUCCESS Operation completed successfully.
2030 @retval EFI_OUT_OF_RESOURCES Out of memory.
2031 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2035 MeasureAllSecureVariables (
2044 Status
= EFI_NOT_FOUND
;
2045 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2046 Status
= ReadAndMeasureSecureVariable (
2047 mVariableType
[Index
].VariableName
,
2048 mVariableType
[Index
].VendorGuid
,
2052 if (!EFI_ERROR (Status
)) {
2063 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2065 @retval EFI_SUCCESS Operation completed successfully.
2066 @retval EFI_OUT_OF_RESOURCES Out of memory.
2067 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2071 MeasureLaunchOfFirmwareDebugger (
2075 TCG_PCR_EVENT_HDR TcgEvent
;
2077 TcgEvent
.PCRIndex
= 7;
2078 TcgEvent
.EventType
= EV_EFI_ACTION
;
2079 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2080 return TcgDxeHashLogExtendEvent (
2082 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2083 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2085 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2090 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2092 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2093 - The contents of the SecureBoot variable
2094 - The contents of the PK variable
2095 - The contents of the KEK variable
2096 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2097 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2099 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2101 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2102 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2104 @param[in] Event Event whose notification function is being invoked
2105 @param[in] Context Pointer to the notification function's context
2109 MeasureSecureBootPolicy (
2117 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2118 if (EFI_ERROR (Status
)) {
2122 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2123 Status
= MeasureLaunchOfFirmwareDebugger ();
2124 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2127 Status
= MeasureAllSecureVariables ();
2128 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2131 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2132 // and ImageVerification (Authority)
2133 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2134 // the Authority measurement happen before ReadToBoot event.
2136 Status
= MeasureSeparatorEvent (7);
2137 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2142 Ready to Boot Event notification handler.
2144 Sequence of OS boot events is measured in this event notification handler.
2146 @param[in] Event Event whose notification function is being invoked
2147 @param[in] Context Pointer to the notification function's context
2158 TPM_PCRINDEX PcrIndex
;
2160 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2161 if (mBootAttempts
== 0) {
2164 // Measure handoff tables.
2166 Status
= MeasureHandoffTables ();
2167 if (EFI_ERROR (Status
)) {
2168 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2172 // Measure BootOrder & Boot#### variables.
2174 Status
= MeasureAllBootVariables ();
2175 if (EFI_ERROR (Status
)) {
2176 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2180 // 1. This is the first boot attempt.
2182 Status
= TcgMeasureAction (
2183 EFI_CALLING_EFI_APPLICATION
2185 if (EFI_ERROR (Status
)) {
2186 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2190 // 2. Draw a line between pre-boot env and entering post-boot env.
2191 // PCR[7] is already done.
2193 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2194 Status
= MeasureSeparatorEvent (PcrIndex
);
2195 if (EFI_ERROR (Status
)) {
2196 DEBUG ((DEBUG_ERROR
, "Separator Event not Measured. Error!\n"));
2201 // 3. Measure GPT. It would be done in SAP driver.
2205 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2209 // 5. Read & Measure variable. BootOrder already measured.
2213 // 6. Not first attempt, meaning a return from last attempt
2215 Status
= TcgMeasureAction (
2216 EFI_RETURNING_FROM_EFI_APPLICATOIN
2218 if (EFI_ERROR (Status
)) {
2219 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2223 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2225 // Increase boot attempt counter.
2228 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2232 Exit Boot Services Event notification handler.
2234 Measure invocation and success of ExitBootServices.
2236 @param[in] Event Event whose notification function is being invoked
2237 @param[in] Context Pointer to the notification function's context
2242 OnExitBootServices (
2250 // Measure invocation of ExitBootServices,
2252 Status
= TcgMeasureAction (
2253 EFI_EXIT_BOOT_SERVICES_INVOCATION
2255 if (EFI_ERROR (Status
)) {
2256 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2260 // Measure success of ExitBootServices
2262 Status
= TcgMeasureAction (
2263 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2265 if (EFI_ERROR (Status
)) {
2266 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2271 Exit Boot Services Failed Event notification handler.
2273 Measure Failure of ExitBootServices.
2275 @param[in] Event Event whose notification function is being invoked
2276 @param[in] Context Pointer to the notification function's context
2281 OnExitBootServicesFailed (
2289 // Measure Failure of ExitBootServices,
2291 Status
= TcgMeasureAction (
2292 EFI_EXIT_BOOT_SERVICES_FAILED
2294 if (EFI_ERROR (Status
)) {
2295 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2301 The function install Tcg2 protocol.
2303 @retval EFI_SUCCESS Tcg2 protocol is installed.
2304 @retval other Some error occurs.
2315 Status
= gBS
->InstallMultipleProtocolInterfaces (
2317 &gEfiTcg2ProtocolGuid
,
2325 The driver's entry point. It publishes EFI Tcg2 Protocol.
2327 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2328 @param[in] SystemTable A pointer to the EFI System Table.
2330 @retval EFI_SUCCESS The entry point is executed successfully.
2331 @retval other Some error occurs when executing this entry point.
2336 IN EFI_HANDLE ImageHandle
,
2337 IN EFI_SYSTEM_TABLE
*SystemTable
2343 UINT32 MaxCommandSize
;
2344 UINT32 MaxResponseSize
;
2346 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2347 UINT32 ActivePCRBanks
;
2348 UINT32 NumberOfPCRBanks
;
2350 mImageHandle
= ImageHandle
;
2352 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2353 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2354 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2355 return EFI_UNSUPPORTED
;
2358 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2359 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2360 return EFI_DEVICE_ERROR
;
2363 Status
= Tpm2RequestUseTpm ();
2364 if (EFI_ERROR (Status
)) {
2365 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2372 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2374 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2375 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2376 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2377 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2378 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2380 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2381 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2383 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2384 if (EFI_ERROR (Status
)) {
2385 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2387 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2391 UINT32 FirmwareVersion1
;
2392 UINT32 FirmwareVersion2
;
2394 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2395 if (EFI_ERROR (Status
)) {
2396 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2398 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2402 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2403 if (EFI_ERROR (Status
)) {
2404 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2406 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2407 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2408 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2412 // Get supported PCR and current Active PCRs
2414 Status
= Tpm2GetCapabilitySupportedAndActivePcrs (&TpmHashAlgorithmBitmap
, &ActivePCRBanks
);
2415 ASSERT_EFI_ERROR (Status
);
2417 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2418 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2421 // Need calculate NumberOfPCRBanks here, because HashAlgorithmBitmap might be removed by PCD.
2423 NumberOfPCRBanks
= 0;
2424 for (Index
= 0; Index
< 32; Index
++) {
2425 if ((mTcgDxeData
.BsCap
.HashAlgorithmBitmap
& (1u << Index
)) != 0) {
2430 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2431 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2433 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2434 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2435 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2436 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2440 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2441 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) == 0) {
2443 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2445 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
;
2448 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2449 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2450 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2451 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2453 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2455 // Setup the log area and copy event log from hob list to it
2457 Status
= SetupEventLog ();
2458 ASSERT_EFI_ERROR (Status
);
2461 // Measure handoff tables, Boot#### variables etc.
2463 Status
= EfiCreateEventReadyToBootEx (
2470 Status
= gBS
->CreateEventEx (
2475 &gEfiEventExitBootServicesGuid
,
2480 // Measure Exit Boot Service failed
2482 Status
= gBS
->CreateEventEx (
2485 OnExitBootServicesFailed
,
2487 &gEventExitBootServicesFailedGuid
,
2492 // Create event callback, because we need access variable on SecureBootPolicyVariable
2493 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2494 // may update SecureBoot value based on last setting.
2496 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2500 // Install Tcg2Protocol
2502 Status
= InstallTcg2 ();
2503 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));