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