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