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
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.
18 Implements GUIDed section extraction protocol interface with
19 a specific GUID: CRC32.
21 Please refer to the Framewokr Firmware Volume Specification 0.9.
26 #include <Crc32SectionExtract.h>
29 GuidedSectionExtractionProtocolConstructor (
30 OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
**GuidedSep
,
31 IN EFI_EXTRACT_GUIDED_SECTION ExtractSection
37 Constructor for the GUIDed section extraction protocol. Initializes
42 This Instance to construct
46 EFI_SUCCESS: Instance initialized.
49 // TODO: GuidedSep - add argument and description to function comment
50 // TODO: ExtractSection - add argument and description to function comment
51 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
53 *GuidedSep
= AllocatePool (sizeof (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
));
54 if (*GuidedSep
== NULL
) {
55 return EFI_OUT_OF_RESOURCES
;
58 (*GuidedSep
)->ExtractSection
= ExtractSection
;
66 InitializeCrc32GuidedSectionExtractionProtocol (
67 IN EFI_HANDLE ImageHandle
,
68 IN EFI_SYSTEM_TABLE
*SystemTable
74 Entry point of the CRC32 GUIDed section extraction protocol.
75 Creates and initializes an instance of the GUIDed section
76 extraction protocol with CRC32 GUID.
80 ImageHandle EFI_HANDLE: A handle for the image that is initializing
82 SystemTable EFI_SYSTEM_TABLE: A pointer to the EFI system table
86 EFI_SUCCESS: Driver initialized successfully
87 EFI_LOAD_ERROR: Failed to Initialize or has been loaded
88 EFI_OUT_OF_RESOURCES: Could not allocate needed resources
93 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*Crc32GuidedSep
;
97 // Call all constructors per produced protocols
99 Status
= GuidedSectionExtractionProtocolConstructor (
101 (EFI_EXTRACT_GUIDED_SECTION
) Crc32ExtractSection
103 if (EFI_ERROR (Status
)) {
104 if (Crc32GuidedSep
!= NULL
) {
105 FreePool (Crc32GuidedSep
);
111 // Pass in a NULL to install to a new handle
114 Status
= gBS
->InstallProtocolInterface (
116 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
117 EFI_NATIVE_INTERFACE
,
120 if (EFI_ERROR (Status
)) {
121 FreePool (Crc32GuidedSep
);
122 return EFI_LOAD_ERROR
;
132 IN EFI_COMMON_SECTION_HEADER
*CommonHeader
137 Get a length of section.
140 CommonHeader - Pointer to the common section header.
143 The length of the section, including the section header.
146 // TODO: function comment is missing 'Arguments:'
147 // TODO: function comment is missing 'Returns:'
148 // TODO: CommonHeader - add argument and description to function comment
152 Size
= *(UINT32
*) CommonHeader
->Size
& 0x00FFFFFF;
160 Crc32ExtractSection (
161 IN EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*This
,
162 IN VOID
*InputSection
,
163 OUT VOID
**OutputBuffer
,
164 OUT UINTN
*OutputSize
,
165 OUT UINT32
*AuthenticationStatus
170 This function reads and extracts contents of a section from an
171 encapsulating section.
174 This - Indicates the calling context.
175 InputSection - Buffer containing the input GUIDed section
177 OutputBuffer - *OutputBuffer is allocated from boot services
178 pool memory and containing the new section
179 stream. The caller is responsible for freeing
181 AuthenticationStatus - Pointer to a caller allocated UINT32 that
182 indicates the authentication status of the
188 EFI_INVALID_PARAMETER
189 EFI_NOT_AVAILABLE_YET
192 // TODO: function comment is missing 'Arguments:'
193 // TODO: function comment is missing 'Returns:'
194 // TODO: This - add argument and description to function comment
195 // TODO: InputSection - add argument and description to function comment
196 // TODO: OutputBuffer - add argument and description to function comment
197 // TODO: OutputSize - add argument and description to function comment
198 // TODO: AuthenticationStatus - add argument and description to function comment
199 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
200 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
201 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
202 // TODO: EFI_SUCCESS - add return value to function comment
205 CRC32_SECTION_HEADER
*Crc32SectionHeader
;
206 EFI_GUID_DEFINED_SECTION
*GuidedSectionHeader
;
208 UINT32 Crc32Checksum
;
209 VOID
*DummyInterface
;
211 if (OutputBuffer
== NULL
) {
212 return EFI_INVALID_PARAMETER
;
215 *OutputBuffer
= NULL
;
218 // Points to the section header
220 Crc32SectionHeader
= (CRC32_SECTION_HEADER
*) InputSection
;
221 GuidedSectionHeader
= (EFI_GUID_DEFINED_SECTION
*) InputSection
;
224 // Check if the GUID is a CRC32 section GUID
227 &(GuidedSectionHeader
->SectionDefinitionGuid
),
228 &gEfiCrc32GuidedSectionExtractionProtocolGuid
230 return EFI_INVALID_PARAMETER
;
233 Image
= (UINT8
*) InputSection
+ (UINT32
) (GuidedSectionHeader
->DataOffset
);
234 *OutputSize
= GetSectionLength ((EFI_COMMON_SECTION_HEADER
*) InputSection
) - (UINT32
) GuidedSectionHeader
->DataOffset
;
236 *OutputBuffer
= AllocatePool (*OutputSize
);
237 if (*OutputBuffer
== NULL
) {
238 return EFI_OUT_OF_RESOURCES
;
241 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set
243 ASSERT (GuidedSectionHeader
->Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
);
244 *AuthenticationStatus
= EFI_AUTH_STATUS_IMAGE_SIGNED
;
247 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
249 Status
= gBS
->LocateProtocol (&gEfiSecurityPolicyProtocolGuid
, NULL
, &DummyInterface
);
250 if (!EFI_ERROR (Status
)) {
251 *AuthenticationStatus
|= EFI_AUTH_STATUS_PLATFORM_OVERRIDE
;
254 // Calculate CRC32 Checksum of Image
256 gBS
->CalculateCrc32 (Image
, *OutputSize
, &Crc32Checksum
);
257 if (Crc32Checksum
!= Crc32SectionHeader
->CRC32Checksum
) {
258 *AuthenticationStatus
|= EFI_AUTH_STATUS_TEST_FAILED
;
262 CopyMem (*OutputBuffer
, Image
, *OutputSize
);