]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
MdeModulePkg: Variable: Update DBT PCR[7] measure
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / CapsuleService.c
index 17f167c978cad91e9d45d93dc52899b9f4efaaba..216798d1617e07ecf0ca7d5cc2e150259da2ad95 100644 (file)
@@ -4,7 +4,7 @@
   It installs the Capsule Architectural Protocol defined in PI1.0a to signify \r
   the capsule runtime services are ready.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, 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
@@ -19,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Protocol/Capsule.h>\r
 #include <Guid/CapsuleVendor.h>\r
+#include <Guid/FmpCapsule.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
@@ -29,7 +30,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiRuntimeLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/PrintLib.h>\r
-\r
+#include <Library/BaseMemoryLib.h>\r
 //\r
 // Handle for the installation of Capsule Architecture Protocol.\r
 //\r
@@ -40,6 +41,9 @@ EFI_HANDLE  mNewHandle = NULL;
 //\r
 UINTN       mTimes      = 0;\r
 \r
+UINT32      mMaxSizePopulateCapsule     = 0;\r
+UINT32      mMaxSizeNonPopulateCapsule  = 0;\r
+\r
 /**\r
   Create the variable to save the base address of page table and stack\r
   for transferring into long mode in IA32 PEI.\r
@@ -73,6 +77,11 @@ SaveLongModeContext (
   @retval EFI_INVALID_PARAMETER CapsuleCount is Zero.\r
   @retval EFI_INVALID_PARAMETER For across reset capsule image, ScatterGatherList is NULL.\r
   @retval EFI_UNSUPPORTED       CapsuleImage is not recognized by the firmware.\r
+  @retval EFI_OUT_OF_RESOURCES  When ExitBootServices() has been previously called this error indicates the capsule \r
+                                is compatible with this platform but is not capable of being submitted or processed \r
+                                in runtime. The caller may resubmit the capsule prior to ExitBootServices().\r
+  @retval EFI_OUT_OF_RESOURCES  When ExitBootServices() has not been previously called then this error indicates \r
+                                the capsule is compatible with this platform but there are insufficient resources to process.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -119,12 +128,23 @@ UpdateCapsule (
     if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+\r
+    //\r
+    // Check FMP capsule flag \r
+    //\r
+    if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)\r
+     && (CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0 ) {\r
+       return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     //\r
     // Check Capsule image without populate flag by firmware support capsule function  \r
     //\r
-    if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
-        (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
-      return EFI_UNSUPPORTED;\r
+    if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
+      Status = SupportCapsuleImage (CapsuleHeader);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
     }\r
   }\r
 \r
@@ -140,7 +160,7 @@ UpdateCapsule (
     //\r
     if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) == 0) {\r
       if (EfiAtRuntime ()) { \r
-        Status = EFI_UNSUPPORTED;\r
+        Status = EFI_OUT_OF_RESOURCES;\r
       } else {\r
         Status = ProcessCapsuleImage(CapsuleHeader);\r
       }\r
@@ -182,10 +202,16 @@ UpdateCapsule (
   // Construct variable name CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...\r
   // if user calls UpdateCapsule multiple times.\r
   //\r
-  StrCpy (CapsuleVarName, EFI_CAPSULE_VARIABLE_NAME);\r
+  StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CHAR16), EFI_CAPSULE_VARIABLE_NAME);\r
   TempVarName = CapsuleVarName + StrLen (CapsuleVarName);\r
   if (mTimes > 0) {\r
-    UnicodeValueToString (TempVarName, 0, mTimes, 0);\r
+    UnicodeValueToStringS (\r
+      TempVarName,\r
+      sizeof (CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName),\r
+      0,\r
+      mTimes,\r
+      0\r
+      );\r
   }\r
 \r
   //\r
@@ -245,6 +271,7 @@ QueryCapsuleCapabilities (
   OUT EFI_RESET_TYPE       *ResetType\r
   )\r
 {\r
+  EFI_STATUS                Status;\r
   UINTN                     ArrayNumber;\r
   EFI_CAPSULE_HEADER        *CapsuleHeader;\r
   BOOLEAN                   NeedReset;\r
@@ -282,12 +309,23 @@ QueryCapsuleCapabilities (
     if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+\r
+    //\r
+    // Check FMP capsule flag \r
+    //\r
+    if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)\r
+     && (CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0 ) {\r
+       return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     //\r
     // Check Capsule image without populate flag is supported by firmware\r
     //\r
-    if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
-        (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
-      return EFI_UNSUPPORTED;\r
+    if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
+      Status = SupportCapsuleImage (CapsuleHeader);\r
+      if (EFI_ERROR(Status)) {\r
+        return Status;\r
+      }\r
     }\r
   }\r
 \r
@@ -301,7 +339,7 @@ QueryCapsuleCapabilities (
       break;\r
     }\r
   }\r
-  \r
+\r
   if (NeedReset) {\r
     //\r
     //Check if the platform supports update capsule across a system reset\r
@@ -310,13 +348,13 @@ QueryCapsuleCapabilities (
       return EFI_UNSUPPORTED;\r
     }\r
     *ResetType = EfiResetWarm;\r
-    *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r
+    *MaxiumCapsuleSize = (UINT64) mMaxSizePopulateCapsule;\r
   } else {\r
     //\r
     // For non-reset capsule image.\r
     //\r
     *ResetType = EfiResetCold;\r
-    *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r
+    *MaxiumCapsuleSize = (UINT64) mMaxSizeNonPopulateCapsule;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -341,7 +379,10 @@ CapsuleServiceInitialize (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  \r
+\r
+  mMaxSizePopulateCapsule = PcdGet32(PcdMaxSizePopulateCapsule);\r
+  mMaxSizeNonPopulateCapsule = PcdGet32(PcdMaxSizeNonPopulateCapsule);\r
+\r
   //\r
   // When PEI phase is IA32, DXE phase is X64, it is possible that capsule data are \r
   // put above 4GB, so capsule PEI will transfer to long mode to get capsule data.\r