]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
Update the copyright notice format
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / LzmaCustomDecompressLib / GuidedSectionExtraction.c
1 /** @file
2 LZMA Decompress GUIDed Section Extraction Library.
3 It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces
4 and registers them into GUIDed handler table.
5
6 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "LzmaDecompressLibInternal.h"
18
19 /**
20 Examines a GUIDed section and returns the size of the decoded buffer and the
21 size of an scratch buffer required to actually decode the data in a GUIDed section.
22
23 Examines a GUIDed section specified by InputSection.
24 If GUID for InputSection does not match the GUID that this handler supports,
25 then RETURN_UNSUPPORTED is returned.
26 If the required information can not be retrieved from InputSection,
27 then RETURN_INVALID_PARAMETER is returned.
28 If the GUID of InputSection does match the GUID that this handler supports,
29 then the size required to hold the decoded buffer is returned in OututBufferSize,
30 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
31 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
32
33 If InputSection is NULL, then ASSERT().
34 If OutputBufferSize is NULL, then ASSERT().
35 If ScratchBufferSize is NULL, then ASSERT().
36 If SectionAttribute is NULL, then ASSERT().
37
38
39 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
40 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
41 if the buffer specified by InputSection were decoded.
42 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
43 if the buffer specified by InputSection were decoded.
44 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
45 field of EFI_GUID_DEFINED_SECTION in the PI Specification.
46
47 @retval RETURN_SUCCESS The information about InputSection was returned.
48 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
49 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
50
51 **/
52 RETURN_STATUS
53 EFIAPI
54 LzmaGuidedSectionGetInfo (
55 IN CONST VOID *InputSection,
56 OUT UINT32 *OutputBufferSize,
57 OUT UINT32 *ScratchBufferSize,
58 OUT UINT16 *SectionAttribute
59 )
60 {
61 ASSERT (InputSection != NULL);
62 ASSERT (OutputBufferSize != NULL);
63 ASSERT (ScratchBufferSize != NULL);
64 ASSERT (SectionAttribute != NULL);
65
66 if (!CompareGuid (
67 &gLzmaCustomDecompressGuid,
68 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
69 return RETURN_INVALID_PARAMETER;
70 }
71
72 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
73
74 return LzmaUefiDecompressGetInfo (
75 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
76 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
77 OutputBufferSize,
78 ScratchBufferSize
79 );
80 }
81
82 /**
83 Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
84
85 Decodes the GUIDed section specified by InputSection.
86 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
87 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
88 If the GUID of InputSection does match the GUID that this handler supports, then InputSection
89 is decoded into the buffer specified by OutputBuffer and the authentication status of this
90 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
91 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
92 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
93
94 If InputSection is NULL, then ASSERT().
95 If OutputBuffer is NULL, then ASSERT().
96 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
97 If AuthenticationStatus is NULL, then ASSERT().
98
99
100 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
101 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
102 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function
103 as a scratch buffer to perform the decode operation.
104 @param[out] AuthenticationStatus
105 A pointer to the authentication status of the decoded output buffer.
106 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
107 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
108 never be set by this handler.
109
110 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
111 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
112 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
113
114 **/
115 RETURN_STATUS
116 EFIAPI
117 LzmaGuidedSectionExtraction (
118 IN CONST VOID *InputSection,
119 OUT VOID **OutputBuffer,
120 OUT VOID *ScratchBuffer, OPTIONAL
121 OUT UINT32 *AuthenticationStatus
122 )
123 {
124 ASSERT (OutputBuffer != NULL);
125 ASSERT (InputSection != NULL);
126
127 if (!CompareGuid (
128 &gLzmaCustomDecompressGuid,
129 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
130 return RETURN_INVALID_PARAMETER;
131 }
132
133 //
134 // Authentication is set to Zero, which may be ignored.
135 //
136 *AuthenticationStatus = 0;
137
138 return LzmaUefiDecompress (
139 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
140 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
141 *OutputBuffer,
142 ScratchBuffer
143 );
144 }
145
146
147 /**
148 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.
149
150 @retval RETURN_SUCCESS Register successfully.
151 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
152 **/
153 EFI_STATUS
154 EFIAPI
155 LzmaDecompressLibConstructor (
156 )
157 {
158 return ExtractGuidedSectionRegisterHandlers (
159 &gLzmaCustomDecompressGuid,
160 LzmaGuidedSectionGetInfo,
161 LzmaGuidedSectionExtraction
162 );
163 }
164