]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
ad80f2b6beae1e86e6bee795f463d9a53897fd9a
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / BaseUefiTianoCustomDecompressLib / BaseUefiTianoCustomDecompressLib.c
1 /**@file
2 UEFI and Custom Decompress Library
3 The function of UefiTianoDecompress() is interface for this module,
4 it will do tiano or uefi decompress with different verison parameter.
5 See EFI specification 1.1 Chapter 17 to get LZ77 compress/decompress.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "BaseUefiTianoCustomDecompressLibInternals.h"
19
20 /**
21 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
22
23 @param Sd The global scratch data
24 @param NumOfBits The number of bits to shift and read.
25 **/
26 VOID
27 FillBuf (
28 IN SCRATCH_DATA *Sd,
29 IN UINT16 NumOfBits
30 )
31 {
32 Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
33
34 while (NumOfBits > Sd->mBitCount) {
35
36 Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
37
38 if (Sd->mCompSize > 0) {
39 //
40 // Get 1 byte into SubBitBuf
41 //
42 Sd->mCompSize--;
43 Sd->mSubBitBuf = 0;
44 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
45 Sd->mBitCount = 8;
46
47 } else {
48 //
49 // No more bits from the source, just pad zero bit.
50 //
51 Sd->mSubBitBuf = 0;
52 Sd->mBitCount = 8;
53
54 }
55 }
56
57 Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
58 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
59 }
60
61 /**
62 Get NumOfBits of bits out from mBitBuf
63
64 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
65 NumOfBits of bits from source. Returns NumOfBits of bits that are
66 popped out.
67
68 @param Sd The global scratch data.
69 @param NumOfBits The number of bits to pop and read.
70
71 @return The bits that are popped out.
72
73 **/
74 UINT32
75 GetBits (
76 IN SCRATCH_DATA *Sd,
77 IN UINT16 NumOfBits
78 )
79 {
80 UINT32 OutBits;
81
82 OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
83
84 FillBuf (Sd, NumOfBits);
85
86 return OutBits;
87 }
88
89 /**
90 Creates Huffman Code mapping table according to code length array.
91
92 Creates Huffman Code mapping table for Extra Set, Char&Len Set
93 and Position Set according to code length array.
94
95 @param Sd The global scratch data
96 @param NumOfChar Number of symbols in the symbol set
97 @param BitLen Code length array
98 @param TableBits The width of the mapping table
99 @param Table The table
100
101 @retval 0 OK.
102 @retval BAD_TABLE The table is corrupted.
103
104 **/
105 UINT16
106 MakeTable (
107 IN SCRATCH_DATA *Sd,
108 IN UINT16 NumOfChar,
109 IN UINT8 *BitLen,
110 IN UINT16 TableBits,
111 OUT UINT16 *Table
112 )
113 {
114 UINT16 Count[17];
115 UINT16 Weight[17];
116 UINT16 Start[18];
117 UINT16 *Pointer;
118 UINT16 Index3;
119 UINT16 Index;
120 UINT16 Len;
121 UINT16 Char;
122 UINT16 JuBits;
123 UINT16 Avail;
124 UINT16 NextCode;
125 UINT16 Mask;
126 UINT16 WordOfStart;
127 UINT16 WordOfCount;
128
129 for (Index = 0; Index <= 16; Index++) {
130 Count[Index] = 0;
131 }
132
133 for (Index = 0; Index < NumOfChar; Index++) {
134 Count[BitLen[Index]]++;
135 }
136
137 Start[0] = 0;
138 Start[1] = 0;
139
140 for (Index = 1; Index <= 16; Index++) {
141 WordOfStart = Start[Index];
142 WordOfCount = Count[Index];
143 Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));
144 }
145
146 if (Start[17] != 0) {
147 /*(1U << 16)*/
148 return (UINT16) BAD_TABLE;
149 }
150
151 JuBits = (UINT16) (16 - TableBits);
152
153 Weight[0] = 0;
154 for (Index = 1; Index <= TableBits; Index++) {
155 Start[Index] >>= JuBits;
156 Weight[Index] = (UINT16) (1U << (TableBits - Index));
157 }
158
159 while (Index <= 16) {
160 Weight[Index] = (UINT16) (1U << (16 - Index));
161 Index++;
162 }
163
164 Index = (UINT16) (Start[TableBits + 1] >> JuBits);
165
166 if (Index != 0) {
167 Index3 = (UINT16) (1U << TableBits);
168 if (Index < Index3) {
169 SetMem16 (Table + Index, (Index3 - Index) * sizeof (*Table), 0);
170 }
171 }
172
173 Avail = NumOfChar;
174 Mask = (UINT16) (1U << (15 - TableBits));
175
176 for (Char = 0; Char < NumOfChar; Char++) {
177
178 Len = BitLen[Char];
179 if (Len == 0 || Len >= 17) {
180 continue;
181 }
182
183 NextCode = (UINT16) (Start[Len] + Weight[Len]);
184
185 if (Len <= TableBits) {
186
187 for (Index = Start[Len]; Index < NextCode; Index++) {
188 Table[Index] = Char;
189 }
190
191 } else {
192
193 Index3 = Start[Len];
194 Pointer = &Table[Index3 >> JuBits];
195 Index = (UINT16) (Len - TableBits);
196
197 while (Index != 0) {
198 if (*Pointer == 0 && Avail < (2 * NC - 1)) {
199 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
200 *Pointer = Avail++;
201 }
202
203 if (*Pointer < (2 * NC - 1)) {
204 if ((Index3 & Mask) != 0) {
205 Pointer = &Sd->mRight[*Pointer];
206 } else {
207 Pointer = &Sd->mLeft[*Pointer];
208 }
209 }
210
211 Index3 <<= 1;
212 Index--;
213 }
214
215 *Pointer = Char;
216
217 }
218
219 Start[Len] = NextCode;
220 }
221 //
222 // Succeeds
223 //
224 return 0;
225 }
226
227 /**
228 Decodes a position value.
229
230 @param Sd the global scratch data
231
232 @return The position value decoded.
233 **/
234 UINT32
235 DecodeP (
236 IN SCRATCH_DATA *Sd
237 )
238 {
239 UINT16 Val;
240 UINT32 Mask;
241 UINT32 Pos;
242
243 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
244
245 if (Val >= MAXNP) {
246 Mask = 1U << (BITBUFSIZ - 1 - 8);
247
248 do {
249
250 if (Sd->mBitBuf & Mask) {
251 Val = Sd->mRight[Val];
252 } else {
253 Val = Sd->mLeft[Val];
254 }
255
256 Mask >>= 1;
257 } while (Val >= MAXNP);
258 }
259 //
260 // Advance what we have read
261 //
262 FillBuf (Sd, Sd->mPTLen[Val]);
263
264 Pos = Val;
265 if (Val > 1) {
266 Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
267 }
268
269 return Pos;
270 }
271
272 /**
273 Reads code lengths for the Extra Set or the Position Set.
274
275 Read in the Extra Set or Pointion Set Length Arrary, then
276 generate the Huffman code mapping for them.
277
278 @param Sd The global scratch data.
279 @param nn Number of symbols.
280 @param nbit Number of bits needed to represent nn.
281 @param Special The special symbol that needs to be taken care of.
282
283 @retval 0 OK.
284 @retval BAD_TABLE Table is corrupted.
285
286 **/
287 UINT16
288 ReadPTLen (
289 IN SCRATCH_DATA *Sd,
290 IN UINT16 nn,
291 IN UINT16 nbit,
292 IN UINT16 Special
293 )
294 {
295 UINT16 Number;
296 UINT16 CharC;
297 UINT16 Index;
298 UINT32 Mask;
299
300 //
301 // Read Extra Set Code Length Array size
302 //
303 Number = (UINT16) GetBits (Sd, nbit);
304
305 if (Number == 0) {
306 //
307 // This represents only Huffman code used
308 //
309 CharC = (UINT16) GetBits (Sd, nbit);
310
311 for (Index = 0; Index < 256; Index++) {
312 Sd->mPTTable[Index] = CharC;
313 }
314
315 SetMem (Sd->mPTLen, nn, 0);
316
317 return 0;
318 }
319
320 Index = 0;
321
322 while (Index < Number && Index < NPT) {
323
324 CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
325
326 //
327 // If a code length is less than 7, then it is encoded as a 3-bit
328 // value. Or it is encoded as a series of "1"s followed by a
329 // terminating "0". The number of "1"s = Code length - 4.
330 //
331 if (CharC == 7) {
332 Mask = 1U << (BITBUFSIZ - 1 - 3);
333 while (Mask & Sd->mBitBuf) {
334 Mask >>= 1;
335 CharC += 1;
336 }
337 }
338
339 FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
340
341 Sd->mPTLen[Index++] = (UINT8) CharC;
342
343 //
344 // For Code&Len Set,
345 // After the third length of the code length concatenation,
346 // a 2-bit value is used to indicated the number of consecutive
347 // zero lengths after the third length.
348 //
349 if (Index == Special) {
350 CharC = (UINT16) GetBits (Sd, 2);
351 while ((INT16) (--CharC) >= 0 && Index < NPT) {
352 Sd->mPTLen[Index++] = 0;
353 }
354 }
355 }
356
357 while (Index < nn && Index < NPT) {
358 Sd->mPTLen[Index++] = 0;
359 }
360
361 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
362 }
363
364 /**
365 Reads code lengths for Char&Len Set.
366
367 Read in and decode the Char&Len Set Code Length Array, then
368 generate the Huffman Code mapping table for the Char&Len Set.
369
370 @param Sd the global scratch data
371
372 **/
373 VOID
374 ReadCLen (
375 SCRATCH_DATA *Sd
376 )
377 {
378 UINT16 Number;
379 UINT16 CharC;
380 UINT16 Index;
381 UINT32 Mask;
382
383 Number = (UINT16) GetBits (Sd, CBIT);
384
385 if (Number == 0) {
386 //
387 // This represents only Huffman code used
388 //
389 CharC = (UINT16) GetBits (Sd, CBIT);
390
391 SetMem (Sd->mCLen, NC, 0);
392
393 for (Index = 0; Index < 4096; Index++) {
394 Sd->mCTable[Index] = CharC;
395 }
396
397 return ;
398 }
399
400 Index = 0;
401 while (Index < Number && Index < NC) {
402 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
403 if (CharC >= NT) {
404 Mask = 1U << (BITBUFSIZ - 1 - 8);
405
406 do {
407
408 if (Mask & Sd->mBitBuf) {
409 CharC = Sd->mRight[CharC];
410 } else {
411 CharC = Sd->mLeft[CharC];
412 }
413
414 Mask >>= 1;
415
416 } while (CharC >= NT);
417 }
418 //
419 // Advance what we have read
420 //
421 FillBuf (Sd, Sd->mPTLen[CharC]);
422
423 if (CharC <= 2) {
424
425 if (CharC == 0) {
426 CharC = 1;
427 } else if (CharC == 1) {
428 CharC = (UINT16) (GetBits (Sd, 4) + 3);
429 } else if (CharC == 2) {
430 CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
431 }
432
433 while ((INT16) (--CharC) >= 0 && Index < NC) {
434 Sd->mCLen[Index++] = 0;
435 }
436
437 } else {
438
439 Sd->mCLen[Index++] = (UINT8) (CharC - 2);
440
441 }
442 }
443
444 SetMem (Sd->mCLen + Index, NC - Index, 0);
445
446 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
447
448 return ;
449 }
450
451 /**
452 Decode a character/length value.
453
454 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
455 Huffman code mapping table for Extra Set, Code&Len Set and
456 Position Set.
457
458 @param Sd The global scratch data.
459
460 @return The value decoded.
461
462 **/
463 UINT16
464 DecodeC (
465 SCRATCH_DATA *Sd
466 )
467 {
468 UINT16 Index2;
469 UINT32 Mask;
470
471 if (Sd->mBlockSize == 0) {
472 //
473 // Starting a new block
474 //
475 Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
476 Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
477 if (Sd->mBadTableFlag != 0) {
478 return 0;
479 }
480
481 ReadCLen (Sd);
482
483 Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
484 if (Sd->mBadTableFlag != 0) {
485 return 0;
486 }
487 }
488
489 Sd->mBlockSize--;
490 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
491
492 if (Index2 >= NC) {
493 Mask = 1U << (BITBUFSIZ - 1 - 12);
494
495 do {
496 if (Sd->mBitBuf & Mask) {
497 Index2 = Sd->mRight[Index2];
498 } else {
499 Index2 = Sd->mLeft[Index2];
500 }
501
502 Mask >>= 1;
503 } while (Index2 >= NC);
504 }
505 //
506 // Advance what we have read
507 //
508 FillBuf (Sd, Sd->mCLen[Index2]);
509
510 return Index2;
511 }
512
513 /**
514 Decode the source data ad put the resulting data into the destination buffer.
515
516 @param Sd - The global scratch data
517 **/
518 VOID
519 Decode (
520 SCRATCH_DATA *Sd
521 )
522 {
523 UINT16 BytesRemain;
524 UINT32 DataIdx;
525 UINT16 CharC;
526
527 BytesRemain = (UINT16) (-1);
528
529 DataIdx = 0;
530
531 for (;;) {
532 CharC = DecodeC (Sd);
533 if (Sd->mBadTableFlag != 0) {
534 goto Done ;
535 }
536
537 if (CharC < 256) {
538 //
539 // Process an Original character
540 //
541 if (Sd->mOutBuf >= Sd->mOrigSize) {
542 goto Done ;
543 } else {
544 Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
545 }
546
547 } else {
548 //
549 // Process a Pointer
550 //
551 CharC = (UINT16) (CharC - (BIT8 - THRESHOLD));
552
553 BytesRemain = CharC;
554
555 DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
556
557 BytesRemain--;
558 while ((INT16) (BytesRemain) >= 0) {
559 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
560 if (Sd->mOutBuf >= Sd->mOrigSize) {
561 goto Done ;
562 }
563
564 BytesRemain--;
565 }
566 }
567 }
568
569 Done:
570 return ;
571 }
572
573 /**
574 The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
575
576 @param Source The source buffer containing the compressed data.
577 @param SourceSize The size of source buffer
578 @param DestinationSize The size of destination buffer.
579 @param ScratchSize The size of scratch buffer.
580
581 @retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
582 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
583 **/
584 RETURN_STATUS
585 EFIAPI
586 UefiDecompressGetInfo (
587 IN CONST VOID *Source,
588 IN UINT32 SourceSize,
589 OUT UINT32 *DestinationSize,
590 OUT UINT32 *ScratchSize
591 )
592 {
593 UINT32 CompressedSize;
594
595 ASSERT (Source != NULL);
596 ASSERT (DestinationSize != NULL);
597 ASSERT (ScratchSize != NULL);
598
599 if (SourceSize < 8) {
600 return RETURN_INVALID_PARAMETER;
601 }
602
603 CompressedSize = ReadUnaligned32 ((UINT32 *)Source);
604 if (SourceSize < (CompressedSize + 8)) {
605 return RETURN_INVALID_PARAMETER;
606 }
607
608 *ScratchSize = sizeof (SCRATCH_DATA);
609 *DestinationSize = ReadUnaligned32 ((UINT32 *)Source + 1);
610
611 return RETURN_SUCCESS;
612 }
613
614 /**
615 The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
616
617 @param Source The source buffer containing the compressed data.
618 @param Destination The destination buffer to store the decompressed data
619 @param Scratch The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
620 @param Version 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm
621
622 @retval RETURN_SUCCESS Decompression is successfull
623 @retval RETURN_INVALID_PARAMETER The source data is corrupted
624 **/
625 RETURN_STATUS
626 EFIAPI
627 UefiTianoDecompress (
628 IN CONST VOID *Source,
629 IN OUT VOID *Destination,
630 IN OUT VOID *Scratch,
631 IN UINT32 Version
632 )
633 {
634 UINT32 CompSize;
635 UINT32 OrigSize;
636 SCRATCH_DATA *Sd;
637 CONST UINT8 *Src;
638 UINT8 *Dst;
639
640 ASSERT (Source != NULL);
641 ASSERT (Destination != NULL);
642 ASSERT (Scratch != NULL);
643
644 Src = Source;
645 Dst = Destination;
646
647 Sd = (SCRATCH_DATA *) Scratch;
648
649 CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
650 OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
651
652 //
653 // If compressed file size is 0, return
654 //
655 if (OrigSize == 0) {
656 return RETURN_SUCCESS;
657 }
658
659 Src = Src + 8;
660
661 SetMem (Sd, sizeof (SCRATCH_DATA), 0);
662
663 //
664 // The length of the field 'Position Set Code Length Array Size' in Block Header.
665 // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
666 // For Tiano de/compression algorithm(Version 2), mPBit = 5
667 //
668 switch (Version) {
669 case 1 :
670 Sd->mPBit = 4;
671 break;
672 case 2 :
673 Sd->mPBit = 5;
674 break;
675 default:
676 ASSERT (FALSE);
677 }
678 Sd->mSrcBase = (UINT8 *)Src;
679 Sd->mDstBase = Dst;
680 Sd->mCompSize = CompSize;
681 Sd->mOrigSize = OrigSize;
682
683 //
684 // Fill the first BITBUFSIZ bits
685 //
686 FillBuf (Sd, BITBUFSIZ);
687
688 //
689 // Decompress it
690 //
691 Decode (Sd);
692
693 if (Sd->mBadTableFlag != 0) {
694 //
695 // Something wrong with the source
696 //
697 return RETURN_INVALID_PARAMETER;
698 }
699
700 return RETURN_SUCCESS;
701 }
702
703 /**
704 The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
705
706 @param Source - The source buffer containing the compressed data.
707 @param Destination - The destination buffer to store the decompressed data
708 @param Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
709
710 @retval RETURN_SUCCESS - Decompression is successfull
711 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
712 **/
713 RETURN_STATUS
714 EFIAPI
715 UefiDecompress (
716 IN CONST VOID *Source,
717 IN OUT VOID *Destination,
718 IN OUT VOID *Scratch
719 )
720 {
721 return UefiTianoDecompress (Source, Destination, Scratch, 1);
722 }
723
724 /**
725 The internal implementation of Tiano decompress GetInfo.
726
727 @param InputSection Buffer containing the input GUIDed section to be processed.
728 @param OutputBufferSize The size of OutputBuffer.
729 @param ScratchBufferSize The size of ScratchBuffer.
730 @param SectionAttribute The attribute of the input guided section.
731
732 @retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
733 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
734 The GUID in InputSection does not match this instance guid.
735 **/
736 RETURN_STATUS
737 EFIAPI
738 TianoDecompressGetInfo (
739 IN CONST VOID *InputSection,
740 OUT UINT32 *OutputBufferSize,
741 OUT UINT32 *ScratchBufferSize,
742 OUT UINT16 *SectionAttribute
743 )
744
745 {
746 ASSERT (SectionAttribute != NULL);
747
748 if (InputSection == NULL) {
749 return RETURN_INVALID_PARAMETER;
750 }
751
752 if (!CompareGuid (
753 &gTianoCustomDecompressGuid,
754 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
755 return RETURN_INVALID_PARAMETER;
756 }
757 //
758 // Get guid attribute of guid section.
759 //
760 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
761
762 //
763 // Call Tiano GetInfo to get the required size info.
764 //
765 return UefiDecompressGetInfo (
766 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
767 (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
768 OutputBufferSize,
769 ScratchBufferSize
770 );
771 }
772
773 /**
774 The implementation of Tiano Decompress().
775
776 @param InputSection Buffer containing the input GUIDed section to be processed.
777 @param OutputBuffer OutputBuffer to point to the start of the section's contents.
778 if guided data is not prcessed. Otherwise,
779 OutputBuffer to contain the output data, which is allocated by the caller.
780 @param ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
781 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
782 authentication status of the output buffer.
783
784 @retval RETURN_SUCCESS Decompression is successfull
785 @retval RETURN_INVALID_PARAMETER The source data is corrupted, or
786 The GUID in InputSection does not match this instance guid.
787
788 **/
789 RETURN_STATUS
790 EFIAPI
791 TianoDecompress (
792 IN CONST VOID *InputSection,
793 OUT VOID **OutputBuffer,
794 IN VOID *ScratchBuffer, OPTIONAL
795 OUT UINT32 *AuthenticationStatus
796 )
797 {
798 ASSERT (OutputBuffer != NULL);
799
800 if (InputSection == NULL) {
801 return RETURN_INVALID_PARAMETER;
802 }
803
804 if (!CompareGuid (
805 &gTianoCustomDecompressGuid,
806 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
807 return RETURN_INVALID_PARAMETER;
808 }
809
810 //
811 // Set Authentication to Zero.
812 //
813 *AuthenticationStatus = 0;
814
815 //
816 // Call Tiano Decompress to get the raw data
817 //
818 return UefiTianoDecompress (
819 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
820 *OutputBuffer,
821 ScratchBuffer,
822 2
823 );
824 }
825
826 /**
827 Register TianoDecompress handler.
828
829 @retval RETURN_SUCCESS Register successfully.
830 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
831 **/
832 RETURN_STATUS
833 EFIAPI
834 TianoDecompressLibConstructor (
835 )
836 {
837 return ExtractGuidedSectionRegisterHandlers (
838 &gTianoCustomDecompressGuid,
839 TianoDecompressGetInfo,
840 TianoDecompress
841 );
842 }