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