summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library/BrotliCustomDecompressLib
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Library/BrotliCustomDecompressLib')
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf146
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c62
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h86
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c600
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni32
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h94
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c402
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h18
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h18
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h18
-rw-r--r--MdeModulePkg/Library/BrotliCustomDecompressLib/string.h18
11 files changed, 747 insertions, 747 deletions
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf
index 525e92408d..36c585cfa0 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf
@@ -1,73 +1,73 @@
-## @file
-# BrotliCustomDecompressLib produces BROTLI custom decompression algorithm.
-#
-# It is based on the Brotli v0.5.2.
-# Brotli was released on the website https://github.com/google/brotli.
-#
-# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = BrotliDecompressLib
- MODULE_UNI_FILE = BrotliDecompressLib.uni
- FILE_GUID = 69EC7DB2-B0DD-493A-963A-C5F330131BAA
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = NULL
- CONSTRUCTOR = BrotliDecompressLibConstructor
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64
-#
-
-[Sources]
- GuidedSectionExtraction.c
- BrotliDecUefiSupport.c
- BrotliDecUefiSupport.h
- BrotliDecompress.c
- BrotliDecompressLibInternal.h
- # Wrapper header files start #
- stddef.h
- stdint.h
- stdlib.h
- string.h
- # Wrapper header files end #
- brotli/c/common/dictionary.c
- brotli/c/common/transform.c
- brotli/c/dec/bit_reader.c
- brotli/c/dec/decode.c
- brotli/c/dec/huffman.c
- brotli/c/dec/state.c
- brotli/c/include/brotli/decode.h
- brotli/c/include/brotli/port.h
- brotli/c/include/brotli/types.h
- brotli/c/common/constants.h
- brotli/c/common/context.h
- brotli/c/common/dictionary.h
- brotli/c/common/platform.h
- brotli/c/common/transform.h
- brotli/c/common/version.h
- brotli/c/dec/bit_reader.h
- brotli/c/dec/huffman.h
- brotli/c/dec/state.h
- brotli/c/dec/prefix.h
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
-
-[Guids]
- gBrotliCustomDecompressGuid ## PRODUCES ## UNDEFINED # specifies BROTLI custom decompress algorithm.
-
-[LibraryClasses]
- BaseLib
- DebugLib
- BaseMemoryLib
- ExtractGuidedSectionLib
+## @file
+# BrotliCustomDecompressLib produces BROTLI custom decompression algorithm.
+#
+# It is based on the Brotli v0.5.2.
+# Brotli was released on the website https://github.com/google/brotli.
+#
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BrotliDecompressLib
+ MODULE_UNI_FILE = BrotliDecompressLib.uni
+ FILE_GUID = 69EC7DB2-B0DD-493A-963A-C5F330131BAA
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = NULL
+ CONSTRUCTOR = BrotliDecompressLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ GuidedSectionExtraction.c
+ BrotliDecUefiSupport.c
+ BrotliDecUefiSupport.h
+ BrotliDecompress.c
+ BrotliDecompressLibInternal.h
+ # Wrapper header files start #
+ stddef.h
+ stdint.h
+ stdlib.h
+ string.h
+ # Wrapper header files end #
+ brotli/c/common/dictionary.c
+ brotli/c/common/transform.c
+ brotli/c/dec/bit_reader.c
+ brotli/c/dec/decode.c
+ brotli/c/dec/huffman.c
+ brotli/c/dec/state.c
+ brotli/c/include/brotli/decode.h
+ brotli/c/include/brotli/port.h
+ brotli/c/include/brotli/types.h
+ brotli/c/common/constants.h
+ brotli/c/common/context.h
+ brotli/c/common/dictionary.h
+ brotli/c/common/platform.h
+ brotli/c/common/transform.h
+ brotli/c/common/version.h
+ brotli/c/dec/bit_reader.h
+ brotli/c/dec/huffman.h
+ brotli/c/dec/state.h
+ brotli/c/dec/prefix.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[Guids]
+ gBrotliCustomDecompressGuid ## PRODUCES ## UNDEFINED # specifies BROTLI custom decompress algorithm.
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ BaseMemoryLib
+ ExtractGuidedSectionLib
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c
index f89db846ef..28fc7fb4b7 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c
@@ -1,31 +1,31 @@
-/** @file
- Implements for functions declared in BrotliDecUefiSupport.h
-
- Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-#include <BrotliDecUefiSupport.h>
-
-/**
- Dummy malloc function for compiler.
-**/
-VOID *
-BrDummyMalloc (
- IN size_t Size
- )
-{
- ASSERT (FALSE);
- return NULL;
-}
-
-/**
- Dummy free function for compiler.
-**/
-VOID
-BrDummyFree (
- IN VOID *Ptr
- )
-{
- ASSERT (FALSE);
-}
+/** @file
+ Implements for functions declared in BrotliDecUefiSupport.h
+
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <BrotliDecUefiSupport.h>
+
+/**
+ Dummy malloc function for compiler.
+**/
+VOID *
+BrDummyMalloc (
+ IN size_t Size
+ )
+{
+ ASSERT (FALSE);
+ return NULL;
+}
+
+/**
+ Dummy free function for compiler.
+**/
+VOID
+BrDummyFree (
+ IN VOID *Ptr
+ )
+{
+ ASSERT (FALSE);
+}
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h
index 71e76bcbf2..ba3f0c305c 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h
@@ -1,43 +1,43 @@
-/** @file
- BROTLI UEFI header file for definitions
-
- Allows BROTLI code to build under UEFI (edk2) build environment
-
- Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef __BROTLI_DECOMPRESS_UEFI_SUP_H__
-#define __BROTLI_DECOMPRESS_UEFI_SUP_H__
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#define memcpy CopyMem
-#define memmove CopyMem
-#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
-#define malloc BrDummyMalloc
-#define free BrDummyFree
-
-typedef INT8 int8_t;
-typedef INT16 int16_t;
-typedef INT32 int32_t;
-typedef INT64 int64_t;
-typedef UINT8 uint8_t;
-typedef UINT16 uint16_t;
-typedef UINT32 uint32_t;
-typedef UINT64 uint64_t;
-typedef UINTN size_t;
-
-VOID *
-BrDummyMalloc (
- IN size_t Size
- );
-
-VOID
-BrDummyFree (
- IN VOID *Ptr
- );
-
-#endif
+/** @file
+ BROTLI UEFI header file for definitions
+
+ Allows BROTLI code to build under UEFI (edk2) build environment
+
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __BROTLI_DECOMPRESS_UEFI_SUP_H__
+#define __BROTLI_DECOMPRESS_UEFI_SUP_H__
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#define memcpy CopyMem
+#define memmove CopyMem
+#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
+#define malloc BrDummyMalloc
+#define free BrDummyFree
+
+typedef INT8 int8_t;
+typedef INT16 int16_t;
+typedef INT32 int32_t;
+typedef INT64 int64_t;
+typedef UINT8 uint8_t;
+typedef UINT16 uint16_t;
+typedef UINT32 uint32_t;
+typedef UINT64 uint64_t;
+typedef UINTN size_t;
+
+VOID *
+BrDummyMalloc (
+ IN size_t Size
+ );
+
+VOID
+BrDummyFree (
+ IN VOID *Ptr
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
index 3cb31ab984..64e001ceef 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
@@ -1,300 +1,300 @@
-/** @file
- Brotli Decompress interfaces
-
- Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-#include <BrotliDecompressLibInternal.h>
-
-/**
- Allocation routine used by BROTLI decompression.
-
- @param Ptr Pointer to the BROTLI_BUFF instance.
- @param Size The size in bytes to be allocated.
-
- @return The allocated pointer address, or NULL on failure
-**/
-VOID *
-BrAlloc (
- IN VOID *Ptr,
- IN size_t Size
- )
-{
- VOID *Addr;
- BROTLI_BUFF *Private;
-
- Private = (BROTLI_BUFF *)Ptr;
-
- if (Private->BuffSize >= Size) {
- Addr = Private->Buff;
- Private->Buff = (VOID *)((UINT8 *)Addr + Size);
- Private->BuffSize -= Size;
- return Addr;
- } else {
- ASSERT (FALSE);
- return NULL;
- }
-}
-
-/**
- Free routine used by BROTLI decompression.
-
- @param Ptr Pointer to the BROTLI_BUFF instance
- @param Address The address to be freed
-**/
-VOID
-BrFree (
- IN VOID *Ptr,
- IN VOID *Address
- )
-{
- //
- // We use the 'scratch buffer' for allocations, so there is no free
- // operation required. The scratch buffer will be freed by the caller
- // of the decompression code.
- //
-}
-
-/**
- Decompresses a Brotli compressed source buffer.
-
- Extracts decompressed data to its original form.
- If the compressed source data specified by Source is successfully decompressed
- into Destination, then EFI_SUCCESS is returned. If the compressed source data
- specified by Source is not in a valid compressed data format,
- then EFI_INVALID_PARAMETER is returned.
-
- @param Source The source buffer containing the compressed data.
- @param SourceSize The size of source buffer.
- @param Destination The destination buffer to store the decompressed data.
- @param DestSize The destination buffer size.
- @param BuffInfo The pointer to the BROTLI_BUFF instance.
-
- @retval EFI_SUCCESS Decompression completed successfully, and
- the uncompressed buffer is returned in Destination.
- @retval EFI_INVALID_PARAMETER
- The source buffer specified by Source is corrupted
- (not in a valid compressed format).
-**/
-EFI_STATUS
-BrotliDecompress (
- IN CONST VOID *Source,
- IN UINTN SourceSize,
- IN OUT VOID *Destination,
- IN OUT UINTN DestSize,
- IN VOID *BuffInfo
- )
-{
- UINT8 *Input;
- UINT8 *Output;
- const UINT8 *NextIn;
- UINT8 *NextOut;
- size_t TotalOut;
- size_t AvailableIn;
- size_t AvailableOut;
- VOID *Temp;
- BrotliDecoderResult Result;
- BrotliDecoderState *BroState;
-
- TotalOut = 0;
- AvailableOut = FILE_BUFFER_SIZE;
- Result = BROTLI_DECODER_RESULT_ERROR;
- BroState = BrotliDecoderCreateInstance (BrAlloc, BrFree, BuffInfo);
- Temp = Destination;
-
- if (BroState == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Input = (UINT8 *)BrAlloc (BuffInfo, FILE_BUFFER_SIZE);
- Output = (UINT8 *)BrAlloc (BuffInfo, FILE_BUFFER_SIZE);
- if ((Input == NULL) || (Output == NULL)) {
- BrFree (BuffInfo, Input);
- BrFree (BuffInfo, Output);
- BrotliDecoderDestroyInstance (BroState);
- return EFI_INVALID_PARAMETER;
- }
-
- NextOut = Output;
- Result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
- while (1) {
- if (Result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
- if (SourceSize == 0) {
- break;
- }
-
- if (SourceSize >= FILE_BUFFER_SIZE) {
- AvailableIn = FILE_BUFFER_SIZE;
- } else {
- AvailableIn = SourceSize;
- }
-
- CopyMem (Input, Source, AvailableIn);
- Source = (VOID *)((UINT8 *)Source + AvailableIn);
- SourceSize -= AvailableIn;
- NextIn = Input;
- } else if (Result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {
- CopyMem (Temp, Output, FILE_BUFFER_SIZE);
- AvailableOut = FILE_BUFFER_SIZE;
- Temp = (VOID *)((UINT8 *)Temp +FILE_BUFFER_SIZE);
- NextOut = Output;
- } else {
- break; /* Error or success. */
- }
-
- Result = BrotliDecoderDecompressStream (
- BroState,
- &AvailableIn,
- &NextIn,
- &AvailableOut,
- &NextOut,
- &TotalOut
- );
- }
-
- if (NextOut != Output) {
- CopyMem (Temp, Output, (size_t)(NextOut - Output));
- }
-
- DestSize = TotalOut;
-
- BrFree (BuffInfo, Input);
- BrFree (BuffInfo, Output);
- BrotliDecoderDestroyInstance (BroState);
- return (Result == BROTLI_DECODER_RESULT_SUCCESS) ? EFI_SUCCESS : EFI_INVALID_PARAMETER;
-}
-
-/**
- Get the size of the uncompressed buffer by parsing EncodeData header.
-
- @param EncodedData Pointer to the compressed data.
- @param StartOffset Start offset of the compressed data.
- @param EndOffset End offset of the compressed data.
-
- @return The size of the uncompressed buffer.
-**/
-UINT64
-BrGetDecodedSizeOfBuf (
- IN UINT8 *EncodedData,
- IN UINT8 StartOffset,
- IN UINT8 EndOffset
- )
-{
- UINT64 DecodedSize;
- INTN Index;
-
- /* Parse header */
- DecodedSize = 0;
- for (Index = EndOffset - 1; Index >= StartOffset; Index--) {
- DecodedSize = LShiftU64 (DecodedSize, 8) + EncodedData[Index];
- }
-
- return DecodedSize;
-}
-
-/**
- Given a Brotli compressed source buffer, this function retrieves the size of
- the uncompressed buffer and the size of the scratch buffer required
- to decompress the compressed source buffer.
-
- Retrieves the size of the uncompressed buffer and the temporary scratch buffer
- required to decompress the buffer specified by Source and SourceSize.
- The size of the uncompressed buffer is returned in DestinationSize,
- the size of the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
- This function does not have scratch buffer available to perform a thorough
- checking of the validity of the source data. It just retrieves the "Original Size"
- field from the BROTLI_SCRATCH_MAX beginning bytes of the source data and output it as DestinationSize.
- And ScratchSize is specific to the decompression implementation.
-
- If SourceSize is less than BROTLI_SCRATCH_MAX, then ASSERT().
-
- @param Source The source buffer containing the compressed data.
- @param SourceSize The size, in bytes, of the source buffer.
- @param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
- that will be generated when the compressed buffer specified
- by Source and SourceSize is decompressed.
- @param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
- is required to decompress the compressed buffer specified
- by Source and SourceSize.
-
- @retval EFI_SUCCESS The size of the uncompressed data was returned
- in DestinationSize and the size of the scratch
- buffer was returned in ScratchSize.
-**/
-EFI_STATUS
-EFIAPI
-BrotliUefiDecompressGetInfo (
- IN CONST VOID *Source,
- IN UINT32 SourceSize,
- OUT UINT32 *DestinationSize,
- OUT UINT32 *ScratchSize
- )
-{
- UINT64 GetSize;
- UINT8 MaxOffset;
-
- ASSERT (SourceSize >= BROTLI_SCRATCH_MAX);
-
- MaxOffset = BROTLI_DECODE_MAX;
- GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
- *DestinationSize = (UINT32)GetSize;
- MaxOffset = BROTLI_SCRATCH_MAX;
- GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
- *ScratchSize = (UINT32)GetSize;
- return EFI_SUCCESS;
-}
-
-/**
- Decompresses a Brotli compressed source buffer.
-
- Extracts decompressed data to its original form.
- 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.
-
- @param Source The source buffer containing the compressed data.
- @param SourceSize The size of source buffer.
- @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 EFI_SUCCESS Decompression completed successfully, and
- the uncompressed buffer is returned in Destination.
- @retval EFI_INVALID_PARAMETER
- The source buffer specified by Source is corrupted
- (not in a valid compressed format).
-**/
-EFI_STATUS
-EFIAPI
-BrotliUefiDecompress (
- IN CONST VOID *Source,
- IN UINTN SourceSize,
- IN OUT VOID *Destination,
- IN OUT VOID *Scratch
- )
-{
- UINTN DestSize = 0;
- EFI_STATUS Status;
- BROTLI_BUFF BroBuff;
- UINT64 GetSize;
- UINT8 MaxOffset;
-
- MaxOffset = BROTLI_SCRATCH_MAX;
- GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
-
- BroBuff.Buff = Scratch;
- BroBuff.BuffSize = (UINTN)GetSize;
-
- Status = BrotliDecompress (
- (VOID *)((UINT8 *)Source + BROTLI_SCRATCH_MAX),
- SourceSize - BROTLI_SCRATCH_MAX,
- Destination,
- DestSize,
- (VOID *)(&BroBuff)
- );
-
- return Status;
-}
+/** @file
+ Brotli Decompress interfaces
+
+ Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <BrotliDecompressLibInternal.h>
+
+/**
+ Allocation routine used by BROTLI decompression.
+
+ @param Ptr Pointer to the BROTLI_BUFF instance.
+ @param Size The size in bytes to be allocated.
+
+ @return The allocated pointer address, or NULL on failure
+**/
+VOID *
+BrAlloc (
+ IN VOID *Ptr,
+ IN size_t Size
+ )
+{
+ VOID *Addr;
+ BROTLI_BUFF *Private;
+
+ Private = (BROTLI_BUFF *)Ptr;
+
+ if (Private->BuffSize >= Size) {
+ Addr = Private->Buff;
+ Private->Buff = (VOID *)((UINT8 *)Addr + Size);
+ Private->BuffSize -= Size;
+ return Addr;
+ } else {
+ ASSERT (FALSE);
+ return NULL;
+ }
+}
+
+/**
+ Free routine used by BROTLI decompression.
+
+ @param Ptr Pointer to the BROTLI_BUFF instance
+ @param Address The address to be freed
+**/
+VOID
+BrFree (
+ IN VOID *Ptr,
+ IN VOID *Address
+ )
+{
+ //
+ // We use the 'scratch buffer' for allocations, so there is no free
+ // operation required. The scratch buffer will be freed by the caller
+ // of the decompression code.
+ //
+}
+
+/**
+ Decompresses a Brotli compressed source buffer.
+
+ Extracts decompressed data to its original form.
+ If the compressed source data specified by Source is successfully decompressed
+ into Destination, then EFI_SUCCESS is returned. If the compressed source data
+ specified by Source is not in a valid compressed data format,
+ then EFI_INVALID_PARAMETER is returned.
+
+ @param Source The source buffer containing the compressed data.
+ @param SourceSize The size of source buffer.
+ @param Destination The destination buffer to store the decompressed data.
+ @param DestSize The destination buffer size.
+ @param BuffInfo The pointer to the BROTLI_BUFF instance.
+
+ @retval EFI_SUCCESS Decompression completed successfully, and
+ the uncompressed buffer is returned in Destination.
+ @retval EFI_INVALID_PARAMETER
+ The source buffer specified by Source is corrupted
+ (not in a valid compressed format).
+**/
+EFI_STATUS
+BrotliDecompress (
+ IN CONST VOID *Source,
+ IN UINTN SourceSize,
+ IN OUT VOID *Destination,
+ IN OUT UINTN DestSize,
+ IN VOID *BuffInfo
+ )
+{
+ UINT8 *Input;
+ UINT8 *Output;
+ const UINT8 *NextIn;
+ UINT8 *NextOut;
+ size_t TotalOut;
+ size_t AvailableIn;
+ size_t AvailableOut;
+ VOID *Temp;
+ BrotliDecoderResult Result;
+ BrotliDecoderState *BroState;
+
+ TotalOut = 0;
+ AvailableOut = FILE_BUFFER_SIZE;
+ Result = BROTLI_DECODER_RESULT_ERROR;
+ BroState = BrotliDecoderCreateInstance (BrAlloc, BrFree, BuffInfo);
+ Temp = Destination;
+
+ if (BroState == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Input = (UINT8 *)BrAlloc (BuffInfo, FILE_BUFFER_SIZE);
+ Output = (UINT8 *)BrAlloc (BuffInfo, FILE_BUFFER_SIZE);
+ if ((Input == NULL) || (Output == NULL)) {
+ BrFree (BuffInfo, Input);
+ BrFree (BuffInfo, Output);
+ BrotliDecoderDestroyInstance (BroState);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ NextOut = Output;
+ Result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
+ while (1) {
+ if (Result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
+ if (SourceSize == 0) {
+ break;
+ }
+
+ if (SourceSize >= FILE_BUFFER_SIZE) {
+ AvailableIn = FILE_BUFFER_SIZE;
+ } else {
+ AvailableIn = SourceSize;
+ }
+
+ CopyMem (Input, Source, AvailableIn);
+ Source = (VOID *)((UINT8 *)Source + AvailableIn);
+ SourceSize -= AvailableIn;
+ NextIn = Input;
+ } else if (Result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {
+ CopyMem (Temp, Output, FILE_BUFFER_SIZE);
+ AvailableOut = FILE_BUFFER_SIZE;
+ Temp = (VOID *)((UINT8 *)Temp +FILE_BUFFER_SIZE);
+ NextOut = Output;
+ } else {
+ break; /* Error or success. */
+ }
+
+ Result = BrotliDecoderDecompressStream (
+ BroState,
+ &AvailableIn,
+ &NextIn,
+ &AvailableOut,
+ &NextOut,
+ &TotalOut
+ );
+ }
+
+ if (NextOut != Output) {
+ CopyMem (Temp, Output, (size_t)(NextOut - Output));
+ }
+
+ DestSize = TotalOut;
+
+ BrFree (BuffInfo, Input);
+ BrFree (BuffInfo, Output);
+ BrotliDecoderDestroyInstance (BroState);
+ return (Result == BROTLI_DECODER_RESULT_SUCCESS) ? EFI_SUCCESS : EFI_INVALID_PARAMETER;
+}
+
+/**
+ Get the size of the uncompressed buffer by parsing EncodeData header.
+
+ @param EncodedData Pointer to the compressed data.
+ @param StartOffset Start offset of the compressed data.
+ @param EndOffset End offset of the compressed data.
+
+ @return The size of the uncompressed buffer.
+**/
+UINT64
+BrGetDecodedSizeOfBuf (
+ IN UINT8 *EncodedData,
+ IN UINT8 StartOffset,
+ IN UINT8 EndOffset
+ )
+{
+ UINT64 DecodedSize;
+ INTN Index;
+
+ /* Parse header */
+ DecodedSize = 0;
+ for (Index = EndOffset - 1; Index >= StartOffset; Index--) {
+ DecodedSize = LShiftU64 (DecodedSize, 8) + EncodedData[Index];
+ }
+
+ return DecodedSize;
+}
+
+/**
+ Given a Brotli compressed source buffer, this function retrieves the size of
+ the uncompressed buffer and the size of the scratch buffer required
+ to decompress the compressed source buffer.
+
+ Retrieves the size of the uncompressed buffer and the temporary scratch buffer
+ required to decompress the buffer specified by Source and SourceSize.
+ The size of the uncompressed buffer is returned in DestinationSize,
+ the size of the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
+ This function does not have scratch buffer available to perform a thorough
+ checking of the validity of the source data. It just retrieves the "Original Size"
+ field from the BROTLI_SCRATCH_MAX beginning bytes of the source data and output it as DestinationSize.
+ And ScratchSize is specific to the decompression implementation.
+
+ If SourceSize is less than BROTLI_SCRATCH_MAX, then ASSERT().
+
+ @param Source The source buffer containing the compressed data.
+ @param SourceSize The size, in bytes, of the source buffer.
+ @param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
+ that will be generated when the compressed buffer specified
+ by Source and SourceSize is decompressed.
+ @param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
+ is required to decompress the compressed buffer specified
+ by Source and SourceSize.
+
+ @retval EFI_SUCCESS The size of the uncompressed data was returned
+ in DestinationSize and the size of the scratch
+ buffer was returned in ScratchSize.
+**/
+EFI_STATUS
+EFIAPI
+BrotliUefiDecompressGetInfo (
+ IN CONST VOID *Source,
+ IN UINT32 SourceSize,
+ OUT UINT32 *DestinationSize,
+ OUT UINT32 *ScratchSize
+ )
+{
+ UINT64 GetSize;
+ UINT8 MaxOffset;
+
+ ASSERT (SourceSize >= BROTLI_SCRATCH_MAX);
+
+ MaxOffset = BROTLI_DECODE_MAX;
+ GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
+ *DestinationSize = (UINT32)GetSize;
+ MaxOffset = BROTLI_SCRATCH_MAX;
+ GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
+ *ScratchSize = (UINT32)GetSize;
+ return EFI_SUCCESS;
+}
+
+/**
+ Decompresses a Brotli compressed source buffer.
+
+ Extracts decompressed data to its original form.
+ 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.
+
+ @param Source The source buffer containing the compressed data.
+ @param SourceSize The size of source buffer.
+ @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 EFI_SUCCESS Decompression completed successfully, and
+ the uncompressed buffer is returned in Destination.
+ @retval EFI_INVALID_PARAMETER
+ The source buffer specified by Source is corrupted
+ (not in a valid compressed format).
+**/
+EFI_STATUS
+EFIAPI
+BrotliUefiDecompress (
+ IN CONST VOID *Source,
+ IN UINTN SourceSize,
+ IN OUT VOID *Destination,
+ IN OUT VOID *Scratch
+ )
+{
+ UINTN DestSize = 0;
+ EFI_STATUS Status;
+ BROTLI_BUFF BroBuff;
+ UINT64 GetSize;
+ UINT8 MaxOffset;
+
+ MaxOffset = BROTLI_SCRATCH_MAX;
+ GetSize = BrGetDecodedSizeOfBuf ((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);
+
+ BroBuff.Buff = Scratch;
+ BroBuff.BuffSize = (UINTN)GetSize;
+
+ Status = BrotliDecompress (
+ (VOID *)((UINT8 *)Source + BROTLI_SCRATCH_MAX),
+ SourceSize - BROTLI_SCRATCH_MAX,
+ Destination,
+ DestSize,
+ (VOID *)(&BroBuff)
+ );
+
+ return Status;
+}
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni
index 22f9d9add9..a56101b0a1 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni
@@ -1,16 +1,16 @@
-// /** @file
-// BrotliCustomDecompressLib produces BROTLI custom decompression algorithm.
-//
-// It is based on the Brotli v0.5.2.
-// Brotli was released on the website https://github.com/google/brotli.
-//
-// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "BrotliCustomDecompressLib produces BROTLI custom decompression algorithm"
-
-#string STR_MODULE_DESCRIPTION #language en-US "It is based on the Brotli v0.5.2. Brotli was released on the website https://github.com/google/brotli."
+// /** @file
+// BrotliCustomDecompressLib produces BROTLI custom decompression algorithm.
+//
+// It is based on the Brotli v0.5.2.
+// Brotli was released on the website https://github.com/google/brotli.
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "BrotliCustomDecompressLib produces BROTLI custom decompression algorithm"
+
+#string STR_MODULE_DESCRIPTION #language en-US "It is based on the Brotli v0.5.2. Brotli was released on the website https://github.com/google/brotli."
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h
index 312a5ede52..ecf8058484 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h
@@ -1,47 +1,47 @@
-/** @file
- BROTLI UEFI header file
-
- Allows BROTLI code to build under UEFI (edk2) build environment
-
- Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef __BROTLI_DECOMPRESS_INTERNAL_H__
-#define __BROTLI_DECOMPRESS_INTERNAL_H__
-
-#include <PiPei.h>
-#include <Library/ExtractGuidedSectionLib.h>
-#include <brotli/c/include/brotli/types.h>
-#include <brotli/c/include/brotli/decode.h>
-
-typedef struct {
- VOID *Buff;
- UINTN BuffSize;
-} BROTLI_BUFF;
-
-#define FILE_BUFFER_SIZE 65536
-#define BROTLI_INFO_SIZE 8
-#define BROTLI_DECODE_MAX 8
-#define BROTLI_SCRATCH_MAX 16
-
-EFI_STATUS
-EFIAPI
-BrotliUefiDecompressGetInfo (
- IN CONST VOID *Source,
- IN UINT32 SourceSize,
- OUT UINT32 *DestinationSize,
- OUT UINT32 *ScratchSize
- );
-
-EFI_STATUS
-EFIAPI
-BrotliUefiDecompress (
- IN CONST VOID *Source,
- IN UINTN SourceSize,
- IN OUT VOID *Destination,
- IN OUT VOID *Scratch
- );
-
-#endif
+/** @file
+ BROTLI UEFI header file
+
+ Allows BROTLI code to build under UEFI (edk2) build environment
+
+ Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __BROTLI_DECOMPRESS_INTERNAL_H__
+#define __BROTLI_DECOMPRESS_INTERNAL_H__
+
+#include <PiPei.h>
+#include <Library/ExtractGuidedSectionLib.h>
+#include <brotli/c/include/brotli/types.h>
+#include <brotli/c/include/brotli/decode.h>
+
+typedef struct {
+ VOID *Buff;
+ UINTN BuffSize;
+} BROTLI_BUFF;
+
+#define FILE_BUFFER_SIZE 65536
+#define BROTLI_INFO_SIZE 8
+#define BROTLI_DECODE_MAX 8
+#define BROTLI_SCRATCH_MAX 16
+
+EFI_STATUS
+EFIAPI
+BrotliUefiDecompressGetInfo (
+ IN CONST VOID *Source,
+ IN UINT32 SourceSize,
+ OUT UINT32 *DestinationSize,
+ OUT UINT32 *ScratchSize
+ );
+
+EFI_STATUS
+EFIAPI
+BrotliUefiDecompress (
+ IN CONST VOID *Source,
+ IN UINTN SourceSize,
+ IN OUT VOID *Destination,
+ IN OUT VOID *Scratch
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c b/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
index 262f218f1f..d1b1dc912d 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
@@ -1,201 +1,201 @@
-/** @file
- BROTLI Decompress GUIDed Section Extraction Library.
- It wraps Brotli decompress interfaces to GUIDed Section Extraction interfaces
- and registers them into GUIDed handler table.
-
- Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <BrotliDecompressLibInternal.h>
-
-/**
- Examines a GUIDed section and returns the size of the decoded buffer and the
- size of an 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
-BrotliGuidedSectionGetInfo (
- IN CONST VOID *InputSection,
- OUT UINT32 *OutputBufferSize,
- OUT UINT32 *ScratchBufferSize,
- OUT UINT16 *SectionAttribute
- )
-{
- ASSERT (InputSection != NULL);
- ASSERT (OutputBufferSize != NULL);
- ASSERT (ScratchBufferSize != NULL);
- ASSERT (SectionAttribute != NULL);
-
- if (IS_SECTION2 (InputSection)) {
- if (!CompareGuid (
- &gBrotliCustomDecompressGuid,
- &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
- ))
- {
- return RETURN_INVALID_PARAMETER;
- }
-
- *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;
-
- return BrotliUefiDecompressGetInfo (
- (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
- SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
- OutputBufferSize,
- ScratchBufferSize
- );
- } else {
- if (!CompareGuid (
- &gBrotliCustomDecompressGuid,
- &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
- ))
- {
- return RETURN_INVALID_PARAMETER;
- }
-
- *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;
-
- return BrotliUefiDecompressGetInfo (
- (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
- SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
- OutputBufferSize,
- ScratchBufferSize
- );
- }
-}
-
-/**
- Decompress a BROTLI 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[out] 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
-BrotliGuidedSectionExtraction (
- IN CONST VOID *InputSection,
- OUT VOID **OutputBuffer,
- OUT VOID *ScratchBuffer OPTIONAL,
- OUT UINT32 *AuthenticationStatus
- )
-{
- ASSERT (OutputBuffer != NULL);
- ASSERT (InputSection != NULL);
-
- if (IS_SECTION2 (InputSection)) {
- if (!CompareGuid (
- &gBrotliCustomDecompressGuid,
- &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
- ))
- {
- return RETURN_INVALID_PARAMETER;
- }
-
- //
- // Authentication is set to Zero, which may be ignored.
- //
- *AuthenticationStatus = 0;
-
- return BrotliUefiDecompress (
- (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
- SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
- *OutputBuffer,
- ScratchBuffer
- );
- } else {
- if (!CompareGuid (
- &gBrotliCustomDecompressGuid,
- &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
- ))
- {
- return RETURN_INVALID_PARAMETER;
- }
-
- //
- // Authentication is set to Zero, which may be ignored.
- //
- *AuthenticationStatus = 0;
-
- return BrotliUefiDecompress (
- (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
- SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
- *OutputBuffer,
- ScratchBuffer
- );
- }
-}
-
-/**
- Register BrotliDecompress and BrotliDecompressGetInfo handlers with BrotliCustomerDecompressGuid.
-
- @retval EFI_SUCCESS Register successfully.
- @retval EFI_OUT_OF_RESOURCES No enough memory to store this handler.
-**/
-EFI_STATUS
-EFIAPI
-BrotliDecompressLibConstructor (
- VOID
- )
-{
- return ExtractGuidedSectionRegisterHandlers (
- &gBrotliCustomDecompressGuid,
- BrotliGuidedSectionGetInfo,
- BrotliGuidedSectionExtraction
- );
-}
+/** @file
+ BROTLI Decompress GUIDed Section Extraction Library.
+ It wraps Brotli decompress interfaces to GUIDed Section Extraction interfaces
+ and registers them into GUIDed handler table.
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <BrotliDecompressLibInternal.h>
+
+/**
+ Examines a GUIDed section and returns the size of the decoded buffer and the
+ size of an 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
+BrotliGuidedSectionGetInfo (
+ IN CONST VOID *InputSection,
+ OUT UINT32 *OutputBufferSize,
+ OUT UINT32 *ScratchBufferSize,
+ OUT UINT16 *SectionAttribute
+ )
+{
+ ASSERT (InputSection != NULL);
+ ASSERT (OutputBufferSize != NULL);
+ ASSERT (ScratchBufferSize != NULL);
+ ASSERT (SectionAttribute != NULL);
+
+ if (IS_SECTION2 (InputSection)) {
+ if (!CompareGuid (
+ &gBrotliCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
+ ))
+ {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;
+
+ return BrotliUefiDecompressGetInfo (
+ (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
+ SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
+ OutputBufferSize,
+ ScratchBufferSize
+ );
+ } else {
+ if (!CompareGuid (
+ &gBrotliCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
+ ))
+ {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;
+
+ return BrotliUefiDecompressGetInfo (
+ (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
+ SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
+ OutputBufferSize,
+ ScratchBufferSize
+ );
+ }
+}
+
+/**
+ Decompress a BROTLI 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[out] 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
+BrotliGuidedSectionExtraction (
+ IN CONST VOID *InputSection,
+ OUT VOID **OutputBuffer,
+ OUT VOID *ScratchBuffer OPTIONAL,
+ OUT UINT32 *AuthenticationStatus
+ )
+{
+ ASSERT (OutputBuffer != NULL);
+ ASSERT (InputSection != NULL);
+
+ if (IS_SECTION2 (InputSection)) {
+ if (!CompareGuid (
+ &gBrotliCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)
+ ))
+ {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ //
+ // Authentication is set to Zero, which may be ignored.
+ //
+ *AuthenticationStatus = 0;
+
+ return BrotliUefiDecompress (
+ (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
+ SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,
+ *OutputBuffer,
+ ScratchBuffer
+ );
+ } else {
+ if (!CompareGuid (
+ &gBrotliCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)
+ ))
+ {
+ return RETURN_INVALID_PARAMETER;
+ }
+
+ //
+ // Authentication is set to Zero, which may be ignored.
+ //
+ *AuthenticationStatus = 0;
+
+ return BrotliUefiDecompress (
+ (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
+ SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,
+ *OutputBuffer,
+ ScratchBuffer
+ );
+ }
+}
+
+/**
+ Register BrotliDecompress and BrotliDecompressGetInfo handlers with BrotliCustomerDecompressGuid.
+
+ @retval EFI_SUCCESS Register successfully.
+ @retval EFI_OUT_OF_RESOURCES No enough memory to store this handler.
+**/
+EFI_STATUS
+EFIAPI
+BrotliDecompressLibConstructor (
+ VOID
+ )
+{
+ return ExtractGuidedSectionRegisterHandlers (
+ &gBrotliCustomDecompressGuid,
+ BrotliGuidedSectionGetInfo,
+ BrotliGuidedSectionExtraction
+ );
+}
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h
index 917a17700f..0e2fc3ba5a 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h
@@ -1,9 +1,9 @@
-/** @file
- Include file to support building the third-party brotli.
-
-Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <BrotliDecUefiSupport.h>
+/** @file
+ Include file to support building the third-party brotli.
+
+Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <BrotliDecUefiSupport.h>
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h
index 917a17700f..0e2fc3ba5a 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h
@@ -1,9 +1,9 @@
-/** @file
- Include file to support building the third-party brotli.
-
-Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <BrotliDecUefiSupport.h>
+/** @file
+ Include file to support building the third-party brotli.
+
+Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <BrotliDecUefiSupport.h>
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h
index 917a17700f..0e2fc3ba5a 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h
@@ -1,9 +1,9 @@
-/** @file
- Include file to support building the third-party brotli.
-
-Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <BrotliDecUefiSupport.h>
+/** @file
+ Include file to support building the third-party brotli.
+
+Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <BrotliDecUefiSupport.h>
diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h b/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h
index 917a17700f..0e2fc3ba5a 100644
--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h
+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h
@@ -1,9 +1,9 @@
-/** @file
- Include file to support building the third-party brotli.
-
-Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include <BrotliDecUefiSupport.h>
+/** @file
+ Include file to support building the third-party brotli.
+
+Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <BrotliDecUefiSupport.h>