]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/FirmwareVolume/GuidedSectionExtraction/Crc32SectionExtract/Dxe/Crc32SectionExtract.c
Make EdkModulePkg pass Intel IPF compiler with /W4 /WX switches, solving warning...
[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
878ddf1f 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
37\r
38Routine Description: \r
39\r
40 Entry point of the CRC32 GUIDed section extraction protocol. \r
41 Creates and initializes an instance of the GUIDed section \r
42 extraction protocol with CRC32 GUID.\r
43\r
44Arguments: \r
45\r
46 ImageHandle EFI_HANDLE: A handle for the image that is initializing \r
47 this driver\r
48 SystemTable EFI_SYSTEM_TABLE: A pointer to the EFI system table \r
49\r
50Returns: \r
51\r
52 EFI_SUCCESS: Driver initialized successfully\r
53 EFI_LOAD_ERROR: Failed to Initialize or has been loaded \r
54 EFI_OUT_OF_RESOURCES: Could not allocate needed resources\r
55\r
56--*/\r
57{\r
58 EFI_STATUS Status;\r
59 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *Crc32GuidedSep;\r
60 EFI_HANDLE Handle;\r
61\r
62 //\r
63 // Call all constructors per produced protocols\r
64 //\r
65 Status = GuidedSectionExtractionProtocolConstructor (\r
66 &Crc32GuidedSep,\r
67 (EFI_EXTRACT_GUIDED_SECTION) Crc32ExtractSection\r
68 );\r
69 if (EFI_ERROR (Status)) {\r
70 if (Crc32GuidedSep != NULL) {\r
71 gBS->FreePool (Crc32GuidedSep);\r
72 }\r
73\r
74 return Status;\r
75 }\r
76 //\r
77 // Pass in a NULL to install to a new handle\r
78 //\r
79 Handle = NULL;\r
80 Status = gBS->InstallProtocolInterface (\r
81 &Handle,\r
82 &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
83 EFI_NATIVE_INTERFACE,\r
84 Crc32GuidedSep\r
85 );\r
86 if (EFI_ERROR (Status)) {\r
87 gBS->FreePool (Crc32GuidedSep);\r
88 return EFI_LOAD_ERROR;\r
89 }\r
90\r
91 return EFI_SUCCESS;\r
92}\r
93\r
94STATIC\r
95UINT32\r
2bbf72b0 96EFIAPI\r
878ddf1f 97GetSectionLength (\r
98 IN EFI_COMMON_SECTION_HEADER *CommonHeader\r
99 )\r
100/*++\r
101\r
102 Routine Description:\r
103 Get a length of section.\r
104\r
105 Parameters:\r
106 CommonHeader - Pointer to the common section header.\r
107\r
108 Return Value:\r
109 The length of the section, including the section header.\r
110\r
111--*/\r
112// TODO: function comment is missing 'Arguments:'\r
113// TODO: function comment is missing 'Returns:'\r
114// TODO: CommonHeader - add argument and description to function comment\r
115{\r
116 UINT32 Size;\r
117\r
118 Size = *(UINT32 *) CommonHeader->Size & 0x00FFFFFF;\r
119\r
120 return Size;\r
121}\r
122\r
123STATIC\r
124EFI_STATUS\r
2bbf72b0 125EFIAPI\r
878ddf1f 126Crc32ExtractSection (\r
127 IN EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,\r
128 IN VOID *InputSection,\r
129 OUT VOID **OutputBuffer,\r
130 OUT UINTN *OutputSize,\r
131 OUT UINT32 *AuthenticationStatus\r
132 )\r
133/*++\r
134\r
135 Routine Description:\r
136 This function reads and extracts contents of a section from an\r
137 encapsulating section.\r
138\r
139 Parameters:\r
140 This - Indicates the calling context.\r
141 InputSection - Buffer containing the input GUIDed section \r
142 to be processed.\r
143 OutputBuffer - *OutputBuffer is allocated from boot services\r
144 pool memory and containing the new section\r
145 stream. The caller is responsible for freeing\r
146 this buffer.\r
147 AuthenticationStatus - Pointer to a caller allocated UINT32 that\r
148 indicates the authentication status of the\r
149 output buffer\r
150\r
151 Return Value:\r
152 EFI_SUCCESS\r
153 EFI_OUT_OF_RESOURCES\r
154 EFI_INVALID_PARAMETER\r
155 EFI_NOT_AVAILABLE_YET\r
156\r
157--*/\r
158// TODO: function comment is missing 'Arguments:'\r
159// TODO: function comment is missing 'Returns:'\r
160// TODO: This - add argument and description to function comment\r
161// TODO: InputSection - add argument and description to function comment\r
162// TODO: OutputBuffer - add argument and description to function comment\r
163// TODO: OutputSize - add argument and description to function comment\r
164// TODO: AuthenticationStatus - add argument and description to function comment\r
165// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
166// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
167// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
168// TODO: EFI_SUCCESS - add return value to function comment\r
169{\r
170 EFI_STATUS Status;\r
171 CRC32_SECTION_HEADER *Crc32SectionHeader;\r
172 EFI_GUID_DEFINED_SECTION *GuidedSectionHeader;\r
173 UINT8 *Image;\r
174 UINT32 Crc32Checksum;\r
175 VOID *DummyInterface;\r
176\r
177 if (OutputBuffer == NULL) {\r
178 return EFI_INVALID_PARAMETER;\r
179 }\r
180\r
181 *OutputBuffer = NULL;\r
182\r
183 //\r
184 // Points to the section header\r
185 //\r
186 Crc32SectionHeader = (CRC32_SECTION_HEADER *) InputSection;\r
187 GuidedSectionHeader = (EFI_GUID_DEFINED_SECTION *) InputSection;\r
188\r
189 //\r
190 // Check if the GUID is a CRC32 section GUID\r
191 //\r
192 if (!CompareGuid (\r
193 &(GuidedSectionHeader->SectionDefinitionGuid),\r
194 &gEfiCrc32GuidedSectionExtractionProtocolGuid\r
195 )) {\r
196 return EFI_INVALID_PARAMETER;\r
197 }\r
198\r
199 Image = (UINT8 *) InputSection + (UINT32) (GuidedSectionHeader->DataOffset);\r
200 *OutputSize = GetSectionLength ((EFI_COMMON_SECTION_HEADER *) InputSection) - (UINT32) GuidedSectionHeader->DataOffset;\r
201\r
202 Status = gBS->AllocatePool (EfiBootServicesData, *OutputSize, OutputBuffer);\r
203 if (EFI_ERROR (Status)) {\r
204 return EFI_OUT_OF_RESOURCES;\r
205 }\r
206 //\r
207 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set\r
208 //\r
209 ASSERT (GuidedSectionHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
210 *AuthenticationStatus = EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED;\r
211\r
212 //\r
213 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.\r
214 //\r
215 Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);\r
216 if (!EFI_ERROR (Status)) {\r
217 *AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE | EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE;\r
218 } else {\r
219 //\r
220 // Calculate CRC32 Checksum of Image\r
221 //\r
222 gBS->CalculateCrc32 (Image, *OutputSize, &Crc32Checksum);\r
223 if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\r
224 *AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_TEST_FAILED | EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED;\r
225 }\r
226 }\r
227\r
228 CopyMem (*OutputBuffer, Image, *OutputSize);\r
229\r
230 return EFI_SUCCESS;\r
231}\r