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