]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/PlatformBdsDxe/Generic/Capsules.c
add in PlatformBds.inf
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / Capsules.c
CommitLineData
bc11b829 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Capsules.c\r
15\r
16Abstract:\r
17\r
18 BDS routines to handle capsules.\r
19\r
20--*/\r
21\r
22\r
23//\r
24// Include common header file for this module.\r
25//\r
26#include "CommonHeader.h"\r
27\r
28#include <Common/FlashMap.H>\r
29\r
30VOID\r
31BdsLockFv (\r
32 IN EFI_CPU_IO_PROTOCOL *CpuIo,\r
33 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry\r
34 );\r
35\r
36VOID\r
37BdsLockFv (\r
38 IN EFI_CPU_IO_PROTOCOL *CpuIo,\r
39 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry\r
40 )\r
41{\r
42 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;\r
43 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
44 UINT64 BaseAddress;\r
45 UINT8 Data;\r
46 UINT32 BlockLength;\r
47 UINTN Index;\r
48\r
49 BaseAddress = FlashEntry->Base - 0x400000 + 2;\r
50 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (FlashEntry->Base));\r
51 BlockMap = &(FvHeader->FvBlockMap[0]);\r
52\r
53 while ((BlockMap->NumBlocks != 0) && (BlockMap->BlockLength != 0)) {\r
54 BlockLength = BlockMap->BlockLength;\r
55 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {\r
56 CpuIo->Mem.Read (\r
57 CpuIo,\r
58 EfiCpuIoWidthUint8,\r
59 BaseAddress,\r
60 1,\r
61 &Data\r
62 );\r
63 Data = (UINT8) (Data | 0x3);\r
64 CpuIo->Mem.Write (\r
65 CpuIo,\r
66 EfiCpuIoWidthUint8,\r
67 BaseAddress,\r
68 1,\r
69 &Data\r
70 );\r
71 BaseAddress += BlockLength;\r
72 }\r
73\r
74 BlockMap++;\r
75 }\r
76}\r
77\r
78VOID\r
79BdsLockNonUpdatableFlash (\r
80 VOID\r
81 )\r
82{\r
83 EFI_FLASH_MAP_ENTRY_DATA *FlashMapEntryData;\r
84 EFI_PEI_HOB_POINTERS GuidHob;\r
85 EFI_STATUS Status;\r
86 EFI_CPU_IO_PROTOCOL *CpuIo;\r
87\r
88 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &CpuIo);\r
89 ASSERT_EFI_ERROR (Status);\r
90 \r
91 GuidHob.Raw = GetHobList ();\r
92 while ((GuidHob.Raw = GetNextGuidHob (&gEfiFlashMapHobGuid, GuidHob.Raw)) != NULL) {\r
93 FlashMapEntryData = (EFI_FLASH_MAP_ENTRY_DATA *) GET_GUID_HOB_DATA (GuidHob.Guid);\r
94\r
95 //\r
96 // Get the variable store area\r
97 //\r
98 if ((FlashMapEntryData->AreaType == EFI_FLASH_AREA_RECOVERY_BIOS) ||\r
99 (FlashMapEntryData->AreaType == EFI_FLASH_AREA_MAIN_BIOS)\r
100 ) {\r
101 BdsLockFv (CpuIo, &(FlashMapEntryData->Entries[0]));\r
102 }\r
103 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
104 }\r
105\r
106 return ;\r
107}\r
108\r
109EFI_STATUS\r
110ProcessCapsules (\r
111 EFI_BOOT_MODE BootMode\r
112 )\r
113/*++\r
114\r
115Routine Description:\r
116\r
117 This routine is called to see if there are any capsules we need to process.\r
118 If the boot mode is not UPDATE, then we do nothing. Otherwise find the\r
119 capsule HOBS and produce firmware volumes for them via the DXE service.\r
120 Then call the dispatcher to dispatch drivers from them. Finally, check\r
121 the status of the updates.\r
122\r
123Arguments:\r
124\r
125 BootMode - the current boot mode\r
126\r
127Returns:\r
128 \r
129 EFI_INVALID_PARAMETER - boot mode is not correct for an update\r
130\r
131Note:\r
132 \r
133 This function should be called by BDS in case we need to do some\r
134 sort of processing even if there is no capsule to process. We\r
135 need to do this if an earlier update went awry and we need to\r
136 clear the capsule variable so on the next reset PEI does not see it and \r
137 think there is a capsule available.\r
138\r
139--*/\r
140{\r
141 EFI_STATUS Status;\r
142 EFI_HOB_CAPSULE_VOLUME *CvHob;\r
143 EFI_PHYSICAL_ADDRESS BaseAddress;\r
144 UINT64 Length;\r
145 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
146 EFI_HANDLE FvProtocolHandle;\r
147\r
148 //\r
149 // We don't do anything else if the boot mode is not flash-update\r
150 //\r
151 if (BootMode != BOOT_ON_FLASH_UPDATE) {\r
152 return EFI_INVALID_PARAMETER;\r
153 }\r
154 //\r
155 // Only one capsule HOB allowed.\r
156 //\r
157 CvHob = GetFirstHob (EFI_HOB_TYPE_CV);\r
158 if (CvHob == NULL) {\r
159 //\r
160 // We didn't find a hob, so had no errors.\r
161 //\r
162 BdsLockNonUpdatableFlash ();\r
163 return EFI_SUCCESS;\r
164 }\r
165 \r
166 BaseAddress = CvHob->BaseAddress;\r
167 Length = CvHob->Length;\r
168\r
169 Status = EFI_SUCCESS;\r
170 //\r
171 // Now walk the capsule and call the core to process each\r
172 // firmware volume in it.\r
173 //\r
174 while (Length != 0) {\r
175 //\r
176 // Point to the next firmware volume header, and then\r
177 // call the DXE service to process it.\r
178 //\r
179 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
180 if (FwVolHeader->FvLength > Length) {\r
181 //\r
182 // Notes: need to stuff this status somewhere so that the\r
183 // error can be detected at OS runtime\r
184 //\r
185 Status = EFI_VOLUME_CORRUPTED;\r
186 break;\r
187 }\r
188\r
189 Status = gDS->ProcessFirmwareVolume (\r
190 (VOID *) (UINTN) BaseAddress,\r
191 (UINTN) FwVolHeader->FvLength,\r
192 &FvProtocolHandle\r
193 );\r
194 if (EFI_ERROR (Status)) {\r
195 break;\r
196 }\r
197 //\r
198 // Call the dispatcher to dispatch any drivers from the produced firmware volume\r
199 //\r
200 gDS->Dispatch ();\r
201 //\r
202 // On to the next FV in the capsule\r
203 //\r
204 Length -= FwVolHeader->FvLength;\r
205 BaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BaseAddress + FwVolHeader->FvLength);\r
206 //\r
207 // Notes: when capsule spec is finalized, if the requirement is made to\r
208 // have each FV in a capsule aligned, then we will need to align the\r
209 // BaseAddress and Length here.\r
210 //\r
211 }\r
212 \r
213\r
214 BdsLockNonUpdatableFlash ();\r
215\r
216 return Status;\r
217}\r
218\r