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