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, Intel Corporation. All rights reserved.<BR>
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <Library/DebugLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/FmpAuthenticationLib.h>
38 #include <Library/FmpDeviceLib.h>
39 #include <Library/FmpPayloadHeaderLib.h>
40 #include <Library/CapsuleUpdatePolicyLib.h>
41 #include <Protocol/FirmwareManagement.h>
42 #include <Protocol/FirmwareManagementProgress.h>
43 #include <Guid/SystemResourceTable.h>
44 #include <Guid/EventGroup.h>
45 #include "VariableSupport.h"
47 #define VERSION_STRING_NOT_SUPPORTED L"VERSION STRING NOT SUPPORTED"
48 #define VERSION_STRING_NOT_AVAILABLE L"VERSION STRING NOT AVAILABLE"
51 Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches
52 the test key. PcdFmpDeviceTestKeySha256Digest contains the SHA256 hash of
53 the test key. For each key in PcdFmpDevicePkcs7CertBufferXdr, compute the
54 SHA256 hash and compare it to PcdFmpDeviceTestKeySha256Digest. If the
55 SHA256 hash matches or there is then error computing the SHA256 hash, then
56 set PcdTestKeyUsed to TRUE. Skip this check if PcdTestKeyUsed is already
57 TRUE or PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE
66 /// FILE_GUID from FmpDxe.inf. When FmpDxe.inf is used in a platform, the
67 /// FILE_GUID must always be overridden in the <Defines> section to provide
68 /// the ESRT GUID value associated with the updatable firmware image. A
69 /// check is made in this module's driver entry point to verify that a
70 /// new FILE_GUID value has been defined.
72 const EFI_GUID mDefaultModuleFileGuid
= {
73 0x78ef0a56, 0x1cf0, 0x4535, { 0xb5, 0xda, 0xf6, 0xfd, 0x2f, 0x40, 0x5a, 0x11 }
76 EFI_FIRMWARE_IMAGE_DESCRIPTOR mDesc
;
77 BOOLEAN mDescriptorPopulated
= FALSE
;
78 BOOLEAN mRuntimeVersionSupported
= TRUE
;
79 BOOLEAN mFmpInstalled
= FALSE
;
82 /// Function pointer to progress function
84 EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS mProgressFunc
= NULL
;
85 BOOLEAN mProgressSupported
= FALSE
;
87 CHAR16
*mImageIdName
= NULL
;
88 UINT64 mImageId
= 0x1;
89 CHAR16
*mVersionName
= NULL
;
91 EFI_EVENT mFmpDeviceLockEvent
;
92 BOOLEAN mFmpDeviceLocked
= FALSE
;
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 (!mProgressSupported
) {
128 if (mProgressFunc
== NULL
) {
133 // Reserve 6% - 98% for the FmpDeviceLib. Call the real progress function.
135 Status
= mProgressFunc (((Completion
* 92) / 100) + 6);
137 if (Status
== EFI_UNSUPPORTED
) {
138 mProgressSupported
= FALSE
;
139 mProgressFunc
= NULL
;
146 Returns a pointer to the ImageTypeId GUID value. An attempt is made to get
147 the GUID value from the FmpDeviceLib. If the FmpDeviceLib does not provide
148 a GUID value, then gEfiCallerIdGuid is returned.
150 @return The ImageTypeId GUID
159 EFI_GUID
*FmpDeviceLibGuid
;
161 FmpDeviceLibGuid
= NULL
;
162 Status
= FmpDeviceGetImageTypeIdGuidPtr (&FmpDeviceLibGuid
);
163 if (EFI_ERROR (Status
)) {
164 if (Status
!= EFI_UNSUPPORTED
) {
165 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid error %r\n", Status
));
167 return &gEfiCallerIdGuid
;
169 if (FmpDeviceLibGuid
== NULL
) {
170 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib GetImageTypeIdGuidPtr() returned invalid GUID\n"));
171 return &gEfiCallerIdGuid
;
173 return FmpDeviceLibGuid
;
177 Returns a pointer to the Null-terminated Unicode ImageIdName string.
179 @return Null-terminated Unicode ImageIdName string.
183 GetImageTypeNameString (
191 Lowest supported version is a combo of three parts.
192 1. Check if the device lib has a lowest supported version
193 2. Check if we have a variable for lowest supported version (this will be updated with each capsule applied)
194 3. Check Fixed at build PCD
196 Take the largest value
200 GetLowestSupportedVersion (
205 UINT32 DeviceLibLowestSupportedVersion
;
206 UINT32 VariableLowestSupportedVersion
;
210 // Get the LowestSupportedVersion.
213 if (!IsLowestSupportedVersionCheckRequired ()) {
215 // Any Version can pass the 0 LowestSupportedVersion check.
220 ReturnLsv
= PcdGet32 (PcdFmpDeviceBuildTimeLowestSupportedVersion
);
223 // Check the FmpDeviceLib
225 Status
= FmpDeviceGetLowestSupportedVersion (&DeviceLibLowestSupportedVersion
);
226 if (EFI_ERROR (Status
)) {
227 DeviceLibLowestSupportedVersion
= DEFAULT_LOWESTSUPPORTEDVERSION
;
230 if (DeviceLibLowestSupportedVersion
> ReturnLsv
) {
231 ReturnLsv
= DeviceLibLowestSupportedVersion
;
235 // Check the lowest supported version UEFI variable for this device
237 VariableLowestSupportedVersion
= GetLowestSupportedVersionFromVariable();
238 if (VariableLowestSupportedVersion
> ReturnLsv
) {
239 ReturnLsv
= VariableLowestSupportedVersion
;
243 // Return the largest value
249 Populates the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure in the module global
260 mDesc
.ImageIndex
= 1;
261 CopyGuid (&mDesc
.ImageTypeId
, GetImageTypeIdGuid());
262 mDesc
.ImageId
= mImageId
;
263 mDesc
.ImageIdName
= GetImageTypeNameString();
266 // Get the version. Some devices don't support getting the firmware version
267 // at runtime. If FmpDeviceLib does not support returning a version, then
268 // it is stored in a UEFI variable.
270 Status
= FmpDeviceGetVersion (&mDesc
.Version
);
271 if (Status
== EFI_UNSUPPORTED
) {
272 mRuntimeVersionSupported
= FALSE
;
273 mDesc
.Version
= GetVersionFromVariable();
274 } else if (EFI_ERROR (Status
)) {
276 // Unexpected error. Use default version.
278 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetVersion() from FmpDeviceLib (%s) returned %r\n", GetImageTypeNameString(), Status
));
279 mDesc
.Version
= DEFAULT_VERSION
;
283 // Free the current version name. Shouldn't really happen but this populate
284 // function could be called multiple times (to refresh).
286 if (mVersionName
!= NULL
) {
287 FreePool (mVersionName
);
292 // Attempt to get the version string from the FmpDeviceLib
294 Status
= FmpDeviceGetVersionString (&mVersionName
);
295 if (Status
== EFI_UNSUPPORTED
) {
296 DEBUG ((DEBUG_INFO
, "FmpDxe: GetVersionString() unsupported in FmpDeviceLib.\n"));
297 mVersionName
= AllocateCopyPool (
298 sizeof (VERSION_STRING_NOT_SUPPORTED
),
299 VERSION_STRING_NOT_SUPPORTED
301 } else if (EFI_ERROR (Status
)) {
302 DEBUG ((DEBUG_INFO
, "FmpDxe: GetVersionString() not available in FmpDeviceLib.\n"));
303 mVersionName
= AllocateCopyPool (
304 sizeof (VERSION_STRING_NOT_AVAILABLE
),
305 VERSION_STRING_NOT_AVAILABLE
309 mDesc
.VersionName
= mVersionName
;
311 mDesc
.LowestSupportedImageVersion
= GetLowestSupportedVersion();
314 // Get attributes from the FmpDeviceLib
316 FmpDeviceGetAttributes (&mDesc
.AttributesSupported
, &mDesc
.AttributesSetting
);
319 // Force set the updatable bits in the attributes;
321 mDesc
.AttributesSupported
|= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
;
322 mDesc
.AttributesSetting
|= IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
;
325 // Force set the authentication bits in the attributes;
327 mDesc
.AttributesSupported
|= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
);
328 mDesc
.AttributesSetting
|= (IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
);
330 mDesc
.Compatibilities
= 0;
333 // Get the size of the firmware image from the FmpDeviceLib
335 Status
= FmpDeviceGetSize (&mDesc
.Size
);
336 if (EFI_ERROR (Status
)) {
340 mDesc
.LastAttemptVersion
= GetLastAttemptVersionFromVariable ();
341 mDesc
.LastAttemptStatus
= GetLastAttemptStatusFromVariable ();
343 mDescriptorPopulated
= TRUE
;
347 Returns information about the current firmware image(s) of the device.
349 This function allows a copy of the current firmware image to be created and saved.
350 The saved copy could later been used, for example, in firmware image recovery or rollback.
352 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
353 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
354 On input, this is the size of the buffer allocated by the caller.
355 On output, it is the size of the buffer returned by the firmware
356 if the buffer was large enough, or the size of the buffer needed
357 to contain the image(s) information if the buffer was too small.
358 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
359 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
360 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
361 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
362 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
363 descriptors or firmware images within this device.
364 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
365 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
366 @param[out] PackageVersion A version number that represents all the firmware images in the device.
367 The format is vendor specific and new version must have a greater value
368 than the old version. If PackageVersion is not supported, the value is
369 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
370 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
371 that package version update is in progress.
372 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
373 package version name. The buffer is allocated by this function with
374 AllocatePool(), and it is the caller's responsibility to free it with a call
377 @retval EFI_SUCCESS The device was successfully updated with the new image.
378 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
379 needed to hold the image(s) information is returned in ImageInfoSize.
380 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
381 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
387 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
388 IN OUT UINTN
*ImageInfoSize
,
389 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
390 OUT UINT32
*DescriptorVersion
,
391 OUT UINT8
*DescriptorCount
,
392 OUT UINTN
*DescriptorSize
,
393 OUT UINT32
*PackageVersion
,
394 OUT CHAR16
**PackageVersionName
399 Status
= EFI_SUCCESS
;
402 // Check for valid pointer
404 if (ImageInfoSize
== NULL
) {
405 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImageInfo() - ImageInfoSize is NULL.\n"));
406 Status
= EFI_INVALID_PARAMETER
;
411 // Check the buffer size
412 // NOTE: Check this first so caller can get the necessary memory size it must allocate.
414 if (*ImageInfoSize
< (sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
))) {
415 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
416 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: GetImageInfo() - ImageInfoSize is to small.\n"));
417 Status
= EFI_BUFFER_TOO_SMALL
;
422 // Confirm that buffer isn't null
424 if ( (ImageInfo
== NULL
) || (DescriptorVersion
== NULL
) || (DescriptorCount
== NULL
) || (DescriptorSize
== NULL
)
425 || (PackageVersion
== NULL
)) {
426 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImageInfo() - Pointer Parameter is NULL.\n"));
427 Status
= EFI_INVALID_PARAMETER
;
432 // Set the size to whatever we need
434 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
437 if (!mDescriptorPopulated
) {
438 PopulateDescriptor();
442 // Copy the image descriptor
444 CopyMem (ImageInfo
, &mDesc
, sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
));
446 *DescriptorVersion
= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION
;
447 *DescriptorCount
= 1;
448 *DescriptorSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
452 *PackageVersion
= 0xFFFFFFFF;
455 // Do not update PackageVersionName since it is not supported in this instance.
464 Retrieves a copy of the current firmware image of the device.
466 This function allows a copy of the current firmware image to be created and saved.
467 The saved copy could later been used, for example, in firmware image recovery or rollback.
469 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
470 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
471 The number is between 1 and DescriptorCount.
472 @param[out] Image Points to the buffer where the current image is copied to.
473 @param[out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
474 On return, points to the length of the image, in bytes.
476 @retval EFI_SUCCESS The device was successfully updated with the new image.
477 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
478 image. The current buffer size needed to hold the image is returned
480 @retval EFI_INVALID_PARAMETER The Image was NULL.
481 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
482 @retval EFI_UNSUPPORTED The operation is not supported.
483 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
489 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
492 IN OUT UINTN
*ImageSize
498 Status
= EFI_SUCCESS
;
501 // Check to make sure index is 1 (only 1 image for this device)
503 if (ImageIndex
!= 1) {
504 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - Image Index Invalid.\n"));
505 Status
= EFI_INVALID_PARAMETER
;
509 if ((ImageSize
== NULL
)) {
510 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - ImageSize Pointer Parameter is NULL.\n"));
511 Status
= EFI_INVALID_PARAMETER
;
516 // Check the buffer size
518 Status
= FmpDeviceGetSize (&Size
);
519 if (EFI_ERROR (Status
)) {
522 if (*ImageSize
< Size
) {
524 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: GetImage() - ImageSize is to small.\n"));
525 Status
= EFI_BUFFER_TOO_SMALL
;
530 DEBUG ((DEBUG_ERROR
, "FmpDxe: GetImage() - Image Pointer Parameter is NULL.\n"));
531 Status
= EFI_INVALID_PARAMETER
;
535 Status
= FmpDeviceGetImage (Image
, ImageSize
);
542 Helper function to safely retrieve the FMP header from
543 within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.
545 @param[in] Image Pointer to the image.
546 @param[in] ImageSize Size of the image.
547 @param[out] PayloadSize
549 @retval !NULL Valid pointer to the header.
550 @retval NULL Structure is bad and pointer cannot be found.
555 IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION
*Image
,
556 IN CONST UINTN ImageSize
,
557 OUT UINTN
*PayloadSize
561 // Check to make sure that operation can be safely performed.
563 if (((UINTN
)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
) < (UINTN
)Image
|| \
564 ((UINTN
)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
) >= (UINTN
)Image
+ ImageSize
) {
566 // Pointer overflow. Invalid image.
571 *PayloadSize
= ImageSize
- (sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
);
572 return (VOID
*)((UINT8
*)Image
+ sizeof (Image
->MonotonicCount
) + Image
->AuthInfo
.Hdr
.dwLength
);
576 Helper function to safely calculate the size of all headers
577 within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure.
579 @param[in] Image Pointer to the image.
580 @param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function.
582 @retval UINT32>0 Valid size of all the headers.
583 @retval 0 Structure is bad and size cannot be found.
588 IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION
*Image
,
589 IN UINT32 AdditionalHeaderSize
592 UINT32 CalculatedSize
;
594 CalculatedSize
= sizeof (Image
->MonotonicCount
) +
595 AdditionalHeaderSize
+
596 Image
->AuthInfo
.Hdr
.dwLength
;
599 // Check to make sure that operation can be safely performed.
601 if (CalculatedSize
< sizeof (Image
->MonotonicCount
) ||
602 CalculatedSize
< AdditionalHeaderSize
||
603 CalculatedSize
< Image
->AuthInfo
.Hdr
.dwLength
) {
605 // Integer overflow. Invalid image.
610 return CalculatedSize
;
614 Checks if the firmware image is valid for the device.
616 This function allows firmware update application to validate the firmware image without
617 invoking the SetImage() first.
619 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
620 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
621 The number is between 1 and DescriptorCount.
622 @param[in] Image Points to the new image.
623 @param[in] ImageSize Size of the new image in bytes.
624 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
625 if available, additional information if the image is invalid.
627 @retval EFI_SUCCESS The image was successfully checked.
628 @retval EFI_ABORTED The operation is aborted.
629 @retval EFI_INVALID_PARAMETER The Image was NULL.
630 @retval EFI_UNSUPPORTED The operation is not supported.
631 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
637 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
639 IN CONST VOID
*Image
,
641 OUT UINT32
*ImageUpdateable
646 VOID
*FmpPayloadHeader
;
647 UINTN FmpPayloadSize
;
649 UINT32 FmpHeaderSize
;
653 UINTN PublicKeyDataLength
;
654 UINT8
*PublicKeyDataXdr
;
655 UINT8
*PublicKeyDataXdrEnd
;
657 Status
= EFI_SUCCESS
;
659 FmpPayloadHeader
= NULL
;
666 // make sure the descriptor has already been loaded
668 if (!mDescriptorPopulated
) {
669 PopulateDescriptor();
672 if (ImageUpdateable
== NULL
) {
673 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - ImageUpdateable Pointer Parameter is NULL.\n"));
674 Status
= EFI_INVALID_PARAMETER
;
679 //Set to valid and then if any tests fail it will update this flag.
681 *ImageUpdateable
= IMAGE_UPDATABLE_VALID
;
684 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - Image Pointer Parameter is NULL.\n"));
686 // not sure if this is needed
688 *ImageUpdateable
= IMAGE_UPDATABLE_INVALID
;
689 return EFI_INVALID_PARAMETER
;
692 PublicKeyDataXdr
= PcdGetPtr (PcdFmpDevicePkcs7CertBufferXdr
);
693 PublicKeyDataXdrEnd
= PublicKeyDataXdr
+ PcdGetSize (PcdFmpDevicePkcs7CertBufferXdr
);
695 if (PublicKeyDataXdr
== NULL
|| (PublicKeyDataXdr
== PublicKeyDataXdrEnd
)) {
696 DEBUG ((DEBUG_ERROR
, "FmpDxe: Invalid certificate, skipping it.\n"));
697 Status
= EFI_ABORTED
;
700 // Try each key from PcdFmpDevicePkcs7CertBufferXdr
702 for (Index
= 1; PublicKeyDataXdr
< PublicKeyDataXdrEnd
; Index
++) {
706 "FmpDxe: Certificate #%d [%p..%p].\n",
713 if ((PublicKeyDataXdr
+ sizeof (UINT32
)) > PublicKeyDataXdrEnd
) {
715 // Key data extends beyond end of PCD
717 DEBUG ((DEBUG_ERROR
, "FmpDxe: Certificate size extends beyond end of PCD, skipping it.\n"));
718 Status
= EFI_ABORTED
;
722 // Read key length stored in big-endian format
724 PublicKeyDataLength
= SwapBytes32 (*(UINT32
*)(PublicKeyDataXdr
));
726 // Point to the start of the key data
728 PublicKeyDataXdr
+= sizeof (UINT32
);
729 if (PublicKeyDataXdr
+ PublicKeyDataLength
> PublicKeyDataXdrEnd
) {
731 // Key data extends beyond end of PCD
733 DEBUG ((DEBUG_ERROR
, "FmpDxe: Certificate extends beyond end of PCD, skipping it.\n"));
734 Status
= EFI_ABORTED
;
737 PublicKeyData
= PublicKeyDataXdr
;
738 Status
= AuthenticateFmpImage (
739 (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
,
744 if (!EFI_ERROR (Status
)) {
747 PublicKeyDataXdr
+= PublicKeyDataLength
;
748 PublicKeyDataXdr
= (UINT8
*)ALIGN_POINTER (PublicKeyDataXdr
, sizeof (UINT32
));
752 if (EFI_ERROR (Status
)) {
753 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - Authentication Failed %r.\n", Status
));
758 // Check to make sure index is 1
760 if (ImageIndex
!= 1) {
761 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckImage() - Image Index Invalid.\n"));
762 *ImageUpdateable
= IMAGE_UPDATABLE_INVALID_TYPE
;
763 Status
= EFI_SUCCESS
;
769 // Check the FmpPayloadHeader
771 FmpPayloadHeader
= GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, ImageSize
, &FmpPayloadSize
);
772 if (FmpPayloadHeader
== NULL
) {
773 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpHeader failed.\n"));
774 Status
= EFI_ABORTED
;
777 Status
= GetFmpPayloadHeaderVersion (FmpPayloadHeader
, FmpPayloadSize
, &Version
);
778 if (EFI_ERROR (Status
)) {
779 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderVersion failed %r.\n", Status
));
780 *ImageUpdateable
= IMAGE_UPDATABLE_INVALID
;
781 Status
= EFI_SUCCESS
;
786 // Check the lowest supported version
788 if (Version
< mDesc
.LowestSupportedImageVersion
) {
791 "FmpDxe: CheckTheImage() - Version Lower than lowest supported version. 0x%08X < 0x%08X\n",
792 Version
, mDesc
.LowestSupportedImageVersion
)
794 *ImageUpdateable
= IMAGE_UPDATABLE_INVALID_OLD
;
795 Status
= EFI_SUCCESS
;
800 // Get the FmpHeaderSize so we can determine the real payload size
802 Status
= GetFmpPayloadHeaderSize (FmpPayloadHeader
, FmpPayloadSize
, &FmpHeaderSize
);
803 if (EFI_ERROR (Status
)) {
804 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status
));
805 *ImageUpdateable
= IMAGE_UPDATABLE_INVALID
;
806 Status
= EFI_SUCCESS
;
811 // Call FmpDevice Lib Check Image on the
812 // Raw payload. So all headers need stripped off
814 AllHeaderSize
= GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, FmpHeaderSize
);
815 if (AllHeaderSize
== 0) {
816 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - GetAllHeaderSize failed.\n"));
817 Status
= EFI_ABORTED
;
820 RawSize
= ImageSize
- AllHeaderSize
;
823 // FmpDeviceLib CheckImage function to do any specific checks
825 Status
= FmpDeviceCheckImage ((((UINT8
*)Image
) + AllHeaderSize
), RawSize
, ImageUpdateable
);
826 if (EFI_ERROR (Status
)) {
827 DEBUG ((DEBUG_ERROR
, "FmpDxe: CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", Status
));
835 Updates the firmware image of the device.
837 This function updates the hardware with the new firmware image.
838 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
839 If the firmware image is updatable, the function should perform the following minimal validations
840 before proceeding to do the firmware image update.
841 - Validate the image authentication if image has attribute
842 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
843 EFI_SECURITY_VIOLATION if the validation fails.
844 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
845 the image is unsupported. The function can optionally provide more detailed information on
846 why the image is not a supported image.
847 - Validate the data from VendorCode if not null. Image validation must be performed before
848 VendorCode data validation. VendorCode data is ignored or considered invalid if image
849 validation failed. The function returns EFI_ABORTED if the data is invalid.
851 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
852 the caller did not specify the policy or use the default policy. As an example, vendor can implement
853 a policy to allow an option to force a firmware image update when the abort reason is due to the new
854 firmware image version is older than the current firmware image version or bad image checksum.
855 Sensitive operations such as those wiping the entire firmware image and render the device to be
856 non-functional should be encoded in the image itself rather than passed with the VendorCode.
857 AbortReason enables vendor to have the option to provide a more detailed description of the abort
858 reason to the caller.
860 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
861 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
862 The number is between 1 and DescriptorCount.
863 @param[in] Image Points to the new image.
864 @param[in] ImageSize Size of the new image in bytes.
865 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
866 Null indicates the caller did not specify the policy or use the default policy.
867 @param[in] Progress A function used by the driver to report the progress of the firmware update.
868 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
869 details for the aborted operation. The buffer is allocated by this function
870 with AllocatePool(), and it is the caller's responsibility to free it with a
873 @retval EFI_SUCCESS The device was successfully updated with the new image.
874 @retval EFI_ABORTED The operation is aborted.
875 @retval EFI_INVALID_PARAMETER The Image was NULL.
876 @retval EFI_UNSUPPORTED The operation is not supported.
877 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
883 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
885 IN CONST VOID
*Image
,
887 IN CONST VOID
*VendorCode
,
888 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
,
889 OUT CHAR16
**AbortReason
894 BOOLEAN BooleanValue
;
895 UINT32 FmpHeaderSize
;
897 UINTN FmpPayloadSize
;
898 UINT32 AllHeaderSize
;
899 UINT32 IncommingFwVersion
;
900 UINT32 LastAttemptStatus
;
902 Status
= EFI_SUCCESS
;
904 BooleanValue
= FALSE
;
909 IncommingFwVersion
= 0;
910 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL
;
913 SetLastAttemptVersionInVariable (IncommingFwVersion
); //set to 0 to clear any previous results.
916 // if we have locked the device, then skip the set operation.
917 // it should be blocked by hardware too but we can catch here even faster
919 if (mFmpDeviceLocked
) {
920 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Device is already locked. Can't update.\n"));
921 Status
= EFI_ACCESS_DENIED
;
926 // Call check image to verify the image
928 Status
= CheckTheImage (This
, ImageIndex
, Image
, ImageSize
, &Updateable
);
929 if (EFI_ERROR (Status
)) {
930 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Check The Image failed with %r.\n", Status
));
931 if (Status
== EFI_SECURITY_VIOLATION
) {
932 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR
;
938 // No functional error in CheckTheImage. Attempt to get the Version to
939 // support better error reporting.
941 FmpHeader
= GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, ImageSize
, &FmpPayloadSize
);
942 if (FmpHeader
== NULL
) {
943 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetFmpHeader failed.\n"));
944 Status
= EFI_ABORTED
;
947 Status
= GetFmpPayloadHeaderVersion (FmpHeader
, FmpPayloadSize
, &IncommingFwVersion
);
948 if (!EFI_ERROR (Status
)) {
950 // Set to actual value
952 SetLastAttemptVersionInVariable (IncommingFwVersion
);
956 if (Updateable
!= IMAGE_UPDATABLE_VALID
) {
959 "FmpDxed: SetTheImage() - Check The Image returned that the Image was not valid for update. Updatable value = 0x%X.\n",
962 Status
= EFI_ABORTED
;
966 if (Progress
== NULL
) {
967 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Invalid progress callback\n"));
968 Status
= EFI_INVALID_PARAMETER
;
972 mProgressFunc
= Progress
;
973 mProgressSupported
= TRUE
;
976 // Checking the image is at least 1%
978 Status
= Progress (1);
979 if (EFI_ERROR (Status
)) {
980 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - Progress Callback failed with Status %r.\n", Status
));
986 Status
= CheckSystemPower (&BooleanValue
);
987 if (EFI_ERROR (Status
)) {
988 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemPower - API call failed %r.\n", Status
));
992 Status
= EFI_ABORTED
;
995 "FmpDxe: SetTheImage() - CheckSystemPower - returned False. Update not allowed due to System Power.\n")
997 LastAttemptStatus
= LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT
;
1004 //Check System Thermal
1006 Status
= CheckSystemThermal (&BooleanValue
);
1007 if (EFI_ERROR (Status
)) {
1008 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemThermal - API call failed %r.\n", Status
));
1011 if (!BooleanValue
) {
1012 Status
= EFI_ABORTED
;
1015 "FmpDxe: SetTheImage() - CheckSystemThermal - returned False. Update not allowed due to System Thermal.\n")
1023 //Check System Environment
1025 Status
= CheckSystemEnvironment (&BooleanValue
);
1026 if (EFI_ERROR (Status
)) {
1027 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - CheckSystemEnvironment - API call failed %r.\n", Status
));
1030 if (!BooleanValue
) {
1031 Status
= EFI_ABORTED
;
1034 "FmpDxe: SetTheImage() - CheckSystemEnvironment - returned False. Update not allowed due to System Environment.\n")
1042 // Save LastAttemptStatus as error so that if SetImage never returns the error
1043 // state is recorded.
1045 SetLastAttemptStatusInVariable (LastAttemptStatus
);
1048 // Strip off all the headers so the device can process its firmware
1050 Status
= GetFmpPayloadHeaderSize (FmpHeader
, FmpPayloadSize
, &FmpHeaderSize
);
1051 if (EFI_ERROR (Status
)) {
1052 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetFmpPayloadHeaderSize failed %r.\n", Status
));
1056 AllHeaderSize
= GetAllHeaderSize ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION
*)Image
, FmpHeaderSize
);
1057 if (AllHeaderSize
== 0) {
1058 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() - GetAllHeaderSize failed.\n"));
1059 Status
= EFI_ABORTED
;
1064 // Indicate that control is handed off to FmpDeviceLib
1069 //Copy the requested image to the firmware using the FmpDeviceLib
1071 Status
= FmpDeviceSetImage (
1072 (((UINT8
*)Image
) + AllHeaderSize
),
1073 ImageSize
- AllHeaderSize
,
1079 if (EFI_ERROR (Status
)) {
1080 DEBUG ((DEBUG_ERROR
, "FmpDxe: SetTheImage() SetImage from FmpDeviceLib failed. Status = %r.\n", Status
));
1086 // Finished the update without error
1087 // Indicate that control has been returned from FmpDeviceLib
1092 // Update the version stored in variable
1094 if (!mRuntimeVersionSupported
) {
1095 UINT32 Version
= DEFAULT_VERSION
;
1096 GetFmpPayloadHeaderVersion (FmpHeader
, FmpPayloadSize
, &Version
);
1097 SetVersionInVariable (Version
);
1101 // Update lowest supported variable
1104 UINT32 Version
= DEFAULT_LOWESTSUPPORTEDVERSION
;
1105 GetFmpPayloadHeaderLowestSupportedVersion (FmpHeader
, FmpPayloadSize
, &Version
);
1106 SetLowestSupportedVersionInVariable (Version
);
1109 LastAttemptStatus
= LAST_ATTEMPT_STATUS_SUCCESS
;
1112 // Set flag so the descriptor is repopulated
1113 // This only applied to devices that do not require system reboot
1115 if (!PcdGetBool (PcdFmpDeviceSystemResetRequired
)) {
1116 mDescriptorPopulated
= FALSE
;
1120 mProgressFunc
= NULL
;
1121 mProgressSupported
= FALSE
;
1122 SetLastAttemptStatusInVariable (LastAttemptStatus
);
1124 if (Progress
!= NULL
) {
1126 // Set progress to 100 after everything is done including recording Status.
1135 Returns information about the firmware package.
1137 This function returns package information.
1139 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
1140 @param[out] PackageVersion A version number that represents all the firmware images in the device.
1141 The format is vendor specific and new version must have a greater value
1142 than the old version. If PackageVersion is not supported, the value is
1143 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
1144 comparison is to be performed using PackageVersionName. A value of
1145 0xFFFFFFFD indicates that package version update is in progress.
1146 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
1147 the package version name. The buffer is allocated by this function with
1148 AllocatePool(), and it is the caller's responsibility to free it with a
1150 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
1151 package version name. A value of 0 indicates the device does not support
1152 update of package version name. Length is the number of Unicode characters,
1153 including the terminating null character.
1154 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
1155 Definitions' for possible returned values of this parameter. A value of 1
1156 indicates the attribute is supported and the current setting value is
1157 indicated in AttributesSetting. A value of 0 indicates the attribute is not
1158 supported and the current setting value in AttributesSetting is meaningless.
1159 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
1160 values of this parameter
1162 @retval EFI_SUCCESS The package information was successfully returned.
1163 @retval EFI_UNSUPPORTED The operation is not supported.
1169 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
1170 OUT UINT32
*PackageVersion
,
1171 OUT CHAR16
**PackageVersionName
,
1172 OUT UINT32
*PackageVersionNameMaxLen
,
1173 OUT UINT64
*AttributesSupported
,
1174 OUT UINT64
*AttributesSetting
1177 return EFI_UNSUPPORTED
;
1181 Updates information about the firmware package.
1183 This function updates package information.
1184 This function returns EFI_UNSUPPORTED if the package information is not updatable.
1185 VendorCode enables vendor to implement vendor-specific package information update policy.
1186 Null if the caller did not specify this policy or use the default policy.
1188 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
1189 @param[in] Image Points to the authentication image.
1190 Null if authentication is not required.
1191 @param[in] ImageSize Size of the authentication image in bytes.
1192 0 if authentication is not required.
1193 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
1194 image update policy.
1195 Null indicates the caller did not specify this policy or use
1197 @param[in] PackageVersion The new package version.
1198 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
1199 the package version name.
1200 The string length is equal to or less than the value returned in
1201 PackageVersionNameMaxLen.
1203 @retval EFI_SUCCESS The device was successfully updated with the new package
1205 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
1206 returned in PackageVersionNameMaxLen.
1207 @retval EFI_UNSUPPORTED The operation is not supported.
1208 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
1214 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
1215 IN CONST VOID
*Image
,
1217 IN CONST VOID
*VendorCode
,
1218 IN UINT32 PackageVersion
,
1219 IN CONST CHAR16
*PackageVersionName
1222 return EFI_UNSUPPORTED
;
1226 Event notification function that is invoked when the event GUID specified by
1227 PcdFmpDeviceLockEventGuid is signaled.
1229 @param[in] Event Event whose notification function is being invoked.
1230 @param[in] Context The pointer to the notification function's context,
1231 which is implementation-dependent.
1235 FmpDxeLockEventNotify (
1242 if (!mFmpDeviceLocked
) {
1243 if (IsLockFmpDeviceAtLockEventGuidRequired ()) {
1245 // Lock all UEFI Variables used by this module.
1247 Status
= LockAllFmpVariables ();
1248 if (EFI_ERROR (Status
)) {
1249 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to lock variables. Status = %r.\n"));
1251 DEBUG ((DEBUG_INFO
, "FmpDxe: All variables locked\n"));
1255 // Lock the firmware device
1257 Status
= FmpDeviceLock();
1258 if (EFI_ERROR (Status
)) {
1259 if (Status
!= EFI_UNSUPPORTED
) {
1260 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLock() returned error. Status = %r\n", Status
));
1262 DEBUG ((DEBUG_WARN
, "FmpDxe: FmpDeviceLock() returned error. Status = %r\n", Status
));
1265 mFmpDeviceLocked
= TRUE
;
1267 DEBUG ((DEBUG_VERBOSE
, "FmpDxe: Not calling FmpDeviceLock() because mfg mode\n"));
1273 Function to install FMP instance.
1275 @param[in] Handle The device handle to install a FMP instance on.
1277 @retval EFI_SUCCESS FMP Installed
1278 @retval EFI_INVALID_PARAMETER Handle was invalid
1279 @retval other Error installing FMP
1284 InstallFmpInstance (
1285 IN EFI_HANDLE Handle
1289 EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*Fmp
;
1290 EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL
*FmpProgress
;
1292 Status
= EFI_SUCCESS
;
1297 // Only allow a single FMP Protocol instance to be installed
1299 if (mFmpInstalled
) {
1300 return EFI_ALREADY_STARTED
;
1304 // Allocate FMP Protocol instance
1306 Fmp
= AllocateZeroPool (sizeof (EFI_FIRMWARE_MANAGEMENT_PROTOCOL
));
1308 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to allocate memory for FMP Protocol instance.\n"));
1309 Status
= EFI_OUT_OF_RESOURCES
;
1314 // Allocate FMP Progress Protocol instance
1316 FmpProgress
= AllocateZeroPool (sizeof (EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL
));
1317 if (FmpProgress
== NULL
) {
1318 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to allocate memory for FMP Progress Protocol instance.\n"));
1319 Status
= EFI_OUT_OF_RESOURCES
;
1325 // Set up FMP Protocol function pointers
1327 Fmp
->GetImageInfo
= GetTheImageInfo
;
1328 Fmp
->GetImage
= GetTheImage
;
1329 Fmp
->SetImage
= SetTheImage
;
1330 Fmp
->CheckImage
= CheckTheImage
;
1331 Fmp
->GetPackageInfo
= GetPackageInfo
;
1332 Fmp
->SetPackageInfo
= SetPackageInfo
;
1335 // Fill in FMP Progress Protocol fields for Version 1
1337 FmpProgress
->Version
= 1;
1338 FmpProgress
->ProgressBarForegroundColor
.Raw
= PcdGet32 (PcdFmpDeviceProgressColor
);
1339 FmpProgress
->WatchdogSeconds
= PcdGet8 (PcdFmpDeviceProgressWatchdogTimeInSeconds
);
1342 // Install FMP Protocol and FMP Progress Protocol
1344 Status
= gBS
->InstallMultipleProtocolInterfaces (
1346 &gEfiFirmwareManagementProtocolGuid
,
1348 &gEdkiiFirmwareManagementProgressProtocolGuid
,
1353 if (EFI_ERROR (Status
)) {
1354 DEBUG ((DEBUG_ERROR
, "FmpDxe: FMP Protocol install error. Status = %r.\n", Status
));
1359 DEBUG ((DEBUG_INFO
, "FmpDxe: FMP Protocol Installed!\n"));
1360 mFmpInstalled
= TRUE
;
1368 Main entry for this driver/library.
1370 @param[in] ImageHandle Image handle this driver.
1371 @param[in] SystemTable Pointer to SystemTable.
1377 IN EFI_HANDLE ImageHandle
,
1378 IN EFI_SYSTEM_TABLE
*SystemTable
1385 // Verify that a new FILE_GUID value has been provided in the <Defines>
1386 // section of this module. The FILE_GUID is the ESRT GUID that must be
1387 // unique for each updatable firmware image.
1389 if (CompareGuid (&mDefaultModuleFileGuid
, &gEfiCallerIdGuid
)) {
1390 DEBUG ((DEBUG_ERROR
, "FmpDxe: Use of default FILE_GUID detected. FILE_GUID must be set to a unique value.\n"));
1392 return EFI_UNSUPPORTED
;
1396 // Get the ImageIdName value for the EFI_FIRMWARE_IMAGE_DESCRIPTOR from a PCD.
1398 mImageIdName
= (CHAR16
*) PcdGetPtr (PcdFmpDeviceImageIdName
);
1399 if (PcdGetSize (PcdFmpDeviceImageIdName
) <= 2 || mImageIdName
[0] == 0) {
1401 // PcdFmpDeviceImageIdName must be set to a non-empty Unicode string
1403 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib PcdFmpDeviceImageIdName is an empty string.\n"));
1408 // Detects if PcdFmpDevicePkcs7CertBufferXdr contains a test key.
1413 // Register with library the install function so if the library uses
1414 // UEFI driver model/driver binding protocol it can install FMP on its device handle
1415 // If library is simple lib that does not use driver binding then it should return
1416 // unsupported and this will install the FMP instance on the ImageHandle
1418 Status
= RegisterFmpInstaller (InstallFmpInstance
);
1419 if (Status
== EFI_UNSUPPORTED
) {
1420 DEBUG ((DEBUG_INFO
, "FmpDxe: FmpDeviceLib registration returned EFI_UNSUPPORTED. Installing single FMP instance.\n"));
1421 Status
= InstallFmpInstance (ImageHandle
);
1422 } else if (EFI_ERROR (Status
)) {
1423 DEBUG ((DEBUG_ERROR
, "FmpDxe: FmpDeviceLib registration returned %r. No FMP installed.\n", Status
));
1427 "FmpDxe: FmpDeviceLib registration returned EFI_SUCCESS. Expect FMP to be installed during the BDS/Device connection phase.\n"
1432 // Register notify function to lock the FMP device.
1433 // The lock event GUID is retrieved from PcdFmpDeviceLockEventGuid.
1434 // If PcdFmpDeviceLockEventGuid is not the size of an EFI_GUID, then
1435 // gEfiEndOfDxeEventGroupGuid is used.
1437 LockGuid
= &gEfiEndOfDxeEventGroupGuid
;
1438 if (PcdGetSize (PcdFmpDeviceLockEventGuid
) == sizeof (EFI_GUID
)) {
1439 LockGuid
= (EFI_GUID
*)PcdGetPtr (PcdFmpDeviceLockEventGuid
);
1441 DEBUG ((DEBUG_INFO
, "FmpDxe: Lock GUID: %g\n", LockGuid
));
1443 Status
= gBS
->CreateEventEx (
1446 FmpDxeLockEventNotify
,
1449 &mFmpDeviceLockEvent
1451 if (EFI_ERROR (Status
)) {
1452 DEBUG ((DEBUG_ERROR
, "FmpDxe: Failed to register for ready to boot. Status = %r\n", Status
));
1454 ASSERT_EFI_ERROR (Status
);