]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Capsule Runtime Drivers produces two UEFI capsule runtime services.\r | |
3 | (UpdateCapsule, QueryCapsuleCapabilities)\r | |
4 | It installs the Capsule Architectural Protocol (EDKII definition) to signify \r | |
5 | the capsule runtime services are ready.\r | |
6 | \r | |
7 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | \r | |
20 | #include <Protocol/Capsule.h>\r | |
21 | #include <Guid/CapsuleVendor.h>\r | |
22 | \r | |
23 | #include <Library/DebugLib.h>\r | |
24 | #include <Library/PcdLib.h>\r | |
25 | #include <Library/CapsuleLib.h>\r | |
26 | #include <Library/UefiDriverEntryPoint.h>\r | |
27 | #include <Library/UefiBootServicesTableLib.h>\r | |
28 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
29 | #include <Library/UefiRuntimeLib.h>\r | |
30 | \r | |
31 | /**\r | |
32 | Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended\r | |
33 | consumption, the firmware may process the capsule immediately. If the payload should persist\r | |
34 | across a system reset, the reset value returned from EFI_QueryCapsuleCapabilities must\r | |
35 | be passed into ResetSystem() and will cause the capsule to be processed by the firmware as\r | |
36 | part of the reset process.\r | |
37 | \r | |
38 | @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r | |
39 | being passed into update capsule.\r | |
40 | @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in\r | |
41 | CaspuleHeaderArray.\r | |
42 | @param ScatterGatherList Physical pointer to a set of\r | |
43 | EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the\r | |
44 | location in physical memory of a set of capsules.\r | |
45 | \r | |
46 | @retval EFI_SUCCESS Valid capsule was passed. If\r | |
47 | CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the\r | |
48 | capsule has been successfully processed by the firmware.\r | |
49 | @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.\r | |
50 | @retval EFI_INVALID_PARAMETER CapsuleCount is Zero, or CapsuleImage is not valid.\r | |
51 | For across reset capsule image, ScatterGatherList is NULL.\r | |
52 | @retval EFI_UNSUPPORTED CapsuleImage is not recognized by the firmware.\r | |
53 | \r | |
54 | **/\r | |
55 | EFI_STATUS\r | |
56 | EFIAPI\r | |
57 | UpdateCapsule (\r | |
58 | IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r | |
59 | IN UINTN CapsuleCount,\r | |
60 | IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r | |
61 | )\r | |
62 | {\r | |
63 | UINTN ArrayNumber;\r | |
64 | EFI_STATUS Status;\r | |
65 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
66 | \r | |
67 | //\r | |
68 | // Capsule Count can't be less than one.\r | |
69 | //\r | |
70 | if (CapsuleCount < 1) {\r | |
71 | return EFI_INVALID_PARAMETER;\r | |
72 | }\r | |
73 | \r | |
74 | CapsuleHeader = NULL;\r | |
75 | \r | |
76 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
77 | //\r | |
78 | // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r | |
79 | // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r | |
80 | //\r | |
81 | CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r | |
82 | if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r | |
83 | return EFI_INVALID_PARAMETER;\r | |
84 | }\r | |
85 | //\r | |
86 | // Check Capsule image without populate flag by firmware support capsule function \r | |
87 | //\r | |
88 | if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r | |
89 | (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r | |
90 | return EFI_UNSUPPORTED;\r | |
91 | }\r | |
92 | }\r | |
93 | \r | |
94 | //\r | |
95 | // Assume that capsules have the same flags on reseting or not.\r | |
96 | //\r | |
97 | CapsuleHeader = CapsuleHeaderArray[0];\r | |
98 | \r | |
99 | //\r | |
100 | // Process across reset capsule image.\r | |
101 | //\r | |
102 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r | |
103 | //\r | |
104 | // Check if the platform supports update capsule across a system reset\r | |
105 | //\r | |
106 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r | |
107 | return EFI_UNSUPPORTED;\r | |
108 | }\r | |
109 | //\r | |
110 | // ScatterGatherList is only referenced if the capsules are defined to persist across\r | |
111 | // system reset. \r | |
112 | //\r | |
113 | if (ScatterGatherList == (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) {\r | |
114 | return EFI_INVALID_PARAMETER;\r | |
115 | } else {\r | |
116 | //\r | |
117 | // ScatterGatherList is only referenced if the capsules are defined to persist across\r | |
118 | // system reset. Set its value into NV storage to let pre-boot driver to pick it up \r | |
119 | // after coming through a system reset.\r | |
120 | //\r | |
121 | Status = gRT->SetVariable (\r | |
122 | EFI_CAPSULE_VARIABLE_NAME,\r | |
123 | &gEfiCapsuleVendorGuid,\r | |
124 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
125 | sizeof (UINTN),\r | |
126 | (VOID *) &ScatterGatherList\r | |
127 | );\r | |
128 | if (Status != EFI_SUCCESS) {\r | |
129 | return Status;\r | |
130 | }\r | |
131 | //\r | |
132 | // Successfully set the capsule image address into EFI variable.\r | |
133 | //\r | |
134 | return EFI_SUCCESS;\r | |
135 | }\r | |
136 | }\r | |
137 | \r | |
138 | //\r | |
139 | // Process the non-reset capsule image.\r | |
140 | //\r | |
141 | if (EfiAtRuntime ()) {\r | |
142 | //\r | |
143 | // Runtime mode doesn't support the non-reset capsule image.\r | |
144 | //\r | |
145 | return EFI_UNSUPPORTED;\r | |
146 | }\r | |
147 | \r | |
148 | //\r | |
149 | // Here should be in the boot-time for non-reset capsule image\r | |
150 | // Platform specific update for the non-reset capsule image.\r | |
151 | //\r | |
152 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
153 | Status = ProcessCapsuleImage (CapsuleHeaderArray[ArrayNumber]);\r | |
154 | if (EFI_ERROR (Status)) {\r | |
155 | return Status;\r | |
156 | }\r | |
157 | }\r | |
158 | \r | |
159 | return EFI_SUCCESS;\r | |
160 | }\r | |
161 | \r | |
162 | /**\r | |
163 | Returns if the capsule can be supported via UpdateCapsule().\r | |
164 | \r | |
165 | @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r | |
166 | being passed into update capsule.\r | |
167 | @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in\r | |
168 | CaspuleHeaderArray.\r | |
169 | @param MaxiumCapsuleSize On output the maximum size that UpdateCapsule() can\r | |
170 | support as an argument to UpdateCapsule() via\r | |
171 | CapsuleHeaderArray and ScatterGatherList.\r | |
172 | @param ResetType Returns the type of reset required for the capsule update.\r | |
173 | \r | |
174 | @retval EFI_SUCCESS Valid answer returned.\r | |
175 | @retval EFI_UNSUPPORTED The capsule image is not supported on this platform, and\r | |
176 | MaximumCapsuleSize and ResetType are undefined.\r | |
177 | @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL, or ResetTyep is NULL,\r | |
178 | Or CapsuleCount is Zero, or CapsuleImage is not valid.\r | |
179 | \r | |
180 | **/\r | |
181 | EFI_STATUS\r | |
182 | EFIAPI\r | |
183 | QueryCapsuleCapabilities (\r | |
184 | IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r | |
185 | IN UINTN CapsuleCount,\r | |
186 | OUT UINT64 *MaxiumCapsuleSize,\r | |
187 | OUT EFI_RESET_TYPE *ResetType\r | |
188 | )\r | |
189 | {\r | |
190 | UINTN ArrayNumber;\r | |
191 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
192 | \r | |
193 | //\r | |
194 | // Capsule Count can't be less than one.\r | |
195 | //\r | |
196 | if (CapsuleCount < 1) {\r | |
197 | return EFI_INVALID_PARAMETER;\r | |
198 | }\r | |
199 | \r | |
200 | //\r | |
201 | // Check whether input paramter is valid\r | |
202 | //\r | |
203 | if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r | |
204 | return EFI_INVALID_PARAMETER;\r | |
205 | }\r | |
206 | \r | |
207 | CapsuleHeader = NULL;\r | |
208 | \r | |
209 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
210 | CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r | |
211 | //\r | |
212 | // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r | |
213 | // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r | |
214 | //\r | |
215 | if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r | |
216 | return EFI_INVALID_PARAMETER;\r | |
217 | }\r | |
218 | //\r | |
219 | // Check Capsule image without populate flag is supported by firmware\r | |
220 | //\r | |
221 | if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r | |
222 | (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r | |
223 | return EFI_UNSUPPORTED;\r | |
224 | }\r | |
225 | }\r | |
226 | \r | |
227 | //\r | |
228 | // Assume that capsules have the same flags on reseting or not.\r | |
229 | //\r | |
230 | CapsuleHeader = CapsuleHeaderArray[0];\r | |
231 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r | |
232 | //\r | |
233 | //Check if the platform supports update capsule across a system reset\r | |
234 | //\r | |
235 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r | |
236 | return EFI_UNSUPPORTED;\r | |
237 | }\r | |
238 | *ResetType = EfiResetWarm; \r | |
239 | } else {\r | |
240 | //\r | |
241 | // For non-reset capsule image.\r | |
242 | //\r | |
243 | *ResetType = EfiResetCold;\r | |
244 | }\r | |
245 | \r | |
246 | //\r | |
247 | // The support max capsule image size\r | |
248 | //\r | |
249 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r | |
250 | *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r | |
251 | } else {\r | |
252 | *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r | |
253 | }\r | |
254 | \r | |
255 | return EFI_SUCCESS;\r | |
256 | }\r | |
257 | \r | |
258 | \r | |
259 | /**\r | |
260 | \r | |
261 | This code installs UEFI capsule runtime service.\r | |
262 | \r | |
263 | @param ImageHandle The firmware allocated handle for the EFI image. \r | |
264 | @param SystemTable A pointer to the EFI System Table.\r | |
265 | \r | |
266 | @retval EFI_SUCCESS UEFI Capsule Runtime Services are installed successfully. \r | |
267 | \r | |
268 | **/\r | |
269 | EFI_STATUS\r | |
270 | EFIAPI\r | |
271 | CapsuleServiceInitialize (\r | |
272 | IN EFI_HANDLE ImageHandle,\r | |
273 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
274 | )\r | |
275 | {\r | |
276 | EFI_STATUS Status;\r | |
277 | EFI_HANDLE NewHandle;\r | |
278 | \r | |
279 | //\r | |
280 | // Install capsule runtime services into UEFI runtime service tables.\r | |
281 | //\r | |
282 | gRT->UpdateCapsule = UpdateCapsule;\r | |
283 | gRT->QueryCapsuleCapabilities = QueryCapsuleCapabilities;\r | |
284 | \r | |
285 | //\r | |
286 | // Install the Capsule Architectural Protocol on a new handle\r | |
287 | // to signify the capsule runtime services are ready.\r | |
288 | //\r | |
289 | NewHandle = NULL;\r | |
290 | \r | |
291 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
292 | &NewHandle,\r | |
293 | &gEfiCapsuleArchProtocolGuid,\r | |
294 | NULL,\r | |
295 | NULL\r | |
296 | );\r | |
297 | ASSERT_EFI_ERROR (Status);\r | |
298 | \r | |
299 | return EFI_SUCCESS;\r | |
300 | }\r |