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, 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 Returns the size, in bytes, of the firmware image currently stored in the
45 firmware device. This function is used to by the GetImage() and
46 GetImageInfo() services of the Firmware Management Protocol. If the image
47 size can not be determined from the firmware device, then 0 must be returned.
49 @param[out] Size Pointer to the size, in bytes, of the firmware image
50 currently stored in the firmware device.
52 @retval EFI_SUCCESS The size of the firmware image currently
53 stored in the firmware device was returned.
54 @retval EFI_INVALID_PARAMETER Size is NULL.
55 @retval EFI_UNSUPPORTED The firmware device does not support reporting
56 the size of the currently stored firmware image.
57 @retval EFI_DEVICE_ERROR An error occurred attempting to determine the
58 size of the firmware image currently stored in
59 in the firmware device.
69 return EFI_INVALID_PARAMETER
;
76 Returns the GUID value used to fill in the ImageTypeId field of the
77 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
78 service of the Firmware Management Protocol. If EFI_UNSUPPORTED is returned,
79 then the ImageTypeId field is set to gEfiCallerIdGuid. If EFI_SUCCESS is
80 returned, then ImageTypeId is set to the Guid returned from this function.
82 @param[out] Guid Double pointer to a GUID value that is updated to point to
83 to a GUID value. The GUID value is not allocated and must
84 not be modified or freed by the caller.
86 @retval EFI_SUCCESS EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
87 to the returned Guid value.
88 @retval EFI_UNSUPPORTED EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId GUID is set
94 FmpDeviceGetImageTypeIdGuidPtr (
98 return EFI_UNSUPPORTED
;
102 Returns values used to fill in the AttributesSupported and AttributesSettings
103 fields of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the
104 GetImageInfo() service of the Firmware Management Protocol. The following
105 bit values from the Firmware Management Protocol may be combined:
106 IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
107 IMAGE_ATTRIBUTE_RESET_REQUIRED
108 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
109 IMAGE_ATTRIBUTE_IN_USE
110 IMAGE_ATTRIBUTE_UEFI_IMAGE
112 @param[out] Supported Attributes supported by this firmware device.
113 @param[out] Setting Attributes settings for this firmware device.
115 @retval EFI_SUCCESS The attributes supported by the firmware
116 device were returned.
117 @retval EFI_INVALID_PARAMETER Supported is NULL.
118 @retval EFI_INVALID_PARAMETER Setting is NULL.
123 FmpDeviceGetAttributes (
124 OUT UINT64
*Supported
,
128 if (Supported
== NULL
|| Setting
== NULL
) {
129 return EFI_INVALID_PARAMETER
;
137 Returns the value used to fill in the LowestSupportedVersion field of the
138 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
139 service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
140 the firmware device supports a method to report the LowestSupportedVersion
141 value from the currently stored firmware image. If the value can not be
142 reported for the firmware image currently stored in the firmware device, then
143 EFI_UNSUPPORTED must be returned. EFI_DEVICE_ERROR is returned if an error
144 occurs attempting to retrieve the LowestSupportedVersion value for the
145 currently stored firmware image.
147 @note It is recommended that all firmware devices support a method to report
148 the LowestSupportedVersion value from the currently stored firmware
151 @param[out] LowestSupportedVersion LowestSupportedVersion value retrieved
152 from the currently stored firmware image.
154 @retval EFI_SUCCESS The lowest supported version of currently stored
155 firmware image was returned in LowestSupportedVersion.
156 @retval EFI_UNSUPPORTED The firmware device does not support a method to
157 report the lowest supported version of the currently
158 stored firmware image.
159 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the lowest
160 supported version of the currently stored firmware
166 FmpDeviceGetLowestSupportedVersion (
167 OUT UINT32
*LowestSupportedVersion
170 return EFI_UNSUPPORTED
;
174 Returns the Null-terminated Unicode string that is used to fill in the
175 VersionName field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is
176 returned by the GetImageInfo() service of the Firmware Management Protocol.
177 The returned string must be allocated using EFI_BOOT_SERVICES.AllocatePool().
179 @note It is recommended that all firmware devices support a method to report
180 the VersionName string from the currently stored firmware image.
182 @param[out] VersionString The version string retrieved from the currently
183 stored firmware image.
185 @retval EFI_SUCCESS The version string of currently stored
186 firmware image was returned in Version.
187 @retval EFI_INVALID_PARAMETER VersionString is NULL.
188 @retval EFI_UNSUPPORTED The firmware device does not support a method
189 to report the version string of the currently
190 stored firmware image.
191 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
192 version string of the currently stored
194 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the
195 buffer for the version string of the currently
196 stored firmware image.
201 FmpDeviceGetVersionString (
202 OUT CHAR16
**VersionString
205 if (VersionString
== NULL
) {
206 return EFI_INVALID_PARAMETER
;
208 *VersionString
= NULL
;
209 return EFI_UNSUPPORTED
;
213 Returns the value used to fill in the Version field of the
214 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
215 service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
216 the firmware device supports a method to report the Version value from the
217 currently stored firmware image. If the value can not be reported for the
218 firmware image currently stored in the firmware device, then EFI_UNSUPPORTED
219 must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
220 to retrieve the LowestSupportedVersion value for the currently stored firmware
223 @note It is recommended that all firmware devices support a method to report
224 the Version value from the currently stored firmware image.
226 @param[out] Version The version value retrieved from the currently stored
229 @retval EFI_SUCCESS The version of currently stored firmware image was
231 @retval EFI_UNSUPPORTED The firmware device does not support a method to
232 report the version of the currently stored firmware
234 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the version
235 of the currently stored firmware image.
240 FmpDeviceGetVersion (
244 return EFI_UNSUPPORTED
;
248 Returns a copy of the firmware image currently stored in the firmware device.
250 @note It is recommended that all firmware devices support a method to retrieve
251 a copy currently stored firmware image. This can be used to support
252 features such as recovery and rollback.
254 @param[out] Image Pointer to a caller allocated buffer where the
255 currently stored firmware image is copied to.
256 @param[in, out] ImageSize Pointer the size, in bytes, of the Image buffer.
257 On return, points to the size, in bytes, of firmware
258 image currently stored in the firmware device.
260 @retval EFI_SUCCESS Image contains a copy of the firmware image
261 currently stored in the firmware device, and
262 ImageSize contains the size, in bytes, of the
263 firmware image currently stored in the
265 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small
266 to hold the firmware image currently stored in
267 the firmware device. The buffer size required
268 is returned in ImageSize.
269 @retval EFI_INVALID_PARAMETER The Image is NULL.
270 @retval EFI_INVALID_PARAMETER The ImageSize is NULL.
271 @retval EFI_UNSUPPORTED The operation is not supported.
272 @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
273 firmware image currently stored in the firmware
281 IN OUT UINTN
*ImageSize
284 return EFI_UNSUPPORTED
;
288 Checks if a new firmware image is valid for the firmware device. This
289 function allows firmware update operation to validate the firmware image
290 before FmpDeviceSetImage() is called.
292 @param[in] Image Points to a new firmware image.
293 @param[in] ImageSize Size, in bytes, of a new firmware image.
294 @param[out] ImageUpdatable Indicates if a new firmware image is valid for
295 a firmware update to the firmware device. The
296 following values from the Firmware Management
297 Protocol are supported:
298 IMAGE_UPDATABLE_VALID
299 IMAGE_UPDATABLE_INVALID
300 IMAGE_UPDATABLE_INVALID_TYPE
301 IMAGE_UPDATABLE_INVALID_OLD
302 IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE
304 @retval EFI_SUCCESS The image was successfully checked. Additional
305 status information is returned in
307 @retval EFI_INVALID_PARAMETER Image is NULL.
308 @retval EFI_INVALID_PARAMETER ImageUpdatable is NULL.
313 FmpDeviceCheckImage (
314 IN CONST VOID
*Image
,
316 OUT UINT32
*ImageUpdatable
323 Updates a firmware device with a new firmware image. This function returns
324 EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image
325 is updatable, the function should perform the following minimal validations
326 before proceeding to do the firmware image update.
327 - Validate that the image is a supported image for this firmware device.
328 Return EFI_ABORTED if the image is not supported. Additional details
329 on why the image is not a supported image may be returned in AbortReason.
330 - Validate the data from VendorCode if is not NULL. Firmware image
331 validation must be performed before VendorCode data validation.
332 VendorCode data is ignored or considered invalid if image validation
333 fails. Return EFI_ABORTED if the VendorCode data is invalid.
335 VendorCode enables vendor to implement vendor-specific firmware image update
336 policy. Null if the caller did not specify the policy or use the default
337 policy. As an example, vendor can implement a policy to allow an option to
338 force a firmware image update when the abort reason is due to the new firmware
339 image version is older than the current firmware image version or bad image
340 checksum. Sensitive operations such as those wiping the entire firmware image
341 and render the device to be non-functional should be encoded in the image
342 itself rather than passed with the VendorCode. AbortReason enables vendor to
343 have the option to provide a more detailed description of the abort reason to
346 @param[in] Image Points to the new firmware image.
347 @param[in] ImageSize Size, in bytes, of the new firmware image.
348 @param[in] VendorCode This enables vendor to implement vendor-specific
349 firmware image update policy. NULL indicates
350 the caller did not specify the policy or use the
352 @param[in] Progress A function used to report the progress of
353 updating the firmware device with the new
355 @param[in] CapsuleFwVersion The version of the new firmware image from the
356 update capsule that provided the new firmware
358 @param[out] AbortReason A pointer to a pointer to a Null-terminated
359 Unicode string providing more details on an
360 aborted operation. The buffer is allocated by
362 EFI_BOOT_SERVICES.AllocatePool(). It is the
363 caller's responsibility to free this buffer with
364 EFI_BOOT_SERVICES.FreePool().
366 @retval EFI_SUCCESS The firmware device was successfully updated
367 with the new firmware image.
368 @retval EFI_ABORTED The operation is aborted. Additional details
369 are provided in AbortReason.
370 @retval EFI_INVALID_PARAMETER The Image was NULL.
371 @retval EFI_UNSUPPORTED The operation is not supported.
377 IN CONST VOID
*Image
,
379 IN CONST VOID
*VendorCode
, OPTIONAL
380 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
, OPTIONAL
381 IN UINT32 CapsuleFwVersion
,
382 OUT CHAR16
**AbortReason
385 return EFI_UNSUPPORTED
;
389 Lock the firmware device that contains a firmware image. Once a firmware
390 device is locked, any attempts to modify the firmware image contents in the
391 firmware device must fail.
393 @note It is recommended that all firmware devices support a lock method to
394 prevent modifications to a stored firmware image.
396 @note A firmware device lock mechanism is typically only cleared by a full
397 system reset (not just sleep state/low power mode).
399 @retval EFI_SUCCESS The firmware device was locked.
400 @retval EFI_UNSUPPORTED The firmware device does not support locking
409 return EFI_UNSUPPORTED
;