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/UefiBootServicesTableLib.h>
33 EFI_GUID_DEFINED_SECTION GuidedSectionHeader
;
35 } CRC32_SECTION_HEADER
;
39 Crc32GuidedSectionGetInfo (
40 IN CONST VOID
*InputSection
,
41 OUT UINT32
*OutputBufferSize
,
42 OUT UINT32
*ScratchBufferSize
,
43 OUT UINT16
*SectionAttribute
49 The implementation of Crc32 guided section GetInfo().
52 InputSection Buffer containing the input GUIDed section to be processed.
53 OutputBufferSize The size of OutputBuffer.
54 ScratchBufferSize The size of ScratchBuffer.
55 SectionAttribute The attribute of the input guided section.
59 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
60 EFI_INVALID_PARAMETER - The source data is corrupted
65 // Retrieve the size and attribute of the input section data.
67 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
68 *ScratchBufferSize
= 0;
69 *OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
70 *OutputBufferSize
-= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
;
77 Crc32GuidedSectionHandler (
78 IN CONST VOID
*InputSection
,
79 OUT VOID
**OutputBuffer
,
80 IN VOID
*ScratchBuffer
, OPTIONAL
81 OUT UINT32
*AuthenticationStatus
87 The implementation of Crc32 Guided section extraction.
90 InputSection Buffer containing the input GUIDed section to be processed.
91 OutputBuffer OutputBuffer to point to the start of the section's contents.
92 if guided data is not prcessed. Otherwise,
93 OutputBuffer to contain the output data, which is allocated by the caller.
94 ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
95 AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
96 authentication status of the output buffer.
100 EFI_SUCCESS - Decompression is successfull
101 EFI_INVALID_PARAMETER - The source data is corrupted
106 CRC32_SECTION_HEADER
*Crc32SectionHeader
;
107 UINT32 Crc32Checksum
;
108 UINT32 OutputBufferSize
;
109 VOID
*DummyInterface
;
113 // Points to the Crc32 section header
115 Crc32SectionHeader
= (CRC32_SECTION_HEADER
*) InputSection
;
116 *OutputBuffer
= (UINT8
*) InputSection
+ Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
117 OutputBufferSize
= *(UINT32
*) (((EFI_COMMON_SECTION_HEADER
*) InputSection
)->Size
) & 0x00ffffff;
118 OutputBufferSize
-= Crc32SectionHeader
->GuidedSectionHeader
.DataOffset
;
121 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set
123 ASSERT (Crc32SectionHeader
->GuidedSectionHeader
.Attributes
& EFI_GUIDED_SECTION_AUTH_STATUS_VALID
);
124 *AuthenticationStatus
= EFI_AUTH_STATUS_IMAGE_SIGNED
;
127 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
129 Status
= gBS
->LocateProtocol (&gEfiSecurityPolicyProtocolGuid
, NULL
, &DummyInterface
);
130 if (!EFI_ERROR (Status
)) {
131 *AuthenticationStatus
|= EFI_AUTH_STATUS_PLATFORM_OVERRIDE
;
134 // Calculate CRC32 Checksum of Image
136 Status
= gBS
->CalculateCrc32 (*OutputBuffer
, OutputBufferSize
, &Crc32Checksum
);
137 if (Status
== EFI_SUCCESS
) {
138 if (Crc32Checksum
!= Crc32SectionHeader
->CRC32Checksum
) {
139 *AuthenticationStatus
|= EFI_AUTH_STATUS_TEST_FAILED
;
142 *AuthenticationStatus
|= EFI_AUTH_STATUS_NOT_TESTED
;
150 Register Crc32 section handler.
152 @retval RETURN_SUCCESS Register successfully.
153 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
157 DxeCrc32GuidedSectionExtractLibConstructor (
160 return ExtractGuidedSectionRegisterHandlers (
161 &gEfiCrc32GuidedSectionExtractionProtocolGuid
,
162 Crc32GuidedSectionGetInfo
,
163 Crc32GuidedSectionHandler