Allow restarting OsLoader after trying out all boot options (#387)

After trying out all boot options, if it still fails to boot,
current SBL code will do CpuHalt(). A better approach is to boot
into Shell and reset the current boot option to 0. In this way,
it allows user to try boot option again after modifying boot
option parameters. However, for release build, it does not change
the original behavior. System will still halt in this condition.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
This commit is contained in:
Maurice Ma 2019-10-16 09:28:20 -07:00 committed by Aiden Park
parent 74d9af1e68
commit 66c133b987
1 changed files with 39 additions and 16 deletions

View File

@ -837,6 +837,39 @@ RunShell (
Shell (ShellExtensionCmd, Timeout);
}
/**
Restart the OsLoader from beginning.
This function will roll back the stack to the original point and jump
into SecStartup() again. By doing this, all memory allocated in OsLoader
will be reclaimed. However, special handling might be required to ensure
device state is in good condition in preparation for the restarting.
@param Param parameter passed from SwitchStack().
**/
VOID
RestartOsLoader (
IN VOID *Param
)
{
// De-init boot devices while restarting payload.
DeinitBootDevices ();
// Use switch stack to ensure stack will be rolled back to original point.
// The stack will be adjusted by +8 to match the exact stack top at the
// time that SecStartup() was called by Stage2.
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)SecStartup,
(VOID *)PcdGet32 (PcdPayloadHobList),
NULL,
(VOID *) ((UINT8 *)Param + 8)
);
// Should never reach here
CpuHalt (NULL);
}
/**
Payload main entry.
@ -916,28 +949,18 @@ PayloadMain (
break;
}
// De-init boot devices while restarting payload.
DeinitBootDevices ();
//
// Use switch stack to ensure stack will be rolled back to original point.
// The stack will be adjusted by +8 to match the exact stack top at the
// time that SecStartup() was called by Stage2.
//
// In order to reclaim all allocated memory for previous boot,
// restart OsLoader from beginning.
DEBUG ((DEBUG_INIT, "Try next boot option\n"));
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)SecStartup,
(VOID *)PcdGet32 (PcdPayloadHobList),
NULL,
(VOID *) ((UINT8 *)Param + 8)
);
RestartOsLoader (Param);
}
DEBUG ((DEBUG_INFO, "Error: while trying to booting...\n"));
GOTO_SHELL:
if (DebugCodeEnabled () == TRUE) {
RunShell (0);
// Retry all boot options from beginning
mCurrentBoot = 0;
RestartOsLoader (Param);
}
CpuHalt (NULL);