]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/FirmwareVolume/GuidedSectionExtraction/Crc32SectionExtract/Dxe/Crc32SectionExtract.c
Fix the issues,
[mirror_edk2.git] / EdkModulePkg / Universal / FirmwareVolume / GuidedSectionExtraction / Crc32SectionExtract / Dxe / Crc32SectionExtract.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Crc32SectionExtract.c\r
15\r
16Abstract:\r
17\r
18 Implements GUIDed section extraction protocol interface with \r
19 a specific GUID: CRC32.\r
20\r
21 Please refer to the Tiano File Image Format Specification, \r
22 FV spec 0.3.6\r
23\r
24--*/\r
25\r
26\r
27#include <GuidedSection.h>\r
28#include <Crc32SectionExtract.h>\r
29\r
30EFI_STATUS\r
2bbf72b0 31EFIAPI\r
878ddf1f 32InitializeCrc32GuidedSectionExtractionProtocol (\r
33 IN EFI_HANDLE ImageHandle,\r
34 IN EFI_SYSTEM_TABLE *SystemTable\r
35 );\r
36\r
37EFI_STATUS\r
2bbf72b0 38EFIAPI\r
878ddf1f 39InitializeCrc32GuidedSectionExtractionProtocol (\r
40 IN EFI_HANDLE ImageHandle,\r
41 IN EFI_SYSTEM_TABLE *SystemTable\r
42 )\r
43/*++\r
44\r
45Routine Description: \r
46\r
47 Entry point of the CRC32 GUIDed section extraction protocol. \r
48 Creates and initializes an instance of the GUIDed section \r
49 extraction protocol with CRC32 GUID.\r
50\r
51Arguments: \r
52\r
53 ImageHandle EFI_HANDLE: A handle for the image that is initializing \r
54 this driver\r
55 SystemTable EFI_SYSTEM_TABLE: A pointer to the EFI system table \r
56\r
57Returns: \r
58\r
59 EFI_SUCCESS: Driver initialized successfully\r
60 EFI_LOAD_ERROR: Failed to Initialize or has been loaded \r
61 EFI_OUT_OF_RESOURCES: Could not allocate needed resources\r
62\r
63--*/\r
64{\r
65 EFI_STATUS Status;\r
66 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *Crc32GuidedSep;\r
67 EFI_HANDLE Handle;\r
68\r
69 //\r
70 // Call all constructors per produced protocols\r
71 //\r
72 Status = GuidedSectionExtractionProtocolConstructor (\r
73 &Crc32GuidedSep,\r
74 (EFI_EXTRACT_GUIDED_SECTION) Crc32ExtractSection\r
75 );\r
76 if (EFI_ERROR (Status)) {\r
77 if (Crc32GuidedSep != NULL) {\r
78 gBS->FreePool (Crc32GuidedSep);\r
79 }\r
80\r
81 return Status;\r
82 }\r
83 //\r
84 // Pass in a NULL to install to a new handle\r
85 //\r
86 Handle = NULL;\r
87 Status = gBS->InstallProtocolInterface (\r
88 &Handle,\r
89 &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
90 EFI_NATIVE_INTERFACE,\r
91 Crc32GuidedSep\r
92 );\r
93 if (EFI_ERROR (Status)) {\r
94 gBS->FreePool (Crc32GuidedSep);\r
95 return EFI_LOAD_ERROR;\r
96 }\r
97\r
98 return EFI_SUCCESS;\r
99}\r
100\r
101STATIC\r
102UINT32\r
2bbf72b0 103EFIAPI\r
878ddf1f 104GetSectionLength (\r
105 IN EFI_COMMON_SECTION_HEADER *CommonHeader\r
106 )\r
107/*++\r
108\r
109 Routine Description:\r
110 Get a length of section.\r
111\r
112 Parameters:\r
113 CommonHeader - Pointer to the common section header.\r
114\r
115 Return Value:\r
116 The length of the section, including the section header.\r
117\r
118--*/\r
119// TODO: function comment is missing 'Arguments:'\r
120// TODO: function comment is missing 'Returns:'\r
121// TODO: CommonHeader - add argument and description to function comment\r
122{\r
123 UINT32 Size;\r
124\r
125 Size = *(UINT32 *) CommonHeader->Size & 0x00FFFFFF;\r
126\r
127 return Size;\r
128}\r
129\r
130STATIC\r
131EFI_STATUS\r
2bbf72b0 132EFIAPI\r
878ddf1f 133Crc32ExtractSection (\r
134 IN EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
135 IN VOID *InputSection,\r
136 OUT VOID **OutputBuffer,\r
137 OUT UINTN *OutputSize,\r
138 OUT UINT32 *AuthenticationStatus\r
139 )\r
140/*++\r
141\r
142 Routine Description:\r
143 This function reads and extracts contents of a section from an\r
144 encapsulating section.\r
145\r
146 Parameters:\r
147 This - Indicates the calling context.\r
148 InputSection - Buffer containing the input GUIDed section \r
149 to be processed.\r
150 OutputBuffer - *OutputBuffer is allocated from boot services\r
151 pool memory and containing the new section\r
152 stream. The caller is responsible for freeing\r
153 this buffer.\r
154 AuthenticationStatus - Pointer to a caller allocated UINT32 that\r
155 indicates the authentication status of the\r
156 output buffer\r
157\r
158 Return Value:\r
159 EFI_SUCCESS\r
160 EFI_OUT_OF_RESOURCES\r
161 EFI_INVALID_PARAMETER\r
162 EFI_NOT_AVAILABLE_YET\r
163\r
164--*/\r
165// TODO: function comment is missing 'Arguments:'\r
166// TODO: function comment is missing 'Returns:'\r
167// TODO: This - add argument and description to function comment\r
168// TODO: InputSection - add argument and description to function comment\r
169// TODO: OutputBuffer - add argument and description to function comment\r
170// TODO: OutputSize - add argument and description to function comment\r
171// TODO: AuthenticationStatus - add argument and description to function comment\r
172// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
173// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
174// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
175// TODO: EFI_SUCCESS - add return value to function comment\r
176{\r
177 EFI_STATUS Status;\r
178 CRC32_SECTION_HEADER *Crc32SectionHeader;\r
179 EFI_GUID_DEFINED_SECTION *GuidedSectionHeader;\r
180 UINT8 *Image;\r
181 UINT32 Crc32Checksum;\r
182 VOID *DummyInterface;\r
183\r
184 if (OutputBuffer == NULL) {\r
185 return EFI_INVALID_PARAMETER;\r
186 }\r
187\r
188 *OutputBuffer = NULL;\r
189\r
190 //\r
191 // Points to the section header\r
192 //\r
193 Crc32SectionHeader = (CRC32_SECTION_HEADER *) InputSection;\r
194 GuidedSectionHeader = (EFI_GUID_DEFINED_SECTION *) InputSection;\r
195\r
196 //\r
197 // Check if the GUID is a CRC32 section GUID\r
198 //\r
199 if (!CompareGuid (\r
200 &(GuidedSectionHeader->SectionDefinitionGuid),\r
201 &gEfiCrc32GuidedSectionExtractionProtocolGuid\r
202 )) {\r
203 return EFI_INVALID_PARAMETER;\r
204 }\r
205\r
206 Image = (UINT8 *) InputSection + (UINT32) (GuidedSectionHeader->DataOffset);\r
207 *OutputSize = GetSectionLength ((EFI_COMMON_SECTION_HEADER *) InputSection) - (UINT32) GuidedSectionHeader->DataOffset;\r
208\r
209 Status = gBS->AllocatePool (EfiBootServicesData, *OutputSize, OutputBuffer);\r
210 if (EFI_ERROR (Status)) {\r
211 return EFI_OUT_OF_RESOURCES;\r
212 }\r
213 //\r
214 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set\r
215 //\r
216 ASSERT (GuidedSectionHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
217 *AuthenticationStatus = EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED;\r
218\r
219 //\r
220 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.\r
221 //\r
222 Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);\r
223 if (!EFI_ERROR (Status)) {\r
224 *AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE | EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE;\r
225 } else {\r
226 //\r
227 // Calculate CRC32 Checksum of Image\r
228 //\r
229 gBS->CalculateCrc32 (Image, *OutputSize, &Crc32Checksum);\r
230 if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\r
231 *AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_TEST_FAILED | EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED;\r
232 }\r
233 }\r
234\r
235 CopyMem (*OutputBuffer, Image, *OutputSize);\r
236\r
237 return EFI_SUCCESS;\r
238}\r