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
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 Tiano File Image Format Specification,
27 #include <GuidedSection.h>
28 #include <Crc32SectionExtract.h>
31 InitializeCrc32GuidedSectionExtractionProtocol (
32 IN EFI_HANDLE ImageHandle
,
33 IN EFI_SYSTEM_TABLE
*SystemTable
37 InitializeCrc32GuidedSectionExtractionProtocol (
38 IN EFI_HANDLE ImageHandle
,
39 IN EFI_SYSTEM_TABLE
*SystemTable
45 Entry point of the CRC32 GUIDed section extraction protocol.
46 Creates and initializes an instance of the GUIDed section
47 extraction protocol with CRC32 GUID.
51 ImageHandle EFI_HANDLE: A handle for the image that is initializing
53 SystemTable EFI_SYSTEM_TABLE: A pointer to the EFI system table
57 EFI_SUCCESS: Driver initialized successfully
58 EFI_LOAD_ERROR: Failed to Initialize or has been loaded
59 EFI_OUT_OF_RESOURCES: Could not allocate needed resources
64 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*Crc32GuidedSep
;
68 // Call all constructors per produced protocols
70 Status
= GuidedSectionExtractionProtocolConstructor (
72 (EFI_EXTRACT_GUIDED_SECTION
) Crc32ExtractSection
74 if (EFI_ERROR (Status
)) {
75 if (Crc32GuidedSep
!= NULL
) {
76 gBS
->FreePool (Crc32GuidedSep
);
82 // Pass in a NULL to install to a new handle
85 Status
= gBS
->InstallProtocolInterface (
87 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
91 if (EFI_ERROR (Status
)) {
92 gBS
->FreePool (Crc32GuidedSep
);
93 return EFI_LOAD_ERROR
;
102 IN EFI_COMMON_SECTION_HEADER
*CommonHeader
107 Get a length of section.
110 CommonHeader - Pointer to the common section header.
113 The length of the section, including the section header.
116 // TODO: function comment is missing 'Arguments:'
117 // TODO: function comment is missing 'Returns:'
118 // TODO: CommonHeader - add argument and description to function comment
122 Size
= *(UINT32
*) CommonHeader
->Size
& 0x00FFFFFF;
129 Crc32ExtractSection (
130 IN EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL
*This
,
131 IN VOID
*InputSection
,
132 OUT VOID
**OutputBuffer
,
133 OUT UINTN
*OutputSize
,
134 OUT UINT32
*AuthenticationStatus
139 This function reads and extracts contents of a section from an
140 encapsulating section.
143 This - Indicates the calling context.
144 InputSection - Buffer containing the input GUIDed section
146 OutputBuffer - *OutputBuffer is allocated from boot services
147 pool memory and containing the new section
148 stream. The caller is responsible for freeing
150 AuthenticationStatus - Pointer to a caller allocated UINT32 that
151 indicates the authentication status of the
157 EFI_INVALID_PARAMETER
158 EFI_NOT_AVAILABLE_YET
161 // TODO: function comment is missing 'Arguments:'
162 // TODO: function comment is missing 'Returns:'
163 // TODO: This - add argument and description to function comment
164 // TODO: InputSection - add argument and description to function comment
165 // TODO: OutputBuffer - add argument and description to function comment
166 // TODO: OutputSize - add argument and description to function comment
167 // TODO: AuthenticationStatus - add argument and description to function comment
168 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
169 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
170 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
171 // TODO: EFI_SUCCESS - add return value to function comment
174 CRC32_SECTION_HEADER
*Crc32SectionHeader
;
175 EFI_GUID_DEFINED_SECTION
*GuidedSectionHeader
;
177 UINT32 Crc32Checksum
;
178 VOID
*DummyInterface
;
180 if (OutputBuffer
== NULL
) {
181 return EFI_INVALID_PARAMETER
;
184 *OutputBuffer
= NULL
;
187 // Points to the section header
189 Crc32SectionHeader
= (CRC32_SECTION_HEADER
*) InputSection
;
190 GuidedSectionHeader
= (EFI_GUID_DEFINED_SECTION
*) InputSection
;
193 // Check if the GUID is a CRC32 section GUID
196 &(GuidedSectionHeader
->SectionDefinitionGuid
),
197 &gEfiCrc32GuidedSectionExtractionProtocolGuid
199 return EFI_INVALID_PARAMETER
;
202 Image
= (UINT8
*) InputSection
+ (UINT32
) (GuidedSectionHeader
->DataOffset
);
203 *OutputSize
= GetSectionLength ((EFI_COMMON_SECTION_HEADER
*) InputSection
) - (UINT32
) GuidedSectionHeader
->DataOffset
;
205 Status
= gBS
->AllocatePool (EfiBootServicesData
, *OutputSize
, OutputBuffer
);
206 if (EFI_ERROR (Status
)) {
207 return EFI_OUT_OF_RESOURCES
;
210 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set
212 ASSERT (GuidedSectionHeader
->Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
);
213 *AuthenticationStatus
= EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED
| EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED
;
216 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
218 Status
= gBS
->LocateProtocol (&gEfiSecurityPolicyProtocolGuid
, NULL
, &DummyInterface
);
219 if (!EFI_ERROR (Status
)) {
220 *AuthenticationStatus
|= EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE
| EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE
;
223 // Calculate CRC32 Checksum of Image
225 gBS
->CalculateCrc32 (Image
, *OutputSize
, &Crc32Checksum
);
226 if (Crc32Checksum
!= Crc32SectionHeader
->CRC32Checksum
) {
227 *AuthenticationStatus
|= EFI_LOCAL_AUTH_STATUS_TEST_FAILED
| EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED
;
231 CopyMem (*OutputBuffer
, Image
, *OutputSize
);