]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
MdeModulePkg: Add support for weakly aligned FVs.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index af8f821ebb9ed1b1519d23975097326104220410..e505c707b075771cd13e724e097757f1b5dd412b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Firmware File System service routines.\r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -226,7 +226,7 @@ FindFileEx (
   IN  CONST EFI_GUID                 *FileName,   OPTIONAL\r
   IN        EFI_FV_FILETYPE          SearchType,\r
   IN OUT    EFI_PEI_FILE_HANDLE      *FileHandle,\r
-  IN OUT    EFI_PEI_FV_HANDLE        *AprioriFile  OPTIONAL\r
+  IN OUT    EFI_PEI_FILE_HANDLE      *AprioriFile  OPTIONAL\r
   )\r
 {\r
   EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader;\r
@@ -1112,26 +1112,33 @@ ProcessFvFile (
   }\r
 \r
   //\r
-  // FvAlignment must be more than 8 bytes required by FvHeader structure.\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
-  FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
-  if (FvAlignment < 8) {\r
-    FvAlignment = 8;\r
-  }\r
-  \r
-  //\r
-  // Check FvImage\r
-  //\r
-  if ((UINTN) FvHeader % FvAlignment != 0) {\r
-    FvLength    = ReadUnaligned64 (&FvHeader->FvLength);\r
-    NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
-    if (NewFvBuffer == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
+  if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
+    //\r
+    // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
+    //\r
+    FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
+    if (FvAlignment < 8) {\r
+      FvAlignment = 8;\r
+    }\r
+\r
+    //\r
+    // Check FvImage\r
+    //\r
+    if ((UINTN) FvHeader % FvAlignment != 0) {\r
+      FvLength    = ReadUnaligned64 (&FvHeader->FvLength);\r
+      NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
+      if (NewFvBuffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
     }\r
-    CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
-    FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
   }\r
-  \r
+\r
   Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r
   ASSERT_EFI_ERROR (Status);\r
   \r