FWU: clean up the end firmware update

The patch fixes potential infinite FWU loop if InitFirmwareUpdate fails.

An infinite FWU loop occurs when (Count != MAX_FW_COMPONENTS). Thus,
without this patch, it increases the error-handling complexity in
InitFirmwareUpdate in the future (i.e., all early-return/abort cases must
take care of FW_UPDATE_SM_DONE by themselves).

The fixes simplfes the end firmware update by:
  1. set SM as FW_UPDATE_SM_DONE at EndFirmwareUpdate
  2. move reboot to EndFirmwareUpdate

Verified: EHL CRB

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
This commit is contained in:
Stanley Chang 2022-07-12 14:56:19 +08:00 committed by Guo Dong
parent a5dffd1171
commit c8c53b894e
1 changed files with 10 additions and 17 deletions

View File

@ -1167,9 +1167,6 @@ InitFirmwareUpdate (
if (EFI_ERROR (Status)) {
//
// Error condition
// Clear state machine anyway to prevent FWU loop.
//
SetStateMachineFlag (FW_UPDATE_SM_DONE);
return Status;
}
@ -1261,13 +1258,7 @@ InitFirmwareUpdate (
}
}
//
// At this point, all the firmware images in the capsule are processed
// Clear the state machine and exit
//
if (Count == MAX_FW_COMPONENTS) {
SetStateMachineFlag(FW_UPDATE_SM_DONE);
} else {
if (Count != MAX_FW_COMPONENTS) {
return EFI_ABORTED;
}
@ -1319,11 +1310,8 @@ GetRegionInfo (
This function will clear firmware update trigger and end firmware update.
@retval EFI_SUCCESS Update successfully.
@retval others Error happened during end firmware update.
**/
EFI_STATUS
VOID
EFIAPI
EndFirmwareUpdate (
VOID
@ -1333,8 +1321,15 @@ EndFirmwareUpdate (
ClearFwUpdateTrigger ();
// Clear state machine anyway to prevent FWU loop.
SetStateMachineFlag (FW_UPDATE_SM_DONE);
Status = PlatformEndFirmwareUpdate ();
return Status;
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Platform end firmware update failed: %r\n", Status));
}
Reboot (EfiResetCold);
}
/**
@ -1478,6 +1473,4 @@ EndOfFwu:
//
ConsolePrint ("Exiting Firmware Update (Status: %r)\n", Status);
EndFirmwareUpdate ();
Reboot (EfiResetCold);
}