Rename Crc32GuidedSectionExtractLib to DxeCrc32GuidedSectionExtractLib.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4156 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4 2007-10-17 07:52:02 +00:00
parent 899bc55181
commit d51ffc1fca
2 changed files with 214 additions and 0 deletions

View File

@ -0,0 +1,166 @@
/*++
Copyright (c) 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DxeCrc32GuidedSectionExtractLib.c
Abstract:
Implements GUIDed section extraction protocol interface with
a specific GUID: CRC32.
Please refer to the Framewokr Firmware Volume Specification 0.9.
--*/
#include <PiDxe.h>
#include <Protocol/Crc32GuidedSectionExtraction.h>
#include <Protocol/SecurityPolicy.h>
#include <Library/ExtractGuidedSectionLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
typedef struct {
EFI_GUID_DEFINED_SECTION GuidedSectionHeader;
UINT32 CRC32Checksum;
} CRC32_SECTION_HEADER;
EFI_STATUS
EFIAPI
Crc32GuidedSectionGetInfo (
IN CONST VOID *InputSection,
OUT UINT32 *OutputBufferSize,
OUT UINT32 *ScratchBufferSize,
OUT UINT16 *SectionAttribute
)
/*++
Routine Description:
The implementation of Crc32 guided section GetInfo().
Arguments:
InputSection Buffer containing the input GUIDed section to be processed.
OutputBufferSize The size of OutputBuffer.
ScratchBufferSize The size of ScratchBuffer.
SectionAttribute The attribute of the input guided section.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
//
// Retrieve the size and attribute of the input section data.
//
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
*ScratchBufferSize = 0;
*OutputBufferSize = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff;
*OutputBufferSize -= ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
Crc32GuidedSectionHandler (
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
IN VOID *ScratchBuffer, OPTIONAL
OUT UINT32 *AuthenticationStatus
)
/*++
Routine Description:
The implementation of Crc32 Guided section extraction.
Arguments:
InputSection Buffer containing the input GUIDed section to be processed.
OutputBuffer OutputBuffer to point to the start of the section's contents.
if guided data is not prcessed. Otherwise,
OutputBuffer to contain the output data, which is allocated by the caller.
ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
authentication status of the output buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
EFI_STATUS Status;
CRC32_SECTION_HEADER *Crc32SectionHeader;
UINT32 Crc32Checksum;
UINT32 OutputBufferSize;
VOID *DummyInterface;
Crc32Checksum = 0;
//
// Points to the Crc32 section header
//
Crc32SectionHeader = (CRC32_SECTION_HEADER *) InputSection;
*OutputBuffer = (UINT8 *) InputSection + Crc32SectionHeader->GuidedSectionHeader.DataOffset;
OutputBufferSize = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff;
OutputBufferSize -= Crc32SectionHeader->GuidedSectionHeader.DataOffset;
//
// Implictly CRC32 GUIDed section should have STATUS_VALID bit set
//
ASSERT (Crc32SectionHeader->GuidedSectionHeader.Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);
*AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;
//
// Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.
//
Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);
if (!EFI_ERROR (Status)) {
*AuthenticationStatus |= EFI_AUTH_STATUS_PLATFORM_OVERRIDE;
} else {
//
// Calculate CRC32 Checksum of Image
//
Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);
if (Status == EFI_SUCCESS) {
if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {
*AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;
}
} else {
*AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;
}
}
return EFI_SUCCESS;
}
/**
Register Crc32 section handler.
@retval RETURN_SUCCESS Register successfully.
@retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
**/
EFI_STATUS
EFIAPI
DxeCrc32GuidedSectionExtractLibConstructor (
)
{
return ExtractGuidedSectionRegisterHandlers (
&gEfiCrc32GuidedSectionExtractionProtocolGuid,
Crc32GuidedSectionGetInfo,
Crc32GuidedSectionHandler
);
}

View File

@ -0,0 +1,48 @@
#/** @file
# Component description file for Crc32SectionExtract library.
#
# Copyright (c) 2006 - 2007, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
#**/
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeCrc32GuidedSectionExtractLib
FILE_GUID = 387A2490-81FC-4E7C-8E0A-3E58C30FCD0B
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
CONSTRUCTOR = DxeCrc32GuidedSectionExtractLibConstructor
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
DxeCrc32GuidedSectionExtractLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
ExtractGuidedSectionLib
UefiBootServicesTableLib
DebugLib
[Protocols]
gEfiCrc32GuidedSectionExtractionProtocolGuid
gEfiSecurityPolicyProtocolGuid