+ //\r
+ // Evaluate the authentication status of the Firmware Volume through\r
+ // Security Architectural Protocol\r
+ //\r
+ if (gSecurity != NULL) {\r
+ FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r
+ Status = gSecurity->FileAuthenticationState (\r
+ gSecurity,\r
+ AuthenticationStatus,\r
+ FvFileDevicePath\r
+ );\r
+ if (FvFileDevicePath != NULL) {\r
+ FreePool (FvFileDevicePath);\r
+ }\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ //\r
+ // Security check failed. The firmware volume should not be used for any purpose.\r
+ //\r
+ if (Buffer != NULL) {\r
+ FreePool (Buffer);\r
+ }\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ //\r
+ // FvImage should be at its required alignment.\r
+ //\r
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
+ //\r
+ // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
+ // 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
+ //\r
+ // Get FvHeader alignment\r
+ //\r
+ FvAlignment = 1 << ((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
+ // 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
+ 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