FmpDeviceLib.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /**
  2. Copyright (c) Microsoft Corporation.<BR>
  3. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <LastAttemptStatus.h>
  8. #include <Guid/SystemResourceTable.h>
  9. #include <Library/DebugLib.h>
  10. #include <Protocol/FirmwareManagement.h>
  11. #include <Library/BaseLib.h>
  12. #include <Library/MemoryAllocationLib.h>
  13. #include <Library/BaseMemoryLib.h>
  14. #include <Library/FmpDeviceLib.h>
  15. #include <Library/UefiBootServicesTableLib.h>
  16. /**
  17. Used to pass the FMP install function to this lib.
  18. This allows the library to have control of the handle
  19. that the FMP instance is installed on. This allows the library
  20. to use DriverBinding protocol model to locate its device(s) in the
  21. system.
  22. @param[in] Function pointer to FMP install function.
  23. @retval EFI_SUCCESS Library has saved function pointer and will call function pointer on each DriverBinding Start.
  24. @retval EFI_UNSUPPORTED Library doesn't use driver binding and only supports a single instance.
  25. @retval other error Error occurred. Don't install FMP
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. RegisterFmpInstaller(
  30. IN FMP_DEVICE_LIB_REGISTER_FMP_INSTALLER Func
  31. )
  32. {
  33. // Because this is a sample lib with very simple fake device we don't use
  34. // the driverbinding protocol to locate our device.
  35. //
  36. return EFI_UNSUPPORTED;
  37. }
  38. /**
  39. Provide a function to uninstall the Firmware Management Protocol instance from a
  40. device handle when the device is managed by a driver that follows the UEFI
  41. Driver Model. If the device is not managed by a driver that follows the UEFI
  42. Driver Model, then EFI_UNSUPPORTED is returned.
  43. @param[in] FmpUninstaller Function that installs the Firmware Management
  44. Protocol.
  45. @retval EFI_SUCCESS The device is managed by a driver that follows the
  46. UEFI Driver Model. FmpUinstaller must be called on
  47. each Driver Binding Stop().
  48. @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
  49. the UEFI Driver Model.
  50. @retval other The Firmware Management Protocol for this firmware
  51. device is not installed. The firmware device is
  52. still locked using FmpDeviceLock().
  53. **/
  54. EFI_STATUS
  55. EFIAPI
  56. RegisterFmpUninstaller (
  57. IN FMP_DEVICE_LIB_REGISTER_FMP_UNINSTALLER FmpUninstaller
  58. )
  59. {
  60. //
  61. // This is a system firmware update that does not use Driver Binding Protocol
  62. //
  63. return EFI_UNSUPPORTED;
  64. }
  65. /**
  66. Set the device context for the FmpDeviceLib services when the device is
  67. managed by a driver that follows the UEFI Driver Model. If the device is not
  68. managed by a driver that follows the UEFI Driver Model, then EFI_UNSUPPORTED
  69. is returned. Once a device context is set, the FmpDeviceLib services
  70. operate on the currently set device context.
  71. @param[in] Handle Device handle for the FmpDeviceLib services.
  72. If Handle is NULL, then Context is freed.
  73. @param[in, out] Context Device context for the FmpDeviceLib services.
  74. If Context is NULL, then a new context is allocated
  75. for Handle and the current device context is set and
  76. returned in Context. If Context is not NULL, then
  77. the current device context is set.
  78. @retval EFI_SUCCESS The device is managed by a driver that follows the
  79. UEFI Driver Model.
  80. @retval EFI_UNSUPPORTED The device is not managed by a driver that follows
  81. the UEFI Driver Model.
  82. @retval other The Firmware Management Protocol for this firmware
  83. device is not installed. The firmware device is
  84. still locked using FmpDeviceLock().
  85. **/
  86. EFI_STATUS
  87. EFIAPI
  88. FmpDeviceSetContext (
  89. IN EFI_HANDLE Handle,
  90. OUT VOID **Context
  91. )
  92. {
  93. //
  94. // This is a system firmware update that does not use Driver Binding Protocol
  95. //
  96. return EFI_UNSUPPORTED;
  97. }
  98. /**
  99. Used to get the size of the image in bytes.
  100. NOTE - Do not return zero as that will identify the device as
  101. not updatable.
  102. @retval UINTN that represents the size of the firmware.
  103. **/
  104. EFI_STATUS
  105. EFIAPI
  106. FmpDeviceGetSize (
  107. IN UINTN *Size
  108. )
  109. {
  110. if (Size == NULL) {
  111. return EFI_INVALID_PARAMETER;
  112. }
  113. *Size = 0x1000;
  114. return EFI_SUCCESS;
  115. }
  116. /**
  117. Used to return a library supplied guid that will be the ImageTypeId guid of the FMP descriptor.
  118. This is optional but can be used if at runtime the guid needs to be determined.
  119. @param Guid: Double Guid Ptr that will be updated to point to guid. This should be from static memory
  120. and will not be freed.
  121. @return EFI_UNSUPPORTED: if you library instance doesn't need dynamic guid return this.
  122. @return Error: Any error will cause the wrapper to use the GUID defined by PCD
  123. @return EFI_SUCCESS: Guid ptr should be updated to point to static memeory which contains a valid guid
  124. **/
  125. EFI_STATUS
  126. EFIAPI
  127. FmpDeviceGetImageTypeIdGuidPtr(
  128. OUT EFI_GUID** Guid)
  129. {
  130. //this instance doesn't need dynamic guid detection.
  131. return EFI_UNSUPPORTED;
  132. }
  133. /**
  134. Returns values used to fill in the AttributesSupported and AttributesSettings
  135. fields of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the
  136. GetImageInfo() service of the Firmware Management Protocol. The following
  137. bit values from the Firmware Management Protocol may be combined:
  138. IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
  139. IMAGE_ATTRIBUTE_RESET_REQUIRED
  140. IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
  141. IMAGE_ATTRIBUTE_IN_USE
  142. IMAGE_ATTRIBUTE_UEFI_IMAGE
  143. @param[out] Supported Attributes supported by this firmware device.
  144. @param[out] Setting Attributes settings for this firmware device.
  145. @retval EFI_SUCCESS The attributes supported by the firmware
  146. device were returned.
  147. @retval EFI_INVALID_PARAMETER Supported is NULL.
  148. @retval EFI_INVALID_PARAMETER Setting is NULL.
  149. **/
  150. EFI_STATUS
  151. EFIAPI
  152. FmpDeviceGetAttributes (
  153. IN OUT UINT64 *Supported,
  154. IN OUT UINT64 *Setting
  155. )
  156. {
  157. if (Supported == NULL || Setting == NULL) {
  158. return EFI_INVALID_PARAMETER;
  159. }
  160. *Supported = (IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | IMAGE_ATTRIBUTE_IN_USE);
  161. *Setting = (IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | IMAGE_ATTRIBUTE_IN_USE);
  162. return EFI_SUCCESS;
  163. }
  164. /**
  165. Gets the current Lowest Supported Version.
  166. This is a protection mechanism so that a previous version with known issue is not
  167. applied.
  168. ONLY implement this if your running firmware has a method to return this at runtime.
  169. @param[out] Version On return this value represents the
  170. current Lowest Supported Version (in same format as GetVersion).
  171. @retval EFI_SUCCESS The Lowest Supported Version was correctly retrieved
  172. @retval EFI_UNSUPPORTED Device firmware doesn't support reporting LSV
  173. @retval EFI_DEVICE_ERROR Error occurred when trying to get the LSV
  174. **/
  175. EFI_STATUS
  176. EFIAPI
  177. FmpDeviceGetLowestSupportedVersion (
  178. IN OUT UINT32* LowestSupportedVersion
  179. )
  180. {
  181. return EFI_UNSUPPORTED;
  182. }
  183. /**
  184. Returns the Null-terminated Unicode string that is used to fill in the
  185. VersionName field of the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is
  186. returned by the GetImageInfo() service of the Firmware Management Protocol.
  187. The returned string must be allocated using EFI_BOOT_SERVICES.AllocatePool().
  188. @note It is recommended that all firmware devices support a method to report
  189. the VersionName string from the currently stored firmware image.
  190. @param[out] VersionString The version string retrieved from the currently
  191. stored firmware image.
  192. @retval EFI_SUCCESS The version string of currently stored
  193. firmware image was returned in Version.
  194. @retval EFI_INVALID_PARAMETER VersionString is NULL.
  195. @retval EFI_UNSUPPORTED The firmware device does not support a method
  196. to report the version string of the currently
  197. stored firmware image.
  198. @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the
  199. version string of the currently stored
  200. firmware image.
  201. @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the
  202. buffer for the version string of the currently
  203. stored firmware image.
  204. **/
  205. EFI_STATUS
  206. EFIAPI
  207. FmpDeviceGetVersionString (
  208. OUT CHAR16 **VersionString
  209. )
  210. {
  211. if (VersionString == NULL) {
  212. return EFI_INVALID_PARAMETER;
  213. }
  214. *VersionString = NULL;
  215. return EFI_UNSUPPORTED;
  216. }
  217. /**
  218. Gets the current running version.
  219. ONLY implement this if your running firmware has a method to return this at runtime.
  220. @param[out] Version On return this value represents the current running version
  221. @retval EFI_SUCCESS The version was correctly retrieved
  222. @retval EFI_UNSUPPORTED Device firmware doesn't support reporting current version
  223. @retval EFI_DEVICE_ERROR Error occurred when trying to get the version
  224. **/
  225. EFI_STATUS
  226. EFIAPI
  227. FmpDeviceGetVersion(
  228. IN OUT UINT32* Version
  229. )
  230. {
  231. return EFI_UNSUPPORTED;
  232. }
  233. /**
  234. Returns the value used to fill in the HardwareInstance field of the
  235. EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
  236. service of the Firmware Management Protocol. If EFI_SUCCESS is returned, then
  237. the firmware device supports a method to report the HardwareInstance value.
  238. If the value can not be reported for the firmware device, then EFI_UNSUPPORTED
  239. must be returned. EFI_DEVICE_ERROR is returned if an error occurs attempting
  240. to retrieve the HardwareInstance value for the firmware device.
  241. @param[out] HardwareInstance The hardware instance value for the firmware
  242. device.
  243. @retval EFI_SUCCESS The hardware instance for the current firmware
  244. devide is returned in HardwareInstance.
  245. @retval EFI_UNSUPPORTED The firmware device does not support a method to
  246. report the hardware instance value.
  247. @retval EFI_DEVICE_ERROR An error occurred attempting to retrieve the hardware
  248. instance value.
  249. **/
  250. EFI_STATUS
  251. EFIAPI
  252. FmpDeviceGetHardwareInstance (
  253. OUT UINT64 *HardwareInstance
  254. )
  255. {
  256. return EFI_UNSUPPORTED;
  257. }
  258. /**
  259. Retrieves a copy of the current firmware image of the device.
  260. This function allows a copy of the current firmware image to be created and saved.
  261. The saved copy could later been used, for example, in firmware image recovery or rollback.
  262. @param[out] Image Points to the buffer where the current image is copied to.
  263. @param[out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
  264. On return, points to the length of the image, in bytes.
  265. @retval EFI_SUCCESS The device was successfully updated with the new image.
  266. @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
  267. image. The current buffer size needed to hold the image is returned
  268. in ImageSize.
  269. @retval EFI_INVALID_PARAMETER The Image was NULL.
  270. @retval EFI_NOT_FOUND The current image is not copied to the buffer.
  271. @retval EFI_UNSUPPORTED The operation is not supported.
  272. **/
  273. EFI_STATUS
  274. EFIAPI
  275. FmpDeviceGetImage(
  276. IN OUT VOID *Image,
  277. IN OUT UINTN *ImageSize
  278. )
  279. /*++
  280. Routine Description:
  281. This is a function used to read the current firmware from the device into memory.
  282. This is an optional function and can return EFI_UNSUPPORTED. This is useful for
  283. test and diagnostics.
  284. Arguments:
  285. Image -- Buffer to place the image into.
  286. ImageSize -- Size of the Image buffer.
  287. Return Value:
  288. EFI_STATUS code.
  289. If not possible or not practical return EFI_UNSUPPORTED.
  290. --*/
  291. {
  292. return EFI_UNSUPPORTED;
  293. }//GetImage()
  294. /**
  295. Updates a firmware device with a new firmware image. This function returns
  296. EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image
  297. is updatable, the function should perform the following minimal validations
  298. before proceeding to do the firmware image update.
  299. - Validate that the image is a supported image for this firmware device.
  300. Return EFI_ABORTED if the image is not supported. Additional details
  301. on why the image is not a supported image may be returned in AbortReason.
  302. - Validate the data from VendorCode if is not NULL. Firmware image
  303. validation must be performed before VendorCode data validation.
  304. VendorCode data is ignored or considered invalid if image validation
  305. fails. Return EFI_ABORTED if the VendorCode data is invalid.
  306. VendorCode enables vendor to implement vendor-specific firmware image update
  307. policy. Null if the caller did not specify the policy or use the default
  308. policy. As an example, vendor can implement a policy to allow an option to
  309. force a firmware image update when the abort reason is due to the new firmware
  310. image version is older than the current firmware image version or bad image
  311. checksum. Sensitive operations such as those wiping the entire firmware image
  312. and render the device to be non-functional should be encoded in the image
  313. itself rather than passed with the VendorCode. AbortReason enables vendor to
  314. have the option to provide a more detailed description of the abort reason to
  315. the caller.
  316. @param[in] Image Points to the new firmware image.
  317. @param[in] ImageSize Size, in bytes, of the new firmware image.
  318. @param[in] VendorCode This enables vendor to implement vendor-specific
  319. firmware image update policy. NULL indicates
  320. the caller did not specify the policy or use the
  321. default policy.
  322. @param[in] Progress A function used to report the progress of
  323. updating the firmware device with the new
  324. firmware image.
  325. @param[in] CapsuleFwVersion The version of the new firmware image from the
  326. update capsule that provided the new firmware
  327. image.
  328. @param[out] AbortReason A pointer to a pointer to a Null-terminated
  329. Unicode string providing more details on an
  330. aborted operation. The buffer is allocated by
  331. this function with
  332. EFI_BOOT_SERVICES.AllocatePool(). It is the
  333. caller's responsibility to free this buffer with
  334. EFI_BOOT_SERVICES.FreePool().
  335. @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt
  336. status to report back to the ESRT table in case
  337. of error. This value will only be checked when this
  338. function returns an error.
  339. The return status code must fall in the range of
  340. LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to
  341. LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE.
  342. If the value falls outside this range, it will be converted
  343. to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL.
  344. @retval EFI_SUCCESS The firmware device was successfully updated
  345. with the new firmware image.
  346. @retval EFI_ABORTED The operation is aborted. Additional details
  347. are provided in AbortReason.
  348. @retval EFI_INVALID_PARAMETER The Image was NULL.
  349. @retval EFI_INVALID_PARAMETER LastAttemptStatus was NULL.
  350. @retval EFI_UNSUPPORTED The operation is not supported.
  351. **/
  352. EFI_STATUS
  353. EFIAPI
  354. FmpDeviceSetImageWithStatus (
  355. IN CONST VOID *Image,
  356. IN UINTN ImageSize,
  357. IN CONST VOID *VendorCode, OPTIONAL
  358. IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
  359. IN UINT32 CapsuleFwVersion,
  360. OUT CHAR16 **AbortReason,
  361. OUT UINT32 *LastAttemptStatus
  362. )
  363. {
  364. EFI_STATUS Status = EFI_SUCCESS;
  365. UINT32 Updateable = 0;
  366. Status = FmpDeviceCheckImageWithStatus (Image, ImageSize, &Updateable, LastAttemptStatus);
  367. if (EFI_ERROR(Status))
  368. {
  369. DEBUG((DEBUG_ERROR, "SetImageWithStatus - Check Image failed with %r.\n", Status));
  370. goto cleanup;
  371. }
  372. if (Updateable != IMAGE_UPDATABLE_VALID)
  373. {
  374. DEBUG((DEBUG_ERROR, "SetImageWithStatus - Check Image returned that the Image was not valid for update. Updatable value = 0x%X.\n", Updateable));
  375. Status = EFI_ABORTED;
  376. goto cleanup;
  377. }
  378. if (Progress == NULL)
  379. {
  380. DEBUG((DEBUG_ERROR, "SetImageWithStatus - Invalid progress callback\n"));
  381. Status = EFI_INVALID_PARAMETER;
  382. goto cleanup;
  383. }
  384. Status = Progress(15);
  385. if (EFI_ERROR(Status))
  386. {
  387. DEBUG((DEBUG_ERROR, "SetImageWithStatus - Progress Callback failed with Status %r.\n", Status));
  388. }
  389. {
  390. UINTN p;
  391. for (p = 20; p < 100; p++) {
  392. gBS->Stall (100000); //us = 0.1 seconds
  393. Progress (p);
  394. }
  395. }
  396. //TODO: add support for VendorCode, and AbortReason
  397. cleanup:
  398. if (EFI_ERROR (Status)) {
  399. *LastAttemptStatus = LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE;
  400. }
  401. return Status;
  402. }// SetImageWithStatus()
  403. /**
  404. Updates the firmware image of the device.
  405. This function updates the hardware with the new firmware image.
  406. This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
  407. If the firmware image is updatable, the function should perform the following minimal validations
  408. before proceeding to do the firmware image update.
  409. - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
  410. the image is unsupported. The function can optionally provide more detailed information on
  411. why the image is not a supported image.
  412. - Validate the data from VendorCode if not null. Image validation must be performed before
  413. VendorCode data validation. VendorCode data is ignored or considered invalid if image
  414. validation failed. The function returns EFI_ABORTED if the data is invalid.
  415. VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
  416. the caller did not specify the policy or use the default policy. As an example, vendor can implement
  417. a policy to allow an option to force a firmware image update when the abort reason is due to the new
  418. firmware image version is older than the current firmware image version or bad image checksum.
  419. Sensitive operations such as those wiping the entire firmware image and render the device to be
  420. non-functional should be encoded in the image itself rather than passed with the VendorCode.
  421. AbortReason enables vendor to have the option to provide a more detailed description of the abort
  422. reason to the caller.
  423. @param[in] Image Points to the new image.
  424. @param[in] ImageSize Size of the new image in bytes.
  425. @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
  426. Null indicates the caller did not specify the policy or use the default policy.
  427. @param[in] Progress A function used by the driver to report the progress of the firmware update.
  428. @param[in] CapsuleFwVersion FMP Payload Header version of the image
  429. @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
  430. details for the aborted operation. The buffer is allocated by this function
  431. with AllocatePool(), and it is the caller's responsibility to free it with a
  432. call to FreePool().
  433. @retval EFI_SUCCESS The device was successfully updated with the new image.
  434. @retval EFI_ABORTED The operation is aborted.
  435. @retval EFI_INVALID_PARAMETER The Image was NULL.
  436. @retval EFI_UNSUPPORTED The operation is not supported.
  437. **/
  438. EFI_STATUS
  439. EFIAPI
  440. FmpDeviceSetImage (
  441. IN CONST VOID *Image,
  442. IN UINTN ImageSize,
  443. IN CONST VOID *VendorCode,
  444. IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,
  445. IN UINT32 CapsuleFwVersion,
  446. OUT CHAR16 **AbortReason
  447. )
  448. {
  449. UINT32 LastAttemptStatus;
  450. return FmpDeviceSetImageWithStatus (
  451. Image,
  452. ImageSize,
  453. VendorCode,
  454. Progress,
  455. CapsuleFwVersion,
  456. AbortReason,
  457. &LastAttemptStatus
  458. );
  459. }// SetImage()
  460. /**
  461. Checks if a new firmware image is valid for the firmware device. This
  462. function allows firmware update operation to validate the firmware image
  463. before FmpDeviceSetImage() is called.
  464. @param[in] Image Points to a new firmware image.
  465. @param[in] ImageSize Size, in bytes, of a new firmware image.
  466. @param[out] ImageUpdatable Indicates if a new firmware image is valid for
  467. a firmware update to the firmware device. The
  468. following values from the Firmware Management
  469. Protocol are supported:
  470. IMAGE_UPDATABLE_VALID
  471. IMAGE_UPDATABLE_INVALID
  472. IMAGE_UPDATABLE_INVALID_TYPE
  473. IMAGE_UPDATABLE_INVALID_OLD
  474. IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE
  475. @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt
  476. status to report back to the ESRT table in case
  477. of error. This value will only be checked when this
  478. function returns an error.
  479. The return status code must fall in the range of
  480. LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to
  481. LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE.
  482. If the value falls outside this range, it will be converted
  483. to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL.
  484. @retval EFI_SUCCESS The image was successfully checked. Additional
  485. status information is returned in
  486. ImageUpdatable.
  487. @retval EFI_INVALID_PARAMETER Image is NULL.
  488. @retval EFI_INVALID_PARAMETER ImageUpdatable is NULL.
  489. @retval EFI_INVALID_PARAMETER LastAttemptStatus is NULL.
  490. **/
  491. EFI_STATUS
  492. EFIAPI
  493. FmpDeviceCheckImageWithStatus (
  494. IN CONST VOID *Image,
  495. IN UINTN ImageSize,
  496. OUT UINT32 *ImageUpdatable,
  497. OUT UINT32 *LastAttemptStatus
  498. )
  499. {
  500. EFI_STATUS status = EFI_SUCCESS;
  501. if (LastAttemptStatus == NULL) {
  502. DEBUG ((DEBUG_ERROR, "CheckImageWithStatus - LastAttemptStatus Pointer Parameter is NULL.\n"));
  503. return EFI_INVALID_PARAMETER;
  504. }
  505. *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
  506. if (ImageUpdatable == NULL)
  507. {
  508. DEBUG((DEBUG_ERROR, "CheckImageWithStatus - ImageUpdatable Pointer Parameter is NULL.\n"));
  509. *LastAttemptStatus = LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE;
  510. status = EFI_INVALID_PARAMETER;
  511. goto cleanup;
  512. }
  513. //
  514. //Set to valid and then if any tests fail it will update this flag.
  515. //
  516. *ImageUpdatable = IMAGE_UPDATABLE_VALID;
  517. if (Image == NULL)
  518. {
  519. DEBUG((DEBUG_ERROR, "CheckImageWithStatus - Image Pointer Parameter is NULL.\n"));
  520. *ImageUpdatable = IMAGE_UPDATABLE_INVALID; //not sure if this is needed
  521. *LastAttemptStatus = LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE;
  522. return EFI_INVALID_PARAMETER;
  523. }
  524. cleanup:
  525. return status;
  526. }// CheckImageWithStatus()
  527. /**
  528. Checks if the firmware image is valid for the device.
  529. This function allows firmware update application to validate the firmware image without
  530. invoking the SetImage() first.
  531. @param[in] Image Points to the new image.
  532. @param[in] ImageSize Size of the new image in bytes.
  533. @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
  534. if available, additional information if the image is invalid.
  535. @retval EFI_SUCCESS The image was successfully checked.
  536. @retval EFI_INVALID_PARAMETER The Image was NULL.
  537. **/
  538. EFI_STATUS
  539. EFIAPI
  540. FmpDeviceCheckImage(
  541. IN CONST VOID *Image,
  542. IN UINTN ImageSize,
  543. OUT UINT32 *ImageUpdateable
  544. )
  545. {
  546. UINT32 LastAttemptStatus;
  547. return FmpDeviceCheckImageWithStatus (Image, ImageSize, ImageUpdateable, &LastAttemptStatus);
  548. }// CheckImage()
  549. /**
  550. Device firmware should trigger lock mechanism so that device fw can not be updated or tampered with.
  551. This lock mechanism is generally only cleared by a full system reset (not just sleep state/low power mode)
  552. @retval EFI_SUCCESS The device was successfully locked.
  553. @retval EFI_UNSUPPORTED The hardware device/firmware doesn't support locking
  554. **/
  555. EFI_STATUS
  556. EFIAPI
  557. FmpDeviceLock(
  558. )
  559. {
  560. return EFI_SUCCESS;
  561. }