]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
MdeModulePkg/Core: Fix typos in comments
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVolBlock / FwVolBlock.c
index 523738d52da849884d3d30fcfecde7f21ca9bd1d..f031ef110c19b78680235837541bf6d1566731fc 100644 (file)
@@ -4,7 +4,7 @@
   It consumes FV HOBs and creates read-only Firmare Volume Block protocol\r
   instances for each of them.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -234,7 +234,7 @@ FwVolBlockReadBlock (
 \r
   if (Offset > FvbDevice->LbaCache[LbaIndex].Length) {\r
     //\r
-    // all exceed boundry, read nothing.\r
+    // all exceed boundary, read nothing.\r
     //\r
     *NumBytes = 0;\r
     return EFI_BAD_BUFFER_SIZE;\r
@@ -243,7 +243,7 @@ FwVolBlockReadBlock (
   NumOfBytesRead = *NumBytes;\r
   if (Offset + NumOfBytesRead > FvbDevice->LbaCache[LbaIndex].Length) {\r
     //\r
-    // partial exceed boundry, read data from current postion to end.\r
+    // partial exceed boundary, read data from current postion to end.\r
     //\r
     NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;\r
   }\r
@@ -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
@@ -515,9 +524,14 @@ ProduceFVBProtocolOnBuffer (
        PtrBlockMapEntry++) {\r
     FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;\r
   }\r
+\r
   //\r
   // Second, allocate the cache\r
   //\r
+  if (FvbDev->NumBlocks >= (MAX_ADDRESS / sizeof (LBA_CACHE))) {\r
+    CoreFreePool (FvbDev);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
   FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));\r
   if (FvbDev->LbaCache == NULL) {\r
     CoreFreePool (FvbDev);\r
@@ -632,6 +646,10 @@ FwVolBlockDriverInit (
   particular, it can be called by BDS to process a single firmware\r
   volume found in a capsule.\r
 \r
+  Caution: The caller need validate the input firmware volume to follow\r
+  PI specification.\r
+  DxeCore will trust the input data and process firmware volume directly.\r
+\r
   @param  FvHeader               pointer to a firmware volume header\r
   @param  Size                   the size of the buffer pointed to by FvHeader\r
   @param  FVProtocolHandle       the handle on which a firmware volume protocol\r