]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareDxe.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SignedCapsulePkg / Universal / SystemFirmwareUpdate / SystemFirmwareDxe.h
CommitLineData
f6f91d38
JY
1/** @file\r
2 System Firmware update header file.\r
3\r
c8dca871 4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
fbf06957 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
f6f91d38
JY
6\r
7**/\r
8\r
9#ifndef _SYSTEM_FIRMWARE_UPDATE_H_\r
10#define _SYSTEM_FIRMWARE_UPDATE_H_\r
11\r
12#include <PiDxe.h>\r
13\r
14#include <Guid/SystemResourceTable.h>\r
15#include <Guid/FirmwareContentsSigned.h>\r
16#include <Guid/WinCertificate.h>\r
17#include <Guid/EdkiiSystemFmpCapsule.h>\r
18\r
19#include <Protocol/FirmwareManagement.h>\r
20#include <Protocol/FirmwareVolumeBlock.h>\r
21\r
22#include <Library/BaseLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/DebugLib.h>\r
25#include <Library/MemoryAllocationLib.h>\r
26#include <Library/PcdLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/UefiLib.h>\r
29#include <Library/UefiRuntimeServicesTableLib.h>\r
30#include <Library/UefiDriverEntryPoint.h>\r
31#include <Library/DevicePathLib.h>\r
32#include <Library/HobLib.h>\r
f6f91d38
JY
33#include <Library/DxeServicesTableLib.h>\r
34#include <Library/PlatformFlashAccessLib.h>\r
35#include <Library/EdkiiSystemCapsuleLib.h>\r
36\r
37typedef struct {\r
b8786489
MK
38 UINT32 LastAttemptVersion;\r
39 UINT32 LastAttemptStatus;\r
f6f91d38
JY
40} SYSTEM_FMP_LAST_ATTEMPT_VARIABLE;\r
41\r
42#define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME L"SystemLastAttempVar"\r
43\r
b8786489 44#define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID {0x2f564d6f, 0xcc2c, 0x4838, { 0xb9, 0xa8, 0xbe, 0x59, 0x48, 0xb0, 0x3d, 0x59 }}\r
f6f91d38
JY
45\r
46#define SYSTEM_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('S', 'Y', 'S', 'F')\r
47\r
b8786489 48#define SYSTEM_FMP_PROTOCOL_GUID {0x6d16624a, 0x26a6, 0x4cb4, { 0x84, 0xfa, 0x6, 0x78, 0x5a, 0x7e, 0x82, 0x6a }}\r
f6f91d38
JY
49\r
50//\r
51// SYSTEM FMP private data structure.\r
52//\r
53\r
54struct _SYSTEM_FMP_PRIVATE_DATA {\r
b8786489
MK
55 UINT32 Signature;\r
56 EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp;\r
57 EFI_HANDLE Handle;\r
58 UINT8 DescriptorCount;\r
59 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;\r
60 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE LastAttempt;\r
f6f91d38
JY
61};\r
62\r
b8786489 63typedef struct _SYSTEM_FMP_PRIVATE_DATA SYSTEM_FMP_PRIVATE_DATA;\r
f6f91d38
JY
64\r
65/**\r
66 Returns a pointer to the SYSTEM_FMP_PRIVATE_DATA structure from the input a as Fmp.\r
67\r
68 If the signatures matches, then a pointer to the data structure that contains\r
69 a specified field of that data structure is returned.\r
70\r
71 @param a Pointer to the field specified by ServiceBinding within\r
72 a data structure of type SYSTEM_FMP_PRIVATE_DATA.\r
73\r
74**/\r
75#define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a) \\r
76 CR ( \\r
77 (a), \\r
78 SYSTEM_FMP_PRIVATE_DATA, \\r
79 Fmp, \\r
80 SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \\r
81 )\r
82\r
f6f91d38
JY
83//\r
84// Update data\r
85//\r
86\r
87typedef struct {\r
b8786489 88 UINTN NumOfUpdates;\r
f6f91d38
JY
89} CONFIG_HEADER;\r
90\r
91typedef struct {\r
b8786489
MK
92 UINTN Index;\r
93 PLATFORM_FIRMWARE_TYPE FirmwareType;\r
94 FLASH_ADDRESS_TYPE AddressType;\r
95 EFI_GUID FileGuid;\r
96 EFI_PHYSICAL_ADDRESS BaseAddress;\r
97 UINTN Length;\r
98 UINTN ImageOffset;\r
f6f91d38
JY
99} UPDATE_CONFIG_DATA;\r
100\r
101//\r
102// System Firmware Update SMM Communication\r
103//\r
104\r
b8786489 105#define SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_FUNCTION_SET_IMAGE 1\r
f6f91d38
JY
106\r
107typedef struct {\r
b8786489
MK
108 UINTN Function;\r
109 EFI_STATUS ReturnStatus;\r
110 // UINT8 Data[];\r
f6f91d38
JY
111} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD;\r
112\r
b8786489 113#define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0'\r
f6f91d38 114\r
c38f0816 115#define CAPSULE_IMAGE_ADDITIONAL_MAX_SIZE (0x20020 + 0xA0000) // Additional size for Capsule Header, FV block alignment + DispatchImage.\r
f6f91d38
JY
116\r
117typedef struct {\r
b8786489
MK
118 UINT8 ImageIndex;\r
119 UINTN ImageSize;\r
120 UINTN AbortReasonSize;\r
121 UINT32 LastAttemptVersion;\r
122 UINT32 LastAttemptStatus;\r
123 // UINT8 Data[AbortReasonMaxSize + ImageSize];\r
f6f91d38
JY
124} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE;\r
125\r
f6f91d38
JY
126/**\r
127 Returns information about the current firmware image(s) of the device.\r
128\r
129 This function allows a copy of the current firmware image to be created and saved.\r
130 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
131\r
132 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
133 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r
134 On input, this is the size of the buffer allocated by the caller.\r
135 On output, it is the size of the buffer returned by the firmware\r
136 if the buffer was large enough, or the size of the buffer needed\r
137 to contain the image(s) information if the buffer was too small.\r
138 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r
139 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
140 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r
141 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
142 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r
143 descriptors or firmware images within this device.\r
144 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r
145 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
146 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
147 The format is vendor specific and new version must have a greater value\r
148 than the old version. If PackageVersion is not supported, the value is\r
149 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
150 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
151 that package version update is in progress.\r
152 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
153 package version name. The buffer is allocated by this function with\r
154 AllocatePool(), and it is the caller's responsibility to free it with a call\r
155 to FreePool().\r
156\r
157 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
158 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r
159 needed to hold the image(s) information is returned in ImageInfoSize.\r
160 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r
161 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r
162\r
163**/\r
164EFI_STATUS\r
165EFIAPI\r
166FmpGetImageInfo (\r
b8786489
MK
167 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
168 IN OUT UINTN *ImageInfoSize,\r
169 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r
170 OUT UINT32 *DescriptorVersion,\r
171 OUT UINT8 *DescriptorCount,\r
172 OUT UINTN *DescriptorSize,\r
173 OUT UINT32 *PackageVersion,\r
174 OUT CHAR16 **PackageVersionName\r
f6f91d38
JY
175 );\r
176\r
177/**\r
178 Retrieves a copy of the current firmware image of the device.\r
179\r
180 This function allows a copy of the current firmware image to be created and saved.\r
181 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
182\r
183 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
184 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
185 The number is between 1 and DescriptorCount.\r
186 @param[in,out] Image Points to the buffer where the current image is copied to.\r
187 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r
188 On return, points to the length of the image, in bytes.\r
189\r
190 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
191 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r
192 image. The current buffer size needed to hold the image is returned\r
193 in ImageSize.\r
194 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
195 @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r
196 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 197 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202FmpGetImage (\r
203 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
204 IN UINT8 ImageIndex,\r
205 IN OUT VOID *Image,\r
206 IN OUT UINTN *ImageSize\r
207 );\r
208\r
209/**\r
210 Updates the firmware image of the device.\r
211\r
212 This function updates the hardware with the new firmware image.\r
213 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
214 If the firmware image is updatable, the function should perform the following minimal validations\r
215 before proceeding to do the firmware image update.\r
216 - Validate the image authentication if image has attribute\r
217 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
218 EFI_SECURITY_VIOLATION if the validation fails.\r
219 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
220 the image is unsupported. The function can optionally provide more detailed information on\r
221 why the image is not a supported image.\r
222 - Validate the data from VendorCode if not null. Image validation must be performed before\r
223 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
224 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
225\r
226 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
227 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
228 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
229 firmware image version is older than the current firmware image version or bad image checksum.\r
230 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
231 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
232 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
233 reason to the caller.\r
234\r
235 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
236 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
237 The number is between 1 and DescriptorCount.\r
238 @param[in] Image Points to the new image.\r
239 @param[in] ImageSize Size of the new image in bytes.\r
240 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
241 Null indicates the caller did not specify the policy or use the default policy.\r
242 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
243 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
244 details for the aborted operation. The buffer is allocated by this function\r
245 with AllocatePool(), and it is the caller's responsibility to free it with a\r
246 call to FreePool().\r
247\r
248 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
249 @retval EFI_ABORTED The operation is aborted.\r
250 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
251 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 252 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
253\r
254**/\r
255EFI_STATUS\r
256EFIAPI\r
257FmpSetImage (\r
b8786489
MK
258 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
259 IN UINT8 ImageIndex,\r
260 IN CONST VOID *Image,\r
261 IN UINTN ImageSize,\r
262 IN CONST VOID *VendorCode,\r
263 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
264 OUT CHAR16 **AbortReason\r
f6f91d38
JY
265 );\r
266\r
267/**\r
268 Checks if the firmware image is valid for the device.\r
269\r
270 This function allows firmware update application to validate the firmware image without\r
271 invoking the SetImage() first.\r
272\r
273 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
274 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
275 The number is between 1 and DescriptorCount.\r
276 @param[in] Image Points to the new image.\r
277 @param[in] ImageSize Size of the new image in bytes.\r
278 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
279 if available, additional information if the image is invalid.\r
280\r
281 @retval EFI_SUCCESS The image was successfully checked.\r
282 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
283 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 284 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
285\r
286**/\r
287EFI_STATUS\r
288EFIAPI\r
289FmpCheckImage (\r
290 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
291 IN UINT8 ImageIndex,\r
292 IN CONST VOID *Image,\r
293 IN UINTN ImageSize,\r
294 OUT UINT32 *ImageUpdatable\r
295 );\r
296\r
297/**\r
298 Returns information about the firmware package.\r
299\r
300 This function returns package information.\r
301\r
302 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
303 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
304 The format is vendor specific and new version must have a greater value\r
305 than the old version. If PackageVersion is not supported, the value is\r
306 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
307 comparison is to be performed using PackageVersionName. A value of\r
308 0xFFFFFFFD indicates that package version update is in progress.\r
309 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
310 the package version name. The buffer is allocated by this function with\r
311 AllocatePool(), and it is the caller's responsibility to free it with a\r
312 call to FreePool().\r
313 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
314 package version name. A value of 0 indicates the device does not support\r
315 update of package version name. Length is the number of Unicode characters,\r
316 including the terminating null character.\r
317 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
318 Definitions' for possible returned values of this parameter. A value of 1\r
319 indicates the attribute is supported and the current setting value is\r
320 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
321 supported and the current setting value in AttributesSetting is meaningless.\r
322 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
323 values of this parameter\r
324\r
325 @retval EFI_SUCCESS The package information was successfully returned.\r
326 @retval EFI_UNSUPPORTED The operation is not supported.\r
327\r
328**/\r
329EFI_STATUS\r
330EFIAPI\r
331FmpGetPackageInfo (\r
b8786489
MK
332 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
333 OUT UINT32 *PackageVersion,\r
334 OUT CHAR16 **PackageVersionName,\r
335 OUT UINT32 *PackageVersionNameMaxLen,\r
336 OUT UINT64 *AttributesSupported,\r
337 OUT UINT64 *AttributesSetting\r
f6f91d38
JY
338 );\r
339\r
340/**\r
341 Updates information about the firmware package.\r
342\r
343 This function updates package information.\r
344 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
345 VendorCode enables vendor to implement vendor-specific package information update policy.\r
346 Null if the caller did not specify this policy or use the default policy.\r
347\r
348 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
349 @param[in] Image Points to the authentication image.\r
350 Null if authentication is not required.\r
351 @param[in] ImageSize Size of the authentication image in bytes.\r
352 0 if authentication is not required.\r
353 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
354 image update policy.\r
355 Null indicates the caller did not specify this policy or use\r
356 the default policy.\r
357 @param[in] PackageVersion The new package version.\r
358 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
359 the package version name.\r
360 The string length is equal to or less than the value returned in\r
361 PackageVersionNameMaxLen.\r
362\r
363 @retval EFI_SUCCESS The device was successfully updated with the new package\r
364 information.\r
365 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
366 returned in PackageVersionNameMaxLen.\r
367 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 368 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
369\r
370**/\r
371EFI_STATUS\r
372EFIAPI\r
373FmpSetPackageInfo (\r
b8786489
MK
374 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
375 IN CONST VOID *Image,\r
376 IN UINTN ImageSize,\r
377 IN CONST VOID *VendorCode,\r
378 IN UINT32 PackageVersion,\r
379 IN CONST CHAR16 *PackageVersionName\r
f6f91d38
JY
380 );\r
381\r
382/**\r
383 Initialize SystemFmpDriver private data structure.\r
384\r
385 @param[in] SystemFmpPrivate private data structure to be initialized.\r
386\r
387 @return EFI_SUCCESS private data is initialized.\r
388**/\r
389EFI_STATUS\r
390InitializePrivateData (\r
391 IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate\r
392 );\r
393\r
b8786489
MK
394extern EFI_GUID gSystemFmpLastAttemptVariableGuid;\r
395extern EFI_GUID mCurrentImageTypeId;\r
396extern EFI_GUID gSystemFmpProtocolGuid;\r
f6f91d38
JY
397\r
398#endif\r