2020-02-15 15:51:18 +01:00
/*
* refit / main . c
* Main code for the boot menu
*
* Copyright ( c ) 2006 - 2010 Christoph Pfisterer
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are
* met :
*
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
*
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the
* distribution .
*
* * Neither the name of Christoph Pfisterer nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT
* LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2020-08-17 21:40:52 +02:00
# include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
2021-04-03 12:55:25 +02:00
# include <cpp_util/globals_ctor.h>
# include <cpp_util/globals_dtor.h>
2021-04-28 20:30:34 +02:00
# include "../cpp_foundation/XString.h"
2020-02-23 12:21:28 +01:00
# include "../cpp_unit_test/all_tests.h"
2020-02-15 15:51:18 +01:00
2020-03-13 14:11:58 +01:00
# include "../entry_scan/entry_scan.h"
# include "../libeg/nanosvg.h"
2020-02-29 08:30:21 +01:00
# include "../gui/menu_items/menu_globals.h"
# include "menu.h"
# include "../Platform/Settings.h"
# include "../Platform/DataHubCpu.h"
# include "../Platform/Events.h"
# include "screen.h"
# include "../entry_scan/bootscreen.h"
# include "../Platform/Nvram.h"
2020-04-05 14:25:39 +02:00
# include "../entry_scan/common.h"
# include "../gui/shared_with_menu.h"
2020-04-16 09:15:26 +02:00
# include "../Platform/platformdata.h"
# include "../Platform/guid.h"
# include "../Platform/APFS.h"
# include "../Platform/cpu.h"
# include "../Platform/smbios.h"
# include "../Platform/AcpiPatcher.h"
# include "../Platform/Hibernate.h"
# include "../Platform/LegacyBoot.h"
# include "../Platform/PlatformDriverOverride.h"
# include "../Platform/Edid.h"
# include "../Platform/Console.h"
# include "../Platform/spd.h"
# include "../Platform/Injectors.h"
# include "../Platform/StartupSound.h"
# include "../Platform/BootOptions.h"
2020-04-16 11:09:22 +02:00
# include "../Platform/boot.h"
# include "../Platform/kext_inject.h"
2021-02-06 18:16:46 +01:00
# include "../Platform/KextList.h"
2020-08-09 17:55:30 +02:00
# include "../gui/REFIT_MENU_SCREEN.h"
2021-03-22 13:40:01 +01:00
# include "../gui/REFIT_MAINMENU_SCREEN.h"
2021-04-28 20:30:34 +02:00
# include "../Settings/Self.h"
# include "../Settings/SelfOem.h"
2021-02-06 18:16:46 +01:00
# include "../Platform/BasicIO.h"
# include "../include/OSTypes.h"
# include "../include/OSFlags.h"
# include "../libeg/XTheme.h"
2021-04-28 20:30:34 +02:00
# include "../Settings/ConfigManager.h"
# include "../Platform/CloverVersion.h"
# include "../Platform/SmbiosFillPatchingValues.h"
2020-02-20 13:53:27 +01:00
2020-10-22 15:55:30 +02:00
# include "../include/OC.h"
2020-09-07 00:19:48 +02:00
2022-07-02 12:08:16 +02:00
2020-02-15 15:51:18 +01:00
# ifndef DEBUG_ALL
2020-11-18 22:49:02 +01:00
# ifdef DEBUG_ERALY_CRASH
# define DEBUG_MAIN 2
# else
# define DEBUG_MAIN 1
# endif
2020-02-15 15:51:18 +01:00
# else
2020-11-18 22:49:02 +01:00
# define DEBUG_MAIN DEBUG_ALL
2020-02-15 15:51:18 +01:00
# endif
# if DEBUG_MAIN == 0
# define DBG(...)
# else
# define DBG(...) DebugLog(DEBUG_MAIN, __VA_ARGS__)
# endif
# ifndef HIBERNATE
# define HIBERNATE 0
# endif
# ifndef CHECK_SMC
# define CHECK_SMC 0
# endif
2020-04-16 11:09:22 +02:00
# define PCAT_RTC_ADDRESS_REGISTER 0x70
# define PCAT_RTC_DATA_REGISTER 0x71
2020-02-15 15:51:18 +01:00
// variables
2021-09-28 15:54:31 +02:00
XBool gGuiIsReady = false ;
XBool gThemeNeedInit = true ;
XBool DoHibernateWake = false ;
2022-07-02 12:08:16 +02:00
UINT32 mCurrentColor ;
2020-02-15 15:51:18 +01:00
2023-06-22 21:50:58 +02:00
extern UINT32 gFakeCPUID ;
2020-02-15 15:51:18 +01:00
2020-06-18 18:08:00 +02:00
EFI_HANDLE AudioDriverHandle ;
2021-03-19 08:41:24 +01:00
XStringW OpenRuntimeEfiName ;
2020-06-18 18:08:00 +02:00
2020-10-03 19:02:31 +02:00
extern void HelpRefit ( void ) ;
extern void AboutRefit ( void ) ;
2020-02-15 15:51:18 +01:00
extern EFI_AUDIO_IO_PROTOCOL * AudioIo ;
2020-08-25 17:35:19 +02:00
extern EFI_DXE_SERVICES * gDS ;
2020-02-20 13:53:27 +01:00
2020-02-15 15:51:18 +01:00
static EFI_STATUS LoadEFIImageList ( IN EFI_DEVICE_PATH * * DevicePaths ,
2020-04-27 11:50:49 +02:00
IN CONST XStringW & ImageTitle ,
2020-02-15 15:51:18 +01:00
OUT UINTN * ErrorInStep ,
OUT EFI_HANDLE * NewImageHandle )
{
EFI_STATUS Status , ReturnStatus ;
EFI_HANDLE ChildImageHandle = 0 ;
UINTN DevicePathIndex ;
2020-04-27 11:50:49 +02:00
DBG ( " Loading %ls " , ImageTitle . wc_str ( ) ) ;
2020-02-15 15:51:18 +01:00
if ( ErrorInStep ! = NULL ) {
* ErrorInStep = 0 ;
}
if ( NewImageHandle ! = NULL ) {
* NewImageHandle = NULL ;
}
// load the image into memory
ReturnStatus = Status = EFI_NOT_FOUND ; // in case the list is empty
for ( DevicePathIndex = 0 ; DevicePaths [ DevicePathIndex ] ! = NULL ; DevicePathIndex + + ) {
2021-09-28 10:28:45 +02:00
ReturnStatus = Status = gBS - > LoadImage ( false , self . getSelfImageHandle ( ) , DevicePaths [ DevicePathIndex ] , NULL , 0 , & ChildImageHandle ) ;
2021-05-04 12:26:54 +02:00
DBG ( " status=%s " , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
if ( ReturnStatus ! = EFI_NOT_FOUND )
break ;
}
2021-05-04 12:26:54 +02:00
XStringW ErrorInfo = SWPrintf ( " while loading %ls " , ImageTitle . wc_str ( ) ) ;
2020-10-03 19:02:31 +02:00
if ( CheckError ( Status , ErrorInfo . wc_str ( ) ) ) {
2020-02-15 15:51:18 +01:00
if ( ErrorInStep ! = NULL )
* ErrorInStep = 1 ;
2021-05-04 12:03:40 +02:00
PauseForKey ( NullXString8 ) ;
2020-02-15 15:51:18 +01:00
goto bailout ;
2021-05-04 12:26:54 +02:00
} else {
DBG ( " \n " ) ;
2021-05-19 19:10:41 +02:00
# ifdef JIEF_DEBUG
2021-05-04 12:26:54 +02:00
DBG ( " ChildImaheHandle=%llx \n " , uintptr_t ( ChildImageHandle ) ) ;
2021-05-19 19:10:41 +02:00
# endif
2020-02-15 15:51:18 +01:00
}
if ( ! EFI_ERROR ( ReturnStatus ) ) { //why unload driver?!
if ( NewImageHandle ! = NULL ) {
* NewImageHandle = ChildImageHandle ;
}
2020-02-23 12:20:22 +01:00
# ifdef JIEF_DEBUG
2020-02-18 07:03:14 +01:00
EFI_LOADED_IMAGE_PROTOCOL * loadedBootImage = NULL ;
if ( ! EFI_ERROR ( Status = gBS - > HandleProtocol ( ChildImageHandle , & gEfiLoadedImageProtocolGuid , ( void * * ) ( & loadedBootImage ) ) ) ) {
2021-05-19 14:28:57 +02:00
DBG ( " %ls : Image base = 0x%llx \n " , ImageTitle . wc_str ( ) , ( uintptr_t ) loadedBootImage - > ImageBase ) ; // Jief : Do not change this, it's used by grep to feed the debugger
2020-02-18 07:03:14 +01:00
} else {
2021-05-19 14:28:57 +02:00
DBG ( " Can't get loaded image protocol \n " ) ;
2020-02-18 07:03:14 +01:00
}
# endif
2020-02-15 15:51:18 +01:00
goto bailout ;
}
// unload the image, we don't care if it works or not...
Status = gBS - > UnloadImage ( ChildImageHandle ) ;
bailout :
return ReturnStatus ;
}
static EFI_STATUS StartEFILoadedImage ( IN EFI_HANDLE ChildImageHandle ,
2021-03-22 19:02:19 +01:00
IN CONST XString8Array & LoadOptions , IN CONST XStringW & LoadOptionsPrefix ,
2020-04-27 11:50:49 +02:00
IN CONST XStringW & ImageTitle ,
2020-02-15 15:51:18 +01:00
OUT UINTN * ErrorInStep )
{
2020-04-11 19:55:47 +02:00
EFI_STATUS Status , ReturnStatus ;
EFI_LOADED_IMAGE_PROTOCOL * ChildLoadedImage ;
CHAR16 ErrorInfo [ 256 ] ;
2023-06-28 21:01:41 +02:00
2020-04-27 21:20:16 +02:00
XStringW loadOptionsW ; // This has to be declared here, so it's not be freed before calling StartImage
2020-02-15 15:51:18 +01:00
2020-03-25 19:32:44 +01:00
// DBG("Starting %ls\n", ImageTitle);
2020-02-15 15:51:18 +01:00
if ( ErrorInStep ! = NULL ) {
* ErrorInStep = 0 ;
}
ReturnStatus = Status = EFI_NOT_FOUND ; // in case no image handle was specified
if ( ChildImageHandle = = NULL ) {
if ( ErrorInStep ! = NULL ) * ErrorInStep = 1 ;
goto bailout ;
}
// set load options
2020-04-05 14:25:39 +02:00
if ( ! LoadOptions . isEmpty ( ) ) {
2020-10-03 19:02:31 +02:00
ReturnStatus = Status = gBS - > HandleProtocol ( ChildImageHandle , & gEfiLoadedImageProtocolGuid , ( void * * ) & ChildLoadedImage ) ;
2020-02-15 15:51:18 +01:00
if ( CheckError ( Status , L " while getting a LoadedImageProtocol handle " ) ) {
if ( ErrorInStep ! = NULL )
* ErrorInStep = 2 ;
goto bailout_unload ;
}
2021-03-22 19:02:19 +01:00
if ( LoadOptionsPrefix . notEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
// NOTE: That last space is also added by the EFI shell and seems to be significant
// when passing options to Apple's boot.efi...
2021-03-22 19:02:19 +01:00
loadOptionsW = SWPrintf ( " %ls %s " , LoadOptionsPrefix . wc_str ( ) , LoadOptions . ConcatAll ( " " _XS8 ) . c_str ( ) ) ;
2020-04-05 14:25:39 +02:00
} else {
2020-08-12 17:15:47 +02:00
loadOptionsW = SWPrintf ( " %s " , LoadOptions . ConcatAll ( " " _XS8 ) . c_str ( ) ) ; // Jief : should we add a space ? Wasn't the case before big refactoring. Yes, a space required.
2020-02-15 15:51:18 +01:00
}
// NOTE: We also include the terminating null in the length for safety.
2020-04-05 14:25:39 +02:00
ChildLoadedImage - > LoadOptionsSize = ( UINT32 ) loadOptionsW . sizeInBytes ( ) + sizeof ( wchar_t ) ;
2020-04-26 15:07:30 +02:00
ChildLoadedImage - > LoadOptions = loadOptionsW . wc_str ( ) ; //will it be deleted after the procedure exit? Yes, if we don't copy loadOptionsW, so it'll be freed at the end of method
2023-06-28 21:01:41 +02:00
2020-04-27 11:50:49 +02:00
DBG ( " start image '%ls' \n " , ImageTitle . s ( ) ) ;
2020-04-11 19:55:47 +02:00
DBG ( " Using load options '%ls' \n " , ( CHAR16 * ) ChildLoadedImage - > LoadOptions ) ;
2020-02-15 15:51:18 +01:00
}
// close open file handles
UninitRefitLib ( ) ;
// turn control over to the image
//
// Before calling the image, enable the Watchdog Timer for
// the 5 Minute period - Slice - NO! For slow driver and slow disk we need more
//
gBS - > SetWatchdogTimer ( 600 , 0x0000 , 0x00 , NULL ) ;
ReturnStatus = Status = gBS - > StartImage ( ChildImageHandle , NULL , NULL ) ;
//
// Clear the Watchdog Timer after the image returns
//
gBS - > SetWatchdogTimer ( 0x0000 , 0x0000 , 0x0000 , NULL ) ;
2020-10-05 22:45:14 +02:00
ReinitRefitLib ( ) ;
2020-02-15 15:51:18 +01:00
// control returns here when the child image calls Exit()
2020-04-27 11:50:49 +02:00
if ( ImageTitle . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
snwprintf ( ErrorInfo , 512 , " returned from %ls " , ImageTitle . s ( ) ) ;
2020-02-15 15:51:18 +01:00
}
if ( CheckError ( Status , ErrorInfo ) ) {
if ( ErrorInStep ! = NULL )
* ErrorInStep = 3 ;
}
if ( ! EFI_ERROR ( ReturnStatus ) ) { //why unload driver?!
goto bailout ;
}
bailout_unload :
// unload the image, we don't care if it works or not...
Status = gBS - > UnloadImage ( ChildImageHandle ) ;
bailout :
return ReturnStatus ;
}
static EFI_STATUS LoadEFIImage ( IN EFI_DEVICE_PATH * DevicePath ,
2020-04-27 11:50:49 +02:00
IN CONST XStringW & ImageTitle ,
2020-02-15 15:51:18 +01:00
OUT UINTN * ErrorInStep ,
OUT EFI_HANDLE * NewImageHandle )
{
EFI_DEVICE_PATH * DevicePaths [ 2 ] ;
# ifdef ENABLE_SECURE_BOOT
// Verify secure boot policy
2021-05-09 16:13:37 +02:00
if ( GlobalConfig . SecureBoot & & GlobalConfig . SecureBootSetupMode ) {
2020-02-15 15:51:18 +01:00
// Only verify if in forced secure boot mode
EFI_STATUS Status = VerifySecureBootImage ( DevicePath ) ;
if ( EFI_ERROR ( Status ) ) {
return Status ;
}
}
# endif // ENABLE_SECURE_BOOT
// Load the image now
DevicePaths [ 0 ] = DevicePath ;
DevicePaths [ 1 ] = NULL ;
return LoadEFIImageList ( DevicePaths , ImageTitle , ErrorInStep , NewImageHandle ) ;
}
static EFI_STATUS StartEFIImage ( IN EFI_DEVICE_PATH * DevicePath ,
2021-03-22 19:02:19 +01:00
IN CONST XString8Array & LoadOptions , IN CONST XStringW & LoadOptionsPrefix ,
2020-04-27 11:50:49 +02:00
IN CONST XStringW & ImageTitle ,
2020-02-15 15:51:18 +01:00
OUT UINTN * ErrorInStep ,
OUT EFI_HANDLE * NewImageHandle )
{
EFI_STATUS Status ;
EFI_HANDLE ChildImageHandle = NULL ;
Status = LoadEFIImage ( DevicePath , ImageTitle , ErrorInStep , & ChildImageHandle ) ;
if ( ! EFI_ERROR ( Status ) ) {
Status = StartEFILoadedImage ( ChildImageHandle , LoadOptions , LoadOptionsPrefix , ImageTitle , ErrorInStep ) ;
}
if ( NewImageHandle ! = NULL ) {
* NewImageHandle = ChildImageHandle ;
}
return Status ;
}
# ifdef DUMP_KERNEL_KEXT_PATCHES
2020-10-03 19:02:31 +02:00
void DumpKernelAndKextPatches ( KERNEL_AND_KEXT_PATCHES * Patches )
2020-02-15 15:51:18 +01:00
{
if ( ! Patches ) {
DBG ( " Kernel and Kext Patches null pointer \n " ) ;
return ;
}
2020-10-11 08:06:50 +02:00
DBG ( " Kernel and Kext Patches at %llx: \n " , ( uintptr_t ) Patches ) ;
2021-04-03 16:42:49 +02:00
DBG ( " \t Allowed: %c \n " , GlobalConfig . KextPatchesAllowed ? ' y ' : ' n ' ) ;
2020-02-15 15:51:18 +01:00
DBG ( " \t Debug: %c \n " , Patches - > KPDebug ? ' y ' : ' n ' ) ;
2020-05-09 10:55:33 +02:00
// DBG("\tKernelCpu: %c\n", Patches->KPKernelCpu ? 'y' : 'n');
2020-02-15 15:51:18 +01:00
DBG ( " \t KernelLapic: %c \n " , Patches - > KPKernelLapic ? ' y ' : ' n ' ) ;
DBG ( " \t KernelXCPM: %c \n " , Patches - > KPKernelXCPM ? ' y ' : ' n ' ) ;
DBG ( " \t KernelPm: %c \n " , Patches - > KPKernelPm ? ' y ' : ' n ' ) ;
DBG ( " \t AppleIntelCPUPM: %c \n " , Patches - > KPAppleIntelCPUPM ? ' y ' : ' n ' ) ;
DBG ( " \t AppleRTC: %c \n " , Patches - > KPAppleRTC ? ' y ' : ' n ' ) ;
// Dell smbios truncate fix
DBG ( " \t DellSMBIOSPatch: %c \n " , Patches - > KPDELLSMBIOS ? ' y ' : ' n ' ) ;
2020-03-25 19:32:44 +01:00
DBG ( " \t FakeCPUID: 0x%X \n " , Patches - > FakeCPUID ) ;
2020-10-11 08:06:50 +02:00
DBG ( " \t ATIController: %s \n " , Patches - > KPATIConnectorsController . isEmpty ( ) ? " (null) " : Patches - > KPATIConnectorsController . c_str ( ) ) ;
DBG ( " \t ATIDataLength: %zu \n " , Patches - > KPATIConnectorsData . size ( ) ) ;
2021-03-25 15:32:56 +01:00
DBG ( " \t %zu Kexts to load \n " , Patches - > ForceKextsToLoad . size ( ) ) ;
if ( Patches - > ForceKextsToLoad . size ( ) ) {
2020-10-11 08:06:50 +02:00
size_t i = 0 ;
2021-03-25 15:32:56 +01:00
for ( ; i < Patches - > ForceKextsToLoad . size ( ) ; + + i ) {
DBG ( " \t KextToLoad[%zu]: %ls \n " , i , Patches - > ForceKextsToLoad [ i ] . wc_str ( ) ) ;
2020-02-15 15:51:18 +01:00
}
}
2020-10-11 08:06:50 +02:00
DBG ( " \t %zu Kexts to patch \n " , Patches - > KextPatches . size ( ) ) ;
if ( Patches - > KextPatches . size ( ) ) {
size_t i = 0 ;
2020-08-12 17:15:47 +02:00
for ( ; i < Patches - > KextPatches . size ( ) ; + + i ) {
2020-02-15 15:51:18 +01:00
if ( Patches - > KextPatches [ i ] . IsPlistPatch ) {
2020-10-11 08:06:50 +02:00
DBG ( " \t KextPatchPlist[%zu]: %zu bytes, %s \n " , i , Patches - > KextPatches [ i ] . Data . size ( ) , Patches - > KextPatches [ i ] . Name . c_str ( ) ) ;
2020-02-15 15:51:18 +01:00
} else {
2020-10-11 08:06:50 +02:00
DBG ( " \t KextPatch[%zu]: %zu bytes, %s \n " , i , Patches - > KextPatches [ i ] . Data . size ( ) , Patches - > KextPatches [ i ] . Name . c_str ( ) ) ;
2020-02-15 15:51:18 +01:00
}
}
}
}
# endif
2020-10-03 19:02:31 +02:00
void LOADER_ENTRY : : FilterKextPatches ( )
2020-02-15 15:51:18 +01:00
{
2021-04-03 16:42:49 +02:00
if ( GlobalConfig . KextPatchesAllowed & & KernelAndKextPatches . KextPatches . size ( ) > 0 ) {
2020-02-15 15:51:18 +01:00
DBG ( " Filtering KextPatches: \n " ) ;
2020-08-12 17:15:47 +02:00
for ( size_t i = 0 ; i < KernelAndKextPatches . KextPatches . size ( ) ; i + + ) {
DBG ( " - [%02zu]: %s :: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s] " ,
2020-02-15 15:51:18 +01:00
i ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . KextPatches [ i ] . Label . c_str ( ) ,
2020-08-11 14:43:53 +02:00
KernelAndKextPatches . KextPatches [ i ] . IsPlistPatch ? " PlistPatch " : " BinPatch " ,
2021-01-31 10:50:23 +01:00
macOSVersion . asString ( ) . c_str ( ) ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . KextPatches [ i ] . MatchOS . notEmpty ( ) ? KernelAndKextPatches . KextPatches [ i ] . MatchOS . c_str ( ) : " All " ,
KernelAndKextPatches . KextPatches [ i ] . MatchBuild . notEmpty ( ) ? KernelAndKextPatches . KextPatches [ i ] . MatchBuild . c_str ( ) : " All "
2020-02-15 15:51:18 +01:00
) ;
2020-10-10 15:31:14 +02:00
if ( ! gSettings . KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue ) {
KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue = false ;
2020-02-15 15:51:18 +01:00
DBG ( " ==> disabled by user \n " ) ;
continue ;
}
2020-10-10 15:31:14 +02:00
KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue = true ;
2020-08-12 17:15:47 +02:00
if ( ( BuildVersion . notEmpty ( ) ) & & ( KernelAndKextPatches . KextPatches [ i ] . MatchBuild . notEmpty ( ) ) ) {
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . KextPatches [ i ] . IsPatchEnabledByBuildNumber ( BuildVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s \n " , KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
continue ;
}
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . KextPatches [ i ] . IsPatchEnabled ( macOSVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s \n " , KernelAndKextPatches . KextPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
}
}
}
2020-10-03 19:02:31 +02:00
void LOADER_ENTRY : : FilterKernelPatches ( )
2020-02-15 15:51:18 +01:00
{
2021-04-03 16:42:49 +02:00
if ( GlobalConfig . KernelPatchesAllowed & & KernelAndKextPatches . KernelPatches . notEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
DBG ( " Filtering KernelPatches: \n " ) ;
2020-08-12 17:15:47 +02:00
for ( size_t i = 0 ; i < KernelAndKextPatches . KernelPatches . size ( ) ; + + i ) {
DBG ( " - [%02zu]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s] " ,
2020-02-15 15:51:18 +01:00
i ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . KernelPatches [ i ] . Label . c_str ( ) ,
2021-01-31 10:50:23 +01:00
macOSVersion . asString ( ) . c_str ( ) ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . KernelPatches [ i ] . MatchOS . notEmpty ( ) ? KernelAndKextPatches . KernelPatches [ i ] . MatchOS . c_str ( ) : " All " ,
2021-12-24 19:22:53 +01:00
KernelAndKextPatches . KernelPatches [ i ] . MatchBuild . notEmpty ( ) ? KernelAndKextPatches . KernelPatches [ i ] . MatchBuild . c_str ( ) : " All "
2020-02-15 15:51:18 +01:00
) ;
2020-10-10 15:31:14 +02:00
if ( ! gSettings . KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue ) {
KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue = false ;
2020-02-15 15:51:18 +01:00
DBG ( " ==> disabled by user \n " ) ;
continue ;
}
2020-10-10 15:31:14 +02:00
KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue = true ;
2020-08-12 17:15:47 +02:00
if ( ( BuildVersion . notEmpty ( ) ) & & ( KernelAndKextPatches . KernelPatches [ i ] . MatchBuild . notEmpty ( ) ) ) {
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . KernelPatches [ i ] . IsPatchEnabledByBuildNumber ( BuildVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s by build \n " , KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
continue ;
}
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . KernelPatches [ i ] . IsPatchEnabled ( macOSVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s by OS \n " , KernelAndKextPatches . KernelPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
}
}
}
2020-10-03 19:02:31 +02:00
void LOADER_ENTRY : : FilterBootPatches ( )
2020-02-15 15:51:18 +01:00
{
2020-08-12 17:15:47 +02:00
if ( KernelAndKextPatches . BootPatches . notEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
DBG ( " Filtering BootPatches: \n " ) ;
2020-08-12 17:15:47 +02:00
for ( size_t i = 0 ; i < KernelAndKextPatches . BootPatches . size ( ) ; + + i ) {
DBG ( " - [%02zu]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s] " ,
2020-02-15 15:51:18 +01:00
i ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . BootPatches [ i ] . Label . c_str ( ) ,
2021-01-31 10:50:23 +01:00
macOSVersion . asString ( ) . c_str ( ) ,
2020-08-12 17:15:47 +02:00
KernelAndKextPatches . BootPatches [ i ] . MatchOS . notEmpty ( ) ? KernelAndKextPatches . BootPatches [ i ] . MatchOS . c_str ( ) : " All " ,
2021-12-24 19:22:53 +01:00
KernelAndKextPatches . BootPatches [ i ] . MatchBuild . notEmpty ( ) ? KernelAndKextPatches . BootPatches [ i ] . MatchBuild . c_str ( ) : " All "
2020-02-15 15:51:18 +01:00
) ;
2020-10-10 15:31:14 +02:00
if ( ! gSettings . KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue ) {
2020-02-15 15:51:18 +01:00
DBG ( " ==> disabled by user \n " ) ;
continue ;
}
2020-10-10 15:31:14 +02:00
KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue = true ;
2020-08-12 17:15:47 +02:00
if ( ( BuildVersion . notEmpty ( ) ) & & ( KernelAndKextPatches . BootPatches [ i ] . MatchBuild . notEmpty ( ) ) ) {
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . BootPatches [ i ] . IsPatchEnabledByBuildNumber ( BuildVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s by build \n " , KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
continue ;
}
2021-02-06 18:16:46 +01:00
KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue = KernelAndKextPatches . BootPatches [ i ] . IsPatchEnabled ( macOSVersion ) ;
2020-08-11 14:43:53 +02:00
DBG ( " ==> %s by OS \n " , KernelAndKextPatches . BootPatches [ i ] . MenuItem . BValue ? " allowed " : " not allowed " ) ;
2020-02-15 15:51:18 +01:00
}
}
}
//
// Null ConOut OutputString() implementation - for blocking
// text output from boot.efi when booting in graphics mode
//
EFI_STATUS EFIAPI
2021-02-10 13:32:07 +01:00
NullConOutOutputString ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * , IN CONST CHAR16 * ) {
2020-02-15 15:51:18 +01:00
return EFI_SUCCESS ;
}
2020-10-03 19:02:31 +02:00
void CheckEmptyFB ( )
2020-02-18 19:49:54 +01:00
{
2021-09-28 10:28:45 +02:00
XBool EmptyFB = ( GlobalConfig . IgPlatform = = 0x00050000 ) | |
2021-04-12 14:11:01 +02:00
( GlobalConfig . IgPlatform = = 0x01620007 ) | |
( GlobalConfig . IgPlatform = = 0x04120004 ) | |
( GlobalConfig . IgPlatform = = 0x19120001 ) | |
( GlobalConfig . IgPlatform = = 0x59120003 ) | |
2021-11-26 20:26:29 +01:00
( GlobalConfig . IgPlatform = = 0x9BC80003 ) | |
2021-04-12 14:11:01 +02:00
( GlobalConfig . IgPlatform = = 0x3E910003 ) ;
2020-02-18 19:49:54 +01:00
if ( EmptyFB ) {
2021-04-03 16:42:49 +02:00
gSettings . Smbios . gPlatformFeature | = PT_FEATURE_HAS_HEADLESS_GPU ;
2020-02-18 19:49:54 +01:00
} else {
2021-04-03 16:42:49 +02:00
gSettings . Smbios . gPlatformFeature & = ~ PT_FEATURE_HAS_HEADLESS_GPU ;
2020-02-18 19:49:54 +01:00
}
}
2020-09-30 20:56:55 +02:00
size_t setKextAtPos ( XObjArray < SIDELOAD_KEXT > * kextArrayPtr , const XString8 & kextName , size_t pos )
2020-02-15 15:51:18 +01:00
{
2020-09-30 20:56:55 +02:00
XObjArray < SIDELOAD_KEXT > & kextArray = * kextArrayPtr ;
for ( size_t kextIdx = 0 ; kextIdx < kextArray . size ( ) ; kextIdx + + ) {
if ( kextArray [ kextIdx ] . FileName . contains ( kextName ) ) {
2021-11-26 20:26:29 +01:00
# ifdef JIEF_DEBUG
2020-09-30 20:56:55 +02:00
if ( pos > = kextArray . size ( ) ) panic ( " pos >= kextArray.size() " ) ;
2021-02-21 14:49:09 +01:00
# else
//it is impossible
# endif
2020-09-30 20:56:55 +02:00
if ( pos = = kextIdx ) return pos + 1 ;
if ( pos > kextIdx ) pos - = 1 ;
SIDELOAD_KEXT * kextToMove = & kextArray [ kextIdx ] ;
kextArray . RemoveWithoutFreeingAtIndex ( kextIdx ) ;
kextArray . InsertRef ( kextToMove , pos , false ) ;
return pos + 1 ;
}
}
return pos ;
}
2020-10-11 08:06:50 +02:00
static XStringW getDriversPath ( )
{
# if defined(MDE_CPU_X64)
if ( gFirmwareClover ) {
if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ BIOS " ) ) {
return L " drivers \\ BIOS " _XSW ;
} else {
2021-02-21 14:49:09 +01:00
return L " drivers64 " _XSW ; //backward compatibility
2020-10-11 08:06:50 +02:00
}
2023-06-28 21:01:41 +02:00
} else if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ 5142 " ) ) { // can be excluded as obsolete
2021-11-01 19:26:41 +01:00
return L " drivers \\ 5142 " _XSW ;
} else if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ UEFI " ) ) {
return L " drivers \\ UEFI " _XSW ;
2020-10-11 08:06:50 +02:00
} else {
2021-11-01 19:26:41 +01:00
return L " drivers64UEFI " _XSW ;
2020-10-11 08:06:50 +02:00
}
# else
return L " drivers32 " _XSW ;
# endif
}
2021-09-23 12:36:41 +02:00
# ifdef JIEF_DEBUG
2020-09-30 20:56:55 +02:00
void debugStartImageWithOC ( )
{
2021-04-15 20:22:14 +02:00
MsgLog ( " debugStartImageWithOC \n " ) ;
2020-09-30 20:56:55 +02:00
UINT64 CPUFrequencyFromART ;
InternalCalculateARTFrequencyIntel ( & CPUFrequencyFromART , NULL , 1 ) ;
EFI_LOADED_IMAGE * OcLoadedImage ;
2020-10-03 19:02:31 +02:00
EFI_STATUS Status = gBS - > HandleProtocol ( gImageHandle , & gEfiLoadedImageProtocolGuid , ( void * * ) & OcLoadedImage ) ;
2021-09-23 12:36:41 +02:00
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * FileSystem = OcLocateFileSystem ( OcLoadedImage - > DeviceHandle , OcLoadedImage - > FilePath ) ;
Status = OcStorageInitFromFs ( & mOpenCoreStorage , FileSystem , NULL , NULL , self . getCloverDirFullPath ( ) . wc_str ( ) , NULL ) ;
2020-09-30 20:56:55 +02:00
Status = ClOcReadConfigurationFile ( & mOpenCoreStorage , L " config-oc.plist " , & mOpenCoreConfiguration ) ;
if ( EFI_ERROR ( Status ) ) panic ( " ClOcReadConfigurationFile " ) ;
mOpenCoreConfiguration . Misc . Debug . Target = 0 ;
2021-09-23 12:36:41 +02:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Misc . Boot . PickerMode , " Builtin " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Misc . Security . DmgLoading , " Any " ) ;
mOpenCoreConfiguration . Uefi . Quirks . IgnoreInvalidFlexRatio = 0 ;
2022-10-05 20:04:32 +02:00
2021-09-23 12:36:41 +02:00
mOpenCoreConfiguration . Uefi . Quirks . TscSyncTimeout = 0 ;
2020-09-30 20:56:55 +02:00
OcMain ( & mOpenCoreStorage , NULL ) ;
XStringW devicePathToLookFor ;
// devicePathToLookFor.takeValueFrom("PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0x0,0x0)/HD(4,GPT,CA224585-830E-4274-5826-1ACB6DA08A4E,0x299F000,0x4AE6310)/VenMedia(BE74FCF7-0B7C-49F3-9147-01F4042E6842,1ABE434C8D0357398516CFDF0A9DD7EF)"); // Jief High Sierra DevicePath
devicePathToLookFor . takeValueFrom ( " PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0x0,0x0)/HD(2,GPT,D8C7DA82-1E4C-4579-BA7C-6737A5D43464,0x64028,0x1BF08E8) " ) ; // Jief Big Sur Install device path
UINTN HandleCount = 0 ;
EFI_HANDLE * Handles = NULL ;
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiSimpleFileSystemProtocolGuid , NULL , & HandleCount , & Handles ) ;
UINTN HandleIndex = 0 ;
for ( HandleIndex = 0 ; HandleIndex < HandleCount ; HandleIndex + + ) {
EFI_DEVICE_PATH_PROTOCOL * DevicePath = DevicePathFromHandle ( Handles [ HandleIndex ] ) ;
2021-09-28 10:28:45 +02:00
CHAR16 * UnicodeDevicePath = ConvertDevicePathToText ( DevicePath , false , false ) ;
2020-10-14 18:08:32 +02:00
MsgLog ( " debugStartImageWithOC : path %ls \n " , UnicodeDevicePath ) ;
2020-09-30 20:56:55 +02:00
if ( StrCmp ( devicePathToLookFor . wc_str ( ) , UnicodeDevicePath ) = = 0 ) break ;
}
if ( HandleIndex < HandleCount )
2020-10-14 18:08:32 +02:00
{
2020-09-30 20:56:55 +02:00
EFI_DEVICE_PATH_PROTOCOL * jfkImagePath = FileDevicePath ( Handles [ HandleIndex ] , L " \\ System \\ Library \\ CoreServices \\ boot.efi " ) ;
2021-09-28 10:28:45 +02:00
CHAR16 * UnicodeDevicePath = ConvertDevicePathToText ( jfkImagePath , false , false ) ; ( void ) UnicodeDevicePath ;
2020-09-30 20:56:55 +02:00
EFI_HANDLE EntryHandle = NULL ;
// point to InternalEfiLoadImage from OC
Status = gBS - > LoadImage (
2021-09-28 10:28:45 +02:00
false ,
2020-09-30 20:56:55 +02:00
gImageHandle ,
jfkImagePath ,
NULL ,
0 ,
& EntryHandle
) ;
if ( EFI_ERROR ( Status ) ) return ; // TODO message ?
EFI_LOADED_IMAGE * LoadedImage = NULL ;
EFI_STATUS OptionalStatus = gBS - > HandleProtocol (
EntryHandle ,
& gEfiLoadedImageProtocolGuid ,
2020-10-03 19:02:31 +02:00
( void * * ) & LoadedImage
2020-09-30 20:56:55 +02:00
) ;
if ( EFI_ERROR ( OptionalStatus ) ) return ; // TODO message ?
// XStringW LoadOptionsAsXStringW = SWPrintf("%s ", LoadOptions.ConcatAll(" "_XS8).c_str());
XStringW LoadOptionsAsXStringW = SWPrintf ( " boot.efi -v -no_compat_check slide=0 kext-dev-mode=1 keepsyms=1 -wegdbg igfxgl=1 bpr_probedelay=200 bpr_initialdelay=400 bpr_postresetdelay=400 " ) ;
LoadedImage - > LoadOptions = ( void * ) LoadOptionsAsXStringW . wc_str ( ) ;
LoadedImage - > LoadOptionsSize = ( UINT32 ) LoadOptionsAsXStringW . sizeInBytesIncludingTerminator ( ) ;
// point to OcStartImage from OC
Status = gBS - > StartImage ( EntryHandle , 0 , NULL ) ;
if ( EFI_ERROR ( Status ) ) return ; // TODO message ?
} else {
MsgLog ( " debugStartImageWithOC : not found \n " ) ;
}
2020-10-12 13:48:50 +02:00
}
2021-02-21 14:49:09 +01:00
# endif
2021-05-18 05:14:56 +02:00
2020-10-12 13:48:50 +02:00
void LOADER_ENTRY : : DelegateKernelPatches ( )
{
2021-03-25 15:32:56 +01:00
XObjArray < ABSTRACT_KEXT_OR_KERNEL_PATCH > selectedPathArray ;
2020-10-12 13:48:50 +02:00
for ( size_t kextPatchIdx = 0 ; kextPatchIdx < KernelAndKextPatches . KextPatches . size ( ) ; kextPatchIdx + + )
{
if ( KernelAndKextPatches . KextPatches [ kextPatchIdx ] . MenuItem . BValue )
selectedPathArray . AddReference ( & KernelAndKextPatches . KextPatches [ kextPatchIdx ] , false ) ;
}
for ( size_t kernelPatchIdx = 0 ; kernelPatchIdx < KernelAndKextPatches . KernelPatches . size ( ) ; kernelPatchIdx + + )
{
if ( KernelAndKextPatches . KernelPatches [ kernelPatchIdx ] . MenuItem . BValue )
selectedPathArray . AddReference ( & KernelAndKextPatches . KernelPatches [ kernelPatchIdx ] , false ) ;
}
mOpenCoreConfiguration . Kernel . Patch . Count = ( UINT32 ) selectedPathArray . size ( ) ;
mOpenCoreConfiguration . Kernel . Patch . AllocCount = mOpenCoreConfiguration . Kernel . Patch . Count ;
mOpenCoreConfiguration . Kernel . Patch . ValueSize = sizeof ( __typeof_am__ ( * * mOpenCoreConfiguration . Kernel . Patch . Values ) ) ;
mOpenCoreConfiguration . Kernel . Patch . Values = ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Patch . Values ) * ) malloc ( mOpenCoreConfiguration . Kernel . Patch . AllocCount * sizeof ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Patch . Values ) ) ) ;
memset ( mOpenCoreConfiguration . Kernel . Patch . Values , 0 , mOpenCoreConfiguration . Kernel . Patch . AllocCount * sizeof ( * mOpenCoreConfiguration . Kernel . Patch . Values ) ) ;
2021-05-18 05:14:56 +02:00
2023-06-22 21:50:58 +02:00
UINT32 FakeCPUID = gSettings . Smbios . SFakeCPU ;
if ( FakeCPUID ! = 0 ) gFakeCPUID = FakeCPUID ;
DBG ( " Set FakeCPUID: 0x%X \n " , gFakeCPUID ) ;
2023-06-28 21:01:41 +02:00
2021-05-19 19:10:41 +02:00
memset ( mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Data , 0 , sizeof ( mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Data ) ) ;
memset ( mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Mask , 0 , sizeof ( mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Mask ) ) ;
2023-06-22 21:50:58 +02:00
mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Data [ 0 ] = gFakeCPUID ;
2021-05-18 05:14:56 +02:00
mOpenCoreConfiguration . Kernel . Emulate . Cpuid1Mask [ 0 ] = 0xFFFFFFFF ;
2020-11-18 22:49:02 +01:00
2020-10-12 13:48:50 +02:00
for ( size_t kextPatchIdx = 0 ; kextPatchIdx < selectedPathArray . size ( ) ; kextPatchIdx + + )
{
2021-03-25 15:32:56 +01:00
const ABSTRACT_KEXT_OR_KERNEL_PATCH & kextPatch = selectedPathArray [ kextPatchIdx ] ; //as well as kernel patches
2021-04-11 07:18:52 +02:00
DBG ( " Bridge %s patch to OC : %s \n " , kextPatch . getName ( ) . c_str ( ) , kextPatch . Label . c_str ( ) ) ;
2020-10-12 13:48:50 +02:00
mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] = ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Patch . Values ) ) AllocateZeroPool ( mOpenCoreConfiguration . Kernel . Patch . ValueSize ) ; // sizeof(OC_KERNEL_ADD_ENTRY) == 680
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Arch , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Scheme . KernelArch ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Base , kextPatch . ProcedureName . c_str ( ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Comment , kextPatch . Label . c_str ( ) ) ;
mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Count = ( UINT32 ) kextPatch . Count ;
mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Enabled = 1 ;
2021-09-25 12:25:02 +02:00
OC_DATA_ASSIGN_N ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Find , kextPatch . Find . data ( ) , kextPatch . Find . size ( ) ) ;
2021-04-11 07:18:52 +02:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Identifier , kextPatch . getName ( ) . c_str ( ) ) ;
2020-10-12 13:48:50 +02:00
mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Limit = ( UINT32 ) kextPatch . SearchLen ;
2021-09-25 12:25:02 +02:00
OC_DATA_ASSIGN_N ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Mask , kextPatch . MaskFind . data ( ) , kextPatch . MaskFind . size ( ) ) ;
2020-10-12 13:48:50 +02:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > MaxKernel , " " ) ; // it has been filtered, so we don't need to set Min and MaxKernel
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > MinKernel , " " ) ;
2021-09-25 12:25:02 +02:00
OC_DATA_ASSIGN_N ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Replace , kextPatch . Replace . data ( ) , kextPatch . Replace . size ( ) ) ;
OC_DATA_ASSIGN_N ( mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > ReplaceMask , kextPatch . MaskReplace . data ( ) , kextPatch . MaskReplace . size ( ) ) ;
2020-10-12 13:48:50 +02:00
mOpenCoreConfiguration . Kernel . Patch . Values [ kextPatchIdx ] - > Skip = ( UINT32 ) kextPatch . Skip ;
2020-10-23 20:52:01 +02:00
# ifdef JIEF_DEBUG
if ( kextPatch . Label = = " algrey - cpuid_set_info - ryzen cores and logicals count - part 3 - 10.14 " _XS8 ) {
DEBUG ( ( DEBUG_INFO , " " ) ) ;
}
# endif
2020-09-07 00:19:48 +02:00
}
2020-10-12 13:48:50 +02:00
}
2020-09-07 00:19:48 +02:00
2020-10-03 19:02:31 +02:00
void LOADER_ENTRY : : StartLoader ( )
2020-09-30 20:56:55 +02:00
{
2020-02-15 15:51:18 +01:00
EFI_STATUS Status ;
EFI_TEXT_STRING ConOutOutputString = 0 ;
EFI_HANDLE ImageHandle = NULL ;
EFI_LOADED_IMAGE * LoadedImage = NULL ;
2022-03-09 20:34:49 +01:00
CONST CHAR8 * InstallerVersion ;
2020-03-10 15:05:39 +01:00
NSVGfont * font ; // , *nextFont;
2020-02-15 15:51:18 +01:00
DbgHeader ( " StartLoader " ) ;
2020-09-30 20:56:55 +02:00
2020-10-22 15:55:30 +02:00
DBG ( " Starting %ls \n " , FileDevicePathToXStringW ( DevicePath ) . wc_str ( ) ) ;
2020-08-09 17:55:30 +02:00
if ( Settings . notEmpty ( ) ) {
DBG ( " Settings: %ls \n " , Settings . wc_str ( ) ) ;
2021-04-28 20:30:34 +02:00
Status = gConf . ReLoadConfig ( Settings ) ;
2020-02-15 15:51:18 +01:00
if ( ! EFI_ERROR ( Status ) ) {
2020-08-09 17:55:30 +02:00
DBG ( " - found custom settings for this entry: %ls \n " , Settings . wc_str ( ) ) ;
2020-02-15 15:51:18 +01:00
} else {
2020-08-25 17:35:19 +02:00
DBG ( " - [!] LoadUserSettings failed: %s \n " , efiStrError ( Status ) ) ;
2021-04-28 20:30:34 +02:00
/* we are not sure of the state of gSettings here... try to boot anyway */
2020-02-15 15:51:18 +01:00
}
}
2021-02-06 18:16:46 +01:00
DBG ( " Finally: ExternalClock=%lluMHz BusSpeed=%llukHz CPUFreq=%uMHz " ,
DivU64x32 ( gCPUStructure . ExternalClock + Kilo - 1 , Kilo ) ,
DivU64x32 ( gCPUStructure . FSBFrequency + Kilo - 1 , Kilo ) ,
2020-02-15 15:51:18 +01:00
gCPUStructure . MaxSpeed ) ;
2021-03-19 16:35:01 +01:00
if ( gSettings . CPU . QPI ) {
DBG ( " QPI: hw.busfrequency=%lluHz \n " , MultU64x32 ( gSettings . CPU . QPI , Mega ) ) ;
2020-02-15 15:51:18 +01:00
} else {
// to match the value of hw.busfrequency in the terminal
2021-02-06 18:16:46 +01:00
DBG ( " PIS: hw.busfrequency=%lluHz \n " , MultU64x32 ( LShiftU64 ( DivU64x32 ( gCPUStructure . ExternalClock + Kilo - 1 , Kilo ) , 2 ) , Mega ) ) ;
2020-02-15 15:51:18 +01:00
}
//Free memory
2021-09-27 09:05:11 +02:00
ConfigsList . setEmpty ( ) ;
2021-09-27 09:18:52 +02:00
DsdtsList . setEmpty ( ) ;
2023-06-16 23:44:39 +02:00
2020-03-03 21:44:07 +01:00
OptionMenu . FreeMenu ( ) ;
2020-02-15 15:51:18 +01:00
//there is a place to free memory
// GuiAnime
// mainParser
// BuiltinIcons
// OSIcons
2020-03-10 14:00:02 +01:00
NSVGfontChain * fontChain = fontsDB ;
while ( fontChain ) {
font = fontChain - > font ;
2020-03-13 09:44:45 +01:00
NSVGfontChain * nextChain = fontChain - > next ;
2020-03-10 14:00:02 +01:00
if ( font ) {
nsvg__deleteFont ( font ) ;
fontChain - > font = NULL ;
}
2020-03-13 09:44:45 +01:00
FreePool ( fontChain ) ;
2020-03-13 13:13:08 +01:00
fontChain = nextChain ;
2020-02-15 15:51:18 +01:00
}
2020-03-13 13:13:08 +01:00
fontsDB = NULL ;
2020-09-30 20:56:55 +02:00
if ( OSTYPE_IS_OSX ( LoaderType ) | | OSTYPE_IS_OSX_RECOVERY ( LoaderType ) | | OSTYPE_IS_OSX_INSTALLER ( LoaderType ) ) {
2021-01-22 09:35:57 +01:00
// if OC is NOT initialized with OcMain, we need the following
// OcConfigureLogProtocol (
// 9,
// 0,
// 2151678018,
// 2147483648,
// OPEN_CORE_LOG_PREFIX_PATH,
// mOpenCoreStorage.FileSystem
// );
// DEBUG ((DEBUG_INFO, "OC: Log initialized...\n"));
// OcAppleDebugLogInstallProtocol(0);
2020-02-15 15:51:18 +01:00
2023-06-28 21:01:41 +02:00
DBG ( " Beginning OC \n " ) ;
2020-11-05 07:29:56 +01:00
2021-01-22 09:35:57 +01:00
EFI_LOADED_IMAGE * OcLoadedImage ;
Status = gBS - > HandleProtocol ( gImageHandle , & gEfiLoadedImageProtocolGuid , ( VOID * * ) & OcLoadedImage ) ;
2021-09-23 12:36:41 +02:00
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * FileSystem = OcLocateFileSystem ( OcLoadedImage - > DeviceHandle , OcLoadedImage - > FilePath ) ;
Status = OcStorageInitFromFs ( & mOpenCoreStorage , FileSystem , NULL , NULL , self . getCloverDirFullPath ( ) . wc_str ( ) , NULL ) ;
2020-02-15 15:51:18 +01:00
2021-01-22 09:35:57 +01:00
/*
* Define READ_FROM_OC to have mOpenCoreConfiguration initialized from config - oc . plist
* The boot should work .
* Next , comment out the next lines one by one . Once the boot failed , we got the section that
* holds the setting that makes a difference .
*/
//#define USE_OC_SECTION_Acpi
//#define USE_OC_SECTION_Booter
//#define USE_OC_SECTION_DeviceProperties
//#define USE_OC_SECTION_Kernel
//#define USE_OC_SECTION_Misc
//#define USE_OC_SECTION_Nvram
//#define USE_OC_SECTION_PlatformInfo
//#define USE_OC_SECTION_Uefi
2020-02-15 15:51:18 +01:00
2021-01-22 09:35:57 +01:00
# if !defined(USE_OC_SECTION_Acpi) && !defined(USE_OC_SECTION_Booter) && !defined(USE_OC_SECTION_DeviceProperties) && !defined(USE_OC_SECTION_Kernel) && !defined(USE_OC_SECTION_Misc) && \
! defined ( USE_OC_SECTION_Nvram ) & & ! defined ( USE_OC_SECTION_PlatformInfo ) & & ! defined ( USE_OC_SECTION_Uefi )
2020-02-15 15:51:18 +01:00
2021-03-19 08:41:24 +01:00
memset ( & mOpenCoreConfiguration , 0 , sizeof ( mOpenCoreConfiguration ) ) ;
2023-06-28 21:01:41 +02:00
// DBG("config-oc.plist isn't used at all\n");
2020-02-15 15:51:18 +01:00
2020-09-30 20:56:55 +02:00
# else
2021-01-22 09:35:57 +01:00
Status = ClOcReadConfigurationFile ( & mOpenCoreStorage , L " config-oc.plist " , & mOpenCoreConfiguration ) ;
if ( EFI_ERROR ( Status ) ) panic ( " ClOcReadConfigurationFile " ) ;
# ifndef USE_OC_SECTION_Acpi
memset ( & mOpenCoreConfiguration . Acpi , 0 , sizeof ( mOpenCoreConfiguration . Acpi ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Acpi \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Acpi \n " ) ;
# endif
# ifndef USE_OC_SECTION_Booter
memset ( & mOpenCoreConfiguration . Booter , 0 , sizeof ( mOpenCoreConfiguration . Booter ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Booter \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Booter \n " ) ;
# endif
# ifndef USE_OC_SECTION_DeviceProperties
memset ( & mOpenCoreConfiguration . DeviceProperties , 0 , sizeof ( mOpenCoreConfiguration . DeviceProperties ) ) ;
DBG ( " Erase mOpenCoreConfiguration.DeviceProperties \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.DeviceProperties \n " ) ;
# endif
# ifndef USE_OC_SECTION_Kernel
memset ( & mOpenCoreConfiguration . Kernel , 0 , sizeof ( mOpenCoreConfiguration . Kernel ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Kernel \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Kernel \n " ) ;
for ( size_t i = 0 ; i < mOpenCoreConfiguration . Kernel . Add . Count ; i + + ) {
OC_KERNEL_ADD_ENTRY * entry = mOpenCoreConfiguration . Kernel . Add . Values [ i ] ;
OC_STRING_ASSIGN ( entry - > BundlePath , S8Printf ( " Kexts \\ %s " , OC_BLOB_GET ( & entry - > BundlePath ) ) . c_str ( ) ) ;
}
2021-09-25 12:17:25 +02:00
// DBG("mOpenCoreConfiguration.Kernel.Add.Count=%d\n", mOpenCoreConfiguration.Kernel.Add.Count);
// for ( size_t i = 0 ; i < mOpenCoreConfiguration.Kernel.Add.Count ; i++ )
// {
// DBG("mOpenCoreConfiguration.Kernel.Add.Values[%zd]->Identifier=%s\n", i, OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[i]->Identifier));
// DBG("mOpenCoreConfiguration.Kernel.Add.Values[%zd]->BundlePath=%s\n", i, OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[i]->BundlePath));
// DBG("mOpenCoreConfiguration.Kernel.Add.Values[%zd]->PlistPath=%s\n", i, OC_BLOB_GET(&mOpenCoreConfiguration.Kernel.Add.Values[i]->PlistPath));
// }
2021-01-22 09:35:57 +01:00
# endif
# ifndef USE_OC_SECTION_Misc
memset ( & mOpenCoreConfiguration . Misc , 0 , sizeof ( mOpenCoreConfiguration . Misc ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Misc \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Misc \n " ) ;
# endif
# ifndef USE_OC_SECTION_Nvram
memset ( & mOpenCoreConfiguration . Nvram , 0 , sizeof ( mOpenCoreConfiguration . Nvram ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Nvram \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Nvram \n " ) ;
# endif
# ifndef USE_OC_SECTION_PlatformInfo
memset ( & mOpenCoreConfiguration . PlatformInfo , 0 , sizeof ( mOpenCoreConfiguration . PlatformInfo ) ) ;
DBG ( " Erase mOpenCoreConfiguration.PlatformInfo \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.PlatformInfo \n " ) ;
# endif
# ifndef USE_OC_SECTION_Uefi
memset ( & mOpenCoreConfiguration . Uefi , 0 , sizeof ( mOpenCoreConfiguration . Uefi ) ) ;
DBG ( " Erase mOpenCoreConfiguration.Uefi \n " ) ;
# else
DBG ( " Keep mOpenCoreConfiguration.Uefi \n " ) ;
// memset(&mOpenCoreConfiguration.Uefi.Apfs, 0, sizeof(mOpenCoreConfiguration.Uefi.Apfs));
// memset(&mOpenCoreConfiguration.Uefi.Audio, 0, sizeof(mOpenCoreConfiguration.Uefi.Audio));
// memset(&mOpenCoreConfiguration.Uefi.ConnectDrivers, 0, sizeof(mOpenCoreConfiguration.Uefi.ConnectDrivers));
// memset(&mOpenCoreConfiguration.Uefi.Drivers, 0, sizeof(mOpenCoreConfiguration.Uefi.Drivers));
// memset(&mOpenCoreConfiguration.Uefi.Input, 0, sizeof(mOpenCoreConfiguration.Uefi.Input));
// memset(&mOpenCoreConfiguration.Uefi.Output, 0, sizeof(mOpenCoreConfiguration.Uefi.Output));
// memset(&mOpenCoreConfiguration.Uefi.ProtocolOverrides, 0, sizeof(mOpenCoreConfiguration.Uefi.ProtocolOverrides));
// memset(&mOpenCoreConfiguration.Uefi.Quirks, 0, sizeof(mOpenCoreConfiguration.Uefi.Quirks));
// memset(&mOpenCoreConfiguration.Uefi.ReservedMemory, 0, sizeof(mOpenCoreConfiguration.Uefi.ReservedMemory)); // doesn't matter
# endif
2020-09-30 20:56:55 +02:00
# endif
2021-01-22 09:35:57 +01:00
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DebugLog ) {
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Misc . Debug . AppleDebug = true ;
mOpenCoreConfiguration . Misc . Debug . ApplePanic = true ;
2023-06-28 21:01:41 +02:00
2021-01-22 09:35:57 +01:00
# ifndef LESS_DEBUG
mOpenCoreConfiguration . Misc . Debug . DisplayLevel = 0x80400042 ;
2020-09-30 20:56:55 +02:00
# else
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Misc . Debug . DisplayLevel = 0x80000042 ;
2020-09-30 20:56:55 +02:00
# endif
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Misc . Debug . Target = 0x41 ;
2023-06-28 21:01:41 +02:00
} else {
2021-01-22 09:35:57 +01:00
# ifdef JIEF_DEBUG
egSetGraphicsModeEnabled ( false ) ;
mOpenCoreConfiguration . Misc . Debug . ApplePanic = true ;
mOpenCoreConfiguration . Misc . Debug . DisplayLevel = 0x80000042 ;
mOpenCoreConfiguration . Misc . Debug . Target = 0x3 ;
2020-09-30 20:56:55 +02:00
# endif
2020-11-05 07:29:56 +01:00
}
2020-02-15 15:51:18 +01:00
2021-04-17 13:32:32 +02:00
# ifndef USE_OC_SECTION_Misc
2021-01-22 09:35:57 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Misc . Security . SecureBootModel , " Disabled " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Misc . Security . Vault , " Optional " ) ;
2021-04-17 13:32:32 +02:00
# endif
# ifdef USE_OC_SECTION_Nvram
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Nvram . WriteFlash = true ;
2020-10-11 08:06:50 +02:00
# endif
2021-11-11 19:58:28 +01:00
# ifndef USE_OC_SECTION_Uefi
mOpenCoreConfiguration . Uefi . Quirks . ForceOcWriteFlash = gSettings . Quirks . OcBooterQuirks . ForceOcWriteFlash ;
# endif
2020-02-15 15:51:18 +01:00
2021-01-22 09:35:57 +01:00
# ifndef USE_OC_SECTION_Booter
2020-02-15 15:51:18 +01:00
2021-03-28 22:13:43 +02:00
mOpenCoreConfiguration . Booter . MmioWhitelist . Count = ( UINT32 ) gSettings . Quirks . mmioWhiteListArray . size ( ) ;
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Booter . MmioWhitelist . AllocCount = mOpenCoreConfiguration . Booter . MmioWhitelist . Count ;
mOpenCoreConfiguration . Booter . MmioWhitelist . ValueSize = sizeof ( __typeof_am__ ( * * mOpenCoreConfiguration . Booter . MmioWhitelist . Values ) ) ; // sizeof(OC_KERNEL_ADD_ENTRY) == 680
if ( mOpenCoreConfiguration . Booter . MmioWhitelist . Count > 0 ) {
2023-06-28 21:01:41 +02:00
mOpenCoreConfiguration . Booter . MmioWhitelist . Values = ( OC_BOOTER_WL_ENTRY * * ) AllocatePool ( mOpenCoreConfiguration . Booter . MmioWhitelist . AllocCount * sizeof ( * mOpenCoreConfiguration . Booter . MmioWhitelist . Values ) ) ; // sizeof(OC_KERNEL_ADD_ENTRY) == 680
} else {
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Booter . MmioWhitelist . Values = NULL ;
}
2021-03-28 22:13:43 +02:00
for ( size_t idx = 0 ; idx < gSettings . Quirks . mmioWhiteListArray . size ( ) ; idx + + ) {
const SETTINGS_DATA : : QuirksClass : : MMIOWhiteList & entry = gSettings . Quirks . mmioWhiteListArray [ idx ] ;
2021-01-22 09:35:57 +01:00
DBG ( " Bridge mmioWhiteList[%zu] to OC : comment=%s \n " , idx , entry . comment . c_str ( ) ) ;
mOpenCoreConfiguration . Booter . MmioWhitelist . Values [ idx ] = ( __typeof_am__ ( * mOpenCoreConfiguration . Booter . MmioWhitelist . Values ) ) AllocatePool ( mOpenCoreConfiguration . Booter . MmioWhitelist . ValueSize ) ;
mOpenCoreConfiguration . Booter . MmioWhitelist . Values [ idx ] - > Address = entry . address ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Booter . MmioWhitelist . Values [ idx ] - > Comment , entry . comment . c_str ( ) ) ;
mOpenCoreConfiguration . Booter . MmioWhitelist . Values [ idx ] - > Enabled = entry . enabled ;
}
2020-02-15 15:51:18 +01:00
2021-04-11 07:18:52 +02:00
// It's possible to memcpy the whole struct instead of assigning individual member. But that would be relying on internel C++ binary structure,
// and worse, if a field is added by OC, everything could be shifted.
memset ( & mOpenCoreConfiguration . Booter . Quirks , 0 , sizeof ( mOpenCoreConfiguration . Booter . Quirks ) ) ;
mOpenCoreConfiguration . Booter . Quirks . AvoidRuntimeDefrag = gSettings . Quirks . OcBooterQuirks . AvoidRuntimeDefrag ;
mOpenCoreConfiguration . Booter . Quirks . DevirtualiseMmio = gSettings . Quirks . OcBooterQuirks . DevirtualiseMmio ;
mOpenCoreConfiguration . Booter . Quirks . DisableSingleUser = gSettings . Quirks . OcBooterQuirks . DisableSingleUser ;
mOpenCoreConfiguration . Booter . Quirks . DisableVariableWrite = gSettings . Quirks . OcBooterQuirks . DisableVariableWrite ;
mOpenCoreConfiguration . Booter . Quirks . DiscardHibernateMap = gSettings . Quirks . OcBooterQuirks . DiscardHibernateMap ;
mOpenCoreConfiguration . Booter . Quirks . EnableSafeModeSlide = gSettings . Quirks . OcBooterQuirks . EnableSafeModeSlide ;
mOpenCoreConfiguration . Booter . Quirks . EnableWriteUnprotector = gSettings . Quirks . OcBooterQuirks . EnableWriteUnprotector ;
mOpenCoreConfiguration . Booter . Quirks . ForceExitBootServices = gSettings . Quirks . OcBooterQuirks . ForceExitBootServices ;
mOpenCoreConfiguration . Booter . Quirks . ProtectMemoryRegions = gSettings . Quirks . OcBooterQuirks . ProtectMemoryRegions ;
mOpenCoreConfiguration . Booter . Quirks . ProtectSecureBoot = gSettings . Quirks . OcBooterQuirks . ProtectSecureBoot ;
mOpenCoreConfiguration . Booter . Quirks . ProtectUefiServices = gSettings . Quirks . OcBooterQuirks . ProtectUefiServices ;
mOpenCoreConfiguration . Booter . Quirks . ProvideCustomSlide = gSettings . Quirks . OcBooterQuirks . ProvideCustomSlide ;
mOpenCoreConfiguration . Booter . Quirks . ProvideMaxSlide = gSettings . Quirks . OcBooterQuirks . ProvideMaxSlide ;
mOpenCoreConfiguration . Booter . Quirks . RebuildAppleMemoryMap = gSettings . Quirks . OcBooterQuirks . RebuildAppleMemoryMap ;
2022-07-02 09:08:53 +02:00
mOpenCoreConfiguration . Booter . Quirks . ResizeAppleGpuBars = gSettings . Quirks . OcBooterQuirks . ResizeAppleGpuBars ;
2021-04-11 07:18:52 +02:00
mOpenCoreConfiguration . Booter . Quirks . SetupVirtualMap = gSettings . Quirks . OcBooterQuirks . SetupVirtualMap ;
2022-10-05 20:04:32 +02:00
mOpenCoreConfiguration . Booter . Quirks . SignalAppleOS = false ; //gSettings.Quirks.OcBooterQuirks.SignalAppleOS;
2021-04-11 07:18:52 +02:00
mOpenCoreConfiguration . Booter . Quirks . SyncRuntimePermissions = gSettings . Quirks . OcBooterQuirks . SyncRuntimePermissions ;
2022-07-02 09:08:53 +02:00
2020-02-15 15:51:18 +01:00
2021-01-22 09:35:57 +01:00
# endif
2020-02-15 15:51:18 +01:00
2022-10-05 20:04:32 +02:00
2021-04-17 13:32:32 +02:00
FillOCCpuInfo ( & mOpenCoreCpuInfo ) ;
2020-02-15 15:51:18 +01:00
2023-06-28 21:01:41 +02:00
mOpenCoreConfiguration . Uefi . Quirks . TscSyncTimeout = gSettings . Quirks . OcBooterQuirks . TscSyncTimeout ;
2020-09-07 00:19:48 +02:00
2021-01-22 09:35:57 +01:00
# ifndef USE_OC_SECTION_Kernel
2020-09-07 00:19:48 +02:00
2021-01-22 09:35:57 +01:00
XObjArray < SIDELOAD_KEXT > kextArray ;
if ( ! DoHibernateWake ) {
AddKextsInArray ( & kextArray ) ;
}
2020-09-07 00:19:48 +02:00
2021-01-22 09:35:57 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Scheme . KernelArch , " x86_64 " ) ;
2021-03-25 15:32:56 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Scheme . KernelCache , gSettings . Quirks . OcKernelCache . c_str ( ) ) ;
mOpenCoreConfiguration . Kernel . Scheme . FuzzyMatch = gSettings . Quirks . FuzzyMatch ;
2021-04-11 07:18:52 +02:00
memset ( & mOpenCoreConfiguration . Kernel . Quirks , 0 , sizeof ( mOpenCoreConfiguration . Kernel . Quirks ) ) ;
2022-06-19 18:46:52 +02:00
mOpenCoreConfiguration . Kernel . Quirks . SetApfsTrimTimeout = - 1 ; // Jief: Slice modified OcConfigurationLib.h to set -1 by default instead of 999. I prefer the modification here to minimize commts in OC submodule. Makes it easier to upgrade submodule.
2021-04-11 07:18:52 +02:00
mOpenCoreConfiguration . Kernel . Quirks . AppleCpuPmCfgLock = GlobalConfig . KPAppleIntelCPUPM ;
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmCfgLock = GlobalConfig . KPKernelPm ;
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmExtraMsrs = gSettings . Quirks . OcKernelQuirks . AppleXcpmExtraMsrs ;
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmForceBoost = gSettings . Quirks . OcKernelQuirks . AppleXcpmForceBoost ;
# ifndef USE_OC_SECTION_PlatformInfo
mOpenCoreConfiguration . Kernel . Quirks . CustomSmbiosGuid = gSettings . KernelAndKextPatches . KPDELLSMBIOS ;
# endif
mOpenCoreConfiguration . Kernel . Quirks . DisableIoMapper = gSettings . Quirks . OcKernelQuirks . DisableIoMapper ;
mOpenCoreConfiguration . Kernel . Quirks . DisableLinkeditJettison = gSettings . Quirks . OcKernelQuirks . DisableLinkeditJettison ;
mOpenCoreConfiguration . Kernel . Quirks . DisableRtcChecksum = gSettings . KernelAndKextPatches . KPAppleRTC ;
2021-09-23 12:36:41 +02:00
mOpenCoreConfiguration . Kernel . Emulate . DummyPowerManagement = gSettings . Quirks . OcKernelQuirks . DummyPowerManagement ;
2021-09-25 10:51:37 +02:00
mOpenCoreConfiguration . Kernel . Quirks . ExtendBTFeatureFlags = gSettings . Quirks . OcKernelQuirks . ExtendBTFeatureFlags ;
2021-04-11 07:18:52 +02:00
mOpenCoreConfiguration . Kernel . Quirks . ExternalDiskIcons = gSettings . Quirks . OcKernelQuirks . ExternalDiskIcons ;
mOpenCoreConfiguration . Kernel . Quirks . IncreasePciBarSize = gSettings . Quirks . OcKernelQuirks . IncreasePciBarSize ;
mOpenCoreConfiguration . Kernel . Quirks . LapicKernelPanic = gSettings . KernelAndKextPatches . KPKernelLapic ;
mOpenCoreConfiguration . Kernel . Quirks . PanicNoKextDump = gSettings . KernelAndKextPatches . KPPanicNoKextDump ;
mOpenCoreConfiguration . Kernel . Quirks . PowerTimeoutKernelPanic = gSettings . Quirks . OcKernelQuirks . PowerTimeoutKernelPanic ;
mOpenCoreConfiguration . Kernel . Quirks . ThirdPartyDrives = gSettings . Quirks . OcKernelQuirks . ThirdPartyDrives ;
mOpenCoreConfiguration . Kernel . Quirks . XhciPortLimit = gSettings . Quirks . OcKernelQuirks . XhciPortLimit ;
2022-01-28 19:47:15 +01:00
mOpenCoreConfiguration . Kernel . Quirks . ProvideCurrentCpuInfo = gSettings . Quirks . OcKernelQuirks . ProvideCurrentCpuInfo ;
2021-01-22 09:35:57 +01:00
mOpenCoreConfiguration . Kernel . Add . Count = ( UINT32 ) kextArray . size ( ) ;
mOpenCoreConfiguration . Kernel . Add . AllocCount = mOpenCoreConfiguration . Kernel . Add . Count ;
mOpenCoreConfiguration . Kernel . Add . ValueSize = sizeof ( __typeof_am__ ( * * mOpenCoreConfiguration . Kernel . Add . Values ) ) ; // sizeof(OC_KERNEL_ADD_ENTRY) == 680
mOpenCoreConfiguration . Kernel . Add . Values = ( OC_KERNEL_ADD_ENTRY * * ) malloc ( mOpenCoreConfiguration . Kernel . Add . AllocCount * sizeof ( * mOpenCoreConfiguration . Kernel . Add . Values ) ) ; // sizeof(OC_KERNEL_ADD_ENTRY*) == sizeof(ptr)
memset ( mOpenCoreConfiguration . Kernel . Add . Values , 0 , mOpenCoreConfiguration . Kernel . Add . AllocCount * sizeof ( * mOpenCoreConfiguration . Kernel . Add . Values ) ) ;
// Seems that Lilu must be first.
size_t pos = setKextAtPos ( & kextArray , " Lilu.kext " _XS8 , 0 ) ;
pos = setKextAtPos ( & kextArray , " VirtualSMC.kext " _XS8 , pos ) ;
2022-02-19 17:35:52 +01:00
pos = setKextAtPos ( & kextArray , " FakeSMC.kext " _XS8 , pos ) ;
2022-03-08 17:48:52 +01:00
// pos = setKextAtPos(&kextArray, "vecLib.kext"_XS8, pos);
// pos = setKextAtPos(&kextArray, "IOAudioFamily.kext"_XS8, pos);
2023-09-12 21:14:41 +02:00
pos = setKextAtPos ( & kextArray , " IOSkywalkFamily.kext " _XS8 , pos ) ;
2021-01-22 09:35:57 +01:00
pos = setKextAtPos ( & kextArray , " FakePCIID.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " FakePCIID_XHCIMux.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " AMDRyzenCPUPowerManagement .kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " SMCAMDProcessor.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " WhateverGreen.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " AppleALC.kext " _XS8 , pos ) ;
2023-09-12 21:14:41 +02:00
// pos = setKextAtPos(&kextArray, "IntelMausi.kext"_XS8, pos); // not needed special order?
2021-01-22 09:35:57 +01:00
pos = setKextAtPos ( & kextArray , " SMCProcessor.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " SMCSuperIO.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " USBPorts.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " VoodooGPIO.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " VoodooI2CServices.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " VoodooI2C.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " VoodooI2CHID.kext " _XS8 , pos ) ;
2021-02-06 17:34:31 +01:00
pos = setKextAtPos ( & kextArray , " VoodooSMBus.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " VoodooRMI.kext " _XS8 , pos ) ;
2021-01-22 09:35:57 +01:00
pos = setKextAtPos ( & kextArray , " BrcmFirmwareData.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " BrcmPatchRAM2.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " BrcmPatchRAM3.kext " _XS8 , pos ) ;
2023-10-21 19:26:52 +02:00
pos = setKextAtPos ( & kextArray , " IO80211FamilyLegacy.kext " _XS8 , pos ) ;
2021-01-22 09:35:57 +01:00
pos = setKextAtPos ( & kextArray , " HS80211Family.kext " _XS8 , pos ) ;
pos = setKextAtPos ( & kextArray , " AirPortAtheros40.kext " _XS8 , pos ) ;
2023-06-28 21:01:41 +02:00
for ( size_t kextIdx = 0 ; kextIdx < kextArray . size ( ) ; kextIdx + + ) {
2021-01-22 09:35:57 +01:00
const SIDELOAD_KEXT & KextEntry = kextArray [ kextIdx ] ;
DBG ( " Bridge kext to OC : Path=%ls \n " , KextEntry . FileName . wc_str ( ) ) ;
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] = ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Add . Values ) ) malloc ( mOpenCoreConfiguration . Kernel . Add . ValueSize ) ;
memset ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] , 0 , mOpenCoreConfiguration . Kernel . Add . ValueSize ) ;
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > Enabled = 1 ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > Arch , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Scheme . KernelArch ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > Comment , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > MaxKernel , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > MinKernel , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > Identifier , " " ) ;
assert ( selfOem . isKextsDirFound ( ) ) ; // be sure before calling getKextsPathRelToSelfDir()
XStringW dirPath = SWPrintf ( " %ls \\ %ls " , selfOem . getKextsDirPathRelToSelfDir ( ) . wc_str ( ) , KextEntry . KextDirNameUnderOEMPath . wc_str ( ) ) ;
2023-06-28 21:01:41 +02:00
2021-01-22 09:35:57 +01:00
XString8 bundlePath = S8Printf ( " %ls \\ %ls " , dirPath . wc_str ( ) , KextEntry . FileName . wc_str ( ) ) ;
if ( FileExists ( & self . getCloverDir ( ) , bundlePath ) ) {
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > BundlePath , bundlePath . c_str ( ) ) ;
2023-06-28 21:01:41 +02:00
} else {
2021-01-22 09:35:57 +01:00
DBG ( " Cannot find kext bundlePath at '%s' \n " , bundlePath . c_str ( ) ) ;
2020-10-14 18:08:32 +02:00
}
2021-01-22 09:35:57 +01:00
# if 1
//CFBundleExecutable
2021-09-28 15:54:31 +02:00
XBool NoContents = false ;
2022-03-08 17:48:52 +01:00
XStringW infoPlistPath = getKextPlist ( & self . getCloverDir ( ) , dirPath , KextEntry . FileName , & NoContents ) ; //it will be fullPath, including dir
2022-03-08 19:57:31 +01:00
DBG ( " InfoPlistPath=%ls \n " , infoPlistPath . wc_str ( ) ) ;
2022-03-08 17:48:52 +01:00
TagDict * dict = getInfoPlist ( & self . getCloverDir ( ) , infoPlistPath ) ;
2021-09-28 10:28:45 +02:00
// XBool inject = checkOSBundleRequired(dict);
XBool inject = true ;
2021-01-22 09:35:57 +01:00
if ( inject ) {
if ( infoPlistPath . notEmpty ( ) ) {
if ( NoContents ) {
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > PlistPath , " Info.plist " ) ;
} else {
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > PlistPath , " Contents/Info.plist " ) ;
}
2023-06-28 21:01:41 +02:00
} else {
2021-01-22 09:35:57 +01:00
DBG ( " Cannot find kext info.plist at '%ls' \n " , KextEntry . FileName . wc_str ( ) ) ;
}
2022-03-08 17:48:52 +01:00
XString8 execpath = getKextExecPath ( & self . getCloverDir ( ) , dirPath , KextEntry . FileName , dict , NoContents ) ;
2021-01-22 09:35:57 +01:00
if ( execpath . notEmpty ( ) ) {
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > ExecutablePath , execpath . c_str ( ) ) ;
DBG ( " assign executable as '%s' \n " , execpath . c_str ( ) ) ;
}
2020-10-14 18:08:32 +02:00
}
2020-10-03 22:56:50 +02:00
2021-01-22 09:35:57 +01:00
# else
XStringW execpath = S8Printf ( " Contents \\ MacOS \\ %ls " , KextEntry . FileName . subString ( 0 , KextEntry . FileName . rindexOf ( " . " ) ) . wc_str ( ) ) ;
XStringW fullPath = SWPrintf ( " %s \\ %ls " , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > BundlePath ) , execpath . wc_str ( ) ) ;
if ( FileExists ( & self . getCloverDir ( ) , fullPath ) ) {
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > ExecutablePath , S8Printf ( " Contents \\ MacOS \\ %ls " , KextEntry . FileName . subString ( 0 , KextEntry . FileName . rindexOf ( " . " ) ) . wc_str ( ) ) . c_str ( ) ) ;
}
XStringW infoPlistPath = SWPrintf ( " %s \\ Contents \\ Info.plist " , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > BundlePath ) ) ;
2021-09-27 21:40:40 +02:00
if ( FileExists ( & self . getCloverDir ( ) , infoPlistPath ) ) {
2021-01-22 09:35:57 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > PlistPath , " Contents/Info.plist " ) ; // TODO : is always Contents/Info.plist ?
2021-09-27 21:40:40 +02:00
} else {
2021-01-22 09:35:57 +01:00
DBG ( " Cannot find kext info.plist at '%ls' \n " , infoPlistPath . wc_str ( ) ) ;
}
# endif
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > ImageData = NULL ;
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > ImageDataSize = 0 ;
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > PlistData = NULL ;
mOpenCoreConfiguration . Kernel . Add . Values [ kextIdx ] - > PlistDataSize = 0 ;
2020-10-14 18:08:32 +02:00
2023-06-28 21:01:41 +02:00
} // for (size_t kextIdx
2020-09-07 16:44:24 +02:00
2022-03-08 17:48:52 +01:00
2022-03-02 19:55:17 +01:00
mOpenCoreConfiguration . Kernel . Force . Count = ( UINT32 ) KernelAndKextPatches . ForceKextsToLoad . size ( ) ;
mOpenCoreConfiguration . Kernel . Force . AllocCount = mOpenCoreConfiguration . Kernel . Force . Count ;
mOpenCoreConfiguration . Kernel . Force . ValueSize = sizeof ( __typeof_am__ ( * * mOpenCoreConfiguration . Kernel . Force . Values ) ) ; // sizeof(OC_KERNEL_FORCE_ENTRY)
2022-03-08 17:48:52 +01:00
int valuesSize = mOpenCoreConfiguration . Kernel . Force . AllocCount * sizeof ( * mOpenCoreConfiguration . Kernel . Force . Values ) ;
mOpenCoreConfiguration . Kernel . Force . Values = ( OC_KERNEL_ADD_ENTRY * * ) malloc ( valuesSize ) ; // sizeof(OC_KERNEL_FORCE_ENTRY*) == sizeof(ptr)
memset ( mOpenCoreConfiguration . Kernel . Force . Values , 0 , valuesSize ) ;
2022-03-02 19:55:17 +01:00
2022-03-08 19:57:31 +01:00
2022-03-09 20:34:49 +01:00
2023-06-28 21:01:41 +02:00
for ( size_t kextIdx = 0 ; kextIdx < KernelAndKextPatches . ForceKextsToLoad . size ( ) ; kextIdx + + ) {
2022-03-02 19:55:17 +01:00
const XStringW & forceKext = KernelAndKextPatches . ForceKextsToLoad [ kextIdx ] ;
2022-03-08 17:48:52 +01:00
2022-03-09 20:34:49 +01:00
DBG ( " Force kext to OC : Path=%ls \n " , forceKext . wc_str ( ) ) ;
2022-03-02 19:55:17 +01:00
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] = ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Force . Values ) ) malloc ( mOpenCoreConfiguration . Kernel . Force . ValueSize ) ;
memset ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] , 0 , mOpenCoreConfiguration . Kernel . Force . ValueSize ) ;
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > Enabled = 1 ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > Arch , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Scheme . KernelArch ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > Comment , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > MaxKernel , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > MinKernel , " " ) ;
2022-03-13 06:25:01 +01:00
// OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->Identifier, "");
2022-03-02 19:55:17 +01:00
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > ImageData = NULL ;
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > ImageDataSize = 0 ;
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > PlistData = NULL ;
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > PlistDataSize = 0 ;
2022-03-08 17:48:52 +01:00
REFIT_VOLUME * SystemVolume = Volume ;
2022-03-08 19:57:31 +01:00
EFI_FILE * SysRoot = Volume - > RootDir ;
2023-06-28 21:01:41 +02:00
2022-03-13 06:25:01 +01:00
2022-03-08 17:48:52 +01:00
if ( Volume - > ApfsRole = = APPLE_APFS_VOLUME_ROLE_PREBOOT ) {
2022-03-09 20:34:49 +01:00
//search for other partition
2022-03-08 19:57:31 +01:00
DBG ( " boot from Preboot, index=%llu \n " , Volume - > Index ) ;
2022-04-26 00:55:56 +02:00
size_t numbers = Volumes . size ( ) ;
size_t sysIndex = 0 ;
2022-03-09 20:34:49 +01:00
for ( sysIndex = Volume - > Index + 1 ; sysIndex < numbers ; sysIndex + + ) {
2022-03-08 19:57:31 +01:00
SystemVolume = & Volumes [ sysIndex ] ;
SysRoot = SystemVolume - > RootDir ;
2023-06-28 21:01:41 +02:00
2022-04-26 00:55:56 +02:00
DBG ( " test volume %zd, name %ls: \n " , sysIndex , SystemVolume - > VolName . wc_str ( ) ) ;
2022-03-13 06:25:01 +01:00
2023-06-28 21:01:41 +02:00
if ( FileExists ( SysRoot , L " \\ System \\ Library \\ CoreServices \\ boot.efi " ) ) {
2022-04-26 00:55:56 +02:00
DBG ( " boot.efi found on %zd \n " , sysIndex ) ;
2023-06-28 21:01:41 +02:00
}
2022-03-13 06:25:01 +01:00
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry = NULL ;
DirIterOpen ( SysRoot , L " \\ System \\ Library \\ Extensions \\ AMDSupport.kext \\ Contents \\ MacOS \\ " , & DirIter ) ;
while ( DirIterNext ( & DirIter , 1 , L " * " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = ' . ' ) {
DBG ( " Skip dot entries: %ls \n " , DirEntry - > FileName ) ;
continue ;
}
DBG ( " %ls attr=%llu \n " , DirEntry - > FileName , DirEntry - > Attribute ) ;
}
DirIterClose ( & DirIter ) ;
if ( FileExists ( SysRoot , L " \\ System \\ Library \\ Extensions \\ AMDSupport.kext \\ Contents \\ MacOS \\ AMDSupport " ) ) {
2022-04-26 00:55:56 +02:00
DBG ( " AMDSupport found on %zd \n " , sysIndex ) ; //never found
2022-03-10 17:48:39 +01:00
break ;
2022-03-13 06:25:01 +01:00
}
2022-03-08 19:57:31 +01:00
}
2022-03-08 17:48:52 +01:00
}
2022-03-13 06:25:01 +01:00
mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > ImageData = ( UINT8 * ) SysRoot ;
2022-03-10 17:48:39 +01:00
2022-04-26 00:55:56 +02:00
size_t i1 = forceKext . rindexOf ( " \\ " ) + 1 ;
size_t i2 = forceKext . rindexOf ( " . " ) ;
2022-03-13 06:25:01 +01:00
XStringW identifier = forceKext . subString ( i1 , i2 - i1 ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > Identifier , S8Printf ( " %ls " , identifier . wc_str ( ) ) . c_str ( ) ) ;
2023-06-28 21:01:41 +02:00
2022-03-13 06:25:01 +01:00
XString8 execpath = S8Printf ( " Contents \\ MacOS \\ %ls " , identifier . wc_str ( ) ) ;
DBG ( " calculated execpath=%s \n " , execpath . c_str ( ) ) ;
2023-06-28 21:01:41 +02:00
2022-03-13 06:25:01 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > BundlePath , S8Printf ( " %ls " , forceKext . wc_str ( ) ) . c_str ( ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > PlistPath , " Contents \\ Info.plist " ) ;
2023-06-28 21:01:41 +02:00
2022-03-06 11:42:12 +01:00
//then we have to find executablePath and plistPath
2022-03-13 06:25:01 +01:00
DBG ( " bundle path=%s \n " , mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > BundlePath . Value ) ;
2022-03-06 07:42:49 +01:00
2022-03-08 17:48:52 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > ExecutablePath , execpath . c_str ( ) ) ;
2022-03-02 19:55:17 +01:00
DBG ( " assign executable as '%s' \n " , mOpenCoreConfiguration . Kernel . Force . Values [ kextIdx ] - > ExecutablePath . Value ) ;
2022-03-13 06:25:01 +01:00
2021-01-22 09:35:57 +01:00
}
2023-08-27 21:14:02 +02:00
if ( gSettings . KernelAndKextPatches . BlockSkywalk ) {
mOpenCoreConfiguration . Kernel . Block . Count = 1 ;
mOpenCoreConfiguration . Kernel . Block . AllocCount = 1 ;
mOpenCoreConfiguration . Kernel . Block . ValueSize = sizeof ( __typeof_am__ ( * * mOpenCoreConfiguration . Kernel . Block . Values ) ) ;
valuesSize = mOpenCoreConfiguration . Kernel . Block . AllocCount * sizeof ( * mOpenCoreConfiguration . Kernel . Block . Values ) ;
mOpenCoreConfiguration . Kernel . Block . Values = ( OC_KERNEL_BLOCK_ENTRY * * ) malloc ( valuesSize ) ;
memset ( mOpenCoreConfiguration . Kernel . Block . Values , 0 , valuesSize ) ;
mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] = ( __typeof_am__ ( * mOpenCoreConfiguration . Kernel . Block . Values ) ) malloc ( mOpenCoreConfiguration . Kernel . Block . ValueSize ) ;
memset ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] , 0 , mOpenCoreConfiguration . Kernel . Block . ValueSize ) ;
mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > Enabled = 1 ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > Arch , OC_BLOB_GET ( & mOpenCoreConfiguration . Kernel . Scheme . KernelArch ) ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > Comment , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > MaxKernel , " " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > MinKernel , " 23 " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > Identifier , " com.apple.iokit.IOSkywalkFamily " ) ;
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Kernel . Block . Values [ 0 ] - > Strategy , " Exclude " ) ;
}
2020-10-03 19:02:31 +02:00
# endif
2020-10-11 08:06:50 +02:00
2021-03-19 21:32:42 +01:00
mOpenCoreConfiguration . Uefi . Output . ProvideConsoleGop = gSettings . GUI . ProvideConsoleGop ;
2021-02-02 10:02:21 +01:00
OC_STRING_ASSIGN ( mOpenCoreConfiguration . Uefi . Output . Resolution , XString8 ( gSettings . GUI . ScreenResolution ) . c_str ( ) ) ;
2021-01-22 09:35:57 +01:00
2021-03-19 08:41:24 +01:00
if ( OpenRuntimeEfiName . notEmpty ( ) ) {
XStringW FileName = SWPrintf ( " %ls \\ %ls \\ %ls " , self . getCloverDirFullPath ( ) . wc_str ( ) , getDriversPath ( ) . wc_str ( ) , OpenRuntimeEfiName . wc_str ( ) ) ;
EFI_HANDLE DriverHandle ;
Status = gBS - > LoadImage ( false , gImageHandle , FileDevicePath ( self . getSelfLoadedImage ( ) . DeviceHandle , FileName ) , NULL , 0 , & DriverHandle ) ;
if ( ! EFI_ERROR ( Status ) ) {
Status = gBS - > StartImage ( DriverHandle , 0 , 0 ) ;
DBG ( " Start '%ls' : Status %s \n " , OpenRuntimeEfiName . wc_str ( ) , efiStrError ( Status ) ) ;
2021-09-25 12:02:47 +02:00
if ( ! EFI_ERROR ( Status ) )
{
OC_FIRMWARE_RUNTIME_PROTOCOL * FwRuntime ;
Status = gBS - > LocateProtocol (
2022-04-26 00:55:56 +02:00
gOcFirmwareRuntimeProtocolGuid ,
2021-09-25 12:02:47 +02:00
NULL ,
( VOID * * ) & FwRuntime
) ;
if ( ! EFI_ERROR ( Status ) ) {
if ( FwRuntime - > Revision = = OC_FIRMWARE_RUNTIME_REVISION ) {
} else {
DEBUG ( (
DEBUG_ERROR ,
" OCABC: Incompatible OpenRuntime r%u, require r%u \n " ,
( UINT32 ) FwRuntime - > Revision ,
( UINT32 ) OC_FIRMWARE_RUNTIME_REVISION
) ) ;
2023-06-28 21:01:41 +02:00
DBG ( " Incompatible OpenRuntime r%llu, require r%u \n " , FwRuntime - > Revision , OC_FIRMWARE_RUNTIME_REVISION ) ;
2021-09-25 12:02:47 +02:00
}
}
}
2021-03-19 08:41:24 +01:00
} else {
2023-06-28 21:01:41 +02:00
DBG ( " Error when loading '%ls' : Status %s. \n " , OpenRuntimeEfiName . wc_str ( ) , efiStrError ( Status ) ) ;
2021-03-19 08:41:24 +01:00
}
} else {
DBG ( " No OpenRuntime driver. This is ok, OpenRuntime is not mandatory. \n " ) ;
}
2021-01-22 09:35:57 +01:00
OcMain ( & mOpenCoreStorage , NULL ) ;
XStringW DevicePathAsString = DevicePathToXStringW ( DevicePath ) ;
if ( DevicePathAsString . rindexOf ( " .dmg " ) = = MAX_XSIZE )
{
// point to InternalEfiLoadImage from OC
Status = gBS - > LoadImage (
2021-09-28 10:28:45 +02:00
false ,
2021-01-22 09:35:57 +01:00
gImageHandle ,
DevicePath ,
NULL ,
0 ,
& ImageHandle
) ;
2021-03-22 13:40:01 +01:00
if ( EFI_ERROR ( Status ) ) {
DBG ( " LoadImage at '%ls' failed. Status = %s \n " , DevicePathAsString . wc_str ( ) , efiStrError ( Status ) ) ;
return ;
}
2021-09-25 12:17:25 +02:00
DBG ( " ImageHandle = %llx \n " , uintptr_t ( ImageHandle ) ) ;
2023-06-28 21:01:41 +02:00
} else {
2021-01-22 09:35:57 +01:00
// NOTE : OpenCore ignore the name of the dmg.
// InternalLoadDmg calls InternalFindFirstDmgFileName to find the dmg file name.
// So be careful that, if an other dmg exists in the dir, that might boot on the wrong one.
EFI_DEVICE_PATH_PROTOCOL * DevicePathCopy = DuplicateDevicePath ( DevicePath ) ;
EFI_DEVICE_PATH_PROTOCOL * PreviousNode = NULL ;
EFI_DEVICE_PATH_PROTOCOL * Node = DevicePathCopy ;
while ( ! IsDevicePathEnd ( Node ) ) {
if ( Node - > Type = = MEDIA_DEVICE_PATH & & Node - > SubType = = MEDIA_FILEPATH_DP ) {
PreviousNode = Node ;
break ;
}
2023-06-28 21:01:41 +02:00
2021-01-22 09:35:57 +01:00
PreviousNode = Node ;
Node = NextDevicePathNode ( Node ) ;
}
SetDevicePathEndNode ( PreviousNode ) ;
EFI_DEVICE_PATH_PROTOCOL * LoaderPathBasenameNode = ConvertTextToDeviceNode ( LoaderPath . dirname ( ) . wc_str ( ) ) ;
EFI_DEVICE_PATH_PROTOCOL * DevicePathToDmgDir = AppendDevicePathNode ( DevicePathCopy , LoaderPathBasenameNode ) ;
DBG ( " DevicePathToDmgDir = %ls \n " , DevicePathToXStringW ( DevicePathToDmgDir ) . wc_str ( ) ) ;
2021-02-06 18:16:46 +01:00
INTERNAL_DMG_LOAD_CONTEXT DmgLoadContext = { 0 , 0 , 0 } ;
2021-01-22 09:35:57 +01:00
DmgLoadContext . DevicePath = DevicePathToDmgDir ;
EFI_DEVICE_PATH_PROTOCOL * BootEfiFromDmgDevicePath = InternalLoadDmg ( & DmgLoadContext , OcDmgLoadingAnyImage ) ;
DBG ( " DevicePath of dmg = %ls \n " , DevicePathToXStringW ( BootEfiFromDmgDevicePath ) . wc_str ( ) ) ;
// point to InternalEfiLoadImage from OC
Status = gBS - > LoadImage (
2021-09-28 10:28:45 +02:00
false ,
2021-01-22 09:35:57 +01:00
gImageHandle ,
BootEfiFromDmgDevicePath ,
NULL ,
0 ,
& ImageHandle
) ;
2021-03-22 13:40:01 +01:00
if ( EFI_ERROR ( Status ) ) {
DBG ( " LoadImage at '%ls' failed. Status = %s \n " , DevicePathToXStringW ( BootEfiFromDmgDevicePath ) . wc_str ( ) , efiStrError ( Status ) ) ;
return ;
}
2021-01-22 09:35:57 +01:00
}
EFI_STATUS OptionalStatus = gBS - > HandleProtocol (
ImageHandle ,
& gEfiLoadedImageProtocolGuid ,
( void * * ) & LoadedImage
) ;
if ( EFI_ERROR ( OptionalStatus ) ) return ; // TODO message ?
2023-06-28 21:01:41 +02:00
} else {
2021-01-22 09:35:57 +01:00
// Load image into memory (will be started later)
Status = LoadEFIImage ( DevicePath , LoaderPath . basename ( ) , NULL , & ImageHandle ) ;
if ( EFI_ERROR ( Status ) ) {
DBG ( " Image is not loaded, status=%s \n " , efiStrError ( Status ) ) ;
return ; // no reason to continue if loading image failed
}
2020-09-30 20:56:55 +02:00
}
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
egClearScreen ( & BootBgColor ) ; //if not set then it is already MenuBackgroundPixel
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
// KillMouse();
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
// if (LoaderType == OSTYPE_OSX) {
if ( OSTYPE_IS_OSX ( LoaderType ) | |
OSTYPE_IS_OSX_RECOVERY ( LoaderType ) | |
OSTYPE_IS_OSX_INSTALLER ( LoaderType ) ) {
2020-09-16 01:01:53 +02:00
2020-09-30 20:56:55 +02:00
// To display progress bar properly (especially in FV2 mode) boot.efi needs to be in graphics mode.
// Unfortunately many UEFI implementations change the resolution when SetMode happens.
// This is not what boot.efi expects, and it freely calls SetMode at its will.
// As a result we see progress bar at improper resolution and the background is also missing (10.12.x+).
//
// libeg already has a workaround for SetMode behaviour, so we extend it for boot.efi support.
// The approach tries to be follows:
// 1. Ensure we have graphics mode set (since it is a must in the future).
// 2. Request text mode for boot.efi, which it expects by default (here a SetMode libeg hack will trigger
// on problematic UEFI implementations like AMI).
2021-09-28 10:28:45 +02:00
egSetGraphicsModeEnabled ( true ) ;
egSetGraphicsModeEnabled ( false ) ;
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
DBG ( " GetOSVersion: " ) ;
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
//needed for boot.efi patcher
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( ImageHandle , & gEfiLoadedImageProtocolGuid , ( void * * ) & LoadedImage ) ;
2020-09-30 20:56:55 +02:00
// Correct OSVersion if it was not found
// This should happen only for 10.7-10.9 OSTYPE_OSX_INSTALLER
// For these cases, take OSVersion from loaded boot.efi image in memory
2023-06-28 21:01:41 +02:00
if ( macOSVersion . isEmpty ( ) ) {
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
if ( ! EFI_ERROR ( Status ) ) {
// version in boot.efi appears as "Mac OS X 10.?"
/*
Start OSName Mac OS X 10.12 End OSName Start OSVendor Apple Inc . End
*/
2023-06-28 21:01:41 +02:00
2020-09-30 20:56:55 +02:00
InstallerVersion = AsciiStrStr ( ( CHAR8 * ) LoadedImage - > ImageBase , " Mac OS X " ) ;
2021-06-09 19:49:30 +02:00
int location = 9 ;
if ( InstallerVersion = = NULL ) {
InstallerVersion = AsciiStrStr ( ( CHAR8 * ) LoadedImage - > ImageBase , " macOS " ) ;
location = 7 ;
}
2020-09-30 20:56:55 +02:00
if ( InstallerVersion ! = NULL ) { // string was found
2021-06-09 19:49:30 +02:00
InstallerVersion + = location ; // advance to version location
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
if ( strncmp ( InstallerVersion , " 10.7 " , 4 ) & &
strncmp ( InstallerVersion , " 10.8 " , 4 ) & &
strncmp ( InstallerVersion , " 10.9 " , 4 ) & &
strncmp ( InstallerVersion , " 10.10 " , 5 ) & &
strncmp ( InstallerVersion , " 10.11 " , 5 ) & &
strncmp ( InstallerVersion , " 10.12 " , 5 ) & &
strncmp ( InstallerVersion , " 10.13 " , 5 ) & &
strncmp ( InstallerVersion , " 10.14 " , 5 ) & &
strncmp ( InstallerVersion , " 10.15 " , 5 ) & &
strncmp ( InstallerVersion , " 10.16 " , 5 ) & &
2021-06-09 19:49:30 +02:00
strncmp ( InstallerVersion , " 11. " , 3 ) & &
2022-06-24 18:03:14 +02:00
strncmp ( InstallerVersion , " 12. " , 3 ) & &
2023-06-05 21:23:36 +02:00
strncmp ( InstallerVersion , " 13. " , 3 ) & &
strncmp ( InstallerVersion , " 14. " , 3 )
2022-06-24 18:03:14 +02:00
) {
2020-09-30 20:56:55 +02:00
InstallerVersion = NULL ; // flag known version was not found
}
if ( InstallerVersion ! = NULL ) { // known version was found in image
2021-01-31 10:50:23 +01:00
macOSVersion = InstallerVersion ;
DBG ( " Corrected OSVersion: %s \n " , macOSVersion . asString ( ) . c_str ( ) ) ;
2020-09-30 20:56:55 +02:00
}
2020-09-07 13:13:44 +02:00
}
}
2020-09-30 20:56:55 +02:00
BuildVersion . setEmpty ( ) ;
}
if ( BuildVersion . notEmpty ( ) ) {
2021-01-31 10:50:23 +01:00
DBG ( " %s (%s) \n " , macOSVersion . asString ( ) . c_str ( ) , BuildVersion . c_str ( ) ) ;
2020-09-07 13:13:44 +02:00
} else {
2021-01-31 10:50:23 +01:00
DBG ( " %s \n " , macOSVersion . asString ( ) . c_str ( ) ) ;
2020-09-30 20:56:55 +02:00
}
2021-01-31 10:50:23 +01:00
if ( macOSVersion > = MacOsVersion ( " 10.11 " _XS8 ) ) {
2020-09-30 20:56:55 +02:00
if ( OSFLAG_ISSET ( Flags , OSFLAG_NOSIP ) ) {
2023-06-05 21:23:36 +02:00
gSettings . RtVariables . CsrActiveConfig = ( UINT32 ) 0xBEF ;
2021-03-26 10:43:15 +01:00
gSettings . RtVariables . BooterConfig = 0x28 ;
2020-09-30 20:56:55 +02:00
}
2020-09-07 13:13:44 +02:00
}
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
FilterKextPatches ( ) ;
FilterKernelPatches ( ) ;
FilterBootPatches ( ) ;
if ( LoadedImage & & ! BooterPatch ( ( UINT8 * ) LoadedImage - > ImageBase , LoadedImage - > ImageSize ) ) {
DBG ( " Will not patch boot.efi \n " ) ;
}
2023-06-22 21:50:58 +02:00
gConf . ReloadSmbios ( OSName ) ;
2020-10-12 13:48:50 +02:00
DelegateKernelPatches ( ) ;
2020-09-07 13:13:44 +02:00
2020-09-30 20:56:55 +02:00
// Set boot argument for kernel if no caches, this should force kernel loading
if ( OSFLAG_ISSET ( Flags , OSFLAG_NOCACHES ) & & ! LoadOptions . containsStartWithIC ( " Kernel= " ) ) {
XString8 KernelLocation ;
2020-09-07 13:13:44 +02:00
2021-01-31 10:50:23 +01:00
if ( macOSVersion . notEmpty ( ) & & macOSVersion < = MacOsVersion ( " 10.9 " _XS8 ) ) {
2020-09-30 20:56:55 +02:00
KernelLocation . S8Printf ( " \" Kernel=/mach_kernel \" " ) ;
} else {
2020-11-12 22:25:56 +01:00
// used for 10.10, 10.11, and new version. Jief : also for unknown version.
2020-09-30 20:56:55 +02:00
KernelLocation . S8Printf ( " \" Kernel=/System/Library/Kernels/kernel \" " ) ;
}
LoadOptions . AddID ( KernelLocation ) ;
2020-09-07 13:13:44 +02:00
}
2020-09-30 20:56:55 +02:00
// first patchACPI and find PCIROOT and RTC
// but before ACPI patch we need smbios patch
2021-02-06 18:16:46 +01:00
CheckEmptyFB ( ) ;
2023-06-22 21:50:58 +02:00
2021-04-28 20:30:34 +02:00
SmbiosFillPatchingValues ( GlobalConfig . SetTable132 , GlobalConfig . EnabledCores , g_SmbiosDiscoveredSettings . RamSlotCount , gConf . SlotDeviceArray , gSettings , gCPUStructure , & g_SmbiosInjectedSettings ) ;
PatchSmbios ( g_SmbiosInjectedSettings ) ;
2023-06-28 21:01:41 +02:00
2021-09-25 12:17:25 +02:00
# ifdef USE_OC_SECTION_Acpi
// If we use the ACPI section form config-oc.plist, let's also delegate the acpi patching to OC
# else
2021-01-31 10:50:23 +01:00
PatchACPI ( Volume , macOSVersion ) ;
2021-09-25 12:17:25 +02:00
# endif
# ifdef JIEF_DEBUG
//SaveOemTables();
# endif
2020-09-16 19:50:16 +02:00
//
2023-06-22 21:50:58 +02:00
2020-09-30 20:56:55 +02:00
DbgHeader ( " RestSetup macOS " ) ;
SetDevices ( this ) ;
SetVariablesForOSX ( this ) ;
2020-11-05 07:29:56 +01:00
// Jief : if we want to use our FixUSBOwnership, we need our OnExitBootServices
EventsInitialize ( this ) ;
2021-04-28 20:30:34 +02:00
FinalizeSmbios ( g_SmbiosInjectedSettings ) ;
2020-09-23 07:20:06 +02:00
2021-04-17 13:32:32 +02:00
SetCPUProperties ( ) ; //very special procedure
2020-09-07 13:13:44 +02:00
2020-09-30 20:56:55 +02:00
if ( OSFLAG_ISSET ( Flags , OSFLAG_HIBERNATED ) ) {
DoHibernateWake = PrepareHibernation ( Volume ) ;
2020-09-08 11:33:35 +02:00
}
2020-09-30 20:56:55 +02:00
SetupDataForOSX ( DoHibernateWake ) ;
2020-09-08 11:33:35 +02:00
2020-09-30 20:56:55 +02:00
if ( gDriversFlags . AptioFixLoaded & &
! DoHibernateWake & &
! LoadOptions . containsStartWithIC ( " slide= " ) ) {
// Add slide=0 argument for ML+ if not present
LoadOptions . AddID ( " slide=0 " _XS8 ) ;
}
/**
* syscl - append " -xcpm " argument conditionally if set KernelXCPM on Intel Haswell + low - end CPUs
*/
if ( KernelAndKextPatches . KPKernelXCPM & &
gCPUStructure . Vendor = = CPU_VENDOR_INTEL & & gCPUStructure . Model > = CPU_MODEL_HASWELL & &
2021-09-28 10:28:45 +02:00
( gCPUStructure . BrandString . contains ( " Celeron " ) | | gCPUStructure . BrandString . contains ( " Pentium " ) ) & &
2021-01-31 10:50:23 +01:00
macOSVersion > = MacOsVersion ( " 10.8.5 " _XS8 ) & & macOSVersion < MacOsVersion ( " 10.12 " _XS8 ) & &
2020-09-30 20:56:55 +02:00
( ! LoadOptions . containsIC ( " -xcpm " ) ) ) {
// add "-xcpm" argv if not present on Haswell+ Celeron/Pentium
LoadOptions . AddID ( " -xcpm " _XS8 ) ;
}
// add -xcpm on Ivy Bridge if set KernelXCPM and system version is 10.8.5 - 10.11.x
if ( KernelAndKextPatches . KPKernelXCPM & &
gCPUStructure . Model = = CPU_MODEL_IVY_BRIDGE & &
2021-01-31 10:50:23 +01:00
macOSVersion > = MacOsVersion ( " 10.8.5 " _XS8 ) & & macOSVersion < MacOsVersion ( " 10.12 " _XS8 ) & &
2020-09-30 20:56:55 +02:00
( ! LoadOptions . containsIC ( " -xcpm " ) ) ) {
// add "-xcpm" argv if not present on Ivy Bridge
LoadOptions . AddID ( " -xcpm " _XS8 ) ;
2020-09-08 23:25:26 +02:00
}
2020-09-18 21:54:30 +02:00
2020-09-30 20:56:55 +02:00
if ( AudioIo ) {
AudioIo - > StopPlayback ( AudioIo ) ;
// CheckSyncSound(true);
EFI_DRIVER_BINDING_PROTOCOL * DriverBinding = NULL ;
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( AudioDriverHandle , & gEfiDriverBindingProtocolGuid , ( void * * ) & DriverBinding ) ;
2020-09-30 20:56:55 +02:00
if ( DriverBinding ) {
DriverBinding - > Stop ( DriverBinding , AudioDriverHandle , 0 , NULL ) ;
}
}
2020-09-18 21:54:30 +02:00
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
// blocking boot.efi output if -v is not specified
// note: this blocks output even if -v is specified in
// /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
// which is wrong
// apianti - only block console output if using graphics
// but don't block custom boot logo
if ( LoadOptions . containsIC ( " -v " ) ) {
2020-12-01 20:09:30 +01:00
Flags = OSFLAG_UNSET ( Flags , OSFLAG_USEGRAPHICS ) ;
2020-09-30 20:56:55 +02:00
}
2020-09-07 00:19:48 +02:00
}
2020-09-30 20:56:55 +02:00
else if ( OSTYPE_IS_WINDOWS ( LoaderType ) ) {
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
if ( AudioIo ) {
2020-12-01 20:09:30 +01:00
AudioIo - > StopPlayback ( AudioIo ) ;
2020-09-30 20:56:55 +02:00
}
2020-09-09 19:06:34 +02:00
2020-09-30 20:56:55 +02:00
DBG ( " Closing events for Windows \n " ) ;
gBS - > CloseEvent ( OnReadyToBootEvent ) ;
gBS - > CloseEvent ( ExitBootServiceEvent ) ;
gBS - > CloseEvent ( mSimpleFileSystemChangeEvent ) ;
2020-09-09 19:06:34 +02:00
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
2020-09-14 15:01:30 +02:00
2021-09-28 10:28:45 +02:00
PatchACPI_OtherOS ( L " Windows " , false ) ;
2020-09-14 15:01:30 +02:00
2020-09-07 00:19:48 +02:00
}
2020-09-30 20:56:55 +02:00
else if ( OSTYPE_IS_LINUX ( LoaderType ) | | ( LoaderType = = OSTYPE_LINEFI ) ) {
2020-09-08 23:25:26 +02:00
2020-09-30 20:56:55 +02:00
DBG ( " Closing events for Linux \n " ) ;
gBS - > CloseEvent ( OnReadyToBootEvent ) ;
gBS - > CloseEvent ( ExitBootServiceEvent ) ;
gBS - > CloseEvent ( mSimpleFileSystemChangeEvent ) ;
2020-09-08 11:33:35 +02:00
2020-09-30 20:56:55 +02:00
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
2023-06-28 21:01:41 +02:00
2021-09-28 10:28:45 +02:00
PatchACPI_OtherOS ( L " Linux " , false ) ;
2020-09-08 11:33:35 +02:00
}
2020-09-16 01:01:53 +02:00
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . LastBootedVolume ) {
2022-04-26 00:55:56 +02:00
if ( APFSTargetUUID . notNull ( ) ) {
2020-09-30 20:56:55 +02:00
// Jief : we need to LoaderPath. If not, GUI can't know which target was selected.
SetStartupDiskVolume ( Volume , LoaderPath ) ;
} else {
// Jief : I'm not sure why NullXStringW was given if LoaderType == OSTYPE_OSX.
// Let's do it like it was before when not in case of APFSTargetUUID
SetStartupDiskVolume ( Volume , LoaderType = = OSTYPE_OSX ? NullXStringW : LoaderPath ) ;
}
2021-02-02 10:02:21 +01:00
} else if ( gSettings . Boot . DefaultVolume . notEmpty ( ) ) {
2020-09-30 20:56:55 +02:00
// DefaultVolume specified in Config.plist or in Boot Option
// we'll remove macOS Startup Disk vars which may be present if it is used
// to reboot into another volume
RemoveStartupDiskVolume ( ) ;
2020-09-07 19:33:38 +02:00
}
2020-09-30 20:56:55 +02:00
/*
2020-09-07 19:33:38 +02:00
{
2020-09-30 20:56:55 +02:00
// UINT32 machineSignature = 0;
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE * FadtPointer = NULL ;
EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * Facs = NULL ;
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
// DBG("---dump hibernations data---\n");
FadtPointer = GetFadt ( ) ;
if ( FadtPointer ! = NULL ) {
Facs = ( EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * ) ( UINTN ) ( FadtPointer - > FirmwareCtrl ) ;
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
DBG ( " Firmware wake address=%08lx \n " , Facs - > FirmwareWakingVector ) ;
DBG ( " Firmware wake 64 addr=%16llx \n " , Facs - > XFirmwareWakingVector ) ;
DBG ( " Hardware signature =%08lx \n " , Facs - > HardwareSignature ) ;
DBG ( " GlobalLock =%08lx \n " , Facs - > GlobalLock ) ;
DBG ( " Flags =%08lx \n " , Facs - > Flags ) ;
DBG ( " HS at offset 0x%08X \n " , OFFSET_OF ( EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE , HardwareSignature ) ) ;
// machineSignature = Facs->HardwareSignature;
}
}
*/
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
BeginExternalScreen ( OSFLAG_ISSET ( Flags , OSFLAG_USEGRAPHICS ) /*, L"Booting OS"*/ ) ;
2020-09-07 00:19:48 +02:00
2020-09-30 20:56:55 +02:00
if ( ! OSTYPE_IS_WINDOWS ( LoaderType ) & & ! OSTYPE_IS_LINUX ( LoaderType ) ) {
if ( OSFLAG_ISSET ( Flags , OSFLAG_USEGRAPHICS ) ) {
// save orig OutputString and replace it with
// null implementation
ConOutOutputString = gST - > ConOut - > OutputString ;
gST - > ConOut - > OutputString = NullConOutOutputString ;
}
// Initialize the boot screen
if ( EFI_ERROR ( Status = InitBootScreen ( this ) ) ) {
if ( Status ! = EFI_ABORTED ) DBG ( " Failed to initialize custom boot screen: %s! \n " , efiStrError ( Status ) ) ;
}
else if ( EFI_ERROR ( Status = LockBootScreen ( ) ) ) {
DBG ( " Failed to lock custom boot screen: %s! \n " , efiStrError ( Status ) ) ;
}
} // !OSTYPE_IS_WINDOWS
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
if ( OSTYPE_IS_OSX ( LoaderType ) | |
OSTYPE_IS_OSX_RECOVERY ( LoaderType ) | |
OSTYPE_IS_OSX_INSTALLER ( LoaderType ) ) {
2020-09-16 19:50:16 +02:00
2020-09-30 20:56:55 +02:00
if ( DoHibernateWake ) {
DBG ( " Closing events for wake \n " ) ;
gBS - > CloseEvent ( OnReadyToBootEvent ) ;
// gBS->CloseEvent (ExitBootServiceEvent); // Jief : we don't need that anymore, if we continue to use OC onExtBootService event
gBS - > CloseEvent ( mSimpleFileSystemChangeEvent ) ;
2023-06-28 21:01:41 +02:00
2020-09-30 20:56:55 +02:00
// When doing hibernate wake, save to DataHub only up to initial size of log
2021-09-28 10:28:45 +02:00
SavePreBootLog = false ;
2020-09-30 20:56:55 +02:00
} else {
// delete boot-switch-vars if exists
2022-04-26 00:55:56 +02:00
Status = gRT - > SetVariable ( L " boot-switch-vars " , gEfiAppleBootGuid ,
2020-09-30 20:56:55 +02:00
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
0 , NULL ) ;
2022-04-26 00:55:56 +02:00
DeleteNvramVariable ( L " IOHibernateRTCVariables " , gEfiAppleBootGuid ) ;
DeleteNvramVariable ( L " boot-image " , gEfiAppleBootGuid ) ;
2020-09-30 20:56:55 +02:00
}
SetupBooterLog ( ! DoHibernateWake ) ;
2020-09-07 00:19:48 +02:00
2020-09-08 11:33:35 +02:00
XStringW LoadOptionsAsXStringW = SWPrintf ( " %ls %s " , Basename ( LoaderPath . wc_str ( ) ) , LoadOptions . ConcatAll ( " " _XS8 ) . c_str ( ) ) ;
LoadedImage - > LoadOptions = ( void * ) LoadOptionsAsXStringW . wc_str ( ) ;
LoadedImage - > LoadOptionsSize = ( UINT32 ) LoadOptionsAsXStringW . sizeInBytesIncludingTerminator ( ) ;
2020-09-07 00:19:48 +02:00
2021-03-27 19:53:30 +01:00
DBG ( " Kernel quirks \n " ) ;
2022-01-28 19:47:15 +01:00
DBG ( " ACPCL %d AXCL %d AXEM %d AXFB %d CSG %d DIM %d DLJ %d DRC %d DPM %d EBTFF %d EDI %d IPBS %d LKP %d PNKD %d PTKP %d TPD %d XPL %d PCC %d \n " ,
2021-03-27 19:53:30 +01:00
mOpenCoreConfiguration . Kernel . Quirks . AppleCpuPmCfgLock ,
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmCfgLock ,
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmExtraMsrs ,
mOpenCoreConfiguration . Kernel . Quirks . AppleXcpmForceBoost ,
mOpenCoreConfiguration . Kernel . Quirks . CustomSmbiosGuid ,
mOpenCoreConfiguration . Kernel . Quirks . DisableIoMapper ,
mOpenCoreConfiguration . Kernel . Quirks . DisableLinkeditJettison ,
mOpenCoreConfiguration . Kernel . Quirks . DisableRtcChecksum ,
2021-09-23 12:36:41 +02:00
mOpenCoreConfiguration . Kernel . Emulate . DummyPowerManagement ,
2021-09-25 10:51:37 +02:00
mOpenCoreConfiguration . Kernel . Quirks . ExtendBTFeatureFlags ,
2021-03-27 19:53:30 +01:00
mOpenCoreConfiguration . Kernel . Quirks . ExternalDiskIcons ,
mOpenCoreConfiguration . Kernel . Quirks . IncreasePciBarSize ,
mOpenCoreConfiguration . Kernel . Quirks . LapicKernelPanic ,
mOpenCoreConfiguration . Kernel . Quirks . PanicNoKextDump ,
mOpenCoreConfiguration . Kernel . Quirks . PowerTimeoutKernelPanic ,
mOpenCoreConfiguration . Kernel . Quirks . ThirdPartyDrives ,
2022-01-28 19:47:15 +01:00
mOpenCoreConfiguration . Kernel . Quirks . XhciPortLimit ,
mOpenCoreConfiguration . Kernel . Quirks . ProvideCurrentCpuInfo ) ;
2020-09-30 20:56:55 +02:00
DBG ( " Closing log \n " ) ;
if ( SavePreBootLog ) {
2020-10-17 15:01:33 +02:00
Status = SaveBooterLog ( & self . getCloverDir ( ) , PREBOOT_LOG ) ;
2020-09-30 20:56:55 +02:00
}
2021-05-04 12:26:54 +02:00
# ifdef JIEF_DEBUG
//Status = EFI_NOT_FOUND;
Status = gBS - > StartImage ( ImageHandle , 0 , NULL ) ; // point to OcStartImage from OC
# else
Status = gBS - > StartImage ( ImageHandle , 0 , NULL ) ; // point to OcStartImage from OC
# endif
if ( EFI_ERROR ( Status ) ) {
// Ideally, we would return to the menu, displaying an error message
// Truth is that we get a black screen before seeing the menu again.
// If I remember well, we get a freeze in BdsLibConnectAllEfi()
// I'm guessing there is a lot of patching done for booting.
// To be able to go back to the menu and boot another thing,
// we must undo all the patching...
// Here is a quick, not as bad as a black screen solution : a text message and a reboot !
DBG ( " StartImage failed : %s \n " , efiStrError ( Status ) ) ;
SaveBooterLog ( & self . getCloverDir ( ) , PREBOOT_LOG ) ;
egSetGraphicsModeEnabled ( false ) ;
printf ( " StartImage failed : %s \n " , efiStrError ( Status ) ) ;
PauseForKey ( " Reboot needed. " _XS8 ) ;
// Attempt warm reboot
gRT - > ResetSystem ( EfiResetWarm , EFI_SUCCESS , 0 , NULL ) ;
// Warm reboot may not be supported attempt cold reboot
gRT - > ResetSystem ( EfiResetCold , EFI_SUCCESS , 0 , NULL ) ;
// Terminate the screen and just exit
return ;
}
2020-09-30 20:56:55 +02:00
} else {
2021-03-22 19:02:19 +01:00
StartEFILoadedImage ( ImageHandle , LoadOptions , NullXStringW , LoaderPath . basename ( ) , NULL ) ;
2020-09-30 20:56:55 +02:00
}
// Unlock boot screen
if ( EFI_ERROR ( Status = UnlockBootScreen ( ) ) ) {
DBG ( " Failed to unlock custom boot screen: %s! \n " , efiStrError ( Status ) ) ;
}
if ( OSFLAG_ISSET ( Flags , OSFLAG_USEGRAPHICS ) ) {
// return back orig OutputString
gST - > ConOut - > OutputString = ConOutOutputString ;
}
2020-09-07 00:19:48 +02:00
2023-06-28 21:01:41 +02:00
2020-09-30 20:56:55 +02:00
FinishExternalScreen ( ) ;
2023-06-28 21:01:41 +02:00
2020-02-15 15:51:18 +01:00
}
2020-02-18 19:49:54 +01:00
2020-02-15 15:51:18 +01:00
2020-10-03 19:02:31 +02:00
void LEGACY_ENTRY : : StartLegacy ( )
2020-02-15 15:51:18 +01:00
{
EFI_STATUS Status = EFI_UNSUPPORTED ;
// Unload EmuVariable before booting legacy.
// This is not needed in most cases, but it seems to interfere with legacy OS
// booted on some UEFI bioses, such as Phoenix UEFI 2.0
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . LastBootedVolume ) {
2020-05-01 18:26:28 +02:00
SetStartupDiskVolume ( Volume , NullXStringW ) ;
2021-02-02 10:02:21 +01:00
} else if ( gSettings . Boot . DefaultVolume . notEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
// DefaultVolume specified in Config.plist:
// we'll remove macOS Startup Disk vars which may be present if it is used
// to reboot into another volume
RemoveStartupDiskVolume ( ) ;
}
2020-04-01 14:57:32 +02:00
egClearScreen ( & MenuBackgroundPixel ) ;
2021-09-28 10:28:45 +02:00
BeginExternalScreen ( true /*, L"Booting Legacy OS"*/ ) ;
2020-03-30 10:34:16 +02:00
XImage BootLogoX ;
2020-10-03 19:02:31 +02:00
BootLogoX . LoadXImage ( & ThemeX . getThemeDir ( ) , Volume - > LegacyOS - > IconName ) ;
2020-03-30 10:34:16 +02:00
BootLogoX . Draw ( ( UGAWidth - BootLogoX . GetWidth ( ) ) > > 1 ,
( UGAHeight - BootLogoX . GetHeight ( ) ) > > 1 ) ;
2020-02-15 15:51:18 +01:00
//try my LegacyBoot
2020-05-01 18:26:28 +02:00
switch ( Volume - > BootType ) {
2020-02-15 15:51:18 +01:00
case BOOTING_BY_CD :
2020-05-01 18:26:28 +02:00
Status = bootElTorito ( Volume ) ;
2020-02-15 15:51:18 +01:00
break ;
case BOOTING_BY_MBR :
2020-05-01 18:26:28 +02:00
Status = bootMBR ( Volume ) ;
2020-02-15 15:51:18 +01:00
break ;
case BOOTING_BY_PBR :
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . LegacyBoot = = " LegacyBiosDefault " _XS8 ) {
Status = bootLegacyBiosDefault ( gSettings . Boot . LegacyBiosDefaultEntry ) ;
} else if ( gSettings . Boot . LegacyBoot = = " PBRtest " _XS8 ) {
2020-05-01 18:26:28 +02:00
Status = bootPBRtest ( Volume ) ;
2021-02-02 10:02:21 +01:00
} else if ( gSettings . Boot . LegacyBoot = = " PBRsata " _XS8 ) {
2021-09-28 10:28:45 +02:00
Status = bootPBR ( Volume , true ) ;
2020-02-15 15:51:18 +01:00
} else {
// default
2021-09-28 10:28:45 +02:00
Status = bootPBR ( Volume , false ) ;
2020-02-15 15:51:18 +01:00
}
break ;
default :
break ;
}
CheckError ( Status , L " while LegacyBoot " ) ;
2020-02-18 19:49:54 +01:00
FinishExternalScreen ( ) ;
2020-02-15 15:51:18 +01:00
}
//
// pre-boot tool functions
//
2020-10-03 19:02:31 +02:00
void REFIT_MENU_ENTRY_LOADER_TOOL : : StartTool ( )
2020-02-15 15:51:18 +01:00
{
2020-05-01 18:26:28 +02:00
DBG ( " Start Tool: %ls \n " , LoaderPath . wc_str ( ) ) ;
2020-04-01 14:57:32 +02:00
egClearScreen ( & MenuBackgroundPixel ) ;
2021-02-06 18:16:46 +01:00
// assumes "Start <title>" as assigned below
BeginExternalScreen ( OSFLAG_ISSET ( Flags , OSFLAG_USEGRAPHICS ) /*, &Entry->Title[6]*/ ) ; // Shouldn't we check that length of Title is at least 6 ?
2021-03-23 22:23:44 +01:00
StartEFIImage ( DevicePath , LoadOptions , NullXStringW , LoaderPath . basename ( ) , NULL , NULL ) ;
2021-03-22 19:02:19 +01:00
FinishExternalScreen ( ) ;
2020-02-15 15:51:18 +01:00
}
//
// pre-boot driver functions
//
2020-10-03 19:02:31 +02:00
static void ScanDriverDir ( IN CONST CHAR16 * Path , OUT EFI_HANDLE * * DriversToConnect , OUT UINTN * DriversToConnectNum )
2020-02-15 15:51:18 +01:00
{
EFI_STATUS Status ;
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
EFI_HANDLE DriverHandle ;
EFI_DRIVER_BINDING_PROTOCOL * DriverBinding ;
UINTN DriversArrSize ;
UINTN DriversArrNum ;
EFI_HANDLE * DriversArr ;
2021-09-28 15:54:31 +02:00
XBool Skip ;
2020-02-15 15:51:18 +01:00
UINT8 AptioBlessed ;
STATIC CHAR16 CONST * CONST AptioNames [ ] = {
L " AptioMemoryFix " ,
L " AptioFix3Drv " ,
L " AptioFix2Drv " ,
L " AptioFixDrv " ,
L " LowMemFix "
} ;
STATIC UINT8 CONST AptioIndices [ ] = {
OFFSET_OF ( DRIVERS_FLAGS , AptioMemFixLoaded ) ,
OFFSET_OF ( DRIVERS_FLAGS , AptioFix3Loaded ) ,
OFFSET_OF ( DRIVERS_FLAGS , AptioFix2Loaded ) ,
OFFSET_OF ( DRIVERS_FLAGS , AptioFixLoaded ) ,
OFFSET_OF ( DRIVERS_FLAGS , MemFixLoaded )
} ;
DriversArrSize = 0 ;
DriversArrNum = 0 ;
DriversArr = NULL ;
2021-11-01 19:26:41 +01:00
// OpenRuntimeEfiName.setEmpty();
2020-02-15 15:51:18 +01:00
//only one driver with highest priority will obtain status "Loaded"
2020-10-03 19:02:31 +02:00
DirIterOpen ( & self . getCloverDir ( ) , Path , & DirIter ) ;
2021-09-28 10:28:45 +02:00
# define BOOLEAN_AT_INDEX(k) (*(XBool*)((UINTN)&gDriversFlags + AptioIndices[(k)]))
2020-08-31 11:00:52 +02:00
for ( size_t i = 0 ; i ! = ARRAY_SIZE ( AptioIndices ) ; + + i )
2021-09-28 10:28:45 +02:00
BOOLEAN_AT_INDEX ( i ) = false ;
2020-02-15 15:51:18 +01:00
AptioBlessed = ( UINT8 ) ARRAY_SIZE ( AptioNames ) ;
while ( DirIterNext ( & DirIter , 2 , L " *.efi " , & DirEntry ) ) {
2020-08-31 11:00:52 +02:00
size_t i ;
2020-02-15 15:51:18 +01:00
for ( i = 0 ; i ! = ARRAY_SIZE ( AptioNames ) ; + + i )
if ( StrStr ( DirEntry - > FileName , AptioNames [ i ] ) ! = NULL )
break ;
if ( ( ( UINT8 ) i ) > = AptioBlessed )
continue ;
AptioBlessed = ( UINT8 ) i ;
if ( ! i )
break ;
}
DirIterClose ( & DirIter ) ;
// look through contents of the directory
2020-10-03 19:02:31 +02:00
DirIterOpen ( & self . getCloverDir ( ) , Path , & DirIter ) ;
2020-02-15 15:51:18 +01:00
while ( DirIterNext ( & DirIter , 2 , L " *.efi " , & DirEntry ) ) {
Skip = ( DirEntry - > FileName [ 0 ] = = L ' . ' ) ;
2020-08-31 11:00:52 +02:00
for ( size_t i = 0 ; i < gSettings . DisabledDriverArray . size ( ) ; i + + ) {
if ( StrStr ( DirEntry - > FileName , gSettings . DisabledDriverArray [ i ] . wc_str ( ) ) ! = NULL ) {
2021-09-28 10:28:45 +02:00
Skip = true ; // skip this
2020-02-15 15:51:18 +01:00
break ;
}
}
if ( Skip ) {
continue ;
}
2021-09-28 10:28:45 +02:00
if ( LStringW ( DirEntry - > FileName ) . startWith ( " ._ " ) ) {
continue ;
}
2020-09-14 15:01:30 +02:00
if ( LStringW ( DirEntry - > FileName ) . containsIC ( " OcQuirks " ) ) {
continue ;
}
if ( LStringW ( DirEntry - > FileName ) . containsIC ( " AptioMemoryFix " ) ) {
2020-09-10 20:35:10 +02:00
continue ;
}
2021-11-01 19:26:41 +01:00
2020-10-09 08:05:51 +02:00
if ( LStringW ( DirEntry - > FileName ) . containsIC ( " OpenRuntime " ) ) {
2021-11-01 19:26:41 +01:00
if ( ! OpenRuntimeEfiName . isEmpty ( ) ) {
DBG ( " - OpenRuntime already detected \n " ) ;
continue ;
}
2021-10-29 21:56:32 +02:00
if ( LStringW ( DirEntry - > FileName ) . isEqualIC ( " OpenRuntime-v12.efi " ) & & LString8 ( OPEN_CORE_VERSION ) . isEqual ( " 0.7.5 " ) ) {
OpenRuntimeEfiName . takeValueFrom ( DirEntry - > FileName ) ;
2021-11-01 19:26:41 +01:00
DBG ( " - OpenRuntime-v12 for 075 taken from %ls \n " , getDriversPath ( ) . wc_str ( ) ) ;
2021-10-29 21:56:32 +02:00
} else
2021-09-25 10:03:31 +02:00
if ( LStringW ( DirEntry - > FileName ) . isEqualIC ( " OpenRuntime-v12.efi " ) & & LString8 ( OPEN_CORE_VERSION ) . isEqual ( " 0.7.3 " ) ) {
OpenRuntimeEfiName . takeValueFrom ( DirEntry - > FileName ) ;
2021-11-01 19:26:41 +01:00
DBG ( " - OpenRuntime-v12 for 073 taken from %ls \n " , getDriversPath ( ) . wc_str ( ) ) ;
2021-09-25 10:03:31 +02:00
} else
if ( LStringW ( DirEntry - > FileName ) . isEqualIC ( " OpenRuntime-v11.efi " ) & & LString8 ( OPEN_CORE_VERSION ) . isEqual ( " 0.6.5 " ) ) {
OpenRuntimeEfiName . takeValueFrom ( DirEntry - > FileName ) ;
2021-11-01 19:26:41 +01:00
DBG ( " - OpenRuntime-v11 for 065 taken from %ls \n " , getDriversPath ( ) . wc_str ( ) ) ;
2021-09-25 10:03:31 +02:00
} else
if ( LStringW ( DirEntry - > FileName ) . isEqualIC ( " OpenRuntime-v11.efi " ) & & LString8 ( OPEN_CORE_VERSION ) . isEqual ( " 0.6.1 " ) ) {
OpenRuntimeEfiName . takeValueFrom ( DirEntry - > FileName ) ;
2021-11-01 19:26:41 +01:00
DBG ( " - OpenRuntime-v11 for 061 taken from %ls \n " , getDriversPath ( ) . wc_str ( ) ) ;
2021-09-25 10:03:31 +02:00
} else
if ( OpenRuntimeEfiName . isEmpty ( ) ) {
OpenRuntimeEfiName . takeValueFrom ( DirEntry - > FileName ) ;
}
2020-10-09 08:05:51 +02:00
continue ;
}
2020-08-31 11:00:52 +02:00
{
size_t i ;
2020-08-31 14:24:00 +02:00
// either AptioMem, AptioFix* or LowMemFix exclusively
for ( i = 0 ; i ! = ARRAY_SIZE ( AptioNames ) ; + + i )
if ( StrStr ( DirEntry - > FileName , AptioNames [ i ] ) ! = NULL )
break ;
if ( i ! = ARRAY_SIZE ( AptioNames ) ) {
if ( ( ( UINT8 ) i ) ! = AptioBlessed )
continue ;
if ( AptioBlessed < ( UINT8 ) ARRAY_SIZE ( AptioIndices ) )
2021-09-28 10:28:45 +02:00
BOOLEAN_AT_INDEX ( AptioBlessed ) = true ;
2020-08-31 14:24:00 +02:00
AptioBlessed = ( UINT8 ) ARRAY_SIZE ( AptioNames ) ;
}
2020-08-31 11:00:52 +02:00
}
2020-02-15 15:51:18 +01:00
# undef BOOLEAN_AT_INDEX
2021-02-06 18:16:46 +01:00
XStringW FileName = SWPrintf ( " %ls \\ %ls \\ %ls " , self . getCloverDirFullPath ( ) . wc_str ( ) , Path , DirEntry - > FileName ) ;
2021-03-22 19:02:19 +01:00
Status = StartEFIImage ( FileDevicePath ( self . getSelfLoadedImage ( ) . DeviceHandle , FileName ) , NullXString8Array , LStringW ( DirEntry - > FileName ) , XStringW ( ) . takeValueFrom ( DirEntry - > FileName ) , NULL , & DriverHandle ) ;
2020-02-15 15:51:18 +01:00
if ( EFI_ERROR ( Status ) ) {
continue ;
}
2020-11-24 14:01:32 +01:00
if ( FileName . containsIC ( " AudioDxe " ) ) {
2020-06-18 18:08:00 +02:00
AudioDriverHandle = DriverHandle ;
}
2020-11-24 14:01:32 +01:00
if ( FileName . containsIC ( " EmuVariable " ) ) {
2021-09-28 10:28:45 +02:00
gDriversFlags . EmuVariableLoaded = true ;
2020-11-24 14:01:32 +01:00
} else if ( FileName . containsIC ( " Video " ) ) {
2021-09-28 10:28:45 +02:00
gDriversFlags . VideoLoaded = true ;
2020-11-24 14:01:32 +01:00
} else if ( FileName . containsIC ( " Partition " ) ) {
2021-09-28 10:28:45 +02:00
gDriversFlags . PartitionLoaded = true ;
2020-11-24 14:01:32 +01:00
} else if ( FileName . containsIC ( " HFS " ) ) {
2021-09-28 10:28:45 +02:00
gDriversFlags . HFSLoaded = true ;
2020-11-24 14:01:32 +01:00
} else if ( FileName . containsIC ( " apfs " ) ) {
2021-09-28 10:28:45 +02:00
gDriversFlags . APFSLoaded = true ;
2020-02-15 15:51:18 +01:00
}
if ( DriverHandle ! = NULL & & DriversToConnectNum ! = NULL & & DriversToConnect ! = NULL ) {
// driver loaded - check for EFI_DRIVER_BINDING_PROTOCOL
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( DriverHandle , & gEfiDriverBindingProtocolGuid , ( void * * ) & DriverBinding ) ;
2020-02-15 15:51:18 +01:00
if ( ! EFI_ERROR ( Status ) & & DriverBinding ! = NULL ) {
DBG ( " - driver needs connecting \n " ) ;
// standard UEFI driver - we would reconnect after loading - add to array
if ( DriversArrSize = = 0 ) {
// new array
DriversArrSize = 16 ;
2020-08-15 15:47:56 +02:00
DriversArr = ( __typeof__ ( DriversArr ) ) AllocateZeroPool ( sizeof ( EFI_HANDLE ) * DriversArrSize ) ;
2020-02-15 15:51:18 +01:00
} else if ( DriversArrNum + 1 = = DriversArrSize ) {
// extend array
DriversArr = ( __typeof__ ( DriversArr ) ) ReallocatePool ( DriversArrSize , DriversArrSize + 16 , DriversArr ) ;
DriversArrSize + = 16 ;
}
DriversArr [ DriversArrNum ] = DriverHandle ;
2020-03-25 19:32:44 +01:00
// DBG(" driver %ls included with Binding=%X\n", FileName, DriverBinding);
2020-02-15 15:51:18 +01:00
DriversArrNum + + ;
// we'll make array terminated
DriversArr [ DriversArrNum ] = NULL ;
}
}
}
Status = DirIterClose ( & DirIter ) ;
if ( Status ! = EFI_NOT_FOUND ) {
2020-10-03 19:02:31 +02:00
CheckError ( Status , SWPrintf ( " while scanning the %ls directory " , Path ) . wc_str ( ) ) ;
2020-02-15 15:51:18 +01:00
}
if ( DriversToConnectNum ! = NULL & & DriversToConnect ! = NULL ) {
* DriversToConnectNum = DriversArrNum ;
* DriversToConnect = DriversArr ;
}
}
/**
* Some UEFI ' s ( like HPQ EFI from HP notebooks ) have DiskIo protocols
* opened BY_DRIVER ( by Partition driver in HP case ) even when no file system
* is produced from this DiskIo . This then blocks our FS drivers from connecting
* and producing file systems .
* To fix it : we will disconnect drivers that connected to DiskIo BY_DRIVER
* if this is partition volume and if those drivers did not produce file system .
*/
2020-10-03 19:02:31 +02:00
void DisconnectInvalidDiskIoChildDrivers ( void )
2020-02-15 15:51:18 +01:00
{
EFI_STATUS Status ;
UINTN HandleCount = 0 ;
UINTN Index ;
UINTN OpenInfoIndex ;
EFI_HANDLE * Handles = NULL ;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * Fs ;
EFI_BLOCK_IO_PROTOCOL * BlockIo ;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY * OpenInfo ;
UINTN OpenInfoCount ;
2021-09-28 15:54:31 +02:00
XBool Found ;
2020-02-15 15:51:18 +01:00
DBG ( " Searching for invalid DiskIo BY_DRIVER connects: " ) ;
//
// Get all DiskIo handles
//
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiDiskIoProtocolGuid , NULL , & HandleCount , & Handles ) ;
if ( EFI_ERROR ( Status ) | | HandleCount = = 0 ) {
DBG ( " no DiskIo handles \n " ) ;
return ;
}
//
// Check every DiskIo handle
//
2021-09-28 10:28:45 +02:00
Found = false ;
2020-02-15 15:51:18 +01:00
for ( Index = 0 ; Index < HandleCount ; Index + + ) {
//DBG("\n");
//DBG(" - Handle %p:", Handles[Index]);
//
// If this is not partition - skip it.
// This is then whole disk and DiskIo
// should be opened here BY_DRIVER by Partition driver
// to produce partition volumes.
//
Status = gBS - > HandleProtocol (
Handles [ Index ] ,
& gEfiBlockIoProtocolGuid ,
2020-10-03 19:02:31 +02:00
( void * * ) & BlockIo
2020-02-15 15:51:18 +01:00
) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-08-25 17:35:19 +02:00
//DBG(" BlockIo: %s - skipping\n", efiStrError(Status));
2020-02-15 15:51:18 +01:00
continue ;
}
if ( BlockIo - > Media = = NULL ) {
//DBG(" BlockIo: no media - skipping\n");
continue ;
}
if ( ! BlockIo - > Media - > LogicalPartition ) {
//DBG(" BlockIo: whole disk - skipping\n");
continue ;
}
//DBG(" BlockIo: partition");
//
// If SimpleFileSystem is already produced - skip it, this is ok
//
Status = gBS - > HandleProtocol (
Handles [ Index ] ,
& gEfiSimpleFileSystemProtocolGuid ,
2020-10-03 19:02:31 +02:00
( void * * ) & Fs
2020-02-15 15:51:18 +01:00
) ;
if ( Status = = EFI_SUCCESS ) {
//DBG(" FS: ok - skipping\n");
continue ;
}
//DBG(" FS: no");
//
// If no SimpleFileSystem on this handle but DiskIo is opened BY_DRIVER
// then disconnect this connection
//
Status = gBS - > OpenProtocolInformation (
Handles [ Index ] ,
& gEfiDiskIoProtocolGuid ,
& OpenInfo ,
& OpenInfoCount
) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-02-15 15:51:18 +01:00
//DBG(" OpenInfo: no - skipping\n");
continue ;
}
//DBG(" OpenInfo: %d", OpenInfoCount);
for ( OpenInfoIndex = 0 ; OpenInfoIndex < OpenInfoCount ; OpenInfoIndex + + ) {
if ( ( OpenInfo [ OpenInfoIndex ] . Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER ) = = EFI_OPEN_PROTOCOL_BY_DRIVER ) {
if ( ! Found ) {
DBG ( " \n " ) ;
}
2021-09-28 10:28:45 +02:00
Found = true ;
2020-02-15 15:51:18 +01:00
Status = gBS - > DisconnectController ( Handles [ Index ] , OpenInfo [ OpenInfoIndex ] . AgentHandle , NULL ) ;
2020-08-25 17:35:19 +02:00
//DBG(" BY_DRIVER Agent: %p, Disconnect: %s", OpenInfo[OpenInfoIndex].AgentHandle, efiStrError(Status));
2020-10-11 08:06:50 +02:00
DBG ( " - Handle %llx with DiskIo, is Partition, no Fs, BY_DRIVER Agent: %llx, Disconnect: %s \n " , ( uintptr_t ) Handles [ Index ] , ( uintptr_t ) ( OpenInfo [ OpenInfoIndex ] . AgentHandle ) , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
}
}
2020-04-23 11:08:10 +02:00
FreePool ( OpenInfo ) ;
2020-02-15 15:51:18 +01:00
}
FreePool ( Handles ) ;
if ( ! Found ) {
DBG ( " not found, all ok \n " ) ;
}
}
2020-10-03 19:02:31 +02:00
void DisconnectSomeDevices ( void )
2020-02-15 15:51:18 +01:00
{
EFI_STATUS Status ;
UINTN HandleCount ;
UINTN Index , Index2 ;
EFI_HANDLE * Handles ;
EFI_HANDLE * ControllerHandles ;
UINTN ControllerHandleCount ;
EFI_BLOCK_IO_PROTOCOL * BlockIo = NULL ;
// EFI_DISK_IO_PROTOCOL *DiskIo = NULL;
EFI_PCI_IO_PROTOCOL * PciIo = NULL ;
// EFI_FILE_PROTOCOL *RootFP = NULL;
// EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *VolumeFS = NULL;
PCI_TYPE00 Pci ;
2021-05-23 05:18:47 +02:00
CHAR16 * DriverName = NULL ;
EFI_COMPONENT_NAME_PROTOCOL * CompName = NULL ;
2020-02-15 15:51:18 +01:00
if ( gDriversFlags . PartitionLoaded ) {
DBG ( " Partition driver loaded: " ) ;
// get all BlockIo handles
HandleCount = 0 ;
Handles = NULL ;
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiBlockIoProtocolGuid , NULL , & HandleCount , & Handles ) ;
if ( Status = = EFI_SUCCESS ) {
for ( Index = 0 ; Index < HandleCount ; Index + + ) {
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( Handles [ Index ] , & gEfiBlockIoProtocolGuid , ( void * * ) & BlockIo ) ;
2020-02-15 15:51:18 +01:00
if ( EFI_ERROR ( Status ) ) {
continue ;
}
if ( BlockIo - > Media - > BlockSize = = 2048 ) {
// disconnect CD controller
Status = gBS - > DisconnectController ( Handles [ Index ] , NULL , NULL ) ;
2020-08-25 17:35:19 +02:00
DBG ( " CD disconnect %s " , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
}
}
/* for (Index = 0; Index < HandleCount; Index++) {
Status = gBS - > DisconnectController ( Handles [ Index ] , NULL , NULL ) ;
} */
FreePool ( Handles ) ;
}
DBG ( " \n " ) ;
}
if ( ( gDriversFlags . HFSLoaded ) | | ( gDriversFlags . APFSLoaded ) ) {
2020-02-18 19:49:54 +01:00
if ( gDriversFlags . HFSLoaded ) {
DBG ( " HFS+ driver loaded \n " ) ;
2020-02-15 15:51:18 +01:00
}
if ( gDriversFlags . APFSLoaded ) {
DBG ( " APFS driver loaded \n " ) ;
}
// get all FileSystem handles
ControllerHandleCount = 0 ;
ControllerHandles = NULL ;
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiSimpleFileSystemProtocolGuid , NULL , & ControllerHandleCount , & ControllerHandles ) ;
2020-04-23 11:08:10 +02:00
/* if (!EFI_ERROR(Status)) {
2020-02-15 15:51:18 +01:00
for ( Index2 = 0 ; Index2 < ControllerHandleCount ; Index2 + + ) {
Status = gBS - > DisconnectController ( ControllerHandles [ Index2 ] ,
NULL , NULL ) ;
2020-08-25 17:35:19 +02:00
DBG ( " Driver [%d] disconnect %s \n " , Index2 , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
}
} */
HandleCount = 0 ;
Handles = NULL ;
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiComponentNameProtocolGuid , NULL , & HandleCount , & Handles ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-02-15 15:51:18 +01:00
for ( Index = 0 ; Index < HandleCount ; Index + + ) {
Status = gBS - > OpenProtocol (
Handles [ Index ] ,
2022-04-26 00:55:56 +02:00
gEfiComponentNameProtocolGuid ,
2020-10-03 19:02:31 +02:00
( void * * ) & CompName ,
2020-02-15 15:51:18 +01:00
gImageHandle ,
NULL ,
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ;
if ( EFI_ERROR ( Status ) ) {
2020-08-25 17:35:19 +02:00
// DBG("CompName %s\n", efiStrError(Status));
2020-02-15 15:51:18 +01:00
continue ;
}
2021-05-23 05:18:47 +02:00
// 2021-05, Jief : PG7 had a crash. In some cases, CompName->GetDriverName == NULL.
if ( CompName - > GetDriverName = = NULL ) {
DBG ( " DisconnectSomeDevices: GetDriverName CompName=%lld, CompName->GetDriverName=NULL \n " , uintptr_t ( CompName ) ) ;
continue ;
}
2020-02-15 15:51:18 +01:00
Status = CompName - > GetDriverName ( CompName , " eng " , & DriverName ) ;
if ( EFI_ERROR ( Status ) ) {
continue ;
}
if ( ( StriStr ( DriverName , L " HFS " ) ) | | ( StriStr ( DriverName , L " apfs " ) ) ) {
for ( Index2 = 0 ; Index2 < ControllerHandleCount ; Index2 + + ) {
Status = gBS - > DisconnectController ( ControllerHandles [ Index2 ] ,
Handles [ Index ] , NULL ) ;
2021-05-23 05:18:47 +02:00
//DBG("Disconnect [%ls] from %llX: %s\n", DriverName, uintptr_t(ControllerHandles[Index2]), efiStrError(Status));
2020-02-15 15:51:18 +01:00
}
}
}
FreePool ( Handles ) ;
}
// DBG("\n");
FreePool ( ControllerHandles ) ;
}
if ( gDriversFlags . VideoLoaded ) {
DBG ( " Video driver loaded: " ) ;
// get all PciIo handles
HandleCount = 0 ;
Handles = NULL ;
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiPciIoProtocolGuid , NULL , & HandleCount , & Handles ) ;
if ( Status = = EFI_SUCCESS ) {
for ( Index = 0 ; Index < HandleCount ; Index + + ) {
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( Handles [ Index ] , & gEfiPciIoProtocolGuid , ( void * * ) & PciIo ) ;
2020-02-15 15:51:18 +01:00
if ( EFI_ERROR ( Status ) ) {
continue ;
}
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint32 , 0 , sizeof ( Pci ) / sizeof ( UINT32 ) , & Pci ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2021-09-28 10:28:45 +02:00
if ( IS_PCI_VGA ( & Pci ) = = true ) {
2020-02-15 15:51:18 +01:00
// disconnect VGA
Status = gBS - > DisconnectController ( Handles [ Index ] , NULL , NULL ) ;
2020-08-25 17:35:19 +02:00
DBG ( " disconnect %s " , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
}
}
}
FreePool ( Handles ) ;
}
DBG ( " \n " ) ;
}
if ( ! gFirmwareClover ) {
DisconnectInvalidDiskIoChildDrivers ( ) ;
}
}
2020-10-03 19:02:31 +02:00
void PatchVideoBios ( UINT8 * Edid )
2020-02-15 15:51:18 +01:00
{
2021-03-27 19:53:30 +01:00
if ( gSettings . Graphics . PatchVBiosBytes . notEmpty ( ) ) {
VideoBiosPatchBytes ( gSettings . Graphics . PatchVBiosBytes . getVBIOS_PATCH_BYTES ( ) , gSettings . Graphics . PatchVBiosBytes . getVBIOS_PATCH_BYTES_count ( ) ) ;
2020-02-15 15:51:18 +01:00
}
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . PatchVBios ) {
2020-02-15 15:51:18 +01:00
VideoBiosPatchNativeFromEdid ( Edid ) ;
}
}
2020-10-03 19:02:31 +02:00
static void LoadDrivers ( void )
2020-02-15 15:51:18 +01:00
{
EFI_STATUS Status ;
EFI_HANDLE * DriversToConnect = NULL ;
UINTN DriversToConnectNum = 0 ;
UINT8 * Edid ;
UINTN VarSize = 0 ;
2021-09-28 15:54:31 +02:00
XBool VBiosPatchNeeded ;
2020-02-15 15:51:18 +01:00
DbgHeader ( " LoadDrivers " ) ;
// load drivers from /efi/drivers
# if defined(MDE_CPU_X64)
if ( gFirmwareClover ) {
2020-10-03 19:02:31 +02:00
if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ BIOS " ) ) {
ScanDriverDir ( L " drivers \\ BIOS " , & DriversToConnect , & DriversToConnectNum ) ;
2020-02-15 15:51:18 +01:00
} else {
2020-10-03 19:02:31 +02:00
ScanDriverDir ( L " drivers64 " , & DriversToConnect , & DriversToConnectNum ) ;
2020-02-15 15:51:18 +01:00
}
} else {
2021-11-01 19:26:41 +01:00
OpenRuntimeEfiName . setEmpty ( ) ;
if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ 5142 " ) ) {
ScanDriverDir ( L " drivers \\ 5142 " , & DriversToConnect , & DriversToConnectNum ) ;
}
if ( FileExists ( & self . getCloverDir ( ) , L " drivers \\ UEFI " ) ) {
ScanDriverDir ( L " drivers \\ UEFI " , & DriversToConnect , & DriversToConnectNum ) ;
} else {
ScanDriverDir ( L " drivers64UEFI " , & DriversToConnect , & DriversToConnectNum ) ;
}
2020-02-15 15:51:18 +01:00
}
# else
2020-10-03 19:02:31 +02:00
ScanDriverDir ( L " drivers32 " , & DriversToConnect , & DriversToConnectNum ) ;
2020-02-15 15:51:18 +01:00
# endif
2021-03-27 19:53:30 +01:00
VBiosPatchNeeded = gSettings . Graphics . PatchVBios | | gSettings . Graphics . PatchVBiosBytes . getVBIOS_PATCH_BYTES_count ( ) > 0 ;
2020-02-15 15:51:18 +01:00
if ( VBiosPatchNeeded ) {
// check if it is already done in CloverEFI BiosVideo
Status = gRT - > GetVariable (
L " CloverVBiosPatchDone " ,
2022-04-26 00:55:56 +02:00
gEfiGlobalVariableGuid ,
2020-02-15 15:51:18 +01:00
NULL ,
& VarSize ,
NULL
) ;
if ( Status = = EFI_BUFFER_TOO_SMALL ) {
// var exists - it's done - let's not do it again
2021-09-28 10:28:45 +02:00
VBiosPatchNeeded = false ;
2020-02-15 15:51:18 +01:00
}
}
2021-03-26 10:43:15 +01:00
if ( ( gSettings . Graphics . EDID . CustomEDID . notEmpty ( ) & & gFirmwareClover ) | | ( VBiosPatchNeeded & & ! gDriversFlags . VideoLoaded ) ) {
2020-02-15 15:51:18 +01:00
// we have video bios patch - force video driver reconnect
DBG ( " Video bios patch requested or CustomEDID - forcing video reconnect \n " ) ;
2021-09-28 10:28:45 +02:00
gDriversFlags . VideoLoaded = true ;
2020-02-15 15:51:18 +01:00
DriversToConnectNum + + ;
}
2020-10-17 15:01:33 +02:00
UninitRefitLib ( ) ;
2020-02-15 15:51:18 +01:00
if ( DriversToConnectNum > 0 ) {
2021-02-06 18:16:46 +01:00
DBG ( " %llu drivers needs connecting ... \n " , DriversToConnectNum ) ;
2020-02-15 15:51:18 +01:00
// note: our platform driver protocol
// will use DriversToConnect - do not release it
RegisterDriversToHighestPriority ( DriversToConnect ) ;
if ( VBiosPatchNeeded ) {
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . EDID . CustomEDID . notEmpty ( ) ) {
Edid = gSettings . Graphics . EDID . CustomEDID . data ( ) ;
2020-02-15 15:51:18 +01:00
} else {
Edid = getCurrentEdid ( ) ;
}
DisconnectSomeDevices ( ) ;
PatchVideoBios ( Edid ) ;
2021-03-26 10:43:15 +01:00
if ( gSettings . Graphics . EDID . CustomEDID . isEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
FreePool ( Edid ) ;
}
} else {
DisconnectSomeDevices ( ) ;
}
BdsLibConnectAllDriversToAllControllers ( ) ;
// Boot speedup: remove temporary "BiosVideoBlockSwitchMode" RT var
// to unlock mode switching in CsmVideo
2022-04-26 00:55:56 +02:00
gRT - > SetVariable ( L " BiosVideoBlockSwitchMode " , gEfiGlobalVariableGuid , EFI_VARIABLE_BOOTSERVICE_ACCESS , 0 , NULL ) ;
2020-10-03 19:02:31 +02:00
} else {
BdsLibConnectAllEfi ( ) ; // jief : without any driver loaded, i couldn't see my CD, unless I call BdsLibConnectAllEfi
2020-02-15 15:51:18 +01:00
}
2020-10-17 15:01:33 +02:00
ReinitRefitLib ( ) ;
2020-02-15 15:51:18 +01:00
}
2020-10-03 19:02:31 +02:00
INTN FindDefaultEntry ( void )
2020-02-15 15:51:18 +01:00
{
INTN Index = - 1 ;
REFIT_VOLUME * Volume ;
2021-09-28 15:54:31 +02:00
XBool SearchForLoader ;
2020-02-15 15:51:18 +01:00
// DBG("FindDefaultEntry ...\n");
//DbgHeader("FindDefaultEntry");
//
// try to detect volume set by Startup Disk or previous Clover selection
// with broken nvram this requires emulation to be installed.
// enable emulation to determin efi-boot-device-data
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > InstallEmulation ( gEmuVariableControl ) ;
}
Index = FindStartupDiskVolume ( & MainMenu ) ;
if ( Index > = 0 ) {
2021-02-06 18:16:46 +01:00
DBG ( " Boot redirected to Entry %lld. '%ls' \n " , Index , MainMenu . Entries [ Index ] . Title . s ( ) ) ;
2020-02-15 15:51:18 +01:00
// we got boot-device-data, no need to keep emulating anymore
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
return Index ;
}
//
// if not found, then try DefaultVolume from config.plist
2021-02-02 10:02:21 +01:00
// if not null or empty, search volume that matches gSettings.Boot.DefaultVolume
2020-02-15 15:51:18 +01:00
//
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DefaultVolume . notEmpty ( ) ) {
2020-02-15 15:51:18 +01:00
2021-02-02 10:02:21 +01:00
// if not null or empty, also search for loader that matches gSettings.Boot.DefaultLoader
SearchForLoader = gSettings . Boot . DefaultLoader . notEmpty ( ) ;
2020-02-15 15:51:18 +01:00
/*
if ( SearchForLoader ) {
2021-02-02 10:02:21 +01:00
DBG ( " Searching for DefaultVolume '%ls', DefaultLoader '%ls' ... \n " , gSettings . Boot . DefaultVolume , gSettings . Boot . DefaultLoader ) ;
2020-02-15 15:51:18 +01:00
} else {
2021-02-02 10:02:21 +01:00
DBG ( " Searching for DefaultVolume '%ls' ... \n " , gSettings . Boot . DefaultVolume ) ;
2020-02-15 15:51:18 +01:00
}
*/
2020-02-28 21:28:33 +01:00
for ( Index = 0 ; Index < ( INTN ) MainMenu . Entries . size ( ) & & MainMenu . Entries [ Index ] . getLOADER_ENTRY ( ) & & MainMenu . Entries [ Index ] . getLOADER_ENTRY ( ) - > Row = = 0 ; Index + + ) {
2020-02-15 15:51:18 +01:00
2020-02-28 21:28:33 +01:00
LOADER_ENTRY & Entry = * MainMenu . Entries [ Index ] . getLOADER_ENTRY ( ) ;
if ( ! Entry . Volume ) {
2020-02-15 15:51:18 +01:00
continue ;
}
2020-02-28 21:28:33 +01:00
Volume = Entry . Volume ;
2021-02-02 10:02:21 +01:00
if ( ( Volume - > VolName . isEmpty ( ) | | Volume - > VolName ! = gSettings . Boot . DefaultVolume ) & &
! Volume - > DevicePathString . contains ( gSettings . Boot . DefaultVolume ) ) {
2020-02-15 15:51:18 +01:00
continue ;
}
2020-02-28 21:28:33 +01:00
// we alreday know that Entry.isLoader
2021-02-02 10:02:21 +01:00
if ( SearchForLoader & & ( /*Entry.Tag != TAG_LOADER ||*/ ! Entry . LoaderPath . containsIC ( gSettings . Boot . DefaultLoader ) ) ) {
2020-02-15 15:51:18 +01:00
continue ;
}
2021-02-06 18:16:46 +01:00
DBG ( " - found entry %lld. '%ls', Volume '%ls', DevicePath '%ls' \n " , Index , Entry . Title . s ( ) , Volume - > VolName . wc_str ( ) , Entry . DevicePathString . wc_str ( ) ) ;
2020-02-15 15:51:18 +01:00
// if first method failed and second succeeded - uninstall emulation
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
return Index ;
}
}
DBG ( " Default boot entry not found \n " ) ;
// if both methods to determine default boot entry have failed - uninstall emulation before GUI
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
return - 1 ;
}
2020-10-03 19:02:31 +02:00
void SetVariablesFromNvram ( )
2020-02-15 15:51:18 +01:00
{
CHAR8 * tmpString ;
UINTN Size = 0 ;
2020-08-15 15:47:56 +02:00
UINTN index = 0 , index2 , i ;
2020-02-15 15:51:18 +01:00
CHAR8 * arg = NULL ;
// DbgHeader("SetVariablesFromNvram");
2022-04-26 00:55:56 +02:00
tmpString = ( __typeof__ ( tmpString ) ) GetNvramVariable ( L " boot-args " , gEfiAppleBootGuid , NULL , & Size ) ;
2020-02-15 15:51:18 +01:00
if ( tmpString & & ( Size < = 0x1000 ) & & ( Size > 0 ) ) {
2021-02-06 18:16:46 +01:00
DBG ( " found boot-args in NVRAM:%s, size=%llu \n " , tmpString , Size ) ;
2020-02-15 15:51:18 +01:00
// use and forget old one
// DeleteNvramVariable(L"boot-args", &gEfiAppleBootGuid);
Size = AsciiStrLen ( tmpString ) ; // some EFI implementations include '\0' in Size, and others don't, so update Size to string length
arg = ( __typeof__ ( arg ) ) AllocatePool ( Size + 1 ) ;
/* if (AsciiStrStr(tmpString, "nvda_drv=1")) { //found substring
2021-09-28 10:28:45 +02:00
gSettings . NvidiaWeb = true ;
2020-02-15 15:51:18 +01:00
} */
//first we will find new args that is not present in main args
index = 0 ;
while ( ( index < Size ) & & ( tmpString [ index ] ! = 0x0 ) ) {
ZeroMem ( arg , Size + 1 ) ;
index2 = 0 ;
if ( tmpString [ index ] ! = ' \" ' ) {
// DBG("search space index=%d\n", index);
while ( ( index < Size ) & & ( tmpString [ index ] ! = 0x20 ) & & ( tmpString [ index ] ! = 0x0 ) ) {
arg [ index2 + + ] = tmpString [ index + + ] ;
}
2020-03-25 19:32:44 +01:00
DBG ( " ...found arg:%s \n " , arg ) ;
2020-02-15 15:51:18 +01:00
} else {
index + + ;
// DBG("search quote index=%d\n", index);
while ( ( index < Size ) & & ( tmpString [ index ] ! = ' \" ' ) & & ( tmpString [ index ] ! = 0x0 ) ) {
arg [ index2 + + ] = tmpString [ index + + ] ;
}
if ( tmpString [ index ] = = ' \" ' ) {
index + + ;
}
2020-03-25 19:32:44 +01:00
DBG ( " ...found quoted arg: \n " /*, arg*/ ) ;
2020-02-15 15:51:18 +01:00
}
while ( tmpString [ index ] = = 0x20 ) {
index + + ;
}
// For the moment only arg -s must be ignored
if ( AsciiStrCmp ( arg , " -s " ) = = 0 ) {
2020-04-05 23:14:27 +02:00
DBG ( " ...ignoring arg:%s \n " , arg ) ;
2020-02-15 15:51:18 +01:00
continue ;
}
2021-02-02 10:02:21 +01:00
if ( ! gSettings . Boot . BootArgs . contains ( arg ) ) {
2020-02-15 15:51:18 +01:00
//this arg is not present will add
2020-03-25 19:32:44 +01:00
DBG ( " ...adding arg:%s \n " , arg ) ;
2021-02-02 10:02:21 +01:00
gSettings . Boot . BootArgs . trim ( ) ;
gSettings . Boot . BootArgs + = ' ' ;
2020-02-15 15:51:18 +01:00
for ( i = 0 ; i < index2 ; i + + ) {
2021-02-02 10:02:21 +01:00
gSettings . Boot . BootArgs + = arg [ i ] ;
2020-02-15 15:51:18 +01:00
}
2021-02-02 10:02:21 +01:00
gSettings . Boot . BootArgs + = ' ' ;
2020-02-15 15:51:18 +01:00
}
}
FreePool ( arg ) ;
}
if ( tmpString ) {
FreePool ( tmpString ) ;
}
2022-04-26 00:55:56 +02:00
tmpString = ( __typeof__ ( tmpString ) ) GetNvramVariable ( L " nvda_drv " , gEfiAppleBootGuid , NULL , NULL ) ;
2020-02-15 15:51:18 +01:00
if ( tmpString & & AsciiStrCmp ( tmpString , " 1 " ) = = 0 ) {
2021-09-28 10:28:45 +02:00
gSettings . SystemParameters . NvidiaWeb = true ;
2020-02-15 15:51:18 +01:00
}
if ( tmpString ) {
FreePool ( tmpString ) ;
}
}
2021-02-06 18:16:46 +01:00
void
2021-06-23 20:24:46 +02:00
GetListOfConfigs ( )
2021-02-06 18:16:46 +01:00
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
2021-09-27 09:05:11 +02:00
ConfigsList . setEmpty ( ) ;
2021-02-06 18:16:46 +01:00
OldChosenConfig = 0 ;
DirIterOpen ( & selfOem . getConfigDir ( ) , NULL , & DirIter ) ;
DbgHeader ( " Found config plists " ) ;
while ( DirIterNext ( & DirIter , 2 , L " config*.plist " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
2023-06-16 23:44:39 +02:00
if ( StriCmp ( DirEntry - > FileName , L " config.plist " ) = = 0 ) {
OldChosenConfig = ConfigsList . size ( ) ; // DirEntry->FileName is not yet inserted into ConfigsList. So its index will be ConfigsList.size()
2021-02-06 18:16:46 +01:00
}
2023-06-16 23:44:39 +02:00
size_t NameLen = wcslen ( DirEntry - > FileName ) - 6 ; //without ".plist"
if ( NameLen < = MAX_INTN ) {
ConfigsList . AddReference ( SWPrintf ( " %.*ls " , ( int ) NameLen , DirEntry - > FileName ) . forgetDataWithoutFreeing ( ) , true ) ; // this avoid to reallocate and copy memory
DBG ( " - %ls \n " , DirEntry - > FileName ) ;
} else {
DBG ( " - bug!, NameLen > MAX_INTN " ) ;
}
}
2021-02-06 18:16:46 +01:00
DirIterClose ( & DirIter ) ;
}
void
GetListOfDsdts ( )
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
2021-09-27 09:18:52 +02:00
DsdtsList . setEmpty ( ) ;
2021-02-06 18:16:46 +01:00
OldChosenDsdt = 0xFFFF ;
DirIterOpen ( & selfOem . getConfigDir ( ) , L " ACPI \\ patched " , & DirIter ) ;
DbgHeader ( " Found DSDT tables " ) ;
while ( DirIterNext ( & DirIter , 2 , L " DSDT*.aml " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
2021-04-11 07:18:52 +02:00
if ( gSettings . ACPI . DSDT . DsdtName . isEqualIC ( DirEntry - > FileName ) ) {
2021-09-27 09:18:52 +02:00
OldChosenDsdt = DsdtsList . size ( ) ; // DirEntry->FileName is not yet inserted into DsdtsList. So its index will be DsdtsList.size()
2021-02-06 18:16:46 +01:00
}
2021-09-27 09:18:52 +02:00
size_t NameLen = wcslen ( DirEntry - > FileName ) ; //with ".aml"
DsdtsList . AddReference ( SWPrintf ( " %.*ls " , ( int ) NameLen , DirEntry - > FileName ) . forgetDataWithoutFreeing ( ) , true ) ; // this avoid to reallocate and copy memory
2021-02-06 18:16:46 +01:00
DBG ( " - %ls \n " , DirEntry - > FileName ) ;
}
DirIterClose ( & DirIter ) ;
}
void
GetListOfACPI ( )
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry = NULL ;
2021-03-23 20:59:30 +01:00
2021-02-06 18:16:46 +01:00
// XStringW AcpiPath = SWPrintf("%ls\\ACPI\\patched", OEMPath.wc_str());
// DBG("Get list of ACPI at path %ls\n", AcpiPath.wc_str());
2021-03-23 20:59:30 +01:00
ACPIPatchedAML . setEmpty ( ) ;
2021-02-06 18:16:46 +01:00
DirIterOpen ( & selfOem . getConfigDir ( ) , L " ACPI \\ patched " , & DirIter ) ;
while ( DirIterNext ( & DirIter , 2 , L " *.aml " , & DirEntry ) ) {
// DBG("next entry is %ls\n", DirEntry->FileName);
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
if ( StriStr ( DirEntry - > FileName , L " DSDT " ) ) {
continue ;
}
// DBG("Found name %ls\n", DirEntry->FileName);
2021-09-28 10:28:45 +02:00
XBool ACPIDisabled = false ;
2021-03-23 20:59:30 +01:00
ACPI_PATCHED_AML * ACPIPatchedAMLTmp = new ACPI_PATCHED_AML ;
ACPIPatchedAMLTmp - > FileName . takeValueFrom ( DirEntry - > FileName ) ;
2021-02-06 18:16:46 +01:00
2021-02-11 12:41:59 +01:00
INTN Count = gSettings . ACPI . DisabledAML . size ( ) ;
2021-02-06 18:16:46 +01:00
for ( INTN i = 0 ; i < Count ; i + + ) {
2021-04-11 07:18:52 +02:00
if ( gSettings . ACPI . DisabledAML [ i ] . isEqualIC ( ACPIPatchedAMLTmp - > FileName ) ) {
2021-02-11 12:41:59 +01:00
// if ((gSettings.ACPI.DisabledAML[i] != NULL) &&
// (StriCmp(ACPIPatchedAMLTmp->FileName, gSettings.ACPI.DisabledAML[i]) == 0)
// ) {
2021-09-28 10:28:45 +02:00
ACPIDisabled = true ;
2021-02-06 18:16:46 +01:00
break ;
}
}
ACPIPatchedAMLTmp - > MenuItem . BValue = ACPIDisabled ;
2021-03-23 20:59:30 +01:00
ACPIPatchedAML . AddReference ( ACPIPatchedAMLTmp , true ) ;
2021-02-06 18:16:46 +01:00
}
DirIterClose ( & DirIter ) ;
}
void
GetListOfThemes ( )
{
EFI_STATUS Status = EFI_NOT_FOUND ;
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
XStringW ThemeTestPath ;
EFI_FILE * ThemeTestDir = NULL ;
CHAR8 * ThemePtr = NULL ;
UINTN Size = 0 ;
DbgHeader ( " GetListOfThemes " ) ;
ThemeNameArray . setEmpty ( ) ;
if ( ! self . themesDirExists ( ) ) {
DBG ( " No theme dir was discovered \n " ) ;
return ;
}
DirIterOpen ( & self . getThemesDir ( ) , NULL , & DirIter ) ;
while ( DirIterNext ( & DirIter , 1 , L " * " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = ' . ' ) {
//DBG("Skip theme: %ls\n", DirEntry->FileName);
continue ;
}
//DBG("Found theme directory: %ls", DirEntry->FileName);
DBG ( " - [%02zu]: %ls " , ThemeNameArray . size ( ) , DirEntry - > FileName ) ;
Status = self . getThemesDir ( ) . Open ( & self . getThemesDir ( ) , & ThemeTestDir , DirEntry - > FileName , EFI_FILE_MODE_READ , 0 ) ;
if ( ! EFI_ERROR ( Status ) ) {
Status = egLoadFile ( ThemeTestDir , CONFIG_THEME_FILENAME , ( UINT8 * * ) & ThemePtr , & Size ) ;
if ( EFI_ERROR ( Status ) | | ( ThemePtr = = NULL ) | | ( Size = = 0 ) ) {
Status = egLoadFile ( ThemeTestDir , CONFIG_THEME_SVG , ( UINT8 * * ) & ThemePtr , & Size ) ;
if ( EFI_ERROR ( Status ) ) {
Status = EFI_NOT_FOUND ;
DBG ( " - bad theme because %ls nor %ls can't be load " , CONFIG_THEME_FILENAME , CONFIG_THEME_SVG ) ;
}
}
if ( ! EFI_ERROR ( Status ) ) {
//we found a theme
if ( ( StriCmp ( DirEntry - > FileName , L " embedded " ) = = 0 ) | |
( StriCmp ( DirEntry - > FileName , L " random " ) = = 0 ) ) {
ThemePtr = NULL ;
} else {
ThemeNameArray . Add ( DirEntry - > FileName ) ;
}
}
}
DBG ( " \n " ) ;
if ( ThemePtr ) {
FreePool ( ThemePtr ) ;
}
}
DirIterClose ( & DirIter ) ;
}
2020-02-15 15:51:18 +01:00
//
// main entry point
//
EFI_STATUS
EFIAPI
RefitMain ( IN EFI_HANDLE ImageHandle ,
IN EFI_SYSTEM_TABLE * SystemTable )
{
EFI_STATUS Status ;
2021-09-28 15:54:31 +02:00
XBool MainLoopRunning = true ;
XBool ReinitDesktop = true ;
XBool AfterTool = false ;
2020-02-28 21:28:33 +01:00
REFIT_ABSTRACT_MENU_ENTRY * ChosenEntry = NULL ;
REFIT_ABSTRACT_MENU_ENTRY * DefaultEntry = NULL ;
REFIT_ABSTRACT_MENU_ENTRY * OptionEntry = NULL ;
2020-02-15 15:51:18 +01:00
INTN DefaultIndex ;
UINTN MenuExit ;
2020-08-15 15:47:56 +02:00
UINTN i ;
2020-02-15 15:51:18 +01:00
EFI_TIME Now ;
2021-09-28 15:54:31 +02:00
XBool HaveDefaultVolume ;
2020-04-01 14:57:32 +02:00
REFIT_MENU_SCREEN BootScreen ;
BootScreen . isBootScreen = true ; //other screens will be constructed as false
2020-02-15 15:51:18 +01:00
2021-09-29 15:32:55 +02:00
MemLogInit ( ) ;
2020-02-15 15:51:18 +01:00
// bootstrap
gST = SystemTable ;
gImageHandle = ImageHandle ;
gBS = SystemTable - > BootServices ;
2020-02-16 13:00:20 +01:00
gRT = SystemTable - > RuntimeServices ;
2020-10-03 19:02:31 +02:00
/*Status = */ EfiGetSystemConfigurationTable ( & gEfiDxeServicesTableGuid , ( void * * ) & gDS ) ;
2020-02-15 15:51:18 +01:00
2021-05-06 08:23:07 +02:00
InitBooterLog ( ) ;
2021-10-27 21:41:42 +02:00
// ConsoleInHandle = SystemTable->ConsoleInHandle;
2021-04-28 20:30:34 +02:00
2021-04-12 14:11:01 +02:00
//#define DEBUG_ERALY_CRASH
2020-11-18 22:49:02 +01:00
# ifdef DEBUG_ERALY_CRASH
2021-04-12 14:11:01 +02:00
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step1 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2020-11-18 22:49:02 +01:00
# endif
2020-09-07 16:44:24 +02:00
# ifdef DEBUG_ON_SERIAL_PORT
SerialPortInitialize ( ) ;
# endif
2020-08-09 17:55:30 +02:00
{
EFI_LOADED_IMAGE * LoadedImage ;
2020-10-03 19:02:31 +02:00
Status = gBS - > HandleProtocol ( gImageHandle , & gEfiLoadedImageProtocolGuid , ( void * * ) & LoadedImage ) ;
2020-08-26 20:49:49 +02:00
2021-04-12 14:11:01 +02:00
# ifdef DEBUG_ERALY_CRASH
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step2 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2021-04-12 14:11:01 +02:00
# endif
2020-08-26 20:49:49 +02:00
// if ( !EFI_ERROR(Status) ) {
2021-02-11 12:41:59 +01:00
// XString8 msg = S8Printf("CloverX64 : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
2020-08-26 20:49:49 +02:00
// SerialPortWrite((UINT8*)msg.c_str(), msg.length());
// }
2021-03-28 16:02:56 +02:00
if ( ! EFI_ERROR ( Status ) ) {
DBG ( " CloverX64 : Image base = 0x%llX \n " , ( uintptr_t ) LoadedImage - > ImageBase ) ; // do not change, it's used by grep to feed the debugger
2021-05-04 12:26:54 +02:00
DBG ( " Clover ImageHandle = %llx \n " , ( uintptr_t ) ImageHandle ) ;
2021-04-12 14:11:01 +02:00
# ifdef DEBUG_ERALY_CRASH
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step3 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2021-04-12 14:11:01 +02:00
# endif
2021-03-28 16:02:56 +02:00
}
2020-08-09 17:55:30 +02:00
# ifdef JIEF_DEBUG
2021-02-11 12:41:59 +01:00
gBS - > Stall ( 2500000 ) ; // to give time to gdb to connect
2021-09-29 15:32:55 +02:00
// PauseForKey("press\n"_XS8);
2020-08-09 17:55:30 +02:00
# endif
}
2020-09-07 00:19:48 +02:00
2021-04-12 14:11:01 +02:00
# ifdef DEBUG_ERALY_CRASH
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step4 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2021-04-12 14:11:01 +02:00
# endif
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
2021-09-29 15:32:55 +02:00
// BE CAREFUL. construct_globals_objects will call ctor on every static struct and classes.
// For example, if you do "gCPUStructure.TSCCalibr = GetMemLogTscTicksPerSecond();" before this point, it will be erased by construct_globals_objects()
2021-10-18 21:06:19 +02:00
construct_globals_objects ( gImageHandle ) ;
2021-02-06 18:16:46 +01:00
# endif
2020-09-07 00:19:48 +02:00
2021-09-29 15:32:55 +02:00
gCPUStructure . TSCCalibr = GetMemLogTscTicksPerSecond ( ) ; //ticks for 1second
2021-04-12 14:11:01 +02:00
# ifdef DEBUG_ERALY_CRASH
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step5 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2021-04-12 14:11:01 +02:00
# endif
2020-08-27 20:47:56 +02:00
# ifdef JIEF_DEBUG
// all_tests();
// PauseForKey(L"press\n");
# endif
2020-08-09 17:55:30 +02:00
2020-02-16 13:00:20 +01:00
gRT - > GetTime ( & Now , NULL ) ;
2020-02-15 15:51:18 +01:00
2021-04-12 14:11:01 +02:00
Status = InitRefitLib ( gImageHandle ) ; // From here, debug.log starts to be saved because InitRefitLib call self.initialize()
2021-03-21 15:08:47 +01:00
if ( EFI_ERROR ( Status ) )
return Status ;
2021-04-12 14:11:01 +02:00
# ifdef DEBUG_ERALY_CRASH
SystemTable - > ConOut - > OutputString ( SystemTable - > ConOut , L " Step6 " ) ;
2021-05-05 17:40:10 +02:00
PauseForKey ( " press any key \n " _XS8 ) ;
2021-04-12 14:11:01 +02:00
# endif
2021-05-06 08:23:07 +02:00
// firmware detection
2020-02-15 15:51:18 +01:00
gFirmwareClover = StrCmp ( gST - > FirmwareVendor , L " CLOVER " ) = = 0 ;
if ( ! gFirmwareRevision ) {
2020-08-09 17:55:30 +02:00
// gFirmwareRevision = P__oolPrint(L"%d", gST->FirmwareRevision);
2020-02-15 15:51:18 +01:00
}
2021-02-07 15:59:15 +01:00
DataHubInstall ( ImageHandle , SystemTable ) ;
2020-02-15 15:51:18 +01:00
InitializeConsoleSim ( ) ;
2021-04-21 07:32:38 +02:00
DbgHeader ( " Starting Clover " ) ;
2020-02-15 15:51:18 +01:00
if ( Now . TimeZone < - 1440 | | Now . TimeZone > 1440 ) {
MsgLog ( " Now is %02d.%02d.%d, %02d:%02d:%02d (GMT) \n " ,
Now . Day , Now . Month , Now . Year , Now . Hour , Now . Minute , Now . Second ) ;
} else {
MsgLog ( " Now is %02d.%02d.%d, %02d:%02d:%02d (GMT+%d) \n " ,
2021-02-02 10:02:21 +01:00
Now . Day , Now . Month , Now . Year , Now . Hour , Now . Minute , Now . Second , gSettings . GUI . Timezone ) ;
2020-02-15 15:51:18 +01:00
}
2020-04-16 14:24:21 +02:00
//MsgLog("Starting Clover rev %ls on %ls EFI\n", gFirmwareRevision, gST->FirmwareVendor);
2021-02-06 18:16:46 +01:00
MsgLog ( " Starting %s on %ls EFI \n " , gRevisionStr , gST - > FirmwareVendor ) ;
2020-10-07 19:25:31 +02:00
MsgLog ( " Build id: %s \n " , gBuildId . c_str ( ) ) ;
2021-02-06 18:16:46 +01:00
if ( gBuildInfo ) DBG ( " Build with: [%s] \n " , gBuildInfo ) ;
2020-02-15 15:51:18 +01:00
2020-09-16 19:50:16 +02:00
2020-02-15 15:51:18 +01:00
//dumping SETTING structure
// if you change something in Platform.h, please uncomment and test that all offsets
// are natural aligned i.e. pointers are 8 bytes aligned
/*
DBG ( " Settings offsets: \n " ) ;
2020-03-25 19:32:44 +01:00
DBG ( " OEMProduct: %X \n " , OFFSET_OF ( SETTINGS_DATA , OEMProduct ) ) ;
DBG ( " DefaultVolume: %X \n " , OFFSET_OF ( SETTINGS_DATA , DefaultVolume ) ) ;
DBG ( " DefaultLoader: %X \n " , OFFSET_OF ( SETTINGS_DATA , DefaultLoader ) ) ;
DBG ( " ResetAddr: %X \n " , OFFSET_OF ( SETTINGS_DATA , ResetAddr ) ) ;
DBG ( " FixDsdt: %X \n " , OFFSET_OF ( SETTINGS_DATA , FixDsdt ) ) ;
DBG ( " FakeATI: %X \n " , OFFSET_OF ( SETTINGS_DATA , FakeATI ) ) ;
DBG ( " PatchVBiosBytes:%X \n " , OFFSET_OF ( SETTINGS_DATA , PatchVBiosBytes ) ) ;
DBG ( " VRAM: %X \n " , OFFSET_OF ( SETTINGS_DATA , VRAM ) ) ;
DBG ( " SecureBootWhiteListCount: %X \n " , OFFSET_OF ( SETTINGS_DATA , SecureBootWhiteListCount ) ) ;
DBG ( " LegacyBoot: %X \n " , OFFSET_OF ( SETTINGS_DATA , LegacyBoot ) ) ;
DBG ( " HVHideStrings: %X \n " , OFFSET_OF ( SETTINGS_DATA , HVHideStrings ) ) ;
DBG ( " PointerSpeed: %X \n " , OFFSET_OF ( SETTINGS_DATA , PointerSpeed ) ) ;
DBG ( " RtMLB: %X \n " , OFFSET_OF ( SETTINGS_DATA , RtMLB ) ) ;
DBG ( " ConfigName: %X \n " , OFFSET_OF ( SETTINGS_DATA , ConfigName ) ) ;
DBG ( " PointerSpeed: %X \n " , OFFSET_OF ( SETTINGS_DATA , PointerSpeed ) ) ;
DBG ( " PatchDsdtNum: %X \n " , OFFSET_OF ( SETTINGS_DATA , PatchDsdtNum ) ) ;
DBG ( " LenToReplace: %X \n " , OFFSET_OF ( SETTINGS_DATA , LenToReplace ) ) ;
DBG ( " ACPIDropTables: %X \n " , OFFSET_OF ( SETTINGS_DATA , ACPIDropTables ) ) ;
DBG ( " CustomEntries: %X \n " , OFFSET_OF ( SETTINGS_DATA , CustomEntries ) ) ;
DBG ( " CustomTool: %X \n " , OFFSET_OF ( SETTINGS_DATA , CustomTool ) ) ;
DBG ( " AddProperties: %X \n " , OFFSET_OF ( SETTINGS_DATA , AddProperties ) ) ;
DBG ( " BlockKexts: %X \n " , OFFSET_OF ( SETTINGS_DATA , BlockKexts ) ) ;
2020-02-15 15:51:18 +01:00
*/
// disable EFI watchdog timer
gBS - > SetWatchdogTimer ( 0x0000 , 0x0000 , 0x0000 , NULL ) ;
2020-10-03 19:02:31 +02:00
// ZeroMem((void*)&gSettings, sizeof(SETTINGS_DATA));
2020-02-15 15:51:18 +01:00
Status = InitializeUnicodeCollationProtocol ( ) ;
if ( EFI_ERROR ( Status ) ) {
2020-08-25 17:35:19 +02:00
DBG ( " UnicodeCollation Status=%s \n " , efiStrError ( Status ) ) ;
2020-02-15 15:51:18 +01:00
}
2021-10-27 21:41:42 +02:00
// Status = gBS->HandleProtocol(ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (void **)&SimpleTextEx);
// if ( EFI_ERROR(Status) ) {
// SimpleTextEx = NULL;
// }
// DBG("SimpleTextEx Status=%s\n", efiStrError(Status));
2020-02-15 15:51:18 +01:00
2021-04-28 20:30:34 +02:00
gConf . InitialisePlatform ( ) ;
2021-07-02 17:10:10 +02:00
# ifdef JIEF_DEBUG
DumpNvram ( ) ;
# endif
2021-05-06 08:23:07 +02:00
/*
* saving debug . log works from here
*/
2020-02-15 15:51:18 +01:00
{
// UINT32 machineSignature = 0;
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE * FadtPointer = NULL ;
EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * Facs = NULL ;
// DBG("---dump hibernations data---\n");
FadtPointer = GetFadt ( ) ;
if ( FadtPointer ! = NULL ) {
Facs = ( EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * ) ( UINTN ) ( FadtPointer - > FirmwareCtrl ) ;
/*
DBG ( " Firmware wake address=%08lx \n " , Facs - > FirmwareWakingVector ) ;
DBG ( " Firmware wake 64 addr=%16llx \n " , Facs - > XFirmwareWakingVector ) ;
DBG ( " Hardware signature =%08lx \n " , Facs - > HardwareSignature ) ;
DBG ( " GlobalLock =%08lx \n " , Facs - > GlobalLock ) ;
DBG ( " Flags =%08lx \n " , Facs - > Flags ) ;
*/
machineSignature = Facs - > HardwareSignature ;
}
# if HIBERNATE_DUMP_DATA
//------------------------------------------------------
2022-04-26 00:55:56 +02:00
DumpVariable ( L " Boot0082 " , gEfiGlobalVariableGuid , 8 ) ;
DumpVariable ( L " boot-switch-vars " , gEfiAppleBootGuid , - 1 ) ;
DumpVariable ( L " boot-signature " , gEfiAppleBootGuid , - 1 ) ;
DumpVariable ( L " boot-image-key " , gEfiAppleBootGuid , - 1 ) ;
DumpVariable ( L " boot-image " , gEfiAppleBootGuid , 0 ) ;
2020-02-15 15:51:18 +01:00
//-----------------------------------------------------------
# endif //
}
#if 0
//testing place
{
2020-05-13 12:04:48 +02:00
const CHAR16 aaa [ ] = L " 12345 " ;
2020-04-13 10:43:18 +02:00
const CHAR8 * bbb = " 12345 " ;
DBG ( " string %ls, size=%lld, len=%lld sizeof=%ld iStrLen=%lld \n " , aaa , StrSize ( aaa ) , StrLen ( aaa ) , sizeof ( aaa ) , iStrLen ( bbb , 10 ) ) ;
2020-04-25 05:37:56 +02:00
const CHAR8 * ccc = " Выход " ;
DBG ( " string %s, size=%lld, len=%lld sizeof=%ld iStrLen=%lld \n " , ccc , AsciiStrSize ( ccc ) , AsciiStrLen ( ccc ) , sizeof ( ccc ) , iStrLen ( ccc , 10 ) ) ;
2020-04-30 08:22:26 +02:00
XString8 ddd = " Выход " _XS8 ;
2020-04-24 18:24:34 +02:00
// size_t sizex = ddd.allocatedSize();
2020-04-25 05:37:56 +02:00
DBG ( " xstring %s, asize=%ld, sizeinbyte=%ld sizeof=%ld lastcharat=%ld \n " , ddd . c_str ( ) , ddd . allocatedSize ( ) , ddd . sizeInBytes ( ) , sizeof ( ddd ) ,
2020-04-25 12:07:23 +02:00
ddd . indexOf ( ddd . lastChar ( ) ) ) ;
2020-04-13 10:43:18 +02:00
CHAR8 compatible [ 64 ] ;
UINT32 FakeLAN = 0x0030168c ;
UINT32 FakeID = FakeLAN > > 16 ;
2020-04-14 06:34:10 +02:00
UINT32 FakeVendor = FakeLAN & 0xFFFF ;
snprintf ( compatible , 64 , " pci%x,%x " , FakeVendor , FakeID ) ;
2020-04-13 10:43:18 +02:00
DBG ( " FakeLAN = 0x%x \n " , FakeLAN ) ;
DBG ( " Compatible=%s strlen=%ld sizeof=%ld iStrLen=%lld \n " , compatible ,
strlen ( compatible ) , sizeof ( compatible ) , iStrLen ( compatible , 64 ) ) ;
// LowCase(compatible);
// DBG(" Low Compatible=%s strlen=%ld sizeof=%ld iStrLen=%lld\n", compatible,
// strlen(compatible), sizeof(compatible), iStrLen(compatible, 64));
2020-04-19 20:48:00 +02:00
DBG ( " void*=%ld int=%ld long=%ld longlong=%ld enum=%ld \n " ,
sizeof ( void * ) , sizeof ( int ) , sizeof ( long int ) , sizeof ( long long ) , sizeof ( EFI_ALLOCATE_TYPE ) ) ;
2020-05-13 12:04:48 +02:00
/*
Results
41 : 381 0 : 000 string 12345 , size = 16 , len = 7 sizeof = 16 iStrLen = 5
41 : 381 0 : 000 string В ы х о д , size = 13 , len = 12 sizeof = 8 iStrLen = 10
41 : 381 0 : 000 xstring В ы х о д , asize = 0 , sizeinbyte = 11 sizeof = 16 lastcharat = 5
41 : 381 0 : 000 FakeLAN = 0x30168c
41 : 381 0 : 000 Compatible = pci168c , 30 strlen = 10 sizeof = 64 iStrLen = 10
*/
2020-02-15 15:51:18 +01:00
}
# endif
2021-02-02 10:02:21 +01:00
if ( ! GlobalConfig . isFastBoot ( ) ) {
2020-02-15 15:51:18 +01:00
GetListOfThemes ( ) ;
GetListOfConfigs ( ) ;
2023-06-16 23:44:39 +02:00
// SmbiosList.setEmpty();
// SmbiosList.AddReference(new XStringW(L"auto"_XSW), true);
2020-02-15 15:51:18 +01:00
}
2020-04-16 13:04:24 +02:00
// ThemeX.FillByEmbedded(); //init XTheme before EarlyUserSettings
2021-02-02 10:02:21 +01:00
{
void * Value = NULL ;
UINTN Size = 0 ;
//read aptiofixflag from nvram for special boot
2022-04-26 00:55:56 +02:00
Status = GetVariable2 ( L " aptiofixflag " , gEfiAppleBootGuid , & Value , & Size ) ;
2021-02-02 10:02:21 +01:00
if ( ! EFI_ERROR ( Status ) ) {
2021-09-28 10:28:45 +02:00
GlobalConfig . SpecialBootMode = true ;
2021-02-02 10:02:21 +01:00
FreePool ( Value ) ;
DBG ( " Fast option enabled \n " ) ;
}
}
2020-03-31 14:35:04 +02:00
2021-04-28 20:30:34 +02:00
// for (i=0; i<2; i++) {
// if (gConfigDict[i]) {
// GetEarlyUserSettings(gConfigDict[i], gSettings);
// }
// }
2020-02-15 15:51:18 +01:00
# ifdef ENABLE_SECURE_BOOT
// Install secure boot shim
if ( EFI_ERROR ( Status = InstallSecureBoot ( ) ) ) {
2021-05-05 17:40:10 +02:00
PauseForKey ( " Secure boot failure! \n " _XS8 ) ;
2020-02-15 15:51:18 +01:00
return Status ;
}
# endif // ENABLE_SECURE_BOOT
2021-02-02 10:02:21 +01:00
MainMenu . TimeoutSeconds = gSettings . Boot . Timeout > = 0 ? gSettings . Boot . Timeout : 0 ;
2020-02-15 15:51:18 +01:00
//DBG("LoadDrivers() start\n");
LoadDrivers ( ) ;
2022-04-26 00:55:56 +02:00
Status = gBS - > LocateProtocol ( gEmuVariableControlProtocolGuid , NULL , ( void * * ) & gEmuVariableControl ) ;
2020-02-15 15:51:18 +01:00
if ( EFI_ERROR ( Status ) ) {
gEmuVariableControl = NULL ;
}
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > InstallEmulation ( gEmuVariableControl ) ;
}
DbgHeader ( " InitScreen " ) ;
2021-02-06 18:16:46 +01:00
2021-02-02 10:02:21 +01:00
if ( ! GlobalConfig . isFastBoot ( ) ) {
2020-02-15 15:51:18 +01:00
// init screen and dump video modes to log
if ( gDriversFlags . VideoLoaded ) {
2021-09-28 10:28:45 +02:00
InitScreen ( false ) ;
2020-02-15 15:51:18 +01:00
} else {
2021-09-28 10:28:45 +02:00
InitScreen ( ! gFirmwareClover ) ; // ? false : true);
2020-02-15 15:51:18 +01:00
}
//DBG("DBG: setup screen\n");
SetupScreen ( ) ;
} else {
2021-09-28 10:28:45 +02:00
InitScreen ( false ) ;
2020-02-15 15:51:18 +01:00
}
2021-02-06 18:16:46 +01:00
2020-10-03 19:02:31 +02:00
//DBG("ReinitRefitLib\n");
2020-02-15 15:51:18 +01:00
//Now we have to reinit handles
2020-10-03 19:02:31 +02:00
Status = ReinitRefitLib ( ) ;
2020-02-15 15:51:18 +01:00
if ( EFI_ERROR ( Status ) ) {
2022-03-24 18:32:31 +01:00
// DebugLog(2, " %s", efiStrError(Status));
2021-05-04 12:03:40 +02:00
PauseForKey ( " Error reinit refit. " _XS8 ) ;
2020-02-15 15:51:18 +01:00
# ifdef ENABLE_SECURE_BOOT
UninstallSecureBoot ( ) ;
# endif // ENABLE_SECURE_BOOT
return Status ;
}
2021-02-06 18:16:46 +01:00
2020-02-15 15:51:18 +01:00
// DBG("DBG: messages\n");
2021-02-02 10:02:21 +01:00
if ( ! gSettings . Boot . NoEarlyProgress & & ! GlobalConfig . isFastBoot ( ) & & gSettings . Boot . Timeout > 0 ) {
2020-03-31 17:59:35 +02:00
XStringW Message = SWPrintf ( " Welcome to Clover %ls " , gFirmwareRevision ) ;
2020-04-01 14:57:32 +02:00
BootScreen . DrawTextXY ( Message , ( UGAWidth > > 1 ) , UGAHeight > > 1 , X_IS_CENTER ) ;
BootScreen . DrawTextXY ( L " ... testing hardware ... " _XSW , ( UGAWidth > > 1 ) , ( UGAHeight > > 1 ) + 20 , X_IS_CENTER ) ;
2020-02-15 15:51:18 +01:00
}
// DumpBiosMemoryMap();
GuiEventsInitialize ( ) ;
//DBG("ScanSPD() start\n");
ScanSPD ( ) ;
//DBG("ScanSPD() end\n");
SetPrivateVarProto ( ) ;
// GetDefaultSettings();
GetAcpiTablesList ( ) ;
2021-02-02 10:02:21 +01:00
if ( ! gSettings . Boot . NoEarlyProgress & & ! GlobalConfig . isFastBoot ( ) & & gSettings . Boot . Timeout > 0 ) {
2020-03-31 17:59:35 +02:00
XStringW Message = SWPrintf ( " ... user settings ... " ) ;
2020-04-01 14:57:32 +02:00
BootScreen . EraseTextXY ( ) ;
BootScreen . DrawTextXY ( Message , ( UGAWidth > > 1 ) , ( UGAHeight > > 1 ) + 20 , X_IS_CENTER ) ;
2020-02-15 15:51:18 +01:00
}
2023-06-12 13:35:14 +02:00
afterGetUserSettings ( gSettings ) ;
2023-06-22 21:50:58 +02:00
gFakeCPUID = gSettings . KernelAndKextPatches . FakeCPUID ;
DBG ( " Set FakeCPUID: 0x%X \n " , gFakeCPUID ) ;
2020-02-15 15:51:18 +01:00
2021-02-02 10:02:21 +01:00
HaveDefaultVolume = gSettings . Boot . DefaultVolume . notEmpty ( ) ;
2020-02-15 15:51:18 +01:00
if ( ! gFirmwareClover & &
! gDriversFlags . EmuVariableLoaded & &
! HaveDefaultVolume & &
2021-02-02 10:02:21 +01:00
gSettings . Boot . Timeout = = 0 & & ! ReadAllKeyStrokes ( ) ) {
2020-02-15 15:51:18 +01:00
// UEFI boot: get gEfiBootDeviceGuid from NVRAM.
// if present, ScanVolumes() will skip scanning other volumes
// in the first run.
// this speeds up loading of default macOS volume.
GetEfiBootDeviceFromNvram ( ) ;
}
2021-02-02 10:02:21 +01:00
if ( ! gSettings . Boot . NoEarlyProgress & & ! GlobalConfig . isFastBoot ( ) & & gSettings . Boot . Timeout > 0 ) {
2020-03-31 17:59:35 +02:00
XStringW Message = SWPrintf ( " ... scan entries ... " ) ;
2020-04-01 14:57:32 +02:00
BootScreen . EraseTextXY ( ) ;
BootScreen . DrawTextXY ( Message , ( UGAWidth > > 1 ) , ( UGAHeight > > 1 ) + 20 , X_IS_CENTER ) ;
2020-02-15 15:51:18 +01:00
}
2021-09-28 10:28:45 +02:00
AfterTool = false ;
gGuiIsReady = true ;
GlobalConfig . gBootChanged = true ;
GlobalConfig . gThemeChanged = true ;
2021-06-24 21:52:12 +02:00
2020-02-15 15:51:18 +01:00
do {
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gBootChanged & & GlobalConfig . gThemeChanged ) { // config changed
2020-05-01 02:14:11 +02:00
GetListOfDsdts ( ) ; //only after GetUserSettings
GetListOfACPI ( ) ; //ssdt and other tables
}
2021-09-28 10:28:45 +02:00
GlobalConfig . gBootChanged = false ;
2020-08-12 17:15:47 +02:00
MainMenu . Entries . setEmpty ( ) ;
OptionMenu . Entries . setEmpty ( ) ;
2020-02-15 15:51:18 +01:00
InitKextList ( ) ;
ScanVolumes ( ) ;
// as soon as we have Volumes, find latest nvram.plist and copy it to RT vars
if ( ! AfterTool ) {
if ( gFirmwareClover | | gDriversFlags . EmuVariableLoaded ) {
PutNvramPlistToRtVars ( ) ;
}
}
2020-06-05 11:43:12 +02:00
// log Audio devices in boot-log. This is for clients like Clover.app
2020-02-15 15:51:18 +01:00
GetOutputs ( ) ;
2020-08-31 09:07:36 +02:00
for ( i = 0 ; i < AudioList . size ( ) ; i + + ) {
if ( AudioList [ i ] . Name . notEmpty ( ) ) {
2023-06-12 13:35:14 +02:00
// Never change this log, otherwise clients will stop interpret the output.
2021-02-06 18:16:46 +01:00
MsgLog ( " Found Audio Device %ls (%s) at index %llu \n " , AudioList [ i ] . Name . wc_str ( ) , AudioOutputNames [ AudioList [ i ] . Device ] , i ) ;
2020-02-15 15:51:18 +01:00
}
}
2021-02-02 10:02:21 +01:00
if ( ! GlobalConfig . isFastBoot ( ) ) {
2020-02-15 15:51:18 +01:00
if ( gThemeNeedInit ) {
2021-02-06 18:16:46 +01:00
UINTN Size = 0 ;
2022-04-26 00:55:56 +02:00
InitTheme ( ( CHAR8 * ) GetNvramVariable ( L " Clover.Theme " , gEfiAppleBootGuid , NULL , & Size ) ) ;
2021-09-28 10:28:45 +02:00
gThemeNeedInit = false ;
2021-02-06 18:16:46 +01:00
} else if ( GlobalConfig . gThemeChanged ) {
2020-02-15 15:51:18 +01:00
DBG ( " change theme \n " ) ;
2021-02-06 18:16:46 +01:00
InitTheme ( NULL ) ;
2020-08-12 17:15:47 +02:00
AboutMenu . Entries . setEmpty ( ) ;
HelpMenu . Entries . setEmpty ( ) ;
2020-02-15 15:51:18 +01:00
}
DBG ( " theme inited \n " ) ;
2020-03-29 18:17:27 +02:00
if ( ThemeX . embedded ) {
DBG ( " Chosen embedded theme \n " ) ;
} else {
2020-08-15 15:47:56 +02:00
DBG ( " Chosen theme %ls \n " , ThemeX . Theme . wc_str ( ) ) ;
2020-03-29 18:17:27 +02:00
}
2020-02-15 15:51:18 +01:00
//now it is a time to set RtVariables
SetVariablesFromNvram ( ) ;
2021-09-27 21:40:40 +02:00
XString8Array TmpArgs = Split < XString8Array > ( gSettings . Boot . BootArgs , " " ) ;
2021-02-02 10:02:21 +01:00
DBG ( " after NVRAM boot-args=%s \n " , gSettings . Boot . BootArgs . c_str ( ) ) ;
2021-04-03 16:42:49 +02:00
GlobalConfig . OptionsBits = EncodeOptions ( TmpArgs ) ;
// DBG("initial OptionsBits %X\n", GlobalConfig.OptionsBits);
2021-09-28 10:28:45 +02:00
FillInputs ( true ) ;
2020-02-15 15:51:18 +01:00
// scan for loaders and tools, add then to the menu
2021-03-19 21:32:42 +01:00
if ( gSettings . GUI . Scan . LegacyFirst ) {
2020-02-15 15:51:18 +01:00
AddCustomLegacy ( ) ;
2021-03-19 21:32:42 +01:00
if ( ! gSettings . GUI . Scan . NoLegacy ) {
2020-02-15 15:51:18 +01:00
ScanLegacy ( ) ;
}
}
}
2021-09-28 10:28:45 +02:00
GetSmcKeys ( true ) ;
2020-02-15 15:51:18 +01:00
// Add custom entries
AddCustomEntries ( ) ;
2021-03-19 21:32:42 +01:00
if ( gSettings . GUI . Scan . DisableEntryScan ) {
2020-02-15 15:51:18 +01:00
DBG ( " Entry scan disabled \n " ) ;
} else {
ScanLoader ( ) ;
}
2021-02-02 10:02:21 +01:00
if ( ! GlobalConfig . isFastBoot ( ) ) {
2021-03-19 21:32:42 +01:00
if ( ! gSettings . GUI . Scan . LegacyFirst ) {
2020-02-15 15:51:18 +01:00
AddCustomLegacy ( ) ;
2021-03-19 21:32:42 +01:00
if ( ! gSettings . GUI . Scan . NoLegacy ) {
2020-02-15 15:51:18 +01:00
ScanLegacy ( ) ;
}
}
// fixed other menu entries
2020-03-27 17:50:17 +01:00
if ( ! ( ThemeX . HideUIFlags & HIDEUI_FLAG_TOOLS ) ) {
2020-02-15 15:51:18 +01:00
AddCustomTool ( ) ;
2021-03-19 21:32:42 +01:00
if ( ! gSettings . GUI . Scan . DisableToolScan ) {
2020-02-15 15:51:18 +01:00
ScanTool ( ) ;
# ifdef ENABLE_SECURE_BOOT
// Check for secure boot setup mode
AddSecureBootTool ( ) ;
# endif // ENABLE_SECURE_BOOT
}
}
2021-05-17 07:52:17 +02:00
2020-03-27 17:50:17 +01:00
MenuEntryOptions . Image = ThemeX . GetIcon ( BUILTIN_ICON_FUNC_OPTIONS ) ;
2020-05-18 22:10:38 +02:00
// DBG("Options: IconID=%lld name=%s empty=%s\n", MenuEntryOptions.Image.Id, MenuEntryOptions.Image.Name.c_str(),
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DisableCloverHotkeys )
2020-02-15 15:51:18 +01:00
MenuEntryOptions . ShortcutLetter = 0x00 ;
2020-03-03 21:44:07 +01:00
MainMenu . AddMenuEntry ( & MenuEntryOptions , false ) ;
2020-05-16 21:30:29 +02:00
2020-03-29 18:17:27 +02:00
MenuEntryAbout . Image = ThemeX . GetIcon ( ( INTN ) BUILTIN_ICON_FUNC_ABOUT ) ;
2020-05-18 22:10:38 +02:00
// DBG("About: IconID=%lld name=%s empty=%s\n", MenuEntryAbout.Image.Id, MenuEntryAbout.Image.Name.c_str(),
2023-06-12 13:35:14 +02:00
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DisableCloverHotkeys )
2020-02-15 15:51:18 +01:00
MenuEntryAbout . ShortcutLetter = 0x00 ;
2020-03-03 21:44:07 +01:00
MainMenu . AddMenuEntry ( & MenuEntryAbout , false ) ;
2020-02-15 15:51:18 +01:00
2020-03-29 18:17:27 +02:00
if ( ! ( ThemeX . HideUIFlags & HIDEUI_FLAG_FUNCS ) | | MainMenu . Entries . size ( ) = = 0 ) {
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DisableCloverHotkeys )
2020-03-29 18:17:27 +02:00
MenuEntryReset . ShortcutLetter = 0x00 ;
MenuEntryReset . Image = ThemeX . GetIcon ( BUILTIN_ICON_FUNC_RESET ) ;
MainMenu . AddMenuEntry ( & MenuEntryReset , false ) ;
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . DisableCloverHotkeys )
2020-03-29 18:17:27 +02:00
MenuEntryShutdown . ShortcutLetter = 0x00 ;
MenuEntryShutdown . Image = ThemeX . GetIcon ( BUILTIN_ICON_FUNC_EXIT ) ;
MainMenu . AddMenuEntry ( & MenuEntryShutdown , false ) ;
}
2020-02-15 15:51:18 +01:00
}
// wait for user ACK when there were errors
2021-09-28 10:28:45 +02:00
FinishTextScreen ( false ) ;
2020-02-15 15:51:18 +01:00
# if CHECK_SMC
DumpSmcKeys ( ) ;
# endif
DefaultIndex = FindDefaultEntry ( ) ;
2021-02-06 18:16:46 +01:00
// DBG("DefaultIndex=%lld and MainMenu.Entries.size()=%llu\n", DefaultIndex, MainMenu.Entries.size());
2020-02-28 21:28:33 +01:00
if ( ( DefaultIndex > = 0 ) & & ( DefaultIndex < ( INTN ) MainMenu . Entries . size ( ) ) ) {
DefaultEntry = & MainMenu . Entries [ DefaultIndex ] ;
2020-02-15 15:51:18 +01:00
} else {
DefaultEntry = NULL ;
}
2021-09-28 10:28:45 +02:00
MainLoopRunning = true ;
2021-02-02 10:02:21 +01:00
if ( DefaultEntry & & ( GlobalConfig . isFastBoot ( ) | |
( gSettings . Boot . SkipHibernateTimeout & &
2020-02-28 21:28:33 +01:00
DefaultEntry - > getLOADER_ENTRY ( )
2023-06-12 13:35:14 +02:00
& & OSFLAG_ISSET ( DefaultEntry - > getLOADER_ENTRY ( ) - > Flags , OSFLAG_HIBERNATED ) ) ) ) {
2020-02-28 21:28:33 +01:00
if ( DefaultEntry - > getLOADER_ENTRY ( ) ) {
2020-05-01 18:26:28 +02:00
DefaultEntry - > StartLoader ( ) ;
2020-02-28 21:28:33 +01:00
} else if ( DefaultEntry - > getLEGACY_ENTRY ( ) ) {
2020-05-01 18:26:28 +02:00
DefaultEntry - > StartLegacy ( ) ;
2020-02-15 15:51:18 +01:00
}
2021-09-28 10:28:45 +02:00
gSettings . Boot . FastBoot = false ; //Hmm... will never be here
2020-02-15 15:51:18 +01:00
}
2023-06-12 13:35:14 +02:00
2021-09-28 10:28:45 +02:00
AfterTool = false ;
2020-02-15 15:51:18 +01:00
gEvent = 0 ; //clear to cancel loop
while ( MainLoopRunning ) {
2021-02-02 10:02:21 +01:00
if ( gSettings . Boot . Timeout = = 0 & & DefaultEntry ! = NULL & & ! ReadAllKeyStrokes ( ) ) {
2020-02-15 15:51:18 +01:00
// go strait to DefaultVolume loading
MenuExit = MENU_EXIT_TIMEOUT ;
} else {
2020-04-15 18:30:39 +02:00
MainMenu . GetAnime ( ) ;
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gThemeChanged ) {
2021-09-28 10:28:45 +02:00
GlobalConfig . gThemeChanged = false ;
2020-04-16 18:21:13 +02:00
ThemeX . ClearScreen ( ) ;
}
2020-03-03 21:44:07 +01:00
MenuExit = MainMenu . RunMainMenu ( DefaultIndex , & ChosenEntry ) ;
2020-02-15 15:51:18 +01:00
}
2022-08-02 21:12:31 +02:00
// DBG("exit from MainMenu %llu\n", MenuExit); //MENU_EXIT_ENTER=(1) MENU_EXIT_DETAILS=3
2020-02-15 15:51:18 +01:00
// disable default boot - have sense only in the first run
2021-02-02 10:02:21 +01:00
gSettings . Boot . Timeout = - 1 ;
2020-02-15 15:51:18 +01:00
if ( ( DefaultEntry ! = NULL ) & & ( MenuExit = = MENU_EXIT_TIMEOUT ) ) {
2020-02-28 21:28:33 +01:00
if ( DefaultEntry - > getLOADER_ENTRY ( ) ) {
2020-05-01 18:26:28 +02:00
DefaultEntry - > StartLoader ( ) ;
2020-02-28 21:28:33 +01:00
} else if ( DefaultEntry - > getLEGACY_ENTRY ( ) ) {
2020-05-01 18:26:28 +02:00
DefaultEntry - > StartLegacy ( ) ;
2020-02-15 15:51:18 +01:00
}
// if something goes wrong - break main loop to reinit volumes
break ;
}
if ( MenuExit = = MENU_EXIT_OPTIONS ) {
2021-09-28 10:28:45 +02:00
GlobalConfig . gBootChanged = false ;
2020-03-05 04:37:21 +01:00
OptionsMenu ( & OptionEntry ) ;
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gBootChanged ) {
2021-09-28 10:28:45 +02:00
AfterTool = true ;
MainLoopRunning = false ;
2020-02-15 15:51:18 +01:00
break ;
}
continue ;
}
if ( MenuExit = = MENU_EXIT_HELP ) {
HelpRefit ( ) ;
continue ;
}
// EjectVolume
if ( MenuExit = = MENU_EXIT_EJECT ) {
2020-02-28 21:28:33 +01:00
Status = EFI_SUCCESS ;
if ( ChosenEntry - > getLOADER_ENTRY ( ) ) {
Status = EjectVolume ( ChosenEntry - > getLOADER_ENTRY ( ) - > Volume ) ;
}
if ( ChosenEntry - > getLEGACY_ENTRY ( ) ) {
Status = EjectVolume ( ChosenEntry - > getLEGACY_ENTRY ( ) - > Volume ) ;
}
if ( ! EFI_ERROR ( Status ) ) {
break ; //main loop is broken so Reinit all
2020-02-15 15:51:18 +01:00
}
continue ;
}
// Hide toggle
if ( MenuExit = = MENU_EXIT_HIDE_TOGGLE ) {
2020-08-15 22:39:25 +02:00
MainMenu . Entries . includeHidden = ! MainMenu . Entries . includeHidden ;
continue ;
2020-02-15 15:51:18 +01:00
}
// We don't allow exiting the main menu with the Escape key.
if ( MenuExit = = MENU_EXIT_ESCAPE ) {
break ; //refresh main menu
// continue;
}
2020-02-28 21:28:33 +01:00
if ( ChosenEntry - > getREFIT_MENU_ITEM_RESET ( ) ) { // Restart
if ( MenuExit = = MENU_EXIT_DETAILS ) {
2023-06-12 13:35:14 +02:00
2020-02-28 21:28:33 +01:00
//do clear cmos as for AMI BIOS
// not sure for more robust method
IoWrite8 ( PCAT_RTC_ADDRESS_REGISTER , 0x10 ) ;
IoWrite8 ( PCAT_RTC_DATA_REGISTER , 0x0 ) ;
IoWrite8 ( PCAT_RTC_ADDRESS_REGISTER , 0x11 ) ;
IoWrite8 ( PCAT_RTC_DATA_REGISTER , 0x0 ) ;
2020-02-15 15:51:18 +01:00
// or may be
// IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, 0x17);
// IoWrite8 (PCAT_RTC_DATA_REGISTER, 0x17);
// }
2020-02-28 21:28:33 +01:00
}
// Attempt warm reboot
gRT - > ResetSystem ( EfiResetWarm , EFI_SUCCESS , 0 , NULL ) ;
// Warm reboot may not be supported attempt cold reboot
gRT - > ResetSystem ( EfiResetCold , EFI_SUCCESS , 0 , NULL ) ;
// Terminate the screen and just exit
TerminateScreen ( ) ;
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
ReinitDesktop = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
}
2020-02-15 15:51:18 +01:00
2020-02-28 21:28:33 +01:00
if ( ChosenEntry - > getREFIT_MENU_ITEM_SHUTDOWN ( ) ) { // It is not Shut Down, it is Exit from Clover
TerminateScreen ( ) ;
// gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ; // just in case we get this far
ReinitDesktop = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
}
if ( ChosenEntry - > getREFIT_MENU_ITEM_OPTIONS ( ) ) { // Options like KernelFlags, DSDTname etc.
2021-09-28 10:28:45 +02:00
GlobalConfig . gBootChanged = false ;
2020-03-05 04:37:21 +01:00
OptionsMenu ( & OptionEntry ) ;
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gBootChanged )
2021-09-28 10:28:45 +02:00
AfterTool = true ;
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gBootChanged | | GlobalConfig . gThemeChanged ) // If theme has changed reinit the desktop
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
2020-02-28 21:28:33 +01:00
}
if ( ChosenEntry - > getREFIT_MENU_ITEM_ABOUT ( ) ) { // About rEFIt
AboutRefit ( ) ;
}
2020-02-15 15:51:18 +01:00
2020-02-28 21:28:33 +01:00
/* -- not passed here
// case TAG_HELP:
HelpRefit ( ) ;
break ;
*/
2022-08-02 21:12:31 +02:00
if ( ChosenEntry - > getLOADER_ENTRY ( ) ) { // Boot OS via .EFI loader
2020-02-28 21:28:33 +01:00
SetBootCurrent ( ChosenEntry - > getLOADER_ENTRY ( ) ) ;
2020-05-01 18:26:28 +02:00
ChosenEntry - > StartLoader ( ) ;
2020-02-28 21:28:33 +01:00
//if boot.efi failed we should somehow exit from the loop
TerminateScreen ( ) ;
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
ReinitDesktop = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
}
if ( ChosenEntry - > getLEGACY_ENTRY ( ) ) { // Boot legacy OS
if ( StrCmp ( gST - > FirmwareVendor , L " Phoenix Technologies Ltd. " ) = = 0 & &
gST - > Hdr . Revision > > 16 = = 2 & & ( gST - > Hdr . Revision & ( ( 1 < < 16 ) - 1 ) ) = = 0 ) {
// Phoenix SecureCore Tiano 2.0 can't properly initiate LegacyBios protocol when called externally
// which results in "Operating System not found" message coming from BIOS
// in this case just quit Clover to enter BIOS again
2020-02-15 15:51:18 +01:00
TerminateScreen ( ) ;
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
ReinitDesktop = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
} else {
SetBootCurrent ( ChosenEntry - > getLEGACY_ENTRY ( ) ) ;
2020-05-01 18:26:28 +02:00
ChosenEntry - > StartLegacy ( ) ;
2020-02-28 21:28:33 +01:00
}
}
if ( ChosenEntry - > getREFIT_MENU_ENTRY_LOADER_TOOL ( ) ) { // Start a EFI tool
2020-05-01 18:26:28 +02:00
ChosenEntry - > StartTool ( ) ;
2020-02-28 21:28:33 +01:00
TerminateScreen ( ) ; //does not happen
// return EFI_SUCCESS;
// BdsLibConnectAllDriversToAllControllers();
// PauseForKey(L"Returned from StartTool\n");
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
}
# ifdef ENABLE_SECURE_BOOT
2022-04-26 00:55:56 +02:00
log_technical_bug ( " not done yet " ) ;
2021-02-11 12:41:59 +01:00
// if ( ChosenEntry->getREFIT_MENU_ENTRY_SECURE_BOOT() ) { // Try to enable secure boot
// EnableSecureBoot();
2021-09-28 10:28:45 +02:00
// MainLoopRunning = false;
// AfterTool = true;
2021-02-11 12:41:59 +01:00
// }
//
// if ( ChosenEntry->getREFIT_MENU_ENTRY_SECURE_BOOT_CONFIG() ) { // Configure secure boot
// MainLoopRunning = !ConfigureSecureBoot();
2021-09-28 10:28:45 +02:00
// AfterTool = true;
2021-02-11 12:41:59 +01:00
// }
2020-02-28 21:28:33 +01:00
# endif // ENABLE_SECURE_BOOT
2022-08-02 21:12:31 +02:00
// DBG("come to Clover entry with letter %c\n", ChosenEntry->ShortcutLetter);
REFIT_MENU_ENTRY_CLOVER * LoaderEntry = ChosenEntry - > getREFIT_MENU_ENTRY_CLOVER ( ) ;
if ( ( ChosenEntry - > ShortcutLetter = = ' C ' ) | | LoaderEntry ! = NULL ) { // Clover options
// DBG("enter Clover entry\n");
2020-04-05 14:25:39 +02:00
if ( LoaderEntry - > LoadOptions . notEmpty ( ) ) {
2022-08-02 21:12:31 +02:00
2020-02-28 21:28:33 +01:00
// we are uninstalling in case user selected Clover Options and EmuVar is installed
// because adding bios boot option requires access to real nvram
//Slice: sure?
/* if (gEmuVariableControl != NULL) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
*/
2022-08-02 21:12:31 +02:00
// DBG(" Clover entry not empty\n");
2022-08-01 21:34:35 +02:00
if ( LoaderEntry - > LoadOptions . contains ( L " BO-ADD " ) ) {
2022-08-02 21:12:31 +02:00
// DBG(" BO-ADD");
2020-08-09 17:55:30 +02:00
XStringW Description ;
2020-02-28 21:28:33 +01:00
CONST CHAR16 * LoaderName ;
INTN EntryIndex , NameSize , Name2Size ;
LOADER_ENTRY * Entry ;
UINT8 * OptionalData ;
UINTN OptionalDataSize ;
UINTN BootNum ;
2022-08-02 21:12:31 +02:00
// EFI_HANDLE UsedHandle = 0;
2020-02-28 21:28:33 +01:00
2021-09-28 10:28:45 +02:00
PrintBootOptions ( false ) ;
2020-02-28 21:28:33 +01:00
for ( EntryIndex = 0 ; EntryIndex < ( INTN ) MainMenu . Entries . size ( ) ; EntryIndex + + ) {
if ( MainMenu . Entries [ EntryIndex ] . Row ! = 0 ) {
continue ;
}
if ( ! MainMenu . Entries [ EntryIndex ] . getLOADER_ENTRY ( ) ) {
continue ;
}
Entry = ( LOADER_ENTRY * ) MainMenu . Entries [ EntryIndex ] . getLOADER_ENTRY ( ) ;
2020-08-09 17:55:30 +02:00
XStringW & VolName = Entry - > Volume - > VolName ;
2022-08-01 21:34:35 +02:00
DBG ( " add entry for volume %ls \n " , VolName . wc_str ( ) ) ;
2020-08-09 17:55:30 +02:00
if ( VolName . isEmpty ( ) ) {
VolName = NullXStringW ;
2020-02-28 21:28:33 +01:00
}
2020-08-09 17:55:30 +02:00
NameSize = VolName . sizeInBytes ( ) ;
2020-02-28 21:28:33 +01:00
Name2Size = 0 ;
2020-04-27 11:50:49 +02:00
if ( Entry - > LoaderPath . notEmpty ( ) ) {
LoaderName = Basename ( Entry - > LoaderPath . wc_str ( ) ) ;
2020-02-28 21:28:33 +01:00
} else {
LoaderName = NULL ; //legacy boot
}
if ( LoaderName ! = NULL ) {
Name2Size = StrSize ( LoaderName ) ;
}
2022-08-01 21:34:35 +02:00
Description = SWPrintf ( " Clover UEFI " ) ;
2020-02-28 21:28:33 +01:00
OptionalDataSize = NameSize + Name2Size + 4 + 2 ; //signature + VolNameSize
2020-08-15 15:47:56 +02:00
OptionalData = ( __typeof__ ( OptionalData ) ) AllocateZeroPool ( OptionalDataSize ) ;
2020-02-28 21:28:33 +01:00
if ( OptionalData = = NULL ) {
break ;
}
CopyMem ( OptionalData , " Clvr " , 4 ) ; //signature = 0x72766c43
CopyMem ( OptionalData + 4 , & NameSize , 2 ) ;
2020-08-09 17:55:30 +02:00
CopyMem ( OptionalData + 6 , VolName . wc_str ( ) , VolName . sizeInBytes ( ) ) ;
2020-02-28 21:28:33 +01:00
if ( Name2Size ! = 0 ) {
CopyMem ( OptionalData + 6 + NameSize , LoaderName , Name2Size ) ;
}
2022-08-02 21:12:31 +02:00
// UsedHandle = LoaderEntry->Volume->DeviceHandle;
2020-02-28 21:28:33 +01:00
Status = AddBootOptionForFile (
LoaderEntry - > Volume - > DeviceHandle ,
LoaderEntry - > LoaderPath ,
2021-09-28 10:28:45 +02:00
true ,
2020-08-09 17:55:30 +02:00
Description . wc_str ( ) ,
2020-02-28 21:28:33 +01:00
OptionalData ,
OptionalDataSize ,
EntryIndex ,
( UINT16 * ) & BootNum
) ;
if ( ! EFI_ERROR ( Status ) ) {
2021-09-27 21:40:40 +02:00
DBG ( " Entry %lld assigned option %04llX \n " , EntryIndex , BootNum ) ;
2020-02-28 21:28:33 +01:00
Entry - > BootNum = BootNum ;
}
FreePool ( OptionalData ) ;
2022-08-02 21:12:31 +02:00
break ;
2020-02-28 21:28:33 +01:00
} //for (EntryIndex
2021-09-28 10:28:45 +02:00
PrintBootOptions ( false ) ;
2022-08-01 21:34:35 +02:00
} else if ( LoaderEntry - > LoadOptions . contains ( L " BO-REMOVE " ) ) {
2021-09-28 10:28:45 +02:00
PrintBootOptions ( false ) ;
2020-02-28 21:28:33 +01:00
Status = DeleteBootOptionForFile ( LoaderEntry - > Volume - > DeviceHandle ,
LoaderEntry - > LoaderPath
) ;
2021-09-28 10:28:45 +02:00
PrintBootOptions ( false ) ;
2022-08-01 21:34:35 +02:00
} else if ( LoaderEntry - > LoadOptions . contains ( L " BO-PRINT " ) ) {
2021-09-28 10:28:45 +02:00
PrintBootOptions ( true ) ;
2020-02-15 15:51:18 +01:00
}
2020-02-28 21:28:33 +01:00
}
2021-09-28 10:28:45 +02:00
MainLoopRunning = false ;
AfterTool = true ;
2020-02-28 21:28:33 +01:00
}
2020-02-15 15:51:18 +01:00
} //MainLoopRunning
UninitRefitLib ( ) ;
if ( ! AfterTool ) {
// PauseForKey(L"After uninit");
//reconnectAll
if ( ! gFirmwareClover ) {
BdsLibConnectAllEfi ( ) ;
}
else {
DBG ( " ConnectAll after refresh menu \n " ) ;
BdsLibConnectAllDriversToAllControllers ( ) ;
}
// ReinitRefitLib();
// PauseForKey(L"After ReinitRefitLib");
}
if ( ReinitDesktop ) {
2020-10-03 19:02:31 +02:00
DBG ( " ReinitRefitLib after theme change \n " ) ;
ReinitRefitLib ( ) ;
2020-02-15 15:51:18 +01:00
}
2020-10-03 19:02:31 +02:00
// PauseForKey(L"After ReinitRefitLib");
2020-02-15 15:51:18 +01:00
} while ( ReinitDesktop ) ;
// If we end up here, things have gone wrong. Try to reboot, and if that
// fails, go into an endless loop.
//Slice - NO!!! Return to EFI GUI
2020-02-16 13:00:20 +01:00
// gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
2020-02-15 15:51:18 +01:00
// EndlessIdleLoop();
# ifdef ENABLE_SECURE_BOOT
UninstallSecureBoot ( ) ;
# endif // ENABLE_SECURE_BOOT
// Unload EmuVariable before returning to EFI GUI, as it should not be present when booting other Operating Systems.
// This seems critical in some UEFI implementations, such as Phoenix UEFI 2.0
if ( gEmuVariableControl ! = NULL ) {
gEmuVariableControl - > UninstallEmulation ( gEmuVariableControl ) ;
}
2020-10-03 19:02:31 +02:00
UninitializeConsoleSim ( ) ;
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
2020-10-03 19:02:31 +02:00
destruct_globals_objects ( NULL ) ;
2021-02-06 18:16:46 +01:00
# endif
2020-10-03 19:02:31 +02:00
2020-02-15 15:51:18 +01:00
return EFI_SUCCESS ;
}
2020-02-16 13:00:20 +01:00