From cf7958f7f9394c4a545b707b8409fc5b2ffaf84a Mon Sep 17 00:00:00 2001 From: jljusten Date: Fri, 2 Sep 2011 21:31:02 +0000 Subject: [PATCH] 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 --- .../IntelFrameworkModulePkg.dsc | 1 + .../Library/DxeCapsuleLib/DxeCapsuleLib.c | 141 ++++++++++++++++++ .../Library/DxeCapsuleLib/DxeCapsuleLib.inf | 47 ++++++ 3 files changed, 189 insertions(+) create mode 100644 IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c create mode 100644 IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf diff --git a/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc b/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc index 97d9228952..3fc3bcca69 100644 --- a/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc +++ b/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc @@ -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 diff --git a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c new file mode 100644 index 0000000000..12c72720f7 --- /dev/null +++ b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c @@ -0,0 +1,141 @@ +/** @file + Capsule Library instance to update capsule image to flash. + + Copyright (c) 2007 - 2010, 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. + +**/ +#include +#include +#include +#include +#include +#include +#include + +/** + 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; +} + + diff --git a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf new file mode 100644 index 0000000000..c11d8f7628 --- /dev/null +++ b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf @@ -0,0 +1,47 @@ +## @file +# Capsule library instance for DXE_DRIVER, DXE_RUNTIME_DRIVER +# +# Copyright (c) 2007 - 2011, 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 = 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 + \ No newline at end of file -- 2.39.2