3 Copyright (c) 2006, 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.
18 BDS routines to handle capsules.
24 // Include common header file for this module.
26 #include "CommonHeader.h"
28 #include <Common/FlashMap.H>
32 IN EFI_CPU_IO_PROTOCOL
*CpuIo
,
33 IN EFI_FLASH_SUBAREA_ENTRY
*FlashEntry
38 IN EFI_CPU_IO_PROTOCOL
*CpuIo
,
39 IN EFI_FLASH_SUBAREA_ENTRY
*FlashEntry
45 BdsLockNonUpdatableFlash (
53 EFI_BOOT_MODE BootMode
59 This routine is called to see if there are any capsules we need to process.
60 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
61 capsule HOBS and produce firmware volumes for them via the DXE service.
62 Then call the dispatcher to dispatch drivers from them. Finally, check
63 the status of the updates.
67 BootMode - the current boot mode
71 EFI_INVALID_PARAMETER - boot mode is not correct for an update
75 This function should be called by BDS in case we need to do some
76 sort of processing even if there is no capsule to process. We
77 need to do this if an earlier update went awry and we need to
78 clear the capsule variable so on the next reset PEI does not see it and
79 think there is a capsule available.
84 EFI_HOB_CAPSULE_VOLUME
*CvHob
;
85 EFI_PHYSICAL_ADDRESS BaseAddress
;
87 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
88 EFI_HANDLE FvProtocolHandle
;
91 // We don't do anything else if the boot mode is not flash-update
93 if (BootMode
!= BOOT_ON_FLASH_UPDATE
) {
94 return EFI_INVALID_PARAMETER
;
97 // Only one capsule HOB allowed.
99 CvHob
= GetFirstHob (EFI_HOB_TYPE_CV
);
102 // We didn't find a hob, so had no errors.
104 BdsLockNonUpdatableFlash ();
108 BaseAddress
= CvHob
->BaseAddress
;
109 Length
= CvHob
->Length
;
111 Status
= EFI_SUCCESS
;
113 // Now walk the capsule and call the core to process each
114 // firmware volume in it.
116 while (Length
!= 0) {
118 // Point to the next firmware volume header, and then
119 // call the DXE service to process it.
121 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) BaseAddress
;
122 if (FwVolHeader
->FvLength
> Length
) {
124 // Notes: need to stuff this status somewhere so that the
125 // error can be detected at OS runtime
127 Status
= EFI_VOLUME_CORRUPTED
;
131 Status
= gDS
->ProcessFirmwareVolume (
132 (VOID
*) (UINTN
) BaseAddress
,
133 (UINTN
) FwVolHeader
->FvLength
,
136 if (EFI_ERROR (Status
)) {
140 // Call the dispatcher to dispatch any drivers from the produced firmware volume
144 // On to the next FV in the capsule
146 Length
-= FwVolHeader
->FvLength
;
147 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) ((UINTN
) BaseAddress
+ FwVolHeader
->FvLength
);
149 // Notes: when capsule spec is finalized, if the requirement is made to
150 // have each FV in a capsule aligned, then we will need to align the
151 // BaseAddress and Length here.
156 BdsLockNonUpdatableFlash ();