]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / LzmaCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
306bf4e2 1/** @file\r
2 LZMA Decompress GUIDed Section Extraction Library\r
3\r
4 Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/ExtractGuidedSectionLib.h>\r
19#include <Pi/PiFirmwareFile.h>\r
20#include <Guid/LzmaDecompress.h>\r
21\r
22#include "LzmaDecompress.h"\r
23\r
24\r
25STATIC\r
26RETURN_STATUS\r
27EFIAPI\r
28LzmaGuidedSectionGetCompressedLocation (\r
29 IN CONST VOID *InputSection,\r
30 OUT VOID **LmzaCompressedData,\r
31 OUT UINT32 *LmzaCompressedDataSize OPTIONAL\r
32 )\r
33{\r
34 if (!CompareGuid (\r
35 &gLzmaCustomDecompressGuid, \r
36 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
37 return RETURN_INVALID_PARAMETER;\r
38 }\r
39\r
40 //\r
41 // Retrieve the size and attribute of the input section data.\r
42 //\r
43 *LmzaCompressedData =\r
44 (VOID*) (\r
45 (UINT8 *) InputSection +\r
46 ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
47 );\r
48 if (LmzaCompressedDataSize != NULL) {\r
49 *LmzaCompressedDataSize =\r
50 (UINT32)(\r
51 (\r
52 (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size)) &\r
53 0x00ffffff\r
54 ) -\r
55 ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
56 );\r
57 }\r
58\r
59 return RETURN_SUCCESS;\r
60}\r
61\r
62\r
63/**\r
64 The implementation of 'GetInfo' for Guided Section\r
65 Extraction of LZMA compression.\r
66\r
67 @param InputSection Buffer containing the input GUIDed section to be processed. \r
68 @param OutputBufferSize The size of OutputBuffer.\r
69 @param ScratchBufferSize The size of ScratchBuffer.\r
70 @param SectionAttribute The attribute of the input guided section.\r
71\r
72 @retval RETURN_SUCCESS The size of destination buffer and the size of scratch buffer are successull retrieved.\r
73 @retval RETURN_INVALID_PARAMETER The source data is corrupted, or\r
74 The GUID in InputSection does not match this instance guid.\r
75\r
76**/\r
77RETURN_STATUS\r
78EFIAPI\r
79LzmaGuidedSectionGetInfo (\r
80 IN CONST VOID *InputSection,\r
81 OUT UINT32 *OutputBufferSize,\r
82 OUT UINT32 *ScratchBufferSize,\r
83 OUT UINT16 *SectionAttribute\r
84 )\r
85{\r
86 RETURN_STATUS Status;\r
87 VOID *LzmaInput;\r
88 UINT32 LzmaInputSize;\r
89\r
90 Status = LzmaGuidedSectionGetCompressedLocation(\r
91 InputSection,\r
92 &LzmaInput,\r
93 &LzmaInputSize\r
94 );\r
95 if (RETURN_ERROR (Status)) {\r
96 return Status;\r
97 }\r
98\r
99 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
100\r
101 return LzmaUefiDecompressGetInfo (\r
102 LzmaInput,\r
103 LzmaInputSize,\r
104 OutputBufferSize,\r
105 ScratchBufferSize\r
106 );\r
107}\r
108\r
109/**\r
110 The implementation of Guided Section Extraction\r
111 for LZMA compression.\r
112\r
113 @param InputSection Buffer containing the input GUIDed section to be processed. \r
114 @param OutputBuffer OutputBuffer to point to the start of the section's contents.\r
115 if guided data is not prcessed. Otherwise,\r
116 OutputBuffer to contain the output data, which is allocated by the caller.\r
117 @param ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r
118 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the\r
119 authentication status of the output buffer. \r
120\r
121 @retval RETURN_SUCCESS Decompression is successfull\r
122 @retval RETURN_INVALID_PARAMETER The source data is corrupted, or\r
123 The GUID in InputSection does not match this instance guid.\r
124\r
125**/\r
126RETURN_STATUS\r
127EFIAPI\r
128LzmaGuidedSectionExtraction (\r
129 IN CONST VOID *InputSection,\r
130 OUT VOID **OutputBuffer,\r
131 IN VOID *ScratchBuffer, OPTIONAL\r
132 OUT UINT32 *AuthenticationStatus\r
133 )\r
134{\r
135 RETURN_STATUS Status;\r
136 VOID *LzmaInput;\r
137\r
138 Status = LzmaGuidedSectionGetCompressedLocation(\r
139 InputSection,\r
140 &LzmaInput,\r
141 NULL\r
142 );\r
143 if (RETURN_ERROR (Status)) {\r
144 return Status;\r
145 }\r
146\r
147 //\r
148 // Authentication is set to Zero, which may be ignored.\r
149 //\r
150 *AuthenticationStatus = 0;\r
151\r
152 return LzmaUefiDecompress (\r
153 LzmaInput,\r
154 *OutputBuffer,\r
155 ScratchBuffer\r
156 );\r
157}\r
158\r
159\r
160/**\r
161 Register LzmaDecompress handler.\r
162\r
163 @retval RETURN_SUCCESS Register successfully.\r
164 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r
165**/\r
166EFI_STATUS\r
167EFIAPI\r
168LzmaDecompressLibConstructor (\r
169 )\r
170{\r
171 return ExtractGuidedSectionRegisterHandlers (\r
172 &gLzmaCustomDecompressGuid,\r
173 LzmaGuidedSectionGetInfo,\r
174 LzmaGuidedSectionExtraction\r
175 ); \r
176}\r
177\r