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