2 Produce FMP instance for system firmware.
4 Copyright (c) 2016 - 2018, 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_VIOLATION The operation could not be performed due to an authentication failure.
175 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
178 IN OUT UINTN
*ImageSize
181 return EFI_UNSUPPORTED
;
185 Checks if the firmware image is valid for the device.
187 This function allows firmware update application to validate the firmware image without
188 invoking the SetImage() first.
190 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
191 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
192 The number is between 1 and DescriptorCount.
193 @param[in] Image Points to the new image.
194 @param[in] ImageSize Size of the new image in bytes.
195 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
196 if available, additional information if the image is invalid.
198 @retval EFI_SUCCESS The image was successfully checked.
199 @retval EFI_INVALID_PARAMETER The Image was NULL.
200 @retval EFI_UNSUPPORTED The operation is not supported.
201 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
207 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
209 IN CONST VOID
*Image
,
211 OUT UINT32
*ImageUpdatable
214 return EFI_UNSUPPORTED
;
218 Returns information about the firmware package.
220 This function returns package information.
222 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
223 @param[out] PackageVersion A version number that represents all the firmware images in the device.
224 The format is vendor specific and new version must have a greater value
225 than the old version. If PackageVersion is not supported, the value is
226 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
227 comparison is to be performed using PackageVersionName. A value of
228 0xFFFFFFFD indicates that package version update is in progress.
229 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
230 the package version name. The buffer is allocated by this function with
231 AllocatePool(), and it is the caller's responsibility to free it with a
233 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
234 package version name. A value of 0 indicates the device does not support
235 update of package version name. Length is the number of Unicode characters,
236 including the terminating null character.
237 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
238 Definitions' for possible returned values of this parameter. A value of 1
239 indicates the attribute is supported and the current setting value is
240 indicated in AttributesSetting. A value of 0 indicates the attribute is not
241 supported and the current setting value in AttributesSetting is meaningless.
242 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
243 values of this parameter
245 @retval EFI_SUCCESS The package information was successfully returned.
246 @retval EFI_UNSUPPORTED The operation is not supported.
252 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
253 OUT UINT32
*PackageVersion
,
254 OUT CHAR16
**PackageVersionName
,
255 OUT UINT32
*PackageVersionNameMaxLen
,
256 OUT UINT64
*AttributesSupported
,
257 OUT UINT64
*AttributesSetting
260 return EFI_UNSUPPORTED
;
264 Updates information about the firmware package.
266 This function updates package information.
267 This function returns EFI_UNSUPPORTED if the package information is not updatable.
268 VendorCode enables vendor to implement vendor-specific package information update policy.
269 Null if the caller did not specify this policy or use the default policy.
271 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
272 @param[in] Image Points to the authentication image.
273 Null if authentication is not required.
274 @param[in] ImageSize Size of the authentication image in bytes.
275 0 if authentication is not required.
276 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
278 Null indicates the caller did not specify this policy or use
280 @param[in] PackageVersion The new package version.
281 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
282 the package version name.
283 The string length is equal to or less than the value returned in
284 PackageVersionNameMaxLen.
286 @retval EFI_SUCCESS The device was successfully updated with the new package
288 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
289 returned in PackageVersionNameMaxLen.
290 @retval EFI_UNSUPPORTED The operation is not supported.
291 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
297 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
298 IN CONST VOID
*Image
,
300 IN CONST VOID
*VendorCode
,
301 IN UINT32 PackageVersion
,
302 IN CONST CHAR16
*PackageVersionName
305 return EFI_UNSUPPORTED
;
309 Initialize SystemFmpDriver private data structure.
311 @param[in] SystemFmpPrivate private data structure to be initialized.
313 @return EFI_SUCCESS private data is initialized.
316 InitializePrivateData (
317 IN SYSTEM_FMP_PRIVATE_DATA
*SystemFmpPrivate
320 EFI_STATUS VarStatus
;
323 SystemFmpPrivate
->Signature
= SYSTEM_FMP_PRIVATE_DATA_SIGNATURE
;
324 SystemFmpPrivate
->Handle
= NULL
;
325 SystemFmpPrivate
->DescriptorCount
= 1;
326 CopyMem(&SystemFmpPrivate
->Fmp
, &mFirmwareManagementProtocol
, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL
));
328 SystemFmpPrivate
->ImageDescriptor
= PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor
);
330 SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
= 0x0;
331 SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
= 0x0;
332 VarSize
= sizeof(SystemFmpPrivate
->LastAttempt
);
333 VarStatus
= gRT
->GetVariable(
334 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME
,
335 &gSystemFmpLastAttemptVariableGuid
,
338 &SystemFmpPrivate
->LastAttempt
340 DEBUG((DEBUG_INFO
, "GetLastAttemp - %r\n", VarStatus
));
341 DEBUG((DEBUG_INFO
, "GetLastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate
->LastAttempt
.LastAttemptVersion
, SystemFmpPrivate
->LastAttempt
.LastAttemptStatus
));