]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVol/FwVol.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVol / FwVol.c
index a7b272b4d697518b9a62e7e02ac209d93e61be53..93ddcc35913badc81ae3b141dc6c78fad5a3166a 100644 (file)
@@ -3,7 +3,7 @@
   Layers on top of Firmware Block protocol to produce a file abstraction\r
   of FV based files.\r
 \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -34,8 +34,8 @@ FV_DEVICE mFvDevice = {
     FvReadFile,\r
     FvReadFileSection,\r
     FvWriteFile,\r
-    FvGetNextFile,   \r
-       sizeof (UINTN),\r
+    FvGetNextFile,\r
+  sizeof (UINTN),\r
     NULL,\r
     FvGetVolumeInfo,\r
     FvSetVolumeInfo\r
@@ -56,7 +56,7 @@ FV_DEVICE mFvDevice = {
 // FFS helper functions\r
 //\r
 /**\r
-  Read data from Firmware Block by FVB protocol Read. \r
+  Read data from Firmware Block by FVB protocol Read.\r
   The data may cross the multi block ranges.\r
 \r
   @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to read data.\r
@@ -86,7 +86,7 @@ ReadFvbData (
   UINTN                       BlockIndex;\r
   UINTN                       ReadDataSize;\r
   EFI_STATUS                  Status;\r
-  \r
+\r
   //\r
   // Try read data in current block\r
   //\r
@@ -102,7 +102,7 @@ ReadFvbData (
     //\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Data crosses the blocks, read data from next block\r
   //\r
@@ -118,7 +118,7 @@ ReadFvbData (
     //\r
     // Read data from the crossing blocks\r
     //\r
-    BlockIndex = 0; \r
+    BlockIndex = 0;\r
     while (BlockIndex < NumberOfBlocks && DataSize >= BlockSize) {\r
       Status = Fvb->Read (Fvb, *StartLba + BlockIndex, 0, &BlockSize, Data);\r
       if (EFI_ERROR (Status)) {\r
@@ -128,20 +128,20 @@ ReadFvbData (
       DataSize -= BlockSize;\r
       BlockIndex ++;\r
     }\r
-    \r
+\r
     //\r
     // Data doesn't exceed the current block range.\r
     //\r
     if (DataSize < BlockSize) {\r
       break;\r
     }\r
-    \r
+\r
     //\r
     // Data must be got from the next block range.\r
     //\r
     *StartLba += NumberOfBlocks;\r
   }\r
-  \r
+\r
   //\r
   // read the remaining data\r
   //\r
@@ -151,7 +151,7 @@ ReadFvbData (
       return Status;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Update Lba and Offset used by the following read.\r
   //\r
@@ -173,6 +173,8 @@ ReadFvbData (
   @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated.\r
   @retval EFI_SUCCESS           Successfully read volume header to the allocated\r
                                 buffer.\r
+  @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or\r
+                                the file system could not be understood.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -187,7 +189,7 @@ GetFwVolHeader (
   EFI_LBA                     StartLba;\r
   UINTN                       Offset;\r
   UINT8                       *Buffer;\r
-  \r
+\r
   //\r
   // Read the standard FV header\r
   //\r
@@ -199,6 +201,22 @@ GetFwVolHeader (
     return Status;\r
   }\r
 \r
+  //\r
+  // Validate FV Header signature, if not as expected, continue.\r
+  //\r
+  if (TempFvh.Signature != EFI_FVH_SIGNATURE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Check to see that the file system is indeed formatted in a way we can\r
+  // understand it...\r
+  //\r
+  if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&\r
+      (!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Allocate a buffer for the caller\r
   //\r
@@ -400,9 +418,9 @@ FvCheck (
           HeaderSize = 0;\r
         }\r
       }\r
-    \r
+\r
       //\r
-      // read the FV data  \r
+      // read the FV data\r
       //\r
       for (; Index < BlockMap->NumBlocks; Index ++) {\r
         Status = Fvb->Read (Fvb,\r
@@ -464,7 +482,7 @@ FvCheck (
     FfsHeader = (EFI_FFS_FILE_HEADER *) (FvDevice->CachedFv);\r
   }\r
   TopFvAddress = FvDevice->EndOfCachedFv;\r
-  while ((UINT8 *) FfsHeader < TopFvAddress) {\r
+  while (((UINTN) FfsHeader >= (UINTN) FvDevice->CachedFv) && ((UINTN) FfsHeader <= (UINTN) ((UINTN) TopFvAddress - sizeof (EFI_FFS_FILE_HEADER)))) {\r
 \r
     if (FileCached) {\r
       CoreFreePool (CacheFfsHeader);\r
@@ -536,7 +554,7 @@ FvCheck (
         DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &CacheFfsHeader->Name));\r
         FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));\r
         //\r
-        // Adjust pointer to the next 8-byte aligned boundry.\r
+        // Adjust pointer to the next 8-byte aligned boundary.\r
         //\r
         FfsHeader = (EFI_FFS_FILE_HEADER *) (((UINTN) FfsHeader + 7) & ~0x07);\r
         continue;\r
@@ -571,7 +589,7 @@ FvCheck (
     }\r
 \r
     //\r
-    // Adjust pointer to the next 8-byte aligned boundry.\r
+    // Adjust pointer to the next 8-byte aligned boundary.\r
     //\r
     FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);\r
 \r
@@ -654,33 +672,15 @@ NotifyFwVolBlock (
     //\r
     Status = GetFwVolHeader (Fvb, &FwVolHeader);\r
     if (EFI_ERROR (Status)) {\r
-      return;\r
-    }\r
-    ASSERT (FwVolHeader != NULL);\r
-\r
-    //\r
-    // Validate FV Header signature, if not as expected, continue.\r
-    //\r
-    if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {\r
-      CoreFreePool (FwVolHeader);\r
       continue;\r
     }\r
+    ASSERT (FwVolHeader != NULL);\r
 \r
     if (!VerifyFvHeaderChecksum (FwVolHeader)) {\r
       CoreFreePool (FwVolHeader);\r
       continue;\r
     }\r
 \r
-\r
-    //\r
-    // Check to see that the file system is indeed formatted in a way we can\r
-    // understand it...\r
-    //\r
-    if ((!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&\r
-        (!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {\r
-      continue;\r
-    }\r
-\r
     //\r
     // Check if there is an FV protocol already installed in that handle\r
     //\r
@@ -711,14 +711,11 @@ NotifyFwVolBlock (
       FvDevice->FwVolHeader     = FwVolHeader;\r
       FvDevice->IsFfs3Fv        = CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid);\r
       FvDevice->Fv.ParentHandle = Fvb->ParentHandle;\r
+      //\r
+      // Inherit the authentication status from FVB.\r
+      //\r
+      FvDevice->AuthenticationStatus = GetFvbAuthenticationStatus (Fvb);\r
 \r
-      if (Fvb->ParentHandle != NULL) {\r
-        //\r
-        // Inherit the authentication status from FVB.\r
-        //\r
-        FvDevice->AuthenticationStatus = GetFvbAuthenticationStatus (Fvb);\r
-      }\r
-      \r
       if (!EFI_ERROR (FvCheck (FvDevice))) {\r
         //\r
         // Install an New FV protocol on the existing handle\r