MdeModulePkg/DxeCapsuleLibFmp: Add progress bar support

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>
This commit is contained in:
Kinney, Michael D 2018-02-15 14:02:06 -08:00
parent f3100a1a2f
commit 5747610657
5 changed files with 131 additions and 36 deletions

View File

@ -45,6 +45,7 @@
#include <Protocol/GraphicsOutput.h> #include <Protocol/GraphicsOutput.h>
#include <Protocol/EsrtManagement.h> #include <Protocol/EsrtManagement.h>
#include <Protocol/FirmwareManagement.h> #include <Protocol/FirmwareManagement.h>
#include <Protocol/FirmwareManagementProgress.h>
#include <Protocol/DevicePath.h> #include <Protocol/DevicePath.h>
EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = NULL; EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = NULL;
@ -53,6 +54,8 @@ BOOLEAN mIsVirtualAddrConverted = FALSE;
BOOLEAN mDxeCapsuleLibEndOfDxe = FALSE; BOOLEAN mDxeCapsuleLibEndOfDxe = FALSE;
EFI_EVENT mDxeCapsuleLibEndOfDxeEvent = NULL; EFI_EVENT mDxeCapsuleLibEndOfDxeEvent = NULL;
EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL *mFmpProgress = NULL;
/** /**
Initialize capsule related variables. Initialize capsule related variables.
**/ **/
@ -101,18 +104,17 @@ RecordFmpCapsuleStatusVariable (
Function indicate the current completion progress of the firmware Function indicate the current completion progress of the firmware
update. Platform may override with own specific progress function. update. Platform may override with own specific progress function.
@param[in] Completion A value between 1 and 100 indicating the current completion progress of the firmware update @param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
@retval EFI_SUCESS Input capsule is a correct FMP capsule. @retval EFI_SUCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
Update_Image_Progress ( UpdateImageProgress (
IN UINTN Completion IN UINTN Completion
) );
{
return EFI_SUCCESS;
}
/** /**
Return if this CapsuleGuid is a FMP capsule GUID or not. Return if this CapsuleGuid is a FMP capsule GUID or not.
@ -849,6 +851,19 @@ SetFmpImageData (
return Status; return Status;
} }
//
// Lookup Firmware Management Progress Protocol before SetImage() is called
// This is an optional protocol that may not be present on Handle.
//
Status = gBS->HandleProtocol (
Handle,
&gEdkiiFirmwareManagementProgressProtocolGuid,
(VOID **)&mFmpProgress
);
if (EFI_ERROR (Status)) {
mFmpProgress = NULL;
}
if (ImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) { if (ImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {
Image = (UINT8 *)(ImageHeader + 1); Image = (UINT8 *)(ImageHeader + 1);
} else { } else {
@ -873,21 +888,37 @@ SetFmpImageData (
DEBUG((DEBUG_INFO, "(UpdateHardwareInstance - 0x%x)", ImageHeader->UpdateHardwareInstance)); DEBUG((DEBUG_INFO, "(UpdateHardwareInstance - 0x%x)", ImageHeader->UpdateHardwareInstance));
} }
DEBUG((DEBUG_INFO, "\n")); DEBUG((DEBUG_INFO, "\n"));
//
// Before calling SetImage(), reset the progress bar to 0%
//
UpdateImageProgress (0);
Status = Fmp->SetImage( Status = Fmp->SetImage(
Fmp, Fmp,
ImageHeader->UpdateImageIndex, // ImageIndex ImageHeader->UpdateImageIndex, // ImageIndex
Image, // Image Image, // Image
ImageHeader->UpdateImageSize, // ImageSize ImageHeader->UpdateImageSize, // ImageSize
VendorCode, // VendorCode VendorCode, // VendorCode
Update_Image_Progress, // Progress UpdateImageProgress, // Progress
&AbortReason // AbortReason &AbortReason // AbortReason
); );
//
// Set the progress bar to 100% after returning from SetImage()
//
UpdateImageProgress (100);
DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status)); DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status));
if (AbortReason != NULL) { if (AbortReason != NULL) {
DEBUG ((DEBUG_ERROR, "%s\n", AbortReason)); DEBUG ((DEBUG_ERROR, "%s\n", AbortReason));
FreePool(AbortReason); FreePool(AbortReason);
} }
//
// Clear mFmpProgress after SetImage() returns
//
mFmpProgress = NULL;
return Status; return Status;
} }

View File

@ -52,6 +52,7 @@
PrintLib PrintLib
HobLib HobLib
BmpSupportLib BmpSupportLib
DisplayUpdateProgressLib
[Pcd] [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax ## CONSUMES
@ -66,9 +67,10 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem ## CONSUMES
[Protocols] [Protocols]
gEsrtManagementProtocolGuid ## CONSUMES gEsrtManagementProtocolGuid ## CONSUMES
gEfiFirmwareManagementProtocolGuid ## CONSUMES gEfiFirmwareManagementProtocolGuid ## CONSUMES
gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiFirmwareManagementProgressProtocolGuid ## SOMETIMES_CONSUMES
[Guids] [Guids]
gEfiFmpCapsuleGuid ## SOMETIMES_CONSUMES ## GUID gEfiFmpCapsuleGuid ## SOMETIMES_CONSUMES ## GUID

View File

@ -9,7 +9,7 @@
ProcessCapsules(), ProcessTheseCapsules() will receive untrusted ProcessCapsules(), ProcessTheseCapsules() will receive untrusted
input and do basic validation. input and do basic validation.
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -22,6 +22,7 @@
#include <PiDxe.h> #include <PiDxe.h>
#include <Protocol/EsrtManagement.h> #include <Protocol/EsrtManagement.h>
#include <Protocol/FirmwareManagementProgress.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
@ -34,9 +35,12 @@
#include <Library/HobLib.h> #include <Library/HobLib.h>
#include <Library/ReportStatusCodeLib.h> #include <Library/ReportStatusCodeLib.h>
#include <Library/CapsuleLib.h> #include <Library/CapsuleLib.h>
#include <Library/DisplayUpdateProgressLib.h>
#include <IndustryStandard/WindowsUxCapsule.h> #include <IndustryStandard/WindowsUxCapsule.h>
extern EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL *mFmpProgress;
/** /**
Return if this FMP is a system FMP or a device FMP, based upon CapsuleHeader. Return if this FMP is a system FMP or a device FMP, based upon CapsuleHeader.
@ -101,6 +105,62 @@ VOID **mCapsulePtr;
EFI_STATUS *mCapsuleStatusArray; EFI_STATUS *mCapsuleStatusArray;
UINT32 mCapsuleTotalNumber; UINT32 mCapsuleTotalNumber;
/**
Function indicate the current completion progress of the firmware
update. Platform may override with own specific progress function.
@param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
@retval EFI_SUCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/
EFI_STATUS
EFIAPI
UpdateImageProgress (
IN UINTN Completion
)
{
EFI_STATUS Status;
UINTN Seconds;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color;
DEBUG((DEBUG_INFO, "Update Progress - %d%%\n", Completion));
if (Completion > 100) {
return EFI_INVALID_PARAMETER;
}
//
// Use a default timeout of 5 minutes if there is not FMP Progress Protocol.
//
Seconds = 5 * 60;
Color = NULL;
if (mFmpProgress != NULL) {
Seconds = mFmpProgress->WatchdogSeconds;
Color = &mFmpProgress->ProgressBarForegroundColor;
}
//
// Cancel the watchdog timer
//
gBS->SetWatchdogTimer (0, 0x0000, 0, NULL);
if (Completion != 100) {
//
// Arm the watchdog timer from PCD setting
//
if (Seconds != 0) {
DEBUG ((DEBUG_VERBOSE, "Arm watchdog timer %d seconds\n", Seconds));
gBS->SetWatchdogTimer (Seconds, 0x0000, 0, NULL);
}
}
Status = DisplayUpdateProgress (Completion, Color);
return Status;
}
/** /**
This function initializes the mCapsulePtr, mCapsuleStatusArray and mCapsuleTotalNumber. This function initializes the mCapsulePtr, mCapsuleStatusArray and mCapsuleTotalNumber.
**/ **/
@ -319,7 +379,6 @@ ProcessTheseCapsules (
EFI_STATUS Status; EFI_STATUS Status;
EFI_CAPSULE_HEADER *CapsuleHeader; EFI_CAPSULE_HEADER *CapsuleHeader;
UINT32 Index; UINT32 Index;
BOOLEAN DisplayCapsuleExist;
ESRT_MANAGEMENT_PROTOCOL *EsrtManagement; ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
UINT16 EmbeddedDriverCount; UINT16 EmbeddedDriverCount;
@ -354,12 +413,10 @@ ProcessTheseCapsules (
// //
// If Windows UX capsule exist, process it first // If Windows UX capsule exist, process it first
// //
DisplayCapsuleExist = FALSE;
for (Index = 0; Index < mCapsuleTotalNumber; Index++) { for (Index = 0; Index < mCapsuleTotalNumber; Index++) {
CapsuleHeader = (EFI_CAPSULE_HEADER*) mCapsulePtr [Index]; CapsuleHeader = (EFI_CAPSULE_HEADER*) mCapsulePtr [Index];
if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) { if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
DEBUG ((DEBUG_INFO, "ProcessCapsuleImage (Ux) - 0x%x\n", CapsuleHeader)); DEBUG ((DEBUG_INFO, "ProcessCapsuleImage (Ux) - 0x%x\n", CapsuleHeader));
DisplayCapsuleExist = TRUE;
DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n")); DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n"));
Status = ProcessCapsuleImage (CapsuleHeader); Status = ProcessCapsuleImage (CapsuleHeader);
mCapsuleStatusArray [Index] = EFI_SUCCESS; mCapsuleStatusArray [Index] = EFI_SUCCESS;
@ -368,12 +425,7 @@ ProcessTheseCapsules (
} }
} }
if (!DisplayCapsuleExist) { DEBUG ((DEBUG_INFO, "Updating the firmware ......\n"));
//
// Display Capsule not found. Display the default string.
//
Print (L"Updating the firmware ......\r\n");
}
// //
// All capsules left are recognized by platform. // All capsules left are recognized by platform.
@ -411,7 +463,6 @@ ProcessTheseCapsules (
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
REPORT_STATUS_CODE(EFI_ERROR_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareFailed))); REPORT_STATUS_CODE(EFI_ERROR_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareFailed)));
DEBUG ((DEBUG_ERROR, "Capsule process failed!\n")); DEBUG ((DEBUG_ERROR, "Capsule process failed!\n"));
Print (L"Firmware update failed...\r\n");
} else { } else {
REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareSuccess))); REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwareSuccess)));
} }
@ -447,18 +498,9 @@ DoResetSystem (
VOID VOID
) )
{ {
UINTN Index;
REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeResettingSystem)));
Print(L"Capsule Request Cold Reboot.\n");
DEBUG((DEBUG_INFO, "Capsule Request Cold Reboot.")); DEBUG((DEBUG_INFO, "Capsule Request Cold Reboot."));
for (Index = 5; Index > 0; Index--) { REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeResettingSystem)));
Print(L"\rResetting system in %d seconds ...", Index);
DEBUG((DEBUG_INFO, "\rResetting system in %d seconds ...", Index));
gBS->Stall(1000000);
}
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL); gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);

View File

@ -3,7 +3,7 @@
Dummy function for runtime module, because CapsuleDxeRuntime Dummy function for runtime module, because CapsuleDxeRuntime
does not need call ProcessCapsules(). does not need call ProcessCapsules().
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -17,6 +17,25 @@
#include <PiDxe.h> #include <PiDxe.h>
#include <Library/CapsuleLib.h> #include <Library/CapsuleLib.h>
/**
Function indicate the current completion progress of the firmware
update. Platform may override with own specific progress function.
@param[in] Completion A value between 1 and 100 indicating the current
completion progress of the firmware update
@retval EFI_SUCESS The capsule update progress was updated.
@retval EFI_INVALID_PARAMETER Completion is greater than 100%.
**/
EFI_STATUS
EFIAPI
UpdateImageProgress (
IN UINTN Completion
)
{
return EFI_SUCCESS;
}
/** /**
This routine is called to process capsules. This routine is called to process capsules.

View File

@ -69,9 +69,10 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem ## CONSUMES
[Protocols] [Protocols]
gEsrtManagementProtocolGuid ## CONSUMES gEsrtManagementProtocolGuid ## CONSUMES
gEfiFirmwareManagementProtocolGuid ## CONSUMES gEfiFirmwareManagementProtocolGuid ## CONSUMES
gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES
gEdkiiFirmwareManagementProgressProtocolGuid ## SOMETIMES_CONSUMES
[Guids] [Guids]
gEfiFmpCapsuleGuid ## SOMETIMES_CONSUMES ## GUID gEfiFmpCapsuleGuid ## SOMETIMES_CONSUMES ## GUID