X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SecurityPkg%2FTcg%2FTrEEPei%2FTrEEPei.c;h=b56124579074cbe7ba2900142c66d71b3ca467b4;hp=eea40847c5e648299fe5a27c9ed0d26afa4a5a20;hb=9aeebd913e7b3d34c5a01ba4453c167c1b5ff52f;hpb=6f785cfcc304c48ec04e542ee429df95e7b51bc5 diff --git a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c index eea40847c5..b561245790 100644 --- a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c +++ b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c @@ -1,7 +1,7 @@ /** @file Initialize TPM2 device and measure FVs before handing off control to DXE. -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -62,6 +62,12 @@ EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList = { NULL }; +EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gPeiTpmInitializationDonePpiGuid, + NULL +}; + EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo; UINT32 mMeasuredBaseFvIndex = 0; @@ -126,41 +132,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList[] = { EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi; -/** - This function get digest from digest list. - - @param HashAlg digest algorithm - @param DigestList digest list - @param Digest digest - - @retval EFI_SUCCESS Sha1Digest is found and returned. - @retval EFI_NOT_FOUND Sha1Digest is not found. -**/ -EFI_STATUS -Tpm2GetDigestFromDigestList ( - IN TPMI_ALG_HASH HashAlg, - IN TPML_DIGEST_VALUES *DigestList, - IN VOID *Digest - ) -{ - UINTN Index; - UINT16 DigestSize; - - DigestSize = GetHashSizeFromAlgo (HashAlg); - for (Index = 0; Index < DigestList->count; Index++) { - if (DigestList->digests[Index].hashAlg == HashAlg) { - CopyMem ( - Digest, - &DigestList->digests[Index].digest, - DigestSize - ); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - /** Record all measured Firmware Volum Information into a Guid Hob Guid Hob payload layout is @@ -243,7 +214,7 @@ LogHashEvent ( DEBUG ((EFI_D_INFO, " LogFormat - 0x%08x\n", mTreeEventInfo[Index].LogFormat)); switch (mTreeEventInfo[Index].LogFormat) { case TREE_EVENT_LOG_FORMAT_TCG_1_2: - Status = Tpm2GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); + Status = GetDigestFromDigestList (TPM_ALG_SHA1, DigestList, &NewEventHdr->Digest); if (!EFI_ERROR (Status)) { HobData = BuildGuidHob ( &gTcgEventEntryHobGuid, @@ -425,8 +396,8 @@ MeasureFvImage ( // // Add new FV into the measured FV list. // - ASSERT (mMeasuredBaseFvIndex < FixedPcdGet32 (PcdPeiCoreMaxFvSupported)); - if (mMeasuredBaseFvIndex < FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) { + ASSERT (mMeasuredBaseFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)); + if (mMeasuredBaseFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)) { mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase = FvBase; mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength; mMeasuredBaseFvIndex++; @@ -537,8 +508,8 @@ FirmwareVolmeInfoPpiNotifyCallback ( // if (Fv->ParentFvName != NULL || Fv->ParentFileName != NULL ) { - ASSERT (mMeasuredChildFvIndex < FixedPcdGet32 (PcdPeiCoreMaxFvSupported)); - if (mMeasuredChildFvIndex < FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) { + ASSERT (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)); + if (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)) { // // Check whether FV is in the measured child FV list. // @@ -621,21 +592,18 @@ PeimEntryMA ( ) { EFI_STATUS Status; + EFI_STATUS Status2; EFI_BOOT_MODE BootMode; if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) || CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){ - DEBUG ((EFI_D_ERROR, "No TPM2 instance required!\n")); + DEBUG ((DEBUG_INFO, "No TPM2 instance required!\n")); return EFI_UNSUPPORTED; } - // - // Update for Performance optimization - // - Status = Tpm2RequestUseTpm (); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "TPM not detected!\n")); - return Status; + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM2 error!\n")); + return EFI_DEVICE_ERROR; } Status = PeiServicesGetBootMode (&BootMode); @@ -658,6 +626,12 @@ PeimEntryMA ( // // Initialize TPM device // + Status = Tpm2RequestUseTpm (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "TPM2 not detected!\n")); + goto Done; + } + if (PcdGet8 (PcdTpm2InitializationPolicy) == 1) { if (BootMode == BOOT_ON_S3_RESUME) { Status = Tpm2Startup (TPM_SU_STATE); @@ -668,7 +642,7 @@ PeimEntryMA ( Status = Tpm2Startup (TPM_SU_CLEAR); } if (EFI_ERROR (Status) ) { - return Status; + goto Done; } } @@ -679,21 +653,38 @@ PeimEntryMA ( if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) { Status = Tpm2SelfTest (NO); if (EFI_ERROR (Status)) { - return Status; + goto Done; } } } + // + // Only intall TpmInitializedPpi on success + // Status = PeiServicesInstallPpi (&mTpmInitializedPpiList); ASSERT_EFI_ERROR (Status); } if (mImageInMemory) { Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices); - if (EFI_ERROR (Status)) { - return Status; - } + return Status; } +Done: + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "TPM2 error! Build Hob\n")); + BuildGuidHob (&gTpmErrorHobGuid,0); + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } + // + // Always intall TpmInitializationDonePpi no matter success or fail. + // Other driver can know TPM initialization state by TpmInitializedPpi. + // + Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList); + ASSERT_EFI_ERROR (Status2); + return Status; }