2 Produce FMP instance for system firmware.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "SystemFirmwareDxe.h"
11 EFI_GUID gSystemFmpLastAttemptVariableGuid
= SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID
;
12 EFI_GUID gSystemFmpProtocolGuid
= SYSTEM_FMP_PROTOCOL_GUID
;
14 EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol
= {
24 Returns information about the current firmware image(s) of the device.
26 This function allows a copy of the current firmware image to be created and saved.
27 The saved copy could later been used, for example, in firmware image recovery or rollback.
29 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
30 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
31 On input, this is the size of the buffer allocated by the caller.
32 On output, it is the size of the buffer returned by the firmware
33 if the buffer was large enough, or the size of the buffer needed
34 to contain the image(s) information if the buffer was too small.
35 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
36 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
37 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
38 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
39 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
40 descriptors or firmware images within this device.
41 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
42 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
43 @param[out] PackageVersion A version number that represents all the firmware images in the device.
44 The format is vendor specific and new version must have a greater value
45 than the old version. If PackageVersion is not supported, the value is
46 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
47 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
48 that package version update is in progress.
49 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
50 package version name. The buffer is allocated by this function with
51 AllocatePool(), and it is the caller's responsibility to free it with a call
54 @retval EFI_SUCCESS The device was successfully updated with the new image.
55 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
56 needed to hold the image(s) information is returned in ImageInfoSize.
57 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
58 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
64 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
65 IN OUT UINTN
*ImageInfoSize
,
66 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
67 OUT UINT32
*DescriptorVersion
,
68 OUT UINT8
*DescriptorCount
,
69 OUT UINTN
*DescriptorSize
,
70 OUT UINT32
*PackageVersion
,
71 OUT CHAR16
**PackageVersionName
74 SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
;
75 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR
*ImageDescriptor
;
77 SystemFmpPrivate
= SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This
);
79 if (ImageInfoSize
== NULL
) {
80 return EFI_INVALID_PARAMETER
;
83 if (*ImageInfoSize
< sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
) {
84 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
;
85 return EFI_BUFFER_TOO_SMALL
;
88 if ((ImageInfo
== NULL
) ||
89 (DescriptorVersion
== NULL
) ||
90 (DescriptorCount
== NULL
) ||
91 (DescriptorSize
== NULL
) ||
92 (PackageVersion
== NULL
) ||
93 (PackageVersionName
== NULL
))
95 return EFI_INVALID_PARAMETER
;
98 *ImageInfoSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
;
99 *DescriptorSize
= sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
100 *DescriptorCount
= SystemFmpPrivate
->DescriptorCount
;
101 *DescriptorVersion
= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION
;
104 // supports 1 ImageInfo descriptor
106 ImageDescriptor
= SystemFmpPrivate
->ImageDescriptor
;
107 ImageInfo
->ImageIndex
= ImageDescriptor
->ImageIndex
;
108 CopyGuid (&ImageInfo
->ImageTypeId
, &ImageDescriptor
->ImageTypeId
);
109 ImageInfo
->ImageId
= ImageDescriptor
->ImageId
;
110 if (ImageDescriptor
->ImageIdNameStringOffset
!= 0) {
111 ImageInfo
->ImageIdName
= (CHAR16
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->ImageIdNameStringOffset
);
113 ImageInfo
->ImageIdName
= NULL
;
116 ImageInfo
->Version
= ImageDescriptor
->Version
;
117 if (ImageDescriptor
->VersionNameStringOffset
!= 0) {
118 ImageInfo
->VersionName
= (CHAR16
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->VersionNameStringOffset
);
120 ImageInfo
->VersionName
= NULL
;
123 ImageInfo
->Size
= (UINTN
)ImageDescriptor
->Size
;
124 ImageInfo
->AttributesSupported
= ImageDescriptor
->AttributesSupported
;
125 ImageInfo
->AttributesSetting
= ImageDescriptor
->AttributesSetting
;
126 ImageInfo
->Compatibilities
= ImageDescriptor
->Compatibilities
;
127 ImageInfo
->LowestSupportedImageVersion
= ImageDescriptor
->LowestSupportedImageVersion
;
128 ImageInfo
->LastAttemptVersion
= SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
;
129 ImageInfo
->LastAttemptStatus
= SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
;
130 ImageInfo
->HardwareInstance
= ImageDescriptor
->HardwareInstance
;
135 *PackageVersion
= ImageDescriptor
->PackageVersion
;
136 if (ImageDescriptor
->PackageVersionNameStringOffset
!= 0) {
137 *PackageVersionName
= (VOID
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->PackageVersionNameStringOffset
);
138 *PackageVersionName
= AllocateCopyPool (StrSize (*PackageVersionName
), *PackageVersionName
);
140 *PackageVersionName
= NULL
;
147 Retrieves a copy of the current firmware image of the device.
149 This function allows a copy of the current firmware image to be created and saved.
150 The saved copy could later been used, for example, in firmware image recovery or rollback.
152 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
153 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
154 The number is between 1 and DescriptorCount.
155 @param[in,out] Image Points to the buffer where the current image is copied to.
156 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
157 On return, points to the length of the image, in bytes.
159 @retval EFI_SUCCESS The device was successfully updated with the new image.
160 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
161 image. The current buffer size needed to hold the image is returned
163 @retval EFI_INVALID_PARAMETER The Image was NULL.
164 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
165 @retval EFI_UNSUPPORTED The operation is not supported.
166 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
172 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
175 IN OUT UINTN
*ImageSize
178 return EFI_UNSUPPORTED
;
182 Checks if the firmware image is valid for the device.
184 This function allows firmware update application to validate the firmware image without
185 invoking the SetImage() first.
187 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
188 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
189 The number is between 1 and DescriptorCount.
190 @param[in] Image Points to the new image.
191 @param[in] ImageSize Size of the new image in bytes.
192 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
193 if available, additional information if the image is invalid.
195 @retval EFI_SUCCESS The image was successfully checked.
196 @retval EFI_INVALID_PARAMETER The Image was NULL.
197 @retval EFI_UNSUPPORTED The operation is not supported.
198 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
204 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
206 IN CONST VOID
*Image
,
208 OUT UINT32
*ImageUpdatable
211 return EFI_UNSUPPORTED
;
215 Returns information about the firmware package.
217 This function returns package information.
219 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
220 @param[out] PackageVersion A version number that represents all the firmware images in the device.
221 The format is vendor specific and new version must have a greater value
222 than the old version. If PackageVersion is not supported, the value is
223 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
224 comparison is to be performed using PackageVersionName. A value of
225 0xFFFFFFFD indicates that package version update is in progress.
226 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
227 the package version name. The buffer is allocated by this function with
228 AllocatePool(), and it is the caller's responsibility to free it with a
230 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
231 package version name. A value of 0 indicates the device does not support
232 update of package version name. Length is the number of Unicode characters,
233 including the terminating null character.
234 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
235 Definitions' for possible returned values of this parameter. A value of 1
236 indicates the attribute is supported and the current setting value is
237 indicated in AttributesSetting. A value of 0 indicates the attribute is not
238 supported and the current setting value in AttributesSetting is meaningless.
239 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
240 values of this parameter
242 @retval EFI_SUCCESS The package information was successfully returned.
243 @retval EFI_UNSUPPORTED The operation is not supported.
249 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
250 OUT UINT32
*PackageVersion
,
251 OUT CHAR16
**PackageVersionName
,
252 OUT UINT32
*PackageVersionNameMaxLen
,
253 OUT UINT64
*AttributesSupported
,
254 OUT UINT64
*AttributesSetting
257 return EFI_UNSUPPORTED
;
261 Updates information about the firmware package.
263 This function updates package information.
264 This function returns EFI_UNSUPPORTED if the package information is not updatable.
265 VendorCode enables vendor to implement vendor-specific package information update policy.
266 Null if the caller did not specify this policy or use the default policy.
268 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
269 @param[in] Image Points to the authentication image.
270 Null if authentication is not required.
271 @param[in] ImageSize Size of the authentication image in bytes.
272 0 if authentication is not required.
273 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
275 Null indicates the caller did not specify this policy or use
277 @param[in] PackageVersion The new package version.
278 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
279 the package version name.
280 The string length is equal to or less than the value returned in
281 PackageVersionNameMaxLen.
283 @retval EFI_SUCCESS The device was successfully updated with the new package
285 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
286 returned in PackageVersionNameMaxLen.
287 @retval EFI_UNSUPPORTED The operation is not supported.
288 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
294 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
295 IN CONST VOID
*Image
,
297 IN CONST VOID
*VendorCode
,
298 IN UINT32 PackageVersion
,
299 IN CONST CHAR16
*PackageVersionName
302 return EFI_UNSUPPORTED
;
306 Initialize SystemFmpDriver private data structure.
308 @param[in] SystemFmpPrivate private data structure to be initialized.
310 @return EFI_SUCCESS private data is initialized.
313 InitializePrivateData (
314 IN SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
317 EFI_STATUS VarStatus
;
320 SystemFmpPrivate
->Signature
= SYSTEM_FMP_PRIVATE_DATA_SIGNATURE
;
321 SystemFmpPrivate
->Handle
= NULL
;
322 SystemFmpPrivate
->DescriptorCount
= 1;
323 CopyMem (&SystemFmpPrivate
->Fmp
, &mFirmwareManagementProtocol
, sizeof (EFI_FIRMWARE_MANAGEMENT_PROTOCOL
));
325 SystemFmpPrivate
->ImageDescriptor
= PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor
);
327 SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
= 0x0;
328 SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
= 0x0;
329 VarSize
= sizeof (SystemFmpPrivate
->LastAttempt
);
330 VarStatus
= gRT
->GetVariable (
331 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME
,
332 &gSystemFmpLastAttemptVariableGuid
,
335 &SystemFmpPrivate
->LastAttempt
337 DEBUG ((DEBUG_INFO
, "GetLastAttempt - %r\n", VarStatus
));
338 DEBUG ((DEBUG_INFO
, "GetLastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
, SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
));