public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Kubacki" <michael.kubacki@outlook.com>
To: devel@edk2.groups.io
Cc: Liming Gao <liming.gao@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Guomin Jiang <guomin.jiang@intel.com>,
	Wei6 Xu <wei6.xu@intel.com>
Subject: [PATCH v2 6/6] FmpDevicePkg/FmpDeviceLib: Add Last Attempt Status to Check/Set API
Date: Mon, 10 Aug 2020 13:27:53 -0700	[thread overview]
Message-ID: <MWHPR07MB3440E92CDACB53752E471022E9440@MWHPR07MB3440.namprd07.prod.outlook.com> (raw)
In-Reply-To: <20200810202753.1318-1-michael.kubacki@outlook.com>

From: Michael Kubacki <michael.kubacki@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.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---
 FmpDevicePkg/FmpDxe/FmpDxe.c                         | 36 +++++++++++++++-
 FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c | 42 ++++++++++++-------
 FmpDevicePkg/Include/Library/FmpDeviceLib.h          | 44 +++++++++++++-------
 3 files changed, 92 insertions(+), 30 deletions(-)

diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c
index 84a8e15cfc17..9f55e6ba5f5d 100644
--- a/FmpDevicePkg/FmpDxe/FmpDxe.c
+++ b/FmpDevicePkg/FmpDxe/FmpDxe.c
@@ -1020,14 +1020,32 @@ 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 either be a generic UEFI Specification defined value or
+  // fall within the designated LAST_ATTEMPT_STATUS_LIBRARY_ERROR range
+  //
+  if (
+      (*LastAttemptStatus < LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE &&
+        *LastAttemptStatus >= LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN) ||
+      (*LastAttemptStatus > LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE)) {
+    DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - LastAttemptStatus from FmpDeviceCheckImage is invalid.\n", mImageIdName));
+    ASSERT (FALSE);
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
+  }
+
 cleanup:
   return Status;
 }
@@ -1356,8 +1374,22 @@ SetTheImage (
              VendorCode,
              FmpDxeProgress,
              IncomingFwVersion,
-             AbortReason
+             AbortReason,
+             &LastAttemptStatus
              );
+  //
+  // LastAttemptStatus returned from the device library should either be a generic UEFI Specification defined value or
+  // fall within the designated LAST_ATTEMPT_STATUS_LIBRARY_ERROR range
+  //
+  if (
+      (LastAttemptStatus < LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE &&
+        LastAttemptStatus >= LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN) ||
+      (LastAttemptStatus > LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE)) {
+    DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - LastAttemptStatus from FmpDeviceSetImage is invalid.\n", mImageIdName));
+    ASSERT (FALSE);
+    LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
+  }
+
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SetImage from FmpDeviceLib failed. Status =  %r.\n", mImageIdName, Status));
     goto cleanup;
diff --git a/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c b/FmpDevicePkg/Library/FmpDeviceLibNull/FmpDeviceLib.c
index 316de12e910c..d08b5b82d42f 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,22 @@ 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. The return status code must fall in the range of
+                                  LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE to
+                                  LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE.
 
   @retval EFI_SUCCESS            The image was successfully checked.  Additional
                                  status information is returned in
@@ -404,7 +409,8 @@ EFIAPI
 FmpDeviceCheckImage (
   IN  CONST VOID  *Image,
   IN  UINTN       ImageSize,
-  OUT UINT32      *ImageUpdatable
+  OUT UINT32      *ImageUpdatable,
+  OUT UINT32      *LastAttemptStatus
   )
 {
   return EFI_SUCCESS;
@@ -453,6 +459,13 @@ 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. Will only be checked when this funtions
+                                returns error. Returned status code falls outside of
+                                LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE and
+                                LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE
+                                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 +483,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..163714654d60 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
@@ -12,6 +12,8 @@
 #ifndef __FMP_DEVICE_LIB__
 #define __FMP_DEVICE_LIB__
 
+#include <Guid/SystemResourceTable.h>
+#include <LastAttemptStatus.h>
 #include <Protocol/FirmwareManagement.h>
 
 /**
@@ -376,17 +378,22 @@ 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. The return status code must fall in the range of
+                                  LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE to
+                                  LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE.
 
   @retval EFI_SUCCESS            The image was successfully checked.  Additional
                                  status information is returned in
@@ -400,7 +407,8 @@ EFIAPI
 FmpDeviceCheckImage (
   IN  CONST VOID  *Image,
   IN  UINTN       ImageSize,
-  OUT UINT32      *ImageUpdatable
+  OUT UINT32      *ImageUpdatable,
+  OUT UINT32      *LastAttemptStatus
   );
 
 /**
@@ -446,6 +454,13 @@ 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. Will only be checked when this funtions
+                                returns error. Returned status code falls outside of
+                                LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MIN_ERROR_CODE and
+                                LAST_ATTEMPT_STATUS_LIBRARY_ERROR_MAX_ERROR_CODE
+                                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 +478,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


      parent reply	other threads:[~2020-08-10 20:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200810202753.1318-1-michael.kubacki@outlook.com>
2020-08-10 20:27 ` [PATCH v2 1/6] MdePkg/SystemResourceTable.h: Add vendor range values Michael Kubacki
2020-08-10 20:27 ` [PATCH v2 2/6] FmpDevicePkg: Add LastAttemptStatus.h Michael Kubacki
2020-08-11  0:31   ` [edk2-devel] " Nate DeSimone
2020-08-11 17:46     ` Michael Kubacki
2020-08-11 18:57       ` Michael Kubacki
2020-08-21  5:33         ` Nate DeSimone
2020-08-21 21:23           ` Michael Kubacki
2020-08-24 17:22             ` Nate DeSimone
2020-08-25  0:30               ` Michael Kubacki
     [not found]               ` <957bfe53-d369-2f06-441f-c5c1bb74aeb2@outlook.com>
2020-08-28 17:46                 ` Michael Kubacki
2020-08-10 20:27 ` [PATCH v2 3/6] FmpDevicePkg/FmpDxe: Add check image path Last Attempt Status capability Michael Kubacki
2020-08-10 20:27 ` [PATCH v2 4/6] FmpDevicePkg/FmpDxe: Improve set image path Last Attempt Status granularity Michael Kubacki
2020-08-10 20:27 ` [PATCH v2 5/6] FmpDevicePkg: Add Last Attempt Status support to dependency libs Michael Kubacki
2020-08-10 20:27 ` Michael Kubacki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MWHPR07MB3440E92CDACB53752E471022E9440@MWHPR07MB3440.namprd07.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox