SignedCapsulePkg/SystemFirmwareUpdateDxe: Use progress API
authorKinney, Michael D <michael.d.kinney@intel.com>
Thu, 29 Mar 2018 15:35:07 +0000 (08:35 -0700)
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

Use PlatformFlashWriteWithProgress() instead of PlatformFLashWrite()
so the user can be informed of the progress as a capsule is used
to update a firmware image in a firmware device.

Cc: Jiewen Yao <jiewen.yao@intel.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>
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c

index ce6892d..8e66aed 100644 (file)
@@ -65,11 +65,14 @@ ParseUpdateDataFile (
 **/\r
 EFI_STATUS\r
 PerformUpdate (\r
-  IN VOID                         *SystemFirmwareImage,\r
-  IN UINTN                        SystemFirmwareImageSize,\r
-  IN UPDATE_CONFIG_DATA           *ConfigData,\r
-  OUT UINT32                      *LastAttemptVersion,\r
-  OUT UINT32                      *LastAttemptStatus\r
+  IN VOID                                           *SystemFirmwareImage,\r
+  IN UINTN                                          SystemFirmwareImageSize,\r
+  IN UPDATE_CONFIG_DATA                             *ConfigData,\r
+  OUT UINT32                                        *LastAttemptVersion,\r
+  OUT UINT32                                        *LastAttemptStatus,\r
+  IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress,\r
+  IN UINTN                                          StartPercentage,\r
+  IN UINTN                                          EndPercentage\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -78,13 +81,22 @@ PerformUpdate (
   DEBUG((DEBUG_INFO, "  BaseAddress - 0x%lx,", ConfigData->BaseAddress));\r
   DEBUG((DEBUG_INFO, "  ImageOffset - 0x%x,", ConfigData->ImageOffset));\r
   DEBUG((DEBUG_INFO, "  Legnth - 0x%x\n", ConfigData->Length));\r
-  Status = PerformFlashWrite (\r
+  if (Progress != NULL) {\r
+    Progress (StartPercentage);\r
+  }\r
+  Status = PerformFlashWriteWithProgress (\r
              ConfigData->FirmwareType,\r
              ConfigData->BaseAddress,\r
              ConfigData->AddressType,\r
              (VOID *)((UINTN)SystemFirmwareImage + (UINTN)ConfigData->ImageOffset),\r
-             ConfigData->Length\r
+             ConfigData->Length,\r
+             Progress,\r
+             StartPercentage,\r
+             EndPercentage\r
              );\r
+  if (Progress != NULL) {\r
+    Progress (EndPercentage);\r
+  }\r
   if (!EFI_ERROR(Status)) {\r
     *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
     if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) {\r
@@ -111,12 +123,13 @@ PerformUpdate (
 **/\r
 EFI_STATUS\r
 UpdateImage (\r
-  IN VOID                         *SystemFirmwareImage,\r
-  IN UINTN                        SystemFirmwareImageSize,\r
-  IN VOID                         *ConfigImage,\r
-  IN UINTN                        ConfigImageSize,\r
-  OUT UINT32                      *LastAttemptVersion,\r
-  OUT UINT32                      *LastAttemptStatus\r
+  IN VOID                                           *SystemFirmwareImage,\r
+  IN UINTN                                          SystemFirmwareImageSize,\r
+  IN VOID                                           *ConfigImage,\r
+  IN UINTN                                          ConfigImageSize,\r
+  OUT UINT32                                        *LastAttemptVersion,\r
+  OUT UINT32                                        *LastAttemptStatus,\r
+  IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress\r
   )\r
 {\r
   EFI_STATUS                            Status;\r
@@ -124,19 +137,34 @@ UpdateImage (
   UPDATE_CONFIG_DATA                    *UpdateConfigData;\r
   CONFIG_HEADER                         ConfigHeader;\r
   UINTN                                 Index;\r
+  UINTN                                 TotalSize;\r
+  UINTN                                 BytesWritten;\r
+  UINTN                                 StartPercentage;\r
+  UINTN                                 EndPercentage;\r
 \r
   if (ConfigImage == NULL) {\r
     DEBUG((DEBUG_INFO, "PlatformUpdate (NoConfig):"));\r
     DEBUG((DEBUG_INFO, "  BaseAddress - 0x%x,", 0));\r
     DEBUG((DEBUG_INFO, "  Length - 0x%x\n", SystemFirmwareImageSize));\r
     // ASSUME the whole System Firmware include NVRAM region.\r
-    Status = PerformFlashWrite (\r
+    StartPercentage = 0;\r
+    EndPercentage = 100;\r
+    if (Progress != NULL) {\r
+      Progress (StartPercentage);\r
+    }\r
+    Status = PerformFlashWriteWithProgress (\r
                PlatformFirmwareTypeNvRam,\r
                0,\r
                FlashAddressTypeRelativeAddress,\r
                SystemFirmwareImage,\r
-               SystemFirmwareImageSize\r
+               SystemFirmwareImageSize,\r
+               Progress,\r
+               StartPercentage,\r
+               EndPercentage\r
                );\r
+    if (Progress != NULL) {\r
+      Progress (EndPercentage);\r
+    }\r
     if (!EFI_ERROR(Status)) {\r
       *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
       mNvRamUpdated = TRUE;\r
@@ -163,17 +191,30 @@ UpdateImage (
   DEBUG((DEBUG_INFO, "ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));\r
   DEBUG((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid)));\r
 \r
+  TotalSize = 0;\r
+  for (Index = 0; Index < ConfigHeader.NumOfUpdates; Index++) {\r
+    if (CompareGuid(&ConfigData[Index].FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) {\r
+      TotalSize = TotalSize + ConfigData[Index].Length;\r
+    }\r
+  }\r
+\r
+  BytesWritten = 0;\r
   Index = 0;\r
   UpdateConfigData = ConfigData;\r
   while (Index < ConfigHeader.NumOfUpdates) {\r
     if (CompareGuid(&UpdateConfigData->FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) {\r
       DEBUG((DEBUG_INFO, "FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid));\r
+      StartPercentage = (BytesWritten * 100) / TotalSize;\r
+      EndPercentage   = ((BytesWritten + UpdateConfigData->Length) * 100) / TotalSize;\r
       Status = PerformUpdate (\r
                  SystemFirmwareImage,\r
                  SystemFirmwareImageSize,\r
                  UpdateConfigData,\r
                  LastAttemptVersion,\r
-                 LastAttemptStatus\r
+                 LastAttemptStatus,\r
+                 Progress,\r
+                 StartPercentage,\r
+                 EndPercentage\r
                  );\r
       //\r
       // Shall updates be serialized so that if an update is not successfully completed,\r
@@ -186,6 +227,8 @@ UpdateImage (
       DEBUG((DEBUG_INFO, "FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid));\r
     }\r
 \r
+    BytesWritten += UpdateConfigData->Length;\r
+\r
     Index++;\r
     UpdateConfigData++;\r
   }\r
@@ -209,10 +252,11 @@ UpdateImage (
 **/\r
 EFI_STATUS\r
 SystemFirmwareAuthenticatedUpdate (\r
-  IN VOID                         *Image,\r
-  IN UINTN                        ImageSize,\r
-  OUT UINT32                      *LastAttemptVersion,\r
-  OUT UINT32                      *LastAttemptStatus\r
+  IN VOID                                           *Image,\r
+  IN UINTN                                          ImageSize,\r
+  OUT UINT32                                        *LastAttemptVersion,\r
+  OUT UINT32                                        *LastAttemptStatus,\r
+  IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -240,7 +284,7 @@ SystemFirmwareAuthenticatedUpdate (
   ExtractConfigImage(AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);\r
 \r
   DEBUG((DEBUG_INFO, "UpdateImage ...\n"));\r
-  Status = UpdateImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus);\r
+  Status = UpdateImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus, Progress);\r
   if (EFI_ERROR(Status)) {\r
     DEBUG((DEBUG_INFO, "UpdateImage - %r\n", Status));\r
     return Status;\r
@@ -442,8 +486,8 @@ FmpSetImage (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = SystemFirmwareAuthenticatedUpdate((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);\r
-  DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
+  Status = SystemFirmwareAuthenticatedUpdate((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus, Progress);\r
+  DEBUG((DEBUG_INFO, "SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
 \r
   //\r
   // If NVRAM is updated, we should no longer touch variable services, because\r