]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Searching for files starts on an 8 byte aligned boundary after the end of the Extende...
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 27 Mar 2012 01:57:51 +0000 (01:57 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 27 Mar 2012 01:57:51 +0000 (01:57 +0000)
Signed-off-by: lzeng14
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13143 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c
MdeModulePkg/Core/Dxe/FwVol/FwVol.c
MdeModulePkg/Core/Pei/FwVol/FwVol.c

index a3e507afd05e615b6c4b8df44e04a8851027862c..c3878968d4201b6259b1d5c3aff571f104c4aa90 100644 (file)
@@ -4,7 +4,7 @@
   Layers on top of Firmware Block protocol to produce a file abstraction\r
   of FV based files.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions\r
@@ -194,6 +194,7 @@ FvCheck (
   EFI_FVB_ATTRIBUTES_2                FvbAttributes;\r
   EFI_FV_BLOCK_MAP_ENTRY              *BlockMap;\r
   EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
+  EFI_FIRMWARE_VOLUME_EXT_HEADER      *FwVolExtHeader;\r
   UINT8                               *FwCache;\r
   LBA_ENTRY                           *LbaEntry;\r
   FREE_SPACE_ENTRY                    *FreeSpaceEntry;\r
@@ -349,14 +350,23 @@ FvCheck (
   //\r
   // go through the whole FV cache, check the consistence of the FV\r
   //\r
-  Ptr           = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->HeaderLength);\r
-  TopFvAddress  = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->FvLength - 1);\r
+  if (FvDevice->FwVolHeader->ExtHeaderOffset != 0) {\r
+    //\r
+    // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.\r
+    //\r
+    FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->ExtHeaderOffset);\r
+    Ptr = (UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize;\r
+    Ptr = (UINT8 *) ALIGN_POINTER (Ptr, 8);\r
+  } else {\r
+    Ptr = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->HeaderLength);\r
+  }\r
+  TopFvAddress = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->FvLength);\r
 \r
   //\r
   // Build FFS list & Free Space List here\r
   //\r
-  while (Ptr <= TopFvAddress) {\r
-    TestLength = TopFvAddress - Ptr + 1;\r
+  while (Ptr < TopFvAddress) {\r
+    TestLength = TopFvAddress - Ptr;\r
 \r
     if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {\r
       TestLength = sizeof (EFI_FFS_FILE_HEADER);\r
@@ -370,7 +380,7 @@ FvCheck (
       FreeSize  = 0;\r
 \r
       do {\r
-        TestLength = TopFvAddress - Ptr + 1;\r
+        TestLength = TopFvAddress - Ptr;\r
 \r
         if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {\r
           TestLength = sizeof (EFI_FFS_FILE_HEADER);\r
@@ -382,7 +392,7 @@ FvCheck (
 \r
         FreeSize += TestLength;\r
         Ptr += TestLength;\r
-      } while (Ptr <= TopFvAddress);\r
+      } while (Ptr < TopFvAddress);\r
 \r
       FreeSpaceEntry = AllocateZeroPool (sizeof (FREE_SPACE_ENTRY));\r
       if (FreeSpaceEntry == NULL) {\r
index 66b767387250239611b59a4998e029427f644fac..1cee6a9ba0e3dca053562a44444e56b2a4a98a3d 100644 (file)
@@ -294,6 +294,7 @@ FvCheck (
   EFI_STATUS                            Status;\r
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *Fvb;\r
   EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader;\r
+  EFI_FIRMWARE_VOLUME_EXT_HEADER        *FwVolExtHeader;\r
   EFI_FVB_ATTRIBUTES_2                  FvbAttributes;\r
   EFI_FV_BLOCK_MAP_ENTRY                *BlockMap;\r
   FFS_FILE_LIST_ENTRY                   *FfsFileEntry;\r
@@ -410,7 +411,7 @@ FvCheck (
 \r
   //\r
   // go through the whole FV cache, check the consistence of the FV.\r
-  // Make a linked list off all the Ffs file headers\r
+  // Make a linked list of all the Ffs file headers\r
   //\r
   Status = EFI_SUCCESS;\r
   InitializeListHead (&FvDevice->FfsFileListHeader);\r
@@ -418,7 +419,16 @@ FvCheck (
   //\r
   // Build FFS list\r
   //\r
-  FfsHeader = (EFI_FFS_FILE_HEADER *) FvDevice->CachedFv;\r
+  if (FwVolHeader->ExtHeaderOffset != 0) {\r
+    //\r
+    // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.\r
+    //\r
+    FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (FvDevice->CachedFv + (FwVolHeader->ExtHeaderOffset - FwVolHeader->HeaderLength));\r
+    FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);\r
+    FfsHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsHeader, 8);\r
+  } else {\r
+    FfsHeader = (EFI_FFS_FILE_HEADER *) (FvDevice->CachedFv);\r
+  }\r
   TopFvAddress = FvDevice->EndOfCachedFv;\r
   while ((UINT8 *) FfsHeader < TopFvAddress) {\r
 \r
index bcf8335a27615dee2da102f787c7b58e27b098be..d0375be92e7d36129da5367d3ebe7933693af4bf 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Firmware File System service routines.\r
   \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\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
@@ -229,7 +229,8 @@ FindFileEx (
   IN OUT    EFI_PEI_FV_HANDLE        *AprioriFile  OPTIONAL\r
   )\r
 {\r
-  EFI_FIRMWARE_VOLUME_HEADER           *FwVolHeader;\r
+  EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader;\r
+  EFI_FIRMWARE_VOLUME_EXT_HEADER        *FwVolExtHeader;\r
   EFI_FFS_FILE_HEADER                   **FileHeader;\r
   EFI_FFS_FILE_HEADER                   *FfsFileHeader;\r
   UINT32                                FileLength;\r
@@ -262,7 +263,16 @@ FindFileEx (
   // start from the FileHeader.\r
   //\r
   if ((*FileHeader == NULL) || (FileName != NULL)) {\r
-    FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);\r
+    if (FwVolHeader->ExtHeaderOffset != 0) {\r
+      //\r
+      // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.\r
+      //\r
+      FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->ExtHeaderOffset);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsFileHeader, 8);\r
+    } else {\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r
+    }\r
   } else {\r
     if (IS_FFS_FILE2 (*FileHeader)) {\r
       if (!IsFfs3Fv) {\r