diff options
7 files changed, 366 insertions, 17 deletions
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c index 8e502b0fdb..28b4bf9d8b 100644 --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c @@ -1,19 +1,12 @@ /** @file
UEFI Decompress Library implementation refer to UEFI specification.
- Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
-#include <Base.h>
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiDecompressLib.h>
-
#include "BaseUefiDecompressLibInternals.h"
/**
@@ -734,12 +727,14 @@ UefiDecompressGetInfo ( If Source is NULL, then ASSERT().
If Destination is NULL, then ASSERT().
If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
+ If the Version is not 1 or 2, then ASSERT().
@param Source The source buffer containing the compressed data.
@param Destination The destination buffer to store the decompressed data.
@param Scratch A temporary scratch buffer that is used to perform the decompression.
This is an optional parameter that may be NULL if the
required scratch buffer size is 0.
+ @param Version 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm.
@retval RETURN_SUCCESS Decompression completed successfully, and
the uncompressed buffer is returned in Destination.
@@ -748,11 +743,11 @@ UefiDecompressGetInfo ( (not in a valid compressed format).
**/
RETURN_STATUS
-EFIAPI
-UefiDecompress (
+UefiTianoDecompress (
IN CONST VOID *Source,
IN OUT VOID *Destination,
- IN OUT VOID *Scratch OPTIONAL
+ IN OUT VOID *Scratch,
+ IN UINT32 Version
)
{
UINT32 CompSize;
@@ -764,6 +759,7 @@ UefiDecompress ( ASSERT (Source != NULL);
ASSERT (Destination != NULL);
ASSERT (Scratch != NULL);
+ ASSERT (Version == 1 || Version == 2);
Src = Source;
Dst = Destination;
@@ -786,8 +782,18 @@ UefiDecompress ( //
// The length of the field 'Position Set Code Length Array Size' in Block Header.
// For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
- //
- Sd->mPBit = 4;
+ // For Tiano de/compression algorithm(Version 2), mPBit = 5
+ //
+ switch (Version) {
+ case 1 :
+ Sd->mPBit = 4;
+ break;
+ case 2 :
+ Sd->mPBit = 5;
+ break;
+ default:
+ ASSERT (FALSE);
+ }
Sd->mSrcBase = (UINT8 *)Src;
Sd->mDstBase = Dst;
//
@@ -815,3 +821,43 @@ UefiDecompress ( return RETURN_SUCCESS;
}
+
+/**
+ Decompresses a UEFI compressed source buffer.
+
+ Extracts decompressed data to its original form.
+ This function is designed so that the decompression algorithm can be implemented
+ without using any memory services. As a result, this function is not allowed to
+ call any memory allocation services in its implementation. It is the caller's
+ responsibility to allocate and free the Destination and Scratch buffers.
+ If the compressed source data specified by Source is successfully decompressed
+ into Destination, then RETURN_SUCCESS is returned. If the compressed source data
+ specified by Source is not in a valid compressed data format,
+ then RETURN_INVALID_PARAMETER is returned.
+
+ If Source is NULL, then ASSERT().
+ If Destination is NULL, then ASSERT().
+ If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
+
+ @param Source The source buffer containing the compressed data.
+ @param Destination The destination buffer to store the decompressed data
+ @param Scratch A temporary scratch buffer that is used to perform the decompression.
+ This is an optional parameter that may be NULL if the
+ required scratch buffer size is 0.
+
+ @retval RETURN_SUCCESS Decompression completed successfully, and
+ the uncompressed buffer is returned in Destination.
+ @retval RETURN_INVALID_PARAMETER
+ The source buffer specified by Source is corrupted
+ (not in a valid compressed format).
+**/
+RETURN_STATUS
+EFIAPI
+UefiDecompress (
+ IN CONST VOID *Source,
+ IN OUT VOID *Destination,
+ IN OUT VOID *Scratch OPTIONAL
+ )
+{
+ return UefiTianoDecompress (Source, Destination, Scratch, 1);
+}
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.uni b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.uni index 1cec6bd965..25f379d047 100644 --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.uni +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.uni @@ -3,14 +3,14 @@ //
// UEFI Decompress Library implementation.
//
-// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+// Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
-#string STR_MODULE_ABSTRACT #language en-US "UEFI Decompress Library implementation"
+#string STR_MODULE_ABSTRACT #language en-US "UEFI Decompress Library and Tiano Custom Decompress Library implementation."
-#string STR_MODULE_DESCRIPTION #language en-US "UEFI Decompress Library implementation."
+#string STR_MODULE_DESCRIPTION #language en-US "Tiano custom decompression algorithm shares most of the code with the UEFI Decompress algorithm."
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h index 9821c19c7b..0bfb503337 100644 --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h @@ -1,7 +1,7 @@ /** @file
Internal data structure defintions for Base UEFI Decompress Library.
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -9,6 +9,11 @@ #ifndef __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
#define __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiDecompressLib.h>
//
// Decompression algorithm begins here
//
@@ -58,6 +63,7 @@ typedef struct { ///
/// The length of the field 'Position Set Code Length Array Size' in Block Header.
/// For UEFI 2.0 de/compression algorithm, mPBit = 4.
+ /// For Tiano de/compression algorithm, mPBit = 5.
///
UINT8 mPBit;
} SCRATCH_DATA;
@@ -202,4 +208,40 @@ Decode ( SCRATCH_DATA *Sd
);
+/**
+ Decompresses a compressed source buffer.
+
+ Extracts decompressed data to its original form.
+ This function is designed so that the decompression algorithm can be implemented
+ without using any memory services. As a result, this function is not allowed to
+ call any memory allocation services in its implementation. It is the caller's
+ responsibility to allocate and free the Destination and Scratch buffers.
+ If the compressed source data specified by Source is successfully decompressed
+ into Destination, then RETURN_SUCCESS is returned. If the compressed source data
+ specified by Source is not in a valid compressed data format,
+ then RETURN_INVALID_PARAMETER is returned.
+
+ If Source is NULL, then ASSERT().
+ If Destination is NULL, then ASSERT().
+ If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
+
+ @param Source The source buffer containing the compressed data.
+ @param Destination The destination buffer to store the decompressed data.
+ @param Scratch A temporary scratch buffer that is used to perform the decompression.
+ This is an optional parameter that may be NULL if the
+ required scratch buffer size is 0.
+
+ @retval RETURN_SUCCESS Decompression completed successfully, and
+ the uncompressed buffer is returned in Destination.
+ @retval RETURN_INVALID_PARAMETER
+ The source buffer specified by Source is corrupted
+ (not in a valid compressed format).
+**/
+RETURN_STATUS
+UefiTianoDecompress (
+ IN CONST VOID *Source,
+ IN OUT VOID *Destination,
+ IN OUT VOID *Scratch,
+ IN UINT32 Version
+ );
#endif
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c new file mode 100644 index 0000000000..5a73933d2a --- /dev/null +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c @@ -0,0 +1,213 @@ +/** @file
+ UEFI Decompress Library implementation refer to UEFI specification.
+
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+ Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+#include <Library/ExtractGuidedSectionLib.h>
+#include "BaseUefiDecompressLibInternals.h"
+
+/**
+ Examines a GUIDed section and returns the size of the decoded buffer and the
+ size of an optional scratch buffer required to actually decode the data in a GUIDed section.
+
+ Examines a GUIDed section specified by InputSection.
+ If GUID for InputSection does not match the GUID that this handler supports,
+ then RETURN_UNSUPPORTED is returned.
+ If the required information can not be retrieved from InputSection,
+ then RETURN_INVALID_PARAMETER is returned.
+ If the GUID of InputSection does match the GUID that this handler supports,
+ then the size required to hold the decoded buffer is returned in OututBufferSize,
+ the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
+ from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
+
+ If InputSection is NULL, then ASSERT().
+ If OutputBufferSize is NULL, then ASSERT().
+ If ScratchBufferSize is NULL, then ASSERT().
+ If SectionAttribute is NULL, then ASSERT().
+
+
+ @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
+ @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
+ if the buffer specified by InputSection were decoded.
+ @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
+ if the buffer specified by InputSection were decoded.
+ @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
+ field of EFI_GUID_DEFINED_SECTION in the PI Specification.
+
+ @retval RETURN_SUCCESS The information about InputSection was returned.
+ @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
+ @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
+
+**/
+RETURN_STATUS
+EFIAPI
+TianoDecompressGetInfo (
+ IN CONST VOID *InputSection,
+ OUT UINT32 *OutputBufferSize,
+ OUT UINT32 *ScratchBufferSize,
+ OUT UINT16 *SectionAttribute
+ )
+
+{
+ ASSERT (SectionAttribute != NULL);
+
+ if (InputSection == NULL) {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ if (IS_SECTION2 (InputSection)) {
+ if (!CompareGuid (
+ &gTianoCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
+ }
+ //
+ // Get guid attribute of guid section.
+ //
+ *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;
+
+ //
+ // Call Tiano GetInfo to get the required size info.
+ //
+ return UefiDecompressGetInfo (
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
+ SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
+ OutputBufferSize,
+ ScratchBufferSize
+ );
+ } else {
+ if (!CompareGuid (
+ &gTianoCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
+ }
+ //
+ // Get guid attribute of guid section.
+ //
+ *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
+
+ //
+ // Call Tiano GetInfo to get the required size info.
+ //
+ return UefiDecompressGetInfo (
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
+ SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
+ OutputBufferSize,
+ ScratchBufferSize
+ );
+ }
+}
+
+/**
+ Decompress a Tiano compressed GUIDed section into a caller allocated output buffer.
+
+ Decodes the GUIDed section specified by InputSection.
+ If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
+ If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
+ If the GUID of InputSection does match the GUID that this handler supports, then InputSection
+ is decoded into the buffer specified by OutputBuffer and the authentication status of this
+ decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
+ data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
+ the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
+
+ If InputSection is NULL, then ASSERT().
+ If OutputBuffer is NULL, then ASSERT().
+ If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
+ If AuthenticationStatus is NULL, then ASSERT().
+
+
+ @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
+ @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
+ @param[in] ScratchBuffer A caller allocated buffer that may be required by this function
+ as a scratch buffer to perform the decode operation.
+ @param[out] AuthenticationStatus
+ A pointer to the authentication status of the decoded output buffer.
+ See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
+ section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
+ never be set by this handler.
+
+ @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
+ @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
+ @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
+
+**/
+RETURN_STATUS
+EFIAPI
+TianoDecompress (
+ IN CONST VOID *InputSection,
+ OUT VOID **OutputBuffer,
+ IN VOID *ScratchBuffer, OPTIONAL
+ OUT UINT32 *AuthenticationStatus
+ )
+{
+ ASSERT (OutputBuffer != NULL);
+ ASSERT (InputSection != NULL);
+
+ if (IS_SECTION2 (InputSection)) {
+ if (!CompareGuid (
+ &gTianoCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ //
+ // Set Authentication to Zero.
+ //
+ *AuthenticationStatus = 0;
+
+ //
+ // Call Tiano Decompress to get the raw data
+ //
+ return UefiTianoDecompress (
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
+ *OutputBuffer,
+ ScratchBuffer,
+ 2
+ );
+ } else {
+ if (!CompareGuid (
+ &gTianoCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ //
+ // Set Authentication to Zero.
+ //
+ *AuthenticationStatus = 0;
+
+ //
+ // Call Tiano Decompress to get the raw data
+ //
+ return UefiTianoDecompress (
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
+ *OutputBuffer,
+ ScratchBuffer,
+ 2
+ );
+ }
+}
+
+/**
+ Registers TianoDecompress and TianoDecompressGetInfo handlers with TianoCustomerDecompressGuid
+
+ @retval RETURN_SUCCESS Register successfully.
+ @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
+**/
+RETURN_STATUS
+EFIAPI
+TianoDecompressLibConstructor (
+ VOID
+)
+{
+ return ExtractGuidedSectionRegisterHandlers (
+ &gTianoCustomDecompressGuid,
+ TianoDecompressGetInfo,
+ TianoDecompress
+ );
+}
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf new file mode 100644 index 0000000000..280a5f307d --- /dev/null +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf @@ -0,0 +1,42 @@ +## @file
+# This library instance produces UefiDecompressLib and Tiano Custom decompression algorithm.
+# Tiano custom decompression algorithm shares most of code with Uefi Decompress algorithm.
+#
+# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseUefiTianoCustomDecompressLib
+ MODULE_UNI_FILE = BaseUefiDecompressLib.uni
+ FILE_GUID = d774c4d9-c121-4da3-a5e2-0f317e3c630c
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UefiDecompressLib
+ CONSTRUCTOR = TianoDecompressLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources]
+ BaseUefiDecompressLibInternals.h
+ BaseUefiDecompressLib.c
+ BaseUefiTianoCustomDecompressLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ BaseMemoryLib
+ ExtractGuidedSectionLib
+
+[Guids]
+ gTianoCustomDecompressGuid ## PRODUCES ## UNDEFINED # specifies tiano custom decompress algorithm.
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 28d4a966c2..6c563375ee 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -761,6 +761,11 @@ ## Include/IndustryStandard/WindowsUxCapsule.h
gWindowsUxCapsuleGuid = { 0x3b8c8162, 0x188c, 0x46a4, { 0xae, 0xc9, 0xbe, 0x43, 0xf1, 0xd6, 0x56, 0x97}}
+ #
+ # GUID indicates the tiano custom compress/decompress algorithm.
+ #
+ gTianoCustomDecompressGuid = { 0xA31280AD, 0x481E, 0x41B6, { 0x95, 0xE8, 0x12, 0x7F, 0x4C, 0x98, 0x47, 0x79 }}
+
[Guids.IA32, Guids.X64]
## Include/Guid/Cper.h
gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }}
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 21743e384c..a2ff12fe75 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -57,6 +57,7 @@ MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
+ MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf
MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
|