#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
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
} 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