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.
23 #include <Common/FlashMap.H>
27 IN EFI_CPU_IO_PROTOCOL
*CpuIo
,
28 IN EFI_FLASH_SUBAREA_ENTRY
*FlashEntry
33 IN EFI_CPU_IO_PROTOCOL
*CpuIo
,
34 IN EFI_FLASH_SUBAREA_ENTRY
*FlashEntry
37 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
38 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
44 BaseAddress
= FlashEntry
->Base
- 0x400000 + 2;
45 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (FlashEntry
->Base
));
46 BlockMap
= &(FvHeader
->FvBlockMap
[0]);
48 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->BlockLength
!= 0)) {
49 BlockLength
= BlockMap
->BlockLength
;
50 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
58 Data
= (UINT8
) (Data
| 0x3);
66 BaseAddress
+= BlockLength
;
74 BdsLockNonUpdatableFlash (
78 EFI_FLASH_MAP_ENTRY_DATA
*FlashMapEntryData
;
79 EFI_PEI_HOB_POINTERS GuidHob
;
81 EFI_CPU_IO_PROTOCOL
*CpuIo
;
83 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, &CpuIo
);
84 ASSERT_EFI_ERROR (Status
);
86 GuidHob
.Raw
= GetHobList ();
87 while ((GuidHob
.Raw
= GetNextGuidHob (&gEfiFlashMapHobGuid
, GuidHob
.Raw
)) != NULL
) {
88 FlashMapEntryData
= (EFI_FLASH_MAP_ENTRY_DATA
*) GET_GUID_HOB_DATA (GuidHob
.Guid
);
91 // Get the variable store area
93 if ((FlashMapEntryData
->AreaType
== EFI_FLASH_AREA_RECOVERY_BIOS
) ||
94 (FlashMapEntryData
->AreaType
== EFI_FLASH_AREA_MAIN_BIOS
)
96 BdsLockFv (CpuIo
, &(FlashMapEntryData
->Entries
[0]));
98 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
106 EFI_BOOT_MODE BootMode
112 This routine is called to see if there are any capsules we need to process.
113 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
114 capsule HOBS and produce firmware volumes for them via the DXE service.
115 Then call the dispatcher to dispatch drivers from them. Finally, check
116 the status of the updates.
120 BootMode - the current boot mode
124 EFI_INVALID_PARAMETER - boot mode is not correct for an update
128 This function should be called by BDS in case we need to do some
129 sort of processing even if there is no capsule to process. We
130 need to do this if an earlier update went awry and we need to
131 clear the capsule variable so on the next reset PEI does not see it and
132 think there is a capsule available.
137 EFI_HOB_CAPSULE_VOLUME
*CvHob
;
138 EFI_PHYSICAL_ADDRESS BaseAddress
;
140 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
141 EFI_HANDLE FvProtocolHandle
;
144 // We don't do anything else if the boot mode is not flash-update
146 if (BootMode
!= BOOT_ON_FLASH_UPDATE
) {
147 return EFI_INVALID_PARAMETER
;
150 // Only one capsule HOB allowed.
152 CvHob
= GetFirstHob (EFI_HOB_TYPE_CV
);
155 // We didn't find a hob, so had no errors.
157 BdsLockNonUpdatableFlash ();
161 BaseAddress
= CvHob
->BaseAddress
;
162 Length
= CvHob
->Length
;
164 Status
= EFI_SUCCESS
;
166 // Now walk the capsule and call the core to process each
167 // firmware volume in it.
169 while (Length
!= 0) {
171 // Point to the next firmware volume header, and then
172 // call the DXE service to process it.
174 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) BaseAddress
;
175 if (FwVolHeader
->FvLength
> Length
) {
177 // Notes: need to stuff this status somewhere so that the
178 // error can be detected at OS runtime
180 Status
= EFI_VOLUME_CORRUPTED
;
184 Status
= gDS
->ProcessFirmwareVolume (
185 (VOID
*) (UINTN
) BaseAddress
,
186 (UINTN
) FwVolHeader
->FvLength
,
189 if (EFI_ERROR (Status
)) {
193 // Call the dispatcher to dispatch any drivers from the produced firmware volume
197 // On to the next FV in the capsule
199 Length
-= FwVolHeader
->FvLength
;
200 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) ((UINTN
) BaseAddress
+ FwVolHeader
->FvLength
);
202 // Notes: when capsule spec is finalized, if the requirement is made to
203 // have each FV in a capsule aligned, then we will need to align the
204 // BaseAddress and Length here.
209 BdsLockNonUpdatableFlash ();