2 Provides firmware device specific services to support updates of a firmware
3 image stored in a firmware device.
5 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
6 Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/FmpDeviceLib.h>
16 Provide a function to install the Firmware Management Protocol instance onto a
17 device handle when the device is managed by a driver that follows the UEFI
18 Driver Model. If the device is not managed by a driver that follows the UEFI
19 Driver Model, then EFI_UNSUPPORTED is returned.
21 @param[in] FmpInstaller Function that installs the Firmware Management
24 @retval EFI_SUCCESS The device is managed by a driver that follows the
25 UEFI Driver Model. FmpInstaller must be called on
26 each Driver Binding Start().
27 @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
28 the UEFI Driver Model.
29 @retval other The Firmware Management Protocol for this firmware
30 device is not installed. The firmware device is
31 still locked using FmpDeviceLock().
36 RegisterFmpInstaller (
37 IN FMP_DEVICE_LIB_REGISTER_FMP_INSTALLER Function
40 return EFI_UNSUPPORTED
;
44 Provide a function to uninstall the Firmware Management Protocol instance from a
45 device handle when the device is managed by a driver that follows the UEFI
46 Driver Model. If the device is not managed by a driver that follows the UEFI
47 Driver Model, then EFI_UNSUPPORTED is returned.
49 @param[in] FmpUninstaller Function that installs the Firmware Management
52 @retval EFI_SUCCESS The device is managed by a driver that follows the
53 UEFI Driver Model. FmpUninstaller must be called on
54 each Driver Binding Stop().
55 @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
56 the UEFI Driver Model.
57 @retval other The Firmware Management Protocol for this firmware
58 device is not installed. The firmware device is
59 still locked using FmpDeviceLock().
64 RegisterFmpUninstaller (
65 IN FMP_DEVICE_LIB_REGISTER_FMP_UNINSTALLER Function
68 return EFI_UNSUPPORTED
;
72 Set the device context for the FmpDeviceLib services when the device is
73 managed by a driver that follows the UEFI Driver Model. If the device is not
74 managed by a driver that follows the UEFI Driver Model, then EFI_UNSUPPORTED
75 is returned. Once a device context is set, the FmpDeviceLib services
76 operate on the currently set device context.
78 @param[in] Handle Device handle for the FmpDeviceLib services.
79 If Handle is NULL, then Context is freed.
80 @param[in, out] Context Device context for the FmpDeviceLib services.
81 If Context is NULL, then a new context is allocated
82 for Handle and the current device context is set and
83 returned in Context. If Context is not NULL, then
84 the current device context is set.
86 @retval EFI_SUCCESS The device is managed by a driver that follows the
88 @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
89 the UEFI Driver Model.
90 @retval other The Firmware Management Protocol for this firmware
91 device is not installed. The firmware device is
92 still locked using FmpDeviceLock().
102 return EFI_UNSUPPORTED
;
106 Returns the size, in bytes, of the firmware image currently stored in the
107 firmware device. This function is used to by the GetImage() and
108 GetImageInfo() services of the Firmware Management Protocol. If the image
109 size can not be determined from the firmware device, then 0 must be returned.
111 @param[out] Size Pointer to the size, in bytes, of the firmware image
112 currently stored in the firmware device.
114 @retval EFI_SUCCESS The size of the firmware image currently
115 stored in the firmware device was returned.
116 @retval EFI_INVALID_PARAMETER Size is NULL.
117 @retval EFI_UNSUPPORTED The firmware device does not support reporting
118 the size of the currently stored firmware image.
119 @retval EFI_DEVICE_ERROR An error occurred attempting to determine the
120 size of the firmware image currently stored in
121 in the firmware device.
131 return EFI_INVALID_PARAMETER
;
138 Returns the GUID value used to fill in the ImageTypeId field of the
139 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
140 service of the Firmware Management Protocol. If EFI_UNSUPPORTED is returned,
141 then the ImageTypeId field is set to gEfiCallerIdGuid. If EFI_SUCCESS is
142 returned, then ImageTypeId is set to the Guid returned from this function.
144 @param[out] Guid Double pointer to a GUID value that is updated to point to
145 to a GUID value. The GUID value is not allocated and must
146 not be modified or freed by the caller.
148 @retval EFI_SUCCESS EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
149 to the returned Guid value.
150 @retval EFI_UNSUPPORTED EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
156 FmpDeviceGetImageTypeIdGuidPtr (
160 return EFI_UNSUPPORTED
;
164 Returns values used to fill in the AttributesSupported and AttributesSettings
165 fields of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the
166 GetImageInfo() service of the Firmware Management Protocol. The following
167 bit values from the Firmware Management Protocol may be combined:
168 IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
169 IMAGE_ATTRIBUTE_RESET_REQUIRED
170 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
171 IMAGE_ATTRIBUTE_IN_USE
172 IMAGE_ATTRIBUTE_UEFI_IMAGE
174 @param[out] Supported Attributes supported by this firmware device.
175 @param[out] Setting Attributes settings for this firmware device.
177 @retval EFI_SUCCESS The attributes supported by the firmware
178 device were returned.
179 @retval EFI_INVALID_PARAMETER Supported is NULL.
180 @retval EFI_INVALID_PARAMETER Setting is NULL.
185 FmpDeviceGetAttributes (
186 OUT UINT64
*Supported
,
190 if (Supported
== NULL
|| Setting
== NULL
) {
191 return EFI_INVALID_PARAMETER
;
199 Returns the value used to fill in the LowestSupportedVersion field of the
200 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
201 service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
202 the firmware device supports a method to report the LowestSupportedVersion
203 value from the currently stored firmware image. If the value can not be
204 reported for the firmware image currently stored in the firmware device, then
205 EFI_UNSUPPORTED must be returned. EFI_DEVICE_ERROR is returned if an error
206 occurs attempting to retrieve the LowestSupportedVersion value for the
207 currently stored firmware image.
209 @note It is recommended that all firmware devices support a method to report
210 the LowestSupportedVersion value from the currently stored firmware
213 @param[out] LowestSupportedVersion LowestSupportedVersion value retrieved
214 from the currently stored firmware image.
216 @retval EFI_SUCCESS The lowest supported version of currently stored
217 firmware image was returned in LowestSupportedVersion.
218 @retval EFI_UNSUPPORTED The firmware device does not support a method to
219 report the lowest supported version of the currently
220 stored firmware image.
221 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the lowest
222 supported version of the currently stored firmware
228 FmpDeviceGetLowestSupportedVersion (
229 OUT UINT32
*LowestSupportedVersion
232 return EFI_UNSUPPORTED
;
236 Returns the Null-terminated Unicode string that is used to fill in the
237 VersionName field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is
238 returned by the GetImageInfo() service of the Firmware Management Protocol.
239 The returned string must be allocated using EFI_BOOT_SERVICES.AllocatePool().
241 @note It is recommended that all firmware devices support a method to report
242 the VersionName string from the currently stored firmware image.
244 @param[out] VersionString The version string retrieved from the currently
245 stored firmware image.
247 @retval EFI_SUCCESS The version string of currently stored
248 firmware image was returned in Version.
249 @retval EFI_INVALID_PARAMETER VersionString is NULL.
250 @retval EFI_UNSUPPORTED The firmware device does not support a method
251 to report the version string of the currently
252 stored firmware image.
253 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
254 version string of the currently stored
256 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the
257 buffer for the version string of the currently
258 stored firmware image.
263 FmpDeviceGetVersionString (
264 OUT CHAR16
**VersionString
267 if (VersionString
== NULL
) {
268 return EFI_INVALID_PARAMETER
;
270 *VersionString
= NULL
;
271 return EFI_UNSUPPORTED
;
275 Returns the value used to fill in the Version field of the
276 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
277 service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
278 the firmware device supports a method to report the Version value from the
279 currently stored firmware image. If the value can not be reported for the
280 firmware image currently stored in the firmware device, then EFI_UNSUPPORTED
281 must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
282 to retrieve the LowestSupportedVersion value for the currently stored firmware
285 @note It is recommended that all firmware devices support a method to report
286 the Version value from the currently stored firmware image.
288 @param[out] Version The version value retrieved from the currently stored
291 @retval EFI_SUCCESS The version of currently stored firmware image was
293 @retval EFI_UNSUPPORTED The firmware device does not support a method to
294 report the version of the currently stored firmware
296 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the version
297 of the currently stored firmware image.
302 FmpDeviceGetVersion (
306 return EFI_UNSUPPORTED
;
310 Returns the value used to fill in the HardwareInstance field of the
311 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
312 service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
313 the firmware device supports a method to report the HardwareInstance value.
314 If the value can not be reported for the firmware device, then EFI_UNSUPPORTED
315 must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
316 to retrieve the HardwareInstance value for the firmware device.
318 @param[out] HardwareInstance The hardware instance value for the firmware
321 @retval EFI_SUCCESS The hardware instance for the current firmware
322 device is returned in HardwareInstance.
323 @retval EFI_UNSUPPORTED The firmware device does not support a method to
324 report the hardware instance value.
325 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the hardware
331 FmpDeviceGetHardwareInstance (
332 OUT UINT64
*HardwareInstance
335 return EFI_UNSUPPORTED
;
339 Returns a copy of the firmware image currently stored in the firmware device.
341 @note It is recommended that all firmware devices support a method to retrieve
342 a copy currently stored firmware image. This can be used to support
343 features such as recovery and rollback.
345 @param[out] Image Pointer to a caller allocated buffer where the
346 currently stored firmware image is copied to.
347 @param[in, out] ImageSize Pointer the size, in bytes, of the Image buffer.
348 On return, points to the size, in bytes, of firmware
349 image currently stored in the firmware device.
351 @retval EFI_SUCCESS Image contains a copy of the firmware image
352 currently stored in the firmware device, and
353 ImageSize contains the size, in bytes, of the
354 firmware image currently stored in the
356 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small
357 to hold the firmware image currently stored in
358 the firmware device. The buffer size required
359 is returned in ImageSize.
360 @retval EFI_INVALID_PARAMETER The Image is NULL.
361 @retval EFI_INVALID_PARAMETER The ImageSize is NULL.
362 @retval EFI_UNSUPPORTED The operation is not supported.
363 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
364 firmware image currently stored in the firmware
372 IN OUT UINTN
*ImageSize
375 return EFI_UNSUPPORTED
;
379 Checks if a new firmware image is valid for the firmware device. This
380 function allows firmware update operation to validate the firmware image
381 before FmpDeviceSetImage() is called.
383 @param[in] Image Points to a new firmware image.
384 @param[in] ImageSize Size, in bytes, of a new firmware image.
385 @param[out] ImageUpdatable Indicates if a new firmware image is valid for
386 a firmware update to the firmware device. The
387 following values from the Firmware Management
388 Protocol are supported:
389 IMAGE_UPDATABLE_VALID
390 IMAGE_UPDATABLE_INVALID
391 IMAGE_UPDATABLE_INVALID_TYPE
392 IMAGE_UPDATABLE_INVALID_OLD
393 IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE
395 @retval EFI_SUCCESS The image was successfully checked. Additional
396 status information is returned in
398 @retval EFI_INVALID_PARAMETER Image is NULL.
399 @retval EFI_INVALID_PARAMETER ImageUpdatable is NULL.
404 FmpDeviceCheckImage (
405 IN CONST VOID
*Image
,
407 OUT UINT32
*ImageUpdatable
414 Updates a firmware device with a new firmware image. This function returns
415 EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image
416 is updatable, the function should perform the following minimal validations
417 before proceeding to do the firmware image update.
418 - Validate that the image is a supported image for this firmware device.
419 Return EFI_ABORTED if the image is not supported. Additional details
420 on why the image is not a supported image may be returned in AbortReason.
421 - Validate the data from VendorCode if is not NULL. Firmware image
422 validation must be performed before VendorCode data validation.
423 VendorCode data is ignored or considered invalid if image validation
424 fails. Return EFI_ABORTED if the VendorCode data is invalid.
426 VendorCode enables vendor to implement vendor-specific firmware image update
427 policy. Null if the caller did not specify the policy or use the default
428 policy. As an example, vendor can implement a policy to allow an option to
429 force a firmware image update when the abort reason is due to the new firmware
430 image version is older than the current firmware image version or bad image
431 checksum. Sensitive operations such as those wiping the entire firmware image
432 and render the device to be non-functional should be encoded in the image
433 itself rather than passed with the VendorCode. AbortReason enables vendor to
434 have the option to provide a more detailed description of the abort reason to
437 @param[in] Image Points to the new firmware image.
438 @param[in] ImageSize Size, in bytes, of the new firmware image.
439 @param[in] VendorCode This enables vendor to implement vendor-specific
440 firmware image update policy. NULL indicates
441 the caller did not specify the policy or use the
443 @param[in] Progress A function used to report the progress of
444 updating the firmware device with the new
446 @param[in] CapsuleFwVersion The version of the new firmware image from the
447 update capsule that provided the new firmware
449 @param[out] AbortReason A pointer to a pointer to a Null-terminated
450 Unicode string providing more details on an
451 aborted operation. The buffer is allocated by
453 EFI_BOOT_SERVICES.AllocatePool(). It is the
454 caller's responsibility to free this buffer with
455 EFI_BOOT_SERVICES.FreePool().
457 @retval EFI_SUCCESS The firmware device was successfully updated
458 with the new firmware image.
459 @retval EFI_ABORTED The operation is aborted. Additional details
460 are provided in AbortReason.
461 @retval EFI_INVALID_PARAMETER The Image was NULL.
462 @retval EFI_UNSUPPORTED The operation is not supported.
468 IN CONST VOID
*Image
,
470 IN CONST VOID
*VendorCode
, OPTIONAL
471 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
, OPTIONAL
472 IN UINT32 CapsuleFwVersion
,
473 OUT CHAR16
**AbortReason
476 return EFI_UNSUPPORTED
;
480 Lock the firmware device that contains a firmware image. Once a firmware
481 device is locked, any attempts to modify the firmware image contents in the
482 firmware device must fail.
484 @note It is recommended that all firmware devices support a lock method to
485 prevent modifications to a stored firmware image.
487 @note A firmware device lock mechanism is typically only cleared by a full
488 system reset (not just sleep state/low power mode).
490 @retval EFI_SUCCESS The firmware device was locked.
491 @retval EFI_UNSUPPORTED The firmware device does not support locking
500 return EFI_UNSUPPORTED
;