]> git.proxmox.com Git - mirror_edk2.git/blame - FmpDevicePkg/FmpDxe/FmpDxe.c
FmpDevicePkg: Add Last Attempt Status support to dependency libs
[mirror_edk2.git] / FmpDevicePkg / FmpDxe / FmpDxe.c
CommitLineData
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
23const 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 30BOOLEAN 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
36EDKII_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
42const 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
90EFI_GUID *mLockGuid = NULL;\r
91\r
92///\r
93/// Progress() function pointer passed into SetTheImage()\r
94///\r
95EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS mProgressFunc = NULL;\r
96\r
97///\r
98/// Null-terminated Unicode string retrieved from PcdFmpDeviceImageIdName.\r
99///\r
100CHAR16 *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
122EFI_STATUS\r
123EFIAPI\r
124FmpDxeProgress (\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
158EFI_GUID *\r
159GetImageTypeIdGuid (\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
195CHAR16 *\r
196GetImageTypeNameString (\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
215UINT32\r
216GetLowestSupportedVersion (\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
273VOID\r
274PopulateDescriptor (\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
441EFI_STATUS\r
442EFIAPI\r
443GetTheImageInfo (\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
528cleanup:\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
556EFI_STATUS\r
557EFIAPI\r
558GetTheImage (\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
623cleanup:\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
642VOID *\r
643GetFmpHeader (\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
679UINT32\r
680GetAllHeaderSize (\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
5550f4d3
MK
724 @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt status to report\r
725 back to the ESRT table in case of error. If an error does not occur,\r
726 this function will set the value to LAST_ATTEMPT_STATUS_SUCCESS.\r
727\r
728 This function will return error codes that occur within this function\r
729 implementation within a driver range of last attempt error codes from\r
730 LAST_ATTEMPT_STATUS_DRIVER_MIN_ERROR_CODE_VALUE\r
731 to LAST_ATTEMPT_STATUS_DRIVER_MAX_ERROR_CODE_VALUE.\r
b0bacc00 732\r
207414cb
MK
733 This function might also return error codes that occur within libraries\r
734 linked against this module that return last attempt error codes such as:\r
735\r
736 LAST_ATTEMPT_STATUS_FMP_DEPENDENCY_LIB_MIN_ERROR_CODE_VALUE to\r
737 LAST_ATTEMPT_STATUS_FMP_DEPENDENCY_LIB_MAX_ERROR_CODE_VALUE\r
738\r
739 LAST_ATTEMPT_STATUS_FMP_DEPENDENCY_CHECK_LIB_MIN_ERROR_CODE_VALUE to\r
740 LAST_ATTEMPT_STATUS_FMP_DEPENDENCY_CHECK_LIB_MAX_ERROR_CODE_VALUE\r
741\r
b0bacc00 742 @retval EFI_SUCCESS The image was successfully checked.\r
4e61b8d0 743 @retval EFI_ABORTED The operation is aborted.\r
b0bacc00
KM
744 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
745 @retval EFI_UNSUPPORTED The operation is not supported.\r
5fc5867e 746 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
b0bacc00
KM
747\r
748**/\r
749EFI_STATUS\r
750EFIAPI\r
5550f4d3 751CheckTheImageInternal (\r
b0bacc00
KM
752 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
753 IN UINT8 ImageIndex,\r
754 IN CONST VOID *Image,\r
755 IN UINTN ImageSize,\r
5550f4d3
MK
756 OUT UINT32 *ImageUpdatable,\r
757 OUT UINT32 *LastAttemptStatus\r
b0bacc00
KM
758 )\r
759{\r
4f0544b1 760 EFI_STATUS Status;\r
5550f4d3 761 UINT32 LocalLastAttemptStatus;\r
4f0544b1
EJ
762 FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r
763 UINTN RawSize;\r
764 VOID *FmpPayloadHeader;\r
765 UINTN FmpPayloadSize;\r
766 UINT32 Version;\r
767 UINT32 FmpHeaderSize;\r
768 UINTN AllHeaderSize;\r
769 UINT32 Index;\r
770 VOID *PublicKeyData;\r
771 UINTN PublicKeyDataLength;\r
772 UINT8 *PublicKeyDataXdr;\r
773 UINT8 *PublicKeyDataXdrEnd;\r
2ed845b3
WX
774 EFI_FIRMWARE_IMAGE_DEP *Dependencies;\r
775 UINT32 DependenciesSize;\r
b0bacc00 776\r
5550f4d3
MK
777 Status = EFI_SUCCESS;\r
778 LocalLastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
779 RawSize = 0;\r
780 FmpPayloadHeader = NULL;\r
781 FmpPayloadSize = 0;\r
782 Version = 0;\r
783 FmpHeaderSize = 0;\r
784 AllHeaderSize = 0;\r
785 Dependencies = NULL;\r
786 DependenciesSize = 0;\r
b0bacc00 787\r
11d35494
EJ
788 if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) {\r
789 return EFI_UNSUPPORTED;\r
790 }\r
791\r
5550f4d3
MK
792 if (LastAttemptStatus == NULL) {\r
793 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImageInternal() - LastAttemptStatus is NULL.\n", mImageIdName));\r
794 Status = EFI_INVALID_PARAMETER;\r
795 goto cleanup;\r
796 }\r
797\r
798 //\r
799 // A last attempt status error code will always override the success\r
800 // value before returning from the function\r
801 //\r
802 *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
803\r
b4b9496b
MK
804 if (This == NULL) {\r
805 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - This is NULL.\n", mImageIdName));\r
806 Status = EFI_INVALID_PARAMETER;\r
5550f4d3 807 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_PROTOCOL_ARG_MISSING;\r
b4b9496b
MK
808 goto cleanup;\r
809 }\r
810\r
4f0544b1
EJ
811 //\r
812 // Retrieve the private context structure\r
813 //\r
814 Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r
815 FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
816\r
b0bacc00 817 //\r
67c1e5ee 818 // Make sure the descriptor has already been loaded or refreshed\r
b0bacc00 819 //\r
4f0544b1 820 PopulateDescriptor (Private);\r
b0bacc00 821\r
a6d73269 822 if (ImageUpdatable == NULL) {\r
e0961677 823 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - ImageUpdatable Pointer Parameter is NULL.\n", mImageIdName));\r
b0bacc00 824 Status = EFI_INVALID_PARAMETER;\r
5550f4d3 825 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_IMAGE_NOT_UPDATABLE;\r
b0bacc00
KM
826 goto cleanup;\r
827 }\r
828\r
829 //\r
830 //Set to valid and then if any tests fail it will update this flag.\r
831 //\r
a6d73269 832 *ImageUpdatable = IMAGE_UPDATABLE_VALID;\r
b0bacc00 833\r
0f30087b
WX
834 //\r
835 // Set to satisfied and then if dependency evaluates to false it will update this flag.\r
836 //\r
837 Private->DependenciesSatisfied = TRUE;\r
838\r
b0bacc00 839 if (Image == NULL) {\r
e0961677 840 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Pointer Parameter is NULL.\n", mImageIdName));\r
b0bacc00
KM
841 //\r
842 // not sure if this is needed\r
843 //\r
a6d73269 844 *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r
5550f4d3 845 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_IMAGE_NOT_PROVIDED;\r
b0bacc00
KM
846 return EFI_INVALID_PARAMETER;\r
847 }\r
848\r
849 PublicKeyDataXdr = PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr);\r
850 PublicKeyDataXdrEnd = PublicKeyDataXdr + PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr);\r
851\r
852 if (PublicKeyDataXdr == NULL || (PublicKeyDataXdr == PublicKeyDataXdrEnd)) {\r
e0961677 853 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Invalid certificate, skipping it.\n", mImageIdName));\r
b0bacc00 854 Status = EFI_ABORTED;\r
5550f4d3 855 LocalLastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_INVALID_CERTIFICATE;\r
b0bacc00
KM
856 } else {\r
857 //\r
858 // Try each key from PcdFmpDevicePkcs7CertBufferXdr\r
859 //\r
860 for (Index = 1; PublicKeyDataXdr < PublicKeyDataXdrEnd; Index++) {\r
861 Index++;\r
862 DEBUG (\r
863 (DEBUG_INFO,\r
e0961677
EJ
864 "FmpDxe(%s): Certificate #%d [%p..%p].\n",\r
865 mImageIdName,\r
b0bacc00
KM
866 Index,\r
867 PublicKeyDataXdr,\r
868 PublicKeyDataXdrEnd\r
869 )\r
870 );\r
871\r
872 if ((PublicKeyDataXdr + sizeof (UINT32)) > PublicKeyDataXdrEnd) {\r
873 //\r
874 // Key data extends beyond end of PCD\r
875 //\r
e0961677 876 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Certificate size extends beyond end of PCD, skipping it.\n", mImageIdName));\r
b0bacc00 877 Status = EFI_ABORTED;\r
5550f4d3 878 LocalLastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_INVALID_KEY_LENGTH_VALUE;\r
b0bacc00
KM
879 break;\r
880 }\r
881 //\r
882 // Read key length stored in big-endian format\r
883 //\r
884 PublicKeyDataLength = SwapBytes32 (*(UINT32 *)(PublicKeyDataXdr));\r
885 //\r
886 // Point to the start of the key data\r
887 //\r
888 PublicKeyDataXdr += sizeof (UINT32);\r
889 if (PublicKeyDataXdr + PublicKeyDataLength > PublicKeyDataXdrEnd) {\r
890 //\r
891 // Key data extends beyond end of PCD\r
892 //\r
e0961677 893 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Certificate extends beyond end of PCD, skipping it.\n", mImageIdName));\r
b0bacc00 894 Status = EFI_ABORTED;\r
5550f4d3 895 LocalLastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_INVALID_KEY_LENGTH;\r
b0bacc00
KM
896 break;\r
897 }\r
898 PublicKeyData = PublicKeyDataXdr;\r
899 Status = AuthenticateFmpImage (\r
900 (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image,\r
901 ImageSize,\r
902 PublicKeyData,\r
903 PublicKeyDataLength\r
904 );\r
905 if (!EFI_ERROR (Status)) {\r
906 break;\r
907 }\r
908 PublicKeyDataXdr += PublicKeyDataLength;\r
909 PublicKeyDataXdr = (UINT8 *)ALIGN_POINTER (PublicKeyDataXdr, sizeof (UINT32));\r
910 }\r
911 }\r
912\r
913 if (EFI_ERROR (Status)) {\r
e0961677 914 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Authentication Failed %r.\n", mImageIdName, Status));\r
5550f4d3
MK
915 if (LocalLastAttemptStatus != LAST_ATTEMPT_STATUS_SUCCESS) {\r
916 *LastAttemptStatus = LocalLastAttemptStatus;\r
917 } else {\r
918 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_IMAGE_AUTH_FAILURE;\r
919 }\r
b0bacc00
KM
920 goto cleanup;\r
921 }\r
922\r
923 //\r
924 // Check to make sure index is 1\r
925 //\r
926 if (ImageIndex != 1) {\r
e0961677 927 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Index Invalid.\n", mImageIdName));\r
a6d73269 928 *ImageUpdatable = IMAGE_UPDATABLE_INVALID_TYPE;\r
b4b9496b 929 Status = EFI_INVALID_PARAMETER;\r
5550f4d3 930 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_INVALID_IMAGE_INDEX;\r
b0bacc00
KM
931 goto cleanup;\r
932 }\r
933\r
0f30087b
WX
934 //\r
935 // Get the dependency from Image.\r
936 //\r
207414cb
MK
937 Dependencies = GetImageDependency (\r
938 (EFI_FIRMWARE_IMAGE_AUTHENTICATION *) Image,\r
939 ImageSize,\r
940 &DependenciesSize,\r
941 LastAttemptStatus\r
942 );\r
943 if (*LastAttemptStatus != LAST_ATTEMPT_STATUS_SUCCESS) {\r
944 Status = EFI_ABORTED;\r
945 goto cleanup;\r
946 }\r
b0bacc00
KM
947\r
948 //\r
949 // Check the FmpPayloadHeader\r
950 //\r
0f30087b 951 FmpPayloadHeader = GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, DependenciesSize, &FmpPayloadSize );\r
b0bacc00 952 if (FmpPayloadHeader == NULL) {\r
e0961677 953 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpHeader failed.\n", mImageIdName));\r
b0bacc00 954 Status = EFI_ABORTED;\r
5550f4d3 955 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_FMP_HEADER;\r
b0bacc00
KM
956 goto cleanup;\r
957 }\r
958 Status = GetFmpPayloadHeaderVersion (FmpPayloadHeader, FmpPayloadSize, &Version);\r
959 if (EFI_ERROR (Status)) {\r
0f30087b
WX
960 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpPayloadHeaderVersion failed %r.\n", mImageIdName, Status));\r
961 *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r
962 Status = EFI_SUCCESS;\r
5550f4d3 963 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_FMP_HEADER_VERSION;\r
0f30087b 964 goto cleanup;\r
b0bacc00
KM
965 }\r
966\r
967 //\r
968 // Check the lowest supported version\r
969 //\r
4f0544b1 970 if (Version < Private->Descriptor.LowestSupportedImageVersion) {\r
b0bacc00
KM
971 DEBUG (\r
972 (DEBUG_ERROR,\r
e0961677
EJ
973 "FmpDxe(%s): CheckTheImage() - Version Lower than lowest supported version. 0x%08X < 0x%08X\n",\r
974 mImageIdName, Version, Private->Descriptor.LowestSupportedImageVersion)\r
b0bacc00 975 );\r
a6d73269 976 *ImageUpdatable = IMAGE_UPDATABLE_INVALID_OLD;\r
b0bacc00 977 Status = EFI_SUCCESS;\r
5550f4d3 978 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_VERSION_TOO_LOW;\r
b0bacc00
KM
979 goto cleanup;\r
980 }\r
981\r
2ed845b3
WX
982 //\r
983 // Evaluate dependency expression\r
984 //\r
207414cb
MK
985 Private->DependenciesSatisfied = CheckFmpDependency (\r
986 Private->Descriptor.ImageTypeId,\r
987 Version,\r
988 Dependencies,\r
989 DependenciesSize,\r
990 &LocalLastAttemptStatus\r
991 );\r
0f30087b
WX
992 if (!Private->DependenciesSatisfied) {\r
993 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check failed.\n", mImageIdName));\r
2ed845b3
WX
994 *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r
995 Status = EFI_SUCCESS;\r
207414cb 996 *LastAttemptStatus = LocalLastAttemptStatus;\r
2ed845b3
WX
997 goto cleanup;\r
998 }\r
999\r
b0bacc00
KM
1000 //\r
1001 // Get the FmpHeaderSize so we can determine the real payload size\r
1002 //\r
1003 Status = GetFmpPayloadHeaderSize (FmpPayloadHeader, FmpPayloadSize, &FmpHeaderSize);\r
1004 if (EFI_ERROR (Status)) {\r
1005 DEBUG ((DEBUG_ERROR, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status));\r
a6d73269 1006 *ImageUpdatable = IMAGE_UPDATABLE_INVALID;\r
b0bacc00 1007 Status = EFI_SUCCESS;\r
5550f4d3 1008 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_FMP_HEADER_SIZE;\r
b0bacc00
KM
1009 goto cleanup;\r
1010 }\r
1011\r
1012 //\r
1013 // Call FmpDevice Lib Check Image on the\r
1014 // Raw payload. So all headers need stripped off\r
1015 //\r
2ed845b3 1016 AllHeaderSize = GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, FmpHeaderSize + DependenciesSize);\r
b0bacc00 1017 if (AllHeaderSize == 0) {\r
e0961677 1018 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetAllHeaderSize failed.\n", mImageIdName));\r
b0bacc00 1019 Status = EFI_ABORTED;\r
5550f4d3 1020 *LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_ALL_HEADER_SIZE;\r
b0bacc00
KM
1021 goto cleanup;\r
1022 }\r
1023 RawSize = ImageSize - AllHeaderSize;\r
1024\r
1025 //\r
1026 // FmpDeviceLib CheckImage function to do any specific checks\r
1027 //\r
a6d73269 1028 Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdatable);\r
b0bacc00 1029 if (EFI_ERROR (Status)) {\r
e0961677 1030 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", mImageIdName, Status));\r
b0bacc00
KM
1031 }\r
1032\r
1033cleanup:\r
1034 return Status;\r
1035}\r
1036\r
5550f4d3
MK
1037/**\r
1038 Checks if the firmware image is valid for the device.\r
1039\r
1040 This function allows firmware update application to validate the firmware image without\r
1041 invoking the SetImage() first.\r
1042\r
1043 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
1044 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
1045 The number is between 1 and DescriptorCount.\r
1046 @param[in] Image Points to the new image.\r
1047 @param[in] ImageSize Size of the new image in bytes.\r
1048 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
1049 if available, additional information if the image is invalid.\r
1050\r
1051 @retval EFI_SUCCESS The image was successfully checked.\r
1052 @retval EFI_ABORTED The operation is aborted.\r
1053 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
1054 @retval EFI_UNSUPPORTED The operation is not supported.\r
1055 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
1056\r
1057**/\r
1058EFI_STATUS\r
1059EFIAPI\r
1060CheckTheImage (\r
1061 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
1062 IN UINT8 ImageIndex,\r
1063 IN CONST VOID *Image,\r
1064 IN UINTN ImageSize,\r
1065 OUT UINT32 *ImageUpdatable\r
1066 )\r
1067{\r
1068 UINT32 LastAttemptStatus;\r
1069\r
1070 return CheckTheImageInternal (This, ImageIndex, Image, ImageSize, ImageUpdatable, &LastAttemptStatus);\r
1071}\r
1072\r
b0bacc00
KM
1073/**\r
1074 Updates the firmware image of the device.\r
1075\r
1076 This function updates the hardware with the new firmware image.\r
1077 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
1078 If the firmware image is updatable, the function should perform the following minimal validations\r
1079 before proceeding to do the firmware image update.\r
1080 - Validate the image authentication if image has attribute\r
1081 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
1082 EFI_SECURITY_VIOLATION if the validation fails.\r
1083 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
1084 the image is unsupported. The function can optionally provide more detailed information on\r
1085 why the image is not a supported image.\r
1086 - Validate the data from VendorCode if not null. Image validation must be performed before\r
1087 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
1088 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
1089\r
1090 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
1091 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
1092 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
1093 firmware image version is older than the current firmware image version or bad image checksum.\r
1094 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
1095 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
1096 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
1097 reason to the caller.\r
1098\r
1099 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
1100 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
1101 The number is between 1 and DescriptorCount.\r
1102 @param[in] Image Points to the new image.\r
1103 @param[in] ImageSize Size of the new image in bytes.\r
1104 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
1105 Null indicates the caller did not specify the policy or use the default policy.\r
1106 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
1107 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
1108 details for the aborted operation. The buffer is allocated by this function\r
1109 with AllocatePool(), and it is the caller's responsibility to free it with a\r
1110 call to FreePool().\r
1111\r
1112 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
1113 @retval EFI_ABORTED The operation is aborted.\r
1114 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
1115 @retval EFI_UNSUPPORTED The operation is not supported.\r
5fc5867e 1116 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
b0bacc00
KM
1117\r
1118**/\r
1119EFI_STATUS\r
1120EFIAPI\r
1121SetTheImage (\r
1122 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
1123 IN UINT8 ImageIndex,\r
1124 IN CONST VOID *Image,\r
1125 IN UINTN ImageSize,\r
1126 IN CONST VOID *VendorCode,\r
1127 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
1128 OUT CHAR16 **AbortReason\r
1129 )\r
1130{\r
4f0544b1
EJ
1131 EFI_STATUS Status;\r
1132 FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r
1133 UINT32 Updateable;\r
1134 BOOLEAN BooleanValue;\r
1135 UINT32 FmpHeaderSize;\r
1136 VOID *FmpHeader;\r
1137 UINTN FmpPayloadSize;\r
1138 UINT32 AllHeaderSize;\r
95d28836 1139 UINT32 IncomingFwVersion;\r
4f0544b1
EJ
1140 UINT32 LastAttemptStatus;\r
1141 UINT32 Version;\r
1142 UINT32 LowestSupportedVersion;\r
2ed845b3
WX
1143 EFI_FIRMWARE_IMAGE_DEP *Dependencies;\r
1144 UINT32 DependenciesSize;\r
b0bacc00
KM
1145\r
1146 Status = EFI_SUCCESS;\r
3633d530 1147 Private = NULL;\r
b0bacc00
KM
1148 Updateable = 0;\r
1149 BooleanValue = FALSE;\r
1150 FmpHeaderSize = 0;\r
1151 FmpHeader = NULL;\r
1152 FmpPayloadSize = 0;\r
1153 AllHeaderSize = 0;\r
2ed845b3 1154 IncomingFwVersion = 0;\r
b0bacc00 1155 LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
2ed845b3
WX
1156 Dependencies = NULL;\r
1157 DependenciesSize = 0;\r
b0bacc00 1158\r
11d35494
EJ
1159 if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) {\r
1160 return EFI_UNSUPPORTED;\r
1161 }\r
1162\r
b4b9496b
MK
1163 if (This == NULL) {\r
1164 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - This is NULL.\n", mImageIdName));\r
1165 Status = EFI_INVALID_PARAMETER;\r
004ce0ab 1166 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_PROTOCOL_ARG_MISSING;\r
b4b9496b
MK
1167 goto cleanup;\r
1168 }\r
1169\r
4f0544b1
EJ
1170 //\r
1171 // Retrieve the private context structure\r
1172 //\r
1173 Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This);\r
1174 FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
b0bacc00 1175\r
67c1e5ee
EJ
1176 //\r
1177 // Make sure the descriptor has already been loaded or refreshed\r
1178 //\r
1179 PopulateDescriptor (Private);\r
1180\r
1181 //\r
1182 // Set to 0 to clear any previous results.\r
1183 //\r
95d28836 1184 SetLastAttemptVersionInVariable (Private, IncomingFwVersion);\r
b0bacc00
KM
1185\r
1186 //\r
1187 // if we have locked the device, then skip the set operation.\r
1188 // it should be blocked by hardware too but we can catch here even faster\r
1189 //\r
4f0544b1 1190 if (Private->FmpDeviceLocked) {\r
e0961677 1191 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Device is already locked. Can't update.\n", mImageIdName));\r
004ce0ab 1192 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_DEVICE_LOCKED;\r
a4c35479 1193 Status = EFI_UNSUPPORTED;\r
b0bacc00
KM
1194 goto cleanup;\r
1195 }\r
1196\r
1197 //\r
1198 // Call check image to verify the image\r
1199 //\r
004ce0ab 1200 Status = CheckTheImageInternal (This, ImageIndex, Image, ImageSize, &Updateable, &LastAttemptStatus);\r
b0bacc00 1201 if (EFI_ERROR (Status)) {\r
e0961677 1202 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Check The Image failed with %r.\n", mImageIdName, Status));\r
b0bacc00
KM
1203 goto cleanup;\r
1204 }\r
1205\r
0f30087b
WX
1206 //\r
1207 // Get the dependency from Image.\r
1208 //\r
207414cb 1209 Dependencies = GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, &DependenciesSize, &LastAttemptStatus);\r
0f30087b 1210\r
b0bacc00
KM
1211 //\r
1212 // No functional error in CheckTheImage. Attempt to get the Version to\r
1213 // support better error reporting.\r
1214 //\r
0f30087b 1215 FmpHeader = GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, ImageSize, DependenciesSize, &FmpPayloadSize );\r
b0bacc00 1216 if (FmpHeader == NULL) {\r
e0961677 1217 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetFmpHeader failed.\n", mImageIdName));\r
004ce0ab 1218 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_FMP_HEADER;\r
b0bacc00
KM
1219 Status = EFI_ABORTED;\r
1220 goto cleanup;\r
1221 }\r
95d28836 1222 Status = GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &IncomingFwVersion);\r
b0bacc00
KM
1223 if (!EFI_ERROR (Status)) {\r
1224 //\r
1225 // Set to actual value\r
1226 //\r
95d28836 1227 SetLastAttemptVersionInVariable (Private, IncomingFwVersion);\r
b0bacc00
KM
1228 }\r
1229\r
1230\r
1231 if (Updateable != IMAGE_UPDATABLE_VALID) {\r
1232 DEBUG (\r
1233 (DEBUG_ERROR,\r
e0961677
EJ
1234 "FmpDxe(%s): SetTheImage() - Check The Image returned that the Image was not valid for update. Updatable value = 0x%X.\n",\r
1235 mImageIdName, Updateable)\r
b0bacc00 1236 );\r
0f30087b 1237 if (Private->DependenciesSatisfied == FALSE) {\r
2ed845b3 1238 LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES;\r
2ed845b3 1239 }\r
b0bacc00
KM
1240 Status = EFI_ABORTED;\r
1241 goto cleanup;\r
1242 }\r
1243\r
1244 if (Progress == NULL) {\r
e0961677 1245 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Invalid progress callback\n", mImageIdName));\r
004ce0ab 1246 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_PROGRESS_CALLBACK_ERROR;\r
b0bacc00
KM
1247 Status = EFI_INVALID_PARAMETER;\r
1248 goto cleanup;\r
1249 }\r
1250\r
1251 mProgressFunc = Progress;\r
b0bacc00
KM
1252\r
1253 //\r
1254 // Checking the image is at least 1%\r
1255 //\r
1256 Status = Progress (1);\r
1257 if (EFI_ERROR (Status)) {\r
e0961677 1258 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Progress Callback failed with Status %r.\n", mImageIdName, Status));\r
b0bacc00
KM
1259 }\r
1260\r
1261 //\r
1262 //Check System Power\r
1263 //\r
1264 Status = CheckSystemPower (&BooleanValue);\r
1265 if (EFI_ERROR (Status)) {\r
e0961677 1266 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemPower - API call failed %r.\n", mImageIdName, Status));\r
004ce0ab 1267 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_CHECK_POWER_API;\r
b0bacc00
KM
1268 goto cleanup;\r
1269 }\r
1270 if (!BooleanValue) {\r
1271 Status = EFI_ABORTED;\r
1272 DEBUG (\r
1273 (DEBUG_ERROR,\r
e0961677 1274 "FmpDxe(%s): SetTheImage() - CheckSystemPower - returned False. Update not allowed due to System Power.\n", mImageIdName)\r
b0bacc00
KM
1275 );\r
1276 LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT;\r
1277 goto cleanup;\r
1278 }\r
1279\r
1280 Progress (2);\r
1281\r
1282 //\r
1283 //Check System Thermal\r
1284 //\r
1285 Status = CheckSystemThermal (&BooleanValue);\r
1286 if (EFI_ERROR (Status)) {\r
e0961677 1287 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemThermal - API call failed %r.\n", mImageIdName, Status));\r
004ce0ab 1288 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_CHECK_SYS_THERMAL_API;\r
b0bacc00
KM
1289 goto cleanup;\r
1290 }\r
1291 if (!BooleanValue) {\r
1292 Status = EFI_ABORTED;\r
004ce0ab 1293 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_THERMAL;\r
b0bacc00
KM
1294 DEBUG (\r
1295 (DEBUG_ERROR,\r
e0961677 1296 "FmpDxe(%s): SetTheImage() - CheckSystemThermal - returned False. Update not allowed due to System Thermal.\n", mImageIdName)\r
b0bacc00
KM
1297 );\r
1298 goto cleanup;\r
1299 }\r
1300\r
1301 Progress (3);\r
1302\r
1303 //\r
1304 //Check System Environment\r
1305 //\r
1306 Status = CheckSystemEnvironment (&BooleanValue);\r
1307 if (EFI_ERROR (Status)) {\r
e0961677 1308 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - CheckSystemEnvironment - API call failed %r.\n", mImageIdName, Status));\r
004ce0ab 1309 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_CHECK_SYS_ENV_API;\r
b0bacc00
KM
1310 goto cleanup;\r
1311 }\r
1312 if (!BooleanValue) {\r
1313 Status = EFI_ABORTED;\r
004ce0ab 1314 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_SYSTEM_ENV;\r
b0bacc00
KM
1315 DEBUG (\r
1316 (DEBUG_ERROR,\r
e0961677 1317 "FmpDxe(%s): SetTheImage() - CheckSystemEnvironment - returned False. Update not allowed due to System Environment.\n", mImageIdName)\r
b0bacc00
KM
1318 );\r
1319 goto cleanup;\r
1320 }\r
1321\r
1322 Progress (4);\r
1323\r
1324 //\r
1325 // Save LastAttemptStatus as error so that if SetImage never returns the error\r
1326 // state is recorded.\r
1327 //\r
67c1e5ee 1328 SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r
b0bacc00
KM
1329\r
1330 //\r
1331 // Strip off all the headers so the device can process its firmware\r
1332 //\r
1333 Status = GetFmpPayloadHeaderSize (FmpHeader, FmpPayloadSize, &FmpHeaderSize);\r
1334 if (EFI_ERROR (Status)) {\r
e0961677 1335 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetFmpPayloadHeaderSize failed %r.\n", mImageIdName, Status));\r
004ce0ab 1336 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_FMP_HEADER_SIZE;\r
b0bacc00
KM
1337 goto cleanup;\r
1338 }\r
1339\r
2ed845b3 1340 AllHeaderSize = GetAllHeaderSize ((EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image, FmpHeaderSize + DependenciesSize);\r
b0bacc00 1341 if (AllHeaderSize == 0) {\r
e0961677 1342 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetAllHeaderSize failed.\n", mImageIdName));\r
004ce0ab 1343 LastAttemptStatus = LAST_ATTEMPT_STATUS_DRIVER_ERROR_GET_ALL_HEADER_SIZE;\r
b0bacc00
KM
1344 Status = EFI_ABORTED;\r
1345 goto cleanup;\r
1346 }\r
1347\r
1348 //\r
1349 // Indicate that control is handed off to FmpDeviceLib\r
1350 //\r
1351 Progress (5);\r
1352\r
1353 //\r
1354 //Copy the requested image to the firmware using the FmpDeviceLib\r
1355 //\r
1356 Status = FmpDeviceSetImage (\r
0f30087b
WX
1357 (((UINT8 *)Image) + AllHeaderSize),\r
1358 ImageSize - AllHeaderSize,\r
b0bacc00
KM
1359 VendorCode,\r
1360 FmpDxeProgress,\r
95d28836 1361 IncomingFwVersion,\r
b0bacc00
KM
1362 AbortReason\r
1363 );\r
1364 if (EFI_ERROR (Status)) {\r
e0961677 1365 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SetImage from FmpDeviceLib failed. Status = %r.\n", mImageIdName, Status));\r
b0bacc00
KM
1366 goto cleanup;\r
1367 }\r
1368\r
0f30087b
WX
1369 //\r
1370 // Store the dependency\r
1371 //\r
1372 if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) {\r
1373 Status = SaveFmpDependency (Dependencies, DependenciesSize);\r
1374 if (EFI_ERROR (Status)) {\r
1375 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SaveFmpDependency from FmpDependencyCheckLib failed. (%r)\n", mImageIdName, Status));\r
1376 }\r
1377 Status = EFI_SUCCESS;\r
1378 }\r
b0bacc00
KM
1379\r
1380 //\r
1381 // Finished the update without error\r
1382 // Indicate that control has been returned from FmpDeviceLib\r
1383 //\r
1384 Progress (99);\r
1385\r
1386 //\r
1387 // Update the version stored in variable\r
1388 //\r
4f0544b1 1389 if (!Private->RuntimeVersionSupported) {\r
a6d73269 1390 Version = DEFAULT_VERSION;\r
b0bacc00 1391 GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &Version);\r
67c1e5ee 1392 SetVersionInVariable (Private, Version);\r
b0bacc00
KM
1393 }\r
1394\r
1395 //\r
1396 // Update lowest supported variable\r
1397 //\r
67c1e5ee
EJ
1398 LowestSupportedVersion = DEFAULT_LOWESTSUPPORTEDVERSION;\r
1399 GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader, FmpPayloadSize, &LowestSupportedVersion);\r
1400 SetLowestSupportedVersionInVariable (Private, LowestSupportedVersion);\r
b0bacc00
KM
1401\r
1402 LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
1403\r
b0bacc00
KM
1404cleanup:\r
1405 mProgressFunc = NULL;\r
3633d530
MK
1406\r
1407 if (Private != NULL) {\r
004ce0ab 1408 DEBUG ((DEBUG_INFO, "FmpDxe(%s): SetTheImage() LastAttemptStatus: %u.\n", mImageIdName, LastAttemptStatus));\r
3633d530
MK
1409 SetLastAttemptStatusInVariable (Private, LastAttemptStatus);\r
1410 }\r
b0bacc00 1411\r
c6c18d87
SZ
1412 if (Progress != NULL) {\r
1413 //\r
1414 // Set progress to 100 after everything is done including recording Status.\r
1415 //\r
1416 Progress (100);\r
1417 }\r
b0bacc00 1418\r
27e42bf6
SZ
1419 //\r
1420 // Need repopulate after SetImage is called to\r
1421 // update LastAttemptVersion and LastAttemptStatus.\r
1422 //\r
3633d530
MK
1423 if (Private != NULL) {\r
1424 Private->DescriptorPopulated = FALSE;\r
1425 }\r
27e42bf6 1426\r
b0bacc00
KM
1427 return Status;\r
1428}\r
1429\r
1430/**\r
1431 Returns information about the firmware package.\r
1432\r
1433 This function returns package information.\r
1434\r
1435 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
1436 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
1437 The format is vendor specific and new version must have a greater value\r
1438 than the old version. If PackageVersion is not supported, the value is\r
1439 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
1440 comparison is to be performed using PackageVersionName. A value of\r
1441 0xFFFFFFFD indicates that package version update is in progress.\r
1442 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
1443 the package version name. The buffer is allocated by this function with\r
1444 AllocatePool(), and it is the caller's responsibility to free it with a\r
1445 call to FreePool().\r
1446 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
1447 package version name. A value of 0 indicates the device does not support\r
1448 update of package version name. Length is the number of Unicode characters,\r
1449 including the terminating null character.\r
1450 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
1451 Definitions' for possible returned values of this parameter. A value of 1\r
1452 indicates the attribute is supported and the current setting value is\r
1453 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
1454 supported and the current setting value in AttributesSetting is meaningless.\r
1455 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
1456 values of this parameter\r
1457\r
1458 @retval EFI_SUCCESS The package information was successfully returned.\r
1459 @retval EFI_UNSUPPORTED The operation is not supported.\r
1460\r
1461**/\r
1462EFI_STATUS\r
1463EFIAPI\r
1464GetPackageInfo (\r
1465 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
1466 OUT UINT32 *PackageVersion,\r
1467 OUT CHAR16 **PackageVersionName,\r
1468 OUT UINT32 *PackageVersionNameMaxLen,\r
1469 OUT UINT64 *AttributesSupported,\r
1470 OUT UINT64 *AttributesSetting\r
1471 )\r
1472{\r
1473 return EFI_UNSUPPORTED;\r
1474}\r
1475\r
1476/**\r
1477 Updates information about the firmware package.\r
1478\r
1479 This function updates package information.\r
1480 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
1481 VendorCode enables vendor to implement vendor-specific package information update policy.\r
1482 Null if the caller did not specify this policy or use the default policy.\r
1483\r
1484 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
1485 @param[in] Image Points to the authentication image.\r
1486 Null if authentication is not required.\r
1487 @param[in] ImageSize Size of the authentication image in bytes.\r
1488 0 if authentication is not required.\r
1489 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
1490 image update policy.\r
1491 Null indicates the caller did not specify this policy or use\r
1492 the default policy.\r
1493 @param[in] PackageVersion The new package version.\r
1494 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
1495 the package version name.\r
1496 The string length is equal to or less than the value returned in\r
1497 PackageVersionNameMaxLen.\r
1498\r
1499 @retval EFI_SUCCESS The device was successfully updated with the new package\r
1500 information.\r
1501 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
1502 returned in PackageVersionNameMaxLen.\r
1503 @retval EFI_UNSUPPORTED The operation is not supported.\r
5fc5867e 1504 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
b0bacc00
KM
1505\r
1506**/\r
1507EFI_STATUS\r
1508EFIAPI\r
1509SetPackageInfo (\r
1510 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
1511 IN CONST VOID *Image,\r
1512 IN UINTN ImageSize,\r
1513 IN CONST VOID *VendorCode,\r
1514 IN UINT32 PackageVersion,\r
1515 IN CONST CHAR16 *PackageVersionName\r
1516 )\r
1517{\r
1518 return EFI_UNSUPPORTED;\r
1519}\r
1520\r
1521/**\r
1522 Event notification function that is invoked when the event GUID specified by\r
1523 PcdFmpDeviceLockEventGuid is signaled.\r
1524\r
1525 @param[in] Event Event whose notification function is being invoked.\r
1526 @param[in] Context The pointer to the notification function's context,\r
1527 which is implementation-dependent.\r
1528**/\r
1529VOID\r
1530EFIAPI\r
1531FmpDxeLockEventNotify (\r
1532 IN EFI_EVENT Event,\r
1533 IN VOID *Context\r
1534 )\r
1535{\r
4f0544b1
EJ
1536 EFI_STATUS Status;\r
1537 FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r
1538\r
b4b9496b
MK
1539 if (Context == NULL) {\r
1540 ASSERT (Context != NULL);\r
1541 return;\r
1542 }\r
1543\r
4f0544b1 1544 Private = (FIRMWARE_MANAGEMENT_PRIVATE_DATA *)Context;\r
b0bacc00 1545\r
4f0544b1 1546 if (!Private->FmpDeviceLocked) {\r
9e6c4f15
SZ
1547 //\r
1548 // Lock the firmware device\r
1549 //\r
4f0544b1 1550 FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
9e6c4f15
SZ
1551 Status = FmpDeviceLock();\r
1552 if (EFI_ERROR (Status)) {\r
1553 if (Status != EFI_UNSUPPORTED) {\r
e0961677 1554 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLock() returned error. Status = %r\n", mImageIdName, Status));\r
b0bacc00 1555 } else {\r
e0961677 1556 DEBUG ((DEBUG_WARN, "FmpDxe(%s): FmpDeviceLock() returned error. Status = %r\n", mImageIdName, Status));\r
b0bacc00 1557 }\r
b0bacc00 1558 }\r
4f0544b1 1559 Private->FmpDeviceLocked = TRUE;\r
b0bacc00
KM
1560 }\r
1561}\r
1562\r
1563/**\r
1564 Function to install FMP instance.\r
1565\r
1566 @param[in] Handle The device handle to install a FMP instance on.\r
1567\r
1568 @retval EFI_SUCCESS FMP Installed\r
1569 @retval EFI_INVALID_PARAMETER Handle was invalid\r
1570 @retval other Error installing FMP\r
1571\r
1572**/\r
1573EFI_STATUS\r
1574EFIAPI\r
1575InstallFmpInstance (\r
1576 IN EFI_HANDLE Handle\r
1577 )\r
1578{\r
4f0544b1
EJ
1579 EFI_STATUS Status;\r
1580 EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;\r
1581 FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r
b0bacc00 1582\r
b0bacc00
KM
1583 //\r
1584 // Only allow a single FMP Protocol instance to be installed\r
1585 //\r
4f0544b1
EJ
1586 Status = gBS->OpenProtocol (\r
1587 Handle,\r
1588 &gEfiFirmwareManagementProtocolGuid,\r
1589 (VOID **)&Fmp,\r
1590 NULL,\r
1591 NULL,\r
1592 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1593 );\r
1594 if (!EFI_ERROR (Status)) {\r
b0bacc00
KM
1595 return EFI_ALREADY_STARTED;\r
1596 }\r
1597\r
1598 //\r
1599 // Allocate FMP Protocol instance\r
1600 //\r
4f0544b1
EJ
1601 Private = AllocateCopyPool (\r
1602 sizeof (mFirmwareManagementPrivateDataTemplate),\r
1603 &mFirmwareManagementPrivateDataTemplate\r
1604 );\r
1605 if (Private == NULL) {\r
e0961677 1606 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to allocate memory for private structure.\n", mImageIdName));\r
b0bacc00
KM
1607 Status = EFI_OUT_OF_RESOURCES;\r
1608 goto cleanup;\r
1609 }\r
1610\r
1611 //\r
4f0544b1 1612 // Initialize private context data structure\r
b0bacc00 1613 //\r
4f0544b1 1614 Private->Handle = Handle;\r
4f0544b1
EJ
1615 Private->FmpDeviceContext = NULL;\r
1616 Status = FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
1617 if (Status == EFI_UNSUPPORTED) {\r
1618 Private->FmpDeviceContext = NULL;\r
1619 } else if (EFI_ERROR (Status)) {\r
b0bacc00
KM
1620 goto cleanup;\r
1621 }\r
1622\r
67c1e5ee
EJ
1623 //\r
1624 // Make sure the descriptor has already been loaded or refreshed\r
1625 //\r
1626 PopulateDescriptor (Private);\r
1627\r
4f0544b1
EJ
1628 if (IsLockFmpDeviceAtLockEventGuidRequired ()) {\r
1629 //\r
e0961677 1630 // Register all UEFI Variables used by this module to be locked.\r
4f0544b1 1631 //\r
67c1e5ee 1632 Status = LockAllFmpVariables (Private);\r
4f0544b1 1633 if (EFI_ERROR (Status)) {\r
e0961677 1634 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to register variables to lock. Status = %r.\n", mImageIdName, Status));\r
4f0544b1 1635 } else {\r
e0961677 1636 DEBUG ((DEBUG_INFO, "FmpDxe(%s): All variables registered to lock\n", mImageIdName));\r
4f0544b1
EJ
1637 }\r
1638\r
1639 //\r
1640 // Create and register notify function to lock the FMP device.\r
1641 //\r
1642 Status = gBS->CreateEventEx (\r
1643 EVT_NOTIFY_SIGNAL,\r
1644 TPL_CALLBACK,\r
1645 FmpDxeLockEventNotify,\r
1646 Private,\r
1647 mLockGuid,\r
1648 &Private->FmpDeviceLockEvent\r
1649 );\r
1650 if (EFI_ERROR (Status)) {\r
e0961677 1651 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Failed to register notification. Status = %r\n", mImageIdName, Status));\r
4f0544b1
EJ
1652 }\r
1653 ASSERT_EFI_ERROR (Status);\r
1654 } else {\r
e0961677 1655 DEBUG ((DEBUG_VERBOSE, "FmpDxe(%s): Not registering notification to call FmpDeviceLock() because mfg mode\n", mImageIdName));\r
4f0544b1 1656 }\r
b0bacc00
KM
1657\r
1658 //\r
1659 // Install FMP Protocol and FMP Progress Protocol\r
1660 //\r
1661 Status = gBS->InstallMultipleProtocolInterfaces (\r
4f0544b1
EJ
1662 &Private->Handle,\r
1663 &gEfiFirmwareManagementProtocolGuid, &Private->Fmp,\r
1664 &gEdkiiFirmwareManagementProgressProtocolGuid, &mFmpProgress,\r
b0bacc00
KM
1665 NULL\r
1666 );\r
b0bacc00 1667 if (EFI_ERROR (Status)) {\r
e0961677 1668 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol install error. Status = %r.\n", mImageIdName, Status));\r
b0bacc00
KM
1669 goto cleanup;\r
1670 }\r
1671\r
b0bacc00
KM
1672cleanup:\r
1673\r
4f0544b1
EJ
1674 if (EFI_ERROR (Status)) {\r
1675 if (Private != NULL) {\r
1676 if (Private->FmpDeviceLockEvent != NULL) {\r
1677 gBS->CloseEvent (Private->FmpDeviceLockEvent);\r
1678 }\r
67c1e5ee
EJ
1679 if (Private->Descriptor.VersionName != NULL) {\r
1680 FreePool (Private->Descriptor.VersionName);\r
1681 }\r
1682 if (Private->FmpDeviceContext != NULL) {\r
1683 FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r
1684 }\r
1685 if (Private->VersionVariableName != NULL) {\r
1686 FreePool (Private->VersionVariableName);\r
1687 }\r
1688 if (Private->LsvVariableName != NULL) {\r
1689 FreePool (Private->LsvVariableName);\r
1690 }\r
1691 if (Private->LastAttemptStatusVariableName != NULL) {\r
1692 FreePool (Private->LastAttemptStatusVariableName);\r
1693 }\r
1694 if (Private->LastAttemptVersionVariableName != NULL) {\r
1695 FreePool (Private->LastAttemptVersionVariableName);\r
1696 }\r
1697 if (Private->FmpStateVariableName != NULL) {\r
1698 FreePool (Private->FmpStateVariableName);\r
1699 }\r
4f0544b1
EJ
1700 FreePool (Private);\r
1701 }\r
1702 }\r
1703\r
b0bacc00
KM
1704 return Status;\r
1705}\r
1706\r
4f0544b1
EJ
1707/**\r
1708 Function to uninstall FMP instance.\r
1709\r
1710 @param[in] Handle The device handle to install a FMP instance on.\r
1711\r
1712 @retval EFI_SUCCESS FMP Installed\r
1713 @retval EFI_INVALID_PARAMETER Handle was invalid\r
1714 @retval other Error installing FMP\r
1715\r
1716**/\r
1717EFI_STATUS\r
1718EFIAPI\r
1719UninstallFmpInstance (\r
1720 IN EFI_HANDLE Handle\r
1721 )\r
1722{\r
1723 EFI_STATUS Status;\r
1724 EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;\r
1725 FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;\r
1726\r
1727 Status = gBS->OpenProtocol (\r
1728 Handle,\r
1729 &gEfiFirmwareManagementProtocolGuid,\r
1730 (VOID **)&Fmp,\r
1731 NULL,\r
1732 NULL,\r
1733 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1734 );\r
1735 if (EFI_ERROR (Status)) {\r
e0961677 1736 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol open error. Status = %r.\n", mImageIdName, Status));\r
4f0544b1
EJ
1737 return Status;\r
1738 }\r
1739\r
1740 Private = FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (Fmp);\r
1741 FmpDeviceSetContext (Private->Handle, &Private->FmpDeviceContext);\r
1742\r
1743 if (Private->FmpDeviceLockEvent != NULL) {\r
1744 gBS->CloseEvent (Private->FmpDeviceLockEvent);\r
1745 }\r
1746\r
1747 Status = gBS->UninstallMultipleProtocolInterfaces (\r
1748 Private->Handle,\r
1749 &gEfiFirmwareManagementProtocolGuid, &Private->Fmp,\r
1750 &gEdkiiFirmwareManagementProgressProtocolGuid, &mFmpProgress,\r
1751 NULL\r
1752 );\r
1753 if (EFI_ERROR (Status)) {\r
e0961677 1754 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Protocol uninstall error. Status = %r.\n", mImageIdName, Status));\r
4f0544b1
EJ
1755 return Status;\r
1756 }\r
1757\r
67c1e5ee
EJ
1758 if (Private->Descriptor.VersionName != NULL) {\r
1759 FreePool (Private->Descriptor.VersionName);\r
1760 }\r
1761 if (Private->FmpDeviceContext != NULL) {\r
1762 FmpDeviceSetContext (NULL, &Private->FmpDeviceContext);\r
1763 }\r
1764 if (Private->VersionVariableName != NULL) {\r
1765 FreePool (Private->VersionVariableName);\r
1766 }\r
1767 if (Private->LsvVariableName != NULL) {\r
1768 FreePool (Private->LsvVariableName);\r
1769 }\r
1770 if (Private->LastAttemptStatusVariableName != NULL) {\r
1771 FreePool (Private->LastAttemptStatusVariableName);\r
1772 }\r
1773 if (Private->LastAttemptVersionVariableName != NULL) {\r
1774 FreePool (Private->LastAttemptVersionVariableName);\r
1775 }\r
1776 if (Private->FmpStateVariableName != NULL) {\r
1777 FreePool (Private->FmpStateVariableName);\r
1778 }\r
4f0544b1
EJ
1779 FreePool (Private);\r
1780\r
1781 return EFI_SUCCESS;\r
1782}\r
1783\r
1784/**\r
1785 Unloads the application and its installed protocol.\r
1786\r
1787 @param ImageHandle Handle that identifies the image to be unloaded.\r
1788 @param SystemTable The system table.\r
1789\r
1790 @retval EFI_SUCCESS The image has been unloaded.\r
1791\r
1792**/\r
1793EFI_STATUS\r
1794EFIAPI\r
1795FmpDxeLibDestructor (\r
1796 IN EFI_HANDLE ImageHandle,\r
1797 IN EFI_SYSTEM_TABLE *SystemTable\r
1798 )\r
1799{\r
1800 if (mFmpSingleInstance) {\r
1801 return UninstallFmpInstance (ImageHandle);\r
1802 }\r
1803 return EFI_SUCCESS;\r
1804}\r
1805\r
b0bacc00 1806/**\r
e8619f82 1807 Main entry for this driver/library.\r
b0bacc00
KM
1808\r
1809 @param[in] ImageHandle Image handle this driver.\r
1810 @param[in] SystemTable Pointer to SystemTable.\r
1811\r
1812**/\r
1813EFI_STATUS\r
1814EFIAPI\r
1815FmpDxeEntryPoint (\r
1816 IN EFI_HANDLE ImageHandle,\r
1817 IN EFI_SYSTEM_TABLE *SystemTable\r
1818 )\r
1819{\r
1820 EFI_STATUS Status;\r
b0bacc00
KM
1821\r
1822 //\r
1823 // Verify that a new FILE_GUID value has been provided in the <Defines>\r
1824 // section of this module. The FILE_GUID is the ESRT GUID that must be\r
1825 // unique for each updatable firmware image.\r
1826 //\r
1827 if (CompareGuid (&mDefaultModuleFileGuid, &gEfiCallerIdGuid)) {\r
1828 DEBUG ((DEBUG_ERROR, "FmpDxe: Use of default FILE_GUID detected. FILE_GUID must be set to a unique value.\n"));\r
1829 ASSERT (FALSE);\r
1830 return EFI_UNSUPPORTED;\r
1831 }\r
1832\r
1833 //\r
1834 // Get the ImageIdName value for the EFI_FIRMWARE_IMAGE_DESCRIPTOR from a PCD.\r
1835 //\r
1836 mImageIdName = (CHAR16 *) PcdGetPtr (PcdFmpDeviceImageIdName);\r
1837 if (PcdGetSize (PcdFmpDeviceImageIdName) <= 2 || mImageIdName[0] == 0) {\r
1838 //\r
1839 // PcdFmpDeviceImageIdName must be set to a non-empty Unicode string\r
1840 //\r
c9fa9762 1841 DEBUG ((DEBUG_ERROR, "FmpDxe(%g): PcdFmpDeviceImageIdName is an empty string.\n", &gEfiCallerIdGuid));\r
b0bacc00 1842 ASSERT (FALSE);\r
e0961677 1843 return EFI_UNSUPPORTED;\r
b0bacc00
KM
1844 }\r
1845\r
1846 //\r
1847 // Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.\r
1848 //\r
1849 DetectTestKey ();\r
1850\r
4f0544b1
EJ
1851 //\r
1852 // Fill in FMP Progress Protocol fields for Version 1\r
1853 //\r
1854 mFmpProgress.Version = 1;\r
1855 mFmpProgress.ProgressBarForegroundColor.Raw = PcdGet32 (PcdFmpDeviceProgressColor);\r
1856 mFmpProgress.WatchdogSeconds = PcdGet8 (PcdFmpDeviceProgressWatchdogTimeInSeconds);\r
9e6c4f15 1857\r
4f0544b1
EJ
1858 // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.\r
1859 // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then\r
1860 // gEfiEndOfDxeEventGroupGuid is used.\r
1861 //\r
1862 mLockGuid = &gEfiEndOfDxeEventGroupGuid;\r
1863 if (PcdGetSize (PcdFmpDeviceLockEventGuid) == sizeof (EFI_GUID)) {\r
1864 mLockGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceLockEventGuid);\r
9e6c4f15 1865 }\r
e0961677 1866 DEBUG ((DEBUG_INFO, "FmpDxe(%s): Lock GUID: %g\n", mImageIdName, mLockGuid));\r
9e6c4f15 1867\r
b0bacc00
KM
1868 //\r
1869 // Register with library the install function so if the library uses\r
1870 // UEFI driver model/driver binding protocol it can install FMP on its device handle\r
1871 // If library is simple lib that does not use driver binding then it should return\r
1872 // unsupported and this will install the FMP instance on the ImageHandle\r
1873 //\r
1874 Status = RegisterFmpInstaller (InstallFmpInstance);\r
1875 if (Status == EFI_UNSUPPORTED) {\r
4f0544b1 1876 mFmpSingleInstance = TRUE;\r
e0961677 1877 DEBUG ((DEBUG_INFO, "FmpDxe(%s): FmpDeviceLib registration returned EFI_UNSUPPORTED. Installing single FMP instance.\n", mImageIdName));\r
4f0544b1
EJ
1878 Status = RegisterFmpUninstaller (UninstallFmpInstance);\r
1879 if (Status == EFI_UNSUPPORTED) {\r
1880 Status = InstallFmpInstance (ImageHandle);\r
1881 } else {\r
e0961677 1882 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n", mImageIdName));\r
4f0544b1
EJ
1883 Status = EFI_UNSUPPORTED;\r
1884 }\r
b0bacc00 1885 } else if (EFI_ERROR (Status)) {\r
e0961677 1886 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib registration returned %r. No FMP installed.\n", mImageIdName, Status));\r
b0bacc00
KM
1887 } else {\r
1888 DEBUG ((\r
1889 DEBUG_INFO,\r
e0961677
EJ
1890 "FmpDxe(%s): FmpDeviceLib registration returned EFI_SUCCESS. Expect FMP to be installed during the BDS/Device connection phase.\n",\r
1891 mImageIdName\r
b0bacc00 1892 ));\r
4f0544b1
EJ
1893 Status = RegisterFmpUninstaller (UninstallFmpInstance);\r
1894 if (EFI_ERROR (Status)) {\r
e0961677 1895 DEBUG ((DEBUG_ERROR, "FmpDxe(%s): FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n", mImageIdName));\r
4f0544b1 1896 }\r
b0bacc00
KM
1897 }\r
1898\r
b0bacc00
KM
1899 return Status;\r
1900}\r