Cache FvImage at buffer with its required alignment.
authorlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 7 Dec 2007 10:25:56 +0000 (10:25 +0000)
committerlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 7 Dec 2007 10:25:56 +0000 (10:25 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4372 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
edk2/MdeModulePkg/Core/Dxe/DxeMain.h
edk2/MdeModulePkg/Core/Dxe/DxeMain.inf
edk2/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c

index 0529d36..bb49686 100644 (file)
@@ -1084,7 +1084,6 @@ Returns:
             if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r
               continue;\r
             }\r
-            \r
             //\r
             // Found a firmware volume image. Produce a firmware volume block\r
             // protocol for it so it gets dispatched from. This is usually a \r
index 16b7d8c..2490979 100644 (file)
@@ -82,6 +82,7 @@ Revision History
 #include <Library/CacheMaintenanceLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/PeCoffLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 \r
 #include "DebugImageInfo.h"\r
 #include "Library.h"\r
index 981c12d..ce6d55f 100644 (file)
@@ -87,6 +87,7 @@
   DxeCoreEntryPoint\r
   PeCoffLib\r
   ExtractGuidedSectionLib\r
+  MemoryAllocationLib\r
 \r
 [Guids]\r
   gEfiEventLegacyBootGuid                       # ALWAYS_CONSUMED\r
index 1a98e97..67dd803 100644 (file)
@@ -412,11 +412,14 @@ Returns:
   UINTN                                                 Instance;\r
   UINT8                                                 *CopyBuffer;\r
   UINTN                                                 SectionSize;\r
+  EFI_FIRMWARE_VOLUME_HEADER                            *FvHeader;\r
+  UINT32                                                FvAlignment;  \r
+  \r
   \r
-\r
   OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
   Instance = SectionInstance + 1;\r
-  \r
+  FvHeader = NULL;\r
+  FvAlignment = 0;\r
   //\r
   // Locate target stream\r
   //\r
@@ -469,8 +472,19 @@ Returns:
   } else {\r
     //\r
     // Callee allocated buffer.  Allocate buffer and return size.\r
+    // For FvImage, the buffer is allocated at its required alignment.\r
     //\r
-    *Buffer = CoreAllocateBootServicesPool (CopySize);\r
+    if (*SectionType == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) CopyBuffer;\r
+      FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+      //\r
+      // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
+      // \r
+      if (FvAlignment < 8) {\r
+        FvAlignment = 8;\r
+      }\r
+    }\r
+    *Buffer = AllocateAlignedPool ((UINTN) CopySize, (UINTN) FvAlignment);\r
     if (*Buffer == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto GetSection_Done;\r