IntelFrameworkModulePkg: Add DxeCapsuleLib

Signed-off-by: jljusten
Reviewed-by: rsun3
Reviewed-by: lgao4

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12274 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jljusten 2011-09-02 21:31:02 +00:00
parent 352892190a
commit cf7958f7f9
3 changed files with 189 additions and 0 deletions

View File

@ -136,6 +136,7 @@
IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
IntelFrameworkModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf
IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf
IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf
IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf

View File

@ -0,0 +1,141 @@
/** @file
Capsule Library instance to update capsule image to flash.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#include <PiDxe.h>
#include <Guid/Capsule.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/CapsuleLib.h>
/**
Those capsules supported by the firmwares.
@param CapsuleHeader Points to a capsule header.
@retval EFI_SUCESS Input capsule is supported by firmware.
@retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
**/
EFI_STATUS
EFIAPI
SupportCapsuleImage (
IN EFI_CAPSULE_HEADER *CapsuleHeader
)
{
if (CompareGuid (&gEfiCapsuleGuid, &CapsuleHeader->CapsuleGuid)) {
return EFI_SUCCESS;
}
return EFI_UNSUPPORTED;
}
/**
The firmware implements to process the capsule image.
@param CapsuleHeader Points to a capsule header.
@retval EFI_SUCESS Process Capsule Image successfully.
@retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
@retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
@retval EFI_OUT_OF_RESOURCES Not enough memory.
**/
EFI_STATUS
EFIAPI
ProcessCapsuleImage (
IN EFI_CAPSULE_HEADER *CapsuleHeader
)
{
UINT32 Length;
EFI_FIRMWARE_VOLUME_HEADER *FvImage;
EFI_FIRMWARE_VOLUME_HEADER *ProcessedFvImage;
EFI_STATUS Status;
EFI_HANDLE FvProtocolHandle;
UINT32 FvAlignment;
FvImage = NULL;
ProcessedFvImage = NULL;
Status = EFI_SUCCESS;
if (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS) {
return EFI_UNSUPPORTED;
}
//
// Skip the capsule header, move to the Firware Volume
//
FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize);
Length = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;
while (Length != 0) {
//
// Point to the next firmware volume header, and then
// call the DXE service to process it.
//
if (FvImage->FvLength > (UINTN) Length) {
//
// Notes: need to stuff this status somewhere so that the
// error can be detected at OS runtime
//
Status = EFI_VOLUME_CORRUPTED;
break;
}
FvAlignment = 1 << ((FvImage->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
//
// FvAlignment must be more than 8 bytes required by FvHeader structure.
//
if (FvAlignment < 8) {
FvAlignment = 8;
}
//
// Check FvImage Align is required.
//
if (((UINTN) FvImage % FvAlignment) == 0) {
ProcessedFvImage = FvImage;
} else {
//
// Allocate new aligned buffer to store FvImage.
//
ProcessedFvImage = (EFI_FIRMWARE_VOLUME_HEADER *) AllocateAlignedPages ((UINTN) EFI_SIZE_TO_PAGES (FvImage->FvLength), (UINTN) FvAlignment);
if (ProcessedFvImage == NULL) {
Status = EFI_OUT_OF_RESOURCES;
break;
}
CopyMem (ProcessedFvImage, FvImage, (UINTN) FvImage->FvLength);
}
Status = gDS->ProcessFirmwareVolume (
(VOID *) ProcessedFvImage,
(UINTN) ProcessedFvImage->FvLength,
&FvProtocolHandle
);
if (EFI_ERROR (Status)) {
break;
}
//
// Call the dispatcher to dispatch any drivers from the produced firmware volume
//
gDS->Dispatch ();
//
// On to the next FV in the capsule
//
Length -= (UINT32) FvImage->FvLength;
FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) FvImage + FvImage->FvLength);
}
return Status;
}

View File

@ -0,0 +1,47 @@
## @file
# Capsule library instance for DXE_DRIVER, DXE_RUNTIME_DRIVER
#
# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
#
# 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 = DxeCapsuleLib
FILE_GUID = 654950df-1ede-4b04-b144-6b77845736ad
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = CapsuleLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DxeCapsuleLib.c
[Packages]
MdePkg/MdePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseMemoryLib
DebugLib
MemoryAllocationLib
DxeServicesTableLib
[Guids]
gEfiCapsuleGuid # SOMETIMES_CONSUMED