// 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