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