]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/FwVol/FwVol.c
Add core FFS3 support, DxeCore.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVol / FwVol.c
index e7a5b44a6605ab181c32a3f966cd95230e50e4fe..1e1cbae368f1817553a56d3e409213ab6f0656c8 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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
@@ -304,7 +304,6 @@ FvCheck (
   UINTN                                 Index;\r
   EFI_LBA                               LbaIndex;\r
   UINTN                                 Size;\r
-  UINTN                                 FileLength;\r
   EFI_FFS_FILE_STATE                    FileState;\r
   UINT8                                 *TopFvAddress;\r
   UINTN                                 TestLength;\r
@@ -438,7 +437,14 @@ FvCheck (
     if (!IsValidFfsHeader (FvDevice->ErasePolarity, FfsHeader, &FileState)) {\r
       if ((FileState == EFI_FILE_HEADER_INVALID) ||\r
           (FileState == EFI_FILE_HEADER_CONSTRUCTION)) {\r
-        FfsHeader++;\r
+        if (IS_FFS_FILE2 (FfsHeader)) {\r
+          if (!FvDevice->IsFfs3Fv) {\r
+            DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));\r
+          }\r
+          FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));\r
+        } else {\r
+          FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER));\r
+        }\r
         continue;\r
       } else {\r
         //\r
@@ -457,10 +463,18 @@ FvCheck (
       goto Done;\r
     }\r
 \r
-    //\r
-    // Size[3] is a three byte array, read 4 bytes and throw one away\r
-    //\r
-    FileLength = *(UINT32 *)&FfsHeader->Size[0] & 0x00FFFFFF;\r
+    if (IS_FFS_FILE2 (FfsHeader)) {\r
+      ASSERT (FFS_FILE2_SIZE (FfsHeader) > 0x00FFFFFF);\r
+      if (!FvDevice->IsFfs3Fv) {\r
+        DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));\r
+        FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (FfsHeader));\r
+        //\r
+        // Adjust pointer to the next 8-byte aligned boundry.\r
+        //\r
+        FfsHeader = (EFI_FFS_FILE_HEADER *) (((UINTN) FfsHeader + 7) & ~0x07);\r
+        continue;\r
+      }\r
+    }\r
 \r
     FileState = GetFileState (FvDevice->ErasePolarity, FfsHeader);\r
 \r
@@ -481,7 +495,11 @@ FvCheck (
       InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link);\r
     }\r
 \r
-    FfsHeader =  (EFI_FFS_FILE_HEADER *)(((UINT8 *)FfsHeader) + FileLength);\r
+    if (IS_FFS_FILE2 (FfsHeader)) {\r
+      FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (FfsHeader));\r
+    } else {\r
+      FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE_SIZE (FfsHeader));\r
+    }\r
 \r
     //\r
     // Adjust pointer to the next 8-byte aligned boundry.\r
@@ -502,7 +520,7 @@ Done:
 \r
 /**\r
   This notification function is invoked when an instance of the\r
-  EFI_FW_VOLUME_BLOCK_PROTOCOL is produced.  It layers an instance of the\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is produced.  It layers an instance of the\r
   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
@@ -577,7 +595,8 @@ NotifyFwVolBlock (
     // 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
+    if ((!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&\r
+        (!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {\r
       continue;\r
     }\r
 \r
@@ -610,6 +629,7 @@ NotifyFwVolBlock (
       FvDevice->Handle          = Handle;\r
       FvDevice->FwVolHeader     = FwVolHeader;\r
       FvDevice->Fv.ParentHandle = Fvb->ParentHandle;\r
+      FvDevice->IsFfs3Fv        = CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid);\r
 \r
       //\r
       // Install an New FV protocol on the existing handle\r