]>
Commit | Line | Data |
---|---|---|
a6d73269 | 1 | /** @file\r |
b0bacc00 KM |
2 | Produces a Firmware Management Protocol that supports updates to a firmware\r |
3 | image stored in a firmware device with platform and firmware device specific\r | |
4 | information provided through PCDs and libraries.\r | |
5 | \r | |
de6859ec | 6 | Copyright (c) Microsoft Corporation.<BR>\r |
2ed845b3 | 7 | Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>\r |
b0bacc00 | 8 | \r |
bcef758c | 9 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
b0bacc00 KM |
10 | \r |
11 | **/\r | |
12 | \r | |
4f0544b1 | 13 | #include "FmpDxe.h"\r |
67c1e5ee | 14 | #include "VariableSupport.h"\r |
b0bacc00 KM |
15 | \r |
16 | ///\r | |
17 | /// FILE_GUID from FmpDxe.inf. When FmpDxe.inf is used in a platform, the\r | |
18 | /// FILE_GUID must always be overridden in the <Defines> section to provide\r | |
19 | /// the ESRT GUID value associated with the updatable firmware image. A\r | |
20 | /// check is made in this module's driver entry point to verify that a\r | |
21 | /// new FILE_GUID value has been defined.\r | |
22 | ///\r | |
23 | const EFI_GUID mDefaultModuleFileGuid = {\r | |
24 | 0x78ef0a56, 0x1cf0, 0x4535, { 0xb5, 0xda, 0xf6, 0xfd, 0x2f, 0x40, 0x5a, 0x11 }\r | |
25 | };\r | |
26 | \r | |
b0bacc00 | 27 | ///\r |
4f0544b1 | 28 | /// TRUE if FmpDeviceLib manages a single firmware storage device.\r |
b0bacc00 | 29 | ///\r |
4f0544b1 | 30 | BOOLEAN mFmpSingleInstance = FALSE;\r |
b0bacc00 | 31 | \r |
4f0544b1 EJ |
32 | ///\r |
33 | /// Firmware Management Protocol instance that is initialized in the entry\r | |
34 | /// point from PCD settings.\r | |
35 | ///\r | |
36 | EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL mFmpProgress;\r | |
b0bacc00 | 37 | \r |
0760f5fe | 38 | //\r |
4f0544b1 EJ |
39 | // Template of the private context structure for the Firmware Management\r |
40 | // Protocol instance\r | |
0760f5fe | 41 | //\r |
4f0544b1 EJ |
42 | const FIRMWARE_MANAGEMENT_PRIVATE_DATA mFirmwareManagementPrivateDataTemplate = {\r |
43 | FIRMWARE_MANAGEMENT_PRIVATE_DATA_SIGNATURE, // Signature\r | |
44 | NULL, // Handle\r | |
45 | { // Fmp\r | |
46 | GetTheImageInfo,\r | |
47 | GetTheImage,\r | |
48 | SetTheImage,\r | |
49 | CheckTheImage,\r | |
50 | GetPackageInfo,\r | |
51 | SetPackageInfo\r | |
52 | },\r | |
53 | FALSE, // DescriptorPopulated\r | |
54 | { // Desc\r | |
55 | 1, // ImageIndex\r | |
56 | //\r | |
57 | // ImageTypeId\r | |
58 | //\r | |
59 | { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },\r | |
60 | 1, // ImageId\r | |
61 | NULL, // ImageIdName\r | |
62 | 0, // Version\r | |
63 | NULL, // VersionName\r | |
64 | 0, // Size\r | |
65 | 0, // AttributesSupported\r | |
66 | 0, // AttributesSetting\r | |
67 | 0, // Compatibilities\r | |
68 | 0, // LowestSupportedImageVersion\r | |
69 | 0, // LastAttemptVersion\r | |
70 | 0, // LastAttemptStatus\r | |
71 | 0 // HardwareInstance\r | |
72 | },\r | |
73 | NULL, // ImageIdName\r | |
74 | NULL, // VersionName\r | |
75 | TRUE, // RuntimeVersionSupported\r | |
76 | NULL, // FmpDeviceLockEvent\r | |
67c1e5ee EJ |
77 | FALSE, // FmpDeviceLocked\r |
78 | NULL, // FmpDeviceContext\r | |
79 | NULL, // VersionVariableName\r | |
80 | NULL, // LsvVariableName\r | |
81 | NULL, // LastAttemptStatusVariableName\r | |
82 | NULL, // LastAttemptVersionVariableName\r | |
0f30087b WX |
83 | NULL, // FmpStateVariableName\r |
84 | TRUE // DependenciesSatisfied\r | |
4f0544b1 EJ |
85 | };\r |
86 | \r | |
87 | ///\r | |
88 | /// GUID that is used to create event used to lock the firmware storage device.\r | |
89 | ///\r | |
90 | EFI_GUID *mLockGuid = NULL;\r | |
91 | \r | |
92 | ///\r | |
93 | /// Progress() function pointer passed into SetTheImage()\r | |
94 | ///\r | |
95 | EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS mProgressFunc = NULL;\r | |
96 | \r | |
97 | ///\r | |
98 | /// Null-terminated Unicode string retrieved from PcdFmpDeviceImageIdName.\r | |
99 | ///\r | |
100 | CHAR16 *mImageIdName = NULL;\r | |
b0bacc00 KM |
101 | \r |
102 | /**\r | |
103 | Callback function to report the process of the firmware updating.\r | |
104 | \r | |
105 | Wrap the caller's version in this so that progress from the device lib is\r | |
106 | within the expected range. Convert device lib 0% - 100% to 6% - 98%.\r | |
107 | \r | |
108 | FmpDxe 1% - 5% for validation\r | |
109 | FmpDeviceLib 6% - 98% for flashing/update\r | |
110 | FmpDxe 99% - 100% finish\r | |
111 | \r | |
112 | @param[in] Completion A value between 1 and 100 indicating the current\r | |
113 | completion progress of the firmware update. Completion\r | |
114 | progress is reported as from 1 to 100 percent. A value\r | |
115 | of 0 is used by the driver to indicate that progress\r | |
116 | reporting is not supported.\r | |
117 | \r | |
118 | @retval EFI_SUCCESS The progress was updated.\r | |
119 | @retval EFI_UNSUPPORTED Updating progress is not supported.\r | |
120 | \r | |
121 | **/\r | |
122 | EFI_STATUS\r | |
123 | EFIAPI\r | |
124 | FmpDxeProgress (\r | |
125 | IN UINTN Completion\r | |
126 | )\r | |
127 | {\r | |
128 | EFI_STATUS Status;\r | |
129 | \r | |
130 | Status = EFI_UNSUPPORTED;\r | |
131 | \r | |
b0bacc00 KM |
132 | if (mProgressFunc == NULL) {\r |
133 | return Status;\r | |
134 | }\r | |
135 | \r | |
136 | //\r | |
137 | // Reserve 6% - 98% for the FmpDeviceLib. Call the real progress function.\r | |
138 | //\r | |
139 | Status = mProgressFunc (((Completion * 92) / 100) + 6);\r | |
140 | \r | |
141 | if (Status == EFI_UNSUPPORTED) {\r | |
b0bacc00 KM |
142 | mProgressFunc = NULL;\r |
143 | }\r | |
144 | \r | |
145 | return Status;\r | |
146 | }\r | |
147 | \r | |
148 | /**\r | |
149 | Returns a pointer to the ImageTypeId GUID value. An attempt is made to get\r | |
150 | the GUID value from the FmpDeviceLib. If the FmpDeviceLib does not provide\r | |
278c3d48 EJ |
151 | a GUID value, then PcdFmpDeviceImageTypeIdGuid is used. If the size of\r |
152 | PcdFmpDeviceImageTypeIdGuid is not the size of EFI_GUID, then gEfiCallerIdGuid\r | |
153 | is returned.\r | |
b0bacc00 | 154 | \r |
67c1e5ee | 155 | @retval The ImageTypeId GUID\r |
b0bacc00 KM |
156 | \r |
157 | **/\r | |
158 | EFI_GUID *\r | |
159 | GetImageTypeIdGuid (\r | |
160 | VOID\r | |
161 | )\r | |
162 | {\r | |
163 | EFI_STATUS Status;\r | |
164 | EFI_GUID *FmpDeviceLibGuid;\r | |
278c3d48 | 165 | UINTN ImageTypeIdGuidSize;\r |
b0bacc00 KM |
166 | \r |
167 | FmpDeviceLibGuid = NULL;\r | |
168 | Status = FmpDeviceGetImageTypeIdGuidPtr (&FmpDeviceLibGuid);\r | |
169 | if (EFI_ERROR (Status)) {\r | |
170 | if (Status != EFI_UNSUPPORTED) {\r | |
e0961677 | 171 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid error %r\n", mImageIdName, Status));\r |
b0bacc00 | 172 | }\r |
278c3d48 | 173 | } else if (FmpDeviceLibGuid == NULL) {\r |
e0961677 | 174 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid GUID\n", mImageIdName));\r |
278c3d48 EJ |
175 | Status = EFI_NOT_FOUND;\r |
176 | }\r | |
177 | if (EFI_ERROR (Status)) {\r | |
178 | ImageTypeIdGuidSize = PcdGetSize (PcdFmpDeviceImageTypeIdGuid);\r | |
179 | if (ImageTypeIdGuidSize == sizeof (EFI_GUID)) {\r | |
180 | FmpDeviceLibGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceImageTypeIdGuid);\r | |
181 | } else {\r | |
de6859ec | 182 | DEBUG ((DEBUG_WARN, "FmpDxe(%s): Fall back to ImageTypeIdGuid of gEfiCallerIdGuid\n", mImageIdName));\r |
278c3d48 EJ |
183 | FmpDeviceLibGuid = &gEfiCallerIdGuid;\r |
184 | }\r | |
b0bacc00 KM |
185 | }\r |
186 | return FmpDeviceLibGuid;\r | |
187 | }\r | |
188 | \r | |
189 | /**\r | |
190 | Returns a pointer to the Null-terminated Unicode ImageIdName string.\r | |
191 | \r | |
67c1e5ee | 192 | @retval Null-terminated Unicode ImageIdName string.\r |
b0bacc00 KM |
193 | \r |
194 | **/\r | |
195 | CHAR16 *\r | |
196 | GetImageTypeNameString (\r | |
197 | VOID\r | |
198 | )\r | |
199 | {\r | |
200 | return mImageIdName;\r | |
201 | }\r | |
202 | \r | |
203 | /**\r | |
204 | Lowest supported version is a combo of three parts.\r | |
205 | 1. Check if the device lib has a lowest supported version\r | |
206 | 2. Check if we have a variable for lowest supported version (this will be updated with each capsule applied)\r | |
207 | 3. Check Fixed at build PCD\r | |
208 | \r | |
67c1e5ee EJ |
209 | @param[in] Private Pointer to the private context structure for the\r |
210 | Firmware Management Protocol instance.\r | |
211 | \r | |
212 | @retval The largest value\r | |
b0bacc00 KM |
213 | \r |
214 | **/\r | |
215 | UINT32\r | |
216 | GetLowestSupportedVersion (\r | |
67c1e5ee | 217 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
218 | )\r |
219 | {\r | |
220 | EFI_STATUS Status;\r | |
221 | UINT32 DeviceLibLowestSupportedVersion;\r | |
222 | UINT32 VariableLowestSupportedVersion;\r | |
223 | UINT32 ReturnLsv;\r | |
224 | \r | |
225 | //\r | |
226 | // Get the LowestSupportedVersion.\r | |
227 | //\r | |
228 | \r | |
b0bacc00 | 229 | if (!IsLowestSupportedVersionCheckRequired ()) {\r |
1bbb5126 SZ |
230 | //\r |
231 | // Any Version can pass the 0 LowestSupportedVersion check.\r | |
232 | //\r | |
233 | return 0;\r | |
b0bacc00 KM |
234 | }\r |
235 | \r | |
1bbb5126 SZ |
236 | ReturnLsv = PcdGet32 (PcdFmpDeviceBuildTimeLowestSupportedVersion);\r |
237 | \r | |
b0bacc00 KM |
238 | //\r |
239 | // Check the FmpDeviceLib\r | |
240 | //\r | |
559b5d52 | 241 | DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r |
b0bacc00 KM |
242 | Status = FmpDeviceGetLowestSupportedVersion (&DeviceLibLowestSupportedVersion);\r |
243 | if (EFI_ERROR (Status)) {\r | |
244 | DeviceLibLowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r | |
245 | }\r | |
246 | \r | |
247 | if (DeviceLibLowestSupportedVersion > ReturnLsv) {\r | |
248 | ReturnLsv = DeviceLibLowestSupportedVersion;\r | |
249 | }\r | |
250 | \r | |
251 | //\r | |
252 | // Check the lowest supported version UEFI variable for this device\r | |
253 | //\r | |
67c1e5ee | 254 | VariableLowestSupportedVersion = GetLowestSupportedVersionFromVariable (Private);\r |
b0bacc00 KM |
255 | if (VariableLowestSupportedVersion > ReturnLsv) {\r |
256 | ReturnLsv = VariableLowestSupportedVersion;\r | |
257 | }\r | |
258 | \r | |
259 | //\r | |
260 | // Return the largest value\r | |
261 | //\r | |
262 | return ReturnLsv;\r | |
263 | }\r | |
264 | \r | |
265 | /**\r | |
4f0544b1 EJ |
266 | Populates the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure in the private\r |
267 | context structure.\r | |
268 | \r | |
269 | @param[in] Private Pointer to the private context structure for the\r | |
270 | Firmware Management Protocol instance.\r | |
b0bacc00 KM |
271 | \r |
272 | **/\r | |
273 | VOID\r | |
274 | PopulateDescriptor (\r | |
4f0544b1 | 275 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
276 | )\r |
277 | {\r | |
278 | EFI_STATUS Status;\r | |
0f30087b | 279 | UINT32 DependenciesSize;\r |
b0bacc00 | 280 | \r |
b4b9496b MK |
281 | if (Private == NULL) {\r |
282 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): PopulateDescriptor() - Private is NULL.\n", mImageIdName));\r | |
283 | return;\r | |
284 | }\r | |
285 | \r | |
4f0544b1 EJ |
286 | if (Private->DescriptorPopulated) {\r |
287 | return;\r | |
288 | }\r | |
289 | \r | |
290 | Private->Descriptor.ImageIndex = 1;\r | |
291 | CopyGuid (&Private->Descriptor.ImageTypeId, GetImageTypeIdGuid());\r | |
292 | Private->Descriptor.ImageId = Private->Descriptor.ImageIndex;\r | |
293 | Private->Descriptor.ImageIdName = GetImageTypeNameString();\r | |
b0bacc00 | 294 | \r |
67c1e5ee EJ |
295 | //\r |
296 | // Get the hardware instance from FmpDeviceLib\r | |
297 | //\r | |
298 | Status = FmpDeviceGetHardwareInstance (&Private->Descriptor.HardwareInstance);\r | |
299 | if (Status == EFI_UNSUPPORTED) {\r | |
300 | Private->Descriptor.HardwareInstance = 0;\r | |
301 | }\r | |
302 | \r | |
303 | //\r | |
304 | // Generate UEFI Variable names used to store status information for this\r | |
305 | // FMP instance.\r | |
306 | //\r | |
307 | GenerateFmpVariableNames (Private);\r | |
308 | \r | |
b0bacc00 KM |
309 | //\r |
310 | // Get the version. Some devices don't support getting the firmware version\r | |
311 | // at runtime. If FmpDeviceLib does not support returning a version, then\r | |
312 | // it is stored in a UEFI variable.\r | |
313 | //\r | |
4f0544b1 | 314 | Status = FmpDeviceGetVersion (&Private->Descriptor.Version);\r |
b0bacc00 | 315 | if (Status == EFI_UNSUPPORTED) {\r |
4f0544b1 | 316 | Private->RuntimeVersionSupported = FALSE;\r |
67c1e5ee | 317 | Private->Descriptor.Version = GetVersionFromVariable (Private);\r |
b0bacc00 KM |
318 | } else if (EFI_ERROR (Status)) {\r |
319 | //\r | |
320 | // Unexpected error. Use default version.\r | |
321 | //\r | |
e0961677 | 322 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetVersion() from FmpDeviceLib (%s) returned %r\n", mImageIdName, GetImageTypeNameString(), Status));\r |
4f0544b1 | 323 | Private->Descriptor.Version = DEFAULT_VERSION;\r |
b0bacc00 KM |
324 | }\r |
325 | \r | |
326 | //\r | |
327 | // Free the current version name. Shouldn't really happen but this populate\r | |
328 | // function could be called multiple times (to refresh).\r | |
329 | //\r | |
4f0544b1 EJ |
330 | if (Private->Descriptor.VersionName != NULL) {\r |
331 | FreePool (Private->Descriptor.VersionName);\r | |
332 | Private->Descriptor.VersionName = NULL;\r | |
b0bacc00 KM |
333 | }\r |
334 | \r | |
335 | //\r | |
336 | // Attempt to get the version string from the FmpDeviceLib\r | |
337 | //\r | |
4f0544b1 | 338 | Status = FmpDeviceGetVersionString (&Private->Descriptor.VersionName);\r |
b0bacc00 | 339 | if (Status == EFI_UNSUPPORTED) {\r |
e0961677 | 340 | DEBUG ((DEBUG_INFO, "FmpDxe(%s): GetVersionString() unsupported in FmpDeviceLib.\n", mImageIdName));\r |
4f0544b1 EJ |
341 | Private->Descriptor.VersionName = AllocateCopyPool (\r |
342 | sizeof (VERSION_STRING_NOT_SUPPORTED),\r | |
343 | VERSION_STRING_NOT_SUPPORTED\r | |
344 | );\r | |
b0bacc00 | 345 | } else if (EFI_ERROR (Status)) {\r |
e0961677 | 346 | DEBUG ((DEBUG_INFO, "FmpDxe(%s): GetVersionString() not available in FmpDeviceLib.\n", mImageIdName));\r |
4f0544b1 EJ |
347 | Private->Descriptor.VersionName = AllocateCopyPool (\r |
348 | sizeof (VERSION_STRING_NOT_AVAILABLE),\r | |
349 | VERSION_STRING_NOT_AVAILABLE\r | |
350 | );\r | |
b0bacc00 KM |
351 | }\r |
352 | \r | |
67c1e5ee | 353 | Private->Descriptor.LowestSupportedImageVersion = GetLowestSupportedVersion (Private);\r |
b0bacc00 KM |
354 | \r |
355 | //\r | |
356 | // Get attributes from the FmpDeviceLib\r | |
357 | //\r | |
4f0544b1 EJ |
358 | FmpDeviceGetAttributes (\r |
359 | &Private->Descriptor.AttributesSupported,\r | |
360 | &Private->Descriptor.AttributesSetting\r | |
361 | );\r | |
b0bacc00 KM |
362 | \r |
363 | //\r | |
364 | // Force set the updatable bits in the attributes;\r | |
365 | //\r | |
4f0544b1 EJ |
366 | Private->Descriptor.AttributesSupported |= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;\r |
367 | Private->Descriptor.AttributesSetting |= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;\r | |
b0bacc00 KM |
368 | \r |
369 | //\r | |
370 | // Force set the authentication bits in the attributes;\r | |
371 | //\r | |
4f0544b1 EJ |
372 | Private->Descriptor.AttributesSupported |= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);\r |
373 | Private->Descriptor.AttributesSetting |= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);\r | |
b0bacc00 | 374 | \r |
4f0544b1 | 375 | Private->Descriptor.Compatibilities = 0;\r |
b0bacc00 KM |
376 | \r |
377 | //\r | |
378 | // Get the size of the firmware image from the FmpDeviceLib\r | |
379 | //\r | |
4f0544b1 | 380 | Status = FmpDeviceGetSize (&Private->Descriptor.Size);\r |
b0bacc00 | 381 | if (EFI_ERROR (Status)) {\r |
4f0544b1 | 382 | Private->Descriptor.Size = 0;\r |
b0bacc00 KM |
383 | }\r |
384 | \r | |
67c1e5ee EJ |
385 | Private->Descriptor.LastAttemptVersion = GetLastAttemptVersionFromVariable (Private);\r |
386 | Private->Descriptor.LastAttemptStatus = GetLastAttemptStatusFromVariable (Private);\r | |
4f0544b1 | 387 | \r |
2ed845b3 | 388 | //\r |
0f30087b | 389 | // Get the dependency from the FmpDependencyDeviceLib.\r |
2ed845b3 WX |
390 | //\r |
391 | Private->Descriptor.Dependencies = NULL;\r | |
392 | \r | |
393 | //\r | |
394 | // Check the attribute IMAGE_ATTRIBUTE_DEPENDENCY\r | |
395 | //\r | |
0f30087b WX |
396 | if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) {\r |
397 | Private->Descriptor.Dependencies = GetFmpDependency (&DependenciesSize);\r | |
2ed845b3 WX |
398 | }\r |
399 | \r | |
4f0544b1 | 400 | Private->DescriptorPopulated = TRUE;\r |
b0bacc00 KM |
401 | }\r |
402 | \r | |
403 | /**\r | |
404 | Returns information about the current firmware image(s) of the device.\r | |
405 | \r | |
406 | This function allows a copy of the current firmware image to be created and saved.\r | |
407 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
408 | \r | |
409 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
410 | @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r | |
411 | On input, this is the size of the buffer allocated by the caller.\r | |
412 | On output, it is the size of the buffer returned by the firmware\r | |
413 | if the buffer was large enough, or the size of the buffer needed\r | |
414 | to contain the image(s) information if the buffer was too small.\r | |
415 | @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r | |
416 | information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r | |
417 | @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r | |
418 | associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
419 | @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r | |
420 | descriptors or firmware images within this device.\r | |
421 | @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r | |
422 | of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
423 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
424 | The format is vendor specific and new version must have a greater value\r | |
425 | than the old version. If PackageVersion is not supported, the value is\r | |
426 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r | |
427 | is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r | |
428 | that package version update is in progress.\r | |
429 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r | |
430 | package version name. The buffer is allocated by this function with\r | |
431 | AllocatePool(), and it is the caller's responsibility to free it with a call\r | |
432 | to FreePool().\r | |
433 | \r | |
434 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
435 | @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r | |
436 | needed to hold the image(s) information is returned in ImageInfoSize.\r | |
437 | @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r | |
438 | @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r | |
439 | \r | |
440 | **/\r | |
441 | EFI_STATUS\r | |
442 | EFIAPI\r | |
443 | GetTheImageInfo (\r | |
444 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
445 | IN OUT UINTN *ImageInfoSize,\r | |
446 | IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r | |
447 | OUT UINT32 *DescriptorVersion,\r | |
448 | OUT UINT8 *DescriptorCount,\r | |
449 | OUT UINTN *DescriptorSize,\r | |
450 | OUT UINT32 *PackageVersion,\r | |
451 | OUT CHAR16 **PackageVersionName\r | |
452 | )\r | |
453 | {\r | |
4f0544b1 EJ |
454 | EFI_STATUS Status;\r |
455 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
b0bacc00 KM |
456 | \r |
457 | Status = EFI_SUCCESS;\r | |
458 | \r | |
b4b9496b MK |
459 | if (This == NULL) {\r |
460 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImageInfo() - This is NULL.\n", mImageIdName));\r | |
461 | Status = EFI_INVALID_PARAMETER;\r | |
462 | goto cleanup;\r | |
463 | }\r | |
464 | \r | |
4f0544b1 EJ |
465 | //\r |
466 | // Retrieve the private context structure\r | |
467 | //\r | |
468 | Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r | |
469 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
470 | \r | |
b0bacc00 KM |
471 | //\r |
472 | // Check for valid pointer\r | |
473 | //\r | |
474 | if (ImageInfoSize == NULL) {\r | |
e0961677 | 475 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImageInfo() - ImageInfoSize is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
476 | Status = EFI_INVALID_PARAMETER;\r |
477 | goto cleanup;\r | |
478 | }\r | |
479 | \r | |
480 | //\r | |
481 | // Check the buffer size\r | |
482 | // NOTE: Check this first so caller can get the necessary memory size it must allocate.\r | |
483 | //\r | |
484 | if (*ImageInfoSize < (sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR))) {\r | |
485 | *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r | |
e0961677 | 486 | DEBUG ((DEBUG_VERBOSE, "FmpDxe(%s): GetImageInfo() - ImageInfoSize is to small.\n", mImageIdName));\r |
b0bacc00 KM |
487 | Status = EFI_BUFFER_TOO_SMALL;\r |
488 | goto cleanup;\r | |
489 | }\r | |
490 | \r | |
491 | //\r | |
492 | // Confirm that buffer isn't null\r | |
493 | //\r | |
494 | if ( (ImageInfo == NULL) || (DescriptorVersion == NULL) || (DescriptorCount == NULL) || (DescriptorSize == NULL)\r | |
495 | || (PackageVersion == NULL)) {\r | |
e0961677 | 496 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImageInfo() - Pointer Parameter is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
497 | Status = EFI_INVALID_PARAMETER;\r |
498 | goto cleanup;\r | |
499 | }\r | |
500 | \r | |
501 | //\r | |
502 | // Set the size to whatever we need\r | |
503 | //\r | |
504 | *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r | |
505 | \r | |
4f0544b1 | 506 | //\r |
67c1e5ee | 507 | // Make sure the descriptor has already been loaded or refreshed\r |
4f0544b1 EJ |
508 | //\r |
509 | PopulateDescriptor (Private);\r | |
b0bacc00 KM |
510 | \r |
511 | //\r | |
512 | // Copy the image descriptor\r | |
513 | //\r | |
4f0544b1 | 514 | CopyMem (ImageInfo, &Private->Descriptor, sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r |
b0bacc00 KM |
515 | \r |
516 | *DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r | |
517 | *DescriptorCount = 1;\r | |
518 | *DescriptorSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r | |
519 | //\r | |
520 | // means unsupported\r | |
521 | //\r | |
522 | *PackageVersion = 0xFFFFFFFF;\r | |
523 | \r | |
524 | //\r | |
525 | // Do not update PackageVersionName since it is not supported in this instance.\r | |
526 | //\r | |
527 | \r | |
528 | cleanup:\r | |
529 | \r | |
530 | return Status;\r | |
531 | }\r | |
532 | \r | |
533 | /**\r | |
534 | Retrieves a copy of the current firmware image of the device.\r | |
535 | \r | |
536 | This function allows a copy of the current firmware image to be created and saved.\r | |
537 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
538 | \r | |
a6d73269 SZ |
539 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r |
540 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
b0bacc00 | 541 | The number is between 1 and DescriptorCount.\r |
a6d73269 SZ |
542 | @param[in, out] Image Points to the buffer where the current image is copied to.\r |
543 | @param[in, out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r | |
b0bacc00 KM |
544 | On return, points to the length of the image, in bytes.\r |
545 | \r | |
546 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
547 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r | |
548 | image. The current buffer size needed to hold the image is returned\r | |
549 | in ImageSize.\r | |
550 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
551 | @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r | |
552 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
5fc5867e | 553 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
b0bacc00 KM |
554 | \r |
555 | **/\r | |
556 | EFI_STATUS\r | |
557 | EFIAPI\r | |
558 | GetTheImage (\r | |
559 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
560 | IN UINT8 ImageIndex,\r | |
561 | IN OUT VOID *Image,\r | |
562 | IN OUT UINTN *ImageSize\r | |
563 | )\r | |
564 | {\r | |
4f0544b1 EJ |
565 | EFI_STATUS Status;\r |
566 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
567 | UINTN Size;\r | |
b0bacc00 | 568 | \r |
11d35494 EJ |
569 | if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) {\r |
570 | return EFI_UNSUPPORTED;\r | |
571 | }\r | |
572 | \r | |
0f30087b | 573 | Status = EFI_SUCCESS;\r |
b0bacc00 | 574 | \r |
b4b9496b MK |
575 | if (This == NULL) {\r |
576 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - This is NULL.\n", mImageIdName));\r | |
577 | Status = EFI_INVALID_PARAMETER;\r | |
578 | goto cleanup;\r | |
579 | }\r | |
580 | \r | |
4f0544b1 EJ |
581 | //\r |
582 | // Retrieve the private context structure\r | |
583 | //\r | |
584 | Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r | |
585 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
586 | \r | |
ebfac291 SZ |
587 | //\r |
588 | // Check to make sure index is 1 (only 1 image for this device)\r | |
589 | //\r | |
590 | if (ImageIndex != 1) {\r | |
e0961677 | 591 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - Image Index Invalid.\n", mImageIdName));\r |
ebfac291 SZ |
592 | Status = EFI_INVALID_PARAMETER;\r |
593 | goto cleanup;\r | |
594 | }\r | |
595 | \r | |
03340683 | 596 | if (ImageSize == NULL) {\r |
e0961677 | 597 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - ImageSize Pointer Parameter is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
598 | Status = EFI_INVALID_PARAMETER;\r |
599 | goto cleanup;\r | |
600 | }\r | |
601 | \r | |
602 | //\r | |
603 | // Check the buffer size\r | |
604 | //\r | |
605 | Status = FmpDeviceGetSize (&Size);\r | |
606 | if (EFI_ERROR (Status)) {\r | |
607 | Size = 0;\r | |
608 | }\r | |
0f30087b WX |
609 | if (*ImageSize < Size) {\r |
610 | *ImageSize = Size;\r | |
e0961677 | 611 | DEBUG ((DEBUG_VERBOSE, "FmpDxe(%s): GetImage() - ImageSize is to small.\n", mImageIdName));\r |
b0bacc00 KM |
612 | Status = EFI_BUFFER_TOO_SMALL;\r |
613 | goto cleanup;\r | |
614 | }\r | |
615 | \r | |
616 | if (Image == NULL) {\r | |
e0961677 | 617 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - Image Pointer Parameter is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
618 | Status = EFI_INVALID_PARAMETER;\r |
619 | goto cleanup;\r | |
620 | }\r | |
621 | \r | |
0f30087b | 622 | Status = FmpDeviceGetImage (Image, ImageSize);\r |
b0bacc00 KM |
623 | cleanup:\r |
624 | \r | |
625 | return Status;\r | |
626 | }\r | |
627 | \r | |
628 | /**\r | |
629 | Helper function to safely retrieve the FMP header from\r | |
630 | within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.\r | |
631 | \r | |
0f30087b WX |
632 | @param[in] Image Pointer to the image.\r |
633 | @param[in] ImageSize Size of the image.\r | |
634 | @param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function.\r | |
b4b9496b MK |
635 | @param[out] PayloadSize An optional pointer to a UINTN that holds the size of the payload\r |
636 | (image size minus headers)\r | |
b0bacc00 KM |
637 | \r |
638 | @retval !NULL Valid pointer to the header.\r | |
639 | @retval NULL Structure is bad and pointer cannot be found.\r | |
640 | \r | |
641 | **/\r | |
642 | VOID *\r | |
643 | GetFmpHeader (\r | |
644 | IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image,\r | |
645 | IN CONST UINTN ImageSize,\r | |
0f30087b | 646 | IN CONST UINTN AdditionalHeaderSize,\r |
b4b9496b | 647 | OUT UINTN *PayloadSize OPTIONAL\r |
b0bacc00 KM |
648 | )\r |
649 | {\r | |
650 | //\r | |
651 | // Check to make sure that operation can be safely performed.\r | |
652 | //\r | |
0f30087b WX |
653 | if (((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength) + AdditionalHeaderSize < (UINTN)Image || \\r |
654 | ((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength) + AdditionalHeaderSize >= (UINTN)Image + ImageSize) {\r | |
b0bacc00 KM |
655 | //\r |
656 | // Pointer overflow. Invalid image.\r | |
657 | //\r | |
658 | return NULL;\r | |
659 | }\r | |
660 | \r | |
b4b9496b MK |
661 | if (PayloadSize != NULL) {\r |
662 | *PayloadSize = ImageSize - (sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize);\r | |
663 | }\r | |
664 | \r | |
0f30087b | 665 | return (VOID *)((UINT8 *)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize);\r |
b0bacc00 KM |
666 | }\r |
667 | \r | |
668 | /**\r | |
669 | Helper function to safely calculate the size of all headers\r | |
670 | within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.\r | |
671 | \r | |
672 | @param[in] Image Pointer to the image.\r | |
673 | @param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function.\r | |
674 | \r | |
675 | @retval UINT32>0 Valid size of all the headers.\r | |
676 | @retval 0 Structure is bad and size cannot be found.\r | |
677 | \r | |
678 | **/\r | |
679 | UINT32\r | |
680 | GetAllHeaderSize (\r | |
681 | IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image,\r | |
682 | IN UINT32 AdditionalHeaderSize\r | |
683 | )\r | |
684 | {\r | |
685 | UINT32 CalculatedSize;\r | |
686 | \r | |
b4b9496b MK |
687 | if (Image == NULL) {\r |
688 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetAllHeaderSize() - Image is NULL.\n", mImageIdName));\r | |
689 | return 0;\r | |
690 | }\r | |
691 | \r | |
b0bacc00 KM |
692 | CalculatedSize = sizeof (Image->MonotonicCount) +\r |
693 | AdditionalHeaderSize +\r | |
694 | Image->AuthInfo.Hdr.dwLength;\r | |
695 | \r | |
696 | //\r | |
697 | // Check to make sure that operation can be safely performed.\r | |
698 | //\r | |
699 | if (CalculatedSize < sizeof (Image->MonotonicCount) ||\r | |
700 | CalculatedSize < AdditionalHeaderSize ||\r | |
701 | CalculatedSize < Image->AuthInfo.Hdr.dwLength ) {\r | |
702 | //\r | |
703 | // Integer overflow. Invalid image.\r | |
704 | //\r | |
705 | return 0;\r | |
706 | }\r | |
707 | \r | |
708 | return CalculatedSize;\r | |
709 | }\r | |
710 | \r | |
711 | /**\r | |
712 | Checks if the firmware image is valid for the device.\r | |
713 | \r | |
714 | This function allows firmware update application to validate the firmware image without\r | |
715 | invoking the SetImage() first.\r | |
716 | \r | |
717 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
718 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
719 | The number is between 1 and DescriptorCount.\r | |
720 | @param[in] Image Points to the new image.\r | |
721 | @param[in] ImageSize Size of the new image in bytes.\r | |
722 | @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r | |
723 | if available, additional information if the image is invalid.\r | |
724 | \r | |
725 | @retval EFI_SUCCESS The image was successfully checked.\r | |
4e61b8d0 | 726 | @retval EFI_ABORTED The operation is aborted.\r |
b0bacc00 KM |
727 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r |
728 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
5fc5867e | 729 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
b0bacc00 KM |
730 | \r |
731 | **/\r | |
732 | EFI_STATUS\r | |
733 | EFIAPI\r | |
734 | CheckTheImage (\r | |
735 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
736 | IN UINT8 ImageIndex,\r | |
737 | IN CONST VOID *Image,\r | |
738 | IN UINTN ImageSize,\r | |
a6d73269 | 739 | OUT UINT32 *ImageUpdatable\r |
b0bacc00 KM |
740 | )\r |
741 | {\r | |
4f0544b1 EJ |
742 | EFI_STATUS Status;\r |
743 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
744 | UINTN RawSize;\r | |
745 | VOID *FmpPayloadHeader;\r | |
746 | UINTN FmpPayloadSize;\r | |
747 | UINT32 Version;\r | |
748 | UINT32 FmpHeaderSize;\r | |
749 | UINTN AllHeaderSize;\r | |
750 | UINT32 Index;\r | |
751 | VOID *PublicKeyData;\r | |
752 | UINTN PublicKeyDataLength;\r | |
753 | UINT8 *PublicKeyDataXdr;\r | |
754 | UINT8 *PublicKeyDataXdrEnd;\r | |
2ed845b3 WX |
755 | EFI_FIRMWARE_IMAGE_DEP *Dependencies;\r |
756 | UINT32 DependenciesSize;\r | |
b0bacc00 KM |
757 | \r |
758 | Status = EFI_SUCCESS;\r | |
759 | RawSize = 0;\r | |
760 | FmpPayloadHeader = NULL;\r | |
761 | FmpPayloadSize = 0;\r | |
762 | Version = 0;\r | |
763 | FmpHeaderSize = 0;\r | |
764 | AllHeaderSize = 0;\r | |
2ed845b3 WX |
765 | Dependencies = NULL;\r |
766 | DependenciesSize = 0;\r | |
b0bacc00 | 767 | \r |
11d35494 EJ |
768 | if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) {\r |
769 | return EFI_UNSUPPORTED;\r | |
770 | }\r | |
771 | \r | |
b4b9496b MK |
772 | if (This == NULL) {\r |
773 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - This is NULL.\n", mImageIdName));\r | |
774 | Status = EFI_INVALID_PARAMETER;\r | |
775 | goto cleanup;\r | |
776 | }\r | |
777 | \r | |
4f0544b1 EJ |
778 | //\r |
779 | // Retrieve the private context structure\r | |
780 | //\r | |
781 | Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r | |
782 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
783 | \r | |
b0bacc00 | 784 | //\r |
67c1e5ee | 785 | // Make sure the descriptor has already been loaded or refreshed\r |
b0bacc00 | 786 | //\r |
4f0544b1 | 787 | PopulateDescriptor (Private);\r |
b0bacc00 | 788 | \r |
a6d73269 | 789 | if (ImageUpdatable == NULL) {\r |
e0961677 | 790 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - ImageUpdatable Pointer Parameter is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
791 | Status = EFI_INVALID_PARAMETER;\r |
792 | goto cleanup;\r | |
793 | }\r | |
794 | \r | |
795 | //\r | |
796 | //Set to valid and then if any tests fail it will update this flag.\r | |
797 | //\r | |
a6d73269 | 798 | *ImageUpdatable = IMAGE_UPDATABLE_VALID;\r |
b0bacc00 | 799 | \r |
0f30087b WX |
800 | //\r |
801 | // Set to satisfied and then if dependency evaluates to false it will update this flag.\r | |
802 | //\r | |
803 | Private->DependenciesSatisfied = TRUE;\r | |
804 | \r | |
b0bacc00 | 805 | if (Image == NULL) {\r |
e0961677 | 806 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Pointer Parameter is NULL.\n", mImageIdName));\r |
b0bacc00 KM |
807 | //\r |
808 | // not sure if this is needed\r | |
809 | //\r | |
a6d73269 | 810 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r |
b0bacc00 KM |
811 | return EFI_INVALID_PARAMETER;\r |
812 | }\r | |
813 | \r | |
814 | PublicKeyDataXdr = PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr);\r | |
815 | PublicKeyDataXdrEnd = PublicKeyDataXdr + PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr);\r | |
816 | \r | |
817 | if (PublicKeyDataXdr == NULL || (PublicKeyDataXdr == PublicKeyDataXdrEnd)) {\r | |
e0961677 | 818 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Invalid certificate, skipping it.\n", mImageIdName));\r |
b0bacc00 KM |
819 | Status = EFI_ABORTED;\r |
820 | } else {\r | |
821 | //\r | |
822 | // Try each key from PcdFmpDevicePkcs7CertBufferXdr\r | |
823 | //\r | |
824 | for (Index = 1; PublicKeyDataXdr < PublicKeyDataXdrEnd; Index++) {\r | |
825 | Index++;\r | |
826 | DEBUG (\r | |
827 | (DEBUG_INFO,\r | |
e0961677 EJ |
828 | "FmpDxe(%s): Certificate #%d [%p..%p].\n",\r |
829 | mImageIdName,\r | |
b0bacc00 KM |
830 | Index,\r |
831 | PublicKeyDataXdr,\r | |
832 | PublicKeyDataXdrEnd\r | |
833 | )\r | |
834 | );\r | |
835 | \r | |
836 | if ((PublicKeyDataXdr + sizeof (UINT32)) > PublicKeyDataXdrEnd) {\r | |
837 | //\r | |
838 | // Key data extends beyond end of PCD\r | |
839 | //\r | |
e0961677 | 840 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Certificate size extends beyond end of PCD, skipping it.\n", mImageIdName));\r |
b0bacc00 KM |
841 | Status = EFI_ABORTED;\r |
842 | break;\r | |
843 | }\r | |
844 | //\r | |
845 | // Read key length stored in big-endian format\r | |
846 | //\r | |
847 | PublicKeyDataLength = SwapBytes32 (*(UINT32 *)(PublicKeyDataXdr));\r | |
848 | //\r | |
849 | // Point to the start of the key data\r | |
850 | //\r | |
851 | PublicKeyDataXdr += sizeof (UINT32);\r | |
852 | if (PublicKeyDataXdr + PublicKeyDataLength > PublicKeyDataXdrEnd) {\r | |
853 | //\r | |
854 | // Key data extends beyond end of PCD\r | |
855 | //\r | |
e0961677 | 856 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Certificate extends beyond end of PCD, skipping it.\n", mImageIdName));\r |
b0bacc00 KM |
857 | Status = EFI_ABORTED;\r |
858 | break;\r | |
859 | }\r | |
860 | PublicKeyData = PublicKeyDataXdr;\r | |
861 | Status = AuthenticateFmpImage (\r | |
862 | (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image,\r | |
863 | ImageSize,\r | |
864 | PublicKeyData,\r | |
865 | PublicKeyDataLength\r | |
866 | );\r | |
867 | if (!EFI_ERROR (Status)) {\r | |
868 | break;\r | |
869 | }\r | |
870 | PublicKeyDataXdr += PublicKeyDataLength;\r | |
871 | PublicKeyDataXdr = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));\r | |
872 | }\r | |
873 | }\r | |
874 | \r | |
875 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 876 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Authentication Failed %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
877 | goto cleanup;\r |
878 | }\r | |
879 | \r | |
880 | //\r | |
881 | // Check to make sure index is 1\r | |
882 | //\r | |
883 | if (ImageIndex != 1) {\r | |
e0961677 | 884 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Index Invalid.\n", mImageIdName));\r |
a6d73269 | 885 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID_TYPE;\r |
b4b9496b | 886 | Status = EFI_INVALID_PARAMETER;\r |
b0bacc00 KM |
887 | goto cleanup;\r |
888 | }\r | |
889 | \r | |
0f30087b WX |
890 | //\r |
891 | // Get the dependency from Image.\r | |
892 | //\r | |
893 | Dependencies = GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, &DependenciesSize);\r | |
b0bacc00 KM |
894 | \r |
895 | //\r | |
896 | // Check the FmpPayloadHeader\r | |
897 | //\r | |
0f30087b | 898 | FmpPayloadHeader = GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, DependenciesSize, &FmpPayloadSize );\r |
b0bacc00 | 899 | if (FmpPayloadHeader == NULL) {\r |
e0961677 | 900 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpHeader failed.\n", mImageIdName));\r |
b0bacc00 KM |
901 | Status = EFI_ABORTED;\r |
902 | goto cleanup;\r | |
903 | }\r | |
904 | Status = GetFmpPayloadHeaderVersion (FmpPayloadHeader, FmpPayloadSize, &Version);\r | |
905 | if (EFI_ERROR (Status)) {\r | |
0f30087b WX |
906 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpPayloadHeaderVersion failed %r.\n", mImageIdName, Status));\r |
907 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r | |
908 | Status = EFI_SUCCESS;\r | |
909 | goto cleanup;\r | |
b0bacc00 KM |
910 | }\r |
911 | \r | |
912 | //\r | |
913 | // Check the lowest supported version\r | |
914 | //\r | |
4f0544b1 | 915 | if (Version < Private->Descriptor.LowestSupportedImageVersion) {\r |
b0bacc00 KM |
916 | DEBUG (\r |
917 | (DEBUG_ERROR,\r | |
e0961677 EJ |
918 | "FmpDxe(%s): CheckTheImage() - Version Lower than lowest supported version. 0x%08X < 0x%08X\n",\r |
919 | mImageIdName, Version, Private->Descriptor.LowestSupportedImageVersion)\r | |
b0bacc00 | 920 | );\r |
a6d73269 | 921 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID_OLD;\r |
b0bacc00 KM |
922 | Status = EFI_SUCCESS;\r |
923 | goto cleanup;\r | |
924 | }\r | |
925 | \r | |
2ed845b3 WX |
926 | //\r |
927 | // Evaluate dependency expression\r | |
928 | //\r | |
0f30087b WX |
929 | Private->DependenciesSatisfied = CheckFmpDependency (Private->Descriptor.ImageTypeId, Version, Dependencies, DependenciesSize);\r |
930 | if (!Private->DependenciesSatisfied) {\r | |
931 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check failed.\n", mImageIdName));\r | |
2ed845b3 WX |
932 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r |
933 | Status = EFI_SUCCESS;\r | |
934 | goto cleanup;\r | |
935 | }\r | |
936 | \r | |
b0bacc00 KM |
937 | //\r |
938 | // Get the FmpHeaderSize so we can determine the real payload size\r | |
939 | //\r | |
940 | Status = GetFmpPayloadHeaderSize (FmpPayloadHeader, FmpPayloadSize, &FmpHeaderSize);\r | |
941 | if (EFI_ERROR (Status)) {\r | |
942 | DEBUG ((DEBUG_ERROR, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status));\r | |
a6d73269 | 943 | *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r |
b0bacc00 KM |
944 | Status = EFI_SUCCESS;\r |
945 | goto cleanup;\r | |
946 | }\r | |
947 | \r | |
948 | //\r | |
949 | // Call FmpDevice Lib Check Image on the\r | |
950 | // Raw payload. So all headers need stripped off\r | |
951 | //\r | |
2ed845b3 | 952 | AllHeaderSize = GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, FmpHeaderSize + DependenciesSize);\r |
b0bacc00 | 953 | if (AllHeaderSize == 0) {\r |
e0961677 | 954 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetAllHeaderSize failed.\n", mImageIdName));\r |
b0bacc00 KM |
955 | Status = EFI_ABORTED;\r |
956 | goto cleanup;\r | |
957 | }\r | |
958 | RawSize = ImageSize - AllHeaderSize;\r | |
959 | \r | |
960 | //\r | |
961 | // FmpDeviceLib CheckImage function to do any specific checks\r | |
962 | //\r | |
a6d73269 | 963 | Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdatable);\r |
b0bacc00 | 964 | if (EFI_ERROR (Status)) {\r |
e0961677 | 965 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", mImageIdName, Status));\r |
b0bacc00 KM |
966 | }\r |
967 | \r | |
968 | cleanup:\r | |
969 | return Status;\r | |
970 | }\r | |
971 | \r | |
972 | /**\r | |
973 | Updates the firmware image of the device.\r | |
974 | \r | |
975 | This function updates the hardware with the new firmware image.\r | |
976 | This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r | |
977 | If the firmware image is updatable, the function should perform the following minimal validations\r | |
978 | before proceeding to do the firmware image update.\r | |
979 | - Validate the image authentication if image has attribute\r | |
980 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r | |
981 | EFI_SECURITY_VIOLATION if the validation fails.\r | |
982 | - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r | |
983 | the image is unsupported. The function can optionally provide more detailed information on\r | |
984 | why the image is not a supported image.\r | |
985 | - Validate the data from VendorCode if not null. Image validation must be performed before\r | |
986 | VendorCode data validation. VendorCode data is ignored or considered invalid if image\r | |
987 | validation failed. The function returns EFI_ABORTED if the data is invalid.\r | |
988 | \r | |
989 | VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r | |
990 | the caller did not specify the policy or use the default policy. As an example, vendor can implement\r | |
991 | a policy to allow an option to force a firmware image update when the abort reason is due to the new\r | |
992 | firmware image version is older than the current firmware image version or bad image checksum.\r | |
993 | Sensitive operations such as those wiping the entire firmware image and render the device to be\r | |
994 | non-functional should be encoded in the image itself rather than passed with the VendorCode.\r | |
995 | AbortReason enables vendor to have the option to provide a more detailed description of the abort\r | |
996 | reason to the caller.\r | |
997 | \r | |
998 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
999 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
1000 | The number is between 1 and DescriptorCount.\r | |
1001 | @param[in] Image Points to the new image.\r | |
1002 | @param[in] ImageSize Size of the new image in bytes.\r | |
1003 | @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r | |
1004 | Null indicates the caller did not specify the policy or use the default policy.\r | |
1005 | @param[in] Progress A function used by the driver to report the progress of the firmware update.\r | |
1006 | @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r | |
1007 | details for the aborted operation. The buffer is allocated by this function\r | |
1008 | with AllocatePool(), and it is the caller's responsibility to free it with a\r | |
1009 | call to FreePool().\r | |
1010 | \r | |
1011 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
1012 | @retval EFI_ABORTED The operation is aborted.\r | |
1013 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
1014 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
5fc5867e | 1015 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
b0bacc00 KM |
1016 | \r |
1017 | **/\r | |
1018 | EFI_STATUS\r | |
1019 | EFIAPI\r | |
1020 | SetTheImage (\r | |
1021 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
1022 | IN UINT8 ImageIndex,\r | |
1023 | IN CONST VOID *Image,\r | |
1024 | IN UINTN ImageSize,\r | |
1025 | IN CONST VOID *VendorCode,\r | |
1026 | IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r | |
1027 | OUT CHAR16 **AbortReason\r | |
1028 | )\r | |
1029 | {\r | |
4f0544b1 EJ |
1030 | EFI_STATUS Status;\r |
1031 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
1032 | UINT32 Updateable;\r | |
1033 | BOOLEAN BooleanValue;\r | |
1034 | UINT32 FmpHeaderSize;\r | |
1035 | VOID *FmpHeader;\r | |
1036 | UINTN FmpPayloadSize;\r | |
1037 | UINT32 AllHeaderSize;\r | |
95d28836 | 1038 | UINT32 IncomingFwVersion;\r |
4f0544b1 EJ |
1039 | UINT32 LastAttemptStatus;\r |
1040 | UINT32 Version;\r | |
1041 | UINT32 LowestSupportedVersion;\r | |
2ed845b3 WX |
1042 | EFI_FIRMWARE_IMAGE_DEP *Dependencies;\r |
1043 | UINT32 DependenciesSize;\r | |
b0bacc00 KM |
1044 | \r |
1045 | Status = EFI_SUCCESS;\r | |
3633d530 | 1046 | Private = NULL;\r |
b0bacc00 KM |
1047 | Updateable = 0;\r |
1048 | BooleanValue = FALSE;\r | |
1049 | FmpHeaderSize = 0;\r | |
1050 | FmpHeader = NULL;\r | |
1051 | FmpPayloadSize = 0;\r | |
1052 | AllHeaderSize = 0;\r | |
2ed845b3 | 1053 | IncomingFwVersion = 0;\r |
b0bacc00 | 1054 | LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r |
2ed845b3 WX |
1055 | Dependencies = NULL;\r |
1056 | DependenciesSize = 0;\r | |
b0bacc00 | 1057 | \r |
11d35494 EJ |
1058 | if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) {\r |
1059 | return EFI_UNSUPPORTED;\r | |
1060 | }\r | |
1061 | \r | |
b4b9496b MK |
1062 | if (This == NULL) {\r |
1063 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - This is NULL.\n", mImageIdName));\r | |
1064 | Status = EFI_INVALID_PARAMETER;\r | |
1065 | goto cleanup;\r | |
1066 | }\r | |
1067 | \r | |
4f0544b1 EJ |
1068 | //\r |
1069 | // Retrieve the private context structure\r | |
1070 | //\r | |
1071 | Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r | |
1072 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
b0bacc00 | 1073 | \r |
67c1e5ee EJ |
1074 | //\r |
1075 | // Make sure the descriptor has already been loaded or refreshed\r | |
1076 | //\r | |
1077 | PopulateDescriptor (Private);\r | |
1078 | \r | |
1079 | //\r | |
1080 | // Set to 0 to clear any previous results.\r | |
1081 | //\r | |
95d28836 | 1082 | SetLastAttemptVersionInVariable (Private, IncomingFwVersion);\r |
b0bacc00 KM |
1083 | \r |
1084 | //\r | |
1085 | // if we have locked the device, then skip the set operation.\r | |
1086 | // it should be blocked by hardware too but we can catch here even faster\r | |
1087 | //\r | |
4f0544b1 | 1088 | if (Private->FmpDeviceLocked) {\r |
e0961677 | 1089 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Device is already locked. Can't update.\n", mImageIdName));\r |
a4c35479 | 1090 | Status = EFI_UNSUPPORTED;\r |
b0bacc00 KM |
1091 | goto cleanup;\r |
1092 | }\r | |
1093 | \r | |
1094 | //\r | |
1095 | // Call check image to verify the image\r | |
1096 | //\r | |
1097 | Status = CheckTheImage (This, ImageIndex, Image, ImageSize, &Updateable);\r | |
1098 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1099 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Check The Image failed with %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1100 | if (Status == EFI_SECURITY_VIOLATION) {\r |
1101 | LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;\r | |
1102 | }\r | |
1103 | goto cleanup;\r | |
1104 | }\r | |
1105 | \r | |
0f30087b WX |
1106 | //\r |
1107 | // Get the dependency from Image.\r | |
1108 | //\r | |
1109 | Dependencies = GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, &DependenciesSize);\r | |
1110 | \r | |
b0bacc00 KM |
1111 | //\r |
1112 | // No functional error in CheckTheImage. Attempt to get the Version to\r | |
1113 | // support better error reporting.\r | |
1114 | //\r | |
0f30087b | 1115 | FmpHeader = GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, DependenciesSize, &FmpPayloadSize );\r |
b0bacc00 | 1116 | if (FmpHeader == NULL) {\r |
e0961677 | 1117 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetFmpHeader failed.\n", mImageIdName));\r |
b0bacc00 KM |
1118 | Status = EFI_ABORTED;\r |
1119 | goto cleanup;\r | |
1120 | }\r | |
95d28836 | 1121 | Status = GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &IncomingFwVersion);\r |
b0bacc00 KM |
1122 | if (!EFI_ERROR (Status)) {\r |
1123 | //\r | |
1124 | // Set to actual value\r | |
1125 | //\r | |
95d28836 | 1126 | SetLastAttemptVersionInVariable (Private, IncomingFwVersion);\r |
b0bacc00 KM |
1127 | }\r |
1128 | \r | |
1129 | \r | |
1130 | if (Updateable != IMAGE_UPDATABLE_VALID) {\r | |
1131 | DEBUG (\r | |
1132 | (DEBUG_ERROR,\r | |
e0961677 EJ |
1133 | "FmpDxe(%s): SetTheImage() - Check The Image returned that the Image was not valid for update. Updatable value = 0x%X.\n",\r |
1134 | mImageIdName, Updateable)\r | |
b0bacc00 | 1135 | );\r |
0f30087b | 1136 | if (Private->DependenciesSatisfied == FALSE) {\r |
2ed845b3 | 1137 | LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES;\r |
2ed845b3 | 1138 | }\r |
b0bacc00 KM |
1139 | Status = EFI_ABORTED;\r |
1140 | goto cleanup;\r | |
1141 | }\r | |
1142 | \r | |
1143 | if (Progress == NULL) {\r | |
e0961677 | 1144 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Invalid progress callback\n", mImageIdName));\r |
b0bacc00 KM |
1145 | Status = EFI_INVALID_PARAMETER;\r |
1146 | goto cleanup;\r | |
1147 | }\r | |
1148 | \r | |
1149 | mProgressFunc = Progress;\r | |
b0bacc00 KM |
1150 | \r |
1151 | //\r | |
1152 | // Checking the image is at least 1%\r | |
1153 | //\r | |
1154 | Status = Progress (1);\r | |
1155 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1156 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Progress Callback failed with Status %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1157 | }\r |
1158 | \r | |
1159 | //\r | |
1160 | //Check System Power\r | |
1161 | //\r | |
1162 | Status = CheckSystemPower (&BooleanValue);\r | |
1163 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1164 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemPower - API call failed %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1165 | goto cleanup;\r |
1166 | }\r | |
1167 | if (!BooleanValue) {\r | |
1168 | Status = EFI_ABORTED;\r | |
1169 | DEBUG (\r | |
1170 | (DEBUG_ERROR,\r | |
e0961677 | 1171 | "FmpDxe(%s): SetTheImage() - CheckSystemPower - returned False. Update not allowed due to System Power.\n", mImageIdName)\r |
b0bacc00 KM |
1172 | );\r |
1173 | LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT;\r | |
1174 | goto cleanup;\r | |
1175 | }\r | |
1176 | \r | |
1177 | Progress (2);\r | |
1178 | \r | |
1179 | //\r | |
1180 | //Check System Thermal\r | |
1181 | //\r | |
1182 | Status = CheckSystemThermal (&BooleanValue);\r | |
1183 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1184 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemThermal - API call failed %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1185 | goto cleanup;\r |
1186 | }\r | |
1187 | if (!BooleanValue) {\r | |
1188 | Status = EFI_ABORTED;\r | |
1189 | DEBUG (\r | |
1190 | (DEBUG_ERROR,\r | |
e0961677 | 1191 | "FmpDxe(%s): SetTheImage() - CheckSystemThermal - returned False. Update not allowed due to System Thermal.\n", mImageIdName)\r |
b0bacc00 KM |
1192 | );\r |
1193 | goto cleanup;\r | |
1194 | }\r | |
1195 | \r | |
1196 | Progress (3);\r | |
1197 | \r | |
1198 | //\r | |
1199 | //Check System Environment\r | |
1200 | //\r | |
1201 | Status = CheckSystemEnvironment (&BooleanValue);\r | |
1202 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1203 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemEnvironment - API call failed %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1204 | goto cleanup;\r |
1205 | }\r | |
1206 | if (!BooleanValue) {\r | |
1207 | Status = EFI_ABORTED;\r | |
1208 | DEBUG (\r | |
1209 | (DEBUG_ERROR,\r | |
e0961677 | 1210 | "FmpDxe(%s): SetTheImage() - CheckSystemEnvironment - returned False. Update not allowed due to System Environment.\n", mImageIdName)\r |
b0bacc00 KM |
1211 | );\r |
1212 | goto cleanup;\r | |
1213 | }\r | |
1214 | \r | |
1215 | Progress (4);\r | |
1216 | \r | |
1217 | //\r | |
1218 | // Save LastAttemptStatus as error so that if SetImage never returns the error\r | |
1219 | // state is recorded.\r | |
1220 | //\r | |
67c1e5ee | 1221 | SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r |
b0bacc00 KM |
1222 | \r |
1223 | //\r | |
1224 | // Strip off all the headers so the device can process its firmware\r | |
1225 | //\r | |
1226 | Status = GetFmpPayloadHeaderSize (FmpHeader, FmpPayloadSize, &FmpHeaderSize);\r | |
1227 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1228 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetFmpPayloadHeaderSize failed %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1229 | goto cleanup;\r |
1230 | }\r | |
1231 | \r | |
2ed845b3 | 1232 | AllHeaderSize = GetAllHeaderSize ((EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, FmpHeaderSize + DependenciesSize);\r |
b0bacc00 | 1233 | if (AllHeaderSize == 0) {\r |
e0961677 | 1234 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetAllHeaderSize failed.\n", mImageIdName));\r |
b0bacc00 KM |
1235 | Status = EFI_ABORTED;\r |
1236 | goto cleanup;\r | |
1237 | }\r | |
1238 | \r | |
1239 | //\r | |
1240 | // Indicate that control is handed off to FmpDeviceLib\r | |
1241 | //\r | |
1242 | Progress (5);\r | |
1243 | \r | |
1244 | //\r | |
1245 | //Copy the requested image to the firmware using the FmpDeviceLib\r | |
1246 | //\r | |
1247 | Status = FmpDeviceSetImage (\r | |
0f30087b WX |
1248 | (((UINT8 *)Image) + AllHeaderSize),\r |
1249 | ImageSize - AllHeaderSize,\r | |
b0bacc00 KM |
1250 | VendorCode,\r |
1251 | FmpDxeProgress,\r | |
95d28836 | 1252 | IncomingFwVersion,\r |
b0bacc00 KM |
1253 | AbortReason\r |
1254 | );\r | |
1255 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1256 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SetImage from FmpDeviceLib failed. Status = %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1257 | goto cleanup;\r |
1258 | }\r | |
1259 | \r | |
0f30087b WX |
1260 | //\r |
1261 | // Store the dependency\r | |
1262 | //\r | |
1263 | if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) {\r | |
1264 | Status = SaveFmpDependency (Dependencies, DependenciesSize);\r | |
1265 | if (EFI_ERROR (Status)) {\r | |
1266 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SaveFmpDependency from FmpDependencyCheckLib failed. (%r)\n", mImageIdName, Status));\r | |
1267 | }\r | |
1268 | Status = EFI_SUCCESS;\r | |
1269 | }\r | |
b0bacc00 KM |
1270 | \r |
1271 | //\r | |
1272 | // Finished the update without error\r | |
1273 | // Indicate that control has been returned from FmpDeviceLib\r | |
1274 | //\r | |
1275 | Progress (99);\r | |
1276 | \r | |
1277 | //\r | |
1278 | // Update the version stored in variable\r | |
1279 | //\r | |
4f0544b1 | 1280 | if (!Private->RuntimeVersionSupported) {\r |
a6d73269 | 1281 | Version = DEFAULT_VERSION;\r |
b0bacc00 | 1282 | GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &Version);\r |
67c1e5ee | 1283 | SetVersionInVariable (Private, Version);\r |
b0bacc00 KM |
1284 | }\r |
1285 | \r | |
1286 | //\r | |
1287 | // Update lowest supported variable\r | |
1288 | //\r | |
67c1e5ee EJ |
1289 | LowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r |
1290 | GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &LowestSupportedVersion);\r | |
1291 | SetLowestSupportedVersionInVariable (Private, LowestSupportedVersion);\r | |
b0bacc00 KM |
1292 | \r |
1293 | LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r | |
1294 | \r | |
b0bacc00 KM |
1295 | cleanup:\r |
1296 | mProgressFunc = NULL;\r | |
3633d530 MK |
1297 | \r |
1298 | if (Private != NULL) {\r | |
1299 | SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r | |
1300 | }\r | |
b0bacc00 | 1301 | \r |
c6c18d87 SZ |
1302 | if (Progress != NULL) {\r |
1303 | //\r | |
1304 | // Set progress to 100 after everything is done including recording Status.\r | |
1305 | //\r | |
1306 | Progress (100);\r | |
1307 | }\r | |
b0bacc00 | 1308 | \r |
27e42bf6 SZ |
1309 | //\r |
1310 | // Need repopulate after SetImage is called to\r | |
1311 | // update LastAttemptVersion and LastAttemptStatus.\r | |
1312 | //\r | |
3633d530 MK |
1313 | if (Private != NULL) {\r |
1314 | Private->DescriptorPopulated = FALSE;\r | |
1315 | }\r | |
27e42bf6 | 1316 | \r |
b0bacc00 KM |
1317 | return Status;\r |
1318 | }\r | |
1319 | \r | |
1320 | /**\r | |
1321 | Returns information about the firmware package.\r | |
1322 | \r | |
1323 | This function returns package information.\r | |
1324 | \r | |
1325 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
1326 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
1327 | The format is vendor specific and new version must have a greater value\r | |
1328 | than the old version. If PackageVersion is not supported, the value is\r | |
1329 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r | |
1330 | comparison is to be performed using PackageVersionName. A value of\r | |
1331 | 0xFFFFFFFD indicates that package version update is in progress.\r | |
1332 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r | |
1333 | the package version name. The buffer is allocated by this function with\r | |
1334 | AllocatePool(), and it is the caller's responsibility to free it with a\r | |
1335 | call to FreePool().\r | |
1336 | @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r | |
1337 | package version name. A value of 0 indicates the device does not support\r | |
1338 | update of package version name. Length is the number of Unicode characters,\r | |
1339 | including the terminating null character.\r | |
1340 | @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r | |
1341 | Definitions' for possible returned values of this parameter. A value of 1\r | |
1342 | indicates the attribute is supported and the current setting value is\r | |
1343 | indicated in AttributesSetting. A value of 0 indicates the attribute is not\r | |
1344 | supported and the current setting value in AttributesSetting is meaningless.\r | |
1345 | @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r | |
1346 | values of this parameter\r | |
1347 | \r | |
1348 | @retval EFI_SUCCESS The package information was successfully returned.\r | |
1349 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
1350 | \r | |
1351 | **/\r | |
1352 | EFI_STATUS\r | |
1353 | EFIAPI\r | |
1354 | GetPackageInfo (\r | |
1355 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
1356 | OUT UINT32 *PackageVersion,\r | |
1357 | OUT CHAR16 **PackageVersionName,\r | |
1358 | OUT UINT32 *PackageVersionNameMaxLen,\r | |
1359 | OUT UINT64 *AttributesSupported,\r | |
1360 | OUT UINT64 *AttributesSetting\r | |
1361 | )\r | |
1362 | {\r | |
1363 | return EFI_UNSUPPORTED;\r | |
1364 | }\r | |
1365 | \r | |
1366 | /**\r | |
1367 | Updates information about the firmware package.\r | |
1368 | \r | |
1369 | This function updates package information.\r | |
1370 | This function returns EFI_UNSUPPORTED if the package information is not updatable.\r | |
1371 | VendorCode enables vendor to implement vendor-specific package information update policy.\r | |
1372 | Null if the caller did not specify this policy or use the default policy.\r | |
1373 | \r | |
1374 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
1375 | @param[in] Image Points to the authentication image.\r | |
1376 | Null if authentication is not required.\r | |
1377 | @param[in] ImageSize Size of the authentication image in bytes.\r | |
1378 | 0 if authentication is not required.\r | |
1379 | @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r | |
1380 | image update policy.\r | |
1381 | Null indicates the caller did not specify this policy or use\r | |
1382 | the default policy.\r | |
1383 | @param[in] PackageVersion The new package version.\r | |
1384 | @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r | |
1385 | the package version name.\r | |
1386 | The string length is equal to or less than the value returned in\r | |
1387 | PackageVersionNameMaxLen.\r | |
1388 | \r | |
1389 | @retval EFI_SUCCESS The device was successfully updated with the new package\r | |
1390 | information.\r | |
1391 | @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r | |
1392 | returned in PackageVersionNameMaxLen.\r | |
1393 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
5fc5867e | 1394 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
b0bacc00 KM |
1395 | \r |
1396 | **/\r | |
1397 | EFI_STATUS\r | |
1398 | EFIAPI\r | |
1399 | SetPackageInfo (\r | |
1400 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
1401 | IN CONST VOID *Image,\r | |
1402 | IN UINTN ImageSize,\r | |
1403 | IN CONST VOID *VendorCode,\r | |
1404 | IN UINT32 PackageVersion,\r | |
1405 | IN CONST CHAR16 *PackageVersionName\r | |
1406 | )\r | |
1407 | {\r | |
1408 | return EFI_UNSUPPORTED;\r | |
1409 | }\r | |
1410 | \r | |
1411 | /**\r | |
1412 | Event notification function that is invoked when the event GUID specified by\r | |
1413 | PcdFmpDeviceLockEventGuid is signaled.\r | |
1414 | \r | |
1415 | @param[in] Event Event whose notification function is being invoked.\r | |
1416 | @param[in] Context The pointer to the notification function's context,\r | |
1417 | which is implementation-dependent.\r | |
1418 | **/\r | |
1419 | VOID\r | |
1420 | EFIAPI\r | |
1421 | FmpDxeLockEventNotify (\r | |
1422 | IN EFI_EVENT Event,\r | |
1423 | IN VOID *Context\r | |
1424 | )\r | |
1425 | {\r | |
4f0544b1 EJ |
1426 | EFI_STATUS Status;\r |
1427 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
1428 | \r | |
b4b9496b MK |
1429 | if (Context == NULL) {\r |
1430 | ASSERT (Context != NULL);\r | |
1431 | return;\r | |
1432 | }\r | |
1433 | \r | |
4f0544b1 | 1434 | Private = (FIRMWARE_MANAGEMENT_PRIVATE_DATA *)Context;\r |
b0bacc00 | 1435 | \r |
4f0544b1 | 1436 | if (!Private->FmpDeviceLocked) {\r |
9e6c4f15 SZ |
1437 | //\r |
1438 | // Lock the firmware device\r | |
1439 | //\r | |
4f0544b1 | 1440 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r |
9e6c4f15 SZ |
1441 | Status = FmpDeviceLock();\r |
1442 | if (EFI_ERROR (Status)) {\r | |
1443 | if (Status != EFI_UNSUPPORTED) {\r | |
e0961677 | 1444 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLock() returned error. Status = %r\n", mImageIdName, Status));\r |
b0bacc00 | 1445 | } else {\r |
e0961677 | 1446 | DEBUG ((DEBUG_WARN, "FmpDxe(%s): FmpDeviceLock() returned error. Status = %r\n", mImageIdName, Status));\r |
b0bacc00 | 1447 | }\r |
b0bacc00 | 1448 | }\r |
4f0544b1 | 1449 | Private->FmpDeviceLocked = TRUE;\r |
b0bacc00 KM |
1450 | }\r |
1451 | }\r | |
1452 | \r | |
1453 | /**\r | |
1454 | Function to install FMP instance.\r | |
1455 | \r | |
1456 | @param[in] Handle The device handle to install a FMP instance on.\r | |
1457 | \r | |
1458 | @retval EFI_SUCCESS FMP Installed\r | |
1459 | @retval EFI_INVALID_PARAMETER Handle was invalid\r | |
1460 | @retval other Error installing FMP\r | |
1461 | \r | |
1462 | **/\r | |
1463 | EFI_STATUS\r | |
1464 | EFIAPI\r | |
1465 | InstallFmpInstance (\r | |
1466 | IN EFI_HANDLE Handle\r | |
1467 | )\r | |
1468 | {\r | |
4f0544b1 EJ |
1469 | EFI_STATUS Status;\r |
1470 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;\r | |
1471 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
b0bacc00 | 1472 | \r |
b0bacc00 KM |
1473 | //\r |
1474 | // Only allow a single FMP Protocol instance to be installed\r | |
1475 | //\r | |
4f0544b1 EJ |
1476 | Status = gBS->OpenProtocol (\r |
1477 | Handle,\r | |
1478 | &gEfiFirmwareManagementProtocolGuid,\r | |
1479 | (VOID **)&Fmp,\r | |
1480 | NULL,\r | |
1481 | NULL,\r | |
1482 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1483 | );\r | |
1484 | if (!EFI_ERROR (Status)) {\r | |
b0bacc00 KM |
1485 | return EFI_ALREADY_STARTED;\r |
1486 | }\r | |
1487 | \r | |
1488 | //\r | |
1489 | // Allocate FMP Protocol instance\r | |
1490 | //\r | |
4f0544b1 EJ |
1491 | Private = AllocateCopyPool (\r |
1492 | sizeof (mFirmwareManagementPrivateDataTemplate),\r | |
1493 | &mFirmwareManagementPrivateDataTemplate\r | |
1494 | );\r | |
1495 | if (Private == NULL) {\r | |
e0961677 | 1496 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to allocate memory for private structure.\n", mImageIdName));\r |
b0bacc00 KM |
1497 | Status = EFI_OUT_OF_RESOURCES;\r |
1498 | goto cleanup;\r | |
1499 | }\r | |
1500 | \r | |
1501 | //\r | |
4f0544b1 | 1502 | // Initialize private context data structure\r |
b0bacc00 | 1503 | //\r |
4f0544b1 | 1504 | Private->Handle = Handle;\r |
4f0544b1 EJ |
1505 | Private->FmpDeviceContext = NULL;\r |
1506 | Status = FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
1507 | if (Status == EFI_UNSUPPORTED) {\r | |
1508 | Private->FmpDeviceContext = NULL;\r | |
1509 | } else if (EFI_ERROR (Status)) {\r | |
b0bacc00 KM |
1510 | goto cleanup;\r |
1511 | }\r | |
1512 | \r | |
67c1e5ee EJ |
1513 | //\r |
1514 | // Make sure the descriptor has already been loaded or refreshed\r | |
1515 | //\r | |
1516 | PopulateDescriptor (Private);\r | |
1517 | \r | |
4f0544b1 EJ |
1518 | if (IsLockFmpDeviceAtLockEventGuidRequired ()) {\r |
1519 | //\r | |
e0961677 | 1520 | // Register all UEFI Variables used by this module to be locked.\r |
4f0544b1 | 1521 | //\r |
67c1e5ee | 1522 | Status = LockAllFmpVariables (Private);\r |
4f0544b1 | 1523 | if (EFI_ERROR (Status)) {\r |
e0961677 | 1524 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to register variables to lock. Status = %r.\n", mImageIdName, Status));\r |
4f0544b1 | 1525 | } else {\r |
e0961677 | 1526 | DEBUG ((DEBUG_INFO, "FmpDxe(%s): All variables registered to lock\n", mImageIdName));\r |
4f0544b1 EJ |
1527 | }\r |
1528 | \r | |
1529 | //\r | |
1530 | // Create and register notify function to lock the FMP device.\r | |
1531 | //\r | |
1532 | Status = gBS->CreateEventEx (\r | |
1533 | EVT_NOTIFY_SIGNAL,\r | |
1534 | TPL_CALLBACK,\r | |
1535 | FmpDxeLockEventNotify,\r | |
1536 | Private,\r | |
1537 | mLockGuid,\r | |
1538 | &Private->FmpDeviceLockEvent\r | |
1539 | );\r | |
1540 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1541 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to register notification. Status = %r\n", mImageIdName, Status));\r |
4f0544b1 EJ |
1542 | }\r |
1543 | ASSERT_EFI_ERROR (Status);\r | |
1544 | } else {\r | |
e0961677 | 1545 | DEBUG ((DEBUG_VERBOSE, "FmpDxe(%s): Not registering notification to call FmpDeviceLock() because mfg mode\n", mImageIdName));\r |
4f0544b1 | 1546 | }\r |
b0bacc00 KM |
1547 | \r |
1548 | //\r | |
1549 | // Install FMP Protocol and FMP Progress Protocol\r | |
1550 | //\r | |
1551 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
4f0544b1 EJ |
1552 | &Private->Handle,\r |
1553 | &gEfiFirmwareManagementProtocolGuid, &Private->Fmp,\r | |
1554 | &gEdkiiFirmwareManagementProgressProtocolGuid, &mFmpProgress,\r | |
b0bacc00 KM |
1555 | NULL\r |
1556 | );\r | |
b0bacc00 | 1557 | if (EFI_ERROR (Status)) {\r |
e0961677 | 1558 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol install error. Status = %r.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1559 | goto cleanup;\r |
1560 | }\r | |
1561 | \r | |
b0bacc00 KM |
1562 | cleanup:\r |
1563 | \r | |
4f0544b1 EJ |
1564 | if (EFI_ERROR (Status)) {\r |
1565 | if (Private != NULL) {\r | |
1566 | if (Private->FmpDeviceLockEvent != NULL) {\r | |
1567 | gBS->CloseEvent (Private->FmpDeviceLockEvent);\r | |
1568 | }\r | |
67c1e5ee EJ |
1569 | if (Private->Descriptor.VersionName != NULL) {\r |
1570 | FreePool (Private->Descriptor.VersionName);\r | |
1571 | }\r | |
1572 | if (Private->FmpDeviceContext != NULL) {\r | |
1573 | FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r | |
1574 | }\r | |
1575 | if (Private->VersionVariableName != NULL) {\r | |
1576 | FreePool (Private->VersionVariableName);\r | |
1577 | }\r | |
1578 | if (Private->LsvVariableName != NULL) {\r | |
1579 | FreePool (Private->LsvVariableName);\r | |
1580 | }\r | |
1581 | if (Private->LastAttemptStatusVariableName != NULL) {\r | |
1582 | FreePool (Private->LastAttemptStatusVariableName);\r | |
1583 | }\r | |
1584 | if (Private->LastAttemptVersionVariableName != NULL) {\r | |
1585 | FreePool (Private->LastAttemptVersionVariableName);\r | |
1586 | }\r | |
1587 | if (Private->FmpStateVariableName != NULL) {\r | |
1588 | FreePool (Private->FmpStateVariableName);\r | |
1589 | }\r | |
4f0544b1 EJ |
1590 | FreePool (Private);\r |
1591 | }\r | |
1592 | }\r | |
1593 | \r | |
b0bacc00 KM |
1594 | return Status;\r |
1595 | }\r | |
1596 | \r | |
4f0544b1 EJ |
1597 | /**\r |
1598 | Function to uninstall FMP instance.\r | |
1599 | \r | |
1600 | @param[in] Handle The device handle to install a FMP instance on.\r | |
1601 | \r | |
1602 | @retval EFI_SUCCESS FMP Installed\r | |
1603 | @retval EFI_INVALID_PARAMETER Handle was invalid\r | |
1604 | @retval other Error installing FMP\r | |
1605 | \r | |
1606 | **/\r | |
1607 | EFI_STATUS\r | |
1608 | EFIAPI\r | |
1609 | UninstallFmpInstance (\r | |
1610 | IN EFI_HANDLE Handle\r | |
1611 | )\r | |
1612 | {\r | |
1613 | EFI_STATUS Status;\r | |
1614 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;\r | |
1615 | FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r | |
1616 | \r | |
1617 | Status = gBS->OpenProtocol (\r | |
1618 | Handle,\r | |
1619 | &gEfiFirmwareManagementProtocolGuid,\r | |
1620 | (VOID **)&Fmp,\r | |
1621 | NULL,\r | |
1622 | NULL,\r | |
1623 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1624 | );\r | |
1625 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1626 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol open error. Status = %r.\n", mImageIdName, Status));\r |
4f0544b1 EJ |
1627 | return Status;\r |
1628 | }\r | |
1629 | \r | |
1630 | Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (Fmp);\r | |
1631 | FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r | |
1632 | \r | |
1633 | if (Private->FmpDeviceLockEvent != NULL) {\r | |
1634 | gBS->CloseEvent (Private->FmpDeviceLockEvent);\r | |
1635 | }\r | |
1636 | \r | |
1637 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
1638 | Private->Handle,\r | |
1639 | &gEfiFirmwareManagementProtocolGuid, &Private->Fmp,\r | |
1640 | &gEdkiiFirmwareManagementProgressProtocolGuid, &mFmpProgress,\r | |
1641 | NULL\r | |
1642 | );\r | |
1643 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1644 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol uninstall error. Status = %r.\n", mImageIdName, Status));\r |
4f0544b1 EJ |
1645 | return Status;\r |
1646 | }\r | |
1647 | \r | |
67c1e5ee EJ |
1648 | if (Private->Descriptor.VersionName != NULL) {\r |
1649 | FreePool (Private->Descriptor.VersionName);\r | |
1650 | }\r | |
1651 | if (Private->FmpDeviceContext != NULL) {\r | |
1652 | FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r | |
1653 | }\r | |
1654 | if (Private->VersionVariableName != NULL) {\r | |
1655 | FreePool (Private->VersionVariableName);\r | |
1656 | }\r | |
1657 | if (Private->LsvVariableName != NULL) {\r | |
1658 | FreePool (Private->LsvVariableName);\r | |
1659 | }\r | |
1660 | if (Private->LastAttemptStatusVariableName != NULL) {\r | |
1661 | FreePool (Private->LastAttemptStatusVariableName);\r | |
1662 | }\r | |
1663 | if (Private->LastAttemptVersionVariableName != NULL) {\r | |
1664 | FreePool (Private->LastAttemptVersionVariableName);\r | |
1665 | }\r | |
1666 | if (Private->FmpStateVariableName != NULL) {\r | |
1667 | FreePool (Private->FmpStateVariableName);\r | |
1668 | }\r | |
4f0544b1 EJ |
1669 | FreePool (Private);\r |
1670 | \r | |
1671 | return EFI_SUCCESS;\r | |
1672 | }\r | |
1673 | \r | |
1674 | /**\r | |
1675 | Unloads the application and its installed protocol.\r | |
1676 | \r | |
1677 | @param ImageHandle Handle that identifies the image to be unloaded.\r | |
1678 | @param SystemTable The system table.\r | |
1679 | \r | |
1680 | @retval EFI_SUCCESS The image has been unloaded.\r | |
1681 | \r | |
1682 | **/\r | |
1683 | EFI_STATUS\r | |
1684 | EFIAPI\r | |
1685 | FmpDxeLibDestructor (\r | |
1686 | IN EFI_HANDLE ImageHandle,\r | |
1687 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1688 | )\r | |
1689 | {\r | |
1690 | if (mFmpSingleInstance) {\r | |
1691 | return UninstallFmpInstance (ImageHandle);\r | |
1692 | }\r | |
1693 | return EFI_SUCCESS;\r | |
1694 | }\r | |
1695 | \r | |
b0bacc00 | 1696 | /**\r |
e8619f82 | 1697 | Main entry for this driver/library.\r |
b0bacc00 KM |
1698 | \r |
1699 | @param[in] ImageHandle Image handle this driver.\r | |
1700 | @param[in] SystemTable Pointer to SystemTable.\r | |
1701 | \r | |
1702 | **/\r | |
1703 | EFI_STATUS\r | |
1704 | EFIAPI\r | |
1705 | FmpDxeEntryPoint (\r | |
1706 | IN EFI_HANDLE ImageHandle,\r | |
1707 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1708 | )\r | |
1709 | {\r | |
1710 | EFI_STATUS Status;\r | |
b0bacc00 KM |
1711 | \r |
1712 | //\r | |
1713 | // Verify that a new FILE_GUID value has been provided in the <Defines>\r | |
1714 | // section of this module. The FILE_GUID is the ESRT GUID that must be\r | |
1715 | // unique for each updatable firmware image.\r | |
1716 | //\r | |
1717 | if (CompareGuid (&mDefaultModuleFileGuid, &gEfiCallerIdGuid)) {\r | |
1718 | DEBUG ((DEBUG_ERROR, "FmpDxe: Use of default FILE_GUID detected. FILE_GUID must be set to a unique value.\n"));\r | |
1719 | ASSERT (FALSE);\r | |
1720 | return EFI_UNSUPPORTED;\r | |
1721 | }\r | |
1722 | \r | |
1723 | //\r | |
1724 | // Get the ImageIdName value for the EFI_FIRMWARE_IMAGE_DESCRIPTOR from a PCD.\r | |
1725 | //\r | |
1726 | mImageIdName = (CHAR16 *) PcdGetPtr (PcdFmpDeviceImageIdName);\r | |
1727 | if (PcdGetSize (PcdFmpDeviceImageIdName) <= 2 || mImageIdName[0] == 0) {\r | |
1728 | //\r | |
1729 | // PcdFmpDeviceImageIdName must be set to a non-empty Unicode string\r | |
1730 | //\r | |
c9fa9762 | 1731 | DEBUG ((DEBUG_ERROR, "FmpDxe(%g): PcdFmpDeviceImageIdName is an empty string.\n", &gEfiCallerIdGuid));\r |
b0bacc00 | 1732 | ASSERT (FALSE);\r |
e0961677 | 1733 | return EFI_UNSUPPORTED;\r |
b0bacc00 KM |
1734 | }\r |
1735 | \r | |
1736 | //\r | |
1737 | // Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.\r | |
1738 | //\r | |
1739 | DetectTestKey ();\r | |
1740 | \r | |
4f0544b1 EJ |
1741 | //\r |
1742 | // Fill in FMP Progress Protocol fields for Version 1\r | |
1743 | //\r | |
1744 | mFmpProgress.Version = 1;\r | |
1745 | mFmpProgress.ProgressBarForegroundColor.Raw = PcdGet32 (PcdFmpDeviceProgressColor);\r | |
1746 | mFmpProgress.WatchdogSeconds = PcdGet8 (PcdFmpDeviceProgressWatchdogTimeInSeconds);\r | |
9e6c4f15 | 1747 | \r |
4f0544b1 EJ |
1748 | // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.\r |
1749 | // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then\r | |
1750 | // gEfiEndOfDxeEventGroupGuid is used.\r | |
1751 | //\r | |
1752 | mLockGuid = &gEfiEndOfDxeEventGroupGuid;\r | |
1753 | if (PcdGetSize (PcdFmpDeviceLockEventGuid) == sizeof (EFI_GUID)) {\r | |
1754 | mLockGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceLockEventGuid);\r | |
9e6c4f15 | 1755 | }\r |
e0961677 | 1756 | DEBUG ((DEBUG_INFO, "FmpDxe(%s): Lock GUID: %g\n", mImageIdName, mLockGuid));\r |
9e6c4f15 | 1757 | \r |
b0bacc00 KM |
1758 | //\r |
1759 | // Register with library the install function so if the library uses\r | |
1760 | // UEFI driver model/driver binding protocol it can install FMP on its device handle\r | |
1761 | // If library is simple lib that does not use driver binding then it should return\r | |
1762 | // unsupported and this will install the FMP instance on the ImageHandle\r | |
1763 | //\r | |
1764 | Status = RegisterFmpInstaller (InstallFmpInstance);\r | |
1765 | if (Status == EFI_UNSUPPORTED) {\r | |
4f0544b1 | 1766 | mFmpSingleInstance = TRUE;\r |
e0961677 | 1767 | DEBUG ((DEBUG_INFO, "FmpDxe(%s): FmpDeviceLib registration returned EFI_UNSUPPORTED. Installing single FMP instance.\n", mImageIdName));\r |
4f0544b1 EJ |
1768 | Status = RegisterFmpUninstaller (UninstallFmpInstance);\r |
1769 | if (Status == EFI_UNSUPPORTED) {\r | |
1770 | Status = InstallFmpInstance (ImageHandle);\r | |
1771 | } else {\r | |
e0961677 | 1772 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n", mImageIdName));\r |
4f0544b1 EJ |
1773 | Status = EFI_UNSUPPORTED;\r |
1774 | }\r | |
b0bacc00 | 1775 | } else if (EFI_ERROR (Status)) {\r |
e0961677 | 1776 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib registration returned %r. No FMP installed.\n", mImageIdName, Status));\r |
b0bacc00 KM |
1777 | } else {\r |
1778 | DEBUG ((\r | |
1779 | DEBUG_INFO,\r | |
e0961677 EJ |
1780 | "FmpDxe(%s): FmpDeviceLib registration returned EFI_SUCCESS. Expect FMP to be installed during the BDS/Device connection phase.\n",\r |
1781 | mImageIdName\r | |
b0bacc00 | 1782 | ));\r |
4f0544b1 EJ |
1783 | Status = RegisterFmpUninstaller (UninstallFmpInstance);\r |
1784 | if (EFI_ERROR (Status)) {\r | |
e0961677 | 1785 | DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n", mImageIdName));\r |
4f0544b1 | 1786 | }\r |
b0bacc00 KM |
1787 | }\r |
1788 | \r | |
b0bacc00 KM |
1789 | return Status;\r |
1790 | }\r |