]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVol/FwVol.c
move header files in MdeModulePkg\Core\Dxe except DxeMain.h into their corresponding...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVol / FwVol.c
index ed81cd464d4ef284ab700c29bece520df0c4ba65..9e26e4f020defbc129127d9d8935057db5f9320d 100644 (file)
@@ -1,22 +1,22 @@
 /** @file\r
   Firmware File System driver that produce Firmware Volume protocol.\r
-  Layers on top of Firmware Block protocol to produce a file abstraction \r
+  Layers on top of Firmware Block protocol to produce a file abstraction\r
   of FV based files.\r
-  \r
-Copyright (c) 2006 - 2008 Intel Corporation. <BR>\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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation. <BR>\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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
+#include "FwVolDriver.h"\r
 \r
-#define KEYSIZE       sizeof (UINTN)\r
 \r
 //\r
 // Protocol notify related globals\r
@@ -34,8 +34,8 @@ FV_DEVICE mFvDevice = {
     FvReadFile,\r
     FvReadFileSection,\r
     FvWriteFile,\r
-    FvGetNextFile,\r
-    KEYSIZE,\r
+    FvGetNextFile,   \r
+       sizeof (UINTN),\r
     NULL,\r
     FvGetVolumeInfo,\r
     FvSetVolumeInfo\r
@@ -52,19 +52,17 @@ FV_DEVICE mFvDevice = {
 //\r
 // FFS helper functions\r
 //\r
-\r
-\r
 /**\r
   given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and\r
   copy the volume header into it.\r
 \r
-  @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to \r
-                                read the volume header \r
-  @param  FwVolHeader           Pointer to pointer to allocated buffer in which \r
-                                the volume header is returned. \r
+  @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to\r
+                                read the volume header\r
+  @param  FwVolHeader           Pointer to pointer to allocated buffer in which\r
+                                the volume header is returned.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated. \r
-  @retval EFI_SUCCESS           Successfully read volume header to the allocated \r
+  @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
 \r
 **/\r
@@ -85,11 +83,14 @@ GetFwVolHeader (
   //\r
   FvhLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER);\r
   Status = Fvb->Read (Fvb, 0, 0, &FvhLength, (UINT8 *)&TempFvh);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Allocate a buffer for the caller\r
   //\r
-  *FwVolHeader = CoreAllocateBootServicesPool (TempFvh.HeaderLength);\r
+  *FwVolHeader = AllocatePool (TempFvh.HeaderLength);\r
   if (*FwVolHeader == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -111,7 +112,7 @@ GetFwVolHeader (
     //\r
     CoreFreePool (*FwVolHeader);\r
   }\r
\r
+\r
   return Status;\r
 }\r
 \r
@@ -120,12 +121,9 @@ GetFwVolHeader (
 /**\r
   Free FvDevice resource when error happens\r
 \r
-  @param  FvDevice              pointer to the FvDevice to be freed. \r
-\r
-  @return None.\r
+  @param  FvDevice              pointer to the FvDevice to be freed.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 FreeFvDeviceResource (\r
   IN FV_DEVICE  *FvDevice\r
@@ -140,7 +138,7 @@ FreeFvDeviceResource (
   FfsFileEntry = (FFS_FILE_LIST_ENTRY *)FvDevice->FfsFileListHeader.ForwardLink;\r
   while (&FfsFileEntry->Link != &FvDevice->FfsFileListHeader) {\r
     NextEntry = (&FfsFileEntry->Link)->ForwardLink;\r
-    \r
+\r
     if (FfsFileEntry->StreamHandle != 0) {\r
       //\r
       // Close stream and free resources from SEP\r
@@ -150,7 +148,7 @@ FreeFvDeviceResource (
 \r
     CoreFreePool (FfsFileEntry);\r
 \r
-    FfsFileEntry = (FFS_FILE_LIST_ENTRY *)NextEntry;\r
+    FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry;\r
   }\r
 \r
 \r
@@ -170,12 +168,12 @@ FreeFvDeviceResource (
 \r
 \r
 /**\r
-  Check if a FV is consistent and allocate cache\r
+  Check if an FV is consistent and allocate cache for it.\r
 \r
-  @param  FvDevice              pointer to the FvDevice to be checked. \r
+  @param  FvDevice              A pointer to the FvDevice to be checked.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated. \r
-  @retval EFI_SUCCESS           FV is consistent and cache is allocated. \r
+  @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated.\r
+  @retval EFI_SUCCESS           FV is consistent and cache is allocated.\r
   @retval EFI_VOLUME_CORRUPTED  File system is corrupted.\r
 \r
 **/\r
@@ -187,7 +185,7 @@ FvCheck (
   EFI_STATUS                            Status;\r
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *Fvb;\r
   EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader;\r
-  EFI_FVB_ATTRIBUTES                    FvbAttributes;\r
+  EFI_FVB_ATTRIBUTES_2                  FvbAttributes;\r
   EFI_FV_BLOCK_MAP_ENTRY                *BlockMap;\r
   FFS_FILE_LIST_ENTRY                   *FfsFileEntry;\r
   EFI_FFS_FILE_HEADER                   *FfsHeader;\r
@@ -204,7 +202,7 @@ FvCheck (
 \r
   Fvb = FvDevice->Fvb;\r
   FwVolHeader = FvDevice->FwVolHeader;\r
\r
+\r
   Status = Fvb->GetAttributes (Fvb, &FvbAttributes);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -215,7 +213,7 @@ FvCheck (
   // the header to check to make sure the volume is valid\r
   //\r
   Size = (UINTN)(FwVolHeader->FvLength - FwVolHeader->HeaderLength);\r
-  FvDevice->CachedFv = CoreAllocateBootServicesPool (Size);\r
+  FvDevice->CachedFv = AllocatePool (Size);\r
 \r
   if (FvDevice->CachedFv == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -235,7 +233,7 @@ FvCheck (
   LbaIndex = 0;\r
   LbaOffset = FwVolHeader->HeaderLength;\r
   while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {\r
-    \r
+\r
     for (Index = 0; Index < BlockMap->NumBlocks; Index ++) {\r
 \r
       Size = BlockMap->Length;\r
@@ -246,18 +244,18 @@ FvCheck (
         Size -= LbaOffset;\r
       }\r
       Status = Fvb->Read (Fvb,\r
-                          LbaIndex,\r
-                          LbaOffset,\r
-                          &Size,\r
-                          CacheLocation\r
-                          );\r
+                      LbaIndex,\r
+                      LbaOffset,\r
+                      &Size,\r
+                      CacheLocation\r
+                      );\r
       //\r
       // Not check EFI_BAD_BUFFER_SIZE, for Size = BlockMap->Length\r
       //\r
       if (EFI_ERROR (Status)) {\r
         goto Done;\r
       }\r
-      \r
+\r
       //\r
       // After we skip Fv Header always read from start of block\r
       //\r
@@ -276,7 +274,7 @@ FvCheck (
     FvDevice->ErasePolarity = 1;\r
   } else {\r
     FvDevice->ErasePolarity = 0;\r
-  } \r
+  }\r
 \r
 \r
   //\r
@@ -289,11 +287,11 @@ FvCheck (
   //\r
   // Build FFS list\r
   //\r
-  FfsHeader = (EFI_FFS_FILE_HEADER *)FvDevice->CachedFv;\r
+  FfsHeader = (EFI_FFS_FILE_HEADER *) FvDevice->CachedFv;\r
   TopFvAddress = FvDevice->EndOfCachedFv;\r
-  while ((UINT8 *)FfsHeader < TopFvAddress) {\r
+  while ((UINT8 *) FfsHeader < TopFvAddress) {\r
 \r
-    TestLength = TopFvAddress - ((UINT8 *)FfsHeader);\r
+    TestLength = TopFvAddress - ((UINT8 *) FfsHeader);\r
     if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {\r
       TestLength = sizeof (EFI_FFS_FILE_HEADER);\r
     }\r
@@ -306,12 +304,10 @@ FvCheck (
     }\r
 \r
     if (!IsValidFfsHeader (FvDevice->ErasePolarity, FfsHeader, &FileState)) {\r
-      if ((FileState == EFI_FILE_HEADER_INVALID) || \r
+      if ((FileState == EFI_FILE_HEADER_INVALID) ||\r
           (FileState == EFI_FILE_HEADER_CONSTRUCTION)) {\r
         FfsHeader++;\r
-      \r
         continue;\r
-      \r
       } else {\r
         //\r
         // File system is corrputed\r
@@ -335,7 +331,7 @@ FvCheck (
     FileLength = *(UINT32 *)&FfsHeader->Size[0] & 0x00FFFFFF;\r
 \r
     FileState = GetFileState (FvDevice->ErasePolarity, FfsHeader);\r
-    \r
+\r
     //\r
     // check for non-deleted file\r
     //\r
@@ -343,23 +339,23 @@ FvCheck (
       //\r
       // Create a FFS list entry for each non-deleted file\r
       //\r
-      FfsFileEntry = CoreAllocateZeroBootServicesPool (sizeof (FFS_FILE_LIST_ENTRY));\r
+      FfsFileEntry = AllocateZeroPool (sizeof (FFS_FILE_LIST_ENTRY));\r
       if (FfsFileEntry == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
-    \r
+\r
       FfsFileEntry->FfsHeader = FfsHeader;\r
       InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link);\r
     }\r
 \r
     FfsHeader =  (EFI_FFS_FILE_HEADER *)(((UINT8 *)FfsHeader) + FileLength);\r
-    \r
+\r
     //\r
     // Adjust pointer to the next 8-byte aligned boundry.\r
     //\r
     FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);\r
-    \r
+\r
   }\r
 \r
 Done:\r
@@ -378,11 +374,10 @@ Done:
   EFI_FIRMWARE_VOLUME2_PROTOCOL on the same handle.  This is the function where\r
   the actual initialization of the EFI_FIRMWARE_VOLUME2_PROTOCOL is done.\r
 \r
-  @param  Event                 The event that occured \r
+  @param  Event                 The event that occured\r
   @param  Context               For EFI compatiblity.  Not used.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EFIAPI\r
 NotifyFwVolBlock (\r
@@ -423,13 +418,13 @@ NotifyFwVolBlock (
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
-    \r
+\r
     //\r
     // Get the FirmwareVolumeBlock protocol on that handle\r
     //\r
-    Status = CoreHandleProtocol (Handle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb); \r
+    Status = CoreHandleProtocol (Handle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);\r
     ASSERT_EFI_ERROR (Status);\r
-    \r
+\r
 \r
     //\r
     // Make sure the Fv Header is O.K.\r
@@ -473,16 +468,16 @@ NotifyFwVolBlock (
       //\r
       // No FwVol protocol on the handle so create a new one\r
       //\r
-      FvDevice = CoreAllocateCopyPool (sizeof (FV_DEVICE), &mFvDevice);\r
+      FvDevice = AllocateCopyPool (sizeof (FV_DEVICE), &mFvDevice);\r
       if (FvDevice == NULL) {\r
         return;\r
       }\r
-      \r
-      FvDevice->Fvb         = Fvb;\r
-      FvDevice->Handle      = Handle;\r
-      FvDevice->FwVolHeader = FwVolHeader;\r
+\r
+      FvDevice->Fvb             = Fvb;\r
+      FvDevice->Handle          = Handle;\r
+      FvDevice->FwVolHeader     = FwVolHeader;\r
       FvDevice->Fv.ParentHandle = Fvb->ParentHandle;\r
-      \r
+\r
       //\r
       // Install an New FV protocol on the existing handle\r
       //\r
@@ -495,19 +490,19 @@ NotifyFwVolBlock (
       ASSERT_EFI_ERROR (Status);\r
     }\r
   }\r
-  \r
+\r
   return;\r
 }\r
 \r
 \r
 \r
 /**\r
-  This routine is the driver initialization entry point.  It initializes the\r
-  libraries, and registers two notification functions.  These notification\r
-  functions are responsible for building the FV stack dynamically.\r
+  This routine is the driver initialization entry point.  It registers\r
+  a notification function.  This notification function are responsible\r
+  for building the FV stack dynamically.\r
 \r
-  @param  ImageHandle           The image handle. \r
-  @param  SystemTable           The system table. \r
+  @param  ImageHandle           The image handle.\r
+  @param  SystemTable           The system table.\r
 \r
   @retval EFI_SUCCESS           Function successfully returned.\r
 \r
@@ -519,13 +514,12 @@ FwVolDriverInit (
   IN EFI_SYSTEM_TABLE             *SystemTable\r
   )\r
 {\r
-  gEfiFwVolBlockEvent = CoreCreateProtocolNotifyEvent (\r
+  gEfiFwVolBlockEvent = EfiCreateProtocolNotifyEvent (\r
                           &gEfiFirmwareVolumeBlockProtocolGuid,\r
                           TPL_CALLBACK,\r
                           NotifyFwVolBlock,\r
                           NULL,\r
-                          &gEfiFwVolBlockNotifyReg,\r
-                          TRUE\r
+                          &gEfiFwVolBlockNotifyReg\r
                           );\r
   return EFI_SUCCESS;\r
 }\r