2011-09-02 09:49:32 +02:00
|
|
|
/** @file
|
|
|
|
Initialize TPM device and measure FVs before handing off control to DXE.
|
|
|
|
|
2018-06-27 15:13:09 +02:00
|
|
|
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:06:56 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <IndustryStandard/Tpm12.h>
|
|
|
|
#include <IndustryStandard/UefiTcgPlatform.h>
|
|
|
|
#include <Ppi/FirmwareVolumeInfo.h>
|
2013-10-11 05:54:13 +02:00
|
|
|
#include <Ppi/FirmwareVolumeInfo2.h>
|
2011-09-02 09:49:32 +02:00
|
|
|
#include <Ppi/LockPhysicalPresence.h>
|
|
|
|
#include <Ppi/TpmInitialized.h>
|
|
|
|
#include <Ppi/FirmwareVolume.h>
|
2012-09-11 04:26:50 +02:00
|
|
|
#include <Ppi/EndOfPeiPhase.h>
|
2013-09-18 07:31:18 +02:00
|
|
|
#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
|
2012-09-11 04:26:50 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
#include <Guid/TcgEventHob.h>
|
2012-09-28 02:57:02 +02:00
|
|
|
#include <Guid/MeasuredFvHob.h>
|
2013-09-18 07:31:18 +02:00
|
|
|
#include <Guid/TpmInstance.h>
|
2012-09-11 04:26:50 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/PeiServicesLib.h>
|
|
|
|
#include <Library/PeimEntryPoint.h>
|
|
|
|
#include <Library/HobLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/PeiServicesTablePointerLib.h>
|
2012-08-27 02:52:18 +02:00
|
|
|
#include <Library/BaseLib.h>
|
2014-08-20 11:37:26 +02:00
|
|
|
#include <Library/MemoryAllocationLib.h>
|
2015-01-12 04:21:00 +01:00
|
|
|
#include <Library/ReportStatusCodeLib.h>
|
2016-01-21 20:30:14 +01:00
|
|
|
#include <Library/Tpm12DeviceLib.h>
|
|
|
|
#include <Library/Tpm12CommandLib.h>
|
|
|
|
#include <Library/BaseCryptLib.h>
|
2018-07-17 07:09:02 +02:00
|
|
|
#include <Library/PerformanceLib.h>
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
BOOLEAN mImageInMemory = FALSE;
|
|
|
|
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList = {
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
|
|
|
|
&gPeiTpmInitializedPpiGuid,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-01-22 06:14:23 +01:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
|
|
|
|
&gPeiTpmInitializationDonePpiGuid,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-11-30 10:14:49 +01:00
|
|
|
//
|
|
|
|
// Number of firmware blobs to grow by each time we run out of room
|
|
|
|
//
|
|
|
|
#define FIRMWARE_BLOB_GROWTH_STEP 4
|
|
|
|
|
2014-08-20 11:37:26 +02:00
|
|
|
EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo;
|
2018-11-30 10:14:49 +01:00
|
|
|
UINT32 mMeasuredMaxBaseFvIndex = 0;
|
2012-09-11 04:26:50 +02:00
|
|
|
UINT32 mMeasuredBaseFvIndex = 0;
|
|
|
|
|
2014-08-20 11:37:26 +02:00
|
|
|
EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredChildFvInfo;
|
2018-11-30 10:14:49 +01:00
|
|
|
UINT32 mMeasuredMaxChildFvIndex = 0;
|
2012-09-11 04:26:50 +02:00
|
|
|
UINT32 mMeasuredChildFvIndex = 0;
|
|
|
|
|
2013-09-18 07:31:18 +02:00
|
|
|
EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi;
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
/**
|
|
|
|
Lock physical presence if needed.
|
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PhysicalPresencePpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Measure and record the Firmware Volum Information once FvInfoPPI install.
|
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
|
|
|
|
@return Others Fail to measure FV.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FirmwareVolmeInfoPpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
);
|
|
|
|
|
2012-09-11 04:26:50 +02:00
|
|
|
/**
|
|
|
|
Record all measured Firmware Volum Information into a Guid Hob
|
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
|
|
|
|
@return Others Fail to measure FV.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
EndofPeiSignalNotifyCallBack (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
);
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList[] = {
|
|
|
|
{
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
|
|
|
|
&gPeiLockPhysicalPresencePpiGuid,
|
|
|
|
PhysicalPresencePpiNotifyCallback
|
|
|
|
},
|
|
|
|
{
|
2012-09-11 04:26:50 +02:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
|
2011-09-02 09:49:32 +02:00
|
|
|
&gEfiPeiFirmwareVolumeInfoPpiGuid,
|
2018-06-27 15:13:09 +02:00
|
|
|
FirmwareVolmeInfoPpiNotifyCallback
|
2012-09-11 04:26:50 +02:00
|
|
|
},
|
2013-10-11 05:54:13 +02:00
|
|
|
{
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
|
|
|
|
&gEfiPeiFirmwareVolumeInfo2PpiGuid,
|
2018-06-27 15:13:09 +02:00
|
|
|
FirmwareVolmeInfoPpiNotifyCallback
|
2013-10-11 05:54:13 +02:00
|
|
|
},
|
2012-09-11 04:26:50 +02:00
|
|
|
{
|
|
|
|
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
|
|
&gEfiEndOfPeiSignalPpiGuid,
|
|
|
|
EndofPeiSignalNotifyCallBack
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-11 04:26:50 +02:00
|
|
|
/**
|
|
|
|
Record all measured Firmware Volum Information into a Guid Hob
|
2018-06-27 15:13:09 +02:00
|
|
|
Guid Hob payload layout is
|
2012-09-11 04:26:50 +02:00
|
|
|
|
|
|
|
UINT32 *************************** FIRMWARE_BLOB number
|
|
|
|
EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array
|
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
|
|
|
|
@return Others Fail to measure FV.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
EndofPeiSignalNotifyCallBack (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
2018-06-27 15:13:09 +02:00
|
|
|
{
|
2012-09-28 02:57:02 +02:00
|
|
|
MEASURED_HOB_DATA *MeasuredHobData;
|
2012-09-11 04:26:50 +02:00
|
|
|
|
2012-09-28 02:57:02 +02:00
|
|
|
MeasuredHobData = NULL;
|
2012-09-11 04:26:50 +02:00
|
|
|
|
2018-07-17 07:09:02 +02:00
|
|
|
PERF_CALLBACK_BEGIN (&gEfiEndOfPeiSignalPpiGuid);
|
|
|
|
|
2012-09-11 04:26:50 +02:00
|
|
|
//
|
2018-06-27 15:13:09 +02:00
|
|
|
// Create a Guid hob to save all measured Fv
|
2012-09-11 04:26:50 +02:00
|
|
|
//
|
2012-09-28 02:57:02 +02:00
|
|
|
MeasuredHobData = BuildGuidHob(
|
|
|
|
&gMeasuredFvHobGuid,
|
|
|
|
sizeof(UINTN) + sizeof(EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredBaseFvIndex + mMeasuredChildFvIndex)
|
|
|
|
);
|
2012-09-11 04:26:50 +02:00
|
|
|
|
2012-09-28 02:57:02 +02:00
|
|
|
if (MeasuredHobData != NULL){
|
2012-09-11 04:26:50 +02:00
|
|
|
//
|
|
|
|
// Save measured FV info enty number
|
|
|
|
//
|
2012-09-28 02:57:02 +02:00
|
|
|
MeasuredHobData->Num = mMeasuredBaseFvIndex + mMeasuredChildFvIndex;
|
2012-09-11 04:26:50 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Save measured base Fv info
|
|
|
|
//
|
2012-09-28 02:57:02 +02:00
|
|
|
CopyMem (MeasuredHobData->MeasuredFvBuf, mMeasuredBaseFvInfo, sizeof(EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredBaseFvIndex));
|
2012-09-11 04:26:50 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Save measured child Fv info
|
|
|
|
//
|
2012-09-28 02:57:02 +02:00
|
|
|
CopyMem (&MeasuredHobData->MeasuredFvBuf[mMeasuredBaseFvIndex] , mMeasuredChildFvInfo, sizeof(EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredChildFvIndex));
|
2012-09-11 04:26:50 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 07:09:02 +02:00
|
|
|
PERF_CALLBACK_END (&gEfiEndOfPeiSignalPpiGuid);
|
|
|
|
|
2012-09-11 04:26:50 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
/**
|
|
|
|
Single function calculates SHA1 digest value for all raw data. It
|
|
|
|
combines Sha1Init(), Sha1Update() and Sha1Final().
|
|
|
|
|
|
|
|
@param[in] Data Raw data to be digested.
|
|
|
|
@param[in] DataLen Size of the raw data.
|
|
|
|
@param[out] Digest Pointer to a buffer that stores the final digest.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Always successfully calculate the final digest.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TpmCommHashAll (
|
|
|
|
IN CONST UINT8 *Data,
|
|
|
|
IN UINTN DataLen,
|
|
|
|
OUT TPM_DIGEST *Digest
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VOID *Sha1Ctx;
|
|
|
|
UINTN CtxSize;
|
|
|
|
|
|
|
|
CtxSize = Sha1GetContextSize ();
|
|
|
|
Sha1Ctx = AllocatePool (CtxSize);
|
|
|
|
ASSERT (Sha1Ctx != NULL);
|
|
|
|
|
|
|
|
Sha1Init (Sha1Ctx);
|
|
|
|
Sha1Update (Sha1Ctx, Data, DataLen);
|
|
|
|
Sha1Final (Sha1Ctx, (UINT8 *)Digest);
|
|
|
|
|
|
|
|
FreePool (Sha1Ctx);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
2018-06-27 15:13:09 +02:00
|
|
|
@param[in] HashData Physical address of the start of the data buffer
|
2011-09-02 09:49:32 +02:00
|
|
|
to be hashed, extended, and logged.
|
|
|
|
@param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData.
|
2018-06-27 15:13:09 +02:00
|
|
|
@param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
|
|
|
|
@param[in] NewEventData Pointer to the new event data.
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
HashLogExtendEvent (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN UINT8 *HashData,
|
|
|
|
IN UINTN HashDataLen,
|
|
|
|
IN TCG_PCR_EVENT_HDR *NewEventHdr,
|
|
|
|
IN UINT8 *NewEventData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
VOID *HobData;
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2015-01-12 04:21:00 +01:00
|
|
|
if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
HobData = NULL;
|
|
|
|
if (HashDataLen != 0) {
|
|
|
|
Status = TpmCommHashAll (
|
|
|
|
HashData,
|
|
|
|
HashDataLen,
|
|
|
|
&NewEventHdr->Digest
|
|
|
|
);
|
2015-01-12 04:21:00 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12Extend (
|
2011-09-02 09:49:32 +02:00
|
|
|
&NewEventHdr->Digest,
|
|
|
|
NewEventHdr->PCRIndex,
|
|
|
|
NULL
|
|
|
|
);
|
2015-01-12 04:21:00 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
HobData = BuildGuidHob (
|
|
|
|
&gTcgEventEntryHobGuid,
|
|
|
|
sizeof (*NewEventHdr) + NewEventHdr->EventSize
|
|
|
|
);
|
|
|
|
if (HobData == NULL) {
|
2015-01-12 04:21:00 +01:00
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (HobData, NewEventHdr, sizeof (*NewEventHdr));
|
|
|
|
HobData = (VOID *) ((UINT8*)HobData + sizeof (*NewEventHdr));
|
|
|
|
CopyMem (HobData, NewEventData, NewEventHdr->EventSize);
|
2015-01-12 04:21:00 +01:00
|
|
|
|
|
|
|
Done:
|
|
|
|
if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_TIMEOUT)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "HashLogExtendEvent - %r. Disable TPM.\n", Status));
|
|
|
|
BuildGuidHob (&gTpmErrorHobGuid,0);
|
|
|
|
REPORT_STATUS_CODE (
|
|
|
|
EFI_ERROR_CODE | EFI_ERROR_MINOR,
|
|
|
|
(PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
|
|
|
|
);
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
return Status;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Measure CRTM version.
|
|
|
|
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MeasureCRTMVersion (
|
2016-01-21 20:29:19 +01:00
|
|
|
IN EFI_PEI_SERVICES **PeiServices
|
2011-09-02 09:49:32 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
TCG_PCR_EVENT_HDR TcgEventHdr;
|
|
|
|
|
|
|
|
//
|
2012-08-27 02:52:18 +02:00
|
|
|
// Use FirmwareVersion string to represent CRTM version.
|
2011-09-02 09:49:32 +02:00
|
|
|
// OEMs should get real CRTM version string and measure it.
|
|
|
|
//
|
|
|
|
|
|
|
|
TcgEventHdr.PCRIndex = 0;
|
|
|
|
TcgEventHdr.EventType = EV_S_CRTM_VERSION;
|
2012-09-05 02:32:12 +02:00
|
|
|
TcgEventHdr.EventSize = (UINT32) StrSize((CHAR16*)PcdGetPtr (PcdFirmwareVersionString));
|
2012-08-27 02:52:18 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
return HashLogExtendEvent (
|
|
|
|
PeiServices,
|
2012-08-27 02:52:18 +02:00
|
|
|
(UINT8*)PcdGetPtr (PcdFirmwareVersionString),
|
2011-09-02 09:49:32 +02:00
|
|
|
TcgEventHdr.EventSize,
|
|
|
|
&TcgEventHdr,
|
2012-08-27 02:52:18 +02:00
|
|
|
(UINT8*)PcdGetPtr (PcdFirmwareVersionString)
|
2011-09-02 09:49:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-27 15:13:09 +02:00
|
|
|
Measure FV image.
|
|
|
|
Add it into the measured FV list after the FV is measured successfully.
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
@param[in] FvBase Base address of FV image.
|
|
|
|
@param[in] FvLength Length of FV image.
|
|
|
|
|
2018-06-27 15:13:09 +02:00
|
|
|
@retval EFI_SUCCESS Fv image is measured successfully
|
2011-09-02 09:49:32 +02:00
|
|
|
or it has been already measured.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MeasureFvImage (
|
|
|
|
IN EFI_PHYSICAL_ADDRESS FvBase,
|
|
|
|
IN UINT64 FvLength
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Index;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PLATFORM_FIRMWARE_BLOB FvBlob;
|
|
|
|
TCG_PCR_EVENT_HDR TcgEventHdr;
|
|
|
|
|
2013-09-18 07:31:18 +02:00
|
|
|
//
|
|
|
|
// Check if it is in Excluded FV list
|
|
|
|
//
|
|
|
|
if (mMeasurementExcludedFvPpi != NULL) {
|
|
|
|
for (Index = 0; Index < mMeasurementExcludedFvPpi->Count; Index ++) {
|
|
|
|
if (mMeasurementExcludedFvPpi->Fv[Index].FvBase == FvBase) {
|
|
|
|
DEBUG ((DEBUG_INFO, "The FV which is excluded by TcgPei starts at: 0x%x\n", FvBase));
|
|
|
|
DEBUG ((DEBUG_INFO, "The FV which is excluded by TcgPei has the size: 0x%x\n", FvLength));
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
// Check whether FV is in the measured FV list.
|
|
|
|
//
|
2012-09-11 04:26:50 +02:00
|
|
|
for (Index = 0; Index < mMeasuredBaseFvIndex; Index ++) {
|
|
|
|
if (mMeasuredBaseFvInfo[Index].BlobBase == FvBase) {
|
2011-09-02 09:49:32 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
// Measure and record the FV to the TPM
|
|
|
|
//
|
|
|
|
FvBlob.BlobBase = FvBase;
|
|
|
|
FvBlob.BlobLength = FvLength;
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "The FV which is measured by TcgPei starts at: 0x%x\n", FvBlob.BlobBase));
|
|
|
|
DEBUG ((DEBUG_INFO, "The FV which is measured by TcgPei has the size: 0x%x\n", FvBlob.BlobLength));
|
|
|
|
|
|
|
|
TcgEventHdr.PCRIndex = 0;
|
|
|
|
TcgEventHdr.EventType = EV_EFI_PLATFORM_FIRMWARE_BLOB;
|
|
|
|
TcgEventHdr.EventSize = sizeof (FvBlob);
|
|
|
|
|
|
|
|
Status = HashLogExtendEvent (
|
|
|
|
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer(),
|
|
|
|
(UINT8*) (UINTN) FvBlob.BlobBase,
|
|
|
|
(UINTN) FvBlob.BlobLength,
|
|
|
|
&TcgEventHdr,
|
|
|
|
(UINT8*) &FvBlob
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add new FV into the measured FV list.
|
|
|
|
//
|
2018-11-30 10:14:49 +01:00
|
|
|
if (mMeasuredBaseFvIndex >= mMeasuredMaxBaseFvIndex) {
|
|
|
|
mMeasuredBaseFvInfo = ReallocatePool (
|
|
|
|
sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxBaseFvIndex,
|
|
|
|
sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP),
|
|
|
|
mMeasuredBaseFvInfo
|
|
|
|
);
|
|
|
|
ASSERT (mMeasuredBaseFvInfo != NULL);
|
|
|
|
mMeasuredMaxBaseFvIndex = mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 10:14:49 +01:00
|
|
|
mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase = FvBase;
|
|
|
|
mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength;
|
|
|
|
mMeasuredBaseFvIndex++;
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Measure main BIOS.
|
|
|
|
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MeasureMainBios (
|
2016-01-21 20:29:19 +01:00
|
|
|
IN EFI_PEI_SERVICES **PeiServices
|
2011-09-02 09:49:32 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 FvInstances;
|
|
|
|
EFI_PEI_FV_HANDLE VolumeHandle;
|
|
|
|
EFI_FV_INFO VolumeInfo;
|
|
|
|
EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
FvInstances = 0;
|
|
|
|
while (TRUE) {
|
|
|
|
//
|
|
|
|
// Traverse all firmware volume instances of Static Core Root of Trust for Measurement
|
|
|
|
// (S-CRTM), this firmware volume measure policy can be modified/enhanced by special
|
|
|
|
// platform for special CRTM TPM measuring.
|
|
|
|
//
|
|
|
|
Status = PeiServicesFfsFindNextVolume (FvInstances, &VolumeHandle);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
// Measure and record the firmware volume that is dispatched by PeiCore
|
|
|
|
//
|
|
|
|
Status = PeiServicesFfsGetVolumeInfo (VolumeHandle, &VolumeInfo);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
//
|
|
|
|
// Locate the corresponding FV_PPI according to founded FV's format guid
|
|
|
|
//
|
|
|
|
Status = PeiServicesLocatePpi (
|
2018-06-27 15:13:09 +02:00
|
|
|
&VolumeInfo.FvFormat,
|
|
|
|
0,
|
2011-09-02 09:49:32 +02:00
|
|
|
NULL,
|
|
|
|
(VOID**)&FvPpi
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
MeasureFvImage ((EFI_PHYSICAL_ADDRESS) (UINTN) VolumeInfo.FvStart, VolumeInfo.FvSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
FvInstances++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Measure and record the Firmware Volum Information once FvInfoPPI install.
|
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The FV Info is measured and recorded to TPM.
|
|
|
|
@return Others Fail to measure FV.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FirmwareVolmeInfoPpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;
|
2014-04-15 11:19:04 +02:00
|
|
|
UINTN Index;
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *) Ppi;
|
|
|
|
|
|
|
|
//
|
|
|
|
// The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.
|
|
|
|
//
|
|
|
|
Status = PeiServicesLocatePpi (
|
2018-06-27 15:13:09 +02:00
|
|
|
&Fv->FvFormat,
|
|
|
|
0,
|
2011-09-02 09:49:32 +02:00
|
|
|
NULL,
|
|
|
|
(VOID**)&FvPpi
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
// This is an FV from an FFS file, and the parent FV must have already been measured,
|
2012-09-11 04:26:50 +02:00
|
|
|
// No need to measure twice, so just record the FV and return
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
if (Fv->ParentFvName != NULL || Fv->ParentFileName != NULL ) {
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2018-11-30 10:14:49 +01:00
|
|
|
if (mMeasuredChildFvIndex >= mMeasuredMaxChildFvIndex) {
|
|
|
|
mMeasuredChildFvInfo = ReallocatePool (
|
|
|
|
sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxChildFvIndex,
|
|
|
|
sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP),
|
|
|
|
mMeasuredChildFvInfo
|
|
|
|
);
|
|
|
|
ASSERT (mMeasuredChildFvInfo != NULL);
|
|
|
|
mMeasuredMaxChildFvIndex = mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Check whether FV is in the measured child FV list.
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < mMeasuredChildFvIndex; Index++) {
|
|
|
|
if (mMeasuredChildFvInfo[Index].BlobBase == (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo) {
|
|
|
|
return EFI_SUCCESS;
|
2014-04-15 11:19:04 +02:00
|
|
|
}
|
2012-09-11 04:26:50 +02:00
|
|
|
}
|
2018-11-30 10:14:49 +01:00
|
|
|
mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobBase = (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo;
|
|
|
|
mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobLength = Fv->FvInfoSize;
|
|
|
|
mMeasuredChildFvIndex++;
|
2011-09-02 09:49:32 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MeasureFvImage ((EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo, Fv->FvInfoSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-26 07:11:47 +02:00
|
|
|
Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by corresponding PCDs.
|
|
|
|
And lock physical presence if needed.
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
@param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
|
|
|
|
@param[in] NotifyDescriptor Address of the notification descriptor data structure.
|
|
|
|
@param[in] Ppi Address of the PPI that was installed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
@retval EFI_ABORTED physicalPresenceCMDEnable is locked.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PhysicalPresencePpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2016-01-21 20:30:14 +01:00
|
|
|
TPM_PERMANENT_FLAGS TpmPermanentFlags;
|
2011-09-02 09:49:32 +02:00
|
|
|
PEI_LOCK_PHYSICAL_PRESENCE_PPI *LockPhysicalPresencePpi;
|
2012-07-26 07:11:47 +02:00
|
|
|
TPM_PHYSICAL_PRESENCE PhysicalPresenceValue;
|
2011-09-02 09:49:32 +02:00
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12GetCapabilityFlagPermanent (&TpmPermanentFlags);
|
2012-07-26 07:11:47 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-07-26 07:11:47 +02:00
|
|
|
// 1. Set physicalPresenceLifetimeLock, physicalPresenceHWEnable and physicalPresenceCMDEnable bit by PCDs.
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
2016-01-21 20:30:14 +01:00
|
|
|
if (PcdGetBool (PcdPhysicalPresenceLifetimeLock) && !TpmPermanentFlags.physicalPresenceLifetimeLock) {
|
2012-07-26 07:11:47 +02:00
|
|
|
//
|
2018-06-27 15:13:09 +02:00
|
|
|
// Lock TPM LifetimeLock is required, and LifetimeLock is not locked yet.
|
2012-07-26 07:11:47 +02:00
|
|
|
//
|
|
|
|
PhysicalPresenceValue = TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK;
|
2017-01-06 02:27:15 +01:00
|
|
|
TpmPermanentFlags.physicalPresenceLifetimeLock = TRUE;
|
2012-07-26 07:11:47 +02:00
|
|
|
|
|
|
|
if (PcdGetBool (PcdPhysicalPresenceCmdEnable)) {
|
|
|
|
PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_CMD_ENABLE;
|
2016-01-21 20:30:14 +01:00
|
|
|
TpmPermanentFlags.physicalPresenceCMDEnable = TRUE;
|
2012-07-26 07:11:47 +02:00
|
|
|
} else {
|
|
|
|
PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_CMD_DISABLE;
|
2016-01-21 20:30:14 +01:00
|
|
|
TpmPermanentFlags.physicalPresenceCMDEnable = FALSE;
|
2012-07-26 07:11:47 +02:00
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
2012-07-26 07:11:47 +02:00
|
|
|
if (PcdGetBool (PcdPhysicalPresenceHwEnable)) {
|
|
|
|
PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_ENABLE;
|
|
|
|
} else {
|
|
|
|
PhysicalPresenceValue |= TPM_PHYSICAL_PRESENCE_HW_DISABLE;
|
2018-06-27 15:13:09 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12PhysicalPresence (
|
2012-07-26 07:11:47 +02:00
|
|
|
PhysicalPresenceValue
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 15:13:09 +02:00
|
|
|
|
2012-07-26 07:11:47 +02:00
|
|
|
//
|
|
|
|
// 2. Lock physical presence if it is required.
|
|
|
|
//
|
|
|
|
LockPhysicalPresencePpi = (PEI_LOCK_PHYSICAL_PRESENCE_PPI *) Ppi;
|
|
|
|
if (!LockPhysicalPresencePpi->LockPhysicalPresence ((CONST EFI_PEI_SERVICES**) PeiServices)) {
|
|
|
|
return EFI_SUCCESS;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
if (!TpmPermanentFlags.physicalPresenceCMDEnable) {
|
|
|
|
if (TpmPermanentFlags.physicalPresenceLifetimeLock) {
|
2011-09-02 09:49:32 +02:00
|
|
|
//
|
|
|
|
// physicalPresenceCMDEnable is locked, can't change.
|
|
|
|
//
|
|
|
|
return EFI_ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enable physical presence command
|
|
|
|
// It is necessary in order to lock physical presence
|
|
|
|
//
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12PhysicalPresence (
|
2011-09-02 09:49:32 +02:00
|
|
|
TPM_PHYSICAL_PRESENCE_CMD_ENABLE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lock physical presence
|
2018-06-27 15:13:09 +02:00
|
|
|
//
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12PhysicalPresence (
|
2011-09-02 09:49:32 +02:00
|
|
|
TPM_PHYSICAL_PRESENCE_LOCK
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check if TPM chip is activeated or not.
|
|
|
|
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@retval TRUE TPM is activated.
|
|
|
|
@retval FALSE TPM is deactivated.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
IsTpmUsable (
|
2016-01-21 20:30:14 +01:00
|
|
|
VOID
|
2011-09-02 09:49:32 +02:00
|
|
|
)
|
|
|
|
{
|
2016-01-21 20:30:14 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
TPM_PERMANENT_FLAGS TpmPermanentFlags;
|
2011-09-02 09:49:32 +02:00
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12GetCapabilityFlagPermanent (&TpmPermanentFlags);
|
2011-09-02 09:49:32 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-01-21 20:30:14 +01:00
|
|
|
return (BOOLEAN)(!TpmPermanentFlags.deactivated);
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Do measurement after memory is ready.
|
|
|
|
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation completed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
|
|
|
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeimEntryMP (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2013-09-18 07:31:18 +02:00
|
|
|
Status = PeiServicesLocatePpi (
|
2018-06-27 15:13:09 +02:00
|
|
|
&gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid,
|
|
|
|
0,
|
2013-09-18 07:31:18 +02:00
|
|
|
NULL,
|
|
|
|
(VOID**)&mMeasurementExcludedFvPpi
|
|
|
|
);
|
|
|
|
// Do not check status, because it is optional
|
|
|
|
|
2016-01-21 20:29:19 +01:00
|
|
|
Status = Tpm12RequestUseTpm ();
|
2011-09-02 09:49:32 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:30:14 +01:00
|
|
|
if (IsTpmUsable ()) {
|
2013-09-18 07:31:18 +02:00
|
|
|
if (PcdGet8 (PcdTpmScrtmPolicy) == 1) {
|
2016-01-21 20:29:19 +01:00
|
|
|
Status = MeasureCRTMVersion (PeiServices);
|
2013-09-18 07:31:18 +02:00
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
2016-01-21 20:29:19 +01:00
|
|
|
Status = MeasureMainBios (PeiServices);
|
2018-06-27 15:13:09 +02:00
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Post callbacks:
|
|
|
|
// 1). for the FvInfoPpi services to measure and record
|
|
|
|
// the additional Fvs to TPM
|
2018-06-27 15:13:09 +02:00
|
|
|
// 2). for the OperatorPresencePpi service to determine whether to
|
2011-09-02 09:49:32 +02:00
|
|
|
// lock the TPM
|
|
|
|
//
|
|
|
|
Status = PeiServicesNotifyPpi (&mNotifyList[0]);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Entry point of this module.
|
|
|
|
|
|
|
|
@param[in] FileHandle Handle of the file being invoked.
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@return Status.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PeimEntryMA (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2015-01-22 06:14:23 +01:00
|
|
|
EFI_STATUS Status2;
|
2011-09-02 09:49:32 +02:00
|
|
|
EFI_BOOT_MODE BootMode;
|
|
|
|
|
2013-09-18 07:31:18 +02:00
|
|
|
if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
|
|
|
|
DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n"));
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:15:08 +01:00
|
|
|
if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "TPM error!\n"));
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-08-28 05:16:10 +02:00
|
|
|
//
|
|
|
|
// Initialize TPM device
|
|
|
|
//
|
|
|
|
Status = PeiServicesGetBootMode (&BootMode);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// In S3 path, skip shadow logic. no measurement is required
|
|
|
|
//
|
|
|
|
if (BootMode != BOOT_ON_S3_RESUME) {
|
|
|
|
Status = (**PeiServices).RegisterForShadow(FileHandle);
|
|
|
|
if (Status == EFI_ALREADY_STARTED) {
|
|
|
|
mImageInMemory = TRUE;
|
|
|
|
} else if (Status == EFI_NOT_FOUND) {
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mImageInMemory) {
|
2016-01-21 20:29:19 +01:00
|
|
|
Status = Tpm12RequestUseTpm ();
|
2011-09-02 09:49:32 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "TPM not detected!\n"));
|
2015-01-22 06:14:23 +01:00
|
|
|
goto Done;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 07:31:18 +02:00
|
|
|
if (PcdGet8 (PcdTpmInitializationPolicy) == 1) {
|
2016-01-21 20:30:14 +01:00
|
|
|
if (BootMode == BOOT_ON_S3_RESUME) {
|
|
|
|
Status = Tpm12Startup (TPM_ST_STATE);
|
|
|
|
} else {
|
|
|
|
Status = Tpm12Startup (TPM_ST_CLEAR);
|
|
|
|
}
|
2013-09-18 07:31:18 +02:00
|
|
|
if (EFI_ERROR (Status) ) {
|
2015-01-22 06:14:23 +01:00
|
|
|
goto Done;
|
2013-09-18 07:31:18 +02:00
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
2012-10-22 06:35:59 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// TpmSelfTest is optional on S3 path, skip it to save S3 time
|
|
|
|
//
|
|
|
|
if (BootMode != BOOT_ON_S3_RESUME) {
|
2016-01-21 20:30:14 +01:00
|
|
|
Status = Tpm12ContinueSelfTest ();
|
2012-10-22 06:35:59 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2015-01-22 06:14:23 +01:00
|
|
|
goto Done;
|
2012-10-22 06:35:59 +02:00
|
|
|
}
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
2012-10-22 06:35:59 +02:00
|
|
|
|
2015-01-22 06:14:23 +01:00
|
|
|
//
|
|
|
|
// Only intall TpmInitializedPpi on success
|
|
|
|
//
|
2011-09-02 09:49:32 +02:00
|
|
|
Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mImageInMemory) {
|
|
|
|
Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
|
2015-01-22 06:14:23 +01:00
|
|
|
return Status;
|
2011-09-02 09:49:32 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 06:14:23 +01:00
|
|
|
Done:
|
2015-03-04 02:15:08 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "TPM error! Build Hob\n"));
|
|
|
|
BuildGuidHob (&gTpmErrorHobGuid,0);
|
|
|
|
REPORT_STATUS_CODE (
|
|
|
|
EFI_ERROR_CODE | EFI_ERROR_MINOR,
|
|
|
|
(PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
|
|
|
|
);
|
|
|
|
}
|
2015-01-22 06:14:23 +01:00
|
|
|
//
|
|
|
|
// Always intall TpmInitializationDonePpi no matter success or fail.
|
|
|
|
// Other driver can know TPM initialization state by TpmInitializedPpi.
|
|
|
|
//
|
|
|
|
Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
|
|
|
|
ASSERT_EFI_ERROR (Status2);
|
|
|
|
|
2011-09-02 09:49:32 +02:00
|
|
|
return Status;
|
|
|
|
}
|