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