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