]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TrEEPei/TrEEPei.c
Handle TPM device error and avoid deadloop in BDS.
[mirror_edk2.git] / SecurityPkg / Tcg / TrEEPei / TrEEPei.c
index 8e2bc748ff41b2b94a0bc3037994cf438a01b75f..eea40847c5e648299fe5a27c9ed0d26afa4a5a20 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Initialize TPM2 device and measure FVs before handing off control to DXE.\r
 \r
-Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2015, 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
@@ -40,19 +40,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/TrEEProtocol.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
 \r
 #define PERF_ID_TREE_PEI  0x3080\r
 \r
 typedef struct {\r
   EFI_GUID               *EventGuid;\r
   TREE_EVENT_LOG_FORMAT  LogFormat;\r
-  UINT32                 BootHashAlg;\r
-  UINT16                 DigestAlgID;\r
-  TPMI_ALG_HASH          TpmHashAlgo;\r
 } TREE_EVENT_INFO_STRUCT;\r
 \r
 TREE_EVENT_INFO_STRUCT mTreeEventInfo[] = {\r
-  {&gTcgEventEntryHobGuid,             TREE_EVENT_LOG_FORMAT_TCG_1_2,      TREE_BOOT_HASH_ALG_SHA1,     0,                       TPM_ALG_SHA1},\r
+  {&gTcgEventEntryHobGuid,             TREE_EVENT_LOG_FORMAT_TCG_1_2},\r
 };\r
 \r
 BOOLEAN                 mImageInMemory  = FALSE;\r
@@ -128,28 +126,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
 \r
 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi;\r
 \r
-/**\r
-  This function return hash algorithm from event log format.\r
-\r
-  @param[in]     EventLogFormat    Event log format.\r
-\r
-  @return hash algorithm.\r
-**/\r
-TPMI_ALG_HASH\r
-TrEEGetHashAlgoFromLogFormat (\r
-  IN      TREE_EVENT_LOG_FORMAT     EventLogFormat\r
-  )\r
-{\r
-  UINTN  Index;\r
-\r
-  for (Index = 0; Index < sizeof(mTreeEventInfo)/sizeof(mTreeEventInfo[0]); Index++) {\r
-    if (mTreeEventInfo[Index].LogFormat == EventLogFormat) {\r
-      return mTreeEventInfo[Index].TpmHashAlgo;\r
-    }\r
-  }\r
-  return TPM_ALG_SHA1;\r
-}\r
-\r
 /**\r
   This function get digest from digest list.\r
 \r
@@ -318,6 +294,10 @@ HashLogExtendEvent (
   EFI_STATUS                        Status;\r
   TPML_DIGEST_VALUES                DigestList;\r
 \r
+  if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   Status = HashAndExtend (\r
              NewEventHdr->PCRIndex,\r
              HashData,\r
@@ -329,6 +309,16 @@ HashLogExtendEvent (
       Status = LogHashEvent (&DigestList, NewEventHdr, NewEventData);\r
     }\r
   }\r
+  \r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((EFI_D_ERROR, "HashLogExtendEvent - %r. Disable TPM.\n", Status));\r
+    BuildGuidHob (&gTpmErrorHobGuid,0);\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)\r
+      );\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -431,7 +421,6 @@ MeasureFvImage (
              &TcgEventHdr,\r
              (UINT8*) &FvBlob\r
              );\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Add new FV into the measured FV list.\r
@@ -600,7 +589,6 @@ PeimEntryMP (
   \r
   if (PcdGet8 (PcdTpm2ScrtmPolicy) == 1) {\r
     Status = MeasureCRTMVersion ();\r
-    ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   Status = MeasureMainBios ();\r