]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TcgPei/TcgPei.c
Add TPM2 implementation.
[mirror_edk2.git] / SecurityPkg / Tcg / TcgPei / TcgPei.c
index 350e60e56123351165173831c402d8bd7d4d63ae..7ff869d0fc80ceb08961769175c08442e4fd8a8b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Initialize TPM device and measure FVs before handing off control to DXE.\r
 \r
-Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -21,9 +21,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Ppi/TpmInitialized.h>\r
 #include <Ppi/FirmwareVolume.h>\r
 #include <Ppi/EndOfPeiPhase.h>\r
+#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>\r
 \r
 #include <Guid/TcgEventHob.h>\r
 #include <Guid/MeasuredFvHob.h>\r
+#include <Guid/TpmInstance.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -51,6 +53,8 @@ UINT32 mMeasuredBaseFvIndex = 0;
 EFI_PLATFORM_FIRMWARE_BLOB mMeasuredChildFvInfo[FixedPcdGet32 (PcdPeiCoreMaxFvSupported)];\r
 UINT32 mMeasuredChildFvIndex = 0;\r
 \r
+EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi;\r
+\r
 /**\r
   Lock physical presence if needed.\r
 \r
@@ -311,6 +315,19 @@ MeasureFvImage (
 \r
   TpmHandle = (TIS_TPM_HANDLE) (UINTN) TPM_BASE_ADDRESS;\r
 \r
+  //\r
+  // Check if it is in Excluded FV list\r
+  //\r
+  if (mMeasurementExcludedFvPpi != NULL) {\r
+    for (Index = 0; Index < mMeasurementExcludedFvPpi->Count; Index ++) {\r
+      if (mMeasurementExcludedFvPpi->Fv[Index].FvBase == FvBase) {\r
+        DEBUG ((DEBUG_INFO, "The FV which is excluded by TcgPei starts at: 0x%x\n", FvBase));\r
+        DEBUG ((DEBUG_INFO, "The FV which is excluded by TcgPei has the size: 0x%x\n", FvLength));\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
   //\r
   // Check whether FV is in the measured FV list.\r
   //\r
@@ -627,6 +644,14 @@ PeimEntryMP (
   EFI_STATUS                        Status;\r
   TIS_TPM_HANDLE                    TpmHandle;\r
 \r
+  Status = PeiServicesLocatePpi (\r
+               &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid, \r
+               0, \r
+               NULL,\r
+               (VOID**)&mMeasurementExcludedFvPpi\r
+               );\r
+  // Do not check status, because it is optional\r
+\r
   TpmHandle = (TIS_TPM_HANDLE)(UINTN)TPM_BASE_ADDRESS;\r
   Status = TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR)TpmHandle);\r
   if (EFI_ERROR (Status)) {\r
@@ -634,8 +659,10 @@ PeimEntryMP (
   }\r
 \r
   if (IsTpmUsable (PeiServices, TpmHandle)) {\r
-    Status = MeasureCRTMVersion (PeiServices, TpmHandle);\r
-    ASSERT_EFI_ERROR (Status);\r
+    if (PcdGet8 (PcdTpmScrtmPolicy) == 1) {\r
+      Status = MeasureCRTMVersion (PeiServices, TpmHandle);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
 \r
     Status = MeasureMainBios (PeiServices, TpmHandle);\r
   }  \r
@@ -673,6 +700,11 @@ PeimEntryMA (
   EFI_BOOT_MODE                     BootMode;\r
   TIS_TPM_HANDLE                    TpmHandle;\r
 \r
+  if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){\r
+    DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n"));\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -703,9 +735,11 @@ PeimEntryMA (
       return Status;\r
     }\r
 \r
-    Status = TpmCommStartup ((EFI_PEI_SERVICES**)PeiServices, TpmHandle, BootMode);\r
-    if (EFI_ERROR (Status) ) {\r
-      return Status;\r
+    if (PcdGet8 (PcdTpmInitializationPolicy) == 1) {\r
+      Status = TpmCommStartup ((EFI_PEI_SERVICES**)PeiServices, TpmHandle, BootMode);\r
+      if (EFI_ERROR (Status) ) {\r
+        return Status;\r
+      }\r
     }\r
 \r
     //\r