2 System Firmware update header file.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _SYSTEM_FIRMWARE_UPDATE_H_
10 #define _SYSTEM_FIRMWARE_UPDATE_H_
14 #include <Guid/SystemResourceTable.h>
15 #include <Guid/FirmwareContentsSigned.h>
16 #include <Guid/WinCertificate.h>
17 #include <Guid/EdkiiSystemFmpCapsule.h>
19 #include <Protocol/FirmwareManagement.h>
20 #include <Protocol/FirmwareVolumeBlock.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/DevicePathLib.h>
32 #include <Library/HobLib.h>
33 #include <Library/DxeServicesTableLib.h>
34 #include <Library/PlatformFlashAccessLib.h>
35 #include <Library/EdkiiSystemCapsuleLib.h>
38 UINT32 LastAttemptVersion
;
39 UINT32 LastAttemptStatus
;
40 } SYSTEM_FMP_LAST_ATTEMPT_VARIABLE
;
42 #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME L"SystemLastAttempVar"
44 #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID {0x2f564d6f, 0xcc2c, 0x4838, { 0xb9, 0xa8, 0xbe, 0x59, 0x48, 0xb0, 0x3d, 0x59 }}
46 #define SYSTEM_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('S', 'Y', 'S', 'F')
48 #define SYSTEM_FMP_PROTOCOL_GUID {0x6d16624a, 0x26a6, 0x4cb4, { 0x84, 0xfa, 0x6, 0x78, 0x5a, 0x7e, 0x82, 0x6a }}
51 // SYSTEM FMP private data structure.
54 struct _SYSTEM_FMP_PRIVATE_DATA
{
56 EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp
;
58 UINT8 DescriptorCount
;
59 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR
*ImageDescriptor
;
60 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE LastAttempt
;
63 typedef struct _SYSTEM_FMP_PRIVATE_DATA SYSTEM_FMP_PRIVATE_DATA
;
66 Returns a pointer to the SYSTEM_FMP_PRIVATE_DATA structure from the input a as Fmp.
68 If the signatures matches, then a pointer to the data structure that contains
69 a specified field of that data structure is returned.
71 @param a Pointer to the field specified by ServiceBinding within
72 a data structure of type SYSTEM_FMP_PRIVATE_DATA.
75 #define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a) \
78 SYSTEM_FMP_PRIVATE_DATA, \
80 SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \
93 PLATFORM_FIRMWARE_TYPE FirmwareType
;
94 FLASH_ADDRESS_TYPE AddressType
;
96 EFI_PHYSICAL_ADDRESS BaseAddress
;
102 // System Firmware Update SMM Communication
105 #define SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_FUNCTION_SET_IMAGE 1
109 EFI_STATUS ReturnStatus
;
111 } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD
;
113 #define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0'
115 #define CAPSULE_IMAGE_ADDITIONAL_MAX_SIZE (0x20020 + 0xA0000) // Additional size for Capsule Header, FV block alignment + DispatchImage.
120 UINTN AbortReasonSize
;
121 UINT32 LastAttemptVersion
;
122 UINT32 LastAttemptStatus
;
123 // UINT8 Data[AbortReasonMaxSize + ImageSize];
124 } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE
;
127 Returns information about the current firmware image(s) of the device.
129 This function allows a copy of the current firmware image to be created and saved.
130 The saved copy could later been used, for example, in firmware image recovery or rollback.
132 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
133 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
134 On input, this is the size of the buffer allocated by the caller.
135 On output, it is the size of the buffer returned by the firmware
136 if the buffer was large enough, or the size of the buffer needed
137 to contain the image(s) information if the buffer was too small.
138 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
139 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
140 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
141 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
142 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
143 descriptors or firmware images within this device.
144 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
145 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
146 @param[out] PackageVersion A version number that represents all the firmware images in the device.
147 The format is vendor specific and new version must have a greater value
148 than the old version. If PackageVersion is not supported, the value is
149 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
150 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
151 that package version update is in progress.
152 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
153 package version name. The buffer is allocated by this function with
154 AllocatePool(), and it is the caller's responsibility to free it with a call
157 @retval EFI_SUCCESS The device was successfully updated with the new image.
158 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
159 needed to hold the image(s) information is returned in ImageInfoSize.
160 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
161 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
167 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
168 IN OUT UINTN
*ImageInfoSize
,
169 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
170 OUT UINT32
*DescriptorVersion
,
171 OUT UINT8
*DescriptorCount
,
172 OUT UINTN
*DescriptorSize
,
173 OUT UINT32
*PackageVersion
,
174 OUT CHAR16
**PackageVersionName
178 Retrieves a copy of the current firmware image of the device.
180 This function allows a copy of the current firmware image to be created and saved.
181 The saved copy could later been used, for example, in firmware image recovery or rollback.
183 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
184 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
185 The number is between 1 and DescriptorCount.
186 @param[in,out] Image Points to the buffer where the current image is copied to.
187 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
188 On return, points to the length of the image, in bytes.
190 @retval EFI_SUCCESS The device was successfully updated with the new image.
191 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
192 image. The current buffer size needed to hold the image is returned
194 @retval EFI_INVALID_PARAMETER The Image was NULL.
195 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
196 @retval EFI_UNSUPPORTED The operation is not supported.
197 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
203 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
206 IN OUT UINTN
*ImageSize
210 Updates the firmware image of the device.
212 This function updates the hardware with the new firmware image.
213 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
214 If the firmware image is updatable, the function should perform the following minimal validations
215 before proceeding to do the firmware image update.
216 - Validate the image authentication if image has attribute
217 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
218 EFI_SECURITY_VIOLATION if the validation fails.
219 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
220 the image is unsupported. The function can optionally provide more detailed information on
221 why the image is not a supported image.
222 - Validate the data from VendorCode if not null. Image validation must be performed before
223 VendorCode data validation. VendorCode data is ignored or considered invalid if image
224 validation failed. The function returns EFI_ABORTED if the data is invalid.
226 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
227 the caller did not specify the policy or use the default policy. As an example, vendor can implement
228 a policy to allow an option to force a firmware image update when the abort reason is due to the new
229 firmware image version is older than the current firmware image version or bad image checksum.
230 Sensitive operations such as those wiping the entire firmware image and render the device to be
231 non-functional should be encoded in the image itself rather than passed with the VendorCode.
232 AbortReason enables vendor to have the option to provide a more detailed description of the abort
233 reason to the caller.
235 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
236 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
237 The number is between 1 and DescriptorCount.
238 @param[in] Image Points to the new image.
239 @param[in] ImageSize Size of the new image in bytes.
240 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
241 Null indicates the caller did not specify the policy or use the default policy.
242 @param[in] Progress A function used by the driver to report the progress of the firmware update.
243 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
244 details for the aborted operation. The buffer is allocated by this function
245 with AllocatePool(), and it is the caller's responsibility to free it with a
248 @retval EFI_SUCCESS The device was successfully updated with the new image.
249 @retval EFI_ABORTED The operation is aborted.
250 @retval EFI_INVALID_PARAMETER The Image was NULL.
251 @retval EFI_UNSUPPORTED The operation is not supported.
252 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
258 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
260 IN CONST VOID
*Image
,
262 IN CONST VOID
*VendorCode
,
263 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
,
264 OUT CHAR16
**AbortReason
268 Checks if the firmware image is valid for the device.
270 This function allows firmware update application to validate the firmware image without
271 invoking the SetImage() first.
273 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
274 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
275 The number is between 1 and DescriptorCount.
276 @param[in] Image Points to the new image.
277 @param[in] ImageSize Size of the new image in bytes.
278 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
279 if available, additional information if the image is invalid.
281 @retval EFI_SUCCESS The image was successfully checked.
282 @retval EFI_INVALID_PARAMETER The Image was NULL.
283 @retval EFI_UNSUPPORTED The operation is not supported.
284 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
290 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
292 IN CONST VOID
*Image
,
294 OUT UINT32
*ImageUpdatable
298 Returns information about the firmware package.
300 This function returns package information.
302 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
303 @param[out] PackageVersion A version number that represents all the firmware images in the device.
304 The format is vendor specific and new version must have a greater value
305 than the old version. If PackageVersion is not supported, the value is
306 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
307 comparison is to be performed using PackageVersionName. A value of
308 0xFFFFFFFD indicates that package version update is in progress.
309 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
310 the package version name. The buffer is allocated by this function with
311 AllocatePool(), and it is the caller's responsibility to free it with a
313 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
314 package version name. A value of 0 indicates the device does not support
315 update of package version name. Length is the number of Unicode characters,
316 including the terminating null character.
317 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
318 Definitions' for possible returned values of this parameter. A value of 1
319 indicates the attribute is supported and the current setting value is
320 indicated in AttributesSetting. A value of 0 indicates the attribute is not
321 supported and the current setting value in AttributesSetting is meaningless.
322 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
323 values of this parameter
325 @retval EFI_SUCCESS The package information was successfully returned.
326 @retval EFI_UNSUPPORTED The operation is not supported.
332 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
333 OUT UINT32
*PackageVersion
,
334 OUT CHAR16
**PackageVersionName
,
335 OUT UINT32
*PackageVersionNameMaxLen
,
336 OUT UINT64
*AttributesSupported
,
337 OUT UINT64
*AttributesSetting
341 Updates information about the firmware package.
343 This function updates package information.
344 This function returns EFI_UNSUPPORTED if the package information is not updatable.
345 VendorCode enables vendor to implement vendor-specific package information update policy.
346 Null if the caller did not specify this policy or use the default policy.
348 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
349 @param[in] Image Points to the authentication image.
350 Null if authentication is not required.
351 @param[in] ImageSize Size of the authentication image in bytes.
352 0 if authentication is not required.
353 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
355 Null indicates the caller did not specify this policy or use
357 @param[in] PackageVersion The new package version.
358 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
359 the package version name.
360 The string length is equal to or less than the value returned in
361 PackageVersionNameMaxLen.
363 @retval EFI_SUCCESS The device was successfully updated with the new package
365 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
366 returned in PackageVersionNameMaxLen.
367 @retval EFI_UNSUPPORTED The operation is not supported.
368 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
374 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
375 IN CONST VOID
*Image
,
377 IN CONST VOID
*VendorCode
,
378 IN UINT32 PackageVersion
,
379 IN CONST CHAR16
*PackageVersionName
383 Initialize SystemFmpDriver private data structure.
385 @param[in] SystemFmpPrivate private data structure to be initialized.
387 @return EFI_SUCCESS private data is initialized.
390 InitializePrivateData (
391 IN SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
394 extern EFI_GUID gSystemFmpLastAttemptVariableGuid
;
395 extern EFI_GUID mCurrentImageTypeId
;
396 extern EFI_GUID gSystemFmpProtocolGuid
;