]>
Commit | Line | Data |
---|---|---|
fd6a62f3 | 1 | /** @file\r |
2 | BDS routines to handle capsules.\r | |
93e3992d | 3 | \r |
fd6a62f3 | 4 | Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r |
93e3992d | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
fd6a62f3 | 13 | **/\r |
93e3992d | 14 | #include "Bds.h"\r |
15 | \r | |
b30312ba | 16 | /**\r |
17 | This function locks the block \r | |
18 | \r | |
19 | @param CpuIo A instance of EFI_CPU_IO_PROTOCOL. \r | |
20 | @param Base The base address flash region to be locked.\r | |
21 | \r | |
b30312ba | 22 | **/\r |
93e3992d | 23 | VOID\r |
24 | BdsLockFv (\r | |
25 | IN EFI_CPU_IO_PROTOCOL *CpuIo,\r | |
26 | IN EFI_PHYSICAL_ADDRESS Base\r | |
27 | )\r | |
28 | {\r | |
29 | EFI_FV_BLOCK_MAP_ENTRY *BlockMap;\r | |
30 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r | |
31 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
32 | UINT8 Data;\r | |
33 | UINT32 BlockLength;\r | |
34 | UINTN Index;\r | |
35 | \r | |
36 | BaseAddress = Base - 0x400000 + 2;\r | |
37 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base));\r | |
38 | BlockMap = &(FvHeader->BlockMap[0]);\r | |
39 | \r | |
40 | while ((BlockMap->NumBlocks != 0) && (BlockMap->Length != 0)) {\r | |
41 | BlockLength = BlockMap->Length;\r | |
42 | for (Index = 0; Index < BlockMap->NumBlocks; Index++) {\r | |
43 | CpuIo->Mem.Read (\r | |
44 | CpuIo,\r | |
45 | EfiCpuIoWidthUint8,\r | |
46 | BaseAddress,\r | |
47 | 1,\r | |
48 | &Data\r | |
49 | );\r | |
50 | Data = (UINT8) (Data | 0x3);\r | |
51 | CpuIo->Mem.Write (\r | |
52 | CpuIo,\r | |
53 | EfiCpuIoWidthUint8,\r | |
54 | BaseAddress,\r | |
55 | 1,\r | |
56 | &Data\r | |
57 | );\r | |
58 | BaseAddress += BlockLength;\r | |
59 | }\r | |
60 | \r | |
61 | BlockMap++;\r | |
62 | }\r | |
63 | }\r | |
64 | \r | |
b30312ba | 65 | /**\r |
93e3992d | 66 | \r |
67 | This routine is called to see if there are any capsules we need to process.\r | |
68 | If the boot mode is not UPDATE, then we do nothing. Otherwise find the\r | |
69 | capsule HOBS and produce firmware volumes for them via the DXE service.\r | |
70 | Then call the dispatcher to dispatch drivers from them. Finally, check\r | |
71 | the status of the updates.\r | |
72 | \r | |
93e3992d | 73 | \r |
b30312ba | 74 | @param BootMode - the current boot mode\r |
93e3992d | 75 | \r |
b30312ba | 76 | @retval EFI_INVALID_PARAMETER boot mode is not correct for an update\r |
77 | Note:\r | |
78 | This function should be called by BDS in case we need to do some\r | |
79 | sort of processing even if there is no capsule to process. We\r | |
80 | need to do this if an earlier update went awry and we need to\r | |
81 | clear the capsule variable so on the next reset PEI does not see it and\r | |
82 | think there is a capsule available.\r | |
30394aa1 | 83 | @retval EFI_SUCCESS There is no error when processing capsule\r |
93e3992d | 84 | \r |
b30312ba | 85 | **/\r |
86 | EFI_STATUS\r | |
87 | ProcessCapsules (\r | |
88 | EFI_BOOT_MODE BootMode\r | |
89 | )\r | |
93e3992d | 90 | {\r |
91 | EFI_STATUS Status;\r | |
92 | EFI_PEI_HOB_POINTERS HobPointer;\r | |
93 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
94 | UINT32 Size;\r | |
95 | UINT32 CapsuleNumber;\r | |
96 | UINT32 CapsuleTotalNumber;\r | |
97 | EFI_CAPSULE_TABLE *CapsuleTable;\r | |
98 | UINT32 Index;\r | |
99 | UINT32 CacheIndex;\r | |
100 | UINT32 CacheNumber;\r | |
101 | VOID **CapsulePtr;\r | |
102 | VOID **CapsulePtrCache;\r | |
103 | EFI_GUID *CapsuleGuidCache; \r | |
104 | CAPSULE_HOB_INFO *CapsuleHobInfo;\r | |
105 | \r | |
106 | CapsuleNumber = 0;\r | |
107 | CapsuleTotalNumber = 0;\r | |
108 | CacheIndex = 0;\r | |
109 | CacheNumber = 0;\r | |
110 | CapsulePtr = NULL;\r | |
111 | CapsulePtrCache = NULL;\r | |
112 | CapsuleGuidCache = NULL;\r | |
113 | \r | |
114 | //\r | |
115 | // We don't do anything else if the boot mode is not flash-update\r | |
116 | //\r | |
117 | if (BootMode != BOOT_ON_FLASH_UPDATE) {\r | |
118 | return EFI_INVALID_PARAMETER;\r | |
119 | }\r | |
120 | \r | |
121 | Status = EFI_SUCCESS;\r | |
122 | //\r | |
123 | // Find all capsule images from hob\r | |
124 | //\r | |
125 | HobPointer.Raw = GetHobList ();\r | |
126 | while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {\r | |
127 | CapsuleTotalNumber ++;\r | |
128 | \r | |
129 | HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r | |
130 | }\r | |
131 | \r | |
132 | if (CapsuleTotalNumber == 0) {\r | |
133 | //\r | |
134 | // We didn't find a hob, so had no errors.\r | |
135 | //\r | |
136 | PlatformBdsLockNonUpdatableFlash ();\r | |
137 | return EFI_SUCCESS;\r | |
138 | }\r | |
139 | \r | |
140 | //\r | |
141 | // Init temp Capsule Data table.\r | |
142 | //\r | |
143 | CapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r | |
144 | ASSERT (CapsulePtr != NULL);\r | |
145 | CapsulePtrCache = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r | |
146 | ASSERT (CapsulePtrCache != NULL);\r | |
147 | CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);\r | |
148 | ASSERT (CapsuleGuidCache != NULL);\r | |
149 | \r | |
150 | //\r | |
151 | // Find all capsule images from hob\r | |
152 | //\r | |
153 | HobPointer.Raw = GetHobList ();\r | |
154 | while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {\r | |
155 | CapsuleHobInfo = GET_GUID_HOB_DATA (HobPointer.Guid);\r | |
156 | CapsulePtr [CapsuleNumber++] = (VOID *)(UINTN)(CapsuleHobInfo->BaseAddress);\r | |
157 | \r | |
158 | HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r | |
159 | }\r | |
160 | \r | |
161 | //\r | |
162 | //Check the capsule flags,if contains CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE, install\r | |
163 | //capsuleTable to configure table with EFI_CAPSULE_GUID\r | |
164 | //\r | |
165 | \r | |
166 | //\r | |
167 | // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating\r | |
168 | // System to have information persist across a system reset. EFI System Table must \r | |
169 | // point to an array of capsules that contains the same CapsuleGuid value. And agents\r | |
170 | // searching for this type capsule will look in EFI System Table and search for the \r | |
171 | // capsule's Guid and associated pointer to retrieve the data. Two steps below describes\r | |
172 | // how to sorting the capsules by the unique guid and install the array to EFI System Table. \r | |
173 | // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an \r | |
174 | // array for later sorting capsules by CapsuleGuid.\r | |
175 | //\r | |
176 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
177 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
178 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r | |
179 | //\r | |
180 | // For each capsule, we compare it with known CapsuleGuid in the CacheArray.\r | |
181 | // If already has the Guid, skip it. Whereas, record it in the CacheArray as \r | |
182 | // an additional one.\r | |
183 | //\r | |
184 | CacheIndex = 0;\r | |
185 | while (CacheIndex < CacheNumber) {\r | |
186 | if (CompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) {\r | |
187 | break;\r | |
188 | }\r | |
189 | CacheIndex++;\r | |
190 | }\r | |
191 | if (CacheIndex == CacheNumber) {\r | |
192 | CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID));\r | |
193 | }\r | |
194 | }\r | |
195 | }\r | |
196 | \r | |
197 | //\r | |
198 | // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules\r | |
199 | // whose guid is the same as it, and malloc memory for an array which preceding\r | |
200 | // with UINT32. The array fills with entry point of capsules that have the same\r | |
201 | // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install\r | |
202 | // this array into EFI System Table, so that agents searching for this type capsule\r | |
203 | // will look in EFI System Table and search for the capsule's Guid and associated\r | |
204 | // pointer to retrieve the data.\r | |
205 | //\r | |
206 | CacheIndex = 0;\r | |
207 | while (CacheIndex < CacheNumber) {\r | |
208 | CapsuleNumber = 0; \r | |
209 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
210 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
211 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r | |
212 | if (CompareGuid (&CapsuleGuidCache[CacheIndex], &CapsuleHeader->CapsuleGuid)) {\r | |
213 | //\r | |
214 | // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid.\r | |
215 | //\r | |
216 | CapsulePtrCache[CapsuleNumber++] = (VOID*)CapsuleHeader;\r | |
217 | }\r | |
218 | }\r | |
219 | }\r | |
220 | if (CapsuleNumber != 0) {\r | |
221 | Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*); \r | |
222 | CapsuleTable = AllocateRuntimePool (Size);\r | |
223 | ASSERT (CapsuleTable != NULL);\r | |
224 | CapsuleTable->CapsuleArrayNumber = CapsuleNumber;\r | |
225 | CopyMem(&CapsuleTable->CapsulePtr[0], CapsulePtrCache, CapsuleNumber * sizeof(VOID*));\r | |
226 | Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable);\r | |
227 | ASSERT_EFI_ERROR (Status);\r | |
228 | }\r | |
229 | CacheIndex++;\r | |
230 | }\r | |
231 | \r | |
232 | //\r | |
233 | // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are\r | |
234 | // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash \r | |
235 | // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional\r | |
236 | // type capsule transaction could be extended. It depends on platform policy.\r | |
237 | //\r | |
238 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
239 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
240 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r | |
241 | //\r | |
242 | // Call capsule library to process capsule image.\r | |
243 | //\r | |
244 | ProcessCapsuleImage (CapsuleHeader);\r | |
245 | }\r | |
246 | }\r | |
247 | \r | |
248 | PlatformBdsLockNonUpdatableFlash ();\r | |
249 | \r | |
250 | //\r | |
251 | // Free the allocated temp memory space.\r | |
252 | //\r | |
253 | FreePool (CapsuleGuidCache);\r | |
254 | FreePool (CapsulePtrCache);\r | |
255 | FreePool (CapsulePtr);\r | |
256 | \r | |
257 | return Status;\r | |
258 | }\r |