From: Michael Kubacki <michael.kuba...@microsoft.com> Provides the ability for a given FMP device library instance to return a Last Attempt Status code during FmpDeviceCheckImage() and FmpDeviceSetImage().
Cc: Liming Gao <liming....@intel.com> Cc: Michael D Kinney <michael.d.kin...@intel.com> Cc: Guomin Jiang <guomin.ji...@intel.com> Cc: Wei6 Xu <wei6...@intel.com> Signed-off-by: Michael Kubacki <michael.kuba...@microsoft.com> --- FmpDevicePkg/FmpDxe/FmpDxe.c | 33 +++++++++++++- FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c | 48 ++++++++++++++------ FmpDevicePkg/Include/Library/FmpDeviceLib.h | 48 ++++++++++++++------ 3 files changed, 99 insertions(+), 30 deletions(-) diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index 93d9a0c3c54c..53beb709e1b2 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -1019,12 +1019,28 @@ CheckTheImageInternal ( } RawSize = ImageSize - AllHeaderSize; + // + // Set LastAttemptStatus to successful prior to getting any potential error codes from FmpDeviceLib + // + *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS; + // // FmpDeviceLib CheckImage function to do any specific checks // - Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdatable); + Status = FmpDeviceCheckImage ((((UINT8 *)Image) + AllHeaderSize), RawSize, ImageUpdatable, LastAttemptStatus); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - FmpDeviceLib CheckImage failed. Status = %r\n", mImageIdName, Status)); + + // + // LastAttemptStatus returned from the device library should fall within the designated error range + // [LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE, LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE] + // + if ((*LastAttemptStatus < LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE) || + (*LastAttemptStatus > LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE)) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - LastAttemptStatus from FmpDeviceCheckImage is invalid.\n", mImageIdName)); + ASSERT (FALSE); + *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; + } } cleanup: @@ -1356,10 +1372,23 @@ SetTheImage ( VendorCode, FmpDxeProgress, IncomingFwVersion, - AbortReason + AbortReason, + &LastAttemptStatus ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SetImage from FmpDeviceLib failed. Status = %r.\n", mImageIdName, Status)); + + // + // LastAttemptStatus returned from the device library should fall within the designated error range + // [LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE, LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE] + // + if ((LastAttemptStatus < LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE) || + (LastAttemptStatus > LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE)) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - LastAttemptStatus from FmpDeviceSetImage is invalid.\n", mImageIdName)); + ASSERT (FALSE); + LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; + } + goto cleanup; } diff --git a/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c b/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c index 316de12e910c..9dacb5801639 100644 --- a/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c +++ b/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c @@ -2,7 +2,7 @@ Provides firmware device specific services to support updates of a firmware image stored in a firmware device. - Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR> + Copyright (c) Microsoft Corporation.<BR> Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -380,17 +380,26 @@ FmpDeviceGetImage ( function allows firmware update operation to validate the firmware image before FmpDeviceSetImage() is called. - @param[in] Image Points to a new firmware image. - @param[in] ImageSize Size, in bytes, of a new firmware image. - @param[out] ImageUpdatable Indicates if a new firmware image is valid for - a firmware update to the firmware device. The - following values from the Firmware Management - Protocol are supported: - IMAGE_UPDATABLE_VALID - IMAGE_UPDATABLE_INVALID - IMAGE_UPDATABLE_INVALID_TYPE - IMAGE_UPDATABLE_INVALID_OLD - IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE + @param[in] Image Points to a new firmware image. + @param[in] ImageSize Size, in bytes, of a new firmware image. + @param[out] ImageUpdatable Indicates if a new firmware image is valid for + a firmware update to the firmware device. The + following values from the Firmware Management + Protocol are supported: + IMAGE_UPDATABLE_VALID + IMAGE_UPDATABLE_INVALID + IMAGE_UPDATABLE_INVALID_TYPE + IMAGE_UPDATABLE_INVALID_OLD + IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE + @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt + status to report back to the ESRT table in case + of error. This value will only be checked when this + function returns an error. The return status code + must fall in the range of + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE. + If the value falls outside this range, it will be converted + to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL. @retval EFI_SUCCESS The image was successfully checked. Additional status information is returned in @@ -404,7 +413,8 @@ EFIAPI FmpDeviceCheckImage ( IN CONST VOID *Image, IN UINTN ImageSize, - OUT UINT32 *ImageUpdatable + OUT UINT32 *ImageUpdatable, + OUT UINT32 *LastAttemptStatus ) { return EFI_SUCCESS; @@ -453,6 +463,15 @@ FmpDeviceCheckImage ( EFI_BOOT_SERVICES.AllocatePool(). It is the caller's responsibility to free this buffer with EFI_BOOT_SERVICES.FreePool(). + @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt + status to report back to the ESRT table in case + of error. This value will only be checked when this + function returns an error. The return status code + must fall in the range of + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE. + If the value falls outside this range, it will be converted + to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL. @retval EFI_SUCCESS The firmware device was successfully updated with the new firmware image. @@ -470,7 +489,8 @@ FmpDeviceSetImage ( IN CONST VOID *VendorCode, OPTIONAL IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL IN UINT32 CapsuleFwVersion, - OUT CHAR16 **AbortReason + OUT CHAR16 **AbortReason, + OUT UINT32 *LastAttemptStatus ) { return EFI_UNSUPPORTED; diff --git a/FmpDevicePkg/Include/Library/FmpDeviceLib.h b/FmpDevicePkg/Include/Library/FmpDeviceLib.h index 9a89f5c2eec5..96d1b999797d 100644 --- a/FmpDevicePkg/Include/Library/FmpDeviceLib.h +++ b/FmpDevicePkg/Include/Library/FmpDeviceLib.h @@ -2,7 +2,7 @@ Provides firmware device specific services to support updates of a firmware image stored in a firmware device. - Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR> + Copyright (c) Microsoft Corporation.<BR> Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -376,17 +376,26 @@ FmpDeviceGetImage ( function allows firmware update operation to validate the firmware image before FmpDeviceSetImage() is called. - @param[in] Image Points to a new firmware image. - @param[in] ImageSize Size, in bytes, of a new firmware image. - @param[out] ImageUpdatable Indicates if a new firmware image is valid for - a firmware update to the firmware device. The - following values from the Firmware Management - Protocol are supported: - IMAGE_UPDATABLE_VALID - IMAGE_UPDATABLE_INVALID - IMAGE_UPDATABLE_INVALID_TYPE - IMAGE_UPDATABLE_INVALID_OLD - IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE + @param[in] Image Points to a new firmware image. + @param[in] ImageSize Size, in bytes, of a new firmware image. + @param[out] ImageUpdatable Indicates if a new firmware image is valid for + a firmware update to the firmware device. The + following values from the Firmware Management + Protocol are supported: + IMAGE_UPDATABLE_VALID + IMAGE_UPDATABLE_INVALID + IMAGE_UPDATABLE_INVALID_TYPE + IMAGE_UPDATABLE_INVALID_OLD + IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE + @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt + status to report back to the ESRT table in case + of error. This value will only be checked when this + function returns an error. The return status code + must fall in the range of + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE. + If the value falls outside this range, it will be converted + to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL. @retval EFI_SUCCESS The image was successfully checked. Additional status information is returned in @@ -400,7 +409,8 @@ EFIAPI FmpDeviceCheckImage ( IN CONST VOID *Image, IN UINTN ImageSize, - OUT UINT32 *ImageUpdatable + OUT UINT32 *ImageUpdatable, + OUT UINT32 *LastAttemptStatus ); /** @@ -446,6 +456,15 @@ FmpDeviceCheckImage ( EFI_BOOT_SERVICES.AllocatePool(). It is the caller's responsibility to free this buffer with EFI_BOOT_SERVICES.FreePool(). + @param[out] LastAttemptStatus A pointer to a UINT32 that holds the last attempt + status to report back to the ESRT table in case + of error. This value will only be checked when this + function returns an error. The return status code + must fall in the range of + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE to + LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE. + If the value falls outside this range, it will be converted + to LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL. @retval EFI_SUCCESS The firmware device was successfully updated with the new firmware image. @@ -463,7 +482,8 @@ FmpDeviceSetImage ( IN CONST VOID *VendorCode, OPTIONAL IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL IN UINT32 CapsuleFwVersion, - OUT CHAR16 **AbortReason + OUT CHAR16 **AbortReason, + OUT UINT32 *LastAttemptStatus ); /** -- 2.28.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#64407): https://edk2.groups.io/g/devel/message/64407 Mute This Topic: https://groups.io/mt/76274493/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-