]>
Commit | Line | Data |
---|---|---|
5c08e117 | 1 | /** @file\r |
2 | BDS routines to handle capsules.\r | |
3 | \r | |
180a5a35 HT |
4 | Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
5c08e117 | 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 | |
13 | **/\r | |
14 | #include "Bds.h"\r | |
15 | \r | |
5c08e117 | 16 | /**\r |
17 | \r | |
18 | This routine is called to see if there are any capsules we need to process.\r | |
19 | If the boot mode is not UPDATE, then we do nothing. Otherwise find the\r | |
20 | capsule HOBS and produce firmware volumes for them via the DXE service.\r | |
21 | Then call the dispatcher to dispatch drivers from them. Finally, check\r | |
22 | the status of the updates.\r | |
23 | \r | |
24 | This function should be called by BDS in case we need to do some\r | |
25 | sort of processing even if there is no capsule to process. We\r | |
26 | need to do this if an earlier update went away and we need to\r | |
27 | clear the capsule variable so on the next reset PEI does not see it and\r | |
28 | think there is a capsule available.\r | |
29 | \r | |
30 | @param BootMode the current boot mode\r | |
31 | \r | |
32 | @retval EFI_INVALID_PARAMETER boot mode is not correct for an update\r | |
33 | @retval EFI_SUCCESS There is no error when processing capsule\r | |
34 | \r | |
35 | **/\r | |
36 | EFI_STATUS\r | |
8861fc79 | 37 | EFIAPI\r |
19bf20e1 | 38 | BdsProcessCapsules (\r |
5c08e117 | 39 | EFI_BOOT_MODE BootMode\r |
40 | )\r | |
41 | {\r | |
42 | EFI_STATUS Status;\r | |
43 | EFI_PEI_HOB_POINTERS HobPointer;\r | |
44 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
45 | UINT32 Size;\r | |
46 | UINT32 CapsuleNumber;\r | |
47 | UINT32 CapsuleTotalNumber;\r | |
48 | EFI_CAPSULE_TABLE *CapsuleTable;\r | |
49 | UINT32 Index;\r | |
50 | UINT32 CacheIndex;\r | |
51 | UINT32 CacheNumber;\r | |
52 | VOID **CapsulePtr;\r | |
53 | VOID **CapsulePtrCache;\r | |
54 | EFI_GUID *CapsuleGuidCache; \r | |
5c08e117 | 55 | \r |
56 | CapsuleNumber = 0;\r | |
57 | CapsuleTotalNumber = 0;\r | |
58 | CacheIndex = 0;\r | |
59 | CacheNumber = 0;\r | |
60 | CapsulePtr = NULL;\r | |
61 | CapsulePtrCache = NULL;\r | |
62 | CapsuleGuidCache = NULL;\r | |
63 | \r | |
64 | //\r | |
65 | // We don't do anything else if the boot mode is not flash-update\r | |
66 | //\r | |
67 | if (BootMode != BOOT_ON_FLASH_UPDATE) {\r | |
68 | return EFI_INVALID_PARAMETER;\r | |
69 | }\r | |
70 | \r | |
71 | Status = EFI_SUCCESS;\r | |
72 | //\r | |
73 | // Find all capsule images from hob\r | |
74 | //\r | |
75 | HobPointer.Raw = GetHobList ();\r | |
019dfb9c | 76 | while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r |
5c08e117 | 77 | CapsuleTotalNumber ++;\r |
5c08e117 | 78 | HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r |
79 | }\r | |
80 | \r | |
81 | if (CapsuleTotalNumber == 0) {\r | |
82 | //\r | |
83 | // We didn't find a hob, so had no errors.\r | |
84 | //\r | |
85 | PlatformBdsLockNonUpdatableFlash ();\r | |
86 | return EFI_SUCCESS;\r | |
87 | }\r | |
88 | \r | |
89 | //\r | |
90 | // Init temp Capsule Data table.\r | |
91 | //\r | |
92 | CapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r | |
93 | ASSERT (CapsulePtr != NULL);\r | |
94 | CapsulePtrCache = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r | |
95 | ASSERT (CapsulePtrCache != NULL);\r | |
96 | CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);\r | |
97 | ASSERT (CapsuleGuidCache != NULL);\r | |
98 | \r | |
99 | //\r | |
100 | // Find all capsule images from hob\r | |
101 | //\r | |
102 | HobPointer.Raw = GetHobList ();\r | |
019dfb9c | 103 | while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r |
104 | CapsulePtr [CapsuleNumber++] = (VOID *) (UINTN) HobPointer.Capsule->BaseAddress;\r | |
5c08e117 | 105 | HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r |
106 | }\r | |
107 | \r | |
108 | //\r | |
109 | //Check the capsule flags,if contains CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE, install\r | |
110 | //capsuleTable to configure table with EFI_CAPSULE_GUID\r | |
111 | //\r | |
112 | \r | |
113 | //\r | |
114 | // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating\r | |
115 | // System to have information persist across a system reset. EFI System Table must \r | |
116 | // point to an array of capsules that contains the same CapsuleGuid value. And agents\r | |
117 | // searching for this type capsule will look in EFI System Table and search for the \r | |
118 | // capsule's Guid and associated pointer to retrieve the data. Two steps below describes\r | |
119 | // how to sorting the capsules by the unique guid and install the array to EFI System Table. \r | |
120 | // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an \r | |
121 | // array for later sorting capsules by CapsuleGuid.\r | |
122 | //\r | |
123 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
124 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
125 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r | |
126 | //\r | |
127 | // For each capsule, we compare it with known CapsuleGuid in the CacheArray.\r | |
128 | // If already has the Guid, skip it. Whereas, record it in the CacheArray as \r | |
129 | // an additional one.\r | |
130 | //\r | |
131 | CacheIndex = 0;\r | |
132 | while (CacheIndex < CacheNumber) {\r | |
133 | if (CompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) {\r | |
134 | break;\r | |
135 | }\r | |
136 | CacheIndex++;\r | |
137 | }\r | |
138 | if (CacheIndex == CacheNumber) {\r | |
139 | CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID));\r | |
140 | }\r | |
141 | }\r | |
142 | }\r | |
143 | \r | |
144 | //\r | |
145 | // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules\r | |
146 | // whose guid is the same as it, and malloc memory for an array which preceding\r | |
147 | // with UINT32. The array fills with entry point of capsules that have the same\r | |
148 | // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install\r | |
149 | // this array into EFI System Table, so that agents searching for this type capsule\r | |
150 | // will look in EFI System Table and search for the capsule's Guid and associated\r | |
151 | // pointer to retrieve the data.\r | |
152 | //\r | |
153 | CacheIndex = 0;\r | |
154 | while (CacheIndex < CacheNumber) {\r | |
155 | CapsuleNumber = 0; \r | |
156 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
157 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
158 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r | |
159 | if (CompareGuid (&CapsuleGuidCache[CacheIndex], &CapsuleHeader->CapsuleGuid)) {\r | |
160 | //\r | |
161 | // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid.\r | |
162 | //\r | |
163 | CapsulePtrCache[CapsuleNumber++] = (VOID*)CapsuleHeader;\r | |
164 | }\r | |
165 | }\r | |
166 | }\r | |
167 | if (CapsuleNumber != 0) {\r | |
168 | Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*); \r | |
169 | CapsuleTable = AllocateRuntimePool (Size);\r | |
170 | ASSERT (CapsuleTable != NULL);\r | |
171 | CapsuleTable->CapsuleArrayNumber = CapsuleNumber;\r | |
172 | CopyMem(&CapsuleTable->CapsulePtr[0], CapsulePtrCache, CapsuleNumber * sizeof(VOID*));\r | |
173 | Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable);\r | |
174 | ASSERT_EFI_ERROR (Status);\r | |
175 | }\r | |
176 | CacheIndex++;\r | |
177 | }\r | |
178 | \r | |
179 | //\r | |
180 | // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are\r | |
181 | // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash \r | |
182 | // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional\r | |
183 | // type capsule transaction could be extended. It depends on platform policy.\r | |
184 | //\r | |
185 | for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r | |
186 | CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r | |
187 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r | |
188 | //\r | |
189 | // Call capsule library to process capsule image.\r | |
190 | //\r | |
191 | ProcessCapsuleImage (CapsuleHeader);\r | |
192 | }\r | |
193 | }\r | |
194 | \r | |
195 | PlatformBdsLockNonUpdatableFlash ();\r | |
196 | \r | |
197 | //\r | |
198 | // Free the allocated temp memory space.\r | |
199 | //\r | |
200 | FreePool (CapsuleGuidCache);\r | |
201 | FreePool (CapsulePtrCache);\r | |
202 | FreePool (CapsulePtr);\r | |
203 | \r | |
204 | return Status;\r | |
205 | }\r | |
019dfb9c | 206 | \r |