2 UEFI and Tiano Custom Decompress Library
3 It will do Tiano or UEFI decompress with different verison parameter.
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "BaseUefiTianoCustomDecompressLibInternals.h"
19 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
21 @param Sd The global scratch data
22 @param NumOfBits The number of bits to shift and read.
31 // Left shift NumOfBits of bits in advance
33 Sd
->mBitBuf
= (UINT32
) LShiftU64 (((UINT64
)Sd
->mBitBuf
), NumOfBits
);
36 // Copy data needed in bytes into mSbuBitBuf
38 while (NumOfBits
> Sd
->mBitCount
) {
39 NumOfBits
= (UINT16
) (NumOfBits
- Sd
->mBitCount
);
40 Sd
->mBitBuf
|= (UINT32
) LShiftU64 (((UINT64
)Sd
->mSubBitBuf
), NumOfBits
);
42 if (Sd
->mCompSize
> 0) {
44 // Get 1 byte into SubBitBuf
48 Sd
->mSubBitBuf
= Sd
->mSrcBase
[Sd
->mInBuf
++];
53 // No more bits from the source, just pad zero bit.
62 // Calculate additional bit count read to update mBitCount
64 Sd
->mBitCount
= (UINT16
) (Sd
->mBitCount
- NumOfBits
);
67 // Copy NumOfBits of bits from mSubBitBuf into mBitBuf
69 Sd
->mBitBuf
|= Sd
->mSubBitBuf
>> Sd
->mBitCount
;
73 Get NumOfBits of bits out from mBitBuf
75 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
76 NumOfBits of bits from source. Returns NumOfBits of bits that are
79 @param Sd The global scratch data.
80 @param NumOfBits The number of bits to pop and read.
82 @return The bits that are popped out.
94 // Pop NumOfBits of Bits from Left
96 OutBits
= (UINT32
) (Sd
->mBitBuf
>> (BITBUFSIZ
- NumOfBits
));
99 // Fill up mBitBuf from source
101 FillBuf (Sd
, NumOfBits
);
107 Creates Huffman Code mapping table according to code length array.
109 Creates Huffman Code mapping table for Extra Set, Char&Len Set
110 and Position Set according to code length array.
111 If TableBits > 16, then ASSERT ().
113 @param Sd The global scratch data
114 @param NumOfChar Number of symbols in the symbol set
115 @param BitLen Code length array
116 @param TableBits The width of the mapping table
117 @param Table The table to be created.
120 @retval BAD_TABLE The table is corrupted.
146 UINT16 MaxTableLength
;
149 // The maximum mapping table width supported by this internal
150 // working function is 16.
152 ASSERT (TableBits
<= 16);
154 for (Index
= 0; Index
<= 16; Index
++) {
158 for (Index
= 0; Index
< NumOfChar
; Index
++) {
159 if (BitLen
[Index
] > 16) {
160 return (UINT16
) BAD_TABLE
;
162 Count
[BitLen
[Index
]]++;
168 for (Index
= 1; Index
<= 16; Index
++) {
169 WordOfStart
= Start
[Index
];
170 WordOfCount
= Count
[Index
];
171 Start
[Index
+ 1] = (UINT16
) (WordOfStart
+ (WordOfCount
<< (16 - Index
)));
174 if (Start
[17] != 0) {
176 return (UINT16
) BAD_TABLE
;
179 JuBits
= (UINT16
) (16 - TableBits
);
182 for (Index
= 1; Index
<= TableBits
; Index
++) {
183 Start
[Index
] >>= JuBits
;
184 Weight
[Index
] = (UINT16
) (1U << (TableBits
- Index
));
187 while (Index
<= 16) {
188 Weight
[Index
] = (UINT16
) (1U << (16 - Index
));
192 Index
= (UINT16
) (Start
[TableBits
+ 1] >> JuBits
);
195 Index3
= (UINT16
) (1U << TableBits
);
196 if (Index
< Index3
) {
197 SetMem16 (Table
+ Index
, (Index3
- Index
) * sizeof (*Table
), 0);
202 Mask
= (UINT16
) (1U << (15 - TableBits
));
203 MaxTableLength
= (UINT16
) (1U << TableBits
);
205 for (Char
= 0; Char
< NumOfChar
; Char
++) {
208 if (Len
== 0 || Len
>= 17) {
212 NextCode
= (UINT16
) (Start
[Len
] + Weight
[Len
]);
214 if (Len
<= TableBits
) {
216 for (Index
= Start
[Len
]; Index
< NextCode
; Index
++) {
217 if (Index
>= MaxTableLength
) {
218 return (UINT16
) BAD_TABLE
;
226 Pointer
= &Table
[Index3
>> JuBits
];
227 Index
= (UINT16
) (Len
- TableBits
);
230 if (*Pointer
== 0 && Avail
< (2 * NC
- 1)) {
231 Sd
->mRight
[Avail
] = Sd
->mLeft
[Avail
] = 0;
235 if (*Pointer
< (2 * NC
- 1)) {
236 if ((Index3
& Mask
) != 0) {
237 Pointer
= &Sd
->mRight
[*Pointer
];
239 Pointer
= &Sd
->mLeft
[*Pointer
];
251 Start
[Len
] = NextCode
;
260 Decodes a position value.
262 Get a position value according to Position Huffman Table.
264 @param Sd the global scratch data
266 @return The position value decoded.
277 Val
= Sd
->mPTTable
[Sd
->mBitBuf
>> (BITBUFSIZ
- 8)];
280 Mask
= 1U << (BITBUFSIZ
- 1 - 8);
284 if ((Sd
->mBitBuf
& Mask
) != 0) {
285 Val
= Sd
->mRight
[Val
];
287 Val
= Sd
->mLeft
[Val
];
291 } while (Val
>= MAXNP
);
294 // Advance what we have read
296 FillBuf (Sd
, Sd
->mPTLen
[Val
]);
300 Pos
= (UINT32
) ((1U << (Val
- 1)) + GetBits (Sd
, (UINT16
) (Val
- 1)));
307 Reads code lengths for the Extra Set or the Position Set.
309 Read in the Extra Set or Position Set Length Array, then
310 generate the Huffman code mapping for them.
312 @param Sd The global scratch data.
313 @param nn Number of symbols.
314 @param nbit Number of bits needed to represent nn.
315 @param Special The special symbol that needs to be taken care of.
318 @retval BAD_TABLE Table is corrupted.
336 // Read Extra Set Code Length Array size
338 Number
= (UINT16
) GetBits (Sd
, nbit
);
342 // This represents only Huffman code used
344 CharC
= (UINT16
) GetBits (Sd
, nbit
);
346 for (Index
= 0; Index
< 256; Index
++) {
347 Sd
->mPTTable
[Index
] = CharC
;
350 SetMem (Sd
->mPTLen
, nn
, 0);
357 while (Index
< Number
&& Index
< NPT
) {
359 CharC
= (UINT16
) (Sd
->mBitBuf
>> (BITBUFSIZ
- 3));
362 // If a code length is less than 7, then it is encoded as a 3-bit
363 // value. Or it is encoded as a series of "1"s followed by a
364 // terminating "0". The number of "1"s = Code length - 4.
367 Mask
= 1U << (BITBUFSIZ
- 1 - 3);
368 while (Mask
& Sd
->mBitBuf
) {
374 FillBuf (Sd
, (UINT16
) ((CharC
< 7) ? 3 : CharC
- 3));
376 Sd
->mPTLen
[Index
++] = (UINT8
) CharC
;
380 // After the third length of the code length concatenation,
381 // a 2-bit value is used to indicated the number of consecutive
382 // zero lengths after the third length.
384 if (Index
== Special
) {
385 CharC
= (UINT16
) GetBits (Sd
, 2);
386 while ((INT16
) (--CharC
) >= 0 && Index
< NPT
) {
387 Sd
->mPTLen
[Index
++] = 0;
392 while (Index
< nn
&& Index
< NPT
) {
393 Sd
->mPTLen
[Index
++] = 0;
396 return MakeTable (Sd
, nn
, Sd
->mPTLen
, 8, Sd
->mPTTable
);
400 Reads code lengths for Char&Len Set.
402 Read in and decode the Char&Len Set Code Length Array, then
403 generate the Huffman Code mapping table for the Char&Len Set.
405 @param Sd the global scratch data
418 Number
= (UINT16
) GetBits (Sd
, CBIT
);
422 // This represents only Huffman code used
424 CharC
= (UINT16
) GetBits (Sd
, CBIT
);
426 SetMem (Sd
->mCLen
, NC
, 0);
428 for (Index
= 0; Index
< 4096; Index
++) {
429 Sd
->mCTable
[Index
] = CharC
;
436 while (Index
< Number
&& Index
< NC
) {
437 CharC
= Sd
->mPTTable
[Sd
->mBitBuf
>> (BITBUFSIZ
- 8)];
439 Mask
= 1U << (BITBUFSIZ
- 1 - 8);
443 if (Mask
& Sd
->mBitBuf
) {
444 CharC
= Sd
->mRight
[CharC
];
446 CharC
= Sd
->mLeft
[CharC
];
451 } while (CharC
>= NT
);
454 // Advance what we have read
456 FillBuf (Sd
, Sd
->mPTLen
[CharC
]);
462 } else if (CharC
== 1) {
463 CharC
= (UINT16
) (GetBits (Sd
, 4) + 3);
464 } else if (CharC
== 2) {
465 CharC
= (UINT16
) (GetBits (Sd
, CBIT
) + 20);
468 while ((INT16
) (--CharC
) >= 0 && Index
< NC
) {
469 Sd
->mCLen
[Index
++] = 0;
474 Sd
->mCLen
[Index
++] = (UINT8
) (CharC
- 2);
479 SetMem (Sd
->mCLen
+ Index
, NC
- Index
, 0);
481 MakeTable (Sd
, NC
, Sd
->mCLen
, 12, Sd
->mCTable
);
487 Decode a character/length value.
489 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
490 Huffman code mapping table for Extra Set, Code&Len Set and
493 @param Sd The global scratch data.
495 @return The value decoded.
506 if (Sd
->mBlockSize
== 0) {
508 // Starting a new block
509 // Read BlockSize from block header
511 Sd
->mBlockSize
= (UINT16
) GetBits (Sd
, 16);
514 // Read in the Extra Set Code Length Array,
515 // Generate the Huffman code mapping table for Extra Set.
517 Sd
->mBadTableFlag
= ReadPTLen (Sd
, NT
, TBIT
, 3);
518 if (Sd
->mBadTableFlag
!= 0) {
523 // Read in and decode the Char&Len Set Code Length Array,
524 // Generate the Huffman code mapping table for Char&Len Set.
529 // Read in the Position Set Code Length Array,
530 // Generate the Huffman code mapping table for the Position Set.
532 Sd
->mBadTableFlag
= ReadPTLen (Sd
, MAXNP
, Sd
->mPBit
, (UINT16
) (-1));
533 if (Sd
->mBadTableFlag
!= 0) {
539 // Get one code according to Code&Set Huffman Table
542 Index2
= Sd
->mCTable
[Sd
->mBitBuf
>> (BITBUFSIZ
- 12)];
545 Mask
= 1U << (BITBUFSIZ
- 1 - 12);
548 if ((Sd
->mBitBuf
& Mask
) != 0) {
549 Index2
= Sd
->mRight
[Index2
];
551 Index2
= Sd
->mLeft
[Index2
];
555 } while (Index2
>= NC
);
558 // Advance what we have read
560 FillBuf (Sd
, Sd
->mCLen
[Index2
]);
566 Decode the source data and put the resulting data into the destination buffer.
568 @param Sd The global scratch data
579 BytesRemain
= (UINT16
) (-1);
585 // Get one code from mBitBuf
587 CharC
= DecodeC (Sd
);
588 if (Sd
->mBadTableFlag
!= 0) {
594 // Process an Original character
596 if (Sd
->mOutBuf
>= Sd
->mOrigSize
) {
600 // Write orignal character into mDstBase
602 Sd
->mDstBase
[Sd
->mOutBuf
++] = (UINT8
) CharC
;
609 CharC
= (UINT16
) (CharC
- (BIT8
- THRESHOLD
));
617 // Locate string position
619 DataIdx
= Sd
->mOutBuf
- DecodeP (Sd
) - 1;
622 // Write BytesRemain of bytes into mDstBase
625 while ((INT16
) (BytesRemain
) >= 0) {
626 if (Sd
->mOutBuf
>= Sd
->mOrigSize
) {
629 if (DataIdx
>= Sd
->mOrigSize
) {
630 Sd
->mBadTableFlag
= (UINT16
) BAD_TABLE
;
633 Sd
->mDstBase
[Sd
->mOutBuf
++] = Sd
->mDstBase
[DataIdx
++];
645 Given a compressed source buffer, this function retrieves the size of
646 the uncompressed buffer and the size of the scratch buffer required
647 to decompress the compressed source buffer.
649 Retrieves the size of the uncompressed buffer and the temporary scratch buffer
650 required to decompress the buffer specified by Source and SourceSize.
651 If the size of the uncompressed buffer or the size of the scratch buffer cannot
652 be determined from the compressed data specified by Source and SourceData,
653 then RETURN_INVALID_PARAMETER is returned. Otherwise, the size of the uncompressed
654 buffer is returned in DestinationSize, the size of the scratch buffer is returned
655 in ScratchSize, and RETURN_SUCCESS is returned.
656 This function does not have scratch buffer available to perform a thorough
657 checking of the validity of the source data. It just retrieves the "Original Size"
658 field from the beginning bytes of the source data and output it as DestinationSize.
659 And ScratchSize is specific to the decompression implementation.
661 If Source is NULL, then ASSERT().
662 If DestinationSize is NULL, then ASSERT().
663 If ScratchSize is NULL, then ASSERT().
665 @param Source The source buffer containing the compressed data.
666 @param SourceSize The size, in bytes, of the source buffer.
667 @param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
668 that will be generated when the compressed buffer specified
669 by Source and SourceSize is decompressed..
670 @param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
671 is required to decompress the compressed buffer specified
672 by Source and SourceSize.
674 @retval RETURN_SUCCESS The size of the uncompressed data was returned
675 in DestinationSize and the size of the scratch
676 buffer was returned in ScratchSize.
677 @retval RETURN_INVALID_PARAMETER
678 The size of the uncompressed data or the size of
679 the scratch buffer cannot be determined from
680 the compressed data specified by Source
685 UefiDecompressGetInfo (
686 IN CONST VOID
*Source
,
687 IN UINT32 SourceSize
,
688 OUT UINT32
*DestinationSize
,
689 OUT UINT32
*ScratchSize
692 UINT32 CompressedSize
;
694 ASSERT (Source
!= NULL
);
695 ASSERT (DestinationSize
!= NULL
);
696 ASSERT (ScratchSize
!= NULL
);
698 if (SourceSize
< 8) {
699 return RETURN_INVALID_PARAMETER
;
702 CompressedSize
= ReadUnaligned32 ((UINT32
*)Source
);
703 if (SourceSize
< (CompressedSize
+ 8) || (CompressedSize
+ 8) < 8) {
704 return RETURN_INVALID_PARAMETER
;
707 *ScratchSize
= sizeof (SCRATCH_DATA
);
708 *DestinationSize
= ReadUnaligned32 ((UINT32
*)Source
+ 1);
710 return RETURN_SUCCESS
;
714 Decompresses a compressed source buffer by EFI or Tiano algorithm.
716 Extracts decompressed data to its original form.
717 This function is designed so that the decompression algorithm can be implemented
718 without using any memory services. As a result, this function is not allowed to
719 call any memory allocation services in its implementation. It is the caller's
720 responsibility to allocate and free the Destination and Scratch buffers.
721 If the compressed source data specified by Source is successfully decompressed
722 into Destination, then RETURN_SUCCESS is returned. If the compressed source data
723 specified by Source is not in a valid compressed data format,
724 then RETURN_INVALID_PARAMETER is returned.
726 If Source is NULL, then ASSERT().
727 If Destination is NULL, then ASSERT().
728 If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
730 @param Source The source buffer containing the compressed data.
731 @param Destination The destination buffer to store the decompressed data
732 @param Scratch A temporary scratch buffer that is used to perform the decompression.
733 This is an optional parameter that may be NULL if the
734 required scratch buffer size is 0.
735 @param Version 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm.
737 @retval RETURN_SUCCESS Decompression completed successfully, and
738 the uncompressed buffer is returned in Destination.
739 @retval RETURN_INVALID_PARAMETER
740 The source buffer specified by Source is corrupted
741 (not in a valid compressed format).
745 UefiTianoDecompress (
746 IN CONST VOID
*Source
,
747 IN OUT VOID
*Destination
,
748 IN OUT VOID
*Scratch
,
758 ASSERT (Source
!= NULL
);
759 ASSERT (Destination
!= NULL
);
760 ASSERT (Scratch
!= NULL
);
765 Sd
= (SCRATCH_DATA
*) Scratch
;
767 CompSize
= Src
[0] + (Src
[1] << 8) + (Src
[2] << 16) + (Src
[3] << 24);
768 OrigSize
= Src
[4] + (Src
[5] << 8) + (Src
[6] << 16) + (Src
[7] << 24);
771 // If compressed file size is 0, return
774 return RETURN_SUCCESS
;
779 SetMem (Sd
, sizeof (SCRATCH_DATA
), 0);
782 // The length of the field 'Position Set Code Length Array Size' in Block Header.
783 // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
784 // For Tiano de/compression algorithm(Version 2), mPBit = 5
796 Sd
->mSrcBase
= (UINT8
*)Src
;
799 // CompSize and OrigSize are calculated in bytes
801 Sd
->mCompSize
= CompSize
;
802 Sd
->mOrigSize
= OrigSize
;
805 // Fill the first BITBUFSIZ bits
807 FillBuf (Sd
, BITBUFSIZ
);
814 if (Sd
->mBadTableFlag
!= 0) {
816 // Something wrong with the source
818 return RETURN_INVALID_PARAMETER
;
821 return RETURN_SUCCESS
;
825 Decompresses a UEFI compressed source buffer.
827 Extracts decompressed data to its original form.
828 This function is designed so that the decompression algorithm can be implemented
829 without using any memory services. As a result, this function is not allowed to
830 call any memory allocation services in its implementation. It is the caller's
831 responsibility to allocate and free the Destination and Scratch buffers.
832 If the compressed source data specified by Source is successfully decompressed
833 into Destination, then RETURN_SUCCESS is returned. If the compressed source data
834 specified by Source is not in a valid compressed data format,
835 then RETURN_INVALID_PARAMETER is returned.
837 If Source is NULL, then ASSERT().
838 If Destination is NULL, then ASSERT().
839 If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
841 @param Source The source buffer containing the compressed data.
842 @param Destination The destination buffer to store the decompressed data
843 @param Scratch A temporary scratch buffer that is used to perform the decompression.
844 This is an optional parameter that may be NULL if the
845 required scratch buffer size is 0.
847 @retval RETURN_SUCCESS Decompression completed successfully, and
848 the uncompressed buffer is returned in Destination.
849 @retval RETURN_INVALID_PARAMETER
850 The source buffer specified by Source is corrupted
851 (not in a valid compressed format).
856 IN CONST VOID
*Source
,
857 IN OUT VOID
*Destination
,
858 IN OUT VOID
*Scratch OPTIONAL
861 return UefiTianoDecompress (Source
, Destination
, Scratch
, 1);
865 Examines a GUIDed section and returns the size of the decoded buffer and the
866 size of an optional scratch buffer required to actually decode the data in a GUIDed section.
868 Examines a GUIDed section specified by InputSection.
869 If GUID for InputSection does not match the GUID that this handler supports,
870 then RETURN_UNSUPPORTED is returned.
871 If the required information can not be retrieved from InputSection,
872 then RETURN_INVALID_PARAMETER is returned.
873 If the GUID of InputSection does match the GUID that this handler supports,
874 then the size required to hold the decoded buffer is returned in OututBufferSize,
875 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
876 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
878 If InputSection is NULL, then ASSERT().
879 If OutputBufferSize is NULL, then ASSERT().
880 If ScratchBufferSize is NULL, then ASSERT().
881 If SectionAttribute is NULL, then ASSERT().
884 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
885 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
886 if the buffer specified by InputSection were decoded.
887 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
888 if the buffer specified by InputSection were decoded.
889 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
890 field of EFI_GUID_DEFINED_SECTION in the PI Specification.
892 @retval RETURN_SUCCESS The information about InputSection was returned.
893 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
894 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
899 TianoDecompressGetInfo (
900 IN CONST VOID
*InputSection
,
901 OUT UINT32
*OutputBufferSize
,
902 OUT UINT32
*ScratchBufferSize
,
903 OUT UINT16
*SectionAttribute
907 ASSERT (SectionAttribute
!= NULL
);
909 if (InputSection
== NULL
) {
910 return RETURN_INVALID_PARAMETER
;
913 if (IS_SECTION2 (InputSection
)) {
915 &gTianoCustomDecompressGuid
,
916 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
917 return RETURN_INVALID_PARAMETER
;
920 // Get guid attribute of guid section.
922 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->Attributes
;
925 // Call Tiano GetInfo to get the required size info.
927 return UefiDecompressGetInfo (
928 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
929 SECTION2_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
935 &gTianoCustomDecompressGuid
,
936 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
937 return RETURN_INVALID_PARAMETER
;
940 // Get guid attribute of guid section.
942 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
945 // Call Tiano GetInfo to get the required size info.
947 return UefiDecompressGetInfo (
948 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
949 SECTION_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
957 Decompress a Tiano compressed GUIDed section into a caller allocated output buffer.
959 Decodes the GUIDed section specified by InputSection.
960 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
961 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
962 If the GUID of InputSection does match the GUID that this handler supports, then InputSection
963 is decoded into the buffer specified by OutputBuffer and the authentication status of this
964 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
965 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
966 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
968 If InputSection is NULL, then ASSERT().
969 If OutputBuffer is NULL, then ASSERT().
970 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
971 If AuthenticationStatus is NULL, then ASSERT().
974 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
975 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
976 @param[in] ScratchBuffer A caller allocated buffer that may be required by this function
977 as a scratch buffer to perform the decode operation.
978 @param[out] AuthenticationStatus
979 A pointer to the authentication status of the decoded output buffer.
980 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
981 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
982 never be set by this handler.
984 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
985 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
986 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
992 IN CONST VOID
*InputSection
,
993 OUT VOID
**OutputBuffer
,
994 IN VOID
*ScratchBuffer
, OPTIONAL
995 OUT UINT32
*AuthenticationStatus
998 ASSERT (OutputBuffer
!= NULL
);
999 ASSERT (InputSection
!= NULL
);
1001 if (IS_SECTION2 (InputSection
)) {
1003 &gTianoCustomDecompressGuid
,
1004 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
1005 return RETURN_INVALID_PARAMETER
;
1009 // Set Authentication to Zero.
1011 *AuthenticationStatus
= 0;
1014 // Call Tiano Decompress to get the raw data
1016 return UefiTianoDecompress (
1017 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
1024 &gTianoCustomDecompressGuid
,
1025 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
1026 return RETURN_INVALID_PARAMETER
;
1030 // Set Authentication to Zero.
1032 *AuthenticationStatus
= 0;
1035 // Call Tiano Decompress to get the raw data
1037 return UefiTianoDecompress (
1038 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
1047 Registers TianoDecompress and TianoDecompressGetInfo handlers with TianoCustomerDecompressGuid
1049 @retval RETURN_SUCCESS Register successfully.
1050 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
1054 TianoDecompressLibConstructor (
1058 return ExtractGuidedSectionRegisterHandlers (
1059 &gTianoCustomDecompressGuid
,
1060 TianoDecompressGetInfo
,