]>
Commit | Line | Data |
---|---|---|
dc65dd5b MK |
1 | /**\r |
2 | \r | |
3 | Copyright (c) 2016, Microsoft Corporation\r | |
4 | \r | |
5 | All rights reserved.\r | |
6 | Redistribution and use in source and binary forms, with or without\r | |
7 | modification, are permitted provided that the following conditions are met:\r | |
8 | 1. Redistributions of source code must retain the above copyright notice,\r | |
9 | this list of conditions and the following disclaimer.\r | |
10 | 2. Redistributions in binary form must reproduce the above copyright notice,\r | |
11 | this list of conditions and the following disclaimer in the documentation\r | |
12 | and/or other materials provided with the distribution.\r | |
13 | \r | |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r | |
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r | |
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r | |
17 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r | |
18 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r | |
19 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r | |
20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r | |
21 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r | |
22 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r | |
23 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
24 | \r | |
25 | **/\r | |
26 | \r | |
27 | #include <PiDxe.h>\r | |
28 | \r | |
29 | #include <Library/FmpDeviceLib.h>\r | |
30 | \r | |
31 | #include <Library/DebugLib.h>\r | |
32 | #include <Library/BaseLib.h>\r | |
33 | #include <Library/BaseMemoryLib.h>\r | |
34 | #include <Library/MemoryAllocationLib.h>\r | |
35 | #include <Library/UefiBootServicesTableLib.h>\r | |
36 | \r | |
37 | #include <Library/PlatformFlashAccessLib.h>\r | |
38 | \r | |
39 | //#include <Protocol/FirmwareManagement.h>\r | |
40 | \r | |
41 | //#include <Guid/SystemResourceTable.h>\r | |
42 | \r | |
43 | typedef struct {\r | |
44 | PLATFORM_FIRMWARE_TYPE FirmwareType;\r | |
45 | FLASH_ADDRESS_TYPE AddressType;\r | |
46 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
47 | UINTN Length;\r | |
48 | UINTN ImageOffset;\r | |
49 | } UPDATE_CONFIG_DATA;\r | |
50 | \r | |
51 | UPDATE_CONFIG_DATA mUpdateConfigData[] = {\r | |
52 | { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00000000, 0x00040000, 0x00000000 },\r | |
53 | { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x000C0000, 0x00050000, 0x000C0000 },\r | |
54 | { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00110000, 0x00210000, 0x00110000 },\r | |
55 | { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00320000, 0x00070000, 0x00320000 },\r | |
56 | { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00390000, 0x00070000, 0x00390000 },\r | |
57 | { PlatformFirmwareTypeNvRam, FlashAddressTypeRelativeAddress, 0x00040000, 0x00080000, 0x00040000 }\r | |
58 | };\r | |
59 | \r | |
60 | /**\r | |
61 | Used to pass the FMP install function to this lib. This allows the library to\r | |
62 | have control of the handle that the FMP instance is installed on. This allows\r | |
63 | the library to use DriverBinding protocol model to locate its device(s) in the\r | |
64 | system.\r | |
65 | \r | |
66 | @param[in] Func Function pointer to FMP install function.\r | |
67 | \r | |
68 | @retval EFI_SUCCESS Library has saved function pointer and will call\r | |
69 | function pointer on each DriverBinding Start.\r | |
70 | @retval EFI_UNSUPPORTED Library doesn't use driver binding and only supports\r | |
71 | a single instance.\r | |
72 | @retval other error Error occurred. Don't install FMP\r | |
73 | \r | |
74 | **/\r | |
75 | EFI_STATUS\r | |
76 | EFIAPI\r | |
77 | RegisterFmpInstaller (\r | |
78 | IN FMP_DEVICE_LIB_REGISTER_FMP_INSTALLER Func\r | |
79 | )\r | |
80 | {\r | |
81 | //\r | |
82 | // This is a system firmware update that does not use Driver Binding Protocol\r | |
83 | //\r | |
84 | return EFI_UNSUPPORTED;\r | |
85 | }\r | |
86 | \r | |
87 | \r | |
88 | /**\r | |
89 | Returns the size, in bytes, of the firmware image currently stored in the\r | |
90 | firmware device. This function is used to by the GetImage() and\r | |
91 | GetImageInfo() services of the Firmware Management Protocol. If the image\r | |
92 | size can not be determined from the firmware device, then 0 must be returned.\r | |
93 | \r | |
94 | @param[out] Size Pointer to the size, in bytes, of the firmware image\r | |
95 | currently stored in the firmware device.\r | |
96 | \r | |
97 | @retval EFI_SUCCESS The size of the firmware image currently\r | |
98 | stored in the firmware device was returned.\r | |
99 | @retval EFI_INVALID_PARAMETER Size is NULL.\r | |
100 | @retval EFI_UNSUPPORTED The firmware device does not support reporting\r | |
101 | the size of the currently stored firmware image.\r | |
102 | @retval EFI_DEVICE_ERROR An error occured attempting to determine the\r | |
103 | size of the firmware image currently stored in\r | |
104 | in the firmware device.\r | |
105 | \r | |
106 | **/\r | |
107 | EFI_STATUS\r | |
108 | EFIAPI\r | |
109 | FmpDeviceGetSize (\r | |
110 | IN UINTN *Size\r | |
111 | )\r | |
112 | {\r | |
113 | if (Size == NULL) {\r | |
114 | return EFI_INVALID_PARAMETER;\r | |
115 | }\r | |
116 | *Size = PcdGet32 (PcdBiosRomBase);\r | |
117 | return EFI_SUCCESS;\r | |
118 | }\r | |
119 | \r | |
120 | /**\r | |
121 | Used to return a library supplied guid that will be the ImageTypeId guid of\r | |
122 | the FMP descriptor. This is optional but can be used if at runtime the guid\r | |
123 | needs to be determined.\r | |
124 | \r | |
125 | @param[out] Guid Double Guid Ptr that will be updated to point to guid.\r | |
126 | This should be from static memory and will not be freed.\r | |
127 | \r | |
128 | @return EFI_UNSUPPORTED Library instance doesn't need dynamic guid.\r | |
129 | @return Error Any error will cause the wrapper to use the GUID\r | |
130 | defined by PCD.\r | |
131 | @return EFI_SUCCESS Guid ptr should be updated to point to static memeory\r | |
132 | which contains a valid guid.\r | |
133 | \r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | FmpDeviceGetImageTypeIdGuidPtr (\r | |
138 | OUT EFI_GUID **Guid\r | |
139 | )\r | |
140 | {\r | |
141 | return EFI_UNSUPPORTED;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Returns values used to fill in the AttributesSupported and AttributesSettings\r | |
146 | fields of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the\r | |
147 | GetImageInfo() service of the Firmware Management Protocol. The following\r | |
148 | bit values from the Firmware Management Protocol may be combined:\r | |
149 | IMAGE_ATTRIBUTE_IMAGE_UPDATABLE\r | |
150 | IMAGE_ATTRIBUTE_RESET_REQUIRED\r | |
151 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED\r | |
152 | IMAGE_ATTRIBUTE_IN_USE\r | |
153 | IMAGE_ATTRIBUTE_UEFI_IMAGE\r | |
154 | \r | |
155 | @param[out] Supported Attributes supported by this firmware device.\r | |
156 | @param[out] Setting Attributes settings for this firmware device.\r | |
157 | \r | |
158 | @retval EFI_SUCCESS The attributes supported by the firmware\r | |
159 | device were returned.\r | |
160 | @retval EFI_INVALID_PARAMETER Supported is NULL.\r | |
161 | @retval EFI_INVALID_PARAMETER Setting is NULL.\r | |
162 | \r | |
163 | **/\r | |
164 | EFI_STATUS\r | |
165 | EFIAPI\r | |
166 | FmpDeviceGetAttributes (\r | |
167 | IN OUT UINT64 *Supported,\r | |
168 | IN OUT UINT64 *Setting\r | |
169 | )\r | |
170 | {\r | |
171 | if (Supported == NULL || Setting == NULL) {\r | |
172 | return EFI_INVALID_PARAMETER;\r | |
173 | }\r | |
174 | *Supported = (IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |\r | |
175 | IMAGE_ATTRIBUTE_RESET_REQUIRED |\r | |
176 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |\r | |
177 | IMAGE_ATTRIBUTE_IN_USE\r | |
178 | );\r | |
179 | *Setting = (IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |\r | |
180 | IMAGE_ATTRIBUTE_RESET_REQUIRED |\r | |
181 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |\r | |
182 | IMAGE_ATTRIBUTE_IN_USE\r | |
183 | );\r | |
184 | return EFI_SUCCESS;\r | |
185 | }\r | |
186 | \r | |
187 | /**\r | |
188 | Gets the current Lowest Supported Version.\r | |
189 | \r | |
190 | This is a protection mechanism so that a previous version with known issue is\r | |
191 | not applied. ONLY implement this if your running firmware has a method to\r | |
192 | return this at runtime. If EFI_UNSUPPORTED is returned, then the Lowest\r | |
193 | Supported Version is stored in a UEFI Variable.\r | |
194 | \r | |
195 | @param[out] Version On return this value represents the current Lowest\r | |
196 | Supported Version (in same format as GetVersion).\r | |
197 | \r | |
198 | @retval EFI_SUCCESS The Lowest Supported Version was correctly retrieved\r | |
199 | @retval EFI_UNSUPPORTED Device firmware doesn't support reporting LSV\r | |
200 | @retval EFI_DEVICE_ERROR Error occurred when trying to get the LSV\r | |
201 | **/\r | |
202 | EFI_STATUS\r | |
203 | EFIAPI\r | |
204 | FmpDeviceGetLowestSupportedVersion (\r | |
205 | IN OUT UINT32 *LowestSupportedVersion\r | |
206 | )\r | |
207 | {\r | |
208 | //\r | |
209 | // Retrieve the lowest support version from a PCD\r | |
210 | // NOTE: This method of using a PCD can only be used for the system firmware\r | |
211 | // FMP instance that is updated every time the system firmware is\r | |
212 | // updated. If system firmware updates support partial updates that\r | |
213 | // would not include the system firmware FMP instance, then a PCD can\r | |
214 | // not be used and the value must come from the currently running system\r | |
215 | // firmware image.\r | |
216 | //\r | |
217 | *LowestSupportedVersion = PcdGet32 (PcdSystemFirmwareFmpLowestSupportedVersion);\r | |
218 | return EFI_SUCCESS;\r | |
219 | }\r | |
220 | \r | |
221 | \r | |
222 | /**\r | |
223 | Returns the Null-terminated Unicode string that is used to fill in the\r | |
224 | VersionName field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is\r | |
225 | returned by the GetImageInfo() service of the Firmware Management Protocol.\r | |
226 | The returned string must be allocated using EFI_BOOT_SERVICES.AllocatePool().\r | |
227 | \r | |
228 | @note It is recommended that all firmware devices support a method to report\r | |
229 | the VersionName string from the currently stored firmware image.\r | |
230 | \r | |
231 | @param[out] VersionString The version string retrieved from the currently\r | |
232 | stored firmware image.\r | |
233 | \r | |
234 | @retval EFI_SUCCESS The version string of currently stored\r | |
235 | firmware image was returned in Version.\r | |
236 | @retval EFI_INVALID_PARAMETER VersionString is NULL.\r | |
237 | @retval EFI_UNSUPPORTED The firmware device does not support a method\r | |
238 | to report the version string of the currently\r | |
239 | stored firmware image.\r | |
240 | @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the\r | |
241 | version string of the currently stored\r | |
242 | firmware image.\r | |
243 | @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the\r | |
244 | buffer for the version string of the currently\r | |
245 | stored firmware image.\r | |
246 | \r | |
247 | **/\r | |
248 | EFI_STATUS\r | |
249 | EFIAPI\r | |
250 | FmpDeviceGetVersionString (\r | |
251 | OUT CHAR16 **VersionString\r | |
252 | )\r | |
253 | {\r | |
254 | if (VersionString == NULL) {\r | |
255 | return EFI_INVALID_PARAMETER;\r | |
256 | }\r | |
257 | \r | |
258 | //\r | |
259 | // Retrieve the version string from a PCD\r | |
260 | // NOTE: This method of using a PCD can only be used for the system firmware\r | |
261 | // FMP instance that is updated every time the system firmware is\r | |
262 | // updated. If system firmware updates support partial updates that\r | |
263 | // would not include the system firmware FMP instance, then a PCD can\r | |
264 | // not be used and the value must come from the currently running system\r | |
265 | // firmware image.\r | |
266 | //\r | |
267 | *VersionString = (CHAR16 *)AllocateCopyPool (\r | |
268 | PcdGetSize (PcdSystemFirmwareFmpVersionString),\r | |
269 | PcdGetPtr (PcdSystemFirmwareFmpVersionString)\r | |
270 | );\r | |
271 | if (*VersionString == NULL) {\r | |
272 | return EFI_OUT_OF_RESOURCES;\r | |
273 | }\r | |
274 | return EFI_SUCCESS;\r | |
275 | }\r | |
276 | \r | |
277 | /**\r | |
278 | Gets the current running version.\r | |
279 | \r | |
280 | ONLY implement this if your running firmware has a method to return this at\r | |
281 | runtime.\r | |
282 | \r | |
283 | @param[out] Version On return this value represents the current running\r | |
284 | version.\r | |
285 | \r | |
286 | @retval EFI_SUCCESS The version was correctly retrieved.\r | |
287 | @retval EFI_UNSUPPORTED Device firmware doesn't support reporting current\r | |
288 | version.\r | |
289 | @retval EFI_DEVICE_ERROR Error occurred when trying to get the version.\r | |
290 | **/\r | |
291 | EFI_STATUS\r | |
292 | EFIAPI\r | |
293 | FmpDeviceGetVersion (\r | |
294 | IN OUT UINT32 *Version\r | |
295 | )\r | |
296 | {\r | |
297 | //\r | |
298 | // Retrieve the version string from a PCD\r | |
299 | // NOTE: This method of using a PCD can only be used for the system firmware\r | |
300 | // FMP instance that is updated every time the system firmware is\r | |
301 | // updated. If system firmware updates support partial updates that\r | |
302 | // would not include the system firmware FMP instance, then a PCD can\r | |
303 | // not be used and the value must come from the currently running system\r | |
304 | // firmware image.\r | |
305 | //\r | |
306 | *Version = PcdGet32 (PcdSystemFirmwareFmpVersion);\r | |
307 | return EFI_SUCCESS;\r | |
308 | }\r | |
309 | \r | |
310 | \r | |
311 | /**\r | |
312 | Retrieves a copy of the current firmware image of the device.\r | |
313 | \r | |
314 | This function allows a copy of the current firmware image to be created and\r | |
315 | saved. The saved copy could later been used, for example, in firmware image\r | |
316 | recovery or rollback.\r | |
317 | \r | |
318 | @param[out] Image Points to the buffer where the current image is copied\r | |
319 | to.\r | |
320 | @param[out] ImageSize On entry, points to the size of the buffer pointed to\r | |
321 | by Image, in bytes. On return, points to the length of\r | |
322 | the image, in bytes.\r | |
323 | \r | |
324 | @retval EFI_SUCCESS The image was successfully read from the device.\r | |
325 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small\r | |
326 | to hold the image. The current buffer size\r | |
327 | needed to hold the image is returned in\r | |
328 | ImageSize.\r | |
329 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
330 | @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r | |
331 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
332 | \r | |
333 | **/\r | |
334 | EFI_STATUS\r | |
335 | EFIAPI\r | |
336 | FmpDeviceGetImage (\r | |
337 | IN OUT VOID *Image,\r | |
338 | IN OUT UINTN *ImageSize\r | |
339 | )\r | |
340 | {\r | |
341 | //\r | |
342 | // Check for invalid p;arameters\r | |
343 | //\r | |
344 | if (Image == NULL || ImageSize == NULL) {\r | |
345 | return EFI_INVALID_PARAMETER;\r | |
346 | }\r | |
347 | \r | |
348 | //\r | |
349 | // Make sure the buffer is big enough to hold the device image\r | |
350 | //\r | |
351 | if (*ImageSize < PcdGet32 (PcdBiosRomSize)) {\r | |
352 | *ImageSize = PcdGet32 (PcdBiosRomSize);\r | |
353 | return EFI_BUFFER_TOO_SMALL;\r | |
354 | }\r | |
355 | \r | |
356 | //\r | |
357 | // Copy the device image to the buffer\r | |
358 | //\r | |
359 | *ImageSize = PcdGet32 (PcdBiosRomSize);\r | |
360 | CopyMem (\r | |
361 | Image,\r | |
362 | (VOID *)(UINTN)PcdGet32 (PcdBiosRomBase),\r | |
363 | *ImageSize\r | |
364 | );\r | |
365 | \r | |
366 | return EFI_SUCCESS;\r | |
367 | }\r | |
368 | \r | |
369 | /**\r | |
370 | Updates the firmware image of the device.\r | |
371 | \r | |
372 | This function updates the hardware with the new firmware image. This function\r | |
373 | returns EFI_UNSUPPORTED if the firmware image is not updatable. If the\r | |
374 | firmware image is updatable, the function should perform the following minimal\r | |
375 | validations before proceeding to do the firmware image update.\r | |
376 | - Validate the image is a supported image for this device. The function\r | |
377 | returns EFI_ABORTED if the image is unsupported. The function can\r | |
378 | optionally provide more detailed information on why the image is not a\r | |
379 | supported image.\r | |
380 | - Validate the data from VendorCode if not null. Image validation must be\r | |
381 | performed before VendorCode data validation. VendorCode data is ignored\r | |
382 | or considered invalid if image validation failed. The function returns\r | |
383 | EFI_ABORTED if the data is invalid.\r | |
384 | \r | |
385 | VendorCode enables vendor to implement vendor-specific firmware image update\r | |
386 | policy. Null if the caller did not specify the policy or use the default\r | |
387 | policy. As an example, vendor can implement a policy to allow an option to\r | |
388 | force a firmware image update when the abort reason is due to the new firmware\r | |
389 | image version is older than the current firmware image version or bad image\r | |
390 | checksum. Sensitive operations such as those wiping the entire firmware image\r | |
391 | and render the device to be non-functional should be encoded in the image\r | |
392 | itself rather than passed with the VendorCode. AbortReason enables vendor to\r | |
393 | have the option to provide a more detailed description of the abort reason to\r | |
394 | the caller.\r | |
395 | \r | |
396 | @param[in] Image Points to the new image.\r | |
397 | @param[in] ImageSize Size of the new image in bytes.\r | |
398 | @param[in] VendorCode This enables vendor to implement vendor-specific\r | |
399 | firmware image update policy. Null indicates the\r | |
400 | caller did not specify the policy or use the\r | |
401 | default policy.\r | |
402 | @param[in] Progress A function used by the driver to report the\r | |
403 | progress of the firmware update.\r | |
404 | @param[in] CapsuleFwVersion FMP Payload Header version of the image.\r | |
405 | @param[out] AbortReason A pointer to a pointer to a null-terminated\r | |
406 | string providing more details for the aborted\r | |
407 | operation. The buffer is allocated by this\r | |
408 | function with AllocatePool(), and it is the\r | |
409 | caller's responsibility to free it with a call\r | |
410 | to FreePool().\r | |
411 | \r | |
412 | @retval EFI_SUCCESS The device was successfully updated with the\r | |
413 | new image.\r | |
414 | @retval EFI_ABORTED The operation is aborted.\r | |
415 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
416 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
417 | \r | |
418 | **/\r | |
419 | EFI_STATUS\r | |
420 | EFIAPI\r | |
421 | FmpDeviceSetImage (\r | |
422 | IN CONST VOID *Image,\r | |
423 | IN UINTN ImageSize,\r | |
424 | IN CONST VOID *VendorCode,\r | |
425 | IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r | |
426 | IN UINT32 CapsuleFwVersion,\r | |
427 | OUT CHAR16 **AbortReason\r | |
428 | )\r | |
429 | {\r | |
430 | EFI_STATUS Status;\r | |
431 | UINT32 Updateable;\r | |
432 | UINTN Percentage;\r | |
433 | UINTN Index;\r | |
434 | UPDATE_CONFIG_DATA *ConfigData;\r | |
435 | UINTN TotalSize;\r | |
436 | UINTN BytesWritten;\r | |
437 | \r | |
438 | Updateable = 0;\r | |
439 | Status = FmpDeviceCheckImage (Image, ImageSize, &Updateable);\r | |
440 | if (EFI_ERROR (Status)) {\r | |
441 | DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Check Image failed with %r.\n", Status));\r | |
442 | return Status;\r | |
443 | }\r | |
444 | \r | |
445 | if (Updateable != IMAGE_UPDATABLE_VALID) {\r | |
446 | DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Check Image returned that the Image was not valid for update. Updatable value = 0x%X.\n", Updateable));\r | |
447 | return EFI_ABORTED;\r | |
448 | }\r | |
449 | \r | |
450 | if (Progress == NULL) {\r | |
451 | DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Invalid progress callback\n"));\r | |
452 | return EFI_INVALID_PARAMETER;\r | |
453 | }\r | |
454 | \r | |
455 | Status = Progress (15);\r | |
456 | if (EFI_ERROR (Status)) {\r | |
457 | DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Progress Callback failed with Status %r.\n", Status));\r | |
458 | }\r | |
459 | \r | |
460 | //\r | |
461 | // Write the image to the firmware device\r | |
462 | //\r | |
463 | Progress (20);\r | |
464 | if (EFI_ERROR (Status)) {\r | |
465 | DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Progress Callback failed with Status %r.\n", Status));\r | |
466 | }\r | |
467 | \r | |
468 | //\r | |
469 | // Simulate update with delays between progress updates\r | |
470 | //\r | |
471 | for (Percentage = 20; Percentage <= 100; Percentage++) {\r | |
472 | //\r | |
473 | // Wait 0.05 seconds\r | |
474 | //\r | |
475 | // gBS->Stall (50000);\r | |
476 | \r | |
477 | // Progress (Percentage);\r | |
478 | // if (EFI_ERROR (Status)) {\r | |
479 | // DEBUG((DEBUG_ERROR, "FmpDeviceSetImage - Progress Callback failed with Status %r.\n", Status));\r | |
480 | // }\r | |
481 | }\r | |
482 | \r | |
483 | DEBUG ((DEBUG_INFO, "FmpDeviceSetImage - %d Images ...\n", ARRAY_SIZE (mUpdateConfigData)));\r | |
484 | \r | |
485 | if (ARRAY_SIZE (mUpdateConfigData) == 0) {\r | |
486 | DEBUG((DEBUG_INFO, "PlatformUpdate: BaseAddress - 0x%lx ImageOffset - 0x%x Length - 0x%x\n", 0, 0, ImageSize));\r | |
487 | Status = PerformFlashWriteWithProgress (\r | |
488 | PlatformFirmwareTypeSystemFirmware, // FirmwareType\r | |
489 | 0x00000000, // FlashAddress\r | |
490 | FlashAddressTypeRelativeAddress, // FlashAddressType\r | |
491 | (VOID *)(UINTN)Image, // Buffer\r | |
492 | ImageSize, // BufferLength\r | |
493 | Progress, // Progress\r | |
494 | 20, // StartPercentage\r | |
495 | 100 // EndPercentage\r | |
496 | );\r | |
497 | }\r | |
498 | \r | |
499 | \r | |
500 | //\r | |
501 | // Compute total size of update\r | |
502 | //\r | |
503 | for (Index = 0, TotalSize = 0; Index < ARRAY_SIZE (mUpdateConfigData); Index++) {\r | |
504 | TotalSize += mUpdateConfigData[Index].Length;\r | |
505 | }\r | |
506 | \r | |
507 | BytesWritten = 0;\r | |
508 | for (Index = 0, ConfigData = mUpdateConfigData; Index < ARRAY_SIZE (mUpdateConfigData); Index++, ConfigData++) {\r | |
509 | DEBUG((DEBUG_INFO, "PlatformUpdate(%d): BaseAddress - 0x%lx ImageOffset - 0x%x Length - 0x%x\n",\r | |
510 | Index,\r | |
511 | ConfigData->BaseAddress,\r | |
512 | ConfigData->ImageOffset,\r | |
513 | ConfigData->Length\r | |
514 | ));\r | |
515 | Status = PerformFlashWriteWithProgress (\r | |
516 | ConfigData->FirmwareType, // FirmwareType\r | |
517 | ConfigData->BaseAddress, // FlashAddress\r | |
518 | ConfigData->AddressType, // FlashAddressType\r | |
519 | (VOID *)((UINTN)Image + (UINTN)ConfigData->ImageOffset), // Buffer\r | |
520 | ConfigData->Length, // BufferLength\r | |
521 | Progress, // Progress\r | |
522 | 20 + (BytesWritten * 80) / TotalSize, // StartPercentage\r | |
523 | 20 + ((BytesWritten + ConfigData->Length) * 80) / TotalSize // EndPercentage\r | |
524 | );\r | |
525 | if (EFI_ERROR(Status)) {\r | |
526 | break;\r | |
527 | }\r | |
528 | BytesWritten += ConfigData->Length;\r | |
529 | }\r | |
530 | \r | |
531 | DEBUG ((DEBUG_INFO, "FmpDeviceSetImage - %r\n", Status));\r | |
532 | \r | |
533 | return Status;\r | |
534 | }\r | |
535 | \r | |
536 | /**\r | |
537 | Checks if the firmware image is valid for the device.\r | |
538 | \r | |
539 | This function allows firmware update application to validate the firmware image without\r | |
540 | invoking the SetImage() first.\r | |
541 | \r | |
542 | @param[in] Image Points to the new image.\r | |
543 | @param[in] ImageSize Size of the new image in bytes.\r | |
544 | @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r | |
545 | if available, additional information if the image is invalid.\r | |
546 | \r | |
547 | @retval EFI_SUCCESS The image was successfully checked.\r | |
548 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
549 | \r | |
550 | **/\r | |
551 | EFI_STATUS\r | |
552 | EFIAPI\r | |
553 | FmpDeviceCheckImage (\r | |
554 | IN CONST VOID *Image,\r | |
555 | IN UINTN ImageSize,\r | |
556 | OUT UINT32 *ImageUpdateable\r | |
557 | )\r | |
558 | {\r | |
559 | if (ImageUpdateable == NULL) {\r | |
560 | DEBUG((DEBUG_ERROR, "CheckImage - ImageUpdateable Pointer Parameter is NULL.\n"));\r | |
561 | return EFI_INVALID_PARAMETER;\r | |
562 | }\r | |
563 | \r | |
564 | //\r | |
565 | //Set to valid and then if any tests fail it will update this flag.\r | |
566 | //\r | |
567 | *ImageUpdateable = IMAGE_UPDATABLE_VALID;\r | |
568 | \r | |
569 | if (Image == NULL) {\r | |
570 | DEBUG((DEBUG_ERROR, "CheckImage - Image Pointer Parameter is NULL.\n"));\r | |
571 | //\r | |
572 | // Not sure if this is needed\r | |
573 | //\r | |
574 | *ImageUpdateable = IMAGE_UPDATABLE_INVALID;\r | |
575 | return EFI_INVALID_PARAMETER;\r | |
576 | }\r | |
577 | \r | |
578 | //\r | |
579 | // Make sure the image size is correct\r | |
580 | //\r | |
581 | if (ImageSize != PcdGet32 (PcdBiosRomSize)) {\r | |
582 | *ImageUpdateable = IMAGE_UPDATABLE_INVALID;\r | |
583 | return EFI_INVALID_PARAMETER;\r | |
584 | }\r | |
585 | \r | |
586 | return EFI_SUCCESS;\r | |
587 | }\r | |
588 | \r | |
589 | /**\r | |
590 | Device firmware should trigger lock mechanism so that device fw can not be\r | |
591 | updated or tampered with. This lock mechanism is generally only cleared by a\r | |
592 | full system reset (not just sleep state/low power mode)\r | |
593 | \r | |
594 | @retval EFI_SUCCESS The device was successfully locked.\r | |
595 | @retval EFI_UNSUPPORTED The hardware device/firmware doesn't support locking\r | |
596 | \r | |
597 | **/\r | |
598 | EFI_STATUS\r | |
599 | EFIAPI\r | |
600 | FmpDeviceLock (\r | |
601 | VOID\r | |
602 | )\r | |
603 | {\r | |
604 | DEBUG ((DEBUG_INFO, "VLV2: FmpDeviceLock() for system FLASH\n"));\r | |
605 | // TODO: Add lock logic\r | |
606 | return EFI_UNSUPPORTED;\r | |
607 | }\r |