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