diff options
Diffstat (limited to 'src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib')
11 files changed, 731 insertions, 0 deletions
diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf new file mode 100644 index 00000000..36c585cf --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliCustomDecompressLib.inf @@ -0,0 +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 diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c new file mode 100644 index 00000000..f1202b9b --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.c @@ -0,0 +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); +} diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h new file mode 100644 index 00000000..2bc25b3c --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecUefiSupport.h @@ -0,0 +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 diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c new file mode 100644 index 00000000..9908a1bb --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c @@ -0,0 +1,293 @@ +/** @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/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni new file mode 100644 index 00000000..22f9d9ad --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLib.uni @@ -0,0 +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."
diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h new file mode 100644 index 00000000..e76f4cda --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompressLibInternal.h @@ -0,0 +1,48 @@ +/** @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/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c new file mode 100644 index 00000000..d84722fb --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c @@ -0,0 +1,191 @@ +/** @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/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h new file mode 100644 index 00000000..0e2fc3ba --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stddef.h @@ -0,0 +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> diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h new file mode 100644 index 00000000..0e2fc3ba --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdint.h @@ -0,0 +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> diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h new file mode 100644 index 00000000..0e2fc3ba --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/stdlib.h @@ -0,0 +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> diff --git a/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h new file mode 100644 index 00000000..0e2fc3ba --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library/BrotliCustomDecompressLib/string.h @@ -0,0 +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> |