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