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
42 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
43 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
49 BaseAddress
= FlashEntry
->Base
- 0x400000 + 2;
50 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (FlashEntry
->Base
));
51 BlockMap
= &(FvHeader
->FvBlockMap
[0]);
53 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->BlockLength
!= 0)) {
54 BlockLength
= BlockMap
->BlockLength
;
55 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
63 Data
= (UINT8
) (Data
| 0x3);
71 BaseAddress
+= BlockLength
;
79 BdsLockNonUpdatableFlash (
83 EFI_FLASH_MAP_ENTRY_DATA
*FlashMapEntryData
;
84 EFI_PEI_HOB_POINTERS GuidHob
;
86 EFI_CPU_IO_PROTOCOL
*CpuIo
;
88 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, &CpuIo
);
89 ASSERT_EFI_ERROR (Status
);
91 GuidHob
.Raw
= GetHobList ();
92 while ((GuidHob
.Raw
= GetNextGuidHob (&gEfiFlashMapHobGuid
, GuidHob
.Raw
)) != NULL
) {
93 FlashMapEntryData
= (EFI_FLASH_MAP_ENTRY_DATA
*) GET_GUID_HOB_DATA (GuidHob
.Guid
);
96 // Get the variable store area
98 if ((FlashMapEntryData
->AreaType
== EFI_FLASH_AREA_RECOVERY_BIOS
) ||
99 (FlashMapEntryData
->AreaType
== EFI_FLASH_AREA_MAIN_BIOS
)
101 BdsLockFv (CpuIo
, &(FlashMapEntryData
->Entries
[0]));
103 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
111 EFI_BOOT_MODE BootMode
117 This routine is called to see if there are any capsules we need to process.
118 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
119 capsule HOBS and produce firmware volumes for them via the DXE service.
120 Then call the dispatcher to dispatch drivers from them. Finally, check
121 the status of the updates.
125 BootMode - the current boot mode
129 EFI_INVALID_PARAMETER - boot mode is not correct for an update
133 This function should be called by BDS in case we need to do some
134 sort of processing even if there is no capsule to process. We
135 need to do this if an earlier update went awry and we need to
136 clear the capsule variable so on the next reset PEI does not see it and
137 think there is a capsule available.
142 EFI_HOB_CAPSULE_VOLUME
*CvHob
;
143 EFI_PHYSICAL_ADDRESS BaseAddress
;
145 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
146 EFI_HANDLE FvProtocolHandle
;
149 // We don't do anything else if the boot mode is not flash-update
151 if (BootMode
!= BOOT_ON_FLASH_UPDATE
) {
152 return EFI_INVALID_PARAMETER
;
155 // Only one capsule HOB allowed.
157 CvHob
= GetFirstHob (EFI_HOB_TYPE_CV
);
160 // We didn't find a hob, so had no errors.
162 BdsLockNonUpdatableFlash ();
166 BaseAddress
= CvHob
->BaseAddress
;
167 Length
= CvHob
->Length
;
169 Status
= EFI_SUCCESS
;
171 // Now walk the capsule and call the core to process each
172 // firmware volume in it.
174 while (Length
!= 0) {
176 // Point to the next firmware volume header, and then
177 // call the DXE service to process it.
179 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) BaseAddress
;
180 if (FwVolHeader
->FvLength
> Length
) {
182 // Notes: need to stuff this status somewhere so that the
183 // error can be detected at OS runtime
185 Status
= EFI_VOLUME_CORRUPTED
;
189 Status
= gDS
->ProcessFirmwareVolume (
190 (VOID
*) (UINTN
) BaseAddress
,
191 (UINTN
) FwVolHeader
->FvLength
,
194 if (EFI_ERROR (Status
)) {
198 // Call the dispatcher to dispatch any drivers from the produced firmware volume
202 // On to the next FV in the capsule
204 Length
-= FwVolHeader
->FvLength
;
205 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) ((UINTN
) BaseAddress
+ FwVolHeader
->FvLength
);
207 // Notes: when capsule spec is finalized, if the requirement is made to
208 // have each FV in a capsule aligned, then we will need to align the
209 // BaseAddress and Length here.
214 BdsLockNonUpdatableFlash ();