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