]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Minor coding style fix.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index 8bf096a67ebdc3bd880abbf6c939cb21bdabc997..30485a836cc98c68b1ccb30fc8973b8f8fe81c4f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Firmware File System service routines.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2010, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -634,7 +634,7 @@ PeiFfsFindSectionData (
   @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param SearchType      Filter to find only files of this type.\r
                          Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
-  @param VolumeHandle    Handle of firmware volume in which to search.\r
+  @param FvHandle        Handle of firmware volume in which to search.\r
   @param FileHandle      On entry, points to the current handle from which to begin searching or NULL to start\r
                          at the beginning of the firmware volume. On exit, points the file handle of the next file\r
                          in the volume or NULL if there are no more files.\r
@@ -813,7 +813,7 @@ PeiFfsGetVolumeInfo (
 {\r
   PEI_CORE_FV_HANDLE                     *CoreHandle;\r
   \r
-  if (VolumeInfo == NULL) {\r
+  if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   \r
@@ -853,6 +853,7 @@ ProcessFvFile (
   EFI_PEI_FV_HANDLE             ParentFvHandle;\r
   EFI_FIRMWARE_VOLUME_HEADER    *FvHeader;\r
   EFI_FV_FILE_INFO              FileInfo;\r
+  UINT64                        FvLength;\r
   \r
   //\r
   // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
@@ -890,7 +891,7 @@ ProcessFvFile (
   //\r
   // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
   //\r
-  FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+  FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
   if (FvAlignment < 8) {\r
     FvAlignment = 8;\r
   }\r
@@ -899,11 +900,12 @@ ProcessFvFile (
   // Check FvImage\r
   //\r
   if ((UINTN) FvHeader % FvAlignment != 0) {\r
-    NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvHeader->FvLength), FvAlignment);\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) FvHeader->FvLength);\r
+    CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
     FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
   }\r
   \r
@@ -1101,6 +1103,7 @@ PeiFfs2FvPpiFindFileByName (
         Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL);\r
         if (!EFI_ERROR (Status)) {\r
           *FvHandle = PrivateData->Fv[Index].FvHandle;\r
+          break;\r
         }\r
       }\r
     }\r
@@ -1153,7 +1156,7 @@ PeiFfs2FvPpiGetFileInfo (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+  if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r
     ErasePolarity = 1;\r
   } else {\r
     ErasePolarity = 0;\r
@@ -1206,7 +1209,7 @@ PeiFfs2FvPpiGetVolumeInfo (
   EFI_FIRMWARE_VOLUME_HEADER             FwVolHeader;\r
   EFI_FIRMWARE_VOLUME_EXT_HEADER         *FwVolExHeaderInfo;\r
 \r
-  if (VolumeInfo == NULL) {\r
+  if ((VolumeInfo == NULL) || (FvHandle == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   \r
@@ -1345,14 +1348,34 @@ FindNextCoreFvHandle (
     //\r
     FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r
     while (FvHob != NULL) {\r
+      //\r
+      // Search whether FvHob has been installed into PeiCore's FV database.\r
+      // If found, no need install new FvInfoPpi for it.\r
+      //\r
       for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r
         if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r
           Match = TRUE;\r
           break;\r
         }\r
       }\r
+      \r
+      //\r
+      // Search whether FvHob has been cached into PeiCore's Unknown FV database.\r
+      // If found, no need install new FvInfoPpi for it.\r
+      //\r
+      if (!Match) {\r
+        for (Index = 0; Index < Private->UnknownFvInfoCount; Index ++) {\r
+          if ((UINTN)FvHob->BaseAddress == (UINTN)Private->UnknownFvInfo[Index].FvInfo) {\r
+            Match = TRUE;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+\r
       //\r
-      // If Not Found, Install FvInfo Ppi for it.\r
+      // If the Fv in FvHob has not been installed into PeiCore's FV database and has\r
+      // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi\r
+      // for it then PeiCore will dispatch it in callback of FvInfoPpi.\r
       //\r
       if (!Match) {\r
         PeiServicesInstallFvInfoPpi (\r
@@ -1363,6 +1386,7 @@ FindNextCoreFvHandle (
           NULL\r
           );\r
       }\r
+      \r
       FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r
     }\r
   }\r