]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Contributed-under: TianoCore Contribution Agreement 1.0
authorMichael Kinney <michael.d.kinney@intel.com>
Thu, 14 Aug 2014 06:29:07 +0000 (06:29 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 14 Aug 2014 06:29:07 +0000 (06:29 +0000)
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
Add support for RSA 2048 SHA 256 signing and verification encoded in a PI FFS GUIDED Encapsulation Section.  The primary use case of this feature is in support of signing and verification of encapsulated FVs for Recovery and Capsule Update, but can potentially be used for signing and verification of any content that can be stored in a PI conformant FFS file.  Signing operations are performed from python scripts that wrap OpenSsl command line utilities.  Verification operations are performed using the OpenSsl libraries in the CryptoPkg.

The guided encapsulation sections uses the UEFI 2.4 Specification defined GUID called EFI_CERT_TYPE_RSA2048_SHA256_GUID.  The data layout for the encapsulation section starts with the UEFI 2.4 Specification defined structure called EFI_CERT_BLOCK_RSA_2048_SHA256 followed immediately by the data.  The signing tool included in these patches performs encode/decode operations using this data layout.  HashType is set to the UEFI 2.4 Specification defined GUID called EFI_HASH_ALGORITHM_SHA256_GUID.

MdePkg/Include/Guid/WinCertificate.h
=================================
//
// WIN_CERTIFICATE_UEFI_GUID.CertType
//
#define EFI_CERT_TYPE_RSA2048_SHA256_GUID \
  {0xa7717414, 0xc616, 0x4977, {0x94, 0x20, 0x84, 0x47, 0x12, 0xa7, 0x35, 0xbf } }

///
/// WIN_CERTIFICATE_UEFI_GUID.CertData
///
typedef struct {
  EFI_GUID  HashType;
  UINT8     PublicKey[256];
  UINT8     Signature[256];
} EFI_CERT_BLOCK_RSA_2048_SHA256;

MdePkg/Include/Protocol/Hash.h
=================================
#define EFI_HASH_ALGORITHM_SHA256_GUID \
  { \
    0x51aa59de, 0xfdf2, 0x4ea3, {0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } \
  }

The verification operations require the use of public key(s).  A new PCD called gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer is added to the SecurityPkg that supports one or more SHA 256 hashes of the public keys.  A SHA 256 hash is performed to minimize the FLASH overhead of storing the public keys.  When a verification operation is performed, a SHA 256 hash is performed on EFI_CERT_BLOCK_RSA_2048_SHA256.PublicKey and a check is made to see if that hash matches any of the hashes in the new PCD.  It is recommended that this PCD always be configured in the DSC file as storage type of [PcdsDynamixExVpd], so the public keys are stored in a protected read-only region.

While working on this feature, I noticed that the CRC32 signing and verification feature was incomplete.  It only supported CRC32 based verification in the DXE Phase, so the attached patches also provide support for CRC32 based verification in the PEI Phase.

I also noticed that the most common method for incorporating guided section extraction libraries was to directly link them to the DXE Core, which is not very flexible.  The attached patches also add a generic section extraction PEIM and a generic section extraction DXE driver that can each be linked against one or more section extraction libraries.  This provides a platform developer with the option of providing section extraction services with the DXE Core or providing section extraction services with these generic PEIM/DXE Drivers.

Patch Summary
==============
1) BaseTools - Rsa2049Sha256Sign python script that can perform test signing or custom signing of PI FFS file GUIDed sections
  a. Wrapper for a set of OpenSsl command line utility operations
  b. OpenSsl command line tool must be installed in location that is in standard OS path or in path specified by OS environment variable called OPENSSL_PATH
  c. Provides standard EDK II command line arguments for a tool that encodes/decodes guided encapsulation section

Rsa2048Sha256Sign - Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
usage: Rsa2048Sha256Sign -e|-d [options] <input_file>

positional arguments:
  input_file            specify the input filename

optional arguments:
  -e                    encode file
  -d                    decode file
  -o filename, --output filename
                        specify the output filename
  --private-key PRIVATEKEYFILE
                        specify the private key filename. If not specified, a
                        test signing key is used.
  -v, --verbose         increase output messages
  -q, --quiet           reduce output messages
  --debug [0-9]         set debug level
  --version             display the program version and exit
  -h, --help            display this help text

2) BaseTools - Rsa2049Sha256GenerateKeys python script that can generate new private/public key and PCD value that is SHA 256 hash of public key using OpenSsl command line utilities.
  a. Wrapper for a set of OpenSsl command line utility operations
  b. OpenSsl command line tool must be installed in location that is in standard path or in path specified by OS environment variable called OPENSSL_PATH

Rsa2048Sha256GenerateKeys - Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
usage: Rsa2048Sha256GenerateKeys [options]

optional arguments:
  -o [filename [filename ...]], --output [filename [filename ...]]
                        specify the output private key filename in PEM format
  -i [filename [filename ...]], --input [filename [filename ...]]
                        specify the input private key filename in PEM format
  --public-key-hash PUBLICKEYHASHFILE
                        specify the public key hash filename that is SHA 256
                        hash of 2048 bit RSA public key in binary format
  --public-key-hash-c PUBLICKEYHASHCFILE
                        specify the public key hash filename that is SHA 256
                        hash of 2048 bit RSA public key in C structure format
  -v, --verbose         increase output messages
  -q, --quiet           reduce output messages
  --debug [0-9]         set debug level
  --version             display the program version and exit
  -h, --help            display this help text

3) BaseTools\Conf\tools_def.template
  a. Define GUID/Tool to perform RSA 2048 SHA 256 test signing and instructions on how to use alternate private/public key
b. GUID is EFI_CERT_TYPE_RSA2048_SHA256_GUID
  c. Tool is Rsa2049Sha256Sign
4) MdeModulePkg\Library\PeiCrc32GuidedSectionExtractionLib
  a. Add peer for DxeCrc32GuidedSectionExtractionLib so both PEI and DXE phases can perform basic integrity checks of PEI and DXE components
5) MdeModulePkg\Universal\SectionExtractionPei
  a. Generic PEIM that can link against one or more NULL section extraction library instances to provided one or more GUIDED Section Extraction PPIs
6) MdeModulePkg\Universal\SectionExtractionDxe
  a. Generic DXE Driver that can link against one or more NULL section extraction library instances to provide one or more GUIDED Section Extraction Protocols.
7) SecurityPkg\Library\PeiRsa2048Sha256GuidedSectionExtractLib
  a. NULL library instances that performs PEI phase RSA 2048 SHA 256 signature verification using OpenSsl libraries from CryptoPkg.
  b. Based on algorithms from SecurityPkg Authenticated Variable services
  c. Uses public key from gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer.
8) SecurityPkg\Library\DxeRsa2048Sha256GuidedSectionExtractLib
  a. NULL library instances that performs DXE phase RSA 2048 SHA 256 signature verification using OpenSsl libraries from CryptoPkg.
  b. Based on algorithms from SecurityPkg Authenticated Variable services
  c. Uses public key from gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer.

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15799 6f19259b-4bc3-4df7-8a09-765794883524

12 files changed:
MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c [new file with mode: 0644]
MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf [new file with mode: 0644]
MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.uni [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.c [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.inf [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeExtra.uni [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeModStrs.uni [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.inf [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiExtra.uni [new file with mode: 0644]
MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiModStrs.uni [new file with mode: 0644]

diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.c
new file mode 100644 (file)
index 0000000..6e3dcdd
--- /dev/null
@@ -0,0 +1,312 @@
+/** @file\r
+\r
+  This library registers CRC32 guided section handler \r
+  to parse CRC32 encapsulation section and extract raw data.\r
+\r
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/Crc32GuidedSectionExtraction.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+///\r
+/// CRC32 Guided Section header\r
+///\r
+typedef struct {\r
+  EFI_GUID_DEFINED_SECTION  GuidedSectionHeader; ///< EFI guided section header\r
+  UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
+} CRC32_SECTION_HEADER;\r
+\r
+typedef struct {\r
+  EFI_GUID_DEFINED_SECTION2 GuidedSectionHeader; ///< EFI guided section header\r
+  UINT32                    CRC32Checksum;       ///< 32bit CRC check sum\r
+} CRC32_SECTION2_HEADER;\r
+\r
+/**\r
+  This internal function reverses bits for 32bit data.\r
+\r
+  @param  Value                 The data to be reversed.\r
+\r
+  @return                       Data reversed.\r
+\r
+**/\r
+UINT32\r
+PeiCrc32GuidedSectionExtractLibReverseBits (\r
+  UINT32  Value\r
+  )\r
+{\r
+  UINTN   Index;\r
+  UINT32  NewValue;\r
+\r
+  NewValue = 0;\r
+  for (Index = 0; Index < 32; Index++) {\r
+    if ((Value & (1 << Index)) != 0) {\r
+      NewValue = NewValue | (1 << (31 - Index));\r
+    }\r
+  }\r
+\r
+  return NewValue;\r
+}\r
+\r
+/**\r
+  Calculate CRC32 for target data.\r
+\r
+  @param  Data                  The target data.\r
+  @param  DataSize              The target data size.\r
+  @param  CrcOut                The CRC32 for target data.\r
+\r
+  @retval EFI_SUCCESS           The CRC32 for target data is calculated successfully.\r
+  @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not\r
+                                calculated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiCrc32GuidedSectionExtractLibCalculateCrc32 (\r
+  IN  VOID    *Data,\r
+  IN  UINTN   DataSize,\r
+  OUT UINT32  *CrcOut\r
+  )\r
+{\r
+  UINT32  CrcTable[256];\r
+  UINTN   TableEntry;\r
+  UINTN   Index;\r
+  UINT32  Value;\r
+  UINT32  Crc;\r
+  UINT8   *Ptr;\r
+\r
+  if (Data == NULL || DataSize == 0 || CrcOut == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Initialize CRC32 table.\r
+  //\r
+  for (TableEntry = 0; TableEntry < 256; TableEntry++) {\r
+    Value = PeiCrc32GuidedSectionExtractLibReverseBits ((UINT32) TableEntry);\r
+    for (Index = 0; Index < 8; Index++) {\r
+      if ((Value & 0x80000000) != 0) {\r
+        Value = (Value << 1) ^ 0x04c11db7;\r
+      } else {\r
+        Value = Value << 1;\r
+      }\r
+    }\r
+    CrcTable[TableEntry] = PeiCrc32GuidedSectionExtractLibReverseBits (Value);\r
+  }\r
+\r
+  //\r
+  // Compute CRC\r
+  //\r
+  Crc = 0xffffffff;\r
+  for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {\r
+    Crc = (Crc >> 8) ^ CrcTable[(UINT8) Crc ^ *Ptr];\r
+  }\r
+\r
+  *CrcOut = Crc ^ 0xffffffff;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  GetInfo gets raw data size and attribute of the input guided section.\r
+  It first checks whether the input guid section is supported. \r
+  If not, EFI_INVALID_PARAMETER will return.\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 EFI_SUCCESS            The size of destination buffer, the size of scratch buffer and \r
+                                 the attribute of the input section are successull retrieved.\r
+  @retval EFI_INVALID_PARAMETER  The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Crc32GuidedSectionGetInfo (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT UINT32      *OutputBufferSize,\r
+  OUT UINT32      *ScratchBufferSize,\r
+  OUT UINT16      *SectionAttribute\r
+  )\r
+{\r
+  if (IS_SECTION2 (InputSection)) {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Retrieve the size and attribute of the input section data.\r
+    //\r
+    *SectionAttribute  = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
+    *ScratchBufferSize = 0;\r
+    *OutputBufferSize  = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+  } else {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Retrieve the size and attribute of the input section data.\r
+    //\r
+    *SectionAttribute  = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+    *ScratchBufferSize = 0;\r
+    *OutputBufferSize  = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  Extraction handler tries to extract raw data from the input guided section.\r
+  It also does authentication check for 32bit CRC value in the input guided section.\r
+  It first checks whether the input guid section is supported. \r
+  If not, EFI_INVALID_PARAMETER will return.\r
+\r
+  @param InputSection    Buffer containing the input GUIDed section to be processed.\r
+  @param OutputBuffer    Buffer to contain the output raw data 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 EFI_SUCCESS            Section Data and Auth Status is extracted successfully.\r
+  @retval EFI_INVALID_PARAMETER  The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Crc32GuidedSectionHandler (\r
+  IN CONST  VOID    *InputSection,\r
+  OUT       VOID    **OutputBuffer,\r
+  IN        VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       UINT32  *AuthenticationStatus\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT32      SectionCrc32Checksum;\r
+  UINT32      Crc32Checksum;\r
+  UINT32      OutputBufferSize;\r
+\r
+  if (IS_SECTION2 (InputSection)) {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  \r
+    //\r
+    // Get section Crc32 checksum.\r
+    //\r
+    SectionCrc32Checksum = ((CRC32_SECTION2_HEADER *) InputSection)->CRC32Checksum;\r
+    *OutputBuffer      = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+    OutputBufferSize   = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+\r
+    //\r
+    // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set\r
+    //\r
+    ASSERT (((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
+    *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
+  } else {\r
+    //\r
+    // Check whether the input guid section is recognized.\r
+    //\r
+    if (!CompareGuid (\r
+        &gEfiCrc32GuidedSectionExtractionGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  \r
+    //\r
+    // Get section Crc32 checksum.\r
+    //\r
+    SectionCrc32Checksum = ((CRC32_SECTION_HEADER *) InputSection)->CRC32Checksum;\r
+    *OutputBuffer      = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+    OutputBufferSize   = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+\r
+    //\r
+    // Implicitly CRC32 GUIDed section should have STATUS_VALID bit set\r
+    //\r
+    ASSERT (((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
+    *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
+  }\r
+\r
+  //\r
+  // Init Checksum value to Zero.\r
+  //\r
+  Crc32Checksum = 0;\r
+\r
+  //\r
+  // Calculate CRC32 Checksum of Image\r
+  //\r
+  Status = PeiCrc32GuidedSectionExtractLibCalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
+  if (Status == EFI_SUCCESS) {\r
+    if (Crc32Checksum != SectionCrc32Checksum) {\r
+      //\r
+      // If Crc32 checksum is not matched, AUTH tested failed bit is set.\r
+      //\r
+      *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;\r
+    }\r
+  } else {\r
+    //\r
+    // If Crc32 checksum is not calculated, AUTH not tested bit is set.\r
+    //\r
+    *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;\r
+  }\r
+\r
+  //\r
+  // Temp solution until PeiCore checks AUTH Status.\r
+  //\r
+  if ((*AuthenticationStatus & (EFI_AUTH_STATUS_TEST_FAILED | EFI_AUTH_STATUS_NOT_TESTED)) != 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Register the handler to extract CRC32 guided section.\r
+\r
+  @param  FileHandle   The handle of FFS header the loaded driver.\r
+  @param  PeiServices  The pointer to the PEI services.\r
+\r
+  @retval  EFI_SUCCESS           Register successfully.\r
+  @retval  EFI_OUT_OF_RESOURCES  Not enough memory to register this handler.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiCrc32GuidedSectionExtractLibConstructor (\r
+  IN EFI_PEI_FILE_HANDLE        FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  return ExtractGuidedSectionRegisterHandlers (\r
+          &gEfiCrc32GuidedSectionExtractionGuid,\r
+          Crc32GuidedSectionGetInfo,\r
+          Crc32GuidedSectionHandler\r
+          );\r
+}\r
diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf
new file mode 100644 (file)
index 0000000..0ecda91
--- /dev/null
@@ -0,0 +1,46 @@
+## @file\r
+#  This library doesn't produce any library class. The constructor function uses \r
+#  ExtractGuidedSectionLib service to register CRC32 guided section handler\r
+#  that parses CRC32 encapsulation section and extracts raw data.\r
+#\r
+# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiCrc32GuidedSectionExtractLib\r
+  FILE_GUID                      = 1EBE57F5-BE42-45f0-A1F9-FA3DC633910B\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = NULL|PEI_CORE PEIM\r
+  CONSTRUCTOR                    = PeiCrc32GuidedSectionExtractLibConstructor\r
+  MODULE_UNI_FILE                = PeiCrc32GuidedSectionExtractLib.uni\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC (EBC is for build only)\r
+#\r
+\r
+[Sources]\r
+  PeiCrc32GuidedSectionExtractLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  ExtractGuidedSectionLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+\r
+[Guids]\r
+  gEfiCrc32GuidedSectionExtractionGuid             ## PRODUCES ## UNDEFINED\r
diff --git a/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.uni b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.uni
new file mode 100644 (file)
index 0000000..6c4ec22
Binary files /dev/null and b/MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.uni differ
index fd32551d77258d12ad52222a6139448a7ebb0ab5..60edd99d9e77882458ef35bd86fb1680df59cd77 100644 (file)
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf\r
   MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf\r
   MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.inf\r
+  MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf\r
   MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf\r
   MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf\r
   MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf\r
   }\r
   MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf\r
   MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf\r
-\r
+  MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.inf {\r
+    <LibraryClasses>\r
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf\r
+  }\r
+  MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.inf {\r
+    <LibraryClasses>\r
+      NULL|MdeModulePkg/Library/PeiCrc32GuidedSectionExtractLib/PeiCrc32GuidedSectionExtractLib.inf\r
+  }\r
+  \r
 [Components.IA32, Components.X64, Components.IPF]\r
   MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf\r
   MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf\r
diff --git a/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.c b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.c
new file mode 100644 (file)
index 0000000..0cdfdef
--- /dev/null
@@ -0,0 +1,280 @@
+/** @file\r
+ Section Extraction DXE Driver\r
+\r
+Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/GuidedSectionExtraction.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Function prototype for Section Extraction Protocol service\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+CustomGuidedSectionExtract (\r
+  IN CONST  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+  IN CONST  VOID                                   *InputSection,\r
+  OUT       VOID                                   **OutputBuffer,\r
+  OUT       UINTN                                  *OutputSize,\r
+  OUT       UINT32                                 *AuthenticationStatus\r
+  );\r
+\r
+//\r
+// Module global for the Section Extraction Protocol handle\r
+//\r
+EFI_HANDLE mSectionExtractionHandle = NULL;\r
+\r
+//\r
+// Module global for the Section Extraction Protocol instance\r
+//\r
+EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {\r
+  CustomGuidedSectionExtract\r
+};\r
+\r
+/**\r
+  The ExtractSection() function processes the input section and\r
+  allocates a buffer from the pool in which it returns the section\r
+  contents. If the section being extracted contains\r
+  authentication information (the section's\r
+  GuidedSectionHeader.Attributes field has the\r
+  EFI_GUIDED_SECTION_AUTH_STATUS_VALID bit set), the values\r
+  returned in AuthenticationStatus must reflect the results of\r
+  the authentication operation. Depending on the algorithm and\r
+  size of the encapsulated data, the time that is required to do\r
+  a full authentication may be prohibitively long for some\r
+  classes of systems. To indicate this, use\r
+  EFI_SECURITY_POLICY_PROTOCOL_GUID, which may be published by\r
+  the security policy driver (see the Platform Initialization\r
+  Driver Execution Environment Core Interface Specification for\r
+  more details and the GUID definition). If the\r
+  EFI_SECURITY_POLICY_PROTOCOL_GUID exists in the handle\r
+  database, then, if possible, full authentication should be\r
+  skipped and the section contents simply returned in the\r
+  OutputBuffer. In this case, the\r
+  EFI_AUTH_STATUS_PLATFORM_OVERRIDE bit AuthenticationStatus\r
+  must be set on return. ExtractSection() is callable only from\r
+  TPL_NOTIFY and below. Behavior of ExtractSection() at any\r
+  EFI_TPL above TPL_NOTIFY is undefined. Type EFI_TPL is\r
+  defined in RaiseTPL() in the UEFI 2.0 specification.\r
+\r
+\r
+  @param This         Indicates the\r
+                      EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL instance.\r
+  @param InputSection Buffer containing the input GUIDed section\r
+                      to be processed. OutputBuffer OutputBuffer\r
+                      is allocated from boot services pool\r
+                      memory and contains the new section\r
+                      stream. The caller is responsible for\r
+                      freeing this buffer.\r
+  @param OutputBuffer *OutputBuffer is allocated from boot services\r
+                      pool memory and contains the new section stream.\r
+                      The caller is responsible for freeing this buffer.\r
+  @param OutputSize   A pointer to a caller-allocated UINTN in\r
+                      which the size of OutputBuffer allocation\r
+                      is stored. If the function returns\r
+                      anything other than EFI_SUCCESS, the value\r
+                      of OutputSize is undefined.\r
+\r
+  @param AuthenticationStatus A pointer to a caller-allocated\r
+                              UINT32 that indicates the\r
+                              authentication status of the\r
+                              output buffer. If the input\r
+                              section's\r
+                              GuidedSectionHeader.Attributes\r
+                              field has the\r
+                              EFI_GUIDED_SECTION_AUTH_STATUS_VAL\r
+                              bit as clear, AuthenticationStatus\r
+                              must return zero. Both local bits\r
+                              (19:16) and aggregate bits (3:0)\r
+                              in AuthenticationStatus are\r
+                              returned by ExtractSection().\r
+                              These bits reflect the status of\r
+                              the extraction operation. The bit\r
+                              pattern in both regions must be\r
+                              the same, as the local and\r
+                              aggregate authentication statuses\r
+                              have equivalent meaning at this\r
+                              level. If the function returns\r
+                              anything other than EFI_SUCCESS,\r
+                              the value of AuthenticationStatus\r
+                              is undefined.\r
+\r
+\r
+  @retval EFI_SUCCESS          The InputSection was successfully\r
+                               processed and the section contents were\r
+                               returned.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES The system has insufficient\r
+                               resources to process the\r
+                               request.\r
+\r
+  @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r
+                                not match this instance of the\r
+                                GUIDed Section Extraction\r
+                                Protocol.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CustomGuidedSectionExtract (\r
+  IN CONST  EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
+  IN CONST  VOID                                   *InputSection,\r
+  OUT       VOID                                   **OutputBuffer,\r
+  OUT       UINTN                                  *OutputSize,\r
+  OUT       UINT32                                 *AuthenticationStatus\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  VOID            *ScratchBuffer;\r
+  VOID            *AllocatedOutputBuffer;\r
+  UINT32          OutputBufferSize;\r
+  UINT32          ScratchBufferSize;\r
+  UINT16          SectionAttribute;\r
+\r
+  //\r
+  // Init local variable\r
+  //\r
+  ScratchBuffer         = NULL;\r
+  AllocatedOutputBuffer = NULL;\r
+\r
+  //\r
+  // Call GetInfo to get the size and attribute of input guided section data.\r
+  //\r
+  Status = ExtractGuidedSectionGetInfo (\r
+             InputSection,\r
+             &OutputBufferSize,\r
+             &ScratchBufferSize,\r
+             &SectionAttribute\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  if (ScratchBufferSize > 0) {\r
+    //\r
+    // Allocate scratch buffer\r
+    //\r
+    ScratchBuffer = AllocatePool (ScratchBufferSize);\r
+    if (ScratchBuffer == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  if (OutputBufferSize > 0) {\r
+    //\r
+    // Allocate output buffer\r
+    //\r
+    AllocatedOutputBuffer = AllocatePool (OutputBufferSize);\r
+    if (AllocatedOutputBuffer == NULL) {\r
+      FreePool (ScratchBuffer);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    *OutputBuffer = AllocatedOutputBuffer;\r
+  }\r
+\r
+  //\r
+  // Call decode function to extract raw data from the guided section.\r
+  //\r
+  Status = ExtractGuidedSectionDecode (\r
+             InputSection,\r
+             OutputBuffer,\r
+             ScratchBuffer,\r
+             AuthenticationStatus\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Decode failed\r
+    //\r
+    if (AllocatedOutputBuffer != NULL) {\r
+      FreePool (AllocatedOutputBuffer);\r
+    }\r
+    if (ScratchBuffer != NULL) {\r
+      FreePool (ScratchBuffer);\r
+    }\r
+    DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  if (*OutputBuffer != AllocatedOutputBuffer) {\r
+    //\r
+    // OutputBuffer was returned as a different value,\r
+    // so copy section contents to the allocated memory buffer.\r
+    //\r
+    CopyMem (AllocatedOutputBuffer, *OutputBuffer, OutputBufferSize);\r
+    *OutputBuffer = AllocatedOutputBuffer;\r
+  }\r
+\r
+  //\r
+  // Set real size of output buffer.\r
+  //\r
+  *OutputSize = (UINTN) OutputBufferSize;\r
+\r
+  //\r
+  // Free unused scratch buffer.\r
+  //\r
+  if (ScratchBuffer != NULL) {\r
+    FreePool (ScratchBuffer);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Main entry for the Section Extraction DXE module.\r
+\r
+  This routine registers the Section Extraction Protocols that have been registered \r
+  with the Section Extraction Library.\r
+  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SectionExtractionDxeEntry (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_GUID    *ExtractHandlerGuidTable;\r
+  UINTN       ExtractHandlerNumber;\r
+\r
+  //\r
+  // Get custom extract guided section method guid list\r
+  //\r
+  ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r
+\r
+  //\r
+  // Install custom guided extraction protocol\r
+  //\r
+  while (ExtractHandlerNumber-- > 0) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mSectionExtractionHandle,\r
+                    &ExtractHandlerGuidTable [ExtractHandlerNumber], &mCustomGuidedSectionExtractionProtocol,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.inf b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxe.inf
new file mode 100644 (file)
index 0000000..dfabe23
--- /dev/null
@@ -0,0 +1,48 @@
+## @file\r
+# Section Extraction DXE Driver\r
+#\r
+# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SectionExtractionDxe\r
+  FILE_GUID                      = A0E8E04C-9B5A-43be-8B7D-C98760492B68\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SectionExtractionDxeEntry\r
+  MODULE_UNI_FILE                = SectionExtractionDxeModStrs.uni\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  SectionExtractionDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  ExtractGuidedSectionLib\r
+\r
+[Depex]\r
+  TRUE\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  SectionExtractionDxeExtra.uni\r
diff --git a/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeExtra.uni b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeExtra.uni
new file mode 100644 (file)
index 0000000..3584435
Binary files /dev/null and b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeExtra.uni differ
diff --git a/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeModStrs.uni b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeModStrs.uni
new file mode 100644 (file)
index 0000000..66c413e
Binary files /dev/null and b/MdeModulePkg/Universal/SectionExtractionDxe/SectionExtractionDxeModStrs.uni differ
diff --git a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c
new file mode 100644 (file)
index 0000000..55c9224
--- /dev/null
@@ -0,0 +1,223 @@
+/** @file\r
+ Section Extraction PEIM\r
+\r
+Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Ppi/GuidedSectionExtraction.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+//\r
+// Function prototype for Section Extraction PPI service\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+CustomGuidedSectionExtract (\r
+  IN CONST  EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r
+  IN CONST  VOID                                  *InputSection,\r
+  OUT       VOID                                  **OutputBuffer,\r
+  OUT       UINTN                                 *OutputSize,\r
+  OUT       UINT32                                *AuthenticationStatus\r
+  );\r
+\r
+//\r
+// Module global for the Section Extraction PPI instance\r
+//\r
+CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r
+  CustomGuidedSectionExtract\r
+};\r
+\r
+/**\r
+  The ExtractSection() function processes the input section and\r
+  returns a pointer to the section contents. If the section being\r
+  extracted does not require processing (if the section\r
+  GuidedSectionHeader.Attributes has the\r
+  EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r
+  OutputBuffer is just updated to point to the start of the\r
+  section's contents. Otherwise, *Buffer must be allocated\r
+  from PEI permanent memory.\r
+\r
+  @param This                   Indicates the\r
+                                EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r
+                                Buffer containing the input GUIDed section to be\r
+                                processed. OutputBuffer OutputBuffer is\r
+                                allocated from PEI permanent memory and contains\r
+                                the new section stream.\r
+  @param InputSection           A pointer to the input buffer, which contains\r
+                                the input section to be processed.\r
+  @param OutputBuffer           A pointer to a caller-allocated buffer, whose\r
+                                size is specified by the contents of OutputSize.\r
+  @param OutputSize             A pointer to a caller-allocated\r
+                                UINTN in which the size of *OutputBuffer\r
+                                allocation is stored. If the function\r
+                                returns anything other than EFI_SUCCESS,\r
+                                the value of OutputSize is undefined.\r
+  @param AuthenticationStatus   A pointer to a caller-allocated\r
+                                UINT32 that indicates the\r
+                                authentication status of the\r
+                                output buffer. If the input\r
+                                section's GuidedSectionHeader.\r
+                                Attributes field has the\r
+                                EFI_GUIDED_SECTION_AUTH_STATUS_VALID \r
+                                bit as clear,\r
+                                AuthenticationStatus must return\r
+                                zero. These bits reflect the\r
+                                status of the extraction\r
+                                operation. If the function\r
+                                returns anything other than\r
+                                EFI_SUCCESS, the value of\r
+                                AuthenticationStatus is\r
+                                undefined.\r
+  \r
+  @retval EFI_SUCCESS           The InputSection was\r
+                                successfully processed and the\r
+                                section contents were returned.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES  The system has insufficient\r
+                                resources to process the request.\r
+  \r
+  @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r
+                                not match this instance of the\r
+                                GUIDed Section Extraction PPI.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CustomGuidedSectionExtract (\r
+  IN CONST  EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r
+  IN CONST  VOID                                  *InputSection,\r
+  OUT       VOID                                  **OutputBuffer,\r
+  OUT       UINTN                                 *OutputSize,\r
+  OUT       UINT32                                *AuthenticationStatus\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UINT8           *ScratchBuffer;\r
+  UINT32          ScratchBufferSize;\r
+  UINT32          OutputBufferSize;\r
+  UINT16          SectionAttribute;\r
+  \r
+  //\r
+  // Init local variable\r
+  //\r
+  ScratchBuffer = NULL;\r
+\r
+  //\r
+  // Call GetInfo to get the size and attribute of input guided section data.\r
+  //\r
+  Status = ExtractGuidedSectionGetInfo (\r
+             InputSection,\r
+             &OutputBufferSize,\r
+             &ScratchBufferSize,\r
+             &SectionAttribute\r
+             );\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+  \r
+  if (ScratchBufferSize != 0) {\r
+    //\r
+    // Allocate scratch buffer\r
+    //\r
+    ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+    if (ScratchBuffer == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) {  \r
+    //\r
+    // Allocate output buffer\r
+    //\r
+    *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);\r
+    if (*OutputBuffer == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r
+    //\r
+    // *OutputBuffer still is one section. Adjust *OutputBuffer offset, \r
+    // skip EFI section header to make section data at page alignment.\r
+    //\r
+    *OutputBuffer = (VOID *)((UINT8 *) *OutputBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER));\r
+  }\r
+  \r
+  Status = ExtractGuidedSectionDecode (\r
+             InputSection, \r
+             OutputBuffer,\r
+             ScratchBuffer,\r
+             AuthenticationStatus\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Decode failed\r
+    //\r
+    DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r
+    return Status;\r
+  }\r
+  \r
+  *OutputSize = (UINTN) OutputBufferSize;\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Main entry for Section Extraction PEIM driver.\r
+  \r
+  This routine registers the Section Extraction PPIs that have been registered \r
+  with the Section Extraction Library.\r
+\r
+  @param  FileHandle  Handle of the file being invoked.\r
+  @param  PeiServices Describes the list of possible PEI Services.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SectionExtractionPeiEntry (\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  ) \r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_GUID                *ExtractHandlerGuidTable;\r
+  UINTN                   ExtractHandlerNumber;\r
+  EFI_PEI_PPI_DESCRIPTOR  *GuidPpi;\r
+\r
+  //\r
+  // Get custom extract guided section method guid list \r
+  //\r
+  ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r
+  \r
+  //\r
+  // Install custom extraction guid PPI\r
+  //\r
+  if (ExtractHandlerNumber > 0) {\r
+    GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
+    ASSERT (GuidPpi != NULL);\r
+    while (ExtractHandlerNumber-- > 0) {\r
+      GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
+      GuidPpi->Ppi   = (VOID *) &mCustomGuidedSectionExtractionPpi;\r
+      GuidPpi->Guid  = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r
+      Status = PeiServicesInstallPpi (GuidPpi++);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.inf b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.inf
new file mode 100644 (file)
index 0000000..92a4474
--- /dev/null
@@ -0,0 +1,49 @@
+## @file\r
+# Section Extraction PEI Module\r
+#\r
+# Produce one or more Section Extraction PPIs.\r
+#\r
+# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SectionExtractionPei\r
+  FILE_GUID                      = EED5EA31-38E2-463d-B623-2C57702B8A1C\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SectionExtractionPeiEntry\r
+  MODULE_UNI_FILE                = SectionExtractionPeiModStrs.uni\r
+\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
+\r
+[Sources]\r
+  SectionExtractionPei.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  PeimEntryPoint\r
+  ExtractGuidedSectionLib\r
+  DebugLib\r
+  MemoryAllocationLib\r
+  PeiServicesLib\r
+  \r
+[Depex]\r
+  gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  SectionExtractionPeiExtra.uni\r
diff --git a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiExtra.uni b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiExtra.uni
new file mode 100644 (file)
index 0000000..99472a3
Binary files /dev/null and b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiExtra.uni differ
diff --git a/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiModStrs.uni b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiModStrs.uni
new file mode 100644 (file)
index 0000000..e28aee9
Binary files /dev/null and b/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPeiModStrs.uni differ