]> git.proxmox.com Git - mirror_edk2.git/blob - FmpDevicePkg/FmpDxe/FmpDxe.h
FmpDevicePkg/FmpDxe: Different variable for each FMP Descriptor
[mirror_edk2.git] / FmpDevicePkg / FmpDxe / FmpDxe.h
1 /** @file
2 Produces a Firmware Management Protocol that supports updates to a firmware
3 image stored in a firmware device with platform and firmware device specific
4 information provided through PCDs and libraries.
5
6 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
7 Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11 **/
12
13 #ifndef _FMP_DXE_H_
14 #define _FMP_DXE_H_
15
16 #include <PiDxe.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/UefiRuntimeServicesTableLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/FmpAuthenticationLib.h>
25 #include <Library/FmpDeviceLib.h>
26 #include <Library/FmpPayloadHeaderLib.h>
27 #include <Library/CapsuleUpdatePolicyLib.h>
28 #include <Protocol/FirmwareManagement.h>
29 #include <Protocol/FirmwareManagementProgress.h>
30 #include <Protocol/VariableLock.h>
31 #include <Guid/SystemResourceTable.h>
32 #include <Guid/EventGroup.h>
33
34 #define VERSION_STRING_NOT_SUPPORTED L"VERSION STRING NOT SUPPORTED"
35 #define VERSION_STRING_NOT_AVAILABLE L"VERSION STRING NOT AVAILABLE"
36
37 ///
38 ///
39 ///
40 #define FIRMWARE_MANAGEMENT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('f','m','p','p')
41
42 typedef struct {
43 UINTN Signature;
44 EFI_HANDLE Handle;
45 EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp;
46 BOOLEAN DescriptorPopulated;
47 EFI_FIRMWARE_IMAGE_DESCRIPTOR Descriptor;
48 CHAR16 *ImageIdName;
49 CHAR16 *VersionName;
50 BOOLEAN RuntimeVersionSupported;
51 EFI_EVENT FmpDeviceLockEvent;
52 //
53 // Indicates if an attempt has been made to lock a
54 // FLASH storage device by calling FmpDeviceLock().
55 // A FLASH storage device may not support being locked,
56 // so this variable is set to TRUE even if FmpDeviceLock()
57 // returns an error.
58 //
59 BOOLEAN FmpDeviceLocked;
60 VOID *FmpDeviceContext;
61 CHAR16 *VersionVariableName;
62 CHAR16 *LsvVariableName;
63 CHAR16 *LastAttemptStatusVariableName;
64 CHAR16 *LastAttemptVersionVariableName;
65 CHAR16 *FmpStateVariableName;
66 } FIRMWARE_MANAGEMENT_PRIVATE_DATA;
67
68 ///
69 ///
70 ///
71 #define FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS(a) \
72 CR (a, FIRMWARE_MANAGEMENT_PRIVATE_DATA, Fmp, FIRMWARE_MANAGEMENT_PRIVATE_DATA_SIGNATURE)
73
74 /**
75 Check to see if any of the keys in PcdFmpDevicePkcs7CertBufferXdr matches
76 the test key. PcdFmpDeviceTestKeySha256Digest contains the SHA256 hash of
77 the test key. For each key in PcdFmpDevicePkcs7CertBufferXdr, compute the
78 SHA256 hash and compare it to PcdFmpDeviceTestKeySha256Digest. If the
79 SHA256 hash matches or there is then error computing the SHA256 hash, then
80 set PcdTestKeyUsed to TRUE. Skip this check if PcdTestKeyUsed is already
81 TRUE or PcdFmpDeviceTestKeySha256Digest is not exactly SHA256_DIGEST_SIZE
82 bytes.
83 **/
84 VOID
85 DetectTestKey (
86 VOID
87 );
88
89 /**
90 Returns information about the current firmware image(s) of the device.
91
92 This function allows a copy of the current firmware image to be created and saved.
93 The saved copy could later been used, for example, in firmware image recovery or rollback.
94
95 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
96 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
97 On input, this is the size of the buffer allocated by the caller.
98 On output, it is the size of the buffer returned by the firmware
99 if the buffer was large enough, or the size of the buffer needed
100 to contain the image(s) information if the buffer was too small.
101 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
102 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
103 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
104 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
105 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
106 descriptors or firmware images within this device.
107 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
108 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
109 @param[out] PackageVersion A version number that represents all the firmware images in the device.
110 The format is vendor specific and new version must have a greater value
111 than the old version. If PackageVersion is not supported, the value is
112 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
113 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
114 that package version update is in progress.
115 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
116 package version name. The buffer is allocated by this function with
117 AllocatePool(), and it is the caller's responsibility to free it with a call
118 to FreePool().
119
120 @retval EFI_SUCCESS The device was successfully updated with the new image.
121 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
122 needed to hold the image(s) information is returned in ImageInfoSize.
123 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
124 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
125
126 **/
127 EFI_STATUS
128 EFIAPI
129 GetTheImageInfo (
130 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
131 IN OUT UINTN *ImageInfoSize,
132 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
133 OUT UINT32 *DescriptorVersion,
134 OUT UINT8 *DescriptorCount,
135 OUT UINTN *DescriptorSize,
136 OUT UINT32 *PackageVersion,
137 OUT CHAR16 **PackageVersionName
138 );
139
140 /**
141 Retrieves a copy of the current firmware image of the device.
142
143 This function allows a copy of the current firmware image to be created and saved.
144 The saved copy could later been used, for example, in firmware image recovery or rollback.
145
146 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
147 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
148 The number is between 1 and DescriptorCount.
149 @param[in, out] Image Points to the buffer where the current image is copied to.
150 @param[in, out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
151 On return, points to the length of the image, in bytes.
152
153 @retval EFI_SUCCESS The device was successfully updated with the new image.
154 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
155 image. The current buffer size needed to hold the image is returned
156 in ImageSize.
157 @retval EFI_INVALID_PARAMETER The Image was NULL.
158 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
159 @retval EFI_UNSUPPORTED The operation is not supported.
160 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
161
162 **/
163 EFI_STATUS
164 EFIAPI
165 GetTheImage (
166 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
167 IN UINT8 ImageIndex,
168 IN OUT VOID *Image,
169 IN OUT UINTN *ImageSize
170 );
171
172
173 /**
174 Checks if the firmware image is valid for the device.
175
176 This function allows firmware update application to validate the firmware image without
177 invoking the SetImage() first.
178
179 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
180 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
181 The number is between 1 and DescriptorCount.
182 @param[in] Image Points to the new image.
183 @param[in] ImageSize Size of the new image in bytes.
184 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
185 if available, additional information if the image is invalid.
186
187 @retval EFI_SUCCESS The image was successfully checked.
188 @retval EFI_ABORTED The operation is aborted.
189 @retval EFI_INVALID_PARAMETER The Image was NULL.
190 @retval EFI_UNSUPPORTED The operation is not supported.
191 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
192
193 **/
194 EFI_STATUS
195 EFIAPI
196 CheckTheImage (
197 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
198 IN UINT8 ImageIndex,
199 IN CONST VOID *Image,
200 IN UINTN ImageSize,
201 OUT UINT32 *ImageUpdatable
202 );
203
204 /**
205 Updates the firmware image of the device.
206
207 This function updates the hardware with the new firmware image.
208 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
209 If the firmware image is updatable, the function should perform the following minimal validations
210 before proceeding to do the firmware image update.
211 - Validate the image authentication if image has attribute
212 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
213 EFI_SECURITY_VIOLATION if the validation fails.
214 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
215 the image is unsupported. The function can optionally provide more detailed information on
216 why the image is not a supported image.
217 - Validate the data from VendorCode if not null. Image validation must be performed before
218 VendorCode data validation. VendorCode data is ignored or considered invalid if image
219 validation failed. The function returns EFI_ABORTED if the data is invalid.
220
221 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
222 the caller did not specify the policy or use the default policy. As an example, vendor can implement
223 a policy to allow an option to force a firmware image update when the abort reason is due to the new
224 firmware image version is older than the current firmware image version or bad image checksum.
225 Sensitive operations such as those wiping the entire firmware image and render the device to be
226 non-functional should be encoded in the image itself rather than passed with the VendorCode.
227 AbortReason enables vendor to have the option to provide a more detailed description of the abort
228 reason to the caller.
229
230 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
231 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
232 The number is between 1 and DescriptorCount.
233 @param[in] Image Points to the new image.
234 @param[in] ImageSize Size of the new image in bytes.
235 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
236 Null indicates the caller did not specify the policy or use the default policy.
237 @param[in] Progress A function used by the driver to report the progress of the firmware update.
238 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
239 details for the aborted operation. The buffer is allocated by this function
240 with AllocatePool(), and it is the caller's responsibility to free it with a
241 call to FreePool().
242
243 @retval EFI_SUCCESS The device was successfully updated with the new image.
244 @retval EFI_ABORTED The operation is aborted.
245 @retval EFI_INVALID_PARAMETER The Image was NULL.
246 @retval EFI_UNSUPPORTED The operation is not supported.
247 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
248
249 **/
250 EFI_STATUS
251 EFIAPI
252 SetTheImage (
253 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
254 IN UINT8 ImageIndex,
255 IN CONST VOID *Image,
256 IN UINTN ImageSize,
257 IN CONST VOID *VendorCode,
258 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,
259 OUT CHAR16 **AbortReason
260 );
261
262 /**
263 Returns information about the firmware package.
264
265 This function returns package information.
266
267 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
268 @param[out] PackageVersion A version number that represents all the firmware images in the device.
269 The format is vendor specific and new version must have a greater value
270 than the old version. If PackageVersion is not supported, the value is
271 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
272 comparison is to be performed using PackageVersionName. A value of
273 0xFFFFFFFD indicates that package version update is in progress.
274 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
275 the package version name. The buffer is allocated by this function with
276 AllocatePool(), and it is the caller's responsibility to free it with a
277 call to FreePool().
278 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
279 package version name. A value of 0 indicates the device does not support
280 update of package version name. Length is the number of Unicode characters,
281 including the terminating null character.
282 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
283 Definitions' for possible returned values of this parameter. A value of 1
284 indicates the attribute is supported and the current setting value is
285 indicated in AttributesSetting. A value of 0 indicates the attribute is not
286 supported and the current setting value in AttributesSetting is meaningless.
287 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
288 values of this parameter
289
290 @retval EFI_SUCCESS The package information was successfully returned.
291 @retval EFI_UNSUPPORTED The operation is not supported.
292
293 **/
294 EFI_STATUS
295 EFIAPI
296 GetPackageInfo (
297 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
298 OUT UINT32 *PackageVersion,
299 OUT CHAR16 **PackageVersionName,
300 OUT UINT32 *PackageVersionNameMaxLen,
301 OUT UINT64 *AttributesSupported,
302 OUT UINT64 *AttributesSetting
303 );
304
305 /**
306 Updates information about the firmware package.
307
308 This function updates package information.
309 This function returns EFI_UNSUPPORTED if the package information is not updatable.
310 VendorCode enables vendor to implement vendor-specific package information update policy.
311 Null if the caller did not specify this policy or use the default policy.
312
313 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
314 @param[in] Image Points to the authentication image.
315 Null if authentication is not required.
316 @param[in] ImageSize Size of the authentication image in bytes.
317 0 if authentication is not required.
318 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
319 image update policy.
320 Null indicates the caller did not specify this policy or use
321 the default policy.
322 @param[in] PackageVersion The new package version.
323 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
324 the package version name.
325 The string length is equal to or less than the value returned in
326 PackageVersionNameMaxLen.
327
328 @retval EFI_SUCCESS The device was successfully updated with the new package
329 information.
330 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
331 returned in PackageVersionNameMaxLen.
332 @retval EFI_UNSUPPORTED The operation is not supported.
333 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
334
335 **/
336 EFI_STATUS
337 EFIAPI
338 SetPackageInfo (
339 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
340 IN CONST VOID *Image,
341 IN UINTN ImageSize,
342 IN CONST VOID *VendorCode,
343 IN UINT32 PackageVersion,
344 IN CONST CHAR16 *PackageVersionName
345 );
346
347 #endif