]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c
MdeModulePkg DxeCapsuleLib: Use Attr to know whether reset is required
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleProcessLib.c
index ba3ff90b9f731c4a8136c95e3f932aa65845dd77..176dea196026cdb9db8b9ec23785592aab34d18e 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
@@ -95,12 +99,88 @@ IsValidCapsuleHeader (
   );\r
 \r
 extern BOOLEAN                   mDxeCapsuleLibEndOfDxe;\r
-BOOLEAN                          mNeedReset;\r
+BOOLEAN                          mNeedReset = FALSE;\r
 \r
 VOID                        **mCapsulePtr;\r
 EFI_STATUS                  *mCapsuleStatusArray;\r
 UINT32                      mCapsuleTotalNumber;\r
 \r
+/**\r
+  The firmware implements to process the capsule image.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  CapsuleHeader         Points to a capsule header.\r
+  @param[out] ResetRequired         Indicates whether reset is required or not.\r
+\r
+  @retval EFI_SUCESS            Process Capsule Image successfully.\r
+  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
+  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessThisCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER  *CapsuleHeader,\r
+  OUT BOOLEAN            *ResetRequired OPTIONAL\r
+  );\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,9 +399,9 @@ ProcessTheseCapsules (
   EFI_STATUS                  Status;\r
   EFI_CAPSULE_HEADER          *CapsuleHeader;\r
   UINT32                      Index;\r
-  BOOLEAN                     DisplayCapsuleExist;\r
   ESRT_MANAGEMENT_PROTOCOL    *EsrtManagement;\r
   UINT16                      EmbeddedDriverCount;\r
+  BOOLEAN                     ResetRequired;\r
 \r
   REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeProcessCapsulesBegin)));\r
 \r
@@ -354,26 +434,19 @@ 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, "ProcessThisCapsuleImage (Ux) - 0x%x\n", CapsuleHeader));\r
       DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n"));\r
-      Status = ProcessCapsuleImage (CapsuleHeader);\r
+      Status = ProcessThisCapsuleImage (CapsuleHeader, NULL);\r
       mCapsuleStatusArray [Index] = EFI_SUCCESS;\r
-      DEBUG((DEBUG_INFO, "ProcessCapsuleImage (Ux) - %r\n", Status));\r
+      DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage (Ux) - %r\n", Status));\r
       break;\r
     }\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
@@ -402,22 +475,22 @@ ProcessTheseCapsules (
       }\r
 \r
       if ((!FirstRound) || (EmbeddedDriverCount == 0)) {\r
-        DEBUG((DEBUG_INFO, "ProcessCapsuleImage - 0x%x\n", CapsuleHeader));\r
-        Status = ProcessCapsuleImage (CapsuleHeader);\r
+        DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - 0x%x\n", CapsuleHeader));\r
+        ResetRequired = FALSE;\r
+        Status = ProcessThisCapsuleImage (CapsuleHeader, &ResetRequired);\r
         mCapsuleStatusArray [Index] = Status;\r
-        DEBUG((DEBUG_INFO, "ProcessCapsuleImage - %r\n", Status));\r
+        DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - %r\n", Status));\r
 \r
         if (Status != EFI_NOT_READY) {\r
           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
 \r
-          if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsuleProcessFlag)) != 0 ||\r
-              IsFmpCapsule(CapsuleHeader)) {\r
+          mNeedReset |= ResetRequired;\r
+          if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsuleProcessFlag)) != 0) {\r
             mNeedReset = TRUE;\r
           }\r
         }\r
@@ -447,18 +520,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