2 Produces a Firmware Management Protocol that supports updates to a firmware
3 image stored in a firmware device with platform and firmware device specific
4 information provided through PCDs and libraries.
6 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
7 Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
16 /// FILE_GUID from FmpDxe.inf. When FmpDxe.inf is used in a platform, the
17 /// FILE_GUID must always be overridden in the <Defines> section to provide
18 /// the ESRT GUID value associated with the updatable firmware image. A
19 /// check is made in this module's driver entry point to verify that a
20 /// new FILE_GUID value has been defined.
22 const EFI_GUID mDefaultModuleFileGuid
= {
23 0x78ef0a56, 0x1cf0, 0x4535, { 0xb5, 0xda, 0xf6, 0xfd, 0x2f, 0x40, 0x5a, 0x11 }
27 /// TRUE if FmpDeviceLib manages a single firmware storage device.
29 BOOLEAN mFmpSingleInstance
= FALSE
;
32 /// Firmware Management Protocol instance that is initialized in the entry
33 /// point from PCD settings.
35 EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL mFmpProgress
;
38 // Template of the private context structure for the Firmware Management
41 const FIRMWARE_MANAGEMENT_PRIVATE_DATA mFirmwareManagementPrivateDataTemplate
= {
42 FIRMWARE_MANAGEMENT_PRIVATE_DATA_SIGNATURE
, // Signature
52 FALSE
, // DescriptorPopulated
58 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
64 0, // AttributesSupported
65 0, // AttributesSetting
67 0, // LowestSupportedImageVersion
68 0, // LastAttemptVersion
69 0, // LastAttemptStatus
74 TRUE
, // RuntimeVersionSupported
75 NULL
, // FmpDeviceLockEvent
76 FALSE
// FmpDeviceLocked
80 /// GUID that is used to create event used to lock the firmware storage device.
82 EFI_GUID
*mLockGuid
= NULL
;
85 /// Progress() function pointer passed into SetTheImage()
87 EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS mProgressFunc
= NULL
;
90 /// Null-terminated Unicode string retrieved from PcdFmpDeviceImageIdName.
92 CHAR16
*mImageIdName
= NULL
;
95 Callback function to report the process of the firmware updating.
97 Wrap the caller's version in this so that progress from the device lib is
98 within the expected range. Convert device lib 0% - 100% to 6% - 98%.
100 FmpDxe 1% - 5% for validation
101 FmpDeviceLib 6% - 98% for flashing/update
102 FmpDxe 99% - 100% finish
104 @param[in] Completion A value between 1 and 100 indicating the current
105 completion progress of the firmware update. Completion
106 progress is reported as from 1 to 100 percent. A value
107 of 0 is used by the driver to indicate that progress
108 reporting is not supported.
110 @retval EFI_SUCCESS The progress was updated.
111 @retval EFI_UNSUPPORTED Updating progress is not supported.
122 Status
= EFI_UNSUPPORTED
;
124 if (mProgressFunc
== NULL
) {
129 // Reserve 6% - 98% for the FmpDeviceLib. Call the real progress function.
131 Status
= mProgressFunc (((Completion
* 92) / 100) + 6);
133 if (Status
== EFI_UNSUPPORTED
) {
134 mProgressFunc
= NULL
;
141 Returns a pointer to the ImageTypeId GUID value. An attempt is made to get
142 the GUID value from the FmpDeviceLib. If the FmpDeviceLib does not provide
143 a GUID value, then gEfiCallerIdGuid is returned.
145 @return The ImageTypeId GUID
154 EFI_GUID
*FmpDeviceLibGuid
;
156 FmpDeviceLibGuid
= NULL
;
157 Status
= FmpDeviceGetImageTypeIdGuidPtr (&FmpDeviceLibGuid
);
158 if (EFI_ERROR (Status
)) {
159 if (Status
!= EFI_UNSUPPORTED
) {
160 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid error %r\n", Status
));
162 return &gEfiCallerIdGuid
;
164 if (FmpDeviceLibGuid
== NULL
) {
165 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid GUID\n"));
166 return &gEfiCallerIdGuid
;
168 return FmpDeviceLibGuid
;
172 Returns a pointer to the Null-terminated Unicode ImageIdName string.
174 @return Null-terminated Unicode ImageIdName string.
178 GetImageTypeNameString (
186 Lowest supported version is a combo of three parts.
187 1. Check if the device lib has a lowest supported version
188 2. Check if we have a variable for lowest supported version (this will be updated with each capsule applied)
189 3. Check Fixed at build PCD
191 @return The largest value
195 GetLowestSupportedVersion (
200 UINT32 DeviceLibLowestSupportedVersion
;
201 UINT32 VariableLowestSupportedVersion
;
205 // Get the LowestSupportedVersion.
208 if (!IsLowestSupportedVersionCheckRequired ()) {
210 // Any Version can pass the 0 LowestSupportedVersion check.
215 ReturnLsv
= PcdGet32 (PcdFmpDeviceBuildTimeLowestSupportedVersion
);
218 // Check the FmpDeviceLib
220 DeviceLibLowestSupportedVersion
= DEFAULT_LOWESTSUPPORTEDVERSION
;
221 Status
= FmpDeviceGetLowestSupportedVersion (&DeviceLibLowestSupportedVersion
);
222 if (EFI_ERROR (Status
)) {
223 DeviceLibLowestSupportedVersion
= DEFAULT_LOWESTSUPPORTEDVERSION
;
226 if (DeviceLibLowestSupportedVersion
> ReturnLsv
) {
227 ReturnLsv
= DeviceLibLowestSupportedVersion
;
231 // Check the lowest supported version UEFI variable for this device
233 VariableLowestSupportedVersion
= GetLowestSupportedVersionFromVariable();
234 if (VariableLowestSupportedVersion
> ReturnLsv
) {
235 ReturnLsv
= VariableLowestSupportedVersion
;
239 // Return the largest value
245 Populates the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure in the private
248 @param[in] Private Pointer to the private context structure for the
249 Firmware Management Protocol instance.
254 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
259 if (Private
->DescriptorPopulated
) {
263 Private
->Descriptor
.ImageIndex
= 1;
264 CopyGuid (&Private
->Descriptor
.ImageTypeId
, GetImageTypeIdGuid());
265 Private
->Descriptor
.ImageId
= Private
->Descriptor
.ImageIndex
;
266 Private
->Descriptor
.ImageIdName
= GetImageTypeNameString();
269 // Get the version. Some devices don't support getting the firmware version
270 // at runtime. If FmpDeviceLib does not support returning a version, then
271 // it is stored in a UEFI variable.
273 Status
= FmpDeviceGetVersion (&Private
->Descriptor
.Version
);
274 if (Status
== EFI_UNSUPPORTED
) {
275 Private
->RuntimeVersionSupported
= FALSE
;
276 Private
->Descriptor
.Version
= GetVersionFromVariable();
277 } else if (EFI_ERROR (Status
)) {
279 // Unexpected error. Use default version.
281 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetVersion() from FmpDeviceLib (%s) returned %r\n", GetImageTypeNameString(), Status
));
282 Private
->Descriptor
.Version
= DEFAULT_VERSION
;
286 // Free the current version name. Shouldn't really happen but this populate
287 // function could be called multiple times (to refresh).
289 if (Private
->Descriptor
.VersionName
!= NULL
) {
290 FreePool (Private
->Descriptor
.VersionName
);
291 Private
->Descriptor
.VersionName
= NULL
;
295 // Attempt to get the version string from the FmpDeviceLib
297 Status
= FmpDeviceGetVersionString (&Private
->Descriptor
.VersionName
);
298 if (Status
== EFI_UNSUPPORTED
) {
299 DEBUG ((DEBUG_INFO
, "FmpDxe: GetVersionString() unsupported in FmpDeviceLib.\n"));
300 Private
->Descriptor
.VersionName
= AllocateCopyPool (
301 sizeof (VERSION_STRING_NOT_SUPPORTED
),
302 VERSION_STRING_NOT_SUPPORTED
304 } else if (EFI_ERROR (Status
)) {
305 DEBUG ((DEBUG_INFO
, "FmpDxe: GetVersionString() not available in FmpDeviceLib.\n"));
306 Private
->Descriptor
.VersionName
= AllocateCopyPool (
307 sizeof (VERSION_STRING_NOT_AVAILABLE
),
308 VERSION_STRING_NOT_AVAILABLE
312 Private
->Descriptor
.LowestSupportedImageVersion
= GetLowestSupportedVersion();
315 // Get attributes from the FmpDeviceLib
317 FmpDeviceGetAttributes (
318 &Private
->Descriptor
.AttributesSupported
,
319 &Private
->Descriptor
.AttributesSetting
323 // Force set the updatable bits in the attributes;
325 Private
->Descriptor
.AttributesSupported
|= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
;
326 Private
->Descriptor
.AttributesSetting
|= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
;
329 // Force set the authentication bits in the attributes;
331 Private
->Descriptor
.AttributesSupported
|= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
);
332 Private
->Descriptor
.AttributesSetting
|= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
);
334 Private
->Descriptor
.Compatibilities
= 0;
337 // Get the size of the firmware image from the FmpDeviceLib
339 Status
= FmpDeviceGetSize (&Private
->Descriptor
.Size
);
340 if (EFI_ERROR (Status
)) {
341 Private
->Descriptor
.Size
= 0;
344 Private
->Descriptor
.LastAttemptVersion
= GetLastAttemptVersionFromVariable ();
345 Private
->Descriptor
.LastAttemptStatus
= GetLastAttemptStatusFromVariable ();
348 // Get the hardware instance from FmpDeviceLib
350 Status
= FmpDeviceGetHardwareInstance (&Private
->Descriptor
.HardwareInstance
);
351 if (Status
== EFI_UNSUPPORTED
) {
352 Private
->Descriptor
.HardwareInstance
= 0;
355 Private
->DescriptorPopulated
= TRUE
;
359 Returns information about the current firmware image(s) of the device.
361 This function allows a copy of the current firmware image to be created and saved.
362 The saved copy could later been used, for example, in firmware image recovery or rollback.
364 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
365 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
366 On input, this is the size of the buffer allocated by the caller.
367 On output, it is the size of the buffer returned by the firmware
368 if the buffer was large enough, or the size of the buffer needed
369 to contain the image(s) information if the buffer was too small.
370 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
371 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
372 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
373 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
374 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
375 descriptors or firmware images within this device.
376 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
377 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
378 @param[out] PackageVersion A version number that represents all the firmware images in the device.
379 The format is vendor specific and new version must have a greater value
380 than the old version. If PackageVersion is not supported, the value is
381 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
382 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
383 that package version update is in progress.
384 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
385 package version name. The buffer is allocated by this function with
386 AllocatePool(), and it is the caller's responsibility to free it with a call
389 @retval EFI_SUCCESS The device was successfully updated with the new image.
390 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
391 needed to hold the image(s) information is returned in ImageInfoSize.
392 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
393 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
399 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
400 IN OUT UINTN
*ImageInfoSize
,
401 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
402 OUT UINT32
*DescriptorVersion
,
403 OUT UINT8
*DescriptorCount
,
404 OUT UINTN
*DescriptorSize
,
405 OUT UINT32
*PackageVersion
,
406 OUT CHAR16
**PackageVersionName
410 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
412 Status
= EFI_SUCCESS
;
415 // Retrieve the private context structure
417 Private
= FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This
);
418 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
421 // Check for valid pointer
423 if (ImageInfoSize
== NULL
) {
424 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImageInfo() - ImageInfoSize is NULL.\n"));
425 Status
= EFI_INVALID_PARAMETER
;
430 // Check the buffer size
431 // NOTE: Check this first so caller can get the necessary memory size it must allocate.
433 if (*ImageInfoSize
< (sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
))) {
434 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
435 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: GetImageInfo() - ImageInfoSize is to small.\n"));
436 Status
= EFI_BUFFER_TOO_SMALL
;
441 // Confirm that buffer isn't null
443 if ( (ImageInfo
== NULL
) || (DescriptorVersion
== NULL
) || (DescriptorCount
== NULL
) || (DescriptorSize
== NULL
)
444 || (PackageVersion
== NULL
)) {
445 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImageInfo() - Pointer Parameter is NULL.\n"));
446 Status
= EFI_INVALID_PARAMETER
;
451 // Set the size to whatever we need
453 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
456 // make sure the descriptor has already been loaded
458 PopulateDescriptor (Private
);
461 // Copy the image descriptor
463 CopyMem (ImageInfo
, &Private
->Descriptor
, sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
));
465 *DescriptorVersion
= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION
;
466 *DescriptorCount
= 1;
467 *DescriptorSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
471 *PackageVersion
= 0xFFFFFFFF;
474 // Do not update PackageVersionName since it is not supported in this instance.
483 Retrieves a copy of the current firmware image of the device.
485 This function allows a copy of the current firmware image to be created and saved.
486 The saved copy could later been used, for example, in firmware image recovery or rollback.
488 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
489 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
490 The number is between 1 and DescriptorCount.
491 @param[in, out] Image Points to the buffer where the current image is copied to.
492 @param[in, out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
493 On return, points to the length of the image, in bytes.
495 @retval EFI_SUCCESS The device was successfully updated with the new image.
496 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
497 image. The current buffer size needed to hold the image is returned
499 @retval EFI_INVALID_PARAMETER The Image was NULL.
500 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
501 @retval EFI_UNSUPPORTED The operation is not supported.
502 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
508 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
511 IN OUT UINTN
*ImageSize
515 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
518 Status
= EFI_SUCCESS
;
521 // Retrieve the private context structure
523 Private
= FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This
);
524 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
527 // Check to make sure index is 1 (only 1 image for this device)
529 if (ImageIndex
!= 1) {
530 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - Image Index Invalid.\n"));
531 Status
= EFI_INVALID_PARAMETER
;
535 if (ImageSize
== NULL
) {
536 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - ImageSize Pointer Parameter is NULL.\n"));
537 Status
= EFI_INVALID_PARAMETER
;
542 // Check the buffer size
544 Status
= FmpDeviceGetSize (&Size
);
545 if (EFI_ERROR (Status
)) {
548 if (*ImageSize
< Size
) {
550 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: GetImage() - ImageSize is to small.\n"));
551 Status
= EFI_BUFFER_TOO_SMALL
;
556 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - Image Pointer Parameter is NULL.\n"));
557 Status
= EFI_INVALID_PARAMETER
;
561 Status
= FmpDeviceGetImage (Image
, ImageSize
);
568 Helper function to safely retrieve the FMP header from
569 within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.
571 @param[in] Image Pointer to the image.
572 @param[in] ImageSize Size of the image.
573 @param[out] PayloadSize
575 @retval !NULL Valid pointer to the header.
576 @retval NULL Structure is bad and pointer cannot be found.
581 IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION
*Image
,
582 IN CONST UINTN ImageSize
,
583 OUT UINTN
*PayloadSize
587 // Check to make sure that operation can be safely performed.
589 if (((UINTN
)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
) < (UINTN
)Image
|| \
590 ((UINTN
)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
) >= (UINTN
)Image
+ ImageSize
) {
592 // Pointer overflow. Invalid image.
597 *PayloadSize
= ImageSize
- (sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
);
598 return (VOID
*)((UINT8
*)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
);
602 Helper function to safely calculate the size of all headers
603 within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.
605 @param[in] Image Pointer to the image.
606 @param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function.
608 @retval UINT32>0 Valid size of all the headers.
609 @retval 0 Structure is bad and size cannot be found.
614 IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION
*Image
,
615 IN UINT32 AdditionalHeaderSize
618 UINT32 CalculatedSize
;
620 CalculatedSize
= sizeof (Image
->MonotonicCount
) +
621 AdditionalHeaderSize
+
622 Image
->AuthInfo
.Hdr
.dwLength
;
625 // Check to make sure that operation can be safely performed.
627 if (CalculatedSize
< sizeof (Image
->MonotonicCount
) ||
628 CalculatedSize
< AdditionalHeaderSize
||
629 CalculatedSize
< Image
->AuthInfo
.Hdr
.dwLength
) {
631 // Integer overflow. Invalid image.
636 return CalculatedSize
;
640 Checks if the firmware image is valid for the device.
642 This function allows firmware update application to validate the firmware image without
643 invoking the SetImage() first.
645 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
646 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
647 The number is between 1 and DescriptorCount.
648 @param[in] Image Points to the new image.
649 @param[in] ImageSize Size of the new image in bytes.
650 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
651 if available, additional information if the image is invalid.
653 @retval EFI_SUCCESS The image was successfully checked.
654 @retval EFI_ABORTED The operation is aborted.
655 @retval EFI_INVALID_PARAMETER The Image was NULL.
656 @retval EFI_UNSUPPORTED The operation is not supported.
657 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
663 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
665 IN CONST VOID
*Image
,
667 OUT UINT32
*ImageUpdatable
671 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
673 VOID
*FmpPayloadHeader
;
674 UINTN FmpPayloadSize
;
676 UINT32 FmpHeaderSize
;
680 UINTN PublicKeyDataLength
;
681 UINT8
*PublicKeyDataXdr
;
682 UINT8
*PublicKeyDataXdrEnd
;
684 Status
= EFI_SUCCESS
;
686 FmpPayloadHeader
= NULL
;
693 // Retrieve the private context structure
695 Private
= FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This
);
696 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
699 // make sure the descriptor has already been loaded
701 PopulateDescriptor (Private
);
703 if (ImageUpdatable
== NULL
) {
704 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - ImageUpdatable Pointer Parameter is NULL.\n"));
705 Status
= EFI_INVALID_PARAMETER
;
710 //Set to valid and then if any tests fail it will update this flag.
712 *ImageUpdatable
= IMAGE_UPDATABLE_VALID
;
715 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - Image Pointer Parameter is NULL.\n"));
717 // not sure if this is needed
719 *ImageUpdatable
= IMAGE_UPDATABLE_INVALID
;
720 return EFI_INVALID_PARAMETER
;
723 PublicKeyDataXdr
= PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr
);
724 PublicKeyDataXdrEnd
= PublicKeyDataXdr
+ PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr
);
726 if (PublicKeyDataXdr
== NULL
|| (PublicKeyDataXdr
== PublicKeyDataXdrEnd
)) {
727 DEBUG ((DEBUG_ERROR
, "FmpDxe: Invalid certificate, skipping it.\n"));
728 Status
= EFI_ABORTED
;
731 // Try each key from PcdFmpDevicePkcs7CertBufferXdr
733 for (Index
= 1; PublicKeyDataXdr
< PublicKeyDataXdrEnd
; Index
++) {
737 "FmpDxe: Certificate #%d [%p..%p].\n",
744 if ((PublicKeyDataXdr
+ sizeof (UINT32
)) > PublicKeyDataXdrEnd
) {
746 // Key data extends beyond end of PCD
748 DEBUG ((DEBUG_ERROR
, "FmpDxe: Certificate size extends beyond end of PCD, skipping it.\n"));
749 Status
= EFI_ABORTED
;
753 // Read key length stored in big-endian format
755 PublicKeyDataLength
= SwapBytes32 (*(UINT32
*)(PublicKeyDataXdr
));
757 // Point to the start of the key data
759 PublicKeyDataXdr
+= sizeof (UINT32
);
760 if (PublicKeyDataXdr
+ PublicKeyDataLength
> PublicKeyDataXdrEnd
) {
762 // Key data extends beyond end of PCD
764 DEBUG ((DEBUG_ERROR
, "FmpDxe: Certificate extends beyond end of PCD, skipping it.\n"));
765 Status
= EFI_ABORTED
;
768 PublicKeyData
= PublicKeyDataXdr
;
769 Status
= AuthenticateFmpImage (
770 (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
,
775 if (!EFI_ERROR (Status
)) {
778 PublicKeyDataXdr
+= PublicKeyDataLength
;
779 PublicKeyDataXdr
= (UINT8
*)ALIGN_POINTER (PublicKeyDataXdr
, sizeof (UINT32
));
783 if (EFI_ERROR (Status
)) {
784 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - Authentication Failed %r.\n", Status
));
789 // Check to make sure index is 1
791 if (ImageIndex
!= 1) {
792 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - Image Index Invalid.\n"));
793 *ImageUpdatable
= IMAGE_UPDATABLE_INVALID_TYPE
;
794 Status
= EFI_SUCCESS
;
800 // Check the FmpPayloadHeader
802 FmpPayloadHeader
= GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, ImageSize
, &FmpPayloadSize
);
803 if (FmpPayloadHeader
== NULL
) {
804 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpHeader failed.\n"));
805 Status
= EFI_ABORTED
;
808 Status
= GetFmpPayloadHeaderVersion (FmpPayloadHeader
, FmpPayloadSize
, &Version
);
809 if (EFI_ERROR (Status
)) {
810 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderVersion failed %r.\n", Status
));
811 *ImageUpdatable
= IMAGE_UPDATABLE_INVALID
;
812 Status
= EFI_SUCCESS
;
817 // Check the lowest supported version
819 if (Version
< Private
->Descriptor
.LowestSupportedImageVersion
) {
822 "FmpDxe: CheckTheImage() - Version Lower than lowest supported version. 0x%08X < 0x%08X\n",
823 Version
, Private
->Descriptor
.LowestSupportedImageVersion
)
825 *ImageUpdatable
= IMAGE_UPDATABLE_INVALID_OLD
;
826 Status
= EFI_SUCCESS
;
831 // Get the FmpHeaderSize so we can determine the real payload size
833 Status
= GetFmpPayloadHeaderSize (FmpPayloadHeader
, FmpPayloadSize
, &FmpHeaderSize
);
834 if (EFI_ERROR (Status
)) {
835 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status
));
836 *ImageUpdatable
= IMAGE_UPDATABLE_INVALID
;
837 Status
= EFI_SUCCESS
;
842 // Call FmpDevice Lib Check Image on the
843 // Raw payload. So all headers need stripped off
845 AllHeaderSize
= GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, FmpHeaderSize
);
846 if (AllHeaderSize
== 0) {
847 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetAllHeaderSize failed.\n"));
848 Status
= EFI_ABORTED
;
851 RawSize
= ImageSize
- AllHeaderSize
;
854 // FmpDeviceLib CheckImage function to do any specific checks
856 Status
= FmpDeviceCheckImage ((((UINT8
*)Image
) + AllHeaderSize
), RawSize
, ImageUpdatable
);
857 if (EFI_ERROR (Status
)) {
858 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", Status
));
866 Updates the firmware image of the device.
868 This function updates the hardware with the new firmware image.
869 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
870 If the firmware image is updatable, the function should perform the following minimal validations
871 before proceeding to do the firmware image update.
872 - Validate the image authentication if image has attribute
873 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
874 EFI_SECURITY_VIOLATION if the validation fails.
875 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
876 the image is unsupported. The function can optionally provide more detailed information on
877 why the image is not a supported image.
878 - Validate the data from VendorCode if not null. Image validation must be performed before
879 VendorCode data validation. VendorCode data is ignored or considered invalid if image
880 validation failed. The function returns EFI_ABORTED if the data is invalid.
882 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
883 the caller did not specify the policy or use the default policy. As an example, vendor can implement
884 a policy to allow an option to force a firmware image update when the abort reason is due to the new
885 firmware image version is older than the current firmware image version or bad image checksum.
886 Sensitive operations such as those wiping the entire firmware image and render the device to be
887 non-functional should be encoded in the image itself rather than passed with the VendorCode.
888 AbortReason enables vendor to have the option to provide a more detailed description of the abort
889 reason to the caller.
891 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
892 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
893 The number is between 1 and DescriptorCount.
894 @param[in] Image Points to the new image.
895 @param[in] ImageSize Size of the new image in bytes.
896 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
897 Null indicates the caller did not specify the policy or use the default policy.
898 @param[in] Progress A function used by the driver to report the progress of the firmware update.
899 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
900 details for the aborted operation. The buffer is allocated by this function
901 with AllocatePool(), and it is the caller's responsibility to free it with a
904 @retval EFI_SUCCESS The device was successfully updated with the new image.
905 @retval EFI_ABORTED The operation is aborted.
906 @retval EFI_INVALID_PARAMETER The Image was NULL.
907 @retval EFI_UNSUPPORTED The operation is not supported.
908 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
914 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
916 IN CONST VOID
*Image
,
918 IN CONST VOID
*VendorCode
,
919 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
,
920 OUT CHAR16
**AbortReason
924 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
926 BOOLEAN BooleanValue
;
927 UINT32 FmpHeaderSize
;
929 UINTN FmpPayloadSize
;
930 UINT32 AllHeaderSize
;
931 UINT32 IncommingFwVersion
;
932 UINT32 LastAttemptStatus
;
934 UINT32 LowestSupportedVersion
;
936 Status
= EFI_SUCCESS
;
938 BooleanValue
= FALSE
;
943 IncommingFwVersion
= 0;
944 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL
;
947 // Retrieve the private context structure
949 Private
= FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This
);
950 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
952 SetLastAttemptVersionInVariable (IncommingFwVersion
); //set to 0 to clear any previous results.
955 // if we have locked the device, then skip the set operation.
956 // it should be blocked by hardware too but we can catch here even faster
958 if (Private
->FmpDeviceLocked
) {
959 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Device is already locked. Can't update.\n"));
960 Status
= EFI_UNSUPPORTED
;
965 // Call check image to verify the image
967 Status
= CheckTheImage (This
, ImageIndex
, Image
, ImageSize
, &Updateable
);
968 if (EFI_ERROR (Status
)) {
969 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Check The Image failed with %r.\n", Status
));
970 if (Status
== EFI_SECURITY_VIOLATION
) {
971 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR
;
977 // No functional error in CheckTheImage. Attempt to get the Version to
978 // support better error reporting.
980 FmpHeader
= GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, ImageSize
, &FmpPayloadSize
);
981 if (FmpHeader
== NULL
) {
982 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetFmpHeader failed.\n"));
983 Status
= EFI_ABORTED
;
986 Status
= GetFmpPayloadHeaderVersion (FmpHeader
, FmpPayloadSize
, &IncommingFwVersion
);
987 if (!EFI_ERROR (Status
)) {
989 // Set to actual value
991 SetLastAttemptVersionInVariable (IncommingFwVersion
);
995 if (Updateable
!= IMAGE_UPDATABLE_VALID
) {
998 "FmpDxed: SetTheImage() - Check The Image returned that the Image was not valid for update. Updatable value = 0x%X.\n",
1001 Status
= EFI_ABORTED
;
1005 if (Progress
== NULL
) {
1006 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Invalid progress callback\n"));
1007 Status
= EFI_INVALID_PARAMETER
;
1011 mProgressFunc
= Progress
;
1014 // Checking the image is at least 1%
1016 Status
= Progress (1);
1017 if (EFI_ERROR (Status
)) {
1018 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Progress Callback failed with Status %r.\n", Status
));
1022 //Check System Power
1024 Status
= CheckSystemPower (&BooleanValue
);
1025 if (EFI_ERROR (Status
)) {
1026 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemPower - API call failed %r.\n", Status
));
1029 if (!BooleanValue
) {
1030 Status
= EFI_ABORTED
;
1033 "FmpDxe: SetTheImage() - CheckSystemPower - returned False. Update not allowed due to System Power.\n")
1035 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT
;
1042 //Check System Thermal
1044 Status
= CheckSystemThermal (&BooleanValue
);
1045 if (EFI_ERROR (Status
)) {
1046 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemThermal - API call failed %r.\n", Status
));
1049 if (!BooleanValue
) {
1050 Status
= EFI_ABORTED
;
1053 "FmpDxe: SetTheImage() - CheckSystemThermal - returned False. Update not allowed due to System Thermal.\n")
1061 //Check System Environment
1063 Status
= CheckSystemEnvironment (&BooleanValue
);
1064 if (EFI_ERROR (Status
)) {
1065 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemEnvironment - API call failed %r.\n", Status
));
1068 if (!BooleanValue
) {
1069 Status
= EFI_ABORTED
;
1072 "FmpDxe: SetTheImage() - CheckSystemEnvironment - returned False. Update not allowed due to System Environment.\n")
1080 // Save LastAttemptStatus as error so that if SetImage never returns the error
1081 // state is recorded.
1083 SetLastAttemptStatusInVariable (LastAttemptStatus
);
1086 // Strip off all the headers so the device can process its firmware
1088 Status
= GetFmpPayloadHeaderSize (FmpHeader
, FmpPayloadSize
, &FmpHeaderSize
);
1089 if (EFI_ERROR (Status
)) {
1090 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status
));
1094 AllHeaderSize
= GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, FmpHeaderSize
);
1095 if (AllHeaderSize
== 0) {
1096 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetAllHeaderSize failed.\n"));
1097 Status
= EFI_ABORTED
;
1102 // Indicate that control is handed off to FmpDeviceLib
1107 //Copy the requested image to the firmware using the FmpDeviceLib
1109 Status
= FmpDeviceSetImage (
1110 (((UINT8
*)Image
) + AllHeaderSize
),
1111 ImageSize
- AllHeaderSize
,
1117 if (EFI_ERROR (Status
)) {
1118 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() SetImage from FmpDeviceLib failed. Status = %r.\n", Status
));
1124 // Finished the update without error
1125 // Indicate that control has been returned from FmpDeviceLib
1130 // Update the version stored in variable
1132 if (!Private
->RuntimeVersionSupported
) {
1133 Version
= DEFAULT_VERSION
;
1134 GetFmpPayloadHeaderVersion (FmpHeader
, FmpPayloadSize
, &Version
);
1135 SetVersionInVariable (Version
);
1139 // Update lowest supported variable
1142 LowestSupportedVersion
= DEFAULT_LOWESTSUPPORTEDVERSION
;
1143 GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader
, FmpPayloadSize
, &LowestSupportedVersion
);
1144 SetLowestSupportedVersionInVariable (LowestSupportedVersion
);
1147 LastAttemptStatus
= LAST_ATTEMPT_STATUS_SUCCESS
;
1150 mProgressFunc
= NULL
;
1151 SetLastAttemptStatusInVariable (LastAttemptStatus
);
1153 if (Progress
!= NULL
) {
1155 // Set progress to 100 after everything is done including recording Status.
1161 // Need repopulate after SetImage is called to
1162 // update LastAttemptVersion and LastAttemptStatus.
1164 Private
->DescriptorPopulated
= FALSE
;
1170 Returns information about the firmware package.
1172 This function returns package information.
1174 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
1175 @param[out] PackageVersion A version number that represents all the firmware images in the device.
1176 The format is vendor specific and new version must have a greater value
1177 than the old version. If PackageVersion is not supported, the value is
1178 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
1179 comparison is to be performed using PackageVersionName. A value of
1180 0xFFFFFFFD indicates that package version update is in progress.
1181 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
1182 the package version name. The buffer is allocated by this function with
1183 AllocatePool(), and it is the caller's responsibility to free it with a
1185 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
1186 package version name. A value of 0 indicates the device does not support
1187 update of package version name. Length is the number of Unicode characters,
1188 including the terminating null character.
1189 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
1190 Definitions' for possible returned values of this parameter. A value of 1
1191 indicates the attribute is supported and the current setting value is
1192 indicated in AttributesSetting. A value of 0 indicates the attribute is not
1193 supported and the current setting value in AttributesSetting is meaningless.
1194 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
1195 values of this parameter
1197 @retval EFI_SUCCESS The package information was successfully returned.
1198 @retval EFI_UNSUPPORTED The operation is not supported.
1204 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
1205 OUT UINT32
*PackageVersion
,
1206 OUT CHAR16
**PackageVersionName
,
1207 OUT UINT32
*PackageVersionNameMaxLen
,
1208 OUT UINT64
*AttributesSupported
,
1209 OUT UINT64
*AttributesSetting
1212 return EFI_UNSUPPORTED
;
1216 Updates information about the firmware package.
1218 This function updates package information.
1219 This function returns EFI_UNSUPPORTED if the package information is not updatable.
1220 VendorCode enables vendor to implement vendor-specific package information update policy.
1221 Null if the caller did not specify this policy or use the default policy.
1223 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
1224 @param[in] Image Points to the authentication image.
1225 Null if authentication is not required.
1226 @param[in] ImageSize Size of the authentication image in bytes.
1227 0 if authentication is not required.
1228 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
1229 image update policy.
1230 Null indicates the caller did not specify this policy or use
1232 @param[in] PackageVersion The new package version.
1233 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
1234 the package version name.
1235 The string length is equal to or less than the value returned in
1236 PackageVersionNameMaxLen.
1238 @retval EFI_SUCCESS The device was successfully updated with the new package
1240 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
1241 returned in PackageVersionNameMaxLen.
1242 @retval EFI_UNSUPPORTED The operation is not supported.
1243 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
1249 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
1250 IN CONST VOID
*Image
,
1252 IN CONST VOID
*VendorCode
,
1253 IN UINT32 PackageVersion
,
1254 IN CONST CHAR16
*PackageVersionName
1257 return EFI_UNSUPPORTED
;
1261 Event notification function that is invoked when the event GUID specified by
1262 PcdFmpDeviceLockEventGuid is signaled.
1264 @param[in] Event Event whose notification function is being invoked.
1265 @param[in] Context The pointer to the notification function's context,
1266 which is implementation-dependent.
1270 FmpDxeLockEventNotify (
1276 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
1278 Private
= (FIRMWARE_MANAGEMENT_PRIVATE_DATA
*)Context
;
1280 if (!Private
->FmpDeviceLocked
) {
1282 // Lock the firmware device
1284 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
1285 Status
= FmpDeviceLock();
1286 if (EFI_ERROR (Status
)) {
1287 if (Status
!= EFI_UNSUPPORTED
) {
1288 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLock() returned error. Status = %r\n", Status
));
1290 DEBUG ((DEBUG_WARN
, "FmpDxe: FmpDeviceLock() returned error. Status = %r\n", Status
));
1293 Private
->FmpDeviceLocked
= TRUE
;
1298 Function to install FMP instance.
1300 @param[in] Handle The device handle to install a FMP instance on.
1302 @retval EFI_SUCCESS FMP Installed
1303 @retval EFI_INVALID_PARAMETER Handle was invalid
1304 @retval other Error installing FMP
1309 InstallFmpInstance (
1310 IN EFI_HANDLE Handle
1314 EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*Fmp
;
1315 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
1317 DEBUG ((DEBUG_ERROR
, "InstallFmpInstance: Entry\n"));
1320 // Only allow a single FMP Protocol instance to be installed
1322 Status
= gBS
->OpenProtocol (
1324 &gEfiFirmwareManagementProtocolGuid
,
1328 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1330 if (!EFI_ERROR (Status
)) {
1331 return EFI_ALREADY_STARTED
;
1335 // Allocate FMP Protocol instance
1337 Private
= AllocateCopyPool (
1338 sizeof (mFirmwareManagementPrivateDataTemplate
),
1339 &mFirmwareManagementPrivateDataTemplate
1341 if (Private
== NULL
) {
1342 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to allocate memory for private structure.\n"));
1343 Status
= EFI_OUT_OF_RESOURCES
;
1348 // Initialize private context data structure
1350 DEBUG ((DEBUG_ERROR
, "InstallFmpInstance: Initialize private context data structure\n"));
1352 Private
->Handle
= Handle
;
1354 Private
->FmpDeviceContext
= NULL
;
1355 Status
= FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
1356 if (Status
== EFI_UNSUPPORTED
) {
1357 Private
->FmpDeviceContext
= NULL
;
1358 } else if (EFI_ERROR (Status
)) {
1362 DEBUG ((DEBUG_ERROR
, "InstallFmpInstance: Lock events\n"));
1364 if (IsLockFmpDeviceAtLockEventGuidRequired ()) {
1366 // Lock all UEFI Variables used by this module.
1368 Status
= LockAllFmpVariables ();
1369 if (EFI_ERROR (Status
)) {
1370 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to lock variables. Status = %r.\n", Status
));
1372 DEBUG ((DEBUG_INFO
, "FmpDxe: All variables locked\n"));
1376 // Create and register notify function to lock the FMP device.
1378 Status
= gBS
->CreateEventEx (
1381 FmpDxeLockEventNotify
,
1384 &Private
->FmpDeviceLockEvent
1386 if (EFI_ERROR (Status
)) {
1387 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to register notification. Status = %r\n", Status
));
1389 ASSERT_EFI_ERROR (Status
);
1391 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: Not registering notification to call FmpDeviceLock() because mfg mode\n"));
1395 // Install FMP Protocol and FMP Progress Protocol
1397 DEBUG ((DEBUG_ERROR
, "InstallFmpInstance: Install FMP Protocol and FMP Progress Protocol\n"));
1399 Status
= gBS
->InstallMultipleProtocolInterfaces (
1401 &gEfiFirmwareManagementProtocolGuid
, &Private
->Fmp
,
1402 &gEdkiiFirmwareManagementProgressProtocolGuid
, &mFmpProgress
,
1406 if (EFI_ERROR (Status
)) {
1407 DEBUG ((DEBUG_ERROR
, "FmpDxe: Protocol install error. Status = %r.\n", Status
));
1411 DEBUG ((DEBUG_INFO
, "FmpDxe: Protocols Installed!\n"));
1415 if (EFI_ERROR (Status
)) {
1416 if (Private
!= NULL
) {
1417 if (Private
->FmpDeviceLockEvent
!= NULL
) {
1418 gBS
->CloseEvent (Private
->FmpDeviceLockEvent
);
1428 Function to uninstall FMP instance.
1430 @param[in] Handle The device handle to install a FMP instance on.
1432 @retval EFI_SUCCESS FMP Installed
1433 @retval EFI_INVALID_PARAMETER Handle was invalid
1434 @retval other Error installing FMP
1439 UninstallFmpInstance (
1440 IN EFI_HANDLE Handle
1444 EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*Fmp
;
1445 FIRMWARE_MANAGEMENT_PRIVATE_DATA
*Private
;
1447 Status
= gBS
->OpenProtocol (
1449 &gEfiFirmwareManagementProtocolGuid
,
1453 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1455 if (EFI_ERROR (Status
)) {
1459 Private
= FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (Fmp
);
1460 FmpDeviceSetContext (Private
->Handle
, &Private
->FmpDeviceContext
);
1462 if (Private
->FmpDeviceLockEvent
!= NULL
) {
1463 gBS
->CloseEvent (Private
->FmpDeviceLockEvent
);
1466 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1468 &gEfiFirmwareManagementProtocolGuid
, &Private
->Fmp
,
1469 &gEdkiiFirmwareManagementProgressProtocolGuid
, &mFmpProgress
,
1472 if (EFI_ERROR (Status
)) {
1476 FmpDeviceSetContext (NULL
, &Private
->FmpDeviceContext
);
1484 Unloads the application and its installed protocol.
1486 @param ImageHandle Handle that identifies the image to be unloaded.
1487 @param SystemTable The system table.
1489 @retval EFI_SUCCESS The image has been unloaded.
1494 FmpDxeLibDestructor (
1495 IN EFI_HANDLE ImageHandle
,
1496 IN EFI_SYSTEM_TABLE
*SystemTable
1499 if (mFmpSingleInstance
) {
1500 return UninstallFmpInstance (ImageHandle
);
1506 Main entry for this driver/library.
1508 @param[in] ImageHandle Image handle this driver.
1509 @param[in] SystemTable Pointer to SystemTable.
1515 IN EFI_HANDLE ImageHandle
,
1516 IN EFI_SYSTEM_TABLE
*SystemTable
1522 // Verify that a new FILE_GUID value has been provided in the <Defines>
1523 // section of this module. The FILE_GUID is the ESRT GUID that must be
1524 // unique for each updatable firmware image.
1526 if (CompareGuid (&mDefaultModuleFileGuid
, &gEfiCallerIdGuid
)) {
1527 DEBUG ((DEBUG_ERROR
, "FmpDxe: Use of default FILE_GUID detected. FILE_GUID must be set to a unique value.\n"));
1529 return EFI_UNSUPPORTED
;
1533 // Get the ImageIdName value for the EFI_FIRMWARE_IMAGE_DESCRIPTOR from a PCD.
1535 mImageIdName
= (CHAR16
*) PcdGetPtr (PcdFmpDeviceImageIdName
);
1536 if (PcdGetSize (PcdFmpDeviceImageIdName
) <= 2 || mImageIdName
[0] == 0) {
1538 // PcdFmpDeviceImageIdName must be set to a non-empty Unicode string
1540 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib PcdFmpDeviceImageIdName is an empty string.\n"));
1546 // Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.
1551 // Fill in FMP Progress Protocol fields for Version 1
1553 mFmpProgress
.Version
= 1;
1554 mFmpProgress
.ProgressBarForegroundColor
.Raw
= PcdGet32 (PcdFmpDeviceProgressColor
);
1555 mFmpProgress
.WatchdogSeconds
= PcdGet8 (PcdFmpDeviceProgressWatchdogTimeInSeconds
);
1557 // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.
1558 // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then
1559 // gEfiEndOfDxeEventGroupGuid is used.
1561 mLockGuid
= &gEfiEndOfDxeEventGroupGuid
;
1562 if (PcdGetSize (PcdFmpDeviceLockEventGuid
) == sizeof (EFI_GUID
)) {
1563 mLockGuid
= (EFI_GUID
*)PcdGetPtr (PcdFmpDeviceLockEventGuid
);
1565 DEBUG ((DEBUG_INFO
, "FmpDxe: Lock GUID: %g\n", mLockGuid
));
1568 // Register with library the install function so if the library uses
1569 // UEFI driver model/driver binding protocol it can install FMP on its device handle
1570 // If library is simple lib that does not use driver binding then it should return
1571 // unsupported and this will install the FMP instance on the ImageHandle
1573 Status
= RegisterFmpInstaller (InstallFmpInstance
);
1574 if (Status
== EFI_UNSUPPORTED
) {
1575 mFmpSingleInstance
= TRUE
;
1576 DEBUG ((DEBUG_INFO
, "FmpDxe: FmpDeviceLib registration returned EFI_UNSUPPORTED. Installing single FMP instance.\n"));
1577 Status
= RegisterFmpUninstaller (UninstallFmpInstance
);
1578 if (Status
== EFI_UNSUPPORTED
) {
1579 Status
= InstallFmpInstance (ImageHandle
);
1581 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n"));
1582 Status
= EFI_UNSUPPORTED
;
1584 } else if (EFI_ERROR (Status
)) {
1585 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib registration returned %r. No FMP installed.\n", Status
));
1589 "FmpDxe: FmpDeviceLib registration returned EFI_SUCCESS. Expect FMP to be installed during the BDS/Device connection phase.\n"
1591 Status
= RegisterFmpUninstaller (UninstallFmpInstance
);
1592 if (EFI_ERROR (Status
)) {
1593 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib RegisterFmpInstaller and RegisterFmpUninstaller do not match.\n"));