]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TcgPei/TcgPei.c
Handle TPM device error and avoid deadloop in BDS.
[mirror_edk2.git] / SecurityPkg / Tcg / TcgPei / TcgPei.c
index 0c00e286cef60ce4a63502c3e5f2f01aa211de39..dcf4b0bbbd62b21279e8fc2c8604b3506cbb535f 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 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/PeiServicesTablePointerLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
 \r
 #include "TpmComm.h"\r
 \r
@@ -221,6 +222,10 @@ HashLogExtendEvent (
 {\r
   EFI_STATUS                        Status;\r
   VOID                              *HobData;\r
+  \r
+  if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 \r
   HobData = NULL;\r
   if (HashDataLen != 0) {\r
@@ -229,7 +234,9 @@ HashLogExtendEvent (
                HashDataLen,\r
                &NewEventHdr->Digest\r
                );\r
-    ASSERT_EFI_ERROR (Status);\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
   }\r
 \r
   Status = TpmCommExtend (\r
@@ -239,20 +246,34 @@ HashLogExtendEvent (
              NewEventHdr->PCRIndex,\r
              NULL\r
              );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
 \r
   HobData = BuildGuidHob (\r
              &gTcgEventEntryHobGuid,\r
              sizeof (*NewEventHdr) + NewEventHdr->EventSize\r
              );\r
   if (HobData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
   }\r
 \r
   CopyMem (HobData, NewEventHdr, sizeof (*NewEventHdr));\r
   HobData = (VOID *) ((UINT8*)HobData + sizeof (*NewEventHdr));\r
   CopyMem (HobData, NewEventData, NewEventHdr->EventSize);\r
-  return EFI_SUCCESS;\r
+\r
+Done:\r
+  if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_TIMEOUT)) {\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
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -365,7 +386,6 @@ MeasureFvImage (
              &TcgEventHdr,\r
              (UINT8*) &FvBlob\r
              );\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Add new FV into the measured FV list.\r
@@ -682,7 +702,6 @@ PeimEntryMP (
   if (IsTpmUsable (PeiServices, TpmHandle)) {\r
     if (PcdGet8 (PcdTpmScrtmPolicy) == 1) {\r
       Status = MeasureCRTMVersion (PeiServices, TpmHandle);\r
-      ASSERT_EFI_ERROR (Status);\r
     }\r
 \r
     Status = MeasureMainBios (PeiServices, TpmHandle);\r