Skip to content

Commit

Permalink
OcAfterBootCompatLib: Add ForceConsoleClearScreen
Browse files Browse the repository at this point in the history
Required to handle transition to verbose boot if CMD+V directly causes
boot.efi to enter verbose mode even though neither boot-args nor OC
hotkeys are present.
  • Loading branch information
mikebeaton committed Feb 16, 2023
1 parent 17d64aa commit e105206
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
18 changes: 18 additions & 0 deletions Include/Acidanthera/Library/OcAfterBootCompatLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ typedef struct OC_ABC_SETTINGS_ {
///
BOOLEAN SignalAppleOS;
///
/// Force console clear screen before image start.
///
BOOLEAN ForceConsoleClearScreen;
///
/// Provide OpenCore boot-signature when loading macOS.
/// This resolves the ability to wake from hibernate on Mac EFI, which
/// checks that the hibernation signature matches the SHA-1 hash of the
Expand Down Expand Up @@ -228,4 +232,18 @@ OcAbcInitialize (
IN OC_CPU_INFO *CpuInfo
);

/**
Late arriving setting, depends on detected user keypresses. Used for CMD+V,
which will cause boot.efi to enter verbose mode even if not forced by OC and
not set in boot-args.
@param[in] ForceConsoleClearScreen Force console clear screen before image start.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
OcAbcForceConsoleClearScreen (
IN BOOLEAN ForceConsoleClearScreen
);

#endif // OC_AFTER_BOOT_COMPAT_LIB_H
13 changes: 13 additions & 0 deletions Library/OcAfterBootCompatLib/OcAfterBootCompatLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,16 @@ OcAbcInitialize (

return EFI_SUCCESS;
}

EFI_STATUS
OcAbcForceConsoleClearScreen (
IN BOOLEAN ForceConsoleClearScreen
)
{
BOOT_COMPAT_CONTEXT *BootCompat;

BootCompat = GetBootCompatContext ();
BootCompat->Settings.ForceConsoleClearScreen = ForceConsoleClearScreen;

return EFI_SUCCESS;
}
15 changes: 8 additions & 7 deletions Library/OcAfterBootCompatLib/ServiceOverrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,13 +1246,14 @@ OcStartImage (
ResizeGpuBars (BootCompat->Settings.ResizeAppleGpuBars, FALSE, BootCompat->Settings.ResizeUsePciRbIo);
}

if (OcCheckArgumentFromEnv (
AppleLoadedImage,
BootCompat->ServicePtrs.GetVariable,
"-v",
L_STR_LEN ("-v"),
NULL
))
if ( BootCompat->Settings.ForceConsoleClearScreen
|| OcCheckArgumentFromEnv (
AppleLoadedImage,
BootCompat->ServicePtrs.GetVariable,
"-v",
L_STR_LEN ("-v"),
NULL
))
{
gST->ConOut->ClearScreen (gST->ConOut);
}
Expand Down
6 changes: 6 additions & 0 deletions Library/OcBootManagementLib/HotKeySupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcTimerLib.h>
#include <Library/OcAfterBootCompatLib.h>
#include <Library/OcAppleKeyMapLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcConfigurationLib.h>
Expand Down Expand Up @@ -122,6 +123,7 @@ OcLoadPickerHotKeys (
BOOLEAN HasZero;
BOOLEAN HasOption;
BOOLEAN HasKeyR;
BOOLEAN HasKeyV;
BOOLEAN HasKeyX;

//
Expand Down Expand Up @@ -172,11 +174,15 @@ OcLoadPickerHotKeys (
HasEscape = OcKeyMapHasKey (Keys, NumKeys, AppleHidUsbKbUsageKeyEscape);
HasZero = OcKeyMapHasKey (Keys, NumKeys, AppleHidUsbKbUsageKeyZero);
HasKeyR = OcKeyMapHasKey (Keys, NumKeys, AppleHidUsbKbUsageKeyR);
HasKeyV = OcKeyMapHasKey (Keys, NumKeys, AppleHidUsbKbUsageKeyV);
HasKeyX = OcKeyMapHasKey (Keys, NumKeys, AppleHidUsbKbUsageKeyX);

if (HasCommand && HasKeyR) {
DEBUG ((DEBUG_INFO, "OCHK: CMD+R causes recovery to boot\n"));
Context->PickerCommand = OcPickerBootAppleRecovery;
} else if (HasCommand && HasKeyV) {
DEBUG ((DEBUG_INFO, "OCHK: CMD+V causes verbose boot\n"));
OcAbcForceConsoleClearScreen (TRUE);
} else if (HasKeyX) {
DEBUG ((DEBUG_INFO, "OCHK: X causes macOS to boot\n"));
Context->PickerCommand = OcPickerBootApple;
Expand Down
1 change: 1 addition & 0 deletions Library/OcBootManagementLib/OcBootManagementLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
MemoryAllocationLib
PrintLib
UefiBootServicesTableLib
OcAfterBootCompatLib
OcApfsLib
OcAppleBootPolicyLib
OcAppleChunklistLib
Expand Down

0 comments on commit e105206

Please sign in to comment.