]>
Commit | Line | Data |
---|---|---|
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 | |
37 | typedef struct {\r | |
38 | UINT32 LastAttemptVersion;\r | |
39 | UINT32 LastAttemptStatus;\r | |
40 | } SYSTEM_FMP_LAST_ATTEMPT_VARIABLE;\r | |
41 | \r | |
42 | #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME L"SystemLastAttempVar"\r | |
43 | \r | |
44 | #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID {0x2f564d6f, 0xcc2c, 0x4838, { 0xb9, 0xa8, 0xbe, 0x59, 0x48, 0xb0, 0x3d, 0x59 }}\r | |
45 | \r | |
46 | #define SYSTEM_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('S', 'Y', 'S', 'F')\r | |
47 | \r | |
48 | #define SYSTEM_FMP_PROTOCOL_GUID {0x6d16624a, 0x26a6, 0x4cb4, { 0x84, 0xfa, 0x6, 0x78, 0x5a, 0x7e, 0x82, 0x6a }}\r | |
49 | \r | |
50 | //\r | |
51 | // SYSTEM FMP private data structure.\r | |
52 | //\r | |
53 | \r | |
54 | struct _SYSTEM_FMP_PRIVATE_DATA {\r | |
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 | |
61 | };\r | |
62 | \r | |
63 | typedef struct _SYSTEM_FMP_PRIVATE_DATA SYSTEM_FMP_PRIVATE_DATA;\r | |
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 | |
83 | \r | |
84 | //\r | |
85 | // Update data\r | |
86 | //\r | |
87 | \r | |
88 | typedef struct {\r | |
89 | UINTN NumOfUpdates;\r | |
90 | } CONFIG_HEADER;\r | |
91 | \r | |
92 | typedef struct {\r | |
93 | UINTN Index;\r | |
94 | PLATFORM_FIRMWARE_TYPE FirmwareType;\r | |
95 | FLASH_ADDRESS_TYPE AddressType;\r | |
96 | EFI_GUID FileGuid;\r | |
97 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
98 | UINTN Length;\r | |
99 | UINTN ImageOffset;\r | |
100 | } UPDATE_CONFIG_DATA;\r | |
101 | \r | |
102 | //\r | |
103 | // System Firmware Update SMM Communication\r | |
104 | //\r | |
105 | \r | |
106 | #define SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_FUNCTION_SET_IMAGE 1\r | |
107 | \r | |
108 | typedef struct {\r | |
109 | UINTN Function;\r | |
110 | EFI_STATUS ReturnStatus;\r | |
111 | //UINT8 Data[];\r | |
112 | } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD;\r | |
113 | \r | |
114 | #define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0'\r | |
115 | \r | |
c38f0816 | 116 | #define CAPSULE_IMAGE_ADDITIONAL_MAX_SIZE (0x20020 + 0xA0000) // Additional size for Capsule Header, FV block alignment + DispatchImage.\r |
f6f91d38 JY |
117 | \r |
118 | typedef struct {\r | |
119 | UINT8 ImageIndex;\r | |
120 | UINTN ImageSize;\r | |
121 | UINTN AbortReasonSize;\r | |
122 | UINT32 LastAttemptVersion;\r | |
123 | UINT32 LastAttemptStatus;\r | |
124 | //UINT8 Data[AbortReasonMaxSize + ImageSize];\r | |
125 | } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE;\r | |
126 | \r | |
127 | \r | |
128 | /**\r | |
129 | Returns information about the current firmware image(s) of the device.\r | |
130 | \r | |
131 | This function allows a copy of the current firmware image to be created and saved.\r | |
132 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
133 | \r | |
134 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
135 | @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r | |
136 | On input, this is the size of the buffer allocated by the caller.\r | |
137 | On output, it is the size of the buffer returned by the firmware\r | |
138 | if the buffer was large enough, or the size of the buffer needed\r | |
139 | to contain the image(s) information if the buffer was too small.\r | |
140 | @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r | |
141 | information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r | |
142 | @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r | |
143 | associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
144 | @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r | |
145 | descriptors or firmware images within this device.\r | |
146 | @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r | |
147 | of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
148 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
149 | The format is vendor specific and new version must have a greater value\r | |
150 | than the old version. If PackageVersion is not supported, the value is\r | |
151 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r | |
152 | is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r | |
153 | that package version update is in progress.\r | |
154 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r | |
155 | package version name. The buffer is allocated by this function with\r | |
156 | AllocatePool(), and it is the caller's responsibility to free it with a call\r | |
157 | to FreePool().\r | |
158 | \r | |
159 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
160 | @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r | |
161 | needed to hold the image(s) information is returned in ImageInfoSize.\r | |
162 | @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r | |
163 | @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r | |
164 | \r | |
165 | **/\r | |
166 | EFI_STATUS\r | |
167 | EFIAPI\r | |
168 | FmpGetImageInfo (\r | |
169 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
170 | IN OUT UINTN *ImageInfoSize,\r | |
171 | IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r | |
172 | OUT UINT32 *DescriptorVersion,\r | |
173 | OUT UINT8 *DescriptorCount,\r | |
174 | OUT UINTN *DescriptorSize,\r | |
175 | OUT UINT32 *PackageVersion,\r | |
176 | OUT CHAR16 **PackageVersionName\r | |
177 | );\r | |
178 | \r | |
179 | /**\r | |
180 | Retrieves a copy of the current firmware image of the device.\r | |
181 | \r | |
182 | This function allows a copy of the current firmware image to be created and saved.\r | |
183 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
184 | \r | |
185 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
186 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
187 | The number is between 1 and DescriptorCount.\r | |
188 | @param[in,out] Image Points to the buffer where the current image is copied to.\r | |
189 | @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r | |
190 | On return, points to the length of the image, in bytes.\r | |
191 | \r | |
192 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
193 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r | |
194 | image. The current buffer size needed to hold the image is returned\r | |
195 | in ImageSize.\r | |
196 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
197 | @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r | |
198 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
c8dca871 | 199 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
f6f91d38 JY |
200 | \r |
201 | **/\r | |
202 | EFI_STATUS\r | |
203 | EFIAPI\r | |
204 | FmpGetImage (\r | |
205 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
206 | IN UINT8 ImageIndex,\r | |
207 | IN OUT VOID *Image,\r | |
208 | IN OUT UINTN *ImageSize\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 | |
c8dca871 | 254 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
f6f91d38 JY |
255 | \r |
256 | **/\r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | FmpSetImage (\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 | Checks if the firmware image is valid for the device.\r | |
271 | \r | |
272 | This function allows firmware update application to validate the firmware image without\r | |
273 | invoking the SetImage() first.\r | |
274 | \r | |
275 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
276 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
277 | The number is between 1 and DescriptorCount.\r | |
278 | @param[in] Image Points to the new image.\r | |
279 | @param[in] ImageSize Size of the new image in bytes.\r | |
280 | @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r | |
281 | if available, additional information if the image is invalid.\r | |
282 | \r | |
283 | @retval EFI_SUCCESS The image was successfully checked.\r | |
284 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
285 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
c8dca871 | 286 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
f6f91d38 JY |
287 | \r |
288 | **/\r | |
289 | EFI_STATUS\r | |
290 | EFIAPI\r | |
291 | FmpCheckImage (\r | |
292 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
293 | IN UINT8 ImageIndex,\r | |
294 | IN CONST VOID *Image,\r | |
295 | IN UINTN ImageSize,\r | |
296 | OUT UINT32 *ImageUpdatable\r | |
297 | );\r | |
298 | \r | |
299 | /**\r | |
300 | Returns information about the firmware package.\r | |
301 | \r | |
302 | This function returns package information.\r | |
303 | \r | |
304 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
305 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
306 | The format is vendor specific and new version must have a greater value\r | |
307 | than the old version. If PackageVersion is not supported, the value is\r | |
308 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r | |
309 | comparison is to be performed using PackageVersionName. A value of\r | |
310 | 0xFFFFFFFD indicates that package version update is in progress.\r | |
311 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r | |
312 | the package version name. The buffer is allocated by this function with\r | |
313 | AllocatePool(), and it is the caller's responsibility to free it with a\r | |
314 | call to FreePool().\r | |
315 | @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r | |
316 | package version name. A value of 0 indicates the device does not support\r | |
317 | update of package version name. Length is the number of Unicode characters,\r | |
318 | including the terminating null character.\r | |
319 | @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r | |
320 | Definitions' for possible returned values of this parameter. A value of 1\r | |
321 | indicates the attribute is supported and the current setting value is\r | |
322 | indicated in AttributesSetting. A value of 0 indicates the attribute is not\r | |
323 | supported and the current setting value in AttributesSetting is meaningless.\r | |
324 | @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r | |
325 | values of this parameter\r | |
326 | \r | |
327 | @retval EFI_SUCCESS The package information was successfully returned.\r | |
328 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
329 | \r | |
330 | **/\r | |
331 | EFI_STATUS\r | |
332 | EFIAPI\r | |
333 | FmpGetPackageInfo (\r | |
334 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
335 | OUT UINT32 *PackageVersion,\r | |
336 | OUT CHAR16 **PackageVersionName,\r | |
337 | OUT UINT32 *PackageVersionNameMaxLen,\r | |
338 | OUT UINT64 *AttributesSupported,\r | |
339 | OUT UINT64 *AttributesSetting\r | |
340 | );\r | |
341 | \r | |
342 | /**\r | |
343 | Updates information about the firmware package.\r | |
344 | \r | |
345 | This function updates package information.\r | |
346 | This function returns EFI_UNSUPPORTED if the package information is not updatable.\r | |
347 | VendorCode enables vendor to implement vendor-specific package information update policy.\r | |
348 | Null if the caller did not specify this policy or use the default policy.\r | |
349 | \r | |
350 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
351 | @param[in] Image Points to the authentication image.\r | |
352 | Null if authentication is not required.\r | |
353 | @param[in] ImageSize Size of the authentication image in bytes.\r | |
354 | 0 if authentication is not required.\r | |
355 | @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r | |
356 | image update policy.\r | |
357 | Null indicates the caller did not specify this policy or use\r | |
358 | the default policy.\r | |
359 | @param[in] PackageVersion The new package version.\r | |
360 | @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r | |
361 | the package version name.\r | |
362 | The string length is equal to or less than the value returned in\r | |
363 | PackageVersionNameMaxLen.\r | |
364 | \r | |
365 | @retval EFI_SUCCESS The device was successfully updated with the new package\r | |
366 | information.\r | |
367 | @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r | |
368 | returned in PackageVersionNameMaxLen.\r | |
369 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
c8dca871 | 370 | @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r |
f6f91d38 JY |
371 | \r |
372 | **/\r | |
373 | EFI_STATUS\r | |
374 | EFIAPI\r | |
375 | FmpSetPackageInfo (\r | |
376 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
377 | IN CONST VOID *Image,\r | |
378 | IN UINTN ImageSize,\r | |
379 | IN CONST VOID *VendorCode,\r | |
380 | IN UINT32 PackageVersion,\r | |
381 | IN CONST CHAR16 *PackageVersionName\r | |
382 | );\r | |
383 | \r | |
384 | /**\r | |
385 | Initialize SystemFmpDriver private data structure.\r | |
386 | \r | |
387 | @param[in] SystemFmpPrivate private data structure to be initialized.\r | |
388 | \r | |
389 | @return EFI_SUCCESS private data is initialized.\r | |
390 | **/\r | |
391 | EFI_STATUS\r | |
392 | InitializePrivateData (\r | |
393 | IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate\r | |
394 | );\r | |
395 | \r | |
396 | extern EFI_GUID gSystemFmpLastAttemptVariableGuid;\r | |
397 | extern EFI_GUID mCurrentImageTypeId;\r | |
398 | extern EFI_GUID gSystemFmpProtocolGuid;\r | |
399 | \r | |
400 | #endif\r | |
401 | \r |