]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
MdeModulePkg: Add support for weakly aligned FVs.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVolBlock / FwVolBlock.c
index 9b7b166a9949596c3c8bf649835fa772d777b2d5..27a7f43fe5713d849a7d31fe9f517ea5495d0300 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   Implementations for Firmware Volume Block protocol.\r
 \r
-  It consumes FV HOBs and creates read-lonly Firmare Volume Block protocol\r
+  It consumes FV HOBs and creates read-only Firmare Volume Block protocol\r
   instances for each of them.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -81,6 +81,7 @@ EFI_FW_VOL_BLOCK_DEVICE  mFwVolBlock = {
   0,\r
   NULL,\r
   0,\r
+  0,\r
   0\r
 };\r
 \r
@@ -402,7 +403,31 @@ FwVolBlockGetBlockSize (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+\r
+  Get FVB authentication status\r
+\r
+  @param FvbProtocol    FVB protocol.\r
+\r
+  @return Authentication status.\r
+\r
+**/\r
+UINT32\r
+GetFvbAuthenticationStatus (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *FvbProtocol\r
+  )\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE   *FvbDevice;\r
+  UINT32                    AuthenticationStatus;\r
 \r
+  AuthenticationStatus = 0;\r
+  FvbDevice = BASE_CR (FvbProtocol, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance);\r
+  if (FvbDevice->Signature == FVB_DEVICE_SIGNATURE) {\r
+    AuthenticationStatus = FvbDevice->AuthenticationStatus;\r
+  }\r
+\r
+  return AuthenticationStatus;\r
+}\r
 \r
 /**\r
   This routine produces a firmware volume block protocol on a given\r
@@ -411,8 +436,10 @@ FwVolBlockGetBlockSize (
   @param  BaseAddress            base address of the firmware volume image\r
   @param  Length                 length of the firmware volume image\r
   @param  ParentHandle           handle of parent firmware volume, if this image\r
-                                 came from an FV image file in another firmware\r
+                                 came from an FV image file and section in another firmware\r
                                  volume (ala capsules)\r
+  @param  AuthenticationStatus   Authentication status inherited, if this image\r
+                                 came from an FV image file and section in another firmware volume.\r
   @param  FvProtocol             Firmware volume block protocol produced.\r
 \r
   @retval EFI_VOLUME_CORRUPTED   Volume corrupted.\r
@@ -426,6 +453,7 @@ ProduceFVBProtocolOnBuffer (
   IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
   IN UINT64                 Length,\r
   IN EFI_HANDLE             ParentHandle,\r
+  IN UINT32                 AuthenticationStatus,\r
   OUT EFI_HANDLE            *FvProtocol  OPTIONAL\r
   )\r
 {\r
@@ -446,19 +474,31 @@ ProduceFVBProtocolOnBuffer (
   if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
+\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 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\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
@@ -470,6 +510,9 @@ ProduceFVBProtocolOnBuffer (
   FvbDev->BaseAddress   = BaseAddress;\r
   FvbDev->FvbAttributes = FwVolHeader->Attributes;\r
   FvbDev->FwVolBlockInstance.ParentHandle = ParentHandle;\r
+  if (ParentHandle != NULL) {\r
+    FvbDev->AuthenticationStatus = AuthenticationStatus;\r
+  }\r
 \r
   //\r
   // Init the block caching fields of the device\r
@@ -584,7 +627,7 @@ FwVolBlockDriverInit (
     //\r
     // Produce an FVB protocol for it\r
     //\r
-    ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, NULL);\r
+    ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, 0, NULL);\r
     FvHob.Raw = GET_NEXT_HOB (FvHob);\r
   }\r
 \r
@@ -626,6 +669,7 @@ CoreProcessFirmwareVolume (
             (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
             (UINT64)Size,\r
             NULL,\r
+            0,\r
             FVProtocolHandle\r
             );\r
   //\r
@@ -637,6 +681,7 @@ CoreProcessFirmwareVolume (
   // somehow.\r
   //\r
   if (!EFI_ERROR(Status)) {\r
+    ASSERT (*FVProtocolHandle != NULL);\r
     Ptr = NULL;\r
     Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);\r
     if (EFI_ERROR(Status) || (Ptr == NULL)) {\r