3 Copyright (c) 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.
14 DxeCrc32GuidedSectionExtractLib.c
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 <Protocol/Crc32GuidedSectionExtraction.h>
27 #include <Protocol/SecurityPolicy.h>
28 #include <Library/ExtractGuidedSectionLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
34 EFI_GUID_DEFINED_SECTION GuidedSectionHeader
;
36 } CRC32_SECTION_HEADER
;
40 Crc32GuidedSectionGetInfo (
41 IN CONST VOID
*InputSection
,
42 OUT UINT32
*OutputBufferSize
,
43 OUT UINT32
*ScratchBufferSize
,
44 OUT UINT16
*SectionAttribute
50 The implementation of Crc32 guided section GetInfo().
53 InputSection Buffer containing the input GUIDed section to be processed.
54 OutputBufferSize The size of OutputBuffer.
55 ScratchBufferSize The size of ScratchBuffer.
56 SectionAttribute The attribute of the input guided section.
60 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
61 EFI_INVALID_PARAMETER - The source data is corrupted, or
62 The GUID in InputSection does not match this instance guid.
67 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
68 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
69 return EFI_INVALID_PARAMETER
;
72 // Retrieve the size and attribute of the input section data.
74 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
75 *ScratchBufferSize
= 0;
76 *OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
77 *OutputBufferSize
-= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
;
84 Crc32GuidedSectionHandler (
85 IN CONST VOID
*InputSection
,
86 OUT VOID
**OutputBuffer
,
87 IN VOID
*ScratchBuffer
, OPTIONAL
88 OUT UINT32
*AuthenticationStatus
94 The implementation of Crc32 Guided section extraction.
97 InputSection Buffer containing the input GUIDed section to be processed.
98 OutputBuffer OutputBuffer to point to the start of the section's contents.
99 if guided data is not prcessed. Otherwise,
100 OutputBuffer to contain the output data, which is allocated by the caller.
101 ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
102 AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
103 authentication status of the output buffer.
107 RETURN_SUCCESS - Decompression is successfull
108 RETURN_INVALID_PARAMETER - The source data is corrupted, or
109 The GUID in InputSection does not match this instance guid.
114 CRC32_SECTION_HEADER
*Crc32SectionHeader
;
115 UINT32 Crc32Checksum
;
116 UINT32 OutputBufferSize
;
117 VOID
*DummyInterface
;
120 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
121 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
122 return EFI_INVALID_PARAMETER
;
127 // Points to the Crc32 section header
129 Crc32SectionHeader
= (CRC32_SECTION_HEADER
*) InputSection
;
130 *OutputBuffer
= (UINT8
*) InputSection
+ Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
131 OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
132 OutputBufferSize
-= Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
135 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set
137 ASSERT (Crc32SectionHeader
->GuidedSectionHeader
.Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
);
138 *AuthenticationStatus
= EFI_AUTH_STATUS_IMAGE_SIGNED
;
141 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
143 Status
= gBS
->LocateProtocol (&gEfiSecurityPolicyProtocolGuid
, NULL
, &DummyInterface
);
144 if (!EFI_ERROR (Status
)) {
145 *AuthenticationStatus
|= EFI_AUTH_STATUS_PLATFORM_OVERRIDE
;
148 // Calculate CRC32 Checksum of Image
150 Status
= gBS
->CalculateCrc32 (*OutputBuffer
, OutputBufferSize
, &Crc32Checksum
);
151 if (Status
== EFI_SUCCESS
) {
152 if (Crc32Checksum
!= Crc32SectionHeader
->CRC32Checksum
) {
153 *AuthenticationStatus
|= EFI_AUTH_STATUS_TEST_FAILED
;
156 *AuthenticationStatus
|= EFI_AUTH_STATUS_NOT_TESTED
;
164 Register Crc32 section handler.
166 @retval RETURN_SUCCESS Register successfully.
167 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
171 DxeCrc32GuidedSectionExtractLibConstructor (
174 return ExtractGuidedSectionRegisterHandlers (
175 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
176 Crc32GuidedSectionGetInfo
,
177 Crc32GuidedSectionHandler