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