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