2 Produce FMP instance for system firmware.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "SystemFirmwareDxe.h"
17 EFI_GUID gSystemFmpLastAttemptVariableGuid
= SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID
;
18 EFI_GUID gSystemFmpProtocolGuid
= SYSTEM_FMP_PROTOCOL_GUID
;
20 EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol
= {
30 Returns information about the current firmware image(s) of the device.
32 This function allows a copy of the current firmware image to be created and saved.
33 The saved copy could later been used, for example, in firmware image recovery or rollback.
35 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
36 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
37 On input, this is the size of the buffer allocated by the caller.
38 On output, it is the size of the buffer returned by the firmware
39 if the buffer was large enough, or the size of the buffer needed
40 to contain the image(s) information if the buffer was too small.
41 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
42 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
43 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
44 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
45 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
46 descriptors or firmware images within this device.
47 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
48 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
49 @param[out] PackageVersion A version number that represents all the firmware images in the device.
50 The format is vendor specific and new version must have a greater value
51 than the old version. If PackageVersion is not supported, the value is
52 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
53 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
54 that package version update is in progress.
55 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
56 package version name. The buffer is allocated by this function with
57 AllocatePool(), and it is the caller's responsibility to free it with a call
60 @retval EFI_SUCCESS The device was successfully updated with the new image.
61 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
62 needed to hold the image(s) information is returned in ImageInfoSize.
63 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
64 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
70 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
71 IN OUT UINTN
*ImageInfoSize
,
72 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
73 OUT UINT32
*DescriptorVersion
,
74 OUT UINT8
*DescriptorCount
,
75 OUT UINTN
*DescriptorSize
,
76 OUT UINT32
*PackageVersion
,
77 OUT CHAR16
**PackageVersionName
80 SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
;
81 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR
*ImageDescriptor
;
83 SystemFmpPrivate
= SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This
);
85 if(ImageInfoSize
== NULL
) {
86 return EFI_INVALID_PARAMETER
;
89 if (*ImageInfoSize
< sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
) {
90 *ImageInfoSize
= sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
;
91 return EFI_BUFFER_TOO_SMALL
;
94 if (ImageInfo
== NULL
||
95 DescriptorVersion
== NULL
||
96 DescriptorCount
== NULL
||
97 DescriptorSize
== NULL
||
98 PackageVersion
== NULL
||
99 PackageVersionName
== NULL
) {
100 return EFI_INVALID_PARAMETER
;
103 *ImageInfoSize
= sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR
) * SystemFmpPrivate
->DescriptorCount
;
104 *DescriptorSize
= sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR
);
105 *DescriptorCount
= SystemFmpPrivate
->DescriptorCount
;
106 *DescriptorVersion
= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION
;
109 // supports 1 ImageInfo descriptor
111 ImageDescriptor
= SystemFmpPrivate
->ImageDescriptor
;
112 ImageInfo
->ImageIndex
= ImageDescriptor
->ImageIndex
;
113 CopyGuid (&ImageInfo
->ImageTypeId
, &ImageDescriptor
->ImageTypeId
);
114 ImageInfo
->ImageId
= ImageDescriptor
->ImageId
;
115 if (ImageDescriptor
->ImageIdNameStringOffset
!= 0) {
116 ImageInfo
->ImageIdName
= (CHAR16
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->ImageIdNameStringOffset
);
118 ImageInfo
->ImageIdName
= NULL
;
120 ImageInfo
->Version
= ImageDescriptor
->Version
;
121 if (ImageDescriptor
->VersionNameStringOffset
!= 0) {
122 ImageInfo
->VersionName
= (CHAR16
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->VersionNameStringOffset
);
124 ImageInfo
->VersionName
= NULL
;
126 ImageInfo
->Size
= (UINTN
)ImageDescriptor
->Size
;
127 ImageInfo
->AttributesSupported
= ImageDescriptor
->AttributesSupported
;
128 ImageInfo
->AttributesSetting
= ImageDescriptor
->AttributesSetting
;
129 ImageInfo
->Compatibilities
= ImageDescriptor
->Compatibilities
;
130 ImageInfo
->LowestSupportedImageVersion
= ImageDescriptor
->LowestSupportedImageVersion
;
131 ImageInfo
->LastAttemptVersion
= SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
;
132 ImageInfo
->LastAttemptStatus
= SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
;
133 ImageInfo
->HardwareInstance
= ImageDescriptor
->HardwareInstance
;
138 *PackageVersion
= ImageDescriptor
->PackageVersion
;
139 if (ImageDescriptor
->PackageVersionNameStringOffset
!= 0) {
140 *PackageVersionName
= (VOID
*)((UINTN
)ImageDescriptor
+ ImageDescriptor
->PackageVersionNameStringOffset
);
141 *PackageVersionName
= AllocateCopyPool(StrSize(*PackageVersionName
), *PackageVersionName
);
143 *PackageVersionName
= NULL
;
150 Retrieves a copy of the current firmware image of the device.
152 This function allows a copy of the current firmware image to be created and saved.
153 The saved copy could later been used, for example, in firmware image recovery or rollback.
155 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
156 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
157 The number is between 1 and DescriptorCount.
158 @param[in,out] Image Points to the buffer where the current image is copied to.
159 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
160 On return, points to the length of the image, in bytes.
162 @retval EFI_SUCCESS The device was successfully updated with the new image.
163 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
164 image. The current buffer size needed to hold the image is returned
166 @retval EFI_INVALID_PARAMETER The Image was NULL.
167 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
168 @retval EFI_UNSUPPORTED The operation is not supported.
169 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.
175 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
178 IN OUT UINTN
*ImageSize
181 SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
;
183 if (Image
== NULL
|| ImageSize
== NULL
) {
184 return EFI_INVALID_PARAMETER
;
187 SystemFmpPrivate
= SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This
);
189 if (ImageIndex
== 0 || ImageIndex
> SystemFmpPrivate
->DescriptorCount
|| ImageSize
== NULL
|| Image
== NULL
) {
190 return EFI_INVALID_PARAMETER
;
193 return EFI_UNSUPPORTED
;
197 Checks if the firmware image is valid for the device.
199 This function allows firmware update application to validate the firmware image without
200 invoking the SetImage() first.
202 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
203 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
204 The number is between 1 and DescriptorCount.
205 @param[in] Image Points to the new image.
206 @param[in] ImageSize Size of the new image in bytes.
207 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
208 if available, additional information if the image is invalid.
210 @retval EFI_SUCCESS The image was successfully checked.
211 @retval EFI_INVALID_PARAMETER The Image was NULL.
212 @retval EFI_UNSUPPORTED The operation is not supported.
213 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.
219 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
221 IN CONST VOID
*Image
,
223 OUT UINT32
*ImageUpdatable
226 return EFI_UNSUPPORTED
;
230 Returns information about the firmware package.
232 This function returns package information.
234 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
235 @param[out] PackageVersion A version number that represents all the firmware images in the device.
236 The format is vendor specific and new version must have a greater value
237 than the old version. If PackageVersion is not supported, the value is
238 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
239 comparison is to be performed using PackageVersionName. A value of
240 0xFFFFFFFD indicates that package version update is in progress.
241 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
242 the package version name. The buffer is allocated by this function with
243 AllocatePool(), and it is the caller's responsibility to free it with a
245 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
246 package version name. A value of 0 indicates the device does not support
247 update of package version name. Length is the number of Unicode characters,
248 including the terminating null character.
249 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
250 Definitions' for possible returned values of this parameter. A value of 1
251 indicates the attribute is supported and the current setting value is
252 indicated in AttributesSetting. A value of 0 indicates the attribute is not
253 supported and the current setting value in AttributesSetting is meaningless.
254 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
255 values of this parameter
257 @retval EFI_SUCCESS The package information was successfully returned.
258 @retval EFI_UNSUPPORTED The operation is not supported.
264 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
265 OUT UINT32
*PackageVersion
,
266 OUT CHAR16
**PackageVersionName
,
267 OUT UINT32
*PackageVersionNameMaxLen
,
268 OUT UINT64
*AttributesSupported
,
269 OUT UINT64
*AttributesSetting
272 return EFI_UNSUPPORTED
;
276 Updates information about the firmware package.
278 This function updates package information.
279 This function returns EFI_UNSUPPORTED if the package information is not updatable.
280 VendorCode enables vendor to implement vendor-specific package information update policy.
281 Null if the caller did not specify this policy or use the default policy.
283 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
284 @param[in] Image Points to the authentication image.
285 Null if authentication is not required.
286 @param[in] ImageSize Size of the authentication image in bytes.
287 0 if authentication is not required.
288 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
290 Null indicates the caller did not specify this policy or use
292 @param[in] PackageVersion The new package version.
293 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
294 the package version name.
295 The string length is equal to or less than the value returned in
296 PackageVersionNameMaxLen.
298 @retval EFI_SUCCESS The device was successfully updated with the new package
300 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
301 returned in PackageVersionNameMaxLen.
302 @retval EFI_UNSUPPORTED The operation is not supported.
303 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.
309 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
310 IN CONST VOID
*Image
,
312 IN CONST VOID
*VendorCode
,
313 IN UINT32 PackageVersion
,
314 IN CONST CHAR16
*PackageVersionName
317 return EFI_UNSUPPORTED
;
321 Initialize SystemFmpDriver private data structure.
323 @param[in] SystemFmpPrivate private data structure to be initialized.
325 @return EFI_SUCCESS private data is initialized.
328 InitializePrivateData (
329 IN SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
332 EFI_STATUS VarStatus
;
335 SystemFmpPrivate
->Signature
= SYSTEM_FMP_PRIVATE_DATA_SIGNATURE
;
336 SystemFmpPrivate
->Handle
= NULL
;
337 SystemFmpPrivate
->DescriptorCount
= 1;
338 CopyMem(&SystemFmpPrivate
->Fmp
, &mFirmwareManagementProtocol
, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL
));
340 SystemFmpPrivate
->ImageDescriptor
= PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor
);
342 SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
= 0x0;
343 SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
= 0x0;
344 VarSize
= sizeof(SystemFmpPrivate
->LastAttempt
);
345 VarStatus
= gRT
->GetVariable(
346 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME
,
347 &gSystemFmpLastAttemptVariableGuid
,
350 &SystemFmpPrivate
->LastAttempt
352 DEBUG((DEBUG_INFO
, "GetLastAttemp - %r\n", VarStatus
));
353 DEBUG((DEBUG_INFO
, "GetLastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
, SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
));
359 Return if this FMP is a system FMP or a device FMP, based upon FmpImageInfo.
361 @param[in] FmpImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR
363 @retval TRUE It is a system FMP.
364 @retval FALSE It is a device FMP.
368 IN EFI_FIRMWARE_IMAGE_DESCRIPTOR
*FmpImageInfo
375 Guid
= PcdGetPtr(PcdSystemFmpCapsuleImageTypeIdGuid
);
376 Count
= PcdGetSize(PcdSystemFmpCapsuleImageTypeIdGuid
) / sizeof(GUID
);
378 for (Index
= 0; Index
< Count
; Index
++, Guid
++) {
379 if (CompareGuid(&FmpImageInfo
->ImageTypeId
, Guid
)) {