]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/Capsules.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / Capsules.c
index 3a998c6df6b947f9911305cc8bab267ec21d3e1c..c144d228aebdf39438464f343fca58ac7628c749 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   BDS routines to handle capsules.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2018, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -34,7 +34,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 EFI_STATUS\r
-ProcessCapsules (\r
+EFIAPI\r
+BdsProcessCapsules (\r
   EFI_BOOT_MODE BootMode\r
   )\r
 {\r
@@ -50,43 +51,48 @@ ProcessCapsules (
   UINT32                      CacheNumber;\r
   VOID                        **CapsulePtr;\r
   VOID                        **CapsulePtrCache;\r
-  EFI_GUID                    *CapsuleGuidCache; \r
-  CAPSULE_HOB_INFO            *CapsuleHobInfo;\r
+  EFI_GUID                    *CapsuleGuidCache;\r
+  BOOLEAN                     NeedReset;\r
 \r
-  CapsuleNumber = 0;\r
+  CapsuleNumber      = 0;\r
   CapsuleTotalNumber = 0;\r
-  CacheIndex   = 0;\r
-  CacheNumber  = 0;\r
-  CapsulePtr        = NULL;\r
-  CapsulePtrCache   = NULL;\r
-  CapsuleGuidCache  = NULL;\r
+  CacheIndex         = 0;\r
+  CacheNumber        = 0;\r
+  CapsulePtr         = NULL;\r
+  CapsulePtrCache    = NULL;\r
+  CapsuleGuidCache   = NULL;\r
+  NeedReset          = FALSE;\r
 \r
   //\r
   // We don't do anything else if the boot mode is not flash-update\r
   //\r
   if (BootMode != BOOT_ON_FLASH_UPDATE) {\r
+    DEBUG ((EFI_D_ERROR, "Boot mode is not correct for capsule update.\n"));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   Status = EFI_SUCCESS;\r
   //\r
   // Find all capsule images from hob\r
   //\r
   HobPointer.Raw = GetHobList ();\r
-  while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {\r
+  while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r
     CapsuleTotalNumber ++;\r
-\r
     HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r
   }\r
-  \r
+\r
   if (CapsuleTotalNumber == 0) {\r
     //\r
     // We didn't find a hob, so had no errors.\r
     //\r
+    DEBUG ((EFI_D_ERROR, "We can not find capsule data in capsule update boot mode.\n"));\r
+    DEBUG ((EFI_D_ERROR, "Please check the followings are correct if unexpected capsule update error happens.\n"));\r
+    DEBUG ((EFI_D_ERROR, "1. CapsuleX64 is built as X64 module when PEI is IA32 and DXE is X64\n"));\r
+    DEBUG ((EFI_D_ERROR, "2. Capsule data should persist in memory across a system reset.\n"));\r
     PlatformBdsLockNonUpdatableFlash ();\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // Init temp Capsule Data table.\r
   //\r
@@ -96,15 +102,13 @@ ProcessCapsules (
   ASSERT (CapsulePtrCache != NULL);\r
   CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);\r
   ASSERT (CapsuleGuidCache != NULL);\r
-  \r
+\r
   //\r
   // Find all capsule images from hob\r
   //\r
   HobPointer.Raw = GetHobList ();\r
-  while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {\r
-    CapsuleHobInfo = GET_GUID_HOB_DATA (HobPointer.Guid);\r
-    CapsulePtr [CapsuleNumber++] = (VOID *)(UINTN)(CapsuleHobInfo->BaseAddress);\r
-\r
+  while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r
+    CapsulePtr [CapsuleNumber++] = (VOID *) (UINTN) HobPointer.Capsule->BaseAddress;\r
     HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r
   }\r
 \r
@@ -115,12 +119,12 @@ ProcessCapsules (
 \r
   //\r
   // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating\r
-  // System to have information persist across a system reset. EFI System Table must \r
+  // System to have information persist across a system reset. EFI System Table must\r
   // point to an array of capsules that contains the same CapsuleGuid value. And agents\r
-  // searching for this type capsule will look in EFI System Table and search for the \r
+  // searching for this type capsule will look in EFI System Table and search for the\r
   // capsule's Guid and associated pointer to retrieve the data. Two steps below describes\r
-  // how to sorting the capsules by the unique guid and install the array to EFI System Table. \r
-  // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an \r
+  // how to sorting the capsules by the unique guid and install the array to EFI System Table.\r
+  // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an\r
   // array for later sorting capsules by CapsuleGuid.\r
   //\r
   for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
@@ -128,7 +132,7 @@ ProcessCapsules (
     if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
       //\r
       // For each capsule, we compare it with known CapsuleGuid in the CacheArray.\r
-      // If already has the Guid, skip it. Whereas, record it in the CacheArray as \r
+      // If already has the Guid, skip it. Whereas, record it in the CacheArray as\r
       // an additional one.\r
       //\r
       CacheIndex = 0;\r
@@ -155,7 +159,7 @@ ProcessCapsules (
   //\r
   CacheIndex = 0;\r
   while (CacheIndex < CacheNumber) {\r
-    CapsuleNumber = 0;  \r
+    CapsuleNumber = 0;\r
     for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
       CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r
       if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
@@ -168,7 +172,7 @@ ProcessCapsules (
       }\r
     }\r
     if (CapsuleNumber != 0) {\r
-      Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*);  \r
+      Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*);\r
       CapsuleTable = AllocateRuntimePool (Size);\r
       ASSERT (CapsuleTable != NULL);\r
       CapsuleTable->CapsuleArrayNumber =  CapsuleNumber;\r
@@ -181,13 +185,20 @@ ProcessCapsules (
 \r
   //\r
   // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are\r
-  // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash \r
+  // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash\r
   // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional\r
   // type capsule transaction could be extended. It depends on platform policy.\r
   //\r
   for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
     CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r
     if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
+      //\r
+      // Always reset system after all capsule processed if FMP capsule exist\r
+      //\r
+      if (CompareGuid (&gEfiFmpCapsuleGuid, &CapsuleHeader->CapsuleGuid)){\r
+        NeedReset = TRUE;\r
+      }\r
+\r
       //\r
       // Call capsule library to process capsule image.\r
       //\r
@@ -195,8 +206,21 @@ ProcessCapsules (
     }\r
   }\r
 \r
+  if (NeedReset) {\r
+    Print(L"Capsule Request Cold Reboot.\n");\r
+\r
+    for (Index = 5; Index > 0; Index--) {\r
+      Print(L"\rResetting system in %d seconds ...", Index);\r
+      gBS->Stall (1000000);\r
+    }\r
+\r
+    gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
+\r
+    CpuDeadLoop ();\r
+  }\r
+\r
   PlatformBdsLockNonUpdatableFlash ();\r
-  \r
+\r
   //\r
   // Free the allocated temp memory space.\r
   //\r
@@ -206,3 +230,4 @@ ProcessCapsules (
 \r
   return Status;\r
 }\r
+\r