+ if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
+ //\r
+ // Get FvHeader alignment\r
+ //\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
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
+ __FUNCTION__,\r
+ FvHeader,\r
+ FvAlignment\r
+ ));\r
+\r
+ //\r
+ // Check FvImage alignment.\r
+ //\r
+ if ((UINTN)FvHeader % FvAlignment != 0) {\r
+ //\r
+ // Allocate the aligned buffer for the FvImage.\r
+ //\r
+ AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN)FvAlignment);\r
+ if (AlignedBuffer == NULL) {\r
+ FreePool (Buffer);\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ } else {\r
+ //\r
+ // Move FvImage into the aligned buffer and release the original buffer.\r
+ //\r
+ if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
+ //\r
+ // Copy the used bytes and fill the rest with the erase value.\r
+ //\r
+ CopyMem (AlignedBuffer, FvHeader, (UINTN)FvUsedSize);\r
+ SetMem (\r
+ (UINT8 *)AlignedBuffer + FvUsedSize,\r
+ (UINTN)(BufferSize - FvUsedSize),\r
+ EraseByte\r
+ );\r
+ } else {\r
+ CopyMem (AlignedBuffer, Buffer, BufferSize);\r
+ }\r
+\r
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)AlignedBuffer;\r
+ FreePool (Buffer);\r
+ Buffer = NULL;\r
+ }\r
+ }\r
+ }\r
+\r