2 Capsule Library instance to update capsule image to flash.
4 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Guid/Capsule.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DxeServicesTableLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/CapsuleLib.h>
24 Those capsules supported by the firmwares.
26 @param CapsuleHeader Points to a capsule header.
28 @retval EFI_SUCESS Input capsule is supported by firmware.
29 @retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
34 IN EFI_CAPSULE_HEADER
*CapsuleHeader
37 if (CompareGuid (&gEfiCapsuleGuid
, &CapsuleHeader
->CapsuleGuid
)) {
41 return EFI_UNSUPPORTED
;
45 The firmware implements to process the capsule image.
47 @param CapsuleHeader Points to a capsule header.
49 @retval EFI_SUCESS Process Capsule Image successfully.
50 @retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
51 @retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
52 @retval EFI_OUT_OF_RESOURCES Not enough memory.
57 IN EFI_CAPSULE_HEADER
*CapsuleHeader
61 EFI_FIRMWARE_VOLUME_HEADER
*FvImage
;
62 EFI_FIRMWARE_VOLUME_HEADER
*ProcessedFvImage
;
64 EFI_HANDLE FvProtocolHandle
;
68 ProcessedFvImage
= NULL
;
71 if (SupportCapsuleImage (CapsuleHeader
) != EFI_SUCCESS
) {
72 return EFI_UNSUPPORTED
;
76 // Skip the capsule header, move to the Firware Volume
78 FvImage
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINT8
*) CapsuleHeader
+ CapsuleHeader
->HeaderSize
);
79 Length
= CapsuleHeader
->CapsuleImageSize
- CapsuleHeader
->HeaderSize
;
83 // Point to the next firmware volume header, and then
84 // call the DXE service to process it.
86 if (FvImage
->FvLength
> (UINTN
) Length
) {
88 // Notes: need to stuff this status somewhere so that the
89 // error can be detected at OS runtime
91 Status
= EFI_VOLUME_CORRUPTED
;
95 FvAlignment
= 1 << ((FvImage
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
97 // FvAlignment must be more than 8 bytes required by FvHeader structure.
99 if (FvAlignment
< 8) {
103 // Check FvImage Align is required.
105 if (((UINTN
) FvImage
% FvAlignment
) == 0) {
106 ProcessedFvImage
= FvImage
;
109 // Allocate new aligned buffer to store FvImage.
111 ProcessedFvImage
= (EFI_FIRMWARE_VOLUME_HEADER
*) AllocateAlignedPages ((UINTN
) EFI_SIZE_TO_PAGES ((UINTN
) FvImage
->FvLength
), (UINTN
) FvAlignment
);
112 if (ProcessedFvImage
== NULL
) {
113 Status
= EFI_OUT_OF_RESOURCES
;
116 CopyMem (ProcessedFvImage
, FvImage
, (UINTN
) FvImage
->FvLength
);
119 Status
= gDS
->ProcessFirmwareVolume (
120 (VOID
*) ProcessedFvImage
,
121 (UINTN
) ProcessedFvImage
->FvLength
,
124 if (EFI_ERROR (Status
)) {
128 // Call the dispatcher to dispatch any drivers from the produced firmware volume
132 // On to the next FV in the capsule
134 Length
-= (UINT32
) FvImage
->FvLength
;
135 FvImage
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINT8
*) FvImage
+ FvImage
->FvLength
);