]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg DxeCore: Check FvImage alignment
authorStar Zeng <star.zeng@intel.com>
Tue, 28 Nov 2017 02:47:19 +0000 (10:47 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 1 Dec 2017 01:36:55 +0000 (09:36 +0800)
No need to allocate aligned buffer if FvImage has been
at required alignment.

Then the code logic will be aligned with ProcessFvFile() in
MdeModulePkg/Core/Pei/FwVol/FwVol.c.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c

index 5eee71bb2cd33ce6fd10dd72c183d76db9239b4d..c7b9224c0e33301e111d48f9b9407c03ac5b8572 100644 (file)
@@ -1023,32 +1023,38 @@ CoreProcessFvImageFile (
     // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
     // its initial linked location and maintain its alignment.\r
     //\r
-    if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
+    if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
       //\r
       // Get FvHeader alignment\r
       //\r
-      FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+      FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
       //\r
       // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
       //\r
       if (FvAlignment < 8) {\r
         FvAlignment = 8;\r
       }\r
+\r
       //\r
-      // Allocate the aligned buffer for the FvImage.\r
+      // Check FvImage alignment.\r
       //\r
-      AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r
-      if (AlignedBuffer == NULL) {\r
-        FreePool (Buffer);\r
-        return EFI_OUT_OF_RESOURCES;\r
-      } else {\r
+      if ((UINTN) FvHeader % FvAlignment != 0) {\r
         //\r
-        // Move FvImage into the aligned buffer and release the original buffer.\r
+        // Allocate the aligned buffer for the FvImage.\r
         //\r
-        CopyMem (AlignedBuffer, Buffer, BufferSize);\r
-        FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;\r
-        CoreFreePool (Buffer);\r
-        Buffer = NULL;\r
+        AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r
+        if (AlignedBuffer == NULL) {\r
+          FreePool (Buffer);\r
+          return EFI_OUT_OF_RESOURCES;\r
+        } else {\r
+          //\r
+          // Move FvImage into the aligned buffer and release the original buffer.\r
+          //\r
+          CopyMem (AlignedBuffer, Buffer, BufferSize);\r
+          FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;\r
+          CoreFreePool (Buffer);\r
+          Buffer = NULL;\r
+        }\r
       }\r
     }\r
     //\r