QuarkPlatformPkg/PlatformInit: Fix recovery detection issues

https://bugzilla.tianocore.org/show_bug.cgi?id=137
https://bugzilla.tianocore.org/show_bug.cgi?id=139

There are four supported methods to generate a boot mode of
BOOT_IN_RECOVERY_MODE on the Galileo platforms:

* Detect a corrupt FV
* Detect a forced recovery from the ForceRecovery UEFI application
  that sets a bit in a sticky R/W register
* The RESET button for the Arduino shield is held while the system
  is powered up
* The RESET button for the Arduino shield is held while the system
  is rebooted using the REBOOT button.

The logic in the PlatformInit module is cleaned up and updated to
support all three of the recovery detection methods.  The clean
ups include:

* Remove extra debug messages
* Remove user input from serial port

In addition, once one of the recovery methods is detected and a
boot mode of BOOT_IN_RECOVERY_MODE is set, the Galileo platforms
would get an error attempting to use the USB host controller to
detect and read a recovery image from a USB drive.  The issue is
the IMR protection registers are programmed to prevent DMA to
memory owned by the PEI Core. The IMR register programming is
updated to allow DMA to memory that is allocated by the recovery
modules using the PEI AllocatePages() service.

Cc: Kelly Steele <kelly.steele@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Kelly Steele <kelly.steele@intel.com>
This commit is contained in:
Michael Kinney
2016-10-03 11:13:42 -07:00
parent 9c3dea8dda
commit 69a0854b8f
6 changed files with 98 additions and 186 deletions

View File

@@ -119,19 +119,6 @@ ValidateFvHeader (
return EFI_SUCCESS;
}
/**
Check whether go to recovery path
@retval TRUE Go to recovery path
@retval FALSE Go to normal path
**/
BOOLEAN
OemRecoveryBootMode ()
{
return PlatformIsBootWithRecoveryStage1 ();
}
/**
Peform the boot mode determination logic
If the box is closed, then
@@ -154,31 +141,35 @@ UpdateBootMode (
EFI_STATUS Status;
EFI_BOOT_MODE NewBootMode;
PEI_CAPSULE_PPI *Capsule;
CHAR8 UserSelection;
UINT32 Straps32;
UINT32 RegValue;
NewBootMode = *BootMode;
//
// Read Straps. Used later if recovery boot.
// Read Sticky R/W Bits
//
Straps32 = QNCAltPortRead (QUARK_SCSS_SOC_UNIT_SB_PORT_ID, QUARK_SCSS_SOC_UNIT_STPDDRCFG);
RegValue = QNCAltPortRead (QUARK_SCSS_SOC_UNIT_SB_PORT_ID, QUARK_SCSS_SOC_UNIT_CFG_STICKY_RW);
DEBUG ((EFI_D_ERROR, "RegValue = %08x\n", RegValue));
//
// Check if we need to boot in recovery mode
//
if ((ValidateFvHeader (BootMode) != EFI_SUCCESS)) {
DEBUG ((EFI_D_INFO, "Force Boot mode recovery\n"));
if ((RegValue & B_CFG_STICKY_RW_FORCE_RECOVERY) != 0) {
NewBootMode = BOOT_IN_RECOVERY_MODE;
Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);
ASSERT_EFI_ERROR (Status);
if (OemRecoveryBootMode () == FALSE) {
DEBUG ((EFI_D_INFO, "Recovery stage1 not Active, reboot to activate recovery stage1 image\n"));
OemInitiateRecoveryAndWait ();
}
} else if (OemRecoveryBootMode ()) {
DEBUG ((EFI_D_INFO, "Boot mode recovery\n"));
DEBUG ((EFI_D_ERROR, "RECOVERY from sticky bit\n"));;
//
// Clear force recovery sticky bit
//
QNCAltPortWrite (
QUARK_SCSS_SOC_UNIT_SB_PORT_ID,
QUARK_SCSS_SOC_UNIT_CFG_STICKY_RW,
RegValue &(~B_CFG_STICKY_RW_FORCE_RECOVERY)
);
} else if (ValidateFvHeader (BootMode) != EFI_SUCCESS) {
NewBootMode = BOOT_IN_RECOVERY_MODE;
Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);
ASSERT_EFI_ERROR (Status);
DEBUG ((EFI_D_ERROR, "RECOVERY from corrupt FV\n"));;
} else if (QNCCheckS3AndClearState ()) {
//
// Determine if we're in capsule update mode
@@ -217,41 +208,17 @@ UpdateBootMode (
NewBootMode = BOOT_WITH_FULL_CONFIGURATION;
}
}
*BootMode = NewBootMode;
if (NewBootMode == BOOT_IN_RECOVERY_MODE) {
DEBUG ((EFI_D_INFO, "Boot mode recovery\n"));
Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode);
ASSERT_EFI_ERROR (Status);
}
Status = PeiServicesSetBootMode (NewBootMode);
ASSERT_EFI_ERROR (Status);
//
// If Recovery Boot then prompt the user to insert a USB key with recovery nodule and
// continue with the recovery. Also give the user a chance to retry a normal boot.
//
if (NewBootMode == BOOT_IN_RECOVERY_MODE) {
if ((Straps32 & B_STPDDRCFG_FORCE_RECOVERY) == 0) {
DEBUG ((EFI_D_ERROR, "*****************************************************************\n"));
DEBUG ((EFI_D_ERROR, "***** Force Recovery Jumper Detected. *****\n"));
DEBUG ((EFI_D_ERROR, "***** Attempting auto recovery of system flash. *****\n"));
DEBUG ((EFI_D_ERROR, "***** Expecting USB key with recovery module connected. *****\n"));
DEBUG ((EFI_D_ERROR, "***** PLEASE REMOVE FORCE RECOVERY JUMPER. *****\n"));
DEBUG ((EFI_D_ERROR, "*****************************************************************\n"));
} else {
DEBUG ((EFI_D_ERROR, "*****************************************************************\n"));
DEBUG ((EFI_D_ERROR, "***** ERROR: System boot failure!!!!!!! *****\n"));
DEBUG ((EFI_D_ERROR, "***** - Press 'R' if you wish to force system recovery *****\n"));
DEBUG ((EFI_D_ERROR, "***** (connect USB key with recovery module first) *****\n"));
DEBUG ((EFI_D_ERROR, "***** - Press any other key to attempt another boot *****\n"));
DEBUG ((EFI_D_ERROR, "*****************************************************************\n"));
UserSelection = PlatformDebugPortGetChar8 ();
if ((UserSelection != 'R') && (UserSelection != 'r')) {
DEBUG ((EFI_D_ERROR, "New boot attempt selected........\n"));
//
// Initialte the cold reset
//
ResetCold ();
}
DEBUG ((EFI_D_ERROR, "Recovery boot selected..........\n"));
}
}
*BootMode = NewBootMode;
return EFI_SUCCESS;
}