TianoCore EDK2 master
Loading...
Searching...
No Matches
Tcg2Pei.c File Reference

Go to the source code of this file.

Data Structures

struct  TCG2_EVENT_INFO_STRUCT
 
struct  FV_HANDOFF_TABLE_POINTERS2
 

Macros

#define PERF_ID_TCG2_PEI   0x3080
 
#define FIRMWARE_BLOB_GROWTH_STEP   4
 
#define FV_HANDOFF_TABLE_DESC   "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"
 

Functions

EFI_STATUS EFIAPI HashLogExtendEvent (IN EDKII_TCG_PPI *This, IN UINT64 Flags, IN UINT8 *HashData, IN UINTN HashDataLen, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
 
EFI_STATUS EFIAPI FirmwareVolumeInfoPpiNotifyCallback (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
 
EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
 
VOID SyncPcrAllocationsAndPcrMask (VOID)
 
EFI_STATUS LogHashEvent (IN TPML_DIGEST_VALUES *DigestList, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
 
EFI_STATUS MeasureCRTMVersion (VOID)
 
VOID * GetFvName (IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
 
EFI_STATUS MeasureFvImage (IN EFI_PHYSICAL_ADDRESS FvBase, IN UINT64 FvLength)
 
EFI_STATUS MeasureMainBios (VOID)
 
EFI_STATUS PeimEntryMP (IN EFI_PEI_SERVICES **PeiServices)
 
EFI_STATUS MeasureSeparatorEventWithError (IN TPM_PCRINDEX PCRIndex)
 
EFI_STATUS EFIAPI PeimEntryMA (IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
 

Variables

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo []
 
BOOLEAN mImageInMemory = FALSE
 
EFI_PEI_FILE_HANDLE mFileHandle
 
EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList
 
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList
 
EDKII_TCG_PPI mEdkiiTcgPpi
 
EFI_PEI_PPI_DESCRIPTOR mTcgPpiList
 
EFI_PLATFORM_FIRMWARE_BLOBmMeasuredBaseFvInfo
 
UINT32 mMeasuredMaxBaseFvIndex = 0
 
UINT32 mMeasuredBaseFvIndex = 0
 
EFI_PLATFORM_FIRMWARE_BLOBmMeasuredChildFvInfo
 
UINT32 mMeasuredMaxChildFvIndex = 0
 
UINT32 mMeasuredChildFvIndex = 0
 
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList []
 

Detailed Description

Initialize TPM2 device and measure FVs before handing off control to DXE.

Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
Copyright (c) 2017, Microsoft Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Tcg2Pei.c.

Macro Definition Documentation

◆ FIRMWARE_BLOB_GROWTH_STEP

#define FIRMWARE_BLOB_GROWTH_STEP   4

Definition at line 116 of file Tcg2Pei.c.

◆ FV_HANDOFF_TABLE_DESC

#define FV_HANDOFF_TABLE_DESC   "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"

Definition at line 128 of file Tcg2Pei.c.

◆ PERF_ID_TCG2_PEI

#define PERF_ID_TCG2_PEI   0x3080

Definition at line 44 of file Tcg2Pei.c.

Function Documentation

◆ EndofPeiSignalNotifyCallBack()

EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack ( IN EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor,
IN VOID *  Ppi 
)

Record all measured Firmware Volume Information into a Guid Hob

Parameters
[in]PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in]NotifyDescriptorAddress of the notification descriptor data structure.
[in]PpiAddress of the PPI that was installed.
Return values
EFI_SUCCESSThe FV Info is measured and recorded to TPM.
Returns
Others Fail to measure FV.

Record all measured Firmware Volume Information into a Guid Hob Guid Hob payload layout is

UINT32 *************************** FIRMWARE_BLOB number EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array

Parameters
[in]PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in]NotifyDescriptorAddress of the notification descriptor data structure.
[in]PpiAddress of the PPI that was installed.
Return values
EFI_SUCCESSThe FV Info is measured and recorded to TPM.
Returns
Others Fail to measure FV.

Definition at line 211 of file Tcg2Pei.c.

◆ FirmwareVolumeInfoPpiNotifyCallback()

EFI_STATUS EFIAPI FirmwareVolumeInfoPpiNotifyCallback ( IN EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor,
IN VOID *  Ppi 
)

Measure and record the Firmware Volume Information once FvInfoPPI install.

Parameters
[in]PeiServicesAn indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
[in]NotifyDescriptorAddress of the notification descriptor data structure.
[in]PpiAddress of the PPI that was installed.
Return values
EFI_SUCCESSThe FV Info is measured and recorded to TPM.
Returns
Others Fail to measure FV.

Definition at line 887 of file Tcg2Pei.c.

◆ GetFvName()

VOID * GetFvName ( IN EFI_PHYSICAL_ADDRESS  FvBase,
IN UINT64  FvLength 
)

Get the FvName from the FV header.

Causion: The FV is untrusted input.

Parameters
[in]FvBaseBase address of FV image.
[in]FvLengthLength of FV image.
Returns
FvName pointer
Return values
NULLFvName is NOT found

Definition at line 557 of file Tcg2Pei.c.

◆ HashLogExtendEvent()

EFI_STATUS EFIAPI HashLogExtendEvent ( IN EDKII_TCG_PPI This,
IN UINT64  Flags,
IN UINT8 *  HashData,
IN UINTN  HashDataLen,
IN TCG_PCR_EVENT_HDR NewEventHdr,
IN UINT8 *  NewEventData 
)

Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and build a GUIDed HOB recording the event which will be passed to the DXE phase and added into the Event Log.

Parameters
[in]ThisIndicates the calling context
[in]FlagsBitmap providing additional information.
[in]HashDataIf BIT0 of Flags is 0, it is physical address of the start of the data buffer to be hashed, extended, and logged. If BIT0 of Flags is 1, it is physical address of the start of the pre-hash data buffter to be extended, and logged. The pre-hash data format is TPML_DIGEST_VALUES.
[in]HashDataLenThe length, in bytes, of the buffer referenced by HashData.
[in]NewEventHdrPointer to a TCG_PCR_EVENT_HDR data structure.
[in]NewEventDataPointer to the new event data.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and build a GUIDed HOB recording the event which will be passed to the DXE phase and added into the Event Log.

Parameters
[in]ThisIndicates the calling context.
[in]FlagsBitmap providing additional information.
[in]HashDataPhysical address of the start of the data buffer to be hashed, extended, and logged.
[in]HashDataLenThe length, in bytes, of the buffer referenced by HashData.
[in]NewEventHdrPointer to a TCG_PCR_EVENT_HDR data structure.
[in]NewEventDataPointer to the new event data.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 460 of file Tcg2Pei.c.

◆ LogHashEvent()

EFI_STATUS LogHashEvent ( IN TPML_DIGEST_VALUES DigestList,
IN OUT TCG_PCR_EVENT_HDR NewEventHdr,
IN UINT8 *  NewEventData 
)

Add a new entry to the Event Log.

Parameters
[in]DigestListA list of digest.
[in,out]NewEventHdrPointer to a TCG_PCR_EVENT_HDR data structure.
[in]NewEventDataPointer to the new event data.
Return values
EFI_SUCCESSThe new event log entry was added.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.

Definition at line 368 of file Tcg2Pei.c.

◆ MeasureCRTMVersion()

EFI_STATUS MeasureCRTMVersion ( VOID  )

Measure CRTM version.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 520 of file Tcg2Pei.c.

◆ MeasureFvImage()

EFI_STATUS MeasureFvImage ( IN EFI_PHYSICAL_ADDRESS  FvBase,
IN UINT64  FvLength 
)

Measure FV image. Add it into the measured FV list after the FV is measured successfully.

Parameters
[in]FvBaseBase address of FV image.
[in]FvLengthLength of FV image.
Return values
EFI_SUCCESSFv image is measured successfully or it has been already measured.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 605 of file Tcg2Pei.c.

◆ MeasureMainBios()

EFI_STATUS MeasureMainBios ( VOID  )

Measure main BIOS.

Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 829 of file Tcg2Pei.c.

◆ MeasureSeparatorEventWithError()

EFI_STATUS MeasureSeparatorEventWithError ( IN TPM_PCRINDEX  PCRIndex)

Measure and log Separator event with error, and extend the measurement result into a specific PCR.

Parameters
[in]PCRIndexPCR index.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_DEVICE_ERRORThe operation was unsuccessful.

Definition at line 999 of file Tcg2Pei.c.

◆ PeimEntryMA()

EFI_STATUS EFIAPI PeimEntryMA ( IN EFI_PEI_FILE_HANDLE  FileHandle,
IN CONST EFI_PEI_SERVICES **  PeiServices 
)

Entry point of this module.

Parameters
[in]FileHandleHandle of the file being invoked.
[in]PeiServicesDescribes the list of possible PEI Services.
Returns
Status.

Definition at line 1027 of file Tcg2Pei.c.

◆ PeimEntryMP()

EFI_STATUS PeimEntryMP ( IN EFI_PEI_SERVICES **  PeiServices)

Do measurement after memory is ready.

Parameters
[in]PeiServicesDescribes the list of possible PEI Services.
Return values
EFI_SUCCESSOperation completed successfully.
EFI_OUT_OF_RESOURCESNo enough memory to log the new event.
EFI_DEVICE_ERRORThe command was unsuccessful.

Definition at line 957 of file Tcg2Pei.c.

◆ SyncPcrAllocationsAndPcrMask()

VOID SyncPcrAllocationsAndPcrMask ( VOID  )

Make sure that the current PCR allocations, the TPM supported PCRs, PcdTcg2HashAlgorithmBitmap and the PcdTpm2HashMask are all in agreement.

Definition at line 258 of file Tcg2Pei.c.

Variable Documentation

◆ mEdkiiTcgPpi

EDKII_TCG_PPI mEdkiiTcgPpi
Initial value:
= {
}
EFI_STATUS EFIAPI HashLogExtendEvent(IN EDKII_TCG_PPI *This, IN UINT64 Flags, IN UINT8 *HashData, IN UINTN HashDataLen, IN TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData)
Definition: Tcg2Pei.c:460

Definition at line 103 of file Tcg2Pei.c.

◆ mFileHandle

EFI_PEI_FILE_HANDLE mFileHandle

Definition at line 57 of file Tcg2Pei.c.

◆ mImageInMemory

BOOLEAN mImageInMemory = FALSE

Definition at line 56 of file Tcg2Pei.c.

◆ mMeasuredBaseFvIndex

UINT32 mMeasuredBaseFvIndex = 0

Definition at line 120 of file Tcg2Pei.c.

◆ mMeasuredBaseFvInfo

EFI_PLATFORM_FIRMWARE_BLOB* mMeasuredBaseFvInfo

Definition at line 118 of file Tcg2Pei.c.

◆ mMeasuredChildFvIndex

UINT32 mMeasuredChildFvIndex = 0

Definition at line 124 of file Tcg2Pei.c.

◆ mMeasuredChildFvInfo

EFI_PLATFORM_FIRMWARE_BLOB* mMeasuredChildFvInfo

Definition at line 122 of file Tcg2Pei.c.

◆ mMeasuredMaxBaseFvIndex

UINT32 mMeasuredMaxBaseFvIndex = 0

Definition at line 119 of file Tcg2Pei.c.

◆ mMeasuredMaxChildFvIndex

UINT32 mMeasuredMaxChildFvIndex = 0

Definition at line 123 of file Tcg2Pei.c.

◆ mNotifyList

Initial value:
= {
{
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
&gEfiPeiFirmwareVolumeInfoPpiGuid,
},
{
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
&gEfiPeiFirmwareVolumeInfo2PpiGuid,
},
{
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiEndOfPeiSignalPpiGuid,
}
}
EFI_STATUS EFIAPI FirmwareVolumeInfoPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: Tcg2Pei.c:887
EFI_STATUS EFIAPI EndofPeiSignalNotifyCallBack(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: Tcg2Pei.c:211

Definition at line 176 of file Tcg2Pei.c.

◆ mTcg2EventInfo

TCG2_EVENT_INFO_STRUCT mTcg2EventInfo[]
Initial value:
= {
{ &gTcgEventEntryHobGuid, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 },
{ &gTcgEvent2EntryHobGuid, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 },
}

Definition at line 51 of file Tcg2Pei.c.

◆ mTcgPpiList

Initial value:
= {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEdkiiTcgPpiGuid,
&mEdkiiTcgPpi
}

Definition at line 107 of file Tcg2Pei.c.

◆ mTpmInitializationDonePpiList

EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList
Initial value:
= {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gPeiTpmInitializationDonePpiGuid,
}
#define NULL
Definition: Base.h:319

Definition at line 65 of file Tcg2Pei.c.

◆ mTpmInitializedPpiList

EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList
Initial value:
= {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gPeiTpmInitializedPpiGuid,
}

Definition at line 59 of file Tcg2Pei.c.