]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Clean up Library LzmaCustomDecompressLib, PeiRecoveryLib and driver SectionExtraction
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 Jun 2009 08:40:49 +0000 (08:40 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 Jun 2009 08:40:49 +0000 (08:40 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8658 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h [deleted file]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/UefiLzma.h
IntelFrameworkModulePkg/Library/PeiRecoveryLib/PeiRecoveryLib.c
IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.c
IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.h [deleted file]
IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.inf

index 2444f31def3a3bea5a58db1e7bba976c3afced47..ff91600afd991008b18892359023a80adb199e36 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
-  LZMA Decompress GUIDed Section Extraction Library\r
+  LZMA Decompress GUIDed Section Extraction Library.\r
+  It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces\r
+  and registers them into GUIDed handler table.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  Copyright (c) 2009, 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
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/ExtractGuidedSectionLib.h>\r
-#include <Pi/PiFirmwareFile.h>\r
-#include <Guid/LzmaDecompress.h>\r
-\r
-#include "LzmaDecompress.h"\r
-\r
-\r
-STATIC\r
-RETURN_STATUS\r
-EFIAPI\r
-LzmaGuidedSectionGetCompressedLocation (\r
-  IN  CONST VOID  *InputSection,\r
-  OUT VOID        **LmzaCompressedData,\r
-  OUT UINT32      *LmzaCompressedDataSize   OPTIONAL\r
-  )\r
-{\r
-  if (!CompareGuid (\r
-        &gLzmaCustomDecompressGuid, \r
-        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Retrieve the size and attribute of the input section data.\r
-  //\r
-  *LmzaCompressedData =\r
-    (VOID*) (\r
-        (UINT8 *) InputSection +\r
-        ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
-      );\r
-  if (LmzaCompressedDataSize != NULL) {\r
-    *LmzaCompressedDataSize =\r
-      (UINT32)(\r
-        (\r
-          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size)) &\r
-          0x00ffffff\r
-        ) -\r
-        ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
-      );\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
+#include "LzmaDecompressLibInternal.h"\r
 \r
 /**\r
-  The implementation of 'GetInfo' for Guided Section\r
-  Extraction of LZMA compression.\r
-\r
-  @param  InputSection          Buffer containing the input GUIDed section to be processed. \r
-  @param  OutputBufferSize      The size of OutputBuffer.\r
-  @param  ScratchBufferSize     The size of ScratchBuffer.\r
-  @param  SectionAttribute      The attribute of the input guided section.\r
-\r
-  @retval RETURN_SUCCESS            The size of destination buffer and the size of scratch buffer are successull retrieved.\r
-  @retval RETURN_INVALID_PARAMETER  The source data is corrupted, or\r
-                                    The GUID in InputSection does not match this instance guid.\r
+  Examines a GUIDed section and returns the size of the decoded buffer and the\r
+  size of an scratch buffer required to actually decode the data in a GUIDed section.\r
+\r
+  Examines a GUIDed section specified by InputSection.  \r
+  If GUID for InputSection does not match the GUID that this handler supports,\r
+  then RETURN_UNSUPPORTED is returned.  \r
+  If the required information can not be retrieved from InputSection,\r
+  then RETURN_INVALID_PARAMETER is returned.\r
+  If the GUID of InputSection does match the GUID that this handler supports,\r
+  then the size required to hold the decoded buffer is returned in OututBufferSize,\r
+  the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
+  from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
+  \r
+  If InputSection is NULL, then ASSERT().\r
+  If OutputBufferSize is NULL, then ASSERT().\r
+  If ScratchBufferSize is NULL, then ASSERT().\r
+  If SectionAttribute is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]  InputSection       A pointer to a GUIDed section of an FFS formatted file.\r
+  @param[out] OutputBufferSize   A pointer to the size, in bytes, of an output buffer required\r
+                                 if the buffer specified by InputSection were decoded.\r
+  @param[out] ScratchBufferSize  A pointer to the size, in bytes, required as scratch space\r
+                                 if the buffer specified by InputSection were decoded.\r
+  @param[out] SectionAttribute   A pointer to the attributes of the GUIDed section. See the Attributes\r
+                                 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
+\r
+  @retval  RETURN_SUCCESS            The information about InputSection was returned.\r
+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.\r
+  @retval  RETURN_INVALID_PARAMETER  The information can not be retrieved from the section specified by InputSection.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -83,44 +58,58 @@ LzmaGuidedSectionGetInfo (
   OUT UINT16      *SectionAttribute\r
   )\r
 {\r
-  RETURN_STATUS Status;\r
-  VOID          *LzmaInput;\r
-  UINT32        LzmaInputSize;\r
-\r
-  Status = LzmaGuidedSectionGetCompressedLocation(\r
-    InputSection,\r
-    &LzmaInput,\r
-    &LzmaInputSize\r
-    );\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
+  ASSERT (InputSection != NULL);\r
+  ASSERT (OutputBufferSize != NULL);\r
+  ASSERT (ScratchBufferSize != NULL);\r
+  ASSERT (SectionAttribute != NULL);\r
+\r
+  if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
   *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
 \r
   return LzmaUefiDecompressGetInfo (\r
-    LzmaInput,\r
-    LzmaInputSize,\r
-    OutputBufferSize,\r
-    ScratchBufferSize\r
-    );\r
+          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+          OutputBufferSize,\r
+          ScratchBufferSize\r
+          );\r
 }\r
 \r
 /**\r
-  The implementation of Guided Section Extraction\r
-  for LZMA compression.\r
-\r
-  @param  InputSection          Buffer containing the input GUIDed section to be processed. \r
-  @param  OutputBuffer          OutputBuffer to point to the start of the section's contents.\r
-                                if guided data is not prcessed. Otherwise,\r
-                                OutputBuffer to contain the output data, which is allocated by the caller.\r
-  @param  ScratchBuffer         A pointer to a caller-allocated buffer for function internal use. \r
-  @param  AuthenticationStatus  A pointer to a caller-allocated UINT32 that indicates the\r
-                                authentication status of the output buffer. \r
-\r
-  @retval RETURN_SUCCESS            Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER  The source data is corrupted, or\r
-                                    The GUID in InputSection does not match this instance guid.\r
+  Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.\r
+  \r
+  Decodes the GUIDed section specified by InputSection.  \r
+  If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.  \r
+  If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
+  If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
+  is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
+  decode operation is returned in AuthenticationStatus.  If the decoded buffer is identical to the\r
+  data in InputSection, then OutputBuffer is set to point at the data in InputSection.  Otherwise,\r
+  the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
+  \r
+  If InputSection is NULL, then ASSERT().\r
+  If OutputBuffer is NULL, then ASSERT().\r
+  If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
+  If AuthenticationStatus is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]  InputSection  A pointer to a GUIDed section of an FFS formatted file.\r
+  @param[out] OutputBuffer  A pointer to a buffer that contains the result of a decode operation. \r
+  @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
+                            as a scratch buffer to perform the decode operation. \r
+  @param[out] AuthenticationStatus \r
+                            A pointer to the authentication status of the decoded output buffer.\r
+                            See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
+                            section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
+                            never be set by this handler.\r
+\r
+  @retval  RETURN_SUCCESS            The buffer specified by InputSection was decoded.\r
+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.\r
+  @retval  RETURN_INVALID_PARAMETER  The section specified by InputSection can not be decoded.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -128,20 +117,17 @@ EFIAPI
 LzmaGuidedSectionExtraction (\r
   IN CONST  VOID    *InputSection,\r
   OUT       VOID    **OutputBuffer,\r
-  IN        VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       VOID    *ScratchBuffer,        OPTIONAL\r
   OUT       UINT32  *AuthenticationStatus\r
   )\r
 {\r
-  RETURN_STATUS Status;\r
-  VOID          *LzmaInput;\r
+  ASSERT (OutputBuffer != NULL);\r
+  ASSERT (InputSection != NULL);\r
 \r
-  Status = LzmaGuidedSectionGetCompressedLocation(\r
-    InputSection,\r
-    &LzmaInput,\r
-    NULL\r
-    );\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
+  if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
   //\r
@@ -150,7 +136,7 @@ LzmaGuidedSectionExtraction (
   *AuthenticationStatus = 0;\r
 \r
   return LzmaUefiDecompress (\r
-    LzmaInput,\r
+    (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
     *OutputBuffer,\r
     ScratchBuffer\r
     );\r
@@ -158,7 +144,7 @@ LzmaGuidedSectionExtraction (
 \r
 \r
 /**\r
-  Register LzmaDecompress handler.\r
+  Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.\r
 \r
   @retval  RETURN_SUCCESS            Register successfully.\r
   @retval  RETURN_OUT_OF_RESOURCES   No enough memory to store this handler.\r
index ebf8b9de18443e205372ec7ddb77e2ad0308b942..a55ddef1c898084c8530c9335e777f7cb9bcece8 100644 (file)
@@ -1,8 +1,11 @@
 #/** @file\r
-# LZMA GUIDed Section Extraction Protocol Library\r
+#  LzmaCustomDecompressLib produces LZMA custom decompression algorithm.\r
 #\r
-# Uefi Decompression library instance\r
-# Copyright (c) 2006, 2009, Intel Corporation.\r
+#  It is based on the LZMA SDK 4.65.\r
+#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.  \r
+#  It was released on the http://www.7-zip.org/sdk.html website.\r
+#\r
+#  Copyright (c) 2009, Intel Corporation.\r
 #\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
@@ -21,9 +24,6 @@
   MODULE_TYPE                    = BASE\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = BASE\r
-  EDK_RELEASE_VERSION            = 0x00020000\r
-  EFI_SPECIFICATION_VERSION      = 0x00020000\r
-\r
   CONSTRUCTOR                    = LzmaDecompressLibConstructor\r
 \r
 #\r
   Sdk/C/LzFind.c\r
   Sdk/C/LzmaDec.c\r
   GuidedSectionExtraction.c\r
+  UefiLzma.h\r
+  LzmaDecompressLibInternal.h\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
 \r
 [Guids]\r
-  gLzmaCustomDecompressGuid \r
+  gLzmaCustomDecompressGuid  ## PRODUCED  ## GUID specifies LZMA custom decompress algorithm.\r
 \r
 [LibraryClasses]\r
   BaseLib\r
index 8497440f3f602b9ea4641f7c16e6cf9833521bb1..b8523f4b4fe2a227a7cabaafe7df39bc5f98146f 100644 (file)
@@ -1,11 +1,7 @@
 /** @file\r
-  LZMA Decompress routines for edk2\r
+  LZMA Decompress interfaces\r
 \r
-  Portions based on LZMA SDK 4.65:\r
-    LzmaUtil.c -- Test application for LZMA compression\r
-    2008-11-23 : Igor Pavlov : Public domain\r
-\r
-  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  Copyright (c) 2009, 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
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiDecompressLib.h>\r
-#include <Library/ExtractGuidedSectionLib.h>\r
-#include <Guid/LzmaDecompress.h>\r
-\r
+#include "LzmaDecompressLibInternal.h"\r
 #include "Sdk/C/Types.h"\r
 #include "Sdk/C/7zVersion.h"\r
 #include "Sdk/C/LzmaDec.h"\r
 // Global data\r
 //\r
 \r
-STATIC CONST VOID  *mSourceLastUsedWithGetInfo;\r
-STATIC UINT32      mSizeOfLastSource;\r
-STATIC UINT32      mDecompressedSizeForLastSource;\r
-STATIC VOID        *mScratchBuffer;\r
-STATIC UINTN       mScratchBufferSize;\r
+CONST VOID  *mSourceLastUsedWithGetInfo;\r
+UINT32      mSizeOfLastSource;\r
+UINT32      mDecompressedSizeForLastSource;\r
+VOID        *mScratchBuffer;\r
+UINTN       mScratchBufferSize;\r
+\r
 #define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB\r
 \r
 /**\r
   Allocation routine used by LZMA decompression.\r
 \r
-  @param p                Pointer to the ISzAlloc instance\r
-  @param size             The size in bytes to be allocated\r
+  @param P                Pointer to the ISzAlloc instance\r
+  @param Size             The size in bytes to be allocated\r
 \r
   @return The allocated pointer address, or NULL on failure\r
 **/\r
-STATIC\r
 VOID *\r
 SzAlloc (\r
-  void *p,\r
-  size_t size\r
+  VOID *P,\r
+  size_t Size\r
   )\r
 {\r
-  VOID *addr;\r
+  VOID *Addr;\r
 \r
-  if (mScratchBufferSize >= size) {\r
-    addr = mScratchBuffer;\r
-    mScratchBuffer = (VOID*) ((UINT8*)addr + size);\r
-    mScratchBufferSize -= size;\r
-    return addr;\r
+  if (mScratchBufferSize >= Size) {\r
+    Addr = mScratchBuffer;\r
+    mScratchBuffer = (VOID*) ((UINT8*)Addr + Size);\r
+    mScratchBufferSize -= Size;\r
+    return Addr;\r
   } else {\r
     ASSERT (FALSE);\r
     return NULL;\r
@@ -70,14 +59,13 @@ SzAlloc (
 /**\r
   Free routine used by LZMA decompression.\r
 \r
-  @param p                Pointer to the ISzAlloc instance\r
-  @param address          The address to be freed\r
+  @param P                Pointer to the ISzAlloc instance\r
+  @param Address          The address to be freed\r
 **/\r
-STATIC\r
 VOID\r
 SzFree (\r
-  void *p,\r
-  void *address\r
+  VOID *P,\r
+  VOID *Address\r
   )\r
 {\r
   //\r
@@ -91,10 +79,16 @@ STATIC ISzAlloc g_Alloc = { SzAlloc, SzFree };
 \r
 #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)\r
 \r
-STATIC\r
+/**\r
+  Get the size of the uncompressed buffer by parsing EncodeData header.\r
+\r
+  @param EncodedData  Pointer to the compressed data.\r
+\r
+  @return The size of the uncompressed buffer.\r
+**/\r
 UINT64\r
 GetDecodedSizeOfBuf(\r
-  UINT8 *encodedData\r
+  UINT8 *EncodedData\r
   )\r
 {\r
   UINT64 DecodedSize;\r
@@ -103,25 +97,44 @@ GetDecodedSizeOfBuf(
   /* Parse header */\r
   DecodedSize = 0;\r
   for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--)\r
-    DecodedSize = LShiftU64(DecodedSize, 8) + encodedData[Index];\r
+    DecodedSize = LShiftU64(DecodedSize, 8) + EncodedData[Index];\r
 \r
   return DecodedSize;\r
 }\r
 \r
 //\r
-// LZMA functions and data as defined in local LzmaDecompress.h\r
+// LZMA functions and data as defined in local LzmaDecompressLibInternal.h\r
 //\r
 \r
 /**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
-  \r
-  @param Source           The source buffer containing the compressed data.\r
-  @param SourceSize       The size of source buffer\r
-  @param DestinationSize  The size of destination buffer.\r
-  @param ScratchSize      The size of scratch buffer.\r
-\r
-  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
+  Given a Lzma compressed source buffer, this function retrieves the size of \r
+  the uncompressed buffer and the size of the scratch buffer required \r
+  to decompress the compressed source buffer.\r
+\r
+  Retrieves the size of the uncompressed buffer and the temporary scratch buffer \r
+  required to decompress the buffer specified by Source and SourceSize.\r
+  The size of the uncompressed buffer is returned in DestinationSize, \r
+  the size of the scratch buffer is returned in ScratchSize, and RETURN_SUCCESS is returned.\r
+  This function does not have scratch buffer available to perform a thorough \r
+  checking of the validity of the source data. It just retrieves the "Original Size"\r
+  field from the LZMA_HEADER_SIZE beginning bytes of the source data and output it as DestinationSize.\r
+  And ScratchSize is specific to the decompression implementation.\r
+\r
+  If SourceSize is less than LZMA_HEADER_SIZE, then ASSERT().\r
+\r
+  @param  Source          The source buffer containing the compressed data.\r
+  @param  SourceSize      The size, in bytes, of the source buffer.\r
+  @param  DestinationSize A pointer to the size, in bytes, of the uncompressed buffer\r
+                          that will be generated when the compressed buffer specified\r
+                          by Source and SourceSize is decompressed.\r
+  @param  ScratchSize     A pointer to the size, in bytes, of the scratch buffer that\r
+                          is required to decompress the compressed buffer specified \r
+                          by Source and SourceSize.\r
+\r
+  @retval  RETURN_SUCCESS The size of the uncompressed data was returned \r
+                          in DestinationSize and the size of the scratch \r
+                          buffer was returned in ScratchSize.\r
+\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -148,14 +161,25 @@ LzmaUefiDecompressGetInfo (
 \r
 \r
 /**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
-  \r
-  @param Source          - The source buffer containing the compressed data.\r
-  @param Destination     - The destination buffer to store the decompressed data\r
-  @param Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
-\r
-  @retval RETURN_SUCCESS           - Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted  \r
+  Decompresses a Lzma compressed source buffer.\r
+\r
+  Extracts decompressed data to its original form.\r
+  If the compressed source data specified by Source is successfully decompressed \r
+  into Destination, then RETURN_SUCCESS is returned.  If the compressed source data \r
+  specified by Source is not in a valid compressed data format,\r
+  then RETURN_INVALID_PARAMETER is returned.\r
+\r
+  @param  Source      The source buffer containing the compressed data.\r
+  @param  Destination The destination buffer to store the decompressed data\r
+  @param  Scratch     A temporary scratch buffer that is used to perform the decompression.\r
+                      This is an optional parameter that may be NULL if the \r
+                      required scratch buffer size is 0.\r
+                     \r
+  @retval  RETURN_SUCCESS Decompression completed successfully, and \r
+                          the uncompressed buffer is returned in Destination.\r
+  @retval  RETURN_INVALID_PARAMETER \r
+                          The source buffer specified by Source is corrupted \r
+                          (not in a valid compressed format).\r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
@@ -165,34 +189,34 @@ LzmaUefiDecompress (
   IN OUT VOID    *Scratch\r
   )\r
 {\r
-  SRes        lzmaResult;\r
-  ELzmaStatus status;\r
-  SizeT       decodedBufSize;\r
-  SizeT       encodedDataSize;\r
+  SRes        LzmaResult;\r
+  ELzmaStatus Status;\r
+  SizeT       DecodedBufSize;\r
+  SizeT       EncodedDataSize;\r
 \r
   if (Source != mSourceLastUsedWithGetInfo) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  decodedBufSize = (SizeT)mDecompressedSizeForLastSource;\r
-  encodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);\r
+  DecodedBufSize = (SizeT)mDecompressedSizeForLastSource;\r
+  EncodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);\r
 \r
   mScratchBuffer = Scratch;\r
   mScratchBufferSize = SCRATCH_BUFFER_REQUEST_SIZE;\r
 \r
-  lzmaResult = LzmaDecode(\r
+  LzmaResult = LzmaDecode(\r
     Destination,\r
-    &decodedBufSize,\r
+    &DecodedBufSize,\r
     (Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),\r
-    &encodedDataSize,\r
+    &EncodedDataSize,\r
     Source,\r
     LZMA_PROPS_SIZE,\r
     LZMA_FINISH_END,\r
-    &status,\r
+    &Status,\r
     &g_Alloc\r
     );\r
 \r
-  if (lzmaResult == SZ_OK) {\r
+  if (LzmaResult == SZ_OK) {\r
     return RETURN_SUCCESS;\r
   } else {\r
     return RETURN_INVALID_PARAMETER;\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h
deleted file mode 100644 (file)
index fbf645e..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/** @file\r
-  LZMA Decompress Library header file\r
-\r
-  Copyright (c) 2006 - 2009, 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
-#ifndef __LZMADECOMPRESS_H__\r
-#define __LZMADECOMPRESS_H__\r
-\r
-/**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
-  \r
-  @param Source           The source buffer containing the compressed data.\r
-  @param SourceSize       The size of source buffer\r
-  @param DestinationSize  The size of destination buffer.\r
-  @param ScratchSize      The size of scratch buffer.\r
-\r
-  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-LzmaUefiDecompressGetInfo (\r
-  IN  CONST VOID  *Source,\r
-  IN  UINT32      SourceSize,\r
-  OUT UINT32      *DestinationSize,\r
-  OUT UINT32      *ScratchSize\r
-  );\r
-\r
-/**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
-  \r
-  @param Source          - The source buffer containing the compressed data.\r
-  @param Destination     - The destination buffer to store the decompressed data\r
-  @param Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
-\r
-  @retval RETURN_SUCCESS           - Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted  \r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-LzmaUefiDecompress (\r
-  IN CONST VOID  *Source,\r
-  IN OUT VOID    *Destination,\r
-  IN OUT VOID    *Scratch\r
-  );\r
-\r
-#endif // __LZMADECOMPRESS_H__\r
-\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h
new file mode 100644 (file)
index 0000000..cc632a2
--- /dev/null
@@ -0,0 +1,94 @@
+/** @file\r
+  LZMA Decompress Library internal header file declares Lzma decompress interfaces.\r
+\r
+  Copyright (c) 2009, 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
+#ifndef __LZMADECOMPRESSLIB_INTERNAL_H__\r
+#define __LZMADECOMPRESSLIB_INTERNAL_H__\r
+\r
+#include <PiPei.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Guid/LzmaDecompress.h>\r
+\r
+/**\r
+  Given a Lzma compressed source buffer, this function retrieves the size of \r
+  the uncompressed buffer and the size of the scratch buffer required \r
+  to decompress the compressed source buffer.\r
+\r
+  Retrieves the size of the uncompressed buffer and the temporary scratch buffer \r
+  required to decompress the buffer specified by Source and SourceSize.\r
+  The size of the uncompressed buffer is returned in DestinationSize, \r
+  the size of the scratch buffer is returned in ScratchSize, and RETURN_SUCCESS is returned.\r
+  This function does not have scratch buffer available to perform a thorough \r
+  checking of the validity of the source data. It just retrieves the "Original Size"\r
+  field from the LZMA_HEADER_SIZE beginning bytes of the source data and output it as DestinationSize.\r
+  And ScratchSize is specific to the decompression implementation.\r
+\r
+  If SourceSize is less than LZMA_HEADER_SIZE, then ASSERT().\r
+\r
+  @param  Source          The source buffer containing the compressed data.\r
+  @param  SourceSize      The size, in bytes, of the source buffer.\r
+  @param  DestinationSize A pointer to the size, in bytes, of the uncompressed buffer\r
+                          that will be generated when the compressed buffer specified\r
+                          by Source and SourceSize is decompressed.\r
+  @param  ScratchSize     A pointer to the size, in bytes, of the scratch buffer that\r
+                          is required to decompress the compressed buffer specified \r
+                          by Source and SourceSize.\r
+\r
+  @retval  RETURN_SUCCESS The size of the uncompressed data was returned \r
+                          in DestinationSize and the size of the scratch \r
+                          buffer was returned in ScratchSize.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompressGetInfo (\r
+  IN  CONST VOID  *Source,\r
+  IN  UINT32      SourceSize,\r
+  OUT UINT32      *DestinationSize,\r
+  OUT UINT32      *ScratchSize\r
+  );\r
+\r
+/**\r
+  Decompresses a Lzma compressed source buffer.\r
+\r
+  Extracts decompressed data to its original form.\r
+  If the compressed source data specified by Source is successfully decompressed \r
+  into Destination, then RETURN_SUCCESS is returned.  If the compressed source data \r
+  specified by Source is not in a valid compressed data format,\r
+  then RETURN_INVALID_PARAMETER is returned.\r
+\r
+  @param  Source      The source buffer containing the compressed data.\r
+  @param  Destination The destination buffer to store the decompressed data\r
+  @param  Scratch     A temporary scratch buffer that is used to perform the decompression.\r
+                      This is an optional parameter that may be NULL if the \r
+                      required scratch buffer size is 0.\r
+                     \r
+  @retval  RETURN_SUCCESS Decompression completed successfully, and \r
+                          the uncompressed buffer is returned in Destination.\r
+  @retval  RETURN_INVALID_PARAMETER \r
+                          The source buffer specified by Source is corrupted \r
+                          (not in a valid compressed format).\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompress (\r
+  IN CONST VOID  *Source,\r
+  IN OUT VOID    *Destination,\r
+  IN OUT VOID    *Scratch\r
+  );\r
+\r
+#endif\r
+\r
index fdd013c5e36a716bef3aa63b1564829438fa4d93..b4fd6c75e6fc9134b987c3e09ee4f2c52c816f17 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-  LZMA UEFI Library header file\r
+  LZMA UEFI header file\r
 \r
   Allows LZMA code to build under UEFI (edk2) build environment\r
 \r
index 5668130c9543d1f62d1edb07a092018f235334a0..63233e601f0feb8045518202761b5bab2ae17a80 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-  This Library uses Framework RecoveryModule PPI to system recovery.\r
+  This Library uses Framework RecoveryModule PPI to do system recovery.\r
 \r
 Copyright (c) 2006 - 2009 Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
index 51fd75933113008f2623edec0f294291e64cb362..f08577cf280d5820c80d513a7d352cfbdc859a73 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 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009, 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
@@ -38,54 +38,70 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include "SectionExtraction.h"\r
+#include <FrameworkDxe.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Protocol/Decompress.h>\r
+#include <Protocol/GuidedSectionExtraction.h>\r
+#include <Protocol/SectionExtraction.h>\r
 \r
 //\r
-// Module globals\r
+// Local defines and typedefs\r
 //\r
-LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);\r
-\r
-EFI_HANDLE mSectionExtractionHandle = NULL;\r
-\r
-EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = { \r
-  OpenSectionStream, \r
-  GetSection, \r
-  CloseSectionStream\r
-};\r
-\r
-/**\r
-  Entry point of the section extraction code. Initializes an instance of the \r
-  section extraction interface and installs it on a new handle.\r
-\r
-  @param ImageHandle             A handle for the image that is initializing this driver\r
-  @param SystemTable             A pointer to the EFI system table        \r
-\r
-  @retval EFI_SUCCESS            Driver initialized successfully\r
-  @retval EFI_OUT_OF_RESOURCES   Could not allocate needed resources\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SectionExtractionEntryPoint (\r
-  IN EFI_HANDLE                   ImageHandle,\r
-  IN EFI_SYSTEM_TABLE             *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS                         Status;\r
-\r
+#define FRAMEWORK_SECTION_CHILD_SIGNATURE  SIGNATURE_32('S','X','F','S')\r
+#define CHILD_SECTION_NODE_FROM_LINK(Node) \\r
+  CR (Node, FRAMEWORK_SECTION_CHILD_NODE, Link, FRAMEWORK_SECTION_CHILD_SIGNATURE)\r
+\r
+typedef struct {\r
+  UINT32                      Signature;\r
+  LIST_ENTRY                  Link;\r
+  UINT32                      Type;\r
+  UINT32                      Size;\r
   //\r
-  // Install SEP to a new handle\r
+  // StreamBase + OffsetInStream == pointer to section header in stream.  The\r
+  // stream base is always known when walking the sections within.\r
   //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &mSectionExtractionHandle,\r
-                  &gEfiSectionExtractionProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &mSectionExtraction\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  UINT32                      OffsetInStream;\r
+  //\r
+  // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an\r
+  // encapsulating section.  Otherwise, it contains the stream handle\r
+  // of the encapsulated stream.  This handle is ALWAYS produced any time an\r
+  // encapsulating child is encountered, irrespective of whether the\r
+  // encapsulated stream is processed further.\r
+  //\r
+  UINTN                       EncapsulatedStreamHandle;\r
+  EFI_GUID                    *EncapsulationGuid;\r
+} FRAMEWORK_SECTION_CHILD_NODE;\r
+\r
+#define FRAMEWORK_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')\r
+#define STREAM_NODE_FROM_LINK(Node) \\r
+  CR (Node, FRAMEWORK_SECTION_STREAM_NODE, Link, FRAMEWORK_SECTION_STREAM_SIGNATURE)\r
+\r
+typedef struct {\r
+  UINT32                      Signature;\r
+  LIST_ENTRY                  Link;\r
+  UINTN                       StreamHandle;\r
+  UINT8                       *StreamBuffer;\r
+  UINTN                       StreamLength;\r
+  LIST_ENTRY                  Children;\r
+  //\r
+  // Authentication status is from GUIDed encapsulations.\r
+  //\r
+  UINT32                      AuthenticationStatus;\r
+} FRAMEWORK_SECTION_STREAM_NODE;\r
 \r
-  return Status;\r
-}\r
+#define NULL_STREAM_HANDLE    0\r
+\r
+typedef struct {\r
+  FRAMEWORK_SECTION_CHILD_NODE     *ChildNode;\r
+  FRAMEWORK_SECTION_STREAM_NODE    *ParentStream;\r
+  VOID                             *Registration;\r
+  EFI_EVENT                        Event;\r
+} RPN_EVENT_CONTEXT;\r
 \r
 /**\r
   SEP member function.  This function creates and returns a new section stream\r
@@ -111,23 +127,8 @@ OpenSectionStream (
   IN     VOID                                      *SectionStream,\r
      OUT UINTN                                     *SectionStreamHandle\r
   )\r
-{\r
-  //\r
-  // Check to see section stream looks good...\r
-  //\r
-  if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  return OpenSectionStreamEx ( \r
-          SectionStreamLength, \r
-          SectionStream,\r
-          TRUE,\r
-          0,\r
-          SectionStreamHandle\r
-          );\r
-}\r
-  \r
+;\r
+\r
 /**\r
   SEP member function.  Retrieves requested section from section stream.\r
 \r
@@ -183,88 +184,7 @@ GetSection (
   IN OUT UINTN                                          *BufferSize,\r
   OUT UINT32                                            *AuthenticationStatus\r
   )\r
-{\r
-  CORE_SECTION_STREAM_NODE                              *StreamNode;\r
-  EFI_TPL                                               OldTpl;\r
-  EFI_STATUS                                            Status;\r
-  CORE_SECTION_CHILD_NODE                               *ChildNode;\r
-  CORE_SECTION_STREAM_NODE                              *ChildStreamNode;\r
-  UINTN                                                 CopySize;\r
-  UINT32                                                ExtractedAuthenticationStatus;\r
-  UINTN                                                 Instance;\r
-  UINT8                                                 *CopyBuffer;\r
-  UINTN                                                 SectionSize;\r
-  \r
-\r
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-  Instance = SectionInstance + 1;\r
-  \r
-  //\r
-  // Locate target stream\r
-  //\r
-  Status = FindStreamNode (SectionStreamHandle, &StreamNode);\r
-  if (EFI_ERROR (Status)) {\r
-    Status = EFI_INVALID_PARAMETER;\r
-    goto GetSection_Done;\r
-  }\r
-  \r
-  //\r
-  // Found the stream, now locate and return the appropriate section\r
-  //\r
-  if (SectionType == NULL) {\r
-    //\r
-    // SectionType == NULL means return the WHOLE section stream...\r
-    //\r
-    CopySize = StreamNode->StreamLength;\r
-    CopyBuffer = StreamNode->StreamBuffer;\r
-    *AuthenticationStatus = StreamNode->AuthenticationStatus;\r
-  } else {\r
-    //\r
-    // There's a requested section type, so go find it and return it...\r
-    //\r
-    Status = FindChildNode (\r
-                      StreamNode, \r
-                      *SectionType, \r
-                      &Instance, \r
-                      SectionDefinitionGuid,\r
-                      &ChildNode,\r
-                      &ChildStreamNode, \r
-                      &ExtractedAuthenticationStatus\r
-                      );\r
-    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
-    *AuthenticationStatus = ExtractedAuthenticationStatus;\r
-  }   \r
-    \r
-  SectionSize = CopySize;  \r
-  if (*Buffer != NULL) {\r
-    //\r
-    // Caller allocated buffer.  Fill to size and return required size...\r
-    //\r
-    if (*BufferSize < CopySize) {\r
-      Status = EFI_WARN_BUFFER_TOO_SMALL;\r
-      CopySize = *BufferSize;\r
-    }\r
-  } else {\r
-    //\r
-    // Callee allocated buffer.  Allocate buffer and return size.\r
-    //\r
-    *Buffer = AllocatePool (CopySize);\r
-    if (*Buffer == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
-      goto GetSection_Done;\r
-    }\r
-  }\r
-  CopyMem (*Buffer, CopyBuffer, CopySize);\r
-  *BufferSize = SectionSize;\r
-  \r
-GetSection_Done:\r
-  gBS->RestoreTPL (OldTpl);\r
-  return Status;\r
-}\r
+;\r
 \r
 /**\r
   SEP member function.  Deletes an existing section stream\r
@@ -284,282 +204,492 @@ CloseSectionStream (
   IN  EFI_SECTION_EXTRACTION_PROTOCOL           *This,\r
   IN  UINTN                                     StreamHandleToClose\r
   )\r
+;\r
+\r
+//\r
+// Module globals\r
+//\r
+LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);\r
+\r
+EFI_HANDLE mSectionExtractionHandle = NULL;\r
+\r
+EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = { \r
+  OpenSectionStream, \r
+  GetSection, \r
+  CloseSectionStream\r
+};\r
+\r
+/**\r
+  Entry point of the section extraction code. Initializes an instance of the \r
+  section extraction interface and installs it on a new handle.\r
+\r
+  @param ImageHandle             A handle for the image that is initializing this driver\r
+  @param SystemTable             A pointer to the EFI system table        \r
+\r
+  @retval EFI_SUCCESS            Driver initialized successfully\r
+  @retval EFI_OUT_OF_RESOURCES   Could not allocate needed resources\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SectionExtractionEntryPoint (\r
+  IN EFI_HANDLE                   ImageHandle,\r
+  IN EFI_SYSTEM_TABLE             *SystemTable\r
+  )\r
 {\r
-  CORE_SECTION_STREAM_NODE                      *StreamNode;\r
-  EFI_TPL                                       OldTpl;\r
-  EFI_STATUS                                    Status;\r
-  LIST_ENTRY                                    *Link;\r
-  CORE_SECTION_CHILD_NODE                       *ChildNode;\r
-  \r
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-  \r
+  EFI_STATUS                         Status;\r
+\r
   //\r
-  // Locate target stream\r
+  // Install SEP to a new handle\r
   //\r
-  Status = FindStreamNode (StreamHandleToClose, &StreamNode);\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Found the stream, so close it\r
-    //\r
-    RemoveEntryList (&StreamNode->Link);\r
-    while (!IsListEmpty (&StreamNode->Children)) {\r
-      Link = GetFirstNode (&StreamNode->Children);\r
-      ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);\r
-      FreeChildNode (ChildNode);\r
-    }\r
-    gBS->FreePool (StreamNode->StreamBuffer);\r
-    gBS->FreePool (StreamNode);\r
-    Status = EFI_SUCCESS;\r
-  } else {\r
-    Status = EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  gBS->RestoreTPL (OldTpl);\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &mSectionExtractionHandle,\r
+                  &gEfiSectionExtractionProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mSectionExtraction\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r
 /**\r
-  Worker function.  Determine if the input stream:child matches the input type.\r
 \r
-  @param Stream                 Indicates the section stream associated with the child\r
-  @param Child                  Indicates the child to check\r
-  @param SearchType             Indicates the type of section to check against for\r
-  @param SectionDefinitionGuid  Indicates the GUID to check against if the type is\r
-                                EFI_SECTION_GUID_DEFINED\r
+  Check if a stream is valid.\r
 \r
-  @retval TRUE                  The child matches\r
-  @retval FALSE                 The child doesn't match\r
+  @param SectionStream         The section stream to be checked\r
+  @param SectionStreamLength   The length of section stream\r
+\r
+  @return A boolean value indicating the validness of the section stream.\r
 \r
 **/\r
 BOOLEAN\r
-ChildIsType (\r
-  IN CORE_SECTION_STREAM_NODE *Stream,\r
-  IN CORE_SECTION_CHILD_NODE  *Child,\r
-  IN EFI_SECTION_TYPE         SearchType,\r
-  IN EFI_GUID                 *SectionDefinitionGuid\r
+IsValidSectionStream (\r
+  IN  VOID              *SectionStream,\r
+  IN  UINTN             SectionStreamLength\r
   )\r
 {\r
-  EFI_GUID_DEFINED_SECTION    *GuidedSection;\r
-  \r
-  if (SearchType == EFI_SECTION_ALL) {\r
-    return TRUE;\r
-  }\r
-  if (Child->Type != SearchType) {\r
-    return FALSE;\r
-  }\r
-  if (SearchType != EFI_SECTION_GUID_DEFINED) {\r
-    return TRUE;\r
-  }\r
-  GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);\r
-  return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
-}\r
-\r
-/**\r
-  Worker function  Recursively searches / builds section stream database\r
-  looking for requested section.\r
+  UINTN                       TotalLength;\r
+  UINTN                       SectionLength;\r
+  EFI_COMMON_SECTION_HEADER   *SectionHeader;\r
+  EFI_COMMON_SECTION_HEADER   *NextSectionHeader;\r
 \r
+  TotalLength = 0;\r
+  SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
+  \r
+  while (TotalLength < SectionStreamLength) {\r
+    SectionLength = SECTION_SIZE (SectionHeader);\r
+    TotalLength += SectionLength;\r
 \r
-  @param SourceStream          Indicates the section stream in which to do the search.\r
-  @param SearchType            Indicates the type of section to search for.\r
-  @param SectionInstance       Indicates which instance of section to find.  This is\r
-                               an in/out parameter to deal with recursions.\r
-  @param SectionDefinitionGuid Guid of section definition\r
-  @param FoundChild            Output indicating the child node that is found.\r
-  @param FoundStream           Output indicating which section stream the child was\r
-                               found in.  If this stream was generated as a result of\r
-                               an encapsulation section, the streamhandle is visible\r
-                               within the SEP driver only.\r
-  @param AuthenticationStatus  Indicates the authentication status of the found section.\r
+    if (TotalLength == SectionStreamLength) {\r
+      return TRUE;    \r
+    }\r
 \r
-  @retval EFI_SUCCESS          Child node was found and returned.\r
-  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
-  @retval EFI_NOT_FOUND        Requested child node does not exist.\r
-  @retval EFI_PROTOCOL_ERROR   A required GUIDED section extraction protocol does not\r
-                               exist\r
+    //\r
+    // Move to the next byte following the section...\r
+    //\r
+    SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);\r
+    \r
+    //\r
+    // Figure out where the next section begins\r
+    //\r
+    NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);\r
+    TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;\r
+    SectionHeader = NextSectionHeader;\r
+  }\r
+\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Worker function.  Constructor for section streams.\r
+\r
+  @param SectionStreamLength   Size in bytes of the section stream.\r
+  @param SectionStream         Buffer containing the new section stream.\r
+  @param AllocateBuffer        Indicates whether the stream buffer is to be copied\r
+                               or the input buffer is to be used in place.\r
+  @param AuthenticationStatus  Indicates the default authentication status for the\r
+                               new stream.\r
+  @param SectionStreamHandle   A pointer to a caller allocated section stream handle.\r
+\r
+  @retval EFI_SUCCESS           Stream was added to stream database.\r
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
 \r
 **/\r
 EFI_STATUS\r
-FindChildNode (\r
-  IN     CORE_SECTION_STREAM_NODE                   *SourceStream,\r
-  IN     EFI_SECTION_TYPE                           SearchType,\r
-  IN OUT UINTN                                      *SectionInstance,\r
-  IN     EFI_GUID                                   *SectionDefinitionGuid,\r
-  OUT    CORE_SECTION_CHILD_NODE                    **FoundChild,\r
-  OUT    CORE_SECTION_STREAM_NODE                   **FoundStream,\r
-  OUT    UINT32                                     *AuthenticationStatus\r
+OpenSectionStreamEx (\r
+  IN     UINTN                                     SectionStreamLength,\r
+  IN     VOID                                      *SectionStream,\r
+  IN     BOOLEAN                                   AllocateBuffer,\r
+  IN     UINT32                                    AuthenticationStatus,   \r
+     OUT UINTN                                     *SectionStreamHandle\r
   )\r
 {\r
-  CORE_SECTION_CHILD_NODE                       *CurrentChildNode;\r
-  CORE_SECTION_CHILD_NODE                       *RecursedChildNode;\r
-  CORE_SECTION_STREAM_NODE                      *RecursedFoundStream;\r
-  UINT32                                        NextChildOffset;\r
-  EFI_STATUS                                    ErrorStatus;\r
-  EFI_STATUS                                    Status;\r
-  \r
-  CurrentChildNode = NULL;\r
-  ErrorStatus = EFI_NOT_FOUND;\r
+  FRAMEWORK_SECTION_STREAM_NODE    *NewStream;\r
+  EFI_TPL                     OldTpl;\r
   \r
-  if (SourceStream->StreamLength == 0) {\r
-    return EFI_NOT_FOUND;\r
+  //\r
+  // Allocate a new stream\r
+  //\r
+  NewStream = AllocatePool (sizeof (FRAMEWORK_SECTION_STREAM_NODE));\r
+  if (NewStream == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
   \r
-  if (IsListEmpty (&SourceStream->Children) && \r
-                   SourceStream->StreamLength > sizeof (EFI_COMMON_SECTION_HEADER)) {\r
+  if (AllocateBuffer) { \r
     //\r
-    // This occurs when a section stream exists, but no child sections\r
-    // have been parsed out yet.  Therefore, extract the first child and add it\r
-    // to the list of children so we can get started.\r
+    // if we're here, we're double buffering, allocate the buffer and copy the\r
+    // data in\r
     //\r
-    Status = CreateChildNode (SourceStream, 0, &CurrentChildNode);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-  \r
-  //\r
-  // At least one child has been parsed out of the section stream.  So, walk\r
-  // through the sections that have already been parsed out looking for the\r
-  // requested section, if necessary, continue parsing section stream and\r
-  // adding children until either the requested section is found, or we run\r
-  // out of data\r
-  //\r
-  CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));\r
-\r
-  for (;;) {\r
-    if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {\r
-      //\r
-      // The type matches, so check the instance count to see if it's the one we want\r
-      //\r
-      (*SectionInstance)--;\r
-      if (*SectionInstance == 0) {\r
-        //\r
-        // Got it!\r
-        //\r
-        *FoundChild = CurrentChildNode;\r
-        *FoundStream = SourceStream;\r
-        *AuthenticationStatus = SourceStream->AuthenticationStatus;\r
-        return EFI_SUCCESS;\r
-      }\r
-    }\r
-    \r
-    if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
-      //\r
-      // If the current node is an encapsulating node, recurse into it...\r
-      //\r
-      Status = FindChildNode (\r
-                (CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,\r
-                SearchType,\r
-                SectionInstance,\r
-                SectionDefinitionGuid,\r
-                &RecursedChildNode,\r
-                &RecursedFoundStream,\r
-                AuthenticationStatus\r
-                );\r
-      //\r
-      // If the status is not EFI_SUCCESS, just save the error code and continue\r
-      // to find the request child node in the rest stream.\r
-      //\r
-      if (*SectionInstance == 0) {\r
-        ASSERT_EFI_ERROR (Status);\r
-        *FoundChild = RecursedChildNode;\r
-        *FoundStream = RecursedFoundStream;\r
-        return EFI_SUCCESS;\r
-      } else {\r
-        ErrorStatus = Status;\r
+    if (SectionStreamLength > 0) {\r
+      NewStream->StreamBuffer = AllocatePool (SectionStreamLength); \r
+      if (NewStream->StreamBuffer == NULL) {\r
+        FreePool (NewStream);\r
+        return EFI_OUT_OF_RESOURCES;\r
       }\r
-    }\r
-    \r
-    if (!IsNodeAtEnd (&SourceStream->Children, &CurrentChildNode->Link)) {\r
       //\r
-      // We haven't found the child node we're interested in yet, but there's\r
-      // still more nodes that have already been parsed so get the next one\r
-      // and continue searching..\r
+      // Copy in stream data\r
       //\r
-      CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream->Children, &CurrentChildNode->Link));\r
+      CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);\r
     } else {\r
       //\r
-      // We've exhausted children that have already been parsed, so see if\r
-      // there's any more data and continue parsing out more children if there\r
-      // is.\r
-      //\r
-      NextChildOffset = CurrentChildNode->OffsetInStream + CurrentChildNode->Size;\r
-      //\r
-      // Round up to 4 byte boundary\r
+      // It's possible to have a zero length section stream.\r
       //\r
-      NextChildOffset += 3;\r
-      NextChildOffset &= ~(UINTN)3;\r
-      if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {\r
-        //\r
-        // There's an unparsed child remaining in the stream, so create a new child node\r
-        //\r
-        Status = CreateChildNode (SourceStream, NextChildOffset, &CurrentChildNode);\r
-        if (EFI_ERROR (Status)) {\r
-          return Status;\r
-        }\r
-      } else {\r
-        ASSERT (EFI_ERROR (ErrorStatus));\r
-        return ErrorStatus;\r
-      }\r
+      NewStream->StreamBuffer = NULL;\r
     }\r
+  } else {\r
+    //\r
+    // If were here, the caller has supplied the buffer (it's an internal call)\r
+    // so just assign the buffer.  This happens when we open section streams\r
+    // as a result of expanding an encapsulating section.\r
+    //\r
+    NewStream->StreamBuffer = SectionStream;\r
   }\r
+  \r
+  //\r
+  // Initialize the rest of the section stream\r
+  //\r
+  NewStream->Signature = FRAMEWORK_SECTION_STREAM_SIGNATURE;\r
+  NewStream->StreamHandle = (UINTN) NewStream;\r
+  NewStream->StreamLength = SectionStreamLength;\r
+  InitializeListHead (&NewStream->Children);\r
+  NewStream->AuthenticationStatus = AuthenticationStatus;\r
+  \r
+  //\r
+  // Add new stream to stream list\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  InsertTailList (&mStreamRoot, &NewStream->Link);\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  *SectionStreamHandle = NewStream->StreamHandle;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Worker function.  Constructor for new child nodes.\r
+  SEP member function.  This function creates and returns a new section stream\r
+  handle to represent the new section stream.\r
 \r
-  @param Stream                Indicates the section stream in which to add the child.\r
-  @param ChildOffset           Indicates the offset in Stream that is the beginning\r
-                               of the child section.\r
-  @param ChildNode             Indicates the Callee allocated and initialized child.\r
+  @param This                 Indicates the calling context.\r
+  @param SectionStreamLength  Size in bytes of the section stream.\r
+  @param SectionStream        Buffer containing the new section stream.\r
+  @param SectionStreamHandle  A pointer to a caller allocated UINTN that on output\r
+                              contains the new section stream handle.\r
 \r
-  @retval EFI_SUCCESS          Child node was found and returned.\r
-  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
-  @retval EFI_PROTOCOL_ERROR   Encapsulation sections produce new stream handles when\r
-                               the child node is created.  If the section type is GUID\r
-                               defined, and the extraction GUID does not exist, and\r
-                               producing the stream requires the GUID, then a protocol\r
-                               error is generated and no child is produced.\r
-                               Values returned by OpenSectionStreamEx.\r
+  @retval EFI_SUCCESS           Section wase opened successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
+  @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of\r
+                                last section.\r
 \r
 **/\r
 EFI_STATUS\r
-CreateChildNode (\r
-  IN     CORE_SECTION_STREAM_NODE              *Stream,\r
-  IN     UINT32                                ChildOffset,\r
-     OUT CORE_SECTION_CHILD_NODE               **ChildNode\r
+EFIAPI\r
+OpenSectionStream (\r
+  IN     EFI_SECTION_EXTRACTION_PROTOCOL           *This,\r
+  IN     UINTN                                     SectionStreamLength,\r
+  IN     VOID                                      *SectionStream,\r
+     OUT UINTN                                     *SectionStreamHandle\r
   )\r
 {\r
-  EFI_STATUS                                   Status;\r
-  EFI_COMMON_SECTION_HEADER                    *SectionHeader;\r
-  EFI_COMPRESSION_SECTION                      *CompressionHeader;\r
-  EFI_GUID_DEFINED_SECTION                     *GuidedHeader;\r
-  EFI_DECOMPRESS_PROTOCOL                      *Decompress;\r
-  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL       *GuidedExtraction;\r
-  VOID                                         *NewStreamBuffer;\r
-  VOID                                         *ScratchBuffer;\r
-  UINT32                                       ScratchSize;\r
-  UINTN                                        NewStreamBufferSize;\r
-  UINT32                                       AuthenticationStatus;\r
-  UINT32                                       SectionLength;\r
-    \r
-  CORE_SECTION_CHILD_NODE                      *Node;\r
-\r
-  SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);\r
-\r
   //\r
-  // Allocate a new node\r
+  // Check to see section stream looks good...\r
   //\r
-  *ChildNode = AllocatePool (sizeof (CORE_SECTION_CHILD_NODE));\r
-  Node = *ChildNode;\r
-  if (Node == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
   \r
-  //\r
-  // Now initialize it\r
-  //\r
-  Node->Signature = CORE_SECTION_CHILD_SIGNATURE;\r
-  Node->Type = SectionHeader->Type;\r
+  return OpenSectionStreamEx ( \r
+          SectionStreamLength, \r
+          SectionStream,\r
+          TRUE,\r
+          0,\r
+          SectionStreamHandle\r
+          );\r
+}\r
+\r
+/**\r
+  Worker function.  Determine if the input stream:child matches the input type.\r
+\r
+  @param Stream                 Indicates the section stream associated with the child\r
+  @param Child                  Indicates the child to check\r
+  @param SearchType             Indicates the type of section to check against for\r
+  @param SectionDefinitionGuid  Indicates the GUID to check against if the type is\r
+                                EFI_SECTION_GUID_DEFINED\r
+\r
+  @retval TRUE                  The child matches\r
+  @retval FALSE                 The child doesn't match\r
+\r
+**/\r
+BOOLEAN\r
+ChildIsType (\r
+  IN FRAMEWORK_SECTION_STREAM_NODE *Stream,\r
+  IN FRAMEWORK_SECTION_CHILD_NODE  *Child,\r
+  IN EFI_SECTION_TYPE         SearchType,\r
+  IN EFI_GUID                 *SectionDefinitionGuid\r
+  )\r
+{\r
+  EFI_GUID_DEFINED_SECTION    *GuidedSection;\r
+  \r
+  if (SearchType == EFI_SECTION_ALL) {\r
+    return TRUE;\r
+  }\r
+  if (Child->Type != SearchType) {\r
+    return FALSE;\r
+  }\r
+  if (SearchType != EFI_SECTION_GUID_DEFINED) {\r
+    return TRUE;\r
+  }\r
+  GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);\r
+  return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);\r
+}\r
+\r
+/**\r
+  Create a protocol notification event and return it.\r
+\r
+  @param ProtocolGuid    Protocol to register notification event on.\r
+  @param NotifyTpl       Maximum TPL to signal the NotifyFunction.\r
+  @param NotifyFunction  EFI notification routine.\r
+  @param NotifyContext   Context passed into Event when it is created.\r
+  @param Registration    Registration key returned from RegisterProtocolNotify().\r
+  @param SignalFlag      Boolean value to decide whether kick the event after register or not.\r
+\r
+  @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
+           is added to the system.\r
+\r
+**/\r
+EFI_EVENT\r
+CreateProtocolNotifyEvent (\r
+  IN EFI_GUID             *ProtocolGuid,\r
+  IN EFI_TPL              NotifyTpl,\r
+  IN EFI_EVENT_NOTIFY     NotifyFunction,\r
+  IN VOID                 *NotifyContext,\r
+  OUT VOID                **Registration,\r
+  IN  BOOLEAN             SignalFlag\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_EVENT               Event;\r
+\r
+  //\r
+  // Create the event\r
+  //\r
+\r
+  Status = gBS->CreateEvent (\r
+            EVT_NOTIFY_SIGNAL,\r
+            NotifyTpl,\r
+            NotifyFunction,\r
+            NotifyContext,\r
+           &Event\r
+            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register for protocol notifactions on this event\r
+  //\r
+\r
+  Status = gBS->RegisterProtocolNotify (\r
+            ProtocolGuid,\r
+            Event,\r
+            Registration\r
+            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (SignalFlag) {\r
+    //\r
+    // Kick the event so we will perform an initial pass of\r
+    // current installed drivers\r
+    //\r
+    gBS->SignalEvent (Event);\r
+  }\r
+\r
+  return Event;\r
+}\r
+\r
+/**\r
+  RPN callback function.  Removes a stale section stream and re-initializes it\r
+  with an updated AuthenticationStatus.\r
+\r
+  @param Event               The event that fired\r
+  @param RpnContext          A pointer to the context that allows us to identify\r
+                             the relevent encapsulation.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+NotifyGuidedExtraction (\r
+  IN   EFI_EVENT   Event,\r
+  IN   VOID        *RpnContext\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  EFI_GUID_DEFINED_SECTION                *GuidedHeader;\r
+  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL  *GuidedExtraction;\r
+  VOID                                    *NewStreamBuffer;\r
+  UINTN                                   NewStreamBufferSize;\r
+  UINT32                                  AuthenticationStatus;\r
+  RPN_EVENT_CONTEXT                       *Context;\r
+  \r
+  Context = RpnContext;\r
+  \r
+  Status = CloseSectionStream (&mSectionExtraction, Context->ChildNode->EncapsulatedStreamHandle);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // The stream closed successfully, so re-open the stream with correct AuthenticationStatus\r
+    //\r
+  \r
+    GuidedHeader = (EFI_GUID_DEFINED_SECTION *) \r
+      (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
+    ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
+    \r
+    Status = gBS->LocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    \r
+    Status = GuidedExtraction->ExtractSection (\r
+                                 GuidedExtraction,\r
+                                 GuidedHeader,\r
+                                 &NewStreamBuffer,\r
+                                 &NewStreamBufferSize,\r
+                                 &AuthenticationStatus\r
+                                 );\r
+    ASSERT_EFI_ERROR (Status);\r
+    //\r
+    // OR in the parent stream's aggregagate status.\r
+    //\r
+    AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
+    Status = OpenSectionStreamEx (\r
+               NewStreamBufferSize,\r
+               NewStreamBuffer,\r
+               FALSE,\r
+               AuthenticationStatus,\r
+               &Context->ChildNode->EncapsulatedStreamHandle\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  //\r
+  //  If above, the stream  did not close successfully, it indicates it's\r
+  //  alread been closed by someone, so just destroy the event and be done with\r
+  //  it.\r
+  //\r
+  \r
+  gBS->CloseEvent (Event);\r
+  FreePool (Context);\r
+}  \r
+\r
+/**\r
+  Worker function.  Constructor for RPN event if needed to keep AuthenticationStatus\r
+  cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
+\r
+  @param ParentStream        Indicates the parent of the ecnapsulation section (child)\r
+  @param ChildNode           Indicates the child node that is the encapsulation section.\r
+\r
+**/\r
+VOID\r
+CreateGuidedExtractionRpnEvent (\r
+  IN FRAMEWORK_SECTION_STREAM_NODE       *ParentStream,\r
+  IN FRAMEWORK_SECTION_CHILD_NODE        *ChildNode\r
+  )\r
+{\r
+  RPN_EVENT_CONTEXT *Context;\r
+  \r
+  //\r
+  // Allocate new event structure and context\r
+  //\r
+  Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));\r
+  ASSERT (Context != NULL);\r
+  \r
+  Context->ChildNode = ChildNode;\r
+  Context->ParentStream = ParentStream;\r
\r
+  Context->Event = CreateProtocolNotifyEvent (\r
+                    Context->ChildNode->EncapsulationGuid,\r
+                    TPL_NOTIFY,\r
+                    NotifyGuidedExtraction,\r
+                    Context,\r
+                    &Context->Registration,\r
+                    FALSE\r
+                    );\r
+}\r
+\r
+/**\r
+  Worker function.  Constructor for new child nodes.\r
+\r
+  @param Stream                Indicates the section stream in which to add the child.\r
+  @param ChildOffset           Indicates the offset in Stream that is the beginning\r
+                               of the child section.\r
+  @param ChildNode             Indicates the Callee allocated and initialized child.\r
+\r
+  @retval EFI_SUCCESS          Child node was found and returned.\r
+  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+  @retval EFI_PROTOCOL_ERROR   Encapsulation sections produce new stream handles when\r
+                               the child node is created.  If the section type is GUID\r
+                               defined, and the extraction GUID does not exist, and\r
+                               producing the stream requires the GUID, then a protocol\r
+                               error is generated and no child is produced.\r
+                               Values returned by OpenSectionStreamEx.\r
+\r
+**/\r
+EFI_STATUS\r
+CreateChildNode (\r
+  IN     FRAMEWORK_SECTION_STREAM_NODE              *Stream,\r
+  IN     UINT32                                ChildOffset,\r
+     OUT FRAMEWORK_SECTION_CHILD_NODE               **ChildNode\r
+  )\r
+{\r
+  EFI_STATUS                                   Status;\r
+  EFI_COMMON_SECTION_HEADER                    *SectionHeader;\r
+  EFI_COMPRESSION_SECTION                      *CompressionHeader;\r
+  EFI_GUID_DEFINED_SECTION                     *GuidedHeader;\r
+  EFI_DECOMPRESS_PROTOCOL                      *Decompress;\r
+  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL       *GuidedExtraction;\r
+  VOID                                         *NewStreamBuffer;\r
+  VOID                                         *ScratchBuffer;\r
+  UINT32                                       ScratchSize;\r
+  UINTN                                        NewStreamBufferSize;\r
+  UINT32                                       AuthenticationStatus;\r
+  UINT32                                       SectionLength;\r
+    \r
+  FRAMEWORK_SECTION_CHILD_NODE                      *Node;\r
+\r
+  SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);\r
+\r
+  //\r
+  // Allocate a new node\r
+  //\r
+  *ChildNode = AllocatePool (sizeof (FRAMEWORK_SECTION_CHILD_NODE));\r
+  Node = *ChildNode;\r
+  if (Node == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  //\r
+  // Now initialize it\r
+  //\r
+  Node->Signature = FRAMEWORK_SECTION_CHILD_SIGNATURE;\r
+  Node->Type = SectionHeader->Type;\r
   Node->Size = SECTION_SIZE (SectionHeader);\r
   Node->OffsetInStream = ChildOffset;\r
   Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;\r
@@ -584,7 +714,7 @@ CreateChildNode (
         NewStreamBufferSize = CompressionHeader->UncompressedLength;\r
         NewStreamBuffer = AllocatePool (NewStreamBufferSize);\r
         if (NewStreamBuffer == NULL) {\r
-          gBS->FreePool (Node);\r
+          FreePool (Node);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
         \r
@@ -617,8 +747,8 @@ CreateChildNode (
 \r
           ScratchBuffer = AllocatePool (ScratchSize);\r
           if (ScratchBuffer == NULL) {\r
-            gBS->FreePool (Node);\r
-            gBS->FreePool (NewStreamBuffer);\r
+            FreePool (Node);\r
+            FreePool (NewStreamBuffer);\r
             return EFI_OUT_OF_RESOURCES;\r
           }\r
 \r
@@ -632,7 +762,7 @@ CreateChildNode (
                                  ScratchSize\r
                                  );\r
           ASSERT_EFI_ERROR (Status);\r
-          gBS->FreePool (ScratchBuffer);                                           \r
+          FreePool (ScratchBuffer);                                           \r
         }\r
       } else {\r
         NewStreamBuffer = NULL;\r
@@ -647,8 +777,8 @@ CreateChildNode (
                  &Node->EncapsulatedStreamHandle\r
                  );\r
       if (EFI_ERROR (Status)) {\r
-        gBS->FreePool (Node);\r
-        gBS->FreePool (NewStreamBuffer);\r
+        FreePool (Node);\r
+        FreePool (NewStreamBuffer);\r
         return Status;\r
       }\r
       break;\r
@@ -670,7 +800,7 @@ CreateChildNode (
                                      &AuthenticationStatus\r
                                      );\r
         if (EFI_ERROR (Status)) {\r
-          gBS->FreePool (*ChildNode);\r
+          FreePool (*ChildNode);\r
           return EFI_PROTOCOL_ERROR;\r
         }\r
         \r
@@ -678,7 +808,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) {\r
+        if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {\r
           //\r
           // OR in the parent stream's aggregate status.\r
           //\r
@@ -699,19 +829,19 @@ CreateChildNode (
                    &Node->EncapsulatedStreamHandle\r
                    );\r
         if (EFI_ERROR (Status)) {\r
-          gBS->FreePool (*ChildNode);\r
-          gBS->FreePool (NewStreamBuffer);\r
+          FreePool (*ChildNode);\r
+          FreePool (NewStreamBuffer);\r
           return Status;\r
         }\r
       } else {\r
         //\r
         // There's no GUIDed section extraction protocol available.\r
         //\r
-        if (GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {\r
+        if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {\r
           //\r
           // If the section REQUIRES an extraction protocol, then we're toast\r
           //\r
-          gBS->FreePool (*ChildNode);\r
+          FreePool (*ChildNode);\r
           return EFI_PROTOCOL_ERROR;\r
         }\r
         \r
@@ -746,261 +876,190 @@ CreateChildNode (
                    &Node->EncapsulatedStreamHandle\r
                    );\r
         if (EFI_ERROR (Status)) {\r
-          gBS->FreePool (Node);\r
+          FreePool (Node);\r
           return Status;\r
         }\r
       }\r
       \r
       if ((AuthenticationStatus & EFI_LOCAL_AUTH_STATUS_ALL) == \r
-            (EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED)) {\r
-        //\r
-        // Need to register for RPN for when the required GUIDed extraction\r
-        // protocol becomes available.  This will enable us to refresh the\r
-        // AuthenticationStatus cached in the Stream if it's ever requested\r
-        // again.\r
-        //\r
-        CreateGuidedExtractionRpnEvent (Stream, Node);\r
-      }\r
-      \r
-      break;\r
-\r
-    default:\r
-      \r
-      //\r
-      // Nothing to do if it's a leaf\r
-      //\r
-      break;\r
-  }\r
-  \r
-  //\r
-  // Last, add the new child node to the stream\r
-  //\r
-  InsertTailList (&Stream->Children, &Node->Link);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Worker function.  Constructor for RPN event if needed to keep AuthenticationStatus\r
-  cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
-\r
-  @param ParentStream        Indicates the parent of the ecnapsulation section (child)\r
-  @param ChildNode           Indicates the child node that is the encapsulation section.\r
-\r
-**/\r
-VOID\r
-CreateGuidedExtractionRpnEvent (\r
-  IN CORE_SECTION_STREAM_NODE       *ParentStream,\r
-  IN CORE_SECTION_CHILD_NODE        *ChildNode\r
-  )\r
-{\r
-  RPN_EVENT_CONTEXT *Context;\r
-  \r
-  //\r
-  // Allocate new event structure and context\r
-  //\r
-  Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));\r
-  ASSERT (Context != NULL);\r
-  \r
-  Context->ChildNode = ChildNode;\r
-  Context->ParentStream = ParentStream;\r
\r
-  Context->Event = CoreCreateProtocolNotifyEvent (\r
-                    Context->ChildNode->EncapsulationGuid,\r
-                    TPL_NOTIFY,\r
-                    NotifyGuidedExtraction,\r
-                    Context,\r
-                    &Context->Registration,\r
-                    FALSE\r
-                    );\r
-}\r
-  \r
-/**\r
-  RPN callback function.  Removes a stale section stream and re-initializes it\r
-  with an updated AuthenticationStatus.\r
-\r
-  @param Event               The event that fired\r
-  @param RpnContext          A pointer to the context that allows us to identify\r
-                             the relevent encapsulation.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-NotifyGuidedExtraction (\r
-  IN   EFI_EVENT   Event,\r
-  IN   VOID        *RpnContext\r
-  )\r
-{\r
-  EFI_STATUS                              Status;\r
-  EFI_GUID_DEFINED_SECTION                *GuidedHeader;\r
-  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL  *GuidedExtraction;\r
-  VOID                                    *NewStreamBuffer;\r
-  UINTN                                   NewStreamBufferSize;\r
-  UINT32                                  AuthenticationStatus;\r
-  RPN_EVENT_CONTEXT                       *Context;\r
-  \r
-  Context = RpnContext;\r
-  \r
-  Status = CloseSectionStream (&mSectionExtraction, Context->ChildNode->EncapsulatedStreamHandle);\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // The stream closed successfully, so re-open the stream with correct AuthenticationStatus\r
-    //\r
-  \r
-    GuidedHeader = (EFI_GUID_DEFINED_SECTION *) \r
-      (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
-    ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
-    \r
-    Status = gBS->LocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
-    ASSERT_EFI_ERROR (Status);\r
+            (EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED)) {\r
+        //\r
+        // Need to register for RPN for when the required GUIDed extraction\r
+        // protocol becomes available.  This will enable us to refresh the\r
+        // AuthenticationStatus cached in the Stream if it's ever requested\r
+        // again.\r
+        //\r
+        CreateGuidedExtractionRpnEvent (Stream, Node);\r
+      }\r
+      \r
+      break;\r
 \r
-    \r
-    Status = GuidedExtraction->ExtractSection (\r
-                                 GuidedExtraction,\r
-                                 GuidedHeader,\r
-                                 &NewStreamBuffer,\r
-                                 &NewStreamBufferSize,\r
-                                 &AuthenticationStatus\r
-                                 );\r
-    ASSERT_EFI_ERROR (Status);\r
-    //\r
-    // OR in the parent stream's aggregagate status.\r
-    //\r
-    AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;\r
-    Status = OpenSectionStreamEx (\r
-               NewStreamBufferSize,\r
-               NewStreamBuffer,\r
-               FALSE,\r
-               AuthenticationStatus,\r
-               &Context->ChildNode->EncapsulatedStreamHandle\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
+    default:\r
+      \r
+      //\r
+      // Nothing to do if it's a leaf\r
+      //\r
+      break;\r
   }\r
-\r
-  //\r
-  //  If above, the stream  did not close successfully, it indicates it's\r
-  //  alread been closed by someone, so just destroy the event and be done with\r
-  //  it.\r
-  //\r
-  \r
-  gBS->CloseEvent (Event);\r
-  gBS->FreePool (Context);\r
-}  \r
-  \r
-/**\r
-  Worker function.  Destructor for child nodes.\r
-\r
-  @param ChildNode           Indicates the node to destroy\r
-\r
-**/\r
-VOID\r
-FreeChildNode (\r
-  IN  CORE_SECTION_CHILD_NODE                   *ChildNode\r
-  )\r
-{\r
-  ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);\r
-  //\r
-  // Remove the child from it's list\r
-  //\r
-  RemoveEntryList (&ChildNode->Link);\r
   \r
-  if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
-    //\r
-    // If it's an encapsulating section, we close the resulting section stream.\r
-    // CloseSectionStream will free all memory associated with the stream.\r
-    //\r
-    CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);\r
-  }\r
   //\r
-  // Last, free the child node itself\r
+  // Last, add the new child node to the stream\r
   //\r
-  gBS->FreePool (ChildNode);\r
-}  \r
+  InsertTailList (&Stream->Children, &Node->Link);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
-  Worker function.  Constructor for section streams.\r
+  Worker function  Recursively searches / builds section stream database\r
+  looking for requested section.\r
 \r
-  @param SectionStreamLength   Size in bytes of the section stream.\r
-  @param SectionStream         Buffer containing the new section stream.\r
-  @param AllocateBuffer        Indicates whether the stream buffer is to be copied\r
-                               or the input buffer is to be used in place.\r
-  @param AuthenticationStatus  Indicates the default authentication status for the\r
-                               new stream.\r
-  @param SectionStreamHandle   A pointer to a caller allocated section stream handle.\r
 \r
-  @retval EFI_SUCCESS           Stream was added to stream database.\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
+  @param SourceStream          Indicates the section stream in which to do the search.\r
+  @param SearchType            Indicates the type of section to search for.\r
+  @param SectionInstance       Indicates which instance of section to find.  This is\r
+                               an in/out parameter to deal with recursions.\r
+  @param SectionDefinitionGuid Guid of section definition\r
+  @param FoundChild            Output indicating the child node that is found.\r
+  @param FoundStream           Output indicating which section stream the child was\r
+                               found in.  If this stream was generated as a result of\r
+                               an encapsulation section, the streamhandle is visible\r
+                               within the SEP driver only.\r
+  @param AuthenticationStatus  Indicates the authentication status of the found section.\r
+\r
+  @retval EFI_SUCCESS          Child node was found and returned.\r
+  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+  @retval EFI_NOT_FOUND        Requested child node does not exist.\r
+  @retval EFI_PROTOCOL_ERROR   A required GUIDED section extraction protocol does not\r
+                               exist\r
 \r
 **/\r
 EFI_STATUS\r
-OpenSectionStreamEx (\r
-  IN     UINTN                                     SectionStreamLength,\r
-  IN     VOID                                      *SectionStream,\r
-  IN     BOOLEAN                                   AllocateBuffer,\r
-  IN     UINT32                                    AuthenticationStatus,   \r
-     OUT UINTN                                     *SectionStreamHandle\r
+FindChildNode (\r
+  IN     FRAMEWORK_SECTION_STREAM_NODE                   *SourceStream,\r
+  IN     EFI_SECTION_TYPE                           SearchType,\r
+  IN OUT UINTN                                      *SectionInstance,\r
+  IN     EFI_GUID                                   *SectionDefinitionGuid,\r
+  OUT    FRAMEWORK_SECTION_CHILD_NODE                    **FoundChild,\r
+  OUT    FRAMEWORK_SECTION_STREAM_NODE                   **FoundStream,\r
+  OUT    UINT32                                     *AuthenticationStatus\r
   )\r
 {\r
-  CORE_SECTION_STREAM_NODE    *NewStream;\r
-  EFI_TPL                     OldTpl;\r
+  FRAMEWORK_SECTION_CHILD_NODE                       *CurrentChildNode;\r
+  FRAMEWORK_SECTION_CHILD_NODE                       *RecursedChildNode;\r
+  FRAMEWORK_SECTION_STREAM_NODE                      *RecursedFoundStream;\r
+  UINT32                                        NextChildOffset;\r
+  EFI_STATUS                                    ErrorStatus;\r
+  EFI_STATUS                                    Status;\r
   \r
-  //\r
-  // Allocate a new stream\r
-  //\r
-  NewStream = AllocatePool (sizeof (CORE_SECTION_STREAM_NODE));\r
-  if (NewStream == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  CurrentChildNode = NULL;\r
+  ErrorStatus = EFI_NOT_FOUND;\r
+  \r
+  if (SourceStream->StreamLength == 0) {\r
+    return EFI_NOT_FOUND;\r
   }\r
   \r
-  if (AllocateBuffer) { \r
+  if (IsListEmpty (&SourceStream->Children) && \r
+                   SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {\r
     //\r
-    // if we're here, we're double buffering, allocate the buffer and copy the\r
-    // data in\r
+    // This occurs when a section stream exists, but no child sections\r
+    // have been parsed out yet.  Therefore, extract the first child and add it\r
+    // to the list of children so we can get started.\r
+    // Section stream may contain an array of zero or more bytes.\r
+    // So, its size should be >= the size of commen section header.\r
     //\r
-    if (SectionStreamLength > 0) {\r
-      NewStream->StreamBuffer = AllocatePool (SectionStreamLength); \r
-      if (NewStream->StreamBuffer == NULL) {\r
-        gBS->FreePool (NewStream);\r
-        return EFI_OUT_OF_RESOURCES;\r
-      }\r
-      //\r
-      // Copy in stream data\r
-      //\r
-      CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);\r
-    } else {\r
-      //\r
-      // It's possible to have a zero length section stream.\r
-      //\r
-      NewStream->StreamBuffer = NULL;\r
+    Status = CreateChildNode (SourceStream, 0, &CurrentChildNode);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
     }\r
-  } else {\r
-    //\r
-    // If were here, the caller has supplied the buffer (it's an internal call)\r
-    // so just assign the buffer.  This happens when we open section streams\r
-    // as a result of expanding an encapsulating section.\r
-    //\r
-    NewStream->StreamBuffer = SectionStream;\r
   }\r
   \r
   //\r
-  // Initialize the rest of the section stream\r
-  //\r
-  NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;\r
-  NewStream->StreamHandle = (UINTN) NewStream;\r
-  NewStream->StreamLength = SectionStreamLength;\r
-  InitializeListHead (&NewStream->Children);\r
-  NewStream->AuthenticationStatus = AuthenticationStatus;\r
-  \r
-  //\r
-  // Add new stream to stream list\r
+  // At least one child has been parsed out of the section stream.  So, walk\r
+  // through the sections that have already been parsed out looking for the\r
+  // requested section, if necessary, continue parsing section stream and\r
+  // adding children until either the requested section is found, or we run\r
+  // out of data\r
   //\r
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-  InsertTailList (&mStreamRoot, &NewStream->Link);\r
-  gBS->RestoreTPL (OldTpl);\r
+  CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));\r
 \r
-  *SectionStreamHandle = NewStream->StreamHandle;\r
-  \r
-  return EFI_SUCCESS;\r
+  for (;;) {\r
+    if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {\r
+      //\r
+      // The type matches, so check the instance count to see if it's the one we want\r
+      //\r
+      (*SectionInstance)--;\r
+      if (*SectionInstance == 0) {\r
+        //\r
+        // Got it!\r
+        //\r
+        *FoundChild = CurrentChildNode;\r
+        *FoundStream = SourceStream;\r
+        *AuthenticationStatus = SourceStream->AuthenticationStatus;\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+    \r
+    if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
+      //\r
+      // If the current node is an encapsulating node, recurse into it...\r
+      //\r
+      Status = FindChildNode (\r
+                (FRAMEWORK_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,\r
+                SearchType,\r
+                SectionInstance,\r
+                SectionDefinitionGuid,\r
+                &RecursedChildNode,\r
+                &RecursedFoundStream,\r
+                AuthenticationStatus\r
+                );\r
+      //\r
+      // If the status is not EFI_SUCCESS, just save the error code and continue\r
+      // to find the request child node in the rest stream.\r
+      //\r
+      if (*SectionInstance == 0) {\r
+        ASSERT_EFI_ERROR (Status);\r
+        *FoundChild = RecursedChildNode;\r
+        *FoundStream = RecursedFoundStream;\r
+        return EFI_SUCCESS;\r
+      } else {\r
+        ErrorStatus = Status;\r
+      }\r
+    }\r
+    \r
+    if (!IsNodeAtEnd (&SourceStream->Children, &CurrentChildNode->Link)) {\r
+      //\r
+      // We haven't found the child node we're interested in yet, but there's\r
+      // still more nodes that have already been parsed so get the next one\r
+      // and continue searching..\r
+      //\r
+      CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream->Children, &CurrentChildNode->Link));\r
+    } else {\r
+      //\r
+      // We've exhausted children that have already been parsed, so see if\r
+      // there's any more data and continue parsing out more children if there\r
+      // is.\r
+      //\r
+      NextChildOffset = CurrentChildNode->OffsetInStream + CurrentChildNode->Size;\r
+      //\r
+      // Round up to 4 byte boundary\r
+      //\r
+      NextChildOffset += 3;\r
+      NextChildOffset &= ~(UINTN)3;\r
+      if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {\r
+        //\r
+        // There's an unparsed child remaining in the stream, so create a new child node\r
+        //\r
+        Status = CreateChildNode (SourceStream, NextChildOffset, &CurrentChildNode);\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+      } else {\r
+        ASSERT (EFI_ERROR (ErrorStatus));\r
+        return ErrorStatus;\r
+      }\r
+    }\r
+  }\r
 }\r
 \r
 /**\r
@@ -1017,10 +1076,10 @@ OpenSectionStreamEx (
 EFI_STATUS\r
 FindStreamNode (\r
   IN  UINTN                                     SearchHandle,\r
-  OUT CORE_SECTION_STREAM_NODE                  **FoundStream\r
+  OUT FRAMEWORK_SECTION_STREAM_NODE                  **FoundStream\r
   )\r
 {  \r
-  CORE_SECTION_STREAM_NODE                      *StreamNode;\r
+  FRAMEWORK_SECTION_STREAM_NODE                      *StreamNode;\r
   \r
   if (!IsListEmpty (&mStreamRoot)) {\r
     StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));\r
@@ -1038,117 +1097,223 @@ FindStreamNode (
   \r
   return EFI_NOT_FOUND;\r
 }\r
-\r
+  \r
 /**\r
+  SEP member function.  Retrieves requested section from section stream.\r
 \r
-  Check if a stream is valid.\r
-\r
-  @param SectionStream         The section stream to be checked\r
-  @param SectionStreamLength   The length of section stream\r
+  @param This                  Pointer to SEP instance.\r
+  @param SectionStreamHandle   The section stream from which to extract the requested\r
+                               section.\r
+  @param SectionType           A pointer to the type of section to search for.\r
+  @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED, then\r
+                               SectionDefinitionGuid indicates which of these types\r
+                               of sections to search for.\r
+  @param SectionInstance       Indicates which instance of the requested section to\r
+                               return.\r
+  @param Buffer                Double indirection to buffer.  If *Buffer is non-null on\r
+                               input, then the buffer is caller allocated.  If\r
+                               *Buffer is NULL, then the buffer is callee allocated.\r
+                               In either case, the requried buffer size is returned\r
+                               in *BufferSize.\r
+  @param BufferSize            On input, indicates the size of *Buffer if *Buffer is\r
+                               non-null on input.  On output, indicates the required\r
+                               size (allocated size if callee allocated) of *Buffer.\r
+  @param AuthenticationStatus  Indicates the authentication status of the retrieved\r
+                               section.\r
 \r
-  @return The validness of a stream.\r
\r
+  @retval EFI_SUCCESS           Section was retrieved successfully\r
+  @retval EFI_PROTOCOL_ERROR    A GUID defined section was encountered in the section \r
+                                stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED\r
+                                bit set, but there was no corresponding GUIDed Section \r
+                                Extraction Protocol in the handle database.  *Buffer is \r
+                                unmodified.\r
+  @retval EFI_NOT_FOUND         An error was encountered when parsing the SectionStream.\r
+                                This indicates the SectionStream  is not correctly \r
+                                formatted.\r
+  @retval EFI_NOT_FOUND         The requested section does not exist.\r
+  @retval EFI_OUT_OF_RESOURCES  The system has insufficient resources to process the \r
+                                request.\r
+  @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.\r
+  @retval EFI_WARN_TOO_SMALL    The size of the caller allocated input buffer is \r
+                                insufficient to contain the requested section.  The \r
+                                input buffer is filled and contents are section contents\r
+                                are truncated.\r
 \r
 **/\r
-BOOLEAN\r
-IsValidSectionStream (\r
-  IN  VOID              *SectionStream,\r
-  IN  UINTN             SectionStreamLength\r
+EFI_STATUS\r
+EFIAPI\r
+GetSection (\r
+  IN EFI_SECTION_EXTRACTION_PROTOCOL                    *This,\r
+  IN UINTN                                              SectionStreamHandle,\r
+  IN EFI_SECTION_TYPE                                   *SectionType,\r
+  IN EFI_GUID                                           *SectionDefinitionGuid,\r
+  IN UINTN                                              SectionInstance,\r
+  IN VOID                                               **Buffer,\r
+  IN OUT UINTN                                          *BufferSize,\r
+  OUT UINT32                                            *AuthenticationStatus\r
   )\r
 {\r
-  UINTN                       TotalLength;\r
-  UINTN                       SectionLength;\r
-  EFI_COMMON_SECTION_HEADER   *SectionHeader;\r
-  EFI_COMMON_SECTION_HEADER   *NextSectionHeader;\r
-\r
-  TotalLength = 0;\r
-  SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;\r
+  FRAMEWORK_SECTION_STREAM_NODE                              *StreamNode;\r
+  EFI_TPL                                               OldTpl;\r
+  EFI_STATUS                                            Status;\r
+  FRAMEWORK_SECTION_CHILD_NODE                               *ChildNode;\r
+  FRAMEWORK_SECTION_STREAM_NODE                              *ChildStreamNode;\r
+  UINTN                                                 CopySize;\r
+  UINT32                                                ExtractedAuthenticationStatus;\r
+  UINTN                                                 Instance;\r
+  UINT8                                                 *CopyBuffer;\r
+  UINTN                                                 SectionSize;\r
   \r
-  while (TotalLength < SectionStreamLength) {\r
-    SectionLength = SECTION_SIZE (SectionHeader);\r
-    TotalLength += SectionLength;\r
-\r
-    if (TotalLength == SectionStreamLength) {\r
-      return TRUE;    \r
-    }\r
 \r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  Instance = SectionInstance + 1;\r
+  \r
+  //\r
+  // Locate target stream\r
+  //\r
+  Status = FindStreamNode (SectionStreamHandle, &StreamNode);\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto GetSection_Done;\r
+  }\r
+  \r
+  //\r
+  // Found the stream, now locate and return the appropriate section\r
+  //\r
+  if (SectionType == NULL) {\r
     //\r
-    // Move to the next byte following the section...\r
+    // SectionType == NULL means return the WHOLE section stream...\r
     //\r
-    SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);\r
+    CopySize = StreamNode->StreamLength;\r
+    CopyBuffer = StreamNode->StreamBuffer;\r
+    *AuthenticationStatus = StreamNode->AuthenticationStatus;\r
+  } else {\r
+    //\r
+    // There's a requested section type, so go find it and return it...\r
+    //\r
+    Status = FindChildNode (\r
+                      StreamNode, \r
+                      *SectionType, \r
+                      &Instance, \r
+                      SectionDefinitionGuid,\r
+                      &ChildNode,\r
+                      &ChildStreamNode, \r
+                      &ExtractedAuthenticationStatus\r
+                      );\r
+    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
+    *AuthenticationStatus = ExtractedAuthenticationStatus;\r
+  }   \r
     \r
+  SectionSize = CopySize;  \r
+  if (*Buffer != NULL) {\r
     //\r
-    // Figure out where the next section begins\r
+    // Caller allocated buffer.  Fill to size and return required size...\r
     //\r
-    NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) SectionHeader + 3);\r
-    NextSectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) NextSectionHeader & ~(UINTN)3);\r
-    TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;\r
-    SectionHeader = NextSectionHeader;\r
+    if (*BufferSize < CopySize) {\r
+      Status = EFI_WARN_BUFFER_TOO_SMALL;\r
+      CopySize = *BufferSize;\r
+    }\r
+  } else {\r
+    //\r
+    // Callee allocated buffer.  Allocate buffer and return size.\r
+    //\r
+    *Buffer = AllocatePool (CopySize);\r
+    if (*Buffer == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto GetSection_Done;\r
+    }\r
   }\r
-\r
-  ASSERT (FALSE);\r
-  return FALSE;\r
+  CopyMem (*Buffer, CopyBuffer, CopySize);\r
+  *BufferSize = SectionSize;\r
+  \r
+GetSection_Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
 }\r
 \r
 /**\r
-  Create a protocol notification event and return it.\r
-\r
-  @param ProtocolGuid    Protocol to register notification event on.\r
-  @param NotifyTpl       Maximum TPL to signal the NotifyFunction.\r
-  @param NotifyFunction  EFI notification routine.\r
-  @param NotifyContext   Context passed into Event when it is created.\r
-  @param Registration    Registration key returned from RegisterProtocolNotify().\r
-  @param SignalFlag      Boolean value to decide whether kick the event after register or not.\r
+  Worker function.  Destructor for child nodes.\r
 \r
-  @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
-           is added to the system.\r
+  @param ChildNode           Indicates the node to destroy\r
 \r
 **/\r
-EFI_EVENT\r
-CoreCreateProtocolNotifyEvent (\r
-  IN EFI_GUID             *ProtocolGuid,\r
-  IN EFI_TPL              NotifyTpl,\r
-  IN EFI_EVENT_NOTIFY     NotifyFunction,\r
-  IN VOID                 *NotifyContext,\r
-  OUT VOID                **Registration,\r
-  IN  BOOLEAN             SignalFlag\r
+VOID\r
+FreeChildNode (\r
+  IN  FRAMEWORK_SECTION_CHILD_NODE                   *ChildNode\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  EFI_EVENT               Event;\r
-\r
+  ASSERT (ChildNode->Signature == FRAMEWORK_SECTION_CHILD_SIGNATURE);\r
   //\r
-  // Create the event\r
+  // Remove the child from it's list\r
   //\r
-\r
-  Status = gBS->CreateEvent (\r
-            EVT_NOTIFY_SIGNAL,\r
-            NotifyTpl,\r
-            NotifyFunction,\r
-            NotifyContext,\r
-           &Event\r
-            );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
+  RemoveEntryList (&ChildNode->Link);\r
+  \r
+  if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
+    //\r
+    // If it's an encapsulating section, we close the resulting section stream.\r
+    // CloseSectionStream will free all memory associated with the stream.\r
+    //\r
+    CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);\r
+  }\r
   //\r
-  // Register for protocol notifactions on this event\r
+  // Last, free the child node itself\r
   //\r
+  FreePool (ChildNode);\r
+}  \r
 \r
-  Status = gBS->RegisterProtocolNotify (\r
-            ProtocolGuid,\r
-            Event,\r
-            Registration\r
-            );\r
-  ASSERT_EFI_ERROR (Status);\r
+/**\r
+  SEP member function.  Deletes an existing section stream\r
 \r
-  if (SignalFlag) {\r
+  @param This                   Indicates the calling context.\r
+  @param StreamHandleToClose    Indicates the stream to close\r
+\r
+  @retval EFI_SUCCESS           Section stream was closed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
+  @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of\r
+                                last section.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CloseSectionStream (\r
+  IN  EFI_SECTION_EXTRACTION_PROTOCOL           *This,\r
+  IN  UINTN                                     StreamHandleToClose\r
+  )\r
+{\r
+  FRAMEWORK_SECTION_STREAM_NODE                      *StreamNode;\r
+  EFI_TPL                                       OldTpl;\r
+  EFI_STATUS                                    Status;\r
+  LIST_ENTRY                                    *Link;\r
+  FRAMEWORK_SECTION_CHILD_NODE                       *ChildNode;\r
+  \r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  \r
+  //\r
+  // Locate target stream\r
+  //\r
+  Status = FindStreamNode (StreamHandleToClose, &StreamNode);\r
+  if (!EFI_ERROR (Status)) {\r
     //\r
-    // Kick the event so we will perform an initial pass of\r
-    // current installed drivers\r
+    // Found the stream, so close it\r
     //\r
-    gBS->SignalEvent (Event);\r
+    RemoveEntryList (&StreamNode->Link);\r
+    while (!IsListEmpty (&StreamNode->Children)) {\r
+      Link = GetFirstNode (&StreamNode->Children);\r
+      ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);\r
+      FreeChildNode (ChildNode);\r
+    }\r
+    FreePool (StreamNode->StreamBuffer);\r
+    FreePool (StreamNode);\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    Status = EFI_INVALID_PARAMETER;\r
   }\r
-\r
-  return Event;\r
+  \r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
 }\r
-\r
-\r
diff --git a/IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.h b/IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.h
deleted file mode 100644 (file)
index 663cd73..0000000
+++ /dev/null
@@ -1,419 +0,0 @@
-/** @file\r
-  Section Extraction Protocol implementation.\r
-  \r
-  Stream database is implemented as a linked list of section streams,\r
-  where each stream contains a linked list of children, which may be leaves or\r
-  encapsulations.  \r
-  \r
-  Children that are encapsulations generate new stream entries\r
-  when they are created.  Streams can also be created by calls to \r
-  SEP->OpenSectionStream().\r
-  \r
-  The database is only created far enough to return the requested data from\r
-  any given stream, or to determine that the requested data is not found.\r
-  \r
-  If a GUIDed encapsulation is encountered, there are three possiblilites.\r
-  \r
-  1) A support protocol is found, in which the stream is simply processed with\r
-     the support protocol.\r
-     \r
-  2) A support protocol is not found, but the data is available to be read\r
-     without processing.  In this case, the database is built up through the\r
-     recursions to return the data, and a RPN event is set that will enable\r
-     the stream in question to be refreshed if and when the required section\r
-     extraction protocol is published.This insures the AuthenticationStatus \r
-     does not become stale in the cache.\r
-     \r
-  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 - 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
-#ifndef _SECION_EXTRACTION_H_\r
-#define _SECION_EXTRACTION_H_\r
-\r
-#include <FrameworkDxe.h>\r
-\r
-#include <Protocol/SectionExtraction.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Protocol/Decompress.h>\r
-#include <Protocol/GuidedSectionExtraction.h>\r
-\r
-//\r
-// Local defines and typedefs\r
-//\r
-#define CORE_SECTION_CHILD_SIGNATURE  SIGNATURE_32('S','X','C','S')\r
-#define CHILD_SECTION_NODE_FROM_LINK(Node) \\r
-  CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)\r
-\r
-typedef struct {\r
-  UINT32                      Signature;\r
-  LIST_ENTRY                  Link;\r
-  UINT32                      Type;\r
-  UINT32                      Size;\r
-  //\r
-  // StreamBase + OffsetInStream == pointer to section header in stream.  The\r
-  // stream base is always known when walking the sections within.\r
-  //\r
-  UINT32                      OffsetInStream;\r
-  //\r
-  // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an\r
-  // encapsulating section.  Otherwise, it contains the stream handle\r
-  // of the encapsulated stream.  This handle is ALWAYS produced any time an\r
-  // encapsulating child is encountered, irrespective of whether the\r
-  // encapsulated stream is processed further.\r
-  //\r
-  UINTN                       EncapsulatedStreamHandle;\r
-  EFI_GUID                    *EncapsulationGuid;\r
-} CORE_SECTION_CHILD_NODE;\r
-\r
-#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')\r
-#define STREAM_NODE_FROM_LINK(Node) \\r
-  CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)\r
-\r
-typedef struct {\r
-  UINT32                      Signature;\r
-  LIST_ENTRY                  Link;\r
-  UINTN                       StreamHandle;\r
-  UINT8                       *StreamBuffer;\r
-  UINTN                       StreamLength;\r
-  LIST_ENTRY                  Children;\r
-  //\r
-  // Authentication status is from GUIDed encapsulations.\r
-  //\r
-  UINT32                      AuthenticationStatus;\r
-} CORE_SECTION_STREAM_NODE;\r
-\r
-#define NULL_STREAM_HANDLE    0\r
-\r
-typedef struct {\r
-  CORE_SECTION_CHILD_NODE     *ChildNode;\r
-  CORE_SECTION_STREAM_NODE    *ParentStream;\r
-  VOID                        *Registration;\r
-  EFI_EVENT                   Event;\r
-} RPN_EVENT_CONTEXT;\r
-  \r
-  \r
-/**\r
-  Create a protocol notification event and return it.\r
-\r
-  @param ProtocolGuid    Protocol to register notification event on.\r
-  @param NotifyTpl       Maximum TPL to signal the NotifyFunction.\r
-  @param NotifyFunction  EFI notification routine.\r
-  @param NotifyContext   Context passed into Event when it is created.\r
-  @param Registration    Registration key returned from RegisterProtocolNotify().\r
-  @param SignalFlag      Boolean value to decide whether kick the event after register or not.\r
-\r
-  @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
-           is added to the system.\r
-\r
-**/\r
-EFI_EVENT\r
-CoreCreateProtocolNotifyEvent (\r
-  IN EFI_GUID             *ProtocolGuid,\r
-  IN EFI_TPL              NotifyTpl,\r
-  IN EFI_EVENT_NOTIFY     NotifyFunction,\r
-  IN VOID                 *NotifyContext,\r
-  OUT VOID                **Registration,\r
-  IN  BOOLEAN             SignalFlag\r
-  );\r
-\r
-//\r
-// Local prototypes\r
-//\r
-\r
-/**\r
-  Worker function.  Determine if the input stream:child matches the input type.\r
-\r
-  @param Stream                 Indicates the section stream associated with the child\r
-  @param Child                  Indicates the child to check\r
-  @param SearchType             Indicates the type of section to check against for\r
-  @param SectionDefinitionGuid  Indicates the GUID to check against if the type is\r
-                                EFI_SECTION_GUID_DEFINED\r
-\r
-  @retval TRUE                  The child matches\r
-  @retval FALSE                 The child doesn't match\r
-\r
-**/\r
-BOOLEAN\r
-ChildIsType (\r
-  IN CORE_SECTION_STREAM_NODE *Stream,\r
-  IN CORE_SECTION_CHILD_NODE  *Child,\r
-  IN EFI_SECTION_TYPE         SearchType,\r
-  IN EFI_GUID                 *SectionDefinitionGuid\r
-  );\r
-\r
-/**\r
-  RPN callback function.  Removes a stale section stream and re-initializes it\r
-  with an updated AuthenticationStatus.\r
-\r
-  @param Event               The event that fired\r
-  @param RpnContext          A pointer to the context that allows us to identify\r
-                             the relevent encapsulation.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-NotifyGuidedExtraction (\r
-  IN   EFI_EVENT   Event,\r
-  IN   VOID        *RpnContext\r
-  );\r
-\r
-/**\r
-  Worker function.  Constructor for RPN event if needed to keep AuthenticationStatus\r
-  cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...\r
-\r
-  @param ParentStream        Indicates the parent of the ecnapsulation section (child)\r
-  @param ChildNode           Indicates the child node that is the encapsulation section.\r
-\r
-**/\r
-VOID\r
-CreateGuidedExtractionRpnEvent (\r
-  IN CORE_SECTION_STREAM_NODE       *ParentStream,\r
-  IN CORE_SECTION_CHILD_NODE        *ChildNode\r
-  );\r
-\r
-/**\r
-  SEP member function.  This function creates and returns a new section stream\r
-  handle to represent the new section stream.\r
-\r
-  @param This                 Indicates the calling context.\r
-  @param SectionStreamLength  Size in bytes of the section stream.\r
-  @param SectionStream        Buffer containing the new section stream.\r
-  @param SectionStreamHandle  A pointer to a caller allocated UINTN that on output\r
-                              contains the new section stream handle.\r
-\r
-  @retval EFI_SUCCESS           Section wase opened successfully.\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
-  @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of\r
-                                last section.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-OpenSectionStream (\r
-  IN     EFI_SECTION_EXTRACTION_PROTOCOL           *This,\r
-  IN     UINTN                                     SectionStreamLength,\r
-  IN     VOID                                      *SectionStream,\r
-     OUT UINTN                                     *SectionStreamHandle\r
-  );\r
-  \r
-/**\r
-  SEP member function.  Retrieves requested section from section stream.\r
-\r
-  @param This                  Pointer to SEP instance.\r
-  @param SectionStreamHandle   The section stream from which to extract the requested\r
-                               section.\r
-  @param SectionType           A pointer to the type of section to search for.\r
-  @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED, then\r
-                               SectionDefinitionGuid indicates which of these types\r
-                               of sections to search for.\r
-  @param SectionInstance       Indicates which instance of the requested section to\r
-                               return.\r
-  @param Buffer                Double indirection to buffer.  If *Buffer is non-null on\r
-                               input, then the buffer is caller allocated.  If\r
-                               *Buffer is NULL, then the buffer is callee allocated.\r
-                               In either case, the requried buffer size is returned\r
-                               in *BufferSize.\r
-  @param BufferSize            On input, indicates the size of *Buffer if *Buffer is\r
-                               non-null on input.  On output, indicates the required\r
-                               size (allocated size if callee allocated) of *Buffer.\r
-  @param AuthenticationStatus  Indicates the authentication status of the retrieved\r
-                               section.\r
-\r
\r
-  @retval EFI_SUCCESS           Section was retrieved successfully\r
-  @retval EFI_PROTOCOL_ERROR    A GUID defined section was encountered in the section \r
-                                stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED\r
-                                bit set, but there was no corresponding GUIDed Section \r
-                                Extraction Protocol in the handle database.  *Buffer is \r
-                                unmodified.\r
-  @retval EFI_NOT_FOUND         An error was encountered when parsing the SectionStream.\r
-                                This indicates the SectionStream  is not correctly \r
-                                formatted.\r
-  @retval EFI_NOT_FOUND         The requested section does not exist.\r
-  @retval EFI_OUT_OF_RESOURCES  The system has insufficient resources to process the \r
-                                request.\r
-  @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.\r
-  @retval EFI_WARN_TOO_SMALL    The size of the caller allocated input buffer is \r
-                                insufficient to contain the requested section.  The \r
-                                input buffer is filled and contents are section contents\r
-                                are truncated.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetSection (\r
-  IN EFI_SECTION_EXTRACTION_PROTOCOL                    *This,\r
-  IN UINTN                                              SectionStreamHandle,\r
-  IN EFI_SECTION_TYPE                                   *SectionType,\r
-  IN EFI_GUID                                           *SectionDefinitionGuid,\r
-  IN UINTN                                              SectionInstance,\r
-  IN VOID                                               **Buffer,\r
-  IN OUT UINTN                                          *BufferSize,\r
-  OUT UINT32                                            *AuthenticationStatus\r
-  );\r
-  \r
-/**\r
-  SEP member function.  Deletes an existing section stream\r
-\r
-  @param This                   Indicates the calling context.\r
-  @param StreamHandleToClose    Indicates the stream to close\r
-\r
-  @retval EFI_SUCCESS           Section stream was closed successfully.\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
-  @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of\r
-                                last section.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CloseSectionStream (\r
-  IN  EFI_SECTION_EXTRACTION_PROTOCOL           *This,\r
-  IN  UINTN                                     StreamHandleToClose\r
-  );\r
-  \r
-/**\r
-  Worker function.  Search stream database for requested stream handle.\r
-\r
-  @param SearchHandle        Indicates which stream to look for.\r
-  @param FoundStream         Output pointer to the found stream.\r
-\r
-  @retval EFI_SUCCESS        StreamHandle was found and *FoundStream contains\r
-                             the stream node.\r
-  @retval EFI_NOT_FOUND      SearchHandle was not found in the stream database.\r
-\r
-**/\r
-EFI_STATUS\r
-FindStreamNode (\r
-  IN  UINTN                                     SearchHandle,\r
-  OUT CORE_SECTION_STREAM_NODE                  **FoundStream\r
-  );\r
-  \r
-/**\r
-  Worker function  Recursively searches / builds section stream database\r
-  looking for requested section.\r
-\r
-\r
-  @param SourceStream          Indicates the section stream in which to do the search.\r
-  @param SearchType            Indicates the type of section to search for.\r
-  @param SectionInstance       Indicates which instance of section to find.  This is\r
-                               an in/out parameter to deal with recursions.\r
-  @param SectionDefinitionGuid Guid of section definition\r
-  @param FoundChild            Output indicating the child node that is found.\r
-  @param FoundStream           Output indicating which section stream the child was\r
-                               found in.  If this stream was generated as a result of\r
-                               an encapsulation section, the streamhandle is visible\r
-                               within the SEP driver only.\r
-  @param AuthenticationStatus  Indicates the authentication status of the found section.\r
-\r
-  @retval EFI_SUCCESS          Child node was found and returned.\r
-  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
-  @retval EFI_NOT_FOUND        Requested child node does not exist.\r
-  @retval EFI_PROTOCOL_ERROR   A required GUIDED section extraction protocol does not\r
-                               exist\r
-\r
-**/\r
-EFI_STATUS\r
-FindChildNode (\r
-  IN     CORE_SECTION_STREAM_NODE                   *SourceStream,\r
-  IN     EFI_SECTION_TYPE                           SearchType,\r
-  IN OUT UINTN                                      *SectionInstance,\r
-  IN     EFI_GUID                                   *SectionDefinitionGuid,\r
-  OUT    CORE_SECTION_CHILD_NODE                    **FoundChild,\r
-  OUT    CORE_SECTION_STREAM_NODE                   **FoundStream,\r
-  OUT    UINT32                                     *AuthenticationStatus\r
-  );\r
-  \r
-/**\r
-  Worker function.  Constructor for new child nodes.\r
-\r
-  @param Stream                Indicates the section stream in which to add the child.\r
-  @param ChildOffset           Indicates the offset in Stream that is the beginning\r
-                               of the child section.\r
-  @param ChildNode             Indicates the Callee allocated and initialized child.\r
-\r
-  @retval EFI_SUCCESS          Child node was found and returned.\r
-  @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
-  @retval EFI_PROTOCOL_ERROR   Encapsulation sections produce new stream handles when\r
-                               the child node is created.  If the section type is GUID\r
-                               defined, and the extraction GUID does not exist, and\r
-                               producing the stream requires the GUID, then a protocol\r
-                               error is generated and no child is produced.\r
-                               Values returned by OpenSectionStreamEx.\r
-\r
-**/\r
-EFI_STATUS\r
-CreateChildNode (\r
-  IN     CORE_SECTION_STREAM_NODE              *Stream,\r
-  IN     UINT32                                ChildOffset,\r
-     OUT CORE_SECTION_CHILD_NODE               **ChildNode\r
-  );\r
-  \r
-/**\r
-  Worker function.  Destructor for child nodes.\r
-\r
-  @param ChildNode           Indicates the node to destroy\r
-\r
-**/\r
-VOID\r
-FreeChildNode (\r
-  IN  CORE_SECTION_CHILD_NODE                   *ChildNode\r
-  );\r
-  \r
-/**\r
-  Worker function.  Constructor for section streams.\r
-\r
-  @param SectionStreamLength   Size in bytes of the section stream.\r
-  @param SectionStream         Buffer containing the new section stream.\r
-  @param AllocateBuffer        Indicates whether the stream buffer is to be copied\r
-                               or the input buffer is to be used in place.\r
-  @param AuthenticationStatus  Indicates the default authentication status for the\r
-                               new stream.\r
-  @param SectionStreamHandle   A pointer to a caller allocated section stream handle.\r
-\r
-  @retval EFI_SUCCESS           Stream was added to stream database.\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
-\r
-**/\r
-EFI_STATUS\r
-OpenSectionStreamEx (\r
-  IN     UINTN                                     SectionStreamLength,\r
-  IN     VOID                                      *SectionStream,\r
-  IN     BOOLEAN                                   AllocateBuffer,\r
-  IN     UINT32                                    AuthenticationStatus,   \r
-     OUT UINTN                                     *SectionStreamHandle\r
-  );\r
-  \r
-/**\r
-\r
-  Check if a stream is valid.\r
-\r
-  @param SectionStream         The section stream to be checked\r
-  @param SectionStreamLength   The length of section stream\r
-\r
-  @return The validness of a stream.\r
-\r
-**/\r
-BOOLEAN\r
-IsValidSectionStream (\r
-  IN  VOID              *SectionStream,\r
-  IN  UINTN             SectionStreamLength\r
-  );\r
-\r
-#endif  // _SECTION_EXTRACTION_H_\r
index c250c0c92ef883dcabc0a574fe2942d93cfed665..55980c920fd8680b5215894bb6f41ce7038183b6 100644 (file)
@@ -1,11 +1,12 @@
 #/** @file\r
 #  \r
-#  Section Extraction Dxe Driver.\r
-#    \r
-#  Section Extraction Protocol implementation as defined in Intel Framework\r
-#  Specification. \r
+#  Section Extraction Dxe Driver produces framework section extract protocol.\r
+#\r
+#  The section is implemented as a linked list of section streams,\r
+#  where each stream contains a linked list of children, which may be leaves or\r
+#  encapsulations. Encapsulation section will further generate new section stream entries.\r
 #  \r
-#  Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+#  Copyright (c) 2006 - 2009, 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
@@ -23,7 +24,7 @@
   MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
   ENTRY_POINT                    = SectionExtractionEntryPoint  \r
-  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
 \r
 [Sources]\r
   SectionExtraction.c\r
-  SectionExtraction.h\r
 \r
 [LibraryClasses]\r
   UefiBootServicesTableLib\r
   MemoryAllocationLib\r
-  UefiLib\r
   DebugLib\r
   BaseLib\r
   BaseMemoryLib\r
   IntelFrameworkPkg/IntelFrameworkPkg.dec\r
 \r
 [Protocols]\r
-  gEfiSectionExtractionProtocolGuid    # ALWAYS_PRODUCED\r
-  gEfiDecompressProtocolGuid           # ALWAYS_CONSUMED\r
+  gEfiSectionExtractionProtocolGuid    ## PRODUCEDS\r
+  gEfiDecompressProtocolGuid           ## CONSUMEDS\r
 \r
 [Depex]\r
-  TRUE
\ No newline at end of file
+  gEfiDecompressProtocolGuid\r
+  \r
+  
\ No newline at end of file