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