]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeCapsuleLibFmp: Add progress bar support
authorKinney, Michael D <michael.d.kinney@intel.com>
Thu, 15 Feb 2018 22:02:06 +0000 (14:02 -0800)
committerKinney, Michael D <michael.d.kinney@intel.com>
Fri, 8 Jun 2018 22:40:54 +0000 (15:40 -0700)
https://bugzilla.tianocore.org/show_bug.cgi?id=801

Based on content from the following branch/commits:
https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport

* Change Update_Image_Progress() to UpdateImageProcess()
* Call DisplayUpdateProgressLib from UpdateImageProgress().
* Split out a boot service and runtime version of
  UpdateImageProgress() so the DisplayUpdateProgressLib is
  not used at runtime.
* If gEdkiiFirmwareManagementProgressProtocolGuid is present,
  then use its progress bar color and watchdog timer value.
* If gEdkiiFirmwareManagementProgressProtocolGuid is not present,
  then use default progress bar color and 5 min watchdog timer.
* Remove Print() calls during capsule processing.  Instead,
  the DisplayUpdateProgressLib is used to inform the user
  of progress during a capsule update.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf

index 05fcd92deb00a9aaf1002653fed7d52439313564..f0226eafa57691be76e07cc1db6da36a5b716791 100644 (file)
@@ -45,6 +45,7 @@
 #include <Protocol/GraphicsOutput.h>\r
 #include <Protocol/EsrtManagement.h>\r
 #include <Protocol/FirmwareManagement.h>\r
+#include <Protocol/FirmwareManagementProgress.h>\r
 #include <Protocol/DevicePath.h>\r
 \r
 EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable                  = NULL;\r
@@ -53,6 +54,8 @@ BOOLEAN                   mIsVirtualAddrConverted      = FALSE;
 BOOLEAN                   mDxeCapsuleLibEndOfDxe       = FALSE;\r
 EFI_EVENT                 mDxeCapsuleLibEndOfDxeEvent  = NULL;\r
 \r
+EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL  *mFmpProgress = NULL;\r
+\r
 /**\r
   Initialize capsule related variables.\r
 **/\r
@@ -101,18 +104,17 @@ RecordFmpCapsuleStatusVariable (
   Function indicate the current completion progress of the firmware\r
   update. Platform may override with own specific progress function.\r
 \r
-  @param[in]  Completion    A value between 1 and 100 indicating the current completion progress of the firmware update\r
+  @param[in]  Completion  A value between 1 and 100 indicating the current\r
+                          completion progress of the firmware update\r
 \r
-  @retval EFI_SUCESS    Input capsule is a correct FMP capsule.\r
+  @retval EFI_SUCESS             The capsule update progress was updated.\r
+  @retval EFI_INVALID_PARAMETER  Completion is greater than 100%.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-Update_Image_Progress (\r
+UpdateImageProgress (\r
   IN UINTN  Completion\r
-  )\r
-{\r
-  return EFI_SUCCESS;\r
-}\r
+  );\r
 \r
 /**\r
   Return if this CapsuleGuid is a FMP capsule GUID or not.\r
@@ -849,6 +851,19 @@ SetFmpImageData (
     return Status;\r
   }\r
 \r
+  //\r
+  // Lookup Firmware Management Progress Protocol before SetImage() is called\r
+  // This is an optional protocol that may not be present on Handle.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEdkiiFirmwareManagementProgressProtocolGuid,\r
+                  (VOID **)&mFmpProgress\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    mFmpProgress = NULL;\r
+  }\r
+\r
   if (ImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {\r
     Image = (UINT8 *)(ImageHeader + 1);\r
   } else {\r
@@ -873,21 +888,37 @@ SetFmpImageData (
     DEBUG((DEBUG_INFO, "(UpdateHardwareInstance - 0x%x)", ImageHeader->UpdateHardwareInstance));\r
   }\r
   DEBUG((DEBUG_INFO, "\n"));\r
+\r
+  //\r
+  // Before calling SetImage(), reset the progress bar to 0%\r
+  //\r
+  UpdateImageProgress (0);\r
+\r
   Status = Fmp->SetImage(\r
                   Fmp,\r
                   ImageHeader->UpdateImageIndex,          // ImageIndex\r
                   Image,                                  // Image\r
                   ImageHeader->UpdateImageSize,           // ImageSize\r
                   VendorCode,                             // VendorCode\r
-                  Update_Image_Progress,                  // Progress\r
+                  UpdateImageProgress,                    // Progress\r
                   &AbortReason                            // AbortReason\r
                   );\r
+  //\r
+  // Set the progress bar to 100% after returning from SetImage()\r
+  //\r
+  UpdateImageProgress (100);\r
+\r
   DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status));\r
   if (AbortReason != NULL) {\r
     DEBUG ((DEBUG_ERROR, "%s\n", AbortReason));\r
     FreePool(AbortReason);\r
   }\r
 \r
+  //\r
+  // Clear mFmpProgress after SetImage() returns\r
+  //\r
+  mFmpProgress = NULL;\r
+\r
   return Status;\r
 }\r
 \r
index 1d947101d30c856b7523ccc2ebfee316cfda1f51..8367264f76a25967a0c1b9cbec14f0650bbcc84f 100644 (file)
@@ -52,6 +52,7 @@
   PrintLib\r
   HobLib\r
   BmpSupportLib\r
+  DisplayUpdateProgressLib\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax                               ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem         ## CONSUMES\r
 \r
 [Protocols]\r
-  gEsrtManagementProtocolGuid             ## CONSUMES\r
-  gEfiFirmwareManagementProtocolGuid      ## CONSUMES\r
-  gEdkiiVariableLockProtocolGuid          ## SOMETIMES_CONSUMES\r
+  gEsrtManagementProtocolGuid                   ## CONSUMES\r
+  gEfiFirmwareManagementProtocolGuid            ## CONSUMES\r
+  gEdkiiVariableLockProtocolGuid                ## SOMETIMES_CONSUMES\r
+  gEdkiiFirmwareManagementProgressProtocolGuid  ## SOMETIMES_CONSUMES\r
 \r
 [Guids]\r
   gEfiFmpCapsuleGuid                      ## SOMETIMES_CONSUMES ## GUID\r
index ba3ff90b9f731c4a8136c95e3f932aa65845dd77..26ca4e295f20bd26fc5d5596ce6c9c36f989f432 100644 (file)
@@ -9,7 +9,7 @@
   ProcessCapsules(), ProcessTheseCapsules() will receive untrusted\r
   input and do basic validation.\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -22,6 +22,7 @@
 \r
 #include <PiDxe.h>\r
 #include <Protocol/EsrtManagement.h>\r
+#include <Protocol/FirmwareManagementProgress.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/CapsuleLib.h>\r
+#include <Library/DisplayUpdateProgressLib.h>\r
 \r
 #include <IndustryStandard/WindowsUxCapsule.h>\r
 \r
+extern EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL  *mFmpProgress;\r
+\r
 /**\r
   Return if this FMP is a system FMP or a device FMP, based upon CapsuleHeader.\r
 \r
@@ -101,6 +105,62 @@ VOID                        **mCapsulePtr;
 EFI_STATUS                  *mCapsuleStatusArray;\r
 UINT32                      mCapsuleTotalNumber;\r
 \r
+/**\r
+  Function indicate the current completion progress of the firmware\r
+  update. Platform may override with own specific progress function.\r
+\r
+  @param[in]  Completion  A value between 1 and 100 indicating the current\r
+                          completion progress of the firmware update\r
+\r
+  @retval EFI_SUCESS             The capsule update progress was updated.\r
+  @retval EFI_INVALID_PARAMETER  Completion is greater than 100%.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UpdateImageProgress (\r
+  IN UINTN  Completion\r
+  )\r
+{\r
+  EFI_STATUS                           Status;\r
+  UINTN                                Seconds;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  *Color;\r
+\r
+  DEBUG((DEBUG_INFO, "Update Progress - %d%%\n", Completion));\r
+\r
+  if (Completion > 100) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Use a default timeout of 5 minutes if there is not FMP Progress Protocol.\r
+  //\r
+  Seconds = 5 * 60;\r
+  Color   = NULL;\r
+  if (mFmpProgress != NULL) {\r
+    Seconds = mFmpProgress->WatchdogSeconds;\r
+    Color   = &mFmpProgress->ProgressBarForegroundColor;\r
+  }\r
+\r
+  //\r
+  // Cancel the watchdog timer\r
+  //\r
+  gBS->SetWatchdogTimer (0, 0x0000, 0, NULL);\r
+\r
+  if (Completion != 100) {\r
+    //\r
+    // Arm the watchdog timer from PCD setting\r
+    //\r
+    if (Seconds != 0) {\r
+      DEBUG ((DEBUG_VERBOSE, "Arm watchdog timer %d seconds\n", Seconds));\r
+      gBS->SetWatchdogTimer (Seconds, 0x0000, 0, NULL);\r
+    }\r
+  }\r
+\r
+  Status = DisplayUpdateProgress (Completion, Color);\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   This function initializes the mCapsulePtr, mCapsuleStatusArray and mCapsuleTotalNumber.\r
 **/\r
@@ -319,7 +379,6 @@ ProcessTheseCapsules (
   EFI_STATUS                  Status;\r
   EFI_CAPSULE_HEADER          *CapsuleHeader;\r
   UINT32                      Index;\r
-  BOOLEAN                     DisplayCapsuleExist;\r
   ESRT_MANAGEMENT_PROTOCOL    *EsrtManagement;\r
   UINT16                      EmbeddedDriverCount;\r
 \r
@@ -354,12 +413,10 @@ ProcessTheseCapsules (
   //\r
   // If Windows UX capsule exist, process it first\r
   //\r
-  DisplayCapsuleExist = FALSE;\r
   for (Index = 0; Index < mCapsuleTotalNumber; Index++) {\r
     CapsuleHeader = (EFI_CAPSULE_HEADER*) mCapsulePtr [Index];\r
     if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {\r
       DEBUG ((DEBUG_INFO, "ProcessCapsuleImage (Ux) - 0x%x\n", CapsuleHeader));\r
-      DisplayCapsuleExist = TRUE;\r
       DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n"));\r
       Status = ProcessCapsuleImage (CapsuleHeader);\r
       mCapsuleStatusArray [Index] = EFI_SUCCESS;\r
@@ -368,12 +425,7 @@ ProcessTheseCapsules (
     }\r
   }\r
 \r
-  if (!DisplayCapsuleExist) {\r
-    //\r
-    // Display Capsule not found. Display the default string.\r
-    //\r
-    Print (L"Updating the firmware ......\r\n");\r
-  }\r
+  DEBUG ((DEBUG_INFO, "Updating the firmware ......\n"));\r
 \r
   //\r
   // All capsules left are recognized by platform.\r
@@ -411,7 +463,6 @@ ProcessTheseCapsules (
           if (EFI_ERROR(Status)) {\r
             REPORT_STATUS_CODE(EFI_ERROR_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareFailed)));\r
             DEBUG ((DEBUG_ERROR, "Capsule process failed!\n"));\r
-            Print (L"Firmware update failed...\r\n");\r
           } else {\r
             REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareSuccess)));\r
           }\r
@@ -447,18 +498,9 @@ DoResetSystem (
   VOID\r
   )\r
 {\r
-  UINTN                         Index;\r
-\r
-  REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeResettingSystem)));\r
-\r
-  Print(L"Capsule Request Cold Reboot.\n");\r
   DEBUG((DEBUG_INFO, "Capsule Request Cold Reboot."));\r
 \r
-  for (Index = 5; Index > 0; Index--) {\r
-    Print(L"\rResetting system in %d seconds ...", Index);\r
-    DEBUG((DEBUG_INFO, "\rResetting system in %d seconds ...", Index));\r
-    gBS->Stall(1000000);\r
-  }\r
+  REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeResettingSystem)));\r
 \r
   gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);\r
 \r
index 07e9e46eae7974a3266964c925737c88b4d3ed6a..274c1c4c1cef9361c99c187e573943cf0eabaf8b 100644 (file)
@@ -3,7 +3,7 @@
   Dummy function for runtime module, because CapsuleDxeRuntime\r
   does not need call ProcessCapsules().\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <PiDxe.h>\r
 #include <Library/CapsuleLib.h>\r
 \r
+/**\r
+  Function indicate the current completion progress of the firmware\r
+  update. Platform may override with own specific progress function.\r
+\r
+  @param[in]  Completion  A value between 1 and 100 indicating the current\r
+                          completion progress of the firmware update\r
+\r
+  @retval EFI_SUCESS             The capsule update progress was updated.\r
+  @retval EFI_INVALID_PARAMETER  Completion is greater than 100%.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UpdateImageProgress (\r
+  IN UINTN  Completion\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
 \r
   This routine is called to process capsules.\r
index 1659b13ef463d1c40ae103803302dd6eec84901d..342df9e99cdf5227c76e05fd985a4cc23f67e82d 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem         ## CONSUMES\r
 \r
 [Protocols]\r
-  gEsrtManagementProtocolGuid             ## CONSUMES\r
-  gEfiFirmwareManagementProtocolGuid      ## CONSUMES\r
-  gEdkiiVariableLockProtocolGuid          ## SOMETIMES_CONSUMES\r
+  gEsrtManagementProtocolGuid                   ## CONSUMES\r
+  gEfiFirmwareManagementProtocolGuid            ## CONSUMES\r
+  gEdkiiVariableLockProtocolGuid                ## SOMETIMES_CONSUMES\r
+  gEdkiiFirmwareManagementProgressProtocolGuid  ## SOMETIMES_CONSUMES\r
 \r
 [Guids]\r
   gEfiFmpCapsuleGuid                      ## SOMETIMES_CONSUMES ## GUID\r