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