]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/PlatformBdsDxe/Generic/Capsules.c
add in PlatformBds.inf
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / Capsules.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 Capsules.c
15
16 Abstract:
17
18 BDS routines to handle capsules.
19
20 --*/
21
22
23 //
24 // Include common header file for this module.
25 //
26 #include "CommonHeader.h"
27
28 #include <Common/FlashMap.H>
29
30 VOID
31 BdsLockFv (
32 IN EFI_CPU_IO_PROTOCOL *CpuIo,
33 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
34 );
35
36 VOID
37 BdsLockFv (
38 IN EFI_CPU_IO_PROTOCOL *CpuIo,
39 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
40 )
41 {
42 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
43 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
44 UINT64 BaseAddress;
45 UINT8 Data;
46 UINT32 BlockLength;
47 UINTN Index;
48
49 BaseAddress = FlashEntry->Base - 0x400000 + 2;
50 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (FlashEntry->Base));
51 BlockMap = &(FvHeader->FvBlockMap[0]);
52
53 while ((BlockMap->NumBlocks != 0) && (BlockMap->BlockLength != 0)) {
54 BlockLength = BlockMap->BlockLength;
55 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {
56 CpuIo->Mem.Read (
57 CpuIo,
58 EfiCpuIoWidthUint8,
59 BaseAddress,
60 1,
61 &Data
62 );
63 Data = (UINT8) (Data | 0x3);
64 CpuIo->Mem.Write (
65 CpuIo,
66 EfiCpuIoWidthUint8,
67 BaseAddress,
68 1,
69 &Data
70 );
71 BaseAddress += BlockLength;
72 }
73
74 BlockMap++;
75 }
76 }
77
78 VOID
79 BdsLockNonUpdatableFlash (
80 VOID
81 )
82 {
83 EFI_FLASH_MAP_ENTRY_DATA *FlashMapEntryData;
84 EFI_PEI_HOB_POINTERS GuidHob;
85 EFI_STATUS Status;
86 EFI_CPU_IO_PROTOCOL *CpuIo;
87
88 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &CpuIo);
89 ASSERT_EFI_ERROR (Status);
90
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);
94
95 //
96 // Get the variable store area
97 //
98 if ((FlashMapEntryData->AreaType == EFI_FLASH_AREA_RECOVERY_BIOS) ||
99 (FlashMapEntryData->AreaType == EFI_FLASH_AREA_MAIN_BIOS)
100 ) {
101 BdsLockFv (CpuIo, &(FlashMapEntryData->Entries[0]));
102 }
103 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
104 }
105
106 return ;
107 }
108
109 EFI_STATUS
110 ProcessCapsules (
111 EFI_BOOT_MODE BootMode
112 )
113 /*++
114
115 Routine Description:
116
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.
122
123 Arguments:
124
125 BootMode - the current boot mode
126
127 Returns:
128
129 EFI_INVALID_PARAMETER - boot mode is not correct for an update
130
131 Note:
132
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.
138
139 --*/
140 {
141 EFI_STATUS Status;
142 EFI_HOB_CAPSULE_VOLUME *CvHob;
143 EFI_PHYSICAL_ADDRESS BaseAddress;
144 UINT64 Length;
145 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
146 EFI_HANDLE FvProtocolHandle;
147
148 //
149 // We don't do anything else if the boot mode is not flash-update
150 //
151 if (BootMode != BOOT_ON_FLASH_UPDATE) {
152 return EFI_INVALID_PARAMETER;
153 }
154 //
155 // Only one capsule HOB allowed.
156 //
157 CvHob = GetFirstHob (EFI_HOB_TYPE_CV);
158 if (CvHob == NULL) {
159 //
160 // We didn't find a hob, so had no errors.
161 //
162 BdsLockNonUpdatableFlash ();
163 return EFI_SUCCESS;
164 }
165
166 BaseAddress = CvHob->BaseAddress;
167 Length = CvHob->Length;
168
169 Status = EFI_SUCCESS;
170 //
171 // Now walk the capsule and call the core to process each
172 // firmware volume in it.
173 //
174 while (Length != 0) {
175 //
176 // Point to the next firmware volume header, and then
177 // call the DXE service to process it.
178 //
179 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
180 if (FwVolHeader->FvLength > Length) {
181 //
182 // Notes: need to stuff this status somewhere so that the
183 // error can be detected at OS runtime
184 //
185 Status = EFI_VOLUME_CORRUPTED;
186 break;
187 }
188
189 Status = gDS->ProcessFirmwareVolume (
190 (VOID *) (UINTN) BaseAddress,
191 (UINTN) FwVolHeader->FvLength,
192 &FvProtocolHandle
193 );
194 if (EFI_ERROR (Status)) {
195 break;
196 }
197 //
198 // Call the dispatcher to dispatch any drivers from the produced firmware volume
199 //
200 gDS->Dispatch ();
201 //
202 // On to the next FV in the capsule
203 //
204 Length -= FwVolHeader->FvLength;
205 BaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BaseAddress + FwVolHeader->FvLength);
206 //
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.
210 //
211 }
212
213
214 BdsLockNonUpdatableFlash ();
215
216 return Status;
217 }
218