]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c
MdeModulePkg/DxeCapsuleLibFmp: Add progress bar support
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleProcessLib.c
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