]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/BdsDxe/Capsules.c
Correct a typo: Change the type of the 4th parameter of EFI_DRIVER_HEALTH_PROTOCOL...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / Capsules.c
CommitLineData
5c08e117 1/** @file\r
2 BDS routines to handle capsules.\r
3\r
5025be3f 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
5c08e117 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT 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
36EFI_STATUS\r
8861fc79 37EFIAPI\r
19bf20e1 38BdsProcessCapsules (\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
5025be3f 68 DEBUG ((EFI_D_ERROR, "Boot mode is not correct for capsule update.\n"));\r
5c08e117 69 return EFI_INVALID_PARAMETER;\r
70 }\r
71 \r
72 Status = EFI_SUCCESS;\r
73 //\r
74 // Find all capsule images from hob\r
75 //\r
76 HobPointer.Raw = GetHobList ();\r
019dfb9c 77 while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r
5c08e117 78 CapsuleTotalNumber ++;\r
5c08e117 79 HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r
80 }\r
81 \r
82 if (CapsuleTotalNumber == 0) {\r
83 //\r
84 // We didn't find a hob, so had no errors.\r
85 //\r
5025be3f 86 DEBUG ((EFI_D_ERROR, "We can not find capsule data in capsule update boot mode.\n"));\r
87 DEBUG ((EFI_D_ERROR, "Please check the followings are correct if unexpected capsule update error happens.\n"));\r
88 DEBUG ((EFI_D_ERROR, "1. CapsuleX64 is built as X64 module when PEI is IA32 and DXE is X64\n"));\r
89 DEBUG ((EFI_D_ERROR, "2. Capsule data should persist in memory across a system reset.\n"));\r
5c08e117 90 PlatformBdsLockNonUpdatableFlash ();\r
91 return EFI_SUCCESS;\r
92 }\r
93 \r
94 //\r
95 // Init temp Capsule Data table.\r
96 //\r
97 CapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r
98 ASSERT (CapsulePtr != NULL);\r
99 CapsulePtrCache = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);\r
100 ASSERT (CapsulePtrCache != NULL);\r
101 CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);\r
102 ASSERT (CapsuleGuidCache != NULL);\r
103 \r
104 //\r
105 // Find all capsule images from hob\r
106 //\r
107 HobPointer.Raw = GetHobList ();\r
019dfb9c 108 while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {\r
109 CapsulePtr [CapsuleNumber++] = (VOID *) (UINTN) HobPointer.Capsule->BaseAddress;\r
5c08e117 110 HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r
111 }\r
112\r
113 //\r
114 //Check the capsule flags,if contains CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE, install\r
115 //capsuleTable to configure table with EFI_CAPSULE_GUID\r
116 //\r
117\r
118 //\r
119 // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating\r
120 // System to have information persist across a system reset. EFI System Table must \r
121 // point to an array of capsules that contains the same CapsuleGuid value. And agents\r
122 // searching for this type capsule will look in EFI System Table and search for the \r
123 // capsule's Guid and associated pointer to retrieve the data. Two steps below describes\r
124 // how to sorting the capsules by the unique guid and install the array to EFI System Table. \r
125 // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an \r
126 // array for later sorting capsules by CapsuleGuid.\r
127 //\r
128 for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
129 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r
130 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
131 //\r
132 // For each capsule, we compare it with known CapsuleGuid in the CacheArray.\r
133 // If already has the Guid, skip it. Whereas, record it in the CacheArray as \r
134 // an additional one.\r
135 //\r
136 CacheIndex = 0;\r
137 while (CacheIndex < CacheNumber) {\r
138 if (CompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) {\r
139 break;\r
140 }\r
141 CacheIndex++;\r
142 }\r
143 if (CacheIndex == CacheNumber) {\r
144 CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID));\r
145 }\r
146 }\r
147 }\r
148\r
149 //\r
150 // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules\r
151 // whose guid is the same as it, and malloc memory for an array which preceding\r
152 // with UINT32. The array fills with entry point of capsules that have the same\r
153 // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install\r
154 // this array into EFI System Table, so that agents searching for this type capsule\r
155 // will look in EFI System Table and search for the capsule's Guid and associated\r
156 // pointer to retrieve the data.\r
157 //\r
158 CacheIndex = 0;\r
159 while (CacheIndex < CacheNumber) {\r
160 CapsuleNumber = 0; \r
161 for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
162 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r
163 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
164 if (CompareGuid (&CapsuleGuidCache[CacheIndex], &CapsuleHeader->CapsuleGuid)) {\r
165 //\r
166 // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid.\r
167 //\r
168 CapsulePtrCache[CapsuleNumber++] = (VOID*)CapsuleHeader;\r
169 }\r
170 }\r
171 }\r
172 if (CapsuleNumber != 0) {\r
173 Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*); \r
174 CapsuleTable = AllocateRuntimePool (Size);\r
175 ASSERT (CapsuleTable != NULL);\r
176 CapsuleTable->CapsuleArrayNumber = CapsuleNumber;\r
177 CopyMem(&CapsuleTable->CapsulePtr[0], CapsulePtrCache, CapsuleNumber * sizeof(VOID*));\r
178 Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable);\r
179 ASSERT_EFI_ERROR (Status);\r
180 }\r
181 CacheIndex++;\r
182 }\r
183\r
184 //\r
185 // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are\r
186 // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash \r
187 // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional\r
188 // type capsule transaction could be extended. It depends on platform policy.\r
189 //\r
190 for (Index = 0; Index < CapsuleTotalNumber; Index++) {\r
191 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];\r
192 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
193 //\r
194 // Call capsule library to process capsule image.\r
195 //\r
196 ProcessCapsuleImage (CapsuleHeader);\r
197 }\r
198 }\r
199\r
200 PlatformBdsLockNonUpdatableFlash ();\r
201 \r
202 //\r
203 // Free the allocated temp memory space.\r
204 //\r
205 FreePool (CapsuleGuidCache);\r
206 FreePool (CapsulePtrCache);\r
207 FreePool (CapsulePtr);\r
208\r
209 return Status;\r
210}\r
019dfb9c 211\r