]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add support for weakly aligned FVs.
authorStar Zeng <star.zeng@intel.com>
Mon, 16 Sep 2013 01:50:44 +0000 (01:50 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Sep 2013 01:50:44 +0000 (01:50 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14671 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
MdeModulePkg/Core/Pei/FwVol/FwVol.c
MdePkg/Include/Pi/PiFirmwareVolume.h

index 75d6267f6143d6f1c191ae9fcc7d13caac116a4a..a70e2e45d581aecb65f19f768ad771f9b3a055ff 100644 (file)
@@ -1036,39 +1036,48 @@ CoreProcessFvImageFile (
     //\r
     FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
     //\r
-    // Get FvHeader alignment\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 << ((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
-      Status = EFI_OUT_OF_RESOURCES;\r
-    } else {\r
+    if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
       //\r
-      // Move FvImage into the aligned buffer and release the original buffer.\r
+      // Get FvHeader alignment\r
       //\r
-      CopyMem (AlignedBuffer, Buffer, BufferSize);\r
-      CoreFreePool (Buffer);\r
-      Buffer = NULL;\r
+      FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
       //\r
-      // Produce a FVB protocol for the file\r
+      // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
       //\r
-      Status = ProduceFVBProtocolOnBuffer (\r
-                (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r
-                (UINT64)BufferSize,\r
-                FvHandle,\r
-                AuthenticationStatus,\r
-                NULL\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
+    //\r
+    // Produce a FVB protocol for the file\r
+    //\r
+    Status = ProduceFVBProtocolOnBuffer (\r
+              (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+              (UINT64)BufferSize,\r
+              FvHandle,\r
+              AuthenticationStatus,\r
+              NULL\r
+              );\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
index 523738d52da849884d3d30fcfecde7f21ca9bd1d..27a7f43fe5713d849a7d31fe9f517ea5495d0300 100644 (file)
@@ -474,22 +474,31 @@ ProduceFVBProtocolOnBuffer (
   if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
+\r
   //\r
-  // Get FvHeader alignment\r
-  //\r
-  FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
-  //\r
-  // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. \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 (FvAlignment < 8) {\r
-    FvAlignment = 8;\r
-  }\r
-  if ((UINTN)BaseAddress % FvAlignment != 0) {\r
+  if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
     //\r
-    // FvImage buffer is not at its required alignment.\r
+    // Get FvHeader alignment\r
     //\r
-    return EFI_VOLUME_CORRUPTED;\r
+    FvAlignment = 1 << ((FwVolHeader->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
+    if ((UINTN)BaseAddress % FvAlignment != 0) {\r
+      //\r
+      // FvImage buffer is not at its required alignment.\r
+      //\r
+      return EFI_VOLUME_CORRUPTED;\r
+    }\r
   }\r
+\r
   //\r
   // Allocate EFI_FW_VOL_BLOCK_DEVICE\r
   //\r
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
index f589c20dd949d18665cdce3f99787378e057db89..7aa2e5e0168f83ac1a325be7e9947bb1d3478980 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The firmware volume related definitions in PI.\r
 \r
-  Copyright (c) 2006 - 2011, 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
@@ -11,7 +11,7 @@
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
   @par Revision Reference:\r
-  PI Version 1.2C\r
+  PI Version 1.3\r
 \r
 **/\r
 \r
@@ -86,7 +86,7 @@ typedef UINT32  EFI_FVB_ATTRIBUTES_2;
 #define EFI_FVB2_ALIGNMENT_512M     0x001D0000\r
 #define EFI_FVB2_ALIGNMENT_1G       0x001E0000\r
 #define EFI_FVB2_ALIGNMENT_2G       0x001F0000\r
-\r
+#define EFI_FVB2_WEAK_ALIGNMENT     0x80000000\r
 \r
 typedef struct {\r
   ///\r