]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
MdeModulePkg/CapsuleLib: Fix runtime issue
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleLib.c
index 71e05bd55783a83aeae4d0468009bca49d29a36f..9ed0be3b653c9d59fde48ede0184750d8a69d29c 100644 (file)
@@ -10,7 +10,7 @@
   ValidateFmpCapsule(), DisplayCapsuleImage(), ConvertBmpToGopBlt() will\r
   receive untrusted input and do basic validation.\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 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
@@ -47,9 +47,8 @@
 #include <Protocol/FirmwareManagement.h>\r
 #include <Protocol/DevicePath.h>\r
 \r
-EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable              = NULL;\r
-BOOLEAN                   mIsVirtualAddrConverted  = FALSE;\r
-BOOLEAN                   mDxeCapsuleLibEndOfDxe   = FALSE;\r
+BOOLEAN                   mDxeCapsuleLibEndOfDxe       = FALSE;\r
+EFI_EVENT                 mDxeCapsuleLibEndOfDxeEvent  = NULL;\r
 \r
 /**\r
   Initialize capsule related variables.\r
@@ -547,7 +546,7 @@ ConvertBmpToGopBlt (
 \r
     }\r
 \r
-    ImageIndex = (UINTN) (Image - ImageHeader);\r
+    ImageIndex = (UINTN) Image - (UINTN) ImageHeader;\r
     if ((ImageIndex % 4) != 0) {\r
       //\r
       // Bmp Image starts each row on a 32-bit boundary!\r
@@ -585,7 +584,7 @@ DisplayCapsuleImage (
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
 \r
   ImagePayload = (DISPLAY_DISPLAY_PAYLOAD *)(CapsuleHeader + 1);\r
-  PayloadSize = (UINTN)(CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER));\r
+  PayloadSize = CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER);\r
 \r
   if (ImagePayload->Version != 1) {\r
     return EFI_UNSUPPORTED;\r
@@ -733,7 +732,7 @@ DumpFmpCapsule (
   for (Index = 0; Index < FmpCapsuleHeader->EmbeddedDriverCount; Index++) {\r
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));\r
   }\r
-  for (; Index < (UINTN)(FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount); Index++) {\r
+  for (; Index < (UINT32)FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount; Index++) {\r
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));\r
     ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);\r
 \r
@@ -1454,33 +1453,44 @@ IsNestedFmpCapsule (
   EFI_SYSTEM_RESOURCE_ENTRY  Entry;\r
 \r
   EsrtGuidFound = FALSE;\r
-\r
-  //\r
-  // Check ESRT protocol\r
-  //\r
-  Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtProtocol);\r
-  if (!EFI_ERROR(Status)) {\r
-    Status = EsrtProtocol->GetEsrtEntry(&CapsuleHeader->CapsuleGuid, &Entry);\r
-    if (!EFI_ERROR(Status)) {\r
-      EsrtGuidFound = TRUE;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Check ESRT configuration table\r
-  //\r
-  if (!EsrtGuidFound) {\r
-    Status = EfiGetSystemConfigurationTable(&gEfiSystemResourceTableGuid, (VOID **)&Esrt);\r
-    if (!EFI_ERROR(Status)) {\r
-      ASSERT (Esrt != NULL);\r
-      EsrtEntry = (VOID *)(Esrt + 1);\r
-      for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {\r
+  if (mIsVirtualAddrConverted) {\r
+    if(mEsrtTable != NULL) {\r
+      EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1);\r
+      for (Index = 0; Index < mEsrtTable->FwResourceCount ; Index++, EsrtEntry++) {\r
         if (CompareGuid(&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
           EsrtGuidFound = TRUE;\r
           break;\r
         }\r
       }\r
     }\r
+  } else {\r
+    //\r
+    // Check ESRT protocol\r
+    //\r
+    Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtProtocol);\r
+    if (!EFI_ERROR(Status)) {\r
+      Status = EsrtProtocol->GetEsrtEntry(&CapsuleHeader->CapsuleGuid, &Entry);\r
+      if (!EFI_ERROR(Status)) {\r
+        EsrtGuidFound = TRUE;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Check ESRT configuration table\r
+    //\r
+    if (!EsrtGuidFound) {\r
+      Status = EfiGetSystemConfigurationTable(&gEfiSystemResourceTableGuid, (VOID **)&Esrt);\r
+      if (!EFI_ERROR(Status)) {\r
+        ASSERT (Esrt != NULL);\r
+        EsrtEntry = (VOID *)(Esrt + 1);\r
+        for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {\r
+          if (CompareGuid(&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
+            EsrtGuidFound = TRUE;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+    }\r
   }\r
   if (!EsrtGuidFound) {\r
     return FALSE;\r
@@ -1654,7 +1664,6 @@ DxeCapsuleLibConstructor (
   IN EFI_SYSTEM_TABLE   *SystemTable\r
   )\r
 {\r
-  EFI_EVENT     EndOfDxeEvent;\r
   EFI_STATUS    Status;\r
 \r
   Status = gBS->CreateEventEx (\r
@@ -1663,7 +1672,7 @@ DxeCapsuleLibConstructor (
                   DxeCapsuleLibEndOfDxe,\r
                   NULL,\r
                   &gEfiEndOfDxeEventGroupGuid,\r
-                  &EndOfDxeEvent\r
+                  &mDxeCapsuleLibEndOfDxeEvent\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -1671,3 +1680,29 @@ DxeCapsuleLibConstructor (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  The destructor function closes the End of DXE event.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The destructor completed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeCapsuleLibDestructor (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  //\r
+  // Close the End of DXE event.\r
+  //\r
+  Status = gBS->CloseEvent (mDxeCapsuleLibEndOfDxeEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r