]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Update PeiCore and DxeCore to verify FFS data checksum.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index c6eb1fa24f55420b0bbde9ff5b3ac39f46dca0b0..941657c07f9d4b2e0ed2430b7571af08791d7299 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Pei Core Firmware File System service routines.\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2006 - 2010, 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
@@ -162,6 +162,7 @@ FindFileEx (
   UINT64                                FvLength;\r
   UINT8                                 ErasePolarity;\r
   UINT8                                 FileState;\r
+  UINT8                                 DataCheckSum;\r
   \r
   //\r
   // Convert the handle of FV to FV header for memory-mapped firmware volume\r
@@ -219,6 +220,16 @@ FindFileEx (
       FileLength       = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r
       FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r
 \r
+      DataCheckSum = FFS_FIXED_CHECKSUM;\r
+      if ((FfsFileHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {\r
+        DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER));\r
+      }\r
+      if (FfsFileHeader->IntegrityCheck.Checksum.File != DataCheckSum) {\r
+        ASSERT (FALSE);\r
+        *FileHeader = NULL;\r
+        return EFI_NOT_FOUND;\r
+      }\r
+\r
       if (FileName != NULL) {\r
         if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r
           *FileHeader = FfsFileHeader;\r
@@ -755,7 +766,7 @@ PeiFfsFindFileByName (
   Returns information about a specific file.\r
 \r
   @param FileHandle       Handle of the file.\r
-  @param FileInfo         Upon exit, points to the files information.\r
+  @param FileInfo         Upon exit, points to the file's information.\r
 \r
   @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r
   @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r
@@ -1348,14 +1359,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
-      // If Not Found, Install FvInfo Ppi for it.\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 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
@@ -1366,10 +1397,12 @@ 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
 \r
+  ASSERT (Private->FvCount <= FixedPcdGet32 (PcdPeiCoreMaxFvSupported));\r
   if (Instance >= Private->FvCount) {\r
     return NULL;\r
   }\r
@@ -1452,7 +1485,7 @@ AddUnknownFormatFvInfo (
 {\r
   PEI_CORE_UNKNOW_FORMAT_FV_INFO    *NewUnknownFv;\r
   \r
-  if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
+  if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   \r
@@ -1585,6 +1618,12 @@ ThirdPartyFvPpiNotifyCallback (
       continue;\r
     }\r
     \r
+    if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
+      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r
+      DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
+      ASSERT (FALSE);\r
+    }\r
+        \r
     //\r
     // Update internal PEI_CORE_FV array.\r
     //\r