MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 7 Jun 2018 06:41:33 +0000 (08:41 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 15 Jun 2018 16:18:17 +0000 (18:18 +0200)
If the first call to UpdateImageProgress() fails, there is no point
in passing a pointer to it to Fmp->SetImage(), since it is highly
unlikely to succeed on any subsequent calls.

This permits the FMP implementation to fall back to an alternate means
of providing feedback to the user, e.g., via the console.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c

index f0226ea..ab41df0 100644 (file)
@@ -841,6 +841,7 @@ SetFmpImageData (
   UINT8                                         *Image;\r
   VOID                                          *VendorCode;\r
   CHAR16                                        *AbortReason;\r
+  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS ProgressCallback;\r
 \r
   Status = gBS->HandleProtocol(\r
                   Handle,\r
@@ -892,7 +893,11 @@ SetFmpImageData (
   //\r
   // Before calling SetImage(), reset the progress bar to 0%\r
   //\r
-  UpdateImageProgress (0);\r
+  ProgressCallback = UpdateImageProgress;\r
+  Status = UpdateImageProgress (0);\r
+  if (EFI_ERROR (Status)) {\r
+    ProgressCallback = NULL;\r
+  }\r
 \r
   Status = Fmp->SetImage(\r
                   Fmp,\r
@@ -900,13 +905,15 @@ SetFmpImageData (
                   Image,                                  // Image\r
                   ImageHeader->UpdateImageSize,           // ImageSize\r
                   VendorCode,                             // VendorCode\r
-                  UpdateImageProgress,                    // Progress\r
+                  ProgressCallback,                       // Progress\r
                   &AbortReason                            // AbortReason\r
                   );\r
   //\r
   // Set the progress bar to 100% after returning from SetImage()\r
   //\r
-  UpdateImageProgress (100);\r
+  if (ProgressCallback != NULL) {\r
+    UpdateImageProgress (100);\r
+  }\r
 \r
   DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status));\r
   if (AbortReason != NULL) {\r