]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add core FFS3 support, DxeCore.
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 27 Oct 2011 09:23:19 +0000 (09:23 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 27 Oct 2011 09:23:19 +0000 (09:23 +0000)
Signed-off-by: lzeng14
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12584 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/Core/Dxe/DxeMain.inf
MdeModulePkg/Core/Dxe/FwVol/Ffs.c
MdeModulePkg/Core/Dxe/FwVol/FwVol.c
MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c

index 511a85ff87058b098f8e504feec1029838a8e923..c084dc821364fc0b0a38da5eb4d9cd38bc5d6e2e 100644 (file)
@@ -54,6 +54,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/SmmBase2.h>\r
 #include <Guid/MemoryTypeInformation.h>\r
 #include <Guid/FirmwareFileSystem2.h>\r
+#include <Guid/FirmwareFileSystem3.h>\r
 #include <Guid/HobList.h>\r
 #include <Guid/DebugImageInfoTable.h>\r
 #include <Guid/FileInfo.h>\r
@@ -2255,6 +2256,7 @@ OpenSectionStream (
                                 function returns anything other than\r
                                 EFI_SUCCESS, the value of *AuthenticationStatus\r
                                 is undefined.\r
+  @param  IsFfs3Fv              Indicates the FV format.\r
 \r
   @retval EFI_SUCCESS           Section was retrieved successfully\r
   @retval EFI_PROTOCOL_ERROR    A GUID defined section was encountered in the\r
@@ -2285,7 +2287,8 @@ GetSection (
   IN UINTN                                              SectionInstance,\r
   IN VOID                                               **Buffer,\r
   IN OUT UINTN                                          *BufferSize,\r
-  OUT UINT32                                            *AuthenticationStatus\r
+  OUT UINT32                                            *AuthenticationStatus,\r
+  IN BOOLEAN                                            IsFfs3Fv\r
   );\r
 \r
 \r
index 3170e37be8e6c9f08730509cbc55e27f53433b7a..6bdab9058db4e8e94f401c0f8389783cc6fdc307 100644 (file)
   gEfiHobMemoryAllocModuleGuid                  ## CONSUMES ## Hob\r
   gEfiFileInfoGuid                              ## CONSUMES ## File\r
   gEfiFirmwareFileSystem2Guid                   ## CONSUMES ## GUID\r
+  gEfiFirmwareFileSystem3Guid                   ## CONSUMES ## GUID\r
   gAprioriGuid                                  ## CONSUMES ## GUID\r
   gEfiDebugImageInfoTableGuid                   ## CONSUMES ## GUID\r
   gEfiHobListGuid                               ## CONSUMES ## GUID\r
index 2bd4405cf13f7feb15b40b627d5bced8e334d11a..20dade18a275c7a4c830cd53d36ced5cda5d05de 100644 (file)
@@ -133,7 +133,11 @@ VerifyHeaderChecksum (
 {\r
   UINT8 HeaderChecksum;\r
 \r
-  HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));\r
+  if (IS_FFS_FILE2 (FfsHeader)) {\r
+    HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));\r
+  } else {\r
+    HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));\r
+  }\r
   HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);\r
 \r
   if (HeaderChecksum == 0) {\r
@@ -202,7 +206,6 @@ IsValidFfsFile (
 {\r
   EFI_FFS_FILE_STATE  FileState;\r
   UINT8               DataCheckSum;\r
-  UINT32              FileLength;\r
 \r
   FileState = GetFileState (ErasePolarity, FfsHeader);\r
   switch (FileState) {\r
@@ -211,9 +214,12 @@ IsValidFfsFile (
   case EFI_FILE_DATA_VALID:\r
   case EFI_FILE_MARKED_FOR_UPDATE:\r
     DataCheckSum = FFS_FIXED_CHECKSUM;\r
-    FileLength   = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF;\r
     if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {\r
-      DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER));\r
+      if (IS_FFS_FILE2 (FfsHeader)) {\r
+        DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER2));\r
+      } else {\r
+        DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER));\r
+      }\r
     }\r
     if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {\r
       return TRUE;\r
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
index 12ace7a097d33e566a23b48d9a81b1d4cd9589ea..7cc775f69b664ba4aabd146ca573fa960d7c7b82 100644 (file)
@@ -2,7 +2,7 @@
   Firmware File System protocol. Layers on top of Firmware\r
   Block protocol to produce a file abstraction of FV based files.\r
 \r
-Copyright (c) 2006 - 2008, 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
@@ -43,6 +43,7 @@ typedef struct {
   LIST_ENTRY                              FfsFileListHeader;\r
 \r
   UINT8                                   ErasePolarity;\r
+  BOOLEAN                                 IsFfs3Fv;\r
 } FV_DEVICE;\r
 \r
 #define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)\r
index 0b53af27d1fd8902b7caea6c8fed7891a43feaa4..52f84919d132b5111be196c53b14eed5e40e69e3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements functions to read firmware file\r
 \r
-Copyright (c) 2006 - 2009, 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
@@ -119,7 +119,6 @@ FvGetNextFile (
   UINTN                                       *KeyValue;\r
   LIST_ENTRY                                  *Link;\r
   FFS_FILE_LIST_ENTRY                         *FfsFileEntry;\r
-  UINTN                                       FileLength;\r
 \r
   FvDevice = FV_DEVICE_FROM_THIS (This);\r
 \r
@@ -201,15 +200,14 @@ FvGetNextFile (
   CopyGuid (NameGuid, &FfsFileHeader->Name);\r
   *Attributes = FfsAttributes2FvFileAttributes (FfsFileHeader->Attributes);\r
 \r
-  //\r
-  // Read four bytes out of the 3 byte array and throw out extra data\r
-  //\r
-  FileLength = *(UINT32 *)&FfsFileHeader->Size[0] & 0x00FFFFFF;\r
-\r
   //\r
   // we need to substract the header size\r
   //\r
-  *Size = FileLength - sizeof(EFI_FFS_FILE_HEADER);\r
+  if (IS_FFS_FILE2 (FfsFileHeader)) {\r
+    *Size = FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER2);\r
+  } else {\r
+    *Size = FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -333,7 +331,11 @@ FvReadFile (
   //\r
   // Skip over file header\r
   //\r
-  SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);\r
+  if (IS_FFS_FILE2 (FfsHeader)) {\r
+    SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);\r
+  } else {\r
+    SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);\r
+  }\r
 \r
   Status = EFI_SUCCESS;\r
   if (*Buffer == NULL) {\r
@@ -447,7 +449,7 @@ FvReadFileSection (
   }\r
 \r
   //\r
-  // Use FfsEntry to cache Section Extraction Protocol Inforomation\r
+  // Use FfsEntry to cache Section Extraction Protocol Information\r
   //\r
   if (FfsEntry->StreamHandle == 0) {\r
     Status = OpenSectionStream (\r
@@ -470,7 +472,8 @@ FvReadFileSection (
              (SectionType == 0) ? 0 : SectionInstance,\r
              Buffer,\r
              BufferSize,\r
-             AuthenticationStatus\r
+             AuthenticationStatus,\r
+             FvDevice->IsFfs3Fv\r
              );\r
 \r
   //\r
index cc129cc008f3583d1fd1a3c8e70fdf01cf119cc6..9fe296daf8e9345f8a05f4d7e11fdd61d50edb02 100644 (file)
@@ -27,7 +27,7 @@
   3) A support protocol is not found, and the data is not available to be read\r
      without it.  This results in EFI_PROTOCOL_ERROR.\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
@@ -269,7 +269,11 @@ IsValidSectionStream (
   SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
 \r
   while (TotalLength < SectionStreamLength) {\r
-    SectionLength = SECTION_SIZE (SectionHeader);\r
+    if (IS_SECTION2 (SectionHeader)) {\r
+      SectionLength = SECTION2_SIZE (SectionHeader);\r
+    } else {\r
+      SectionLength = SECTION_SIZE (SectionHeader);\r
+    }\r
     TotalLength += SectionLength;\r
 \r
     if (TotalLength == SectionStreamLength) {\r
@@ -475,7 +479,11 @@ ChildIsType (
     return TRUE;\r
   }\r
   GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);\r
-  return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
+  if (IS_SECTION2 (GuidedSection)) {\r
+    return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);\r
+  } else {\r
+    return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
+  }\r
 }\r
 \r
 /**\r
@@ -625,7 +633,11 @@ CreateChildNode (
   UINT32                                       ScratchSize;\r
   UINTN                                        NewStreamBufferSize;\r
   UINT32                                       AuthenticationStatus;\r
-  UINT32                                       SectionLength;\r
+  VOID                                         *CompressionSource;\r
+  UINT32                                       CompressionSourceSize;\r
+  UINT32                                       UncompressedLength;\r
+  UINT8                                        CompressionType;\r
+  UINT16                                       GuidedSectionAttributes;\r
 \r
   CORE_SECTION_CHILD_NODE                      *Node;\r
 \r
@@ -645,7 +657,11 @@ CreateChildNode (
   //\r
   Node->Signature = CORE_SECTION_CHILD_SIGNATURE;\r
   Node->Type = SectionHeader->Type;\r
-  Node->Size = SECTION_SIZE (SectionHeader);\r
+  if (IS_SECTION2 (SectionHeader)) {\r
+    Node->Size = SECTION2_SIZE (SectionHeader);\r
+  } else {\r
+    Node->Size = SECTION_SIZE (SectionHeader);\r
+  }\r
   Node->OffsetInStream = ChildOffset;\r
   Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;\r
   Node->EncapsulationGuid = NULL;\r
@@ -662,23 +678,35 @@ CreateChildNode (
 \r
       CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;\r
 \r
+      if (IS_SECTION2 (CompressionHeader)) {\r
+        CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));\r
+        CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));\r
+        UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;\r
+        CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;\r
+      } else {\r
+        CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));\r
+        CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));\r
+        UncompressedLength = CompressionHeader->UncompressedLength;\r
+        CompressionType = CompressionHeader->CompressionType;\r
+      }\r
+\r
       //\r
       // Allocate space for the new stream\r
       //\r
-      if (CompressionHeader->UncompressedLength > 0) {\r
-        NewStreamBufferSize = CompressionHeader->UncompressedLength;\r
+      if (UncompressedLength > 0) {\r
+        NewStreamBufferSize = UncompressedLength;\r
         NewStreamBuffer = AllocatePool (NewStreamBufferSize);\r
         if (NewStreamBuffer == NULL) {\r
           CoreFreePool (Node);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
 \r
-        if (CompressionHeader->CompressionType == EFI_NOT_COMPRESSED) {\r
+        if (CompressionType == EFI_NOT_COMPRESSED) {\r
           //\r
           // stream is not actually compressed, just encapsulated.  So just copy it.\r
           //\r
-          CopyMem (NewStreamBuffer, CompressionHeader + 1, NewStreamBufferSize);\r
-        } else if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION) {\r
+          CopyMem (NewStreamBuffer, CompressionSource, NewStreamBufferSize);\r
+        } else if (CompressionType == EFI_STANDARD_COMPRESSION) {\r
           //\r
           // Only support the EFI_SATNDARD_COMPRESSION algorithm.\r
           //\r
@@ -692,13 +720,13 @@ CreateChildNode (
 \r
           Status = Decompress->GetInfo (\r
                                  Decompress,\r
-                                 CompressionHeader + 1,\r
-                                 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
+                                 CompressionSource,\r
+                                 CompressionSourceSize,\r
                                  (UINT32 *)&NewStreamBufferSize,\r
                                  &ScratchSize\r
                                  );\r
           ASSERT_EFI_ERROR (Status);\r
-          ASSERT (NewStreamBufferSize == CompressionHeader->UncompressedLength);\r
+          ASSERT (NewStreamBufferSize == UncompressedLength);\r
 \r
           ScratchBuffer = AllocatePool (ScratchSize);\r
           if (ScratchBuffer == NULL) {\r
@@ -709,8 +737,8 @@ CreateChildNode (
 \r
           Status = Decompress->Decompress (\r
                                  Decompress,\r
-                                 CompressionHeader + 1,\r
-                                 Node->Size - sizeof (EFI_COMPRESSION_SECTION),\r
+                                 CompressionSource,\r
+                                 CompressionSourceSize,\r
                                  NewStreamBuffer,\r
                                  (UINT32)NewStreamBufferSize,\r
                                  ScratchBuffer,\r
@@ -740,7 +768,13 @@ CreateChildNode (
 \r
     case EFI_SECTION_GUID_DEFINED:\r
       GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;\r
-      Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
+      if (IS_SECTION2 (GuidedHeader)) {\r
+        Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);\r
+        GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;\r
+      } else {\r
+        Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
+        GuidedSectionAttributes = GuidedHeader->Attributes;\r
+      }\r
       Status = CoreLocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
       if (!EFI_ERROR (Status) && GuidedExtraction != NULL) {\r
         //\r
@@ -763,7 +797,7 @@ CreateChildNode (
         // Make sure we initialize the new stream with the correct\r
         // authentication status for both aggregate and local status fields.\r
         //\r
-        if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {\r
+        if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {\r
           //\r
           // OR in the parent stream's aggregate status.\r
           //\r
@@ -792,7 +826,7 @@ CreateChildNode (
         //\r
         // There's no GUIDed section extraction protocol available.\r
         //\r
-        if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {\r
+        if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {\r
           //\r
           // If the section REQUIRES an extraction protocol, register for RPN \r
           // when the required GUIDed extraction protocol becomes available. \r
@@ -804,14 +838,23 @@ CreateChildNode (
           //\r
           AuthenticationStatus = Stream->AuthenticationStatus;\r
 \r
-          SectionLength = SECTION_SIZE (GuidedHeader);\r
-          Status = OpenSectionStreamEx (\r
-                     SectionLength - GuidedHeader->DataOffset,\r
-                     (UINT8 *) GuidedHeader + GuidedHeader->DataOffset,\r
-                     TRUE,\r
-                     AuthenticationStatus,\r
-                     &Node->EncapsulatedStreamHandle\r
-                     );\r
+          if (IS_SECTION2 (GuidedHeader)) {\r
+            Status = OpenSectionStreamEx (\r
+                       SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,\r
+                       (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,\r
+                       TRUE,\r
+                       AuthenticationStatus,\r
+                       &Node->EncapsulatedStreamHandle\r
+                       );\r
+          } else {\r
+            Status = OpenSectionStreamEx (\r
+                       SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,\r
+                       (UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,\r
+                       TRUE,\r
+                       AuthenticationStatus,\r
+                       &Node->EncapsulatedStreamHandle\r
+                       );\r
+          }\r
           if (EFI_ERROR (Status)) {\r
             CoreFreePool (Node);\r
             return Status;\r
@@ -1075,6 +1118,7 @@ FindStreamNode (
                                 function returns anything other than\r
                                 EFI_SUCCESS, the value of *AuthenticationStatus\r
                                 is undefined.\r
+  @param  IsFfs3Fv              Indicates the FV format.\r
 \r
   @retval EFI_SUCCESS           Section was retrieved successfully\r
   @retval EFI_PROTOCOL_ERROR    A GUID defined section was encountered in the\r
@@ -1105,7 +1149,8 @@ GetSection (
   IN UINTN                                              SectionInstance,\r
   IN VOID                                               **Buffer,\r
   IN OUT UINTN                                          *BufferSize,\r
-  OUT UINT32                                            *AuthenticationStatus\r
+  OUT UINT32                                            *AuthenticationStatus,\r
+  IN BOOLEAN                                            IsFfs3Fv\r
   )\r
 {\r
   CORE_SECTION_STREAM_NODE                              *StreamNode;\r
@@ -1118,6 +1163,7 @@ GetSection (
   UINTN                                                 Instance;\r
   UINT8                                                 *CopyBuffer;\r
   UINTN                                                 SectionSize;\r
+  EFI_COMMON_SECTION_HEADER                             *Section;\r
 \r
 \r
   OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
@@ -1158,8 +1204,22 @@ GetSection (
     if (EFI_ERROR (Status)) {\r
       goto GetSection_Done;\r
     }\r
-    CopySize = ChildNode->Size - sizeof (EFI_COMMON_SECTION_HEADER);\r
-    CopyBuffer = ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream + sizeof (EFI_COMMON_SECTION_HEADER);\r
+\r
+    Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);\r
+\r
+    if (IS_SECTION2 (Section)) {\r
+      ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);\r
+      if (!IsFfs3Fv) {\r
+        DEBUG ((DEBUG_ERROR, "It is a FFS3 formatted section in a non-FFS3 formatted FV.\n"));\r
+        Status = EFI_NOT_FOUND;\r
+        goto GetSection_Done;\r
+      }\r
+      CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);\r
+      CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);\r
+    } else {\r
+      CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);\r
+      CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);\r
+    }\r
     *AuthenticationStatus = ExtractedAuthenticationStatus;\r
   }\r
 \r