2019-09-03 11:58:42 +02:00
/*
Slice 2012
*/
2020-03-13 14:11:58 +01:00
# include "../entry_scan/entry_scan.h"
2020-04-11 08:21:06 +02:00
# include "../entry_scan/loader.h"
2019-09-03 11:58:42 +02:00
# include "kernel_patcher.h"
# include "ati.h"
2020-03-13 14:11:58 +01:00
# include "../libeg/nanosvg.h"
2019-09-03 11:58:42 +02:00
# include "nvidia.h"
2020-02-29 08:30:21 +01:00
# include "../refit/screen.h"
# include "../refit/menu.h"
# include "gma.h"
2020-03-31 18:05:34 +02:00
# include "../libeg/VectorGraphics.h"
2020-04-16 09:15:26 +02:00
# include "Nvram.h"
# include "BootOptions.h"
# include "StartupSound.h"
# include "Edid.h"
# include "platformdata.h"
# include "smbios.h"
# include "guid.h"
# include "card_vlist.h"
# include "Injectors.h"
# include "cpu.h"
# include "APFS.h"
# include "hda.h"
2020-04-16 11:09:22 +02:00
# include "FixBiosDsdt.h"
# include "../entry_scan/secureboot.h"
# include "../include/Pci.h"
# include "../include/Devices.h"
# include "ati_reg.h"
2020-04-16 13:19:37 +02:00
# include "../../Version.h"
2019-09-03 11:58:42 +02:00
# ifndef DEBUG_ALL
# define DEBUG_SET 1
# else
# define DEBUG_SET DEBUG_ALL
# endif
# if DEBUG_SET == 0
# define DBG(...)
# else
# define DBG(...) DebugLog (DEBUG_SET, __VA_ARGS__)
# endif
//#define DUMP_KERNEL_KEXT_PATCHES 1
//#define SHORT_LOCATE 1
//#define kXMLTagArray "array"
//EFI_GUID gRandomUUID = {0x0A0B0C0D, 0x0000, 0x1010, {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}};
2020-04-16 11:09:22 +02:00
# define NUM_OF_CONFIGS 3
# define GEN_PMCON_1 0xA0
2020-04-04 14:27:02 +02:00
INTN OldChosenTheme ;
INTN OldChosenConfig ;
INTN OldChosenDsdt ;
UINTN OldChosenAudio ;
BOOLEAN SavePreBootLog ;
UINT8 DefaultAudioVolume ;
INTN LayoutBannerOffset = 64 ;
INTN LayoutTextOffset = 0 ;
INTN LayoutButtonOffset = 0 ;
2019-09-03 11:58:42 +02:00
2020-05-01 02:14:11 +02:00
ACPI_PATCHED_AML * ACPIPatchedAML = NULL ;
2019-09-03 11:58:42 +02:00
SIDELOAD_KEXT * InjectKextList = NULL ;
//SYSVARIABLES *SysVariables;
CHAR16 * IconFormat = NULL ;
TagPtr gConfigDict [ NUM_OF_CONFIGS ] = { NULL , NULL , NULL } ;
SETTINGS_DATA gSettings ;
LANGUAGES gLanguage ;
GFX_PROPERTIES gGraphics [ 4 ] ; //no more then 4 graphics cards
HDA_PROPERTIES gAudios [ 4 ] ; //no more then 4 Audio Controllers
//SLOT_DEVICE Arpt;
SLOT_DEVICE SlotDevices [ 16 ] ; //assume DEV_XXX, Arpt=6
EFI_EDID_DISCOVERED_PROTOCOL * EdidDiscovered ;
//UINT8 *gEDID = NULL;
//EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
//UINT16 gCPUtype;
UINTN NGFX = 0 ; // number of GFX
UINTN NHDA = 0 ; // number of HDA Devices
UINTN nLanCards ; // number of LAN cards
UINT16 gLanVendor [ 4 ] ; // their vendors
UINT8 * gLanMmio [ 4 ] ; // their MMIO regions
UINT8 gLanMac [ 4 ] [ 6 ] ; // their MAC addresses
UINTN nLanPaths ; // number of LAN pathes
UINTN ThemesNum = 0 ;
2020-03-30 10:34:16 +02:00
CONST CHAR16 * ThemesList [ 100 ] ; //no more then 100 themes?
2019-09-03 11:58:42 +02:00
UINTN ConfigsNum ;
CHAR16 * ConfigsList [ 20 ] ;
2020-05-01 02:14:11 +02:00
UINTN DsdtsNum = 0 ;
2019-09-03 11:58:42 +02:00
CHAR16 * DsdtsList [ 20 ] ;
UINTN AudioNum ;
HDA_OUTPUTS AudioList [ 20 ] ;
2019-09-12 12:37:33 +02:00
UINTN RtVariablesNum ;
RT_VARIABLES * RtVariables ;
2019-09-03 11:58:42 +02:00
// firmware
BOOLEAN gFirmwareClover = FALSE ;
UINTN gEvent ;
UINT16 gBacklightLevel ;
2020-05-11 17:44:00 +02:00
//BOOLEAN defDSM;
//UINT16 dropDSM;
2019-09-03 11:58:42 +02:00
BOOLEAN GetLegacyLanAddress ;
BOOLEAN ResumeFromCoreStorage ;
BOOLEAN gRemapSmBiosIsRequire ;
2020-02-17 21:41:09 +01:00
CONST CHAR16 * * SystemPlists = NULL ;
CONST CHAR16 * * InstallPlists = NULL ;
CONST CHAR16 * * RecoveryPlists = NULL ;
2019-09-03 11:58:42 +02:00
// QPI
BOOLEAN SetTable132 = FALSE ;
2020-04-01 14:57:32 +02:00
//EG_PIXEL SelectionBackgroundPixel = { 0xef, 0xef, 0xef, 0xff }; //define in lib.h
2020-03-29 18:17:27 +02:00
const INTN BCSMargin = 11 ;
2019-09-03 11:58:42 +02:00
2020-04-16 09:15:26 +02:00
//
DRIVERS_FLAGS gDriversFlags ; //the initializer is not needed for global variables
# ifdef FIRMWARE_REVISION
CONST CHAR16 * gFirmwareRevision = FIRMWARE_REVISION ;
2020-04-16 13:19:37 +02:00
CONST CHAR8 * gRevisionStr = REVISION_STR ;
2020-04-16 14:24:21 +02:00
CONST CHAR8 * gFirmwareBuildDate = FIRMWARE_BUILDDATE ;
CONST CHAR8 * gBuildInfo = BUILDINFOS_STR ;
2020-04-16 09:15:26 +02:00
# else
2020-04-16 14:24:21 +02:00
CONST CHAR16 * gFirmwareRevision = " unknown " ;
CONST CHAR8 * gRevisionStr = " unknown " ;
CONST CHAR8 * gFirmwareBuildDate = " unknown " ;
CONST CHAR8 * gBuildInfo = NULL ;
2020-04-16 09:15:26 +02:00
# endif
EFI_GUID gUuid ;
EMU_VARIABLE_CONTROL_PROTOCOL * gEmuVariableControl = NULL ;
2019-09-03 11:58:42 +02:00
extern BOOLEAN NeedPMfix ;
2020-04-04 14:27:02 +02:00
2019-09-03 11:58:42 +02:00
//extern INTN OldChosenAudio;
2020-04-26 11:39:41 +02:00
2019-09-03 11:58:42 +02:00
// global configuration with default values
REFIT_CONFIG GlobalConfig = {
- 1 , // INTN Timeout;
0 , // UINTN DisableFlags;
FALSE , // BOOLEAN TextOnly;
TRUE , // BOOLEAN Quiet;
FALSE , // BOOLEAN LegacyFirst;
FALSE , // BOOLEAN NoLegacy;
FALSE , // BOOLEAN DebugLog;
FALSE , // BOOLEAN FastBoot;
FALSE , // BOOLEAN NeverHibernate;
FALSE , // BOOLEAN StrictHibernate;
FALSE , // BOOLEAN RtcHibernateAware;
2020-03-27 17:50:17 +01:00
FALSE , // BOOLEAN HibernationFixup;
FALSE , // BOOLEAN SignatureFixup;
2020-03-31 14:35:04 +02:00
NULL , // CHAR16 *Theme;
2019-09-03 11:58:42 +02:00
NULL , // CHAR16 *ScreenResolution;
0 , // INTN ConsoleMode;
2020-03-27 17:50:17 +01:00
FALSE , // BOOLEAN CustomIcons;
2019-09-03 11:58:42 +02:00
ICON_FORMAT_DEF , // INTN IconFormat;
FALSE , // BOOLEAN NoEarlyProgress;
2020-04-16 13:04:24 +02:00
0xFF , // INT32 Timezone; / 0xFF - not set
2019-09-03 11:58:42 +02:00
FALSE , // BOOLEAN ShowOptimus;
0xC0 , // INTN Codepage;
0xC0 , // INTN CodepageSize; //extended latin
} ;
static struct FIX_CONFIG { const CHAR8 * oldName ; const CHAR8 * newName ; UINT32 bitData ; } FixesConfig [ ] =
{
{ " AddDTGP_0001 " , " AddDTGP " , FIX_DTGP } ,
{ " FixDarwin_0002 " , " FixDarwin " , FIX_WARNING } ,
{ " FixShutdown_0004 " , " FixShutdown " , FIX_SHUTDOWN } ,
{ " AddMCHC_0008 " , " AddMCHC " , FIX_MCHC } ,
{ " FixHPET_0010 " , " FixHPET " , FIX_HPET } ,
{ " FakeLPC_0020 " , " FakeLPC " , FIX_LPC } ,
{ " FixIPIC_0040 " , " FixIPIC " , FIX_IPIC } ,
{ " FixSBUS_0080 " , " FixSBUS " , FIX_SBUS } ,
{ " FixDisplay_0100 " , " FixDisplay " , FIX_DISPLAY } ,
{ " FixIDE_0200 " , " FixIDE " , FIX_IDE } ,
{ " FixSATA_0400 " , " FixSATA " , FIX_SATA } ,
{ " FixFirewire_0800 " , " FixFirewire " , FIX_FIREWIRE } ,
{ " FixUSB_1000 " , " FixUSB " , FIX_USB } ,
{ " FixLAN_2000 " , " FixLAN " , FIX_LAN } ,
{ " FixAirport_4000 " , " FixAirport " , FIX_WIFI } ,
{ " FixHDA_8000 " , " FixHDA " , FIX_HDA } ,
{ " FixDarwin7_10000 " , " FixDarwin7 " , FIX_DARWIN } ,
{ " FIX_RTC_20000 " , " FixRTC " , FIX_RTC } ,
{ " FIX_TMR_40000 " , " FixTMR " , FIX_TMR } ,
{ " AddIMEI_80000 " , " AddIMEI " , FIX_IMEI } ,
{ " FIX_INTELGFX_100000 " , " FixIntelGfx " , FIX_INTELGFX } ,
{ " FIX_WAK_200000 " , " FixWAK " , FIX_WAK } ,
{ " DeleteUnused_400000 " , " DeleteUnused " , FIX_UNUSED } ,
{ " FIX_ADP1_800000 " , " FixADP1 " , FIX_ADP1 } ,
{ " AddPNLF_1000000 " , " AddPNLF " , FIX_PNLF } ,
{ " FIX_S3D_2000000 " , " FixS3D " , FIX_S3D } ,
{ " FIX_ACST_4000000 " , " FixACST " , FIX_ACST } ,
{ " AddHDMI_8000000 " , " AddHDMI " , FIX_HDMI } ,
{ " FixRegions_10000000 " , " FixRegions " , FIX_REGIONS } ,
{ " FixHeaders_20000000 " , " FixHeaders " , FIX_HEADERS } ,
{ NULL , " FixMutex " , FIX_MUTEX }
} ;
/*
VOID __inline WaitForSts ( VOID ) {
UINT32 inline_timeout = 100000 ;
while ( AsmReadMsr64 ( MSR_IA32_PERF_STATUS ) & ( 1 < < 21 ) ) { if ( ! inline_timeout - - ) break ; }
}
*/
2020-02-23 06:53:21 +01:00
#if 0
2019-09-03 11:58:42 +02:00
UINT32
GetCrc32 (
UINT8 * Buffer ,
UINTN Size
)
{
UINTN i ;
UINTN Len ;
UINT32 x ;
UINT32 * Fake ;
Fake = ( UINT32 * ) Buffer ;
if ( Fake = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " Buffer=NULL \n " ) ;
2019-09-03 11:58:42 +02:00
return 0 ;
}
x = 0 ;
Len = Size > > 2 ;
for ( i = 0 ; i < Len ; i + + ) {
x + = Fake [ i ] ;
}
return x ;
}
2020-02-23 06:53:21 +01:00
# else //nice programming
UINT32
GetCrc32 (
UINT8 * Buffer ,
UINTN Size
)
{
UINT32 x = 0 ;
UINT32 * Fake = ( UINT32 * ) Buffer ;
if ( ! Fake ) return 0 ;
Size > > = 2 ;
while ( Size - - ) x + = * Fake + + ;
return x ;
}
# endif
2019-09-03 11:58:42 +02:00
ACPI_NAME_LIST *
ParseACPIName ( CHAR8 * String )
{
ACPI_NAME_LIST * List = NULL ;
ACPI_NAME_LIST * Next = NULL ;
INTN i , j , Len , pos0 , pos1 ;
Len = AsciiStrLen ( String ) ;
2020-03-25 19:32:44 +01:00
// DBG("parse ACPI name: %s\n", String);
2019-09-03 11:58:42 +02:00
if ( Len > 0 ) {
//Parse forward but put in stack LIFO "_SB.PCI0.RP02.PXSX" -1,3,8,13,18
pos0 = - 1 ;
while ( pos0 < Len ) {
2019-12-21 01:31:49 +01:00
List = ( __typeof__ ( List ) ) AllocateZeroPool ( sizeof ( ACPI_NAME_LIST ) ) ;
2019-09-03 11:58:42 +02:00
List - > Next = Next ;
2019-12-21 01:31:49 +01:00
List - > Name = ( __typeof__ ( List - > Name ) ) AllocateZeroPool ( 5 ) ;
2019-09-03 11:58:42 +02:00
pos1 = pos0 + 1 ;
while ( ( pos1 < Len ) & & String [ pos1 ] ! = ' . ' ) pos1 + + ; // 3,8,13,18
// if ((pos1 == Len) || (String[pos1] == ',')) { //always
for ( i = pos0 + 1 , j = 0 ; i < pos1 ; i + + ) {
List - > Name [ j + + ] = String [ i ] ;
}
// extend by '_' up to 4 symbols
if ( j < 4 ) {
2020-02-14 05:15:10 +01:00
SetMem ( List - > Name + j , 4 - j , ' _ ' ) ;
2019-09-03 11:58:42 +02:00
}
List - > Name [ 4 ] = ' \0 ' ;
// }
2020-03-25 19:32:44 +01:00
// DBG("string between [%d,%d]: %s\n", pos0, pos1, List->Name);
2019-09-03 11:58:42 +02:00
pos0 = pos1 ; //comma or zero@end
Next = List ;
}
}
return List ;
}
VOID
ParseLoadOptions (
OUT CHAR16 * * Conf ,
OUT TagPtr * Dict
)
{
CHAR8 * End ;
CHAR8 * Start ;
UINTN TailSize ;
UINTN i ;
2020-02-17 21:41:09 +01:00
CONST CHAR8 * PlistStrings [ ] =
2019-09-03 11:58:42 +02:00
{
" <?xml " ,
" <!DOCTYPE plist " ,
" <plist " ,
" <dict> " ,
" \0 "
} ;
UINTN PlistStringsLen ;
CHAR8 * AsciiConf ;
AsciiConf = NULL ;
* Conf = NULL ;
* Dict = NULL ;
Start = ( CHAR8 * ) SelfLoadedImage - > LoadOptions ;
End = ( CHAR8 * ) ( ( CHAR8 * ) SelfLoadedImage - > LoadOptions + SelfLoadedImage - > LoadOptionsSize ) ;
while ( ( Start < End ) & & ( ( * Start = = ' ' ) | | ( * Start = = ' \\ ' ) | | ( * Start = = ' / ' ) ) )
{
+ + Start ;
}
TailSize = End - Start ;
2020-04-23 18:05:21 +02:00
//DBG("TailSize = %d\n", TailSize);
2019-09-03 11:58:42 +02:00
if ( ( TailSize ) < = 0 ) {
return ;
}
for ( i = 0 ; PlistStrings [ i ] [ 0 ] ! = ' \0 ' ; i + + ) {
2020-04-28 12:49:24 +02:00
PlistStringsLen = AsciiStrLen ( PlistStrings [ i ] ) ;
2020-04-23 18:05:21 +02:00
//DBG("PlistStrings[%d] = %s\n", i, PlistStrings[i]);
2019-09-03 11:58:42 +02:00
if ( PlistStringsLen < TailSize ) {
2020-04-28 12:49:24 +02:00
if ( AsciiStriNCmp ( PlistStrings [ i ] , Start , PlistStringsLen ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " - found plist string = %s, parse XML in LoadOptions \n " , PlistStrings [ i ] ) ;
2020-05-15 05:23:33 +02:00
if ( ParseXML ( Start , Dict , ( UINT32 ) TailSize ) ! = EFI_SUCCESS ) {
2019-09-03 11:58:42 +02:00
* Dict = NULL ;
2020-04-23 18:05:21 +02:00
DBG ( " - [!] xml in load options is bad \n " ) ;
2019-09-03 11:58:42 +02:00
return ;
}
return ;
}
}
}
while ( ( End > Start ) & & ( ( * End = = ' ' ) | | ( * End = = ' \\ ' ) | | ( * End = = ' / ' ) ) ) {
- - End ;
}
TailSize = End - Start ;
2020-04-23 18:05:21 +02:00
// DBG("TailSize2 = %d\n", TailSize);
2019-09-03 11:58:42 +02:00
if ( TailSize > 6 ) {
2020-04-28 12:49:24 +02:00
if ( AsciiStriNCmp ( " .plist " , End - 6 , 6 ) ) {
2019-09-03 11:58:42 +02:00
End - = 6 ;
TailSize - = 6 ;
2020-04-23 18:05:21 +02:00
// DBG("TailSize3 = %d\n", TailSize);
2019-09-03 11:58:42 +02:00
}
} else if ( TailSize < = 0 ) {
return ;
}
2020-04-27 17:16:43 +02:00
AsciiConf = ( __typeof__ ( AsciiConf ) ) AllocateCopyPool ( TailSize + 1 , Start ) ;
2019-09-03 11:58:42 +02:00
if ( AsciiConf ! = NULL ) {
* ( AsciiConf + TailSize ) = ' \0 ' ;
2020-04-28 12:49:24 +02:00
* Conf = ( __typeof_am__ ( * Conf ) ) AllocateZeroPool ( ( TailSize + 1 ) * sizeof ( * * Conf ) ) ;
2019-09-03 11:58:42 +02:00
AsciiStrToUnicodeStrS ( AsciiConf , * Conf , TailSize ) ;
2020-04-23 11:08:10 +02:00
FreePool ( AsciiConf ) ;
2019-09-03 11:58:42 +02:00
}
}
//
// analyze SelfLoadedImage->LoadOptions to extract Default Volume and Default Loader
// input and output data are global
//
VOID
GetBootFromOption ( VOID )
{
2019-12-27 18:01:40 +01:00
UINT8 * Data = ( UINT8 * ) SelfLoadedImage - > LoadOptions ;
2019-09-03 11:58:42 +02:00
UINTN Len = SelfLoadedImage - > LoadOptionsSize ;
UINTN NameSize , Name2Size ;
Data + = 4 ; //skip signature as we already here
NameSize = * ( UINT16 * ) Data ;
Data + = 2 ; // pointer to Volume name
2019-12-21 01:31:49 +01:00
gSettings . DefaultVolume = ( __typeof__ ( gSettings . DefaultVolume ) ) AllocateCopyPool ( NameSize , Data ) ;
2019-09-03 11:58:42 +02:00
Data + = NameSize ;
Name2Size = Len - NameSize ;
if ( Name2Size ! = 0 ) {
2019-12-21 01:31:49 +01:00
gSettings . DefaultLoader = ( __typeof__ ( gSettings . DefaultLoader ) ) AllocateCopyPool ( Name2Size , Data ) ;
2019-09-03 11:58:42 +02:00
}
2020-03-25 19:32:44 +01:00
DBG ( " Clover started with option to boot %ls from %ls \n " ,
2019-09-03 11:58:42 +02:00
( gSettings . DefaultLoader ! = NULL ) ? gSettings . DefaultLoader : L " legacy " ,
gSettings . DefaultVolume ) ;
}
//
// check if this entry corresponds to Boot# variable and then set BootCurrent
//
VOID
2020-03-10 10:45:17 +01:00
SetBootCurrent ( REFIT_MENU_ITEM_BOOTNUM * Entry )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status ;
BO_BOOT_OPTION BootOption ;
CHAR16 * VarName ;
UINTN VarSize = 0 ;
UINT8 * BootVariable ;
UINTN NameSize ;
UINT8 * Data ;
UINT16 * BootOrder ;
UINT16 * BootOrderNew ;
UINT16 * Ptr ;
UINTN BootOrderSize ;
INTN BootIndex = 0 , Index ;
VarName = PoolPrint ( L " Boot%04x " , Entry - > BootNum ) ;
2020-04-28 12:49:24 +02:00
BootVariable = ( UINT8 * ) GetNvramVariable ( VarName , & gEfiGlobalVariableGuid , NULL , & VarSize ) ;
2019-09-03 11:58:42 +02:00
if ( ( BootVariable = = NULL ) | | ( VarSize = = 0 ) ) {
2020-03-25 19:32:44 +01:00
DBG ( " Boot option %ls not found \n " , VarName ) ;
2019-09-03 11:58:42 +02:00
FreePool ( VarName ) ;
return ;
}
FreePool ( VarName ) ;
//decode the variable
BootOption . Variable = BootVariable ;
2020-04-28 14:19:28 +02:00
BootOption . VariableSize = VarSize ;
2019-09-03 11:58:42 +02:00
ParseBootOption ( & BootOption ) ;
if ( ( BootOption . OptionalDataSize = = 0 ) | |
( BootOption . OptionalData = = NULL ) | |
( * ( UINT32 * ) BootOption . OptionalData ! = CLOVER_SIGN ) ) {
DBG ( " BootVariable of the entry is empty \n " ) ;
FreePool ( BootVariable ) ;
return ;
}
Data = BootOption . OptionalData + 4 ;
NameSize = * ( UINT16 * ) Data ;
Data + = 2 ;
if ( StriCmp ( ( CHAR16 * ) Data , Entry - > Volume - > VolName ) ! = 0 ) {
2020-03-25 19:32:44 +01:00
DBG ( " Boot option %llu has other volume name %ls \n " , Entry - > BootNum , ( CHAR16 * ) Data ) ;
2019-09-03 11:58:42 +02:00
FreePool ( BootVariable ) ;
return ;
}
if ( VarSize > NameSize + 6 ) {
Data + = NameSize ;
2020-04-27 11:50:49 +02:00
if ( StriCmp ( ( CHAR16 * ) Data , Basename ( Entry - > LoaderPath . wc_str ( ) ) ) ! = 0 ) {
2020-03-25 19:32:44 +01:00
DBG ( " Boot option %llu has other loader name %ls \n " , Entry - > BootNum , ( CHAR16 * ) Data ) ;
2019-09-03 11:58:42 +02:00
FreePool ( BootVariable ) ;
return ;
}
}
FreePool ( BootVariable ) ;
//all check passed, save the number
Status = SetNvramVariable ( L " BootCurrent " ,
& gEfiGlobalVariableGuid ,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
sizeof ( UINT16 ) ,
& Entry - > BootNum ) ;
if ( EFI_ERROR ( Status ) ) {
2020-03-25 19:32:44 +01:00
DBG ( " Can't save BootCurrent, status=%s \n " , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
}
//Next step is rotate BootOrder to set BootNum to first place
2020-04-28 12:49:24 +02:00
BootOrder = ( __typeof__ ( BootOrder ) ) GetNvramVariable ( L " BootOrder " , & gEfiGlobalVariableGuid , NULL , & BootOrderSize ) ;
2019-09-03 11:58:42 +02:00
if ( BootOrder = = NULL ) {
return ;
}
VarSize = ( INTN ) BootOrderSize / sizeof ( UINT16 ) ; //reuse variable
for ( Index = 0 ; Index < ( INTN ) VarSize ; Index + + ) {
if ( BootOrder [ Index ] = = Entry - > BootNum ) {
BootIndex = Index ;
break ;
}
}
if ( BootIndex ! = 0 ) {
2019-12-21 01:31:49 +01:00
BootOrderNew = ( __typeof__ ( BootOrderNew ) ) AllocatePool ( BootOrderSize ) ;
2019-09-03 11:58:42 +02:00
Ptr = BootOrderNew ;
for ( Index = 0 ; Index < ( INTN ) VarSize - BootIndex ; Index + + ) {
* Ptr + + = BootOrder [ Index + BootIndex ] ;
}
for ( Index = 0 ; Index < BootIndex ; Index + + ) {
* Ptr + + = BootOrder [ Index ] ;
}
Status = gRT - > SetVariable ( L " BootOrder " ,
& gEfiGlobalVariableGuid ,
EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS ,
BootOrderSize ,
BootOrderNew
) ;
if ( EFI_ERROR ( Status ) ) {
2020-03-25 19:32:44 +01:00
DBG ( " Can't save BootOrder, status=%s \n " , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
}
DBG ( " Set new BootOrder \n " ) ;
PrintBootOrder ( BootOrderNew , VarSize ) ;
FreePool ( BootOrderNew ) ;
}
FreePool ( BootOrder ) ;
}
//
// returns binary setting in a new allocated buffer and data length in dataLen.
// data can be specified in <data></data> base64 encoded
// or in <string></string> hex encoded
//
2019-12-27 18:01:40 +01:00
UINT8
2019-09-03 11:58:42 +02:00
* GetDataSetting (
IN TagPtr Dict ,
2020-02-17 21:41:09 +01:00
IN CONST CHAR8 * PropName ,
2019-09-03 11:58:42 +02:00
OUT UINTN * DataLen
)
{
TagPtr Prop ;
UINT8 * Data = NULL ;
UINT32 Len ;
//UINTN i;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , PropName ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > data ! = NULL /*&& Prop->dataLen > 0*/ ) { //rehabman: allow zero length data
// data property
2020-04-28 12:49:24 +02:00
Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Prop - > dataLen ) ;
2020-05-01 18:26:28 +02:00
CopyMem ( Data , Prop - > data , Prop - > dataLen ) ;
2019-09-03 11:58:42 +02:00
if ( DataLen ! = NULL ) {
* DataLen = Prop - > dataLen ;
}
/*
2020-04-23 18:05:21 +02:00
DBG ( " Data: %p, Len: %d = " , Data , Prop - > dataLen ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Prop - > dataLen ; i + + ) {
2020-04-23 18:05:21 +02:00
DBG ( " %02hhX " , Data [ i ] ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2019-09-03 11:58:42 +02:00
*/
} else {
// assume data in hex encoded string property
2020-04-28 12:49:24 +02:00
Len = ( UINT32 ) AsciiStrLen ( Prop - > string ) > > 1 ; // number of hex digits
2019-12-21 01:31:49 +01:00
Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Len ) ; // 2 chars per byte, one more byte for odd number
2019-09-03 11:58:42 +02:00
Len = hex2bin ( Prop - > string , Data , Len ) ;
if ( DataLen ! = NULL ) {
* DataLen = Len ;
}
/*
2020-04-23 18:05:21 +02:00
DBG ( " Data(str): %p, Len: %d = " , data , len ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Len ; i + + ) {
2020-04-23 18:05:21 +02:00
DBG ( " %02hhX " , data [ i ] ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2019-09-03 11:58:42 +02:00
*/
}
}
return Data ;
}
EFI_STATUS
LoadUserSettings (
IN EFI_FILE * RootDir ,
2020-02-17 21:41:09 +01:00
IN CONST CHAR16 * ConfName ,
2019-09-03 11:58:42 +02:00
TagPtr * Dict )
{
EFI_STATUS Status = EFI_NOT_FOUND ;
UINTN Size = 0 ;
CHAR8 * gConfigPtr = NULL ;
CHAR16 * ConfigPlistPath ;
CHAR16 * ConfigOemPath ;
// DbgHeader("LoadUserSettings");
// load config
if ( ( ConfName = = NULL ) | | ( Dict = = NULL ) ) {
return EFI_NOT_FOUND ;
}
2020-04-23 11:08:10 +02:00
ConfigPlistPath = PoolPrint ( L " EFI \\ CLOVER \\ %s.plist " , ConfName ) ;
ConfigOemPath = PoolPrint ( L " %s \\ %s.plist " , OEMPath , ConfName ) ;
2019-09-03 11:58:42 +02:00
if ( FileExists ( SelfRootDir , ConfigOemPath ) ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( SelfRootDir , ConfigOemPath , ( UINT8 * * ) & gConfigPtr , & Size ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
if ( ( RootDir ! = NULL ) & & FileExists ( RootDir , ConfigPlistPath ) ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( RootDir , ConfigPlistPath , ( UINT8 * * ) & gConfigPtr , & Size ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using %ls.plist at RootDir at path: %ls \n " , ConfName , ConfigPlistPath ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( SelfRootDir , ConfigPlistPath , ( UINT8 * * ) & gConfigPtr , & Size ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using %ls.plist at SelfRootDir at path: %ls \n " , ConfName , ConfigPlistPath ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) & & gConfigPtr ! = NULL ) {
2020-05-15 05:23:33 +02:00
Status = ParseXML ( ( const CHAR8 * ) gConfigPtr , Dict , ( UINT32 ) Size ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// Dict = NULL;
2020-04-23 18:05:21 +02:00
DBG ( " config.plist parse error Status=%s \n " , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
return Status ;
}
}
return Status ;
}
2020-05-16 21:30:29 +02:00
STATIC BOOLEAN AddCustomLoaderEntry ( IN CUSTOM_LOADER_ENTRY * Entry )
2019-09-03 11:58:42 +02:00
{
if ( Entry = = NULL ) {
return FALSE ;
}
if ( gSettings . CustomEntries ) {
CUSTOM_LOADER_ENTRY * Entries = gSettings . CustomEntries ;
while ( Entries - > Next ! = NULL ) {
Entries = Entries - > Next ;
}
Entries - > Next = Entry ;
} else {
gSettings . CustomEntries = Entry ;
}
return TRUE ;
}
2020-05-16 21:30:29 +02:00
2019-09-03 11:58:42 +02:00
STATIC BOOLEAN AddCustomLegacyEntry ( IN CUSTOM_LEGACY_ENTRY * Entry )
{
if ( Entry = = NULL ) {
return FALSE ;
}
if ( gSettings . CustomLegacy ! = NULL ) {
CUSTOM_LEGACY_ENTRY * Entries = gSettings . CustomLegacy ;
while ( Entries - > Next ! = NULL ) {
Entries = Entries - > Next ;
}
Entries - > Next = Entry ;
} else {
gSettings . CustomLegacy = Entry ;
}
return TRUE ;
}
STATIC
BOOLEAN
AddCustomToolEntry (
IN CUSTOM_TOOL_ENTRY * Entry
)
{
if ( Entry = = NULL ) {
return FALSE ;
}
if ( gSettings . CustomTool ) {
CUSTOM_TOOL_ENTRY * Entries = gSettings . CustomTool ;
while ( Entries - > Next ! = NULL ) {
Entries = Entries - > Next ;
}
Entries - > Next = Entry ;
} else {
gSettings . CustomTool = Entry ;
}
return TRUE ;
}
STATIC
BOOLEAN
AddCustomSubEntry (
IN OUT CUSTOM_LOADER_ENTRY * Entry ,
IN CUSTOM_LOADER_ENTRY * SubEntry )
{
if ( ( Entry = = NULL ) | | ( SubEntry = = NULL ) ) {
return FALSE ;
}
if ( Entry - > SubEntries ! = NULL ) {
CUSTOM_LOADER_ENTRY * Entries = Entry - > SubEntries ;
while ( Entries - > Next ! = NULL ) {
Entries = Entries - > Next ;
}
Entries - > Next = SubEntry ;
} else {
Entry - > SubEntries = SubEntry ;
}
return TRUE ;
}
BOOLEAN
CopyKernelAndKextPatches ( IN OUT KERNEL_AND_KEXT_PATCHES * Dst ,
IN KERNEL_AND_KEXT_PATCHES * Src )
{
if ( Dst = = NULL | | Src = = NULL ) return FALSE ;
Dst - > KPDebug = Src - > KPDebug ;
2020-05-09 10:55:33 +02:00
// Dst->KPKernelCpu = Src->KPKernelCpu;
2019-09-03 11:58:42 +02:00
Dst - > KPKernelLapic = Src - > KPKernelLapic ;
Dst - > KPKernelXCPM = Src - > KPKernelXCPM ;
Dst - > KPKernelPm = Src - > KPKernelPm ;
Dst - > KPAppleIntelCPUPM = Src - > KPAppleIntelCPUPM ;
Dst - > KPAppleRTC = Src - > KPAppleRTC ;
2020-05-27 20:04:31 +02:00
Dst - > EightApple = Src - > EightApple ;
2019-09-03 11:58:42 +02:00
Dst - > KPDELLSMBIOS = Src - > KPDELLSMBIOS ;
Dst - > FakeCPUID = Src - > FakeCPUID ;
Dst - > KPPanicNoKextDump = Src - > KPPanicNoKextDump ;
if ( Src - > KPATIConnectorsController ! = NULL ) {
2020-04-27 17:16:43 +02:00
Dst - > KPATIConnectorsController = ( __typeof__ ( Dst - > KPATIConnectorsController ) ) AllocateCopyPool ( AsciiStrSize ( Src - > KPATIConnectorsController ) , Src - > KPATIConnectorsController ) ;
2019-09-03 11:58:42 +02:00
}
if ( ( Src - > KPATIConnectorsDataLen > 0 ) & &
( Src - > KPATIConnectorsData ! = NULL ) & &
( Src - > KPATIConnectorsPatch ! = NULL ) ) {
Dst - > KPATIConnectorsDataLen = Src - > KPATIConnectorsDataLen ;
2020-04-27 17:16:43 +02:00
Dst - > KPATIConnectorsData = ( __typeof__ ( Dst - > KPATIConnectorsData ) ) AllocateCopyPool ( Src - > KPATIConnectorsDataLen , Src - > KPATIConnectorsData ) ;
Dst - > KPATIConnectorsPatch = ( __typeof__ ( Dst - > KPATIConnectorsPatch ) ) AllocateCopyPool ( Src - > KPATIConnectorsDataLen , Src - > KPATIConnectorsPatch ) ;
2019-09-03 11:58:42 +02:00
}
if ( ( Src - > NrForceKexts > 0 ) & & ( Src - > ForceKexts ! = NULL ) ) {
INTN i ;
2019-12-21 01:31:49 +01:00
Dst - > ForceKexts = ( __typeof__ ( Dst - > ForceKexts ) ) AllocatePool ( Src - > NrForceKexts * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Src - > NrForceKexts ; i + + ) {
Dst - > ForceKexts [ Dst - > NrForceKexts + + ] = EfiStrDuplicate ( Src - > ForceKexts [ i ] ) ;
}
}
if ( ( Src - > NrKexts > 0 ) & & ( Src - > KextPatches ! = NULL ) ) {
INTN i ;
2019-12-21 01:31:49 +01:00
Dst - > KextPatches = ( __typeof__ ( Dst - > KextPatches ) ) AllocatePool ( Src - > NrKexts * sizeof ( KEXT_PATCH ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Src - > NrKexts ; i + + )
{
if ( ( Src - > KextPatches [ i ] . DataLen < = 0 ) | |
( Src - > KextPatches [ i ] . Data = = NULL ) | |
( Src - > KextPatches [ i ] . Patch = = NULL ) ) {
continue ;
}
if ( Src - > KextPatches [ i ] . Name ) {
2020-04-27 17:16:43 +02:00
Dst - > KextPatches [ Dst - > NrKexts ] . Name = ( CHAR8 * ) AllocateCopyPool ( AsciiStrSize ( Src - > KextPatches [ i ] . Name ) , Src - > KextPatches [ i ] . Name ) ;
2019-09-03 11:58:42 +02:00
}
if ( Src - > KextPatches [ i ] . Label ) {
2020-04-27 17:16:43 +02:00
Dst - > KextPatches [ Dst - > NrKexts ] . Label = ( CHAR8 * ) AllocateCopyPool ( AsciiStrSize ( Src - > KextPatches [ i ] . Label ) , Src - > KextPatches [ i ] . Label ) ;
2019-09-03 11:58:42 +02:00
}
Dst - > KextPatches [ Dst - > NrKexts ] . MenuItem . BValue = Src - > KextPatches [ i ] . MenuItem . BValue ;
Dst - > KextPatches [ Dst - > NrKexts ] . IsPlistPatch = Src - > KextPatches [ i ] . IsPlistPatch ;
Dst - > KextPatches [ Dst - > NrKexts ] . DataLen = Src - > KextPatches [ i ] . DataLen ;
2020-04-27 17:16:43 +02:00
Dst - > KextPatches [ Dst - > NrKexts ] . Data = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . Data ) ) AllocateCopyPool ( Src - > KextPatches [ i ] . DataLen , Src - > KextPatches [ i ] . Data ) ;
Dst - > KextPatches [ Dst - > NrKexts ] . Patch = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . Patch ) ) AllocateCopyPool ( Src - > KextPatches [ i ] . DataLen , Src - > KextPatches [ i ] . Patch ) ;
Dst - > KextPatches [ Dst - > NrKexts ] . MatchOS = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . MatchOS ) ) AllocateCopyPool ( AsciiStrSize ( Src - > KextPatches [ i ] . MatchOS ) , Src - > KextPatches [ i ] . MatchOS ) ;
Dst - > KextPatches [ Dst - > NrKexts ] . MatchBuild = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . MatchBuild ) ) AllocateCopyPool ( AsciiStrSize ( Src - > KextPatches [ i ] . MatchBuild ) , Src - > KextPatches [ i ] . MatchBuild ) ;
2020-04-25 18:18:18 +02:00
if ( Src - > KextPatches [ i ] . StartPattern ! = NULL ) {
2020-04-27 17:16:43 +02:00
Dst - > KextPatches [ Dst - > NrKexts ] . StartPattern = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . StartPattern ) ) AllocateCopyPool ( Src - > KextPatches [ i ] . StartPatternLen , Src - > KextPatches [ i ] . StartPattern ) ;
Dst - > KextPatches [ Dst - > NrKexts ] . StartMask = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . StartMask ) ) AllocateCopyPool ( Src - > KextPatches [ i ] . StartPatternLen , Src - > KextPatches [ i ] . StartMask ) ;
2020-04-25 18:18:18 +02:00
} else {
Dst - > KextPatches [ Dst - > NrKexts ] . StartPattern = NULL ;
Dst - > KextPatches [ Dst - > NrKexts ] . StartMask = NULL ;
}
2020-04-27 17:16:43 +02:00
//ProcedureName
if ( Src - > KextPatches [ i ] . ProcedureName ! = NULL ) {
INTN len = strlen ( Src - > KextPatches [ i ] . ProcedureName ) ;
Dst - > KextPatches [ Dst - > NrKexts ] . ProcedureName = ( __typeof__ ( Dst - > KextPatches [ Dst - > NrKexts ] . ProcedureName ) ) AllocateCopyPool ( len + 1 , Src - > KextPatches [ i ] . ProcedureName ) ;
} else {
Dst - > KextPatches [ Dst - > NrKexts ] . ProcedureName = NULL ;
}
2020-04-25 18:18:18 +02:00
Dst - > KextPatches [ Dst - > NrKexts ] . StartPatternLen = Src - > KextPatches [ i ] . StartPatternLen ;
Dst - > KextPatches [ Dst - > NrKexts ] . SearchLen = Src - > KextPatches [ i ] . SearchLen ;
2019-09-03 11:58:42 +02:00
+ + ( Dst - > NrKexts ) ;
}
}
if ( ( Src - > NrKernels > 0 ) & & ( Src - > KernelPatches ! = NULL ) ) {
INTN i ;
2019-12-21 01:31:49 +01:00
Dst - > KernelPatches = ( __typeof__ ( Dst - > KernelPatches ) ) AllocatePool ( Src - > NrKernels * sizeof ( KERNEL_PATCH ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Src - > NrKernels ; i + + )
{
if ( ( Src - > KernelPatches [ i ] . DataLen < = 0 ) | |
( Src - > KernelPatches [ i ] . Data = = NULL ) | |
( Src - > KernelPatches [ i ] . Patch = = NULL ) ) {
continue ;
}
if ( Src - > KernelPatches [ i ] . Label ) {
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . Label = ( CHAR8 * ) AllocateCopyPool ( AsciiStrSize ( Src - > KernelPatches [ i ] . Label ) , Src - > KernelPatches [ i ] . Label ) ;
2019-09-03 11:58:42 +02:00
}
Dst - > KernelPatches [ Dst - > NrKernels ] . MenuItem . BValue = Src - > KernelPatches [ i ] . MenuItem . BValue ;
Dst - > KernelPatches [ Dst - > NrKernels ] . DataLen = Src - > KernelPatches [ i ] . DataLen ;
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . Data = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . Data ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . DataLen , Src - > KernelPatches [ i ] . Data ) ;
Dst - > KernelPatches [ Dst - > NrKernels ] . Patch = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . Patch ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . DataLen , Src - > KernelPatches [ i ] . Patch ) ;
2019-09-03 11:58:42 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . Count = Src - > KernelPatches [ i ] . Count ;
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . MatchOS = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . MatchOS ) ) AllocateCopyPool ( AsciiStrSize ( Src - > KernelPatches [ i ] . MatchOS ) , Src - > KernelPatches [ i ] . MatchOS ) ;
Dst - > KernelPatches [ Dst - > NrKernels ] . MatchBuild = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . MatchBuild ) ) AllocateCopyPool ( AsciiStrSize ( Src - > KernelPatches [ i ] . MatchBuild ) , Src - > KernelPatches [ i ] . MatchBuild ) ;
2019-10-08 22:57:18 +02:00
if ( Src - > KernelPatches [ i ] . MaskFind ! = NULL ) {
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . MaskFind = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . MaskFind ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . DataLen , Src - > KernelPatches [ i ] . MaskFind ) ;
2019-10-08 22:57:18 +02:00
} else {
2020-04-25 18:18:18 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . MaskFind = NULL ;
2019-10-08 22:57:18 +02:00
}
if ( Src - > KernelPatches [ i ] . MaskReplace ! = NULL ) {
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . MaskReplace = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . MaskReplace ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . DataLen , Src - > KernelPatches [ i ] . MaskReplace ) ;
2019-10-08 22:57:18 +02:00
} else {
2020-04-25 18:18:18 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . MaskReplace = NULL ;
}
if ( Src - > KernelPatches [ i ] . StartPattern ! = NULL ) {
2020-04-27 17:16:43 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . StartPattern = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . StartPattern ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . StartPatternLen , Src - > KernelPatches [ i ] . StartPattern ) ;
Dst - > KernelPatches [ Dst - > NrKernels ] . StartMask = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . StartMask ) ) AllocateCopyPool ( Src - > KernelPatches [ i ] . StartPatternLen , Src - > KernelPatches [ i ] . StartMask ) ;
2020-04-25 18:18:18 +02:00
} else {
Dst - > KernelPatches [ Dst - > NrKernels ] . StartPattern = NULL ;
Dst - > KernelPatches [ Dst - > NrKernels ] . StartMask = NULL ;
2019-10-08 22:57:18 +02:00
}
2020-05-03 09:03:06 +02:00
Dst - > KernelPatches [ Dst - > NrKernels ] . StartPatternLen = Src - > KernelPatches [ i ] . StartPatternLen ;
Dst - > KernelPatches [ Dst - > NrKernels ] . SearchLen = Src - > KernelPatches [ i ] . SearchLen ;
2020-04-27 17:16:43 +02:00
if ( Src - > KernelPatches [ i ] . ProcedureName ! = NULL ) {
INTN len = strlen ( Src - > KernelPatches [ i ] . ProcedureName ) ;
Dst - > KernelPatches [ Dst - > NrKernels ] . ProcedureName = ( __typeof__ ( Dst - > KernelPatches [ Dst - > NrKernels ] . ProcedureName ) ) AllocateCopyPool ( len , Src - > KernelPatches [ i ] . ProcedureName ) ;
} else {
Dst - > KernelPatches [ Dst - > NrKernels ] . ProcedureName = NULL ;
}
2020-04-25 18:18:18 +02:00
2019-09-03 11:58:42 +02:00
+ + ( Dst - > NrKernels ) ;
}
}
return TRUE ;
}
STATIC
CUSTOM_LOADER_ENTRY
* DuplicateCustomEntry (
IN CUSTOM_LOADER_ENTRY * Entry
)
{
if ( Entry = = NULL ) {
return NULL ;
}
2020-04-28 12:49:24 +02:00
// DuplicateEntry = (CUSTOM_LOADER_ENTRY *)AllocateZeroPool(sizeof(CUSTOM_LOADER_ENTRY));
2020-04-05 14:25:39 +02:00
CUSTOM_LOADER_ENTRY * DuplicateEntry = new CUSTOM_LOADER_ENTRY ;
2019-09-03 11:58:42 +02:00
if ( DuplicateEntry ! = NULL ) {
if ( Entry - > Volume ! = NULL ) {
DuplicateEntry - > Volume = EfiStrDuplicate ( Entry - > Volume ) ;
}
2020-04-27 11:50:49 +02:00
DuplicateEntry - > Path = Entry - > Path ;
2019-09-03 11:58:42 +02:00
2020-04-26 15:07:30 +02:00
DuplicateEntry - > LoadOptions = Entry - > LoadOptions ;
2019-09-03 11:58:42 +02:00
2020-04-23 10:23:57 +02:00
if ( Entry - > FullTitle . notEmpty ( ) ) {
2020-04-03 22:00:42 +02:00
DuplicateEntry - > FullTitle = Entry - > FullTitle ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 10:23:57 +02:00
if ( Entry - > Title . notEmpty ( ) ) {
2020-04-03 22:00:42 +02:00
DuplicateEntry - > Title = Entry - > Title ;
2019-09-03 11:58:42 +02:00
}
if ( Entry - > ImagePath ! = NULL ) {
DuplicateEntry - > ImagePath = EfiStrDuplicate ( Entry - > ImagePath ) ;
}
if ( Entry - > DriveImagePath ) {
DuplicateEntry - > DriveImagePath = EfiStrDuplicate ( Entry - > DriveImagePath ) ;
}
2020-04-01 14:57:32 +02:00
DuplicateEntry - > BootBgColor = Entry - > BootBgColor ;
2019-09-03 11:58:42 +02:00
DuplicateEntry - > Image = Entry - > Image ;
DuplicateEntry - > DriveImage = Entry - > DriveImage ;
DuplicateEntry - > Hotkey = Entry - > Hotkey ;
DuplicateEntry - > Flags = Entry - > Flags ;
DuplicateEntry - > Type = Entry - > Type ;
DuplicateEntry - > VolumeType = Entry - > VolumeType ;
DuplicateEntry - > KernelScan = Entry - > KernelScan ;
DuplicateEntry - > CustomBoot = Entry - > CustomBoot ;
DuplicateEntry - > CustomLogo = Entry - > CustomLogo ;
2020-04-03 22:00:42 +02:00
CopyKernelAndKextPatches ( & DuplicateEntry - > KernelAndKextPatches , & Entry - > KernelAndKextPatches ) ;
2019-09-03 11:58:42 +02:00
}
return DuplicateEntry ;
}
STATIC
BOOLEAN
FillinKextPatches ( IN OUT KERNEL_AND_KEXT_PATCHES * Patches ,
TagPtr DictPointer )
{
TagPtr Prop ;
// UINTN i;
if ( Patches = = NULL | | DictPointer = = NULL ) {
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Debug " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPDebug = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-05-09 10:55:33 +02:00
/*
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KernelCpu " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPKernelCpu = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-05-09 10:55:33 +02:00
*/
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KernelLapic " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPKernelLapic = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KernelXCPM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPKernelXCPM = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
if ( IsPropertyTrue ( Prop ) ) {
DBG ( " KernelXCPM: enabled \n " ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KernelPm " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPKernelPm = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " PanicNoKextDump " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPPanicNoKextDump = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AppleIntelCPUPM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPAppleIntelCPUPM = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-05-04 21:31:12 +02:00
//anyway
if ( NeedPMfix ) {
Patches - > KPKernelPm = TRUE ;
Patches - > KPAppleIntelCPUPM = TRUE ;
}
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AppleRTC " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-05-11 08:30:45 +02:00
Patches - > KPAppleRTC = ! IsPropertyFalse ( Prop ) ; //default = TRUE
2019-09-03 11:58:42 +02:00
}
2020-05-27 20:04:31 +02:00
Prop = GetProperty ( DictPointer , " EightApple " ) ;
if ( Prop ! = NULL | | gBootChanged ) {
Patches - > EightApple = IsPropertyTrue ( Prop ) ;
}
2019-09-03 11:58:42 +02:00
//
// Dell SMBIOS Patch
//
// syscl: we do not need gBootChanged and Prop is empty condition
// this change will boost Dell SMBIOS Patch a bit
// but the major target is to make code clean
Prop = GetProperty ( DictPointer , " DellSMBIOSPatch " ) ;
2020-05-11 08:30:45 +02:00
Patches - > KPDELLSMBIOS = IsPropertyTrue ( Prop ) ; // default == FALSE
2019-09-03 11:58:42 +02:00
gRemapSmBiosIsRequire = Patches - > KPDELLSMBIOS ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FakeCPUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL | | gBootChanged ) {
2020-04-23 11:08:10 +02:00
Patches - > FakeCPUID = ( UINT32 ) GetPropertyInteger ( Prop , 0 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " FakeCPUID: %X \n " , Patches - > FakeCPUID ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ATIConnectorsController " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
UINTN len = 0 , i = 0 ;
// ATIConnectors patch
2020-04-27 17:16:43 +02:00
Patches - > KPATIConnectorsController = ( __typeof__ ( Patches - > KPATIConnectorsController ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2020-04-11 17:36:40 +02:00
// AsciiStrToUnicodeStrS (Prop->string, Patches->KPATIConnectorsController, AsciiStrSize(Prop->string));
2019-09-03 11:58:42 +02:00
Patches - > KPATIConnectorsData = GetDataSetting ( DictPointer , " ATIConnectorsData " , & len ) ;
Patches - > KPATIConnectorsDataLen = len ;
Patches - > KPATIConnectorsPatch = GetDataSetting ( DictPointer , " ATIConnectorsPatch " , & i ) ;
if ( Patches - > KPATIConnectorsData = = NULL
| | Patches - > KPATIConnectorsPatch = = NULL
| | Patches - > KPATIConnectorsDataLen = = 0
| | Patches - > KPATIConnectorsDataLen ! = i ) {
// invalid params - no patching
2020-04-23 18:05:21 +02:00
DBG ( " ATIConnectors patch: invalid parameters! \n " ) ;
2019-09-03 11:58:42 +02:00
if ( Patches - > KPATIConnectorsController ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > KPATIConnectorsController ) ;
2019-09-03 11:58:42 +02:00
}
if ( Patches - > KPATIConnectorsData ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > KPATIConnectorsData ) ;
2019-09-03 11:58:42 +02:00
}
if ( Patches - > KPATIConnectorsPatch ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > KPATIConnectorsPatch ) ;
2019-09-03 11:58:42 +02:00
}
Patches - > KPATIConnectorsController = NULL ;
Patches - > KPATIConnectorsData = NULL ;
Patches - > KPATIConnectorsPatch = NULL ;
Patches - > KPATIConnectorsDataLen = 0 ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ForceKextsToLoad " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
TagPtr Prop2 = NULL ;
2020-04-28 12:49:24 +02:00
CHAR16 * * newForceKexts = ( __typeof__ ( newForceKexts ) ) AllocateZeroPool ( ( Patches - > NrForceKexts + Count ) * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
if ( Patches - > ForceKexts ! = NULL ) {
2020-05-01 18:26:28 +02:00
CopyMem ( newForceKexts , Patches - > ForceKexts , ( Patches - > NrForceKexts * sizeof ( CHAR16 * ) ) ) ;
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > ForceKexts ) ;
2019-09-03 11:58:42 +02:00
}
Patches - > ForceKexts = newForceKexts ;
2020-05-27 20:04:31 +02:00
DBG ( " ForceKextsToLoad: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
EFI_STATUS Status = GetElement ( Prop , i , & Prop2 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-05-27 20:04:31 +02:00
DBG ( " - [%02lld]: ForceKexts error %s getting next element \n " , i , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
if ( Prop2 - > string ! = NULL ) {
if ( * ( Prop2 - > string ) = = ' \\ ' ) {
+ + Prop2 - > string ;
}
if ( AsciiStrSize ( Prop2 - > string ) > 1 ) {
2020-04-28 12:49:24 +02:00
Patches - > ForceKexts [ Patches - > NrForceKexts ] = ( __typeof_am__ ( Patches - > ForceKexts [ Patches - > NrForceKexts ] ) ) AllocateZeroPool ( AsciiStrSize ( Prop2 - > string ) * sizeof ( CHAR16 ) ) ;
2019-09-03 11:58:42 +02:00
AsciiStrToUnicodeStrS ( Prop2 - > string , Patches - > ForceKexts [ Patches - > NrForceKexts ] , 255 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " - [%d]: %ls \n " , Patches - > NrForceKexts , Patches - > ForceKexts [ Patches - > NrForceKexts ] ) ;
2019-09-03 11:58:42 +02:00
+ + Patches - > NrForceKexts ;
}
}
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KextsToPatch " ) ; //zzzz
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
//delete old and create new
if ( Patches - > KextPatches ) {
2019-11-15 13:17:19 +01:00
for ( i = 0 ; i < Patches - > NrKexts ; i + + ) {
if ( Patches - > KextPatches [ i ] . Name ) {
FreePool ( Patches - > KextPatches [ i ] . Name ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . Label ) {
FreePool ( Patches - > KextPatches [ i ] . Label ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . Data ) {
FreePool ( Patches - > KextPatches [ i ] . Data ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . Patch ) {
FreePool ( Patches - > KextPatches [ i ] . Patch ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . MaskFind ) {
FreePool ( Patches - > KextPatches [ i ] . MaskFind ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . MaskReplace ) {
FreePool ( Patches - > KextPatches [ i ] . MaskReplace ) ;
2019-10-16 13:25:52 +02:00
}
2019-11-15 13:17:19 +01:00
if ( Patches - > KextPatches [ i ] . MatchOS ) {
FreePool ( Patches - > KextPatches [ i ] . MatchOS ) ;
}
if ( Patches - > KextPatches [ i ] . MatchBuild ) {
FreePool ( Patches - > KextPatches [ i ] . MatchBuild ) ;
2019-10-16 13:25:52 +02:00
}
2020-04-25 18:18:18 +02:00
if ( Patches - > KextPatches [ i ] . StartPattern ) {
FreePool ( Patches - > KextPatches [ i ] . StartPattern ) ;
}
if ( Patches - > KextPatches [ i ] . StartMask ) {
FreePool ( Patches - > KextPatches [ i ] . StartMask ) ;
}
2019-10-16 13:25:52 +02:00
}
2019-09-03 11:58:42 +02:00
Patches - > NrKexts = 0 ;
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > KextPatches ) ;
2019-10-08 22:57:18 +02:00
Patches - > KextPatches = NULL ;
2019-09-03 11:58:42 +02:00
}
if ( Count > 0 ) {
TagPtr Prop2 = NULL , Dict = NULL ;
2020-04-28 12:49:24 +02:00
KEXT_PATCH * newPatches = ( __typeof__ ( newPatches ) ) AllocateZeroPool ( Count * sizeof ( KEXT_PATCH ) ) ;
2019-09-03 11:58:42 +02:00
Patches - > KextPatches = newPatches ;
2020-04-25 18:18:18 +02:00
DBG ( " KextsToPatch: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
CHAR8 * KextPatchesName , * KextPatchesLabel ;
2019-10-08 22:57:18 +02:00
UINTN FindLen = 0 , ReplaceLen = 0 , MaskLen = 0 ;
2019-09-03 11:58:42 +02:00
UINT8 * TmpData , * TmpPatch ;
2020-05-11 08:30:45 +02:00
EFI_STATUS Status = GetElement ( Prop , i , & Prop2 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-25 18:18:18 +02:00
DBG ( " - [%02lld]: Patches error %s getting next element \n " , i , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
2020-04-25 18:18:18 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Name " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict = = NULL ) {
DBG ( " patch without Name, skipped \n " ) ;
continue ;
}
2020-04-27 17:16:43 +02:00
KextPatchesName = ( __typeof__ ( KextPatchesName ) ) AllocateCopyPool ( 255 , Dict - > string ) ;
KextPatchesLabel = ( __typeof__ ( KextPatchesLabel ) ) AllocateCopyPool ( 255 , KextPatchesName ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
//this is impossible because UnicodeStrToAsciiStr not extend output size
// UnicodeStrToAsciiStr(PoolPrint(L"%a (%a)", KextPatchesLabel, Dict->string), KextPatchesLabel);
AsciiStrCatS ( KextPatchesLabel , 255 , " ( " ) ;
AsciiStrCatS ( KextPatchesLabel , 255 , Dict - > string ) ;
AsciiStrCatS ( KextPatchesLabel , 255 , " ) " ) ;
} else {
AsciiStrCatS ( KextPatchesLabel , 255 , " (NoLabel) " ) ;
}
2020-04-23 18:05:21 +02:00
DBG ( " %s " , KextPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MenuItem . BValue = TRUE ;
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
if ( ( Dict ! = NULL ) & & IsPropertyTrue ( Dict ) ) {
2019-09-03 11:58:42 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MenuItem . BValue = FALSE ;
}
2020-04-25 18:18:18 +02:00
Dict = GetProperty ( Prop2 , " RangeFind " ) ;
Patches - > KextPatches [ Patches - > NrKexts ] . SearchLen = GetPropertyInteger ( Dict , 0 ) ; //default 0 will be calculated later
TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
if ( TmpData ! = NULL ) {
Patches - > KextPatches [ Patches - > NrKexts ] . StartPatternLen = FindLen ;
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . StartPattern = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . StartPattern ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2020-04-25 18:18:18 +02:00
FreePool ( TmpData ) ;
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-04-28 12:49:24 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . StartMask = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . StartMask ) ) AllocateZeroPool ( FindLen ) ;
2020-04-25 18:18:18 +02:00
SetMem ( Patches - > KextPatches [ Patches - > NrKexts ] . StartMask , FindLen , 0xFF ) ;
if ( TmpData ! = NULL ) {
CopyMem ( Patches - > KextPatches [ Patches - > NrKexts ] . StartMask , TmpData , ReplaceLen ) ;
}
}
if ( TmpData ! = NULL ) {
FreePool ( TmpData ) ;
}
2019-09-03 11:58:42 +02:00
TmpData = GetDataSetting ( Prop2 , " Find " , & FindLen ) ;
TmpPatch = GetDataSetting ( Prop2 , " Replace " , & ReplaceLen ) ;
2020-04-24 11:01:28 +02:00
if ( ! FindLen | | ! ReplaceLen ) {
2020-04-23 18:05:21 +02:00
DBG ( " - invalid Find/Replace data - skipping! \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-27 17:16:43 +02:00
Dict = GetProperty ( Prop2 , " Procedure " ) ;
if ( Dict ! = NULL ) {
INTN len = strlen ( Dict - > string ) ;
Patches - > KextPatches [ Patches - > NrKexts ] . ProcedureName = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . ProcedureName ) ) AllocateCopyPool ( len , Dict - > string ) ;
}
2019-09-03 11:58:42 +02:00
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . Data = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . Data ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . DataLen = FindLen ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpData ) ;
2020-04-25 18:18:18 +02:00
2019-10-08 22:57:18 +02:00
TmpData = GetDataSetting ( Prop2 , " MaskFind " , & MaskLen ) ;
MaskLen = ( MaskLen > FindLen ) ? FindLen : MaskLen ;
if ( TmpData = = NULL | | MaskLen = = 0 ) {
Patches - > KextPatches [ Patches - > NrKexts ] . MaskFind = NULL ;
} else {
2019-12-21 01:31:49 +01:00
Patches - > KextPatches [ Patches - > NrKexts ] . MaskFind = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . MaskFind ) ) AllocatePool ( FindLen ) ;
2019-10-16 14:38:41 +02:00
SetMem ( Patches - > KextPatches [ Patches - > NrKexts ] . MaskFind , FindLen , 0xFF ) ;
2019-10-08 22:57:18 +02:00
CopyMem ( Patches - > KextPatches [ Patches - > NrKexts ] . MaskFind , TmpData , MaskLen ) ;
}
FreePool ( TmpData ) ;
2020-04-24 11:01:28 +02:00
// take into account a possibility to set ReplaceLen < FindLen. In this case assumes MaskReplace = 0 for the rest of bytes
2020-04-28 12:49:24 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . Patch = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . Patch ) ) AllocateZeroPool ( FindLen ) ;
2020-04-24 11:01:28 +02:00
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
CopyMem ( Patches - > KextPatches [ Patches - > NrKexts ] . Patch , TmpPatch , ReplaceLen ) ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpPatch ) ;
MaskLen = 0 ;
TmpData = GetDataSetting ( Prop2 , " MaskReplace " , & MaskLen ) ;
2020-04-24 11:01:28 +02:00
MaskLen = MIN ( ReplaceLen , MaskLen ) ;
2019-10-08 22:57:18 +02:00
if ( TmpData = = NULL | | MaskLen = = 0 ) {
Patches - > KextPatches [ Patches - > NrKexts ] . MaskReplace = NULL ;
} else {
2020-04-28 12:49:24 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MaskReplace = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . MaskReplace ) ) AllocateZeroPool ( FindLen ) ;
2020-04-24 11:01:28 +02:00
CopyMem ( Patches - > KextPatches [ Patches - > NrKexts ] . MaskReplace , TmpData , MaskLen ) ; //other bytes are zeros, means no replace
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MatchOS = NULL ;
Patches - > KextPatches [ Patches - > NrKexts ] . MatchBuild = NULL ;
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . Name = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . Name ) ) AllocateCopyPool ( AsciiStrSize ( KextPatchesName ) , KextPatchesName ) ;
2019-09-03 11:58:42 +02:00
FreePool ( KextPatchesName ) ;
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . Label = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . Label ) ) AllocateCopyPool ( AsciiStrSize ( KextPatchesLabel ) , KextPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
FreePool ( KextPatchesLabel ) ;
// check enable/disabled patch (OS based) by Micky1979
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchOS " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MatchOS = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . MatchOS ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchOS: %s " , Patches - > KextPatches [ Patches - > NrKexts ] . MatchOS ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchBuild " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . MatchBuild = ( __typeof__ ( Patches - > KextPatches [ Patches - > NrKexts ] . MatchBuild ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchBuild: %s " , Patches - > KextPatches [ Patches - > NrKexts ] . MatchBuild ) ;
2019-09-03 11:58:42 +02:00
}
// check if this is Info.plist patch or kext binary patch
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " InfoPlistPatch " ) ;
2020-05-11 08:30:45 +02:00
Patches - > KextPatches [ Patches - > NrKexts ] . IsPlistPatch = IsPropertyTrue ( Dict ) ;
2019-09-03 11:58:42 +02:00
if ( Patches - > KextPatches [ Patches - > NrKexts ] . IsPlistPatch ) {
2020-04-23 18:05:21 +02:00
DBG ( " :: PlistPatch " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " :: BinPatch " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " :: data len: %lld \n " , Patches - > KextPatches [ Patches - > NrKexts ] . DataLen ) ;
2019-09-03 11:58:42 +02:00
if ( ! Patches - > KextPatches [ Patches - > NrKexts + + ] . MenuItem . BValue ) {
DBG ( " - patch disabled at config \n " ) ;
}
}
}
//gSettings.NrKexts = (INT32)i;
//there is one moment. This data is allocated in BS memory but will be used
// after OnExitBootServices. This is wrong and these arrays should be reallocated
// but I am not sure
}
2019-10-16 13:25:52 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KernelToPatch " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
//delete old and create new
if ( Patches - > KernelPatches ) {
2019-10-16 13:25:52 +02:00
// free all subarrays
for ( i = 0 ; i < Patches - > NrKernels ; i + + ) {
if ( Patches - > KernelPatches [ i ] . Label ) {
FreePool ( Patches - > KernelPatches [ i ] . Label ) ;
}
if ( Patches - > KernelPatches [ i ] . Data ) {
FreePool ( Patches - > KernelPatches [ i ] . Data ) ;
}
if ( Patches - > KernelPatches [ i ] . Patch ) {
FreePool ( Patches - > KernelPatches [ i ] . Patch ) ;
}
if ( Patches - > KernelPatches [ i ] . MaskFind ) {
FreePool ( Patches - > KernelPatches [ i ] . MaskFind ) ;
}
if ( Patches - > KernelPatches [ i ] . MaskReplace ) {
FreePool ( Patches - > KernelPatches [ i ] . MaskReplace ) ;
}
if ( Patches - > KernelPatches [ i ] . MatchOS ) {
FreePool ( Patches - > KernelPatches [ i ] . MatchOS ) ;
}
if ( Patches - > KernelPatches [ i ] . MatchBuild ) {
FreePool ( Patches - > KernelPatches [ i ] . MatchBuild ) ;
}
}
2019-09-03 11:58:42 +02:00
Patches - > NrKernels = 0 ;
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > KernelPatches ) ;
2019-10-16 13:25:52 +02:00
Patches - > KernelPatches = NULL ;
2019-09-03 11:58:42 +02:00
}
if ( Count > 0 ) {
TagPtr Prop2 = NULL , Dict = NULL ;
2020-04-28 12:49:24 +02:00
KERNEL_PATCH * newPatches = ( __typeof__ ( newPatches ) ) AllocateZeroPool ( Count * sizeof ( KERNEL_PATCH ) ) ;
2019-09-03 11:58:42 +02:00
Patches - > KernelPatches = newPatches ;
2020-04-24 11:01:28 +02:00
DBG ( " KernelToPatch: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
CHAR8 * KernelPatchesLabel ;
2019-10-08 22:57:18 +02:00
UINTN FindLen = 0 , ReplaceLen = 0 , MaskLen = 0 ;
2019-09-03 11:58:42 +02:00
UINT8 * TmpData , * TmpPatch ;
2020-05-11 08:30:45 +02:00
EFI_STATUS Status = GetElement ( Prop , i , & Prop2 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: Patches error %s getting next element \n " , i , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-27 17:16:43 +02:00
KernelPatchesLabel = ( __typeof__ ( KernelPatchesLabel ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-27 17:16:43 +02:00
KernelPatchesLabel = ( __typeof__ ( KernelPatchesLabel ) ) AllocateCopyPool ( 8 , " NoLabel " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " %s " , KernelPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MenuItem . BValue = ! IsPropertyTrue ( Dict ) ;
2020-04-25 18:18:18 +02:00
Dict = GetProperty ( Prop2 , " RangeFind " ) ;
Patches - > KernelPatches [ Patches - > NrKernels ] . SearchLen = GetPropertyInteger ( Dict , 0 ) ; //default 0 will be calculated later
TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
if ( TmpData ! = NULL ) {
Patches - > KernelPatches [ Patches - > NrKernels ] . StartPatternLen = FindLen ;
2020-04-27 17:16:43 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . StartPattern = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . StartPattern ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2020-04-25 18:18:18 +02:00
FreePool ( TmpData ) ;
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-04-28 12:49:24 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . StartMask = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . StartMask ) ) AllocateZeroPool ( FindLen ) ;
2020-04-25 18:18:18 +02:00
SetMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . StartMask , FindLen , 0xFF ) ;
if ( TmpData ! = NULL ) {
CopyMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . StartMask , TmpData , ReplaceLen ) ;
}
}
if ( TmpData ! = NULL ) {
FreePool ( TmpData ) ;
}
2019-09-03 11:58:42 +02:00
TmpData = GetDataSetting ( Prop2 , " Find " , & FindLen ) ;
TmpPatch = GetDataSetting ( Prop2 , " Replace " , & ReplaceLen ) ;
2020-03-16 05:27:02 +01:00
//replace len can be smaller if mask using
if ( ! FindLen | | ! ReplaceLen /*|| (FindLen != ReplaceLen)*/ ) {
2020-04-23 18:05:21 +02:00
DBG ( " :: invalid Find/Replace data - skipping! \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-27 17:16:43 +02:00
Dict = GetProperty ( Prop2 , " Procedure " ) ;
if ( Dict ! = NULL ) {
INTN len = strlen ( Dict - > string ) ;
Patches - > KernelPatches [ Patches - > NrKernels ] . ProcedureName = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . ProcedureName ) ) AllocateCopyPool ( len , Dict - > string ) ;
}
2019-09-03 11:58:42 +02:00
2020-04-27 17:16:43 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . Data = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . Data ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . DataLen = FindLen ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpData ) ;
TmpData = GetDataSetting ( Prop2 , " MaskFind " , & MaskLen ) ;
MaskLen = ( MaskLen > FindLen ) ? FindLen : MaskLen ;
if ( TmpData = = NULL | | MaskLen = = 0 ) {
2020-03-19 21:40:27 +01:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MaskFind = NULL ;
2019-10-08 22:57:18 +02:00
} else {
2020-03-19 21:40:27 +01:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MaskFind = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . MaskFind ) ) AllocatePool ( FindLen ) ;
SetMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . MaskFind , FindLen , 0xFF ) ;
CopyMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . MaskFind , TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-03-16 05:27:02 +01:00
// this is "Replace" string len of ReplaceLen
2020-04-24 11:01:28 +02:00
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
2020-03-16 05:27:02 +01:00
Patches - > KernelPatches [ Patches - > NrKernels ] . Patch = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . Patch ) ) AllocateZeroPool ( FindLen ) ;
2020-03-19 21:40:27 +01:00
CopyMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . Patch , TmpPatch , ReplaceLen ) ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpPatch ) ;
2020-04-24 11:01:28 +02:00
MaskLen = 0 ;
2020-03-16 05:27:02 +01:00
TmpData = GetDataSetting ( Prop2 , " MaskReplace " , & MaskLen ) ; //reuse MaskLen
2020-04-24 11:01:28 +02:00
MaskLen = MIN ( ReplaceLen , MaskLen ) ;
2019-10-08 22:57:18 +02:00
if ( TmpData = = NULL | | MaskLen = = 0 ) {
2020-03-19 21:40:27 +01:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MaskReplace = NULL ;
2019-10-08 22:57:18 +02:00
} else {
2020-04-28 12:49:24 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MaskReplace = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . MaskReplace ) ) AllocateZeroPool ( FindLen ) ;
2020-03-19 21:40:27 +01:00
CopyMem ( Patches - > KernelPatches [ Patches - > NrKernels ] . MaskReplace , TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . Count = 0 ;
Patches - > KernelPatches [ Patches - > NrKernels ] . MatchOS = NULL ;
Patches - > KernelPatches [ Patches - > NrKernels ] . MatchBuild = NULL ;
2020-04-27 17:16:43 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . Label = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . Label ) ) AllocateCopyPool ( AsciiStrSize ( KernelPatchesLabel ) , KernelPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Count " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . Count = GetPropertyInteger ( Dict , 0 ) ;
2019-09-03 11:58:42 +02:00
}
FreePool ( KernelPatchesLabel ) ;
// check enable/disabled patch (OS based) by Micky1979
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchOS " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MatchOS = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . MatchOS ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchOS: %s " , Patches - > KernelPatches [ Patches - > NrKernels ] . MatchOS ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchBuild " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > KernelPatches [ Patches - > NrKernels ] . MatchBuild = ( __typeof__ ( Patches - > KernelPatches [ Patches - > NrKernels ] . MatchBuild ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchBuild: %s " , Patches - > KernelPatches [ Patches - > NrKernels ] . MatchBuild ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " :: data len: %lld \n " , Patches - > KernelPatches [ Patches - > NrKernels ] . DataLen ) ;
2019-09-03 11:58:42 +02:00
Patches - > NrKernels + + ;
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BootPatches " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
//delete old and create new
if ( Patches - > BootPatches ) {
2019-10-16 13:25:52 +02:00
// free all subtree
for ( i = 0 ; i < Patches - > NrBoots ; i + + ) {
if ( Patches - > BootPatches [ i ] . Label ) {
FreePool ( Patches - > BootPatches [ i ] . Label ) ;
}
if ( Patches - > BootPatches [ i ] . Data ) {
FreePool ( Patches - > BootPatches [ i ] . Data ) ;
}
if ( Patches - > BootPatches [ i ] . Patch ) {
FreePool ( Patches - > BootPatches [ i ] . Patch ) ;
}
if ( Patches - > BootPatches [ i ] . MaskFind ) {
FreePool ( Patches - > BootPatches [ i ] . MaskFind ) ;
}
if ( Patches - > BootPatches [ i ] . MaskReplace ) {
FreePool ( Patches - > BootPatches [ i ] . MaskReplace ) ;
}
if ( Patches - > BootPatches [ i ] . MatchOS ) {
FreePool ( Patches - > BootPatches [ i ] . MatchOS ) ;
}
if ( Patches - > BootPatches [ i ] . MatchBuild ) {
FreePool ( Patches - > BootPatches [ i ] . MatchBuild ) ;
}
}
2019-09-03 11:58:42 +02:00
Patches - > NrBoots = 0 ;
2020-04-23 11:08:10 +02:00
FreePool ( Patches - > BootPatches ) ;
2019-09-03 11:58:42 +02:00
}
if ( Count > 0 ) {
TagPtr Prop2 = NULL , Dict = NULL ;
2020-04-28 12:49:24 +02:00
KERNEL_PATCH * newPatches = ( __typeof__ ( newPatches ) ) AllocateZeroPool ( Count * sizeof ( KERNEL_PATCH ) ) ;
2019-09-03 11:58:42 +02:00
Patches - > BootPatches = newPatches ;
2020-04-24 11:01:28 +02:00
DBG ( " BootPatches: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
CHAR8 * BootPatchesLabel ;
2019-10-08 22:57:18 +02:00
UINTN FindLen = 0 , ReplaceLen = 0 , MaskLen = 0 ;
2019-09-03 11:58:42 +02:00
UINT8 * TmpData , * TmpPatch ;
2020-05-11 08:30:45 +02:00
EFI_STATUS Status = GetElement ( Prop , i , & Prop2 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: error %s getting next element \n " , i , strerror ( Status ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-27 17:16:43 +02:00
BootPatchesLabel = ( __typeof__ ( BootPatchesLabel ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-27 17:16:43 +02:00
BootPatchesLabel = ( __typeof__ ( BootPatchesLabel ) ) AllocateCopyPool ( 8 , " NoLabel " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " %s " , BootPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MenuItem . BValue = ! IsPropertyTrue ( Dict ) ;
2019-09-03 11:58:42 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MenuItem . ItemType = BoolValue ;
2020-04-25 18:18:18 +02:00
Dict = GetProperty ( Prop2 , " RangeFind " ) ;
Patches - > BootPatches [ Patches - > NrBoots ] . SearchLen = GetPropertyInteger ( Dict , 0 ) ; //default 0 will be calculated later
TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
if ( TmpData ! = NULL ) {
Patches - > BootPatches [ Patches - > NrBoots ] . StartPatternLen = FindLen ;
2020-04-27 17:16:43 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . StartPattern = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . StartPattern ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2020-04-25 18:18:18 +02:00
FreePool ( TmpData ) ;
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-04-28 12:49:24 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . StartMask = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . StartMask ) ) AllocateZeroPool ( FindLen ) ;
2020-04-25 18:18:18 +02:00
SetMem ( Patches - > BootPatches [ Patches - > NrBoots ] . StartMask , FindLen , 0xFF ) ;
if ( TmpData ! = NULL ) {
CopyMem ( Patches - > BootPatches [ Patches - > NrBoots ] . StartMask , TmpData , ReplaceLen ) ;
}
}
if ( TmpData ! = NULL ) {
FreePool ( TmpData ) ;
}
2019-09-03 11:58:42 +02:00
TmpData = GetDataSetting ( Prop2 , " Find " , & FindLen ) ;
TmpPatch = GetDataSetting ( Prop2 , " Replace " , & ReplaceLen ) ;
2020-04-24 11:01:28 +02:00
if ( ! FindLen | | ! ReplaceLen ) {
2020-04-23 18:05:21 +02:00
DBG ( " :: invalid Find/Replace data - skipping! \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-24 11:01:28 +02:00
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
2020-04-27 17:16:43 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . Data = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . Data ) ) AllocateCopyPool ( FindLen , TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . DataLen = FindLen ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpData ) ;
2020-04-24 11:01:28 +02:00
MaskLen = 0 ;
2019-10-08 22:57:18 +02:00
TmpData = GetDataSetting ( Prop2 , " MaskFind " , & MaskLen ) ;
2020-04-24 11:01:28 +02:00
MaskLen = MIN ( FindLen , MaskLen ) ;
2019-10-08 22:57:18 +02:00
if ( TmpData = = NULL | | MaskLen = = 0 ) {
2020-03-19 21:40:27 +01:00
Patches - > BootPatches [ Patches - > NrBoots ] . MaskFind = NULL ;
2019-10-08 22:57:18 +02:00
} else {
2020-03-19 21:40:27 +01:00
Patches - > BootPatches [ Patches - > NrBoots ] . MaskFind = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . MaskFind ) ) AllocatePool ( FindLen ) ;
SetMem ( Patches - > BootPatches [ Patches - > NrBoots ] . MaskFind , FindLen , 0xFF ) ;
CopyMem ( Patches - > BootPatches [ Patches - > NrBoots ] . MaskFind , TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-04-28 12:49:24 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . Patch = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . Patch ) ) AllocateZeroPool ( FindLen ) ;
2020-04-24 11:01:28 +02:00
CopyMem ( Patches - > BootPatches [ Patches - > NrBoots ] . Patch , TmpPatch , ReplaceLen ) ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpPatch ) ;
2020-04-24 11:01:28 +02:00
MaskLen = 0 ;
2019-10-08 22:57:18 +02:00
TmpData = GetDataSetting ( Prop2 , " MaskReplace " , & MaskLen ) ;
2020-04-24 11:01:28 +02:00
MaskLen = MIN ( ReplaceLen , MaskLen ) ;
2019-10-08 22:57:18 +02:00
if ( TmpData = = NULL | | MaskLen = = 0 ) {
2020-04-24 11:01:28 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MaskReplace = NULL ; //this is old behavior
2019-10-08 22:57:18 +02:00
} else {
2020-04-28 12:49:24 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MaskReplace = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . MaskReplace ) ) AllocateZeroPool ( FindLen ) ;
2020-03-19 21:40:27 +01:00
CopyMem ( Patches - > BootPatches [ Patches - > NrBoots ] . MaskReplace , TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2019-09-03 11:58:42 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . Count = 0 ;
Patches - > BootPatches [ Patches - > NrBoots ] . MatchOS = NULL ;
Patches - > BootPatches [ Patches - > NrBoots ] . MatchBuild = NULL ;
2020-04-27 17:16:43 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . Label = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . Label ) ) AllocateCopyPool ( AsciiStrSize ( BootPatchesLabel ) , BootPatchesLabel ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " Count " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . Count = GetPropertyInteger ( Dict , 0 ) ;
2019-09-03 11:58:42 +02:00
}
FreePool ( BootPatchesLabel ) ;
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchOS " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MatchOS = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . MatchOS ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchOS: %s " , Patches - > BootPatches [ Patches - > NrBoots ] . MatchOS ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( Prop2 , " MatchBuild " ) ;
2019-09-03 11:58:42 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > type = = kTagTypeString ) ) {
2020-04-27 17:16:43 +02:00
Patches - > BootPatches [ Patches - > NrBoots ] . MatchBuild = ( __typeof__ ( Patches - > BootPatches [ Patches - > NrBoots ] . MatchBuild ) ) AllocateCopyPool ( AsciiStrSize ( Dict - > string ) , Dict - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " :: MatchBuild: %s " , Patches - > BootPatches [ Patches - > NrBoots ] . MatchBuild ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " :: data len: %lld \n " , Patches - > BootPatches [ Patches - > NrBoots ] . DataLen ) ;
2019-09-03 11:58:42 +02:00
Patches - > NrBoots + + ;
}
}
}
return TRUE ;
}
BOOLEAN
IsPatchEnabled ( CHAR8 * MatchOSEntry , CHAR8 * CurrOS )
{
INTN i ;
BOOLEAN ret = FALSE ;
2019-12-21 01:31:49 +01:00
struct MatchOSes * mos ; // = (__typeof__(mos))AllocatePool(sizeof(struct MatchOSes));
2019-09-03 11:58:42 +02:00
if ( ! MatchOSEntry | | ! CurrOS ) {
return TRUE ; //undefined matched corresponds to old behavior
}
mos = GetStrArraySeparatedByChar ( MatchOSEntry , ' , ' ) ;
if ( ! mos ) {
return TRUE ; //memory fails -> anyway the patch enabled
}
TrimMatchOSArray ( mos ) ;
if ( AsciiStrStr ( mos - > array [ 0 ] , " All " ) ! = NULL ) {
return TRUE ;
}
for ( i = 0 ; i < mos - > count ; + + i ) {
// dot represent MatchOS
if (
( ( AsciiStrStr ( mos - > array [ i ] , " . " ) ! = NULL ) & & IsOSValid ( mos - > array [ i ] , CurrOS ) ) | | // MatchOS
( AsciiStrStr ( mos - > array [ i ] , CurrOS ) ! = NULL ) // MatchBuild
) {
2020-04-23 18:05:21 +02:00
//DBG("\nthis patch will activated for OS %ls!\n", mos->array[i]);
2019-09-03 11:58:42 +02:00
ret = TRUE ;
break ;
}
}
deallocMatchOSes ( mos ) ;
return ret ;
}
struct
MatchOSes * GetStrArraySeparatedByChar ( CHAR8 * str , CHAR8 sep )
{
struct MatchOSes * mo ;
INTN len = 0 , i = 0 , inc = 1 , newLen = 0 ;
// CHAR8 *comp = NULL; //unused
CHAR8 doubleSep [ 2 ] ;
2019-12-21 01:31:49 +01:00
mo = ( __typeof__ ( mo ) ) AllocatePool ( sizeof ( struct MatchOSes ) ) ;
2019-09-03 11:58:42 +02:00
if ( ! mo ) {
return NULL ;
}
mo - > count = countOccurrences ( str , sep ) + 1 ;
2020-03-25 19:32:44 +01:00
// DBG("found %d %c in %ls\n", mo->count, sep, str);
2019-09-03 11:58:42 +02:00
len = ( INTN ) AsciiStrLen ( str ) ;
doubleSep [ 0 ] = sep ; doubleSep [ 1 ] = sep ;
if ( AsciiStrStr ( str , doubleSep ) | | ! len | | str [ 0 ] = = sep | | str [ len - 1 ] = = sep ) {
mo - > count = 0 ;
mo - > array [ 0 ] = NULL ;
// DBG("emtpy string\n");
return mo ;
}
if ( mo - > count > 1 ) {
//INTN indexes[mo->count + 1];
INTN * indexes = ( INTN * ) AllocatePool ( mo - > count + 1 ) ;
for ( i = 0 ; i < len ; + + i ) {
CHAR8 c = str [ i ] ;
if ( c = = sep ) {
indexes [ inc ] = i ;
// DBG("index %d = %d\n", inc, i);
inc + + ;
}
}
// manually add first index
indexes [ 0 ] = 0 ;
// manually add last index
indexes [ mo - > count ] = len ;
for ( i = 0 ; i < mo - > count ; + + i ) {
INTN startLocation , endLocation ;
mo - > array [ i ] = 0 ;
if ( i = = 0 ) {
startLocation = indexes [ 0 ] ;
endLocation = indexes [ 1 ] - 1 ;
} else if ( i = = mo - > count - 1 ) { // never reach the end of the array
startLocation = indexes [ i ] + 1 ;
endLocation = len ;
} else {
startLocation = indexes [ i ] + 1 ;
endLocation = indexes [ i + 1 ] - 1 ;
}
// DBG("start %d, end %d\n", startLocation, endLocation);
newLen = ( endLocation - startLocation ) + 2 ;
/* comp = (CHAR8 *) AllocatePool(newLen);
AsciiStrnCpy ( comp , str + startLocation , newLen ) ;
comp [ newLen ] = ' \0 ' ; */
2020-02-21 22:22:30 +01:00
mo - > array [ i ] = ( __typeof_am__ ( mo - > array [ i ] ) ) AllocateCopyPool ( newLen , str + startLocation ) ;
2019-09-03 11:58:42 +02:00
mo - > array [ i ] [ newLen - 1 ] = ' \0 ' ;
}
FreePool ( indexes ) ;
}
else {
2020-03-25 19:32:44 +01:00
// DBG("str contains only one component and it is our string %ls!\n", str);
2020-02-21 22:22:30 +01:00
mo - > array [ 0 ] = ( __typeof_am__ ( mo - > array [ 0 ] ) ) AllocateCopyPool ( AsciiStrLen ( str ) + 1 , str ) ;
2019-09-03 11:58:42 +02:00
}
return mo ;
}
CHAR8 *
TrimString ( CHAR8 * String )
{
CHAR8 * TempString , * End , * TrimmedString ;
if ( ! String ) {
return NULL ;
}
TempString = String ;
for ( ; * TempString = = ' ' ; TempString + + ) {
}
End = TempString + AsciiStrLen ( TempString ) - 1 ;
for ( ; ( End > TempString ) & & ( * End = = ' ' ) ; End - - ) {
}
* ( End + 1 ) = ' \0 ' ;
2019-12-21 01:31:49 +01:00
TrimmedString = ( __typeof__ ( TrimmedString ) ) AllocateCopyPool ( AsciiStrSize ( TempString ) , TempString ) ;
2019-09-03 11:58:42 +02:00
FreePool ( String ) ;
return TrimmedString ;
}
VOID
TrimMatchOSArray ( struct MatchOSes * s )
{
INTN i ;
if ( ! s ) {
return ;
}
for ( i = 0 ; i < s - > count ; i + + ) {
s - > array [ i ] = TrimString ( s - > array [ i ] ) ;
}
}
BOOLEAN IsOSValid ( CHAR8 * MatchOS , CHAR8 * CurrOS )
{
/* example for valid matches are:
10.7 , only 10.7 ( 10.7 .1 will be skipped )
10.10 .2 only 10.10 .2 ( 10.10 .1 or 10.10 .5 will be skipped )
10.10 . x ( or 10.10 . X ) , in this case is valid for all minor version of 10.10 ( 10.10 . ( 0 - 9 ) )
*/
BOOLEAN ret = FALSE ;
struct MatchOSes * osToc ;
struct MatchOSes * currOStoc ;
if ( ! MatchOS | | ! CurrOS ) {
return TRUE ; //undefined matched corresponds to old behavior
}
osToc = GetStrArraySeparatedByChar ( MatchOS , ' . ' ) ;
currOStoc = GetStrArraySeparatedByChar ( CurrOS , ' . ' ) ;
if ( osToc - > count = = 2 ) {
if ( currOStoc - > count = = 2 ) {
if ( AsciiStrCmp ( osToc - > array [ 0 ] , currOStoc - > array [ 0 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 1 ] , currOStoc - > array [ 1 ] ) = = 0 ) {
ret = TRUE ;
}
}
} else if ( osToc - > count = = 3 ) {
if ( currOStoc - > count = = 3 ) {
if ( AsciiStrCmp ( osToc - > array [ 0 ] , currOStoc - > array [ 0 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 1 ] , currOStoc - > array [ 1 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 2 ] , currOStoc - > array [ 2 ] ) = = 0 ) {
ret = TRUE ;
} else if ( AsciiStrCmp ( osToc - > array [ 0 ] , currOStoc - > array [ 0 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 1 ] , currOStoc - > array [ 1 ] ) = = 0
& & ( AsciiStrCmp ( osToc - > array [ 2 ] , " x " ) = = 0 | | AsciiStrCmp ( osToc - > array [ 2 ] , " X " ) = = 0 ) ) {
ret = TRUE ;
}
} else if ( currOStoc - > count = = 2 ) {
if ( AsciiStrCmp ( osToc - > array [ 0 ] , currOStoc - > array [ 0 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 1 ] , currOStoc - > array [ 1 ] ) = = 0 ) {
ret = TRUE ;
} else if ( AsciiStrCmp ( osToc - > array [ 0 ] , currOStoc - > array [ 0 ] ) = = 0
& & AsciiStrCmp ( osToc - > array [ 1 ] , currOStoc - > array [ 1 ] ) = = 0
& & ( AsciiStrCmp ( osToc - > array [ 2 ] , " x " ) = = 0 | | AsciiStrCmp ( osToc - > array [ 2 ] , " X " ) = = 0 ) ) {
ret = TRUE ;
}
}
}
deallocMatchOSes ( osToc ) ;
deallocMatchOSes ( currOStoc ) ;
return ret ;
}
INTN countOccurrences ( CHAR8 * s , CHAR8 c )
{
return * s = = ' \0 '
? 0
: countOccurrences ( s + 1 , c ) + ( * s = = c ) ;
}
VOID deallocMatchOSes ( struct MatchOSes * s )
{
INTN i ;
if ( ! s ) {
return ;
}
for ( i = 0 ; i < s - > count ; i + + ) {
if ( s - > array [ i ] ) {
FreePool ( s - > array [ i ] ) ;
}
}
FreePool ( s ) ;
}
// End of MatchOS
UINT8 CheckVolumeType ( UINT8 VolumeType , TagPtr Prop )
{
UINT8 VolumeTypeTmp = VolumeType ;
if ( AsciiStriCmp ( Prop - > string , " Internal " ) = = 0 ) {
VolumeTypeTmp | = VOLTYPE_INTERNAL ;
} else if ( AsciiStriCmp ( Prop - > string , " External " ) = = 0 ) {
VolumeTypeTmp | = VOLTYPE_EXTERNAL ;
} else if ( AsciiStriCmp ( Prop - > string , " Optical " ) = = 0 ) {
VolumeTypeTmp | = VOLTYPE_OPTICAL ;
} else if ( AsciiStriCmp ( Prop - > string , " FireWire " ) = = 0 ) {
VolumeTypeTmp | = VOLTYPE_FIREWIRE ;
}
return VolumeTypeTmp ;
}
UINT8 GetVolumeType ( TagPtr DictPointer )
{
TagPtr Prop , Prop2 ;
UINT8 VolumeType = 0 ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " VolumeType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeString ) {
VolumeType = CheckVolumeType ( 0 , Prop ) ;
} else if ( Prop - > type = = kTagTypeArray ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
Prop2 = NULL ;
for ( i = 0 ; i < Count ; i + + ) {
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Prop2 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
if ( ( Prop2 - > type ! = kTagTypeString ) | | ( Prop2 - > string = = NULL ) ) {
continue ;
}
VolumeType = CheckVolumeType ( VolumeType , Prop2 ) ;
}
}
}
}
return VolumeType ;
}
STATIC
BOOLEAN
FillinCustomEntry (
IN OUT CUSTOM_LOADER_ENTRY * Entry ,
TagPtr DictPointer ,
IN BOOLEAN SubEntry
)
{
TagPtr Prop ;
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Volume " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
if ( Entry - > Volume ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > Volume ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Entry - > Volume = PoolPrint ( L " %a " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Path " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-27 11:50:49 +02:00
Entry - > Path . SWPrintf ( " %s " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Settings " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
if ( Entry - > Settings ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > Settings ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Entry - > Settings = PoolPrint ( L " %a " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CommonSettings " ) ;
2020-05-11 08:30:45 +02:00
Entry - > CommonSettings = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AddArguments " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-26 15:07:30 +02:00
// if (Entry->LoadOptions.notEmpty()) {
// Entry->Options.SPrintf("%s %s", Entry->Options.c_str(), Prop->string);
// } else {
// Entry->Options.SPrintf("%s", Prop->string);
// }
2020-04-30 20:17:54 +02:00
Entry - > LoadOptions . import ( Split < XStringArray > ( Prop - > string , " " ) ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Arguments " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-26 15:07:30 +02:00
// Entry->Options.SPrintf("%s", Prop->string);
2020-04-30 20:17:54 +02:00
Entry - > LoadOptions = Split < XStringArray > ( Prop - > string , " " ) ;
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTARGS ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Title " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > Title . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FullTitle " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > FullTitle . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( Entry - > ImagePath ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > ImagePath ) ;
2020-04-03 22:00:42 +02:00
Entry - > ImagePath = NULL ;
}
2020-04-13 17:43:32 +02:00
Entry - > Image . setEmpty ( ) ;
2020-04-13 00:28:01 +02:00
if ( Prop - > type = = kTagTypeString ) {
2020-04-23 11:08:10 +02:00
Entry - > ImagePath = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-13 00:28:01 +02:00
}
// we can't load the file yet, as ThemeDir is not initialized
2020-04-03 22:00:42 +02:00
} else {
UINTN DataLen = 0 ;
UINT8 * TmpData = GetDataSetting ( DictPointer , " ImageData " , & DataLen ) ;
if ( TmpData ) {
2020-05-16 21:30:29 +02:00
if ( ! EFI_ERROR ( Entry - > Image . Image . FromPNG ( TmpData , DataLen ) ) ) {
Entry - > Image . setFilled ( ) ;
}
2020-04-03 22:00:42 +02:00
FreePool ( TmpData ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DriveImage " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( Entry - > DriveImagePath ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > DriveImagePath ) ;
2020-04-03 22:00:42 +02:00
Entry - > DriveImagePath = NULL ;
}
2020-04-13 17:43:32 +02:00
Entry - > DriveImage . setEmpty ( ) ;
2020-04-13 00:28:01 +02:00
if ( Prop - > type = = kTagTypeString ) {
2020-04-23 11:08:10 +02:00
Entry - > DriveImagePath = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-13 00:28:01 +02:00
}
// we can't load the file yet, as ThemeDir is not initialized
2020-04-03 22:00:42 +02:00
} else {
UINTN DataLen = 0 ;
UINT8 * TmpData = GetDataSetting ( DictPointer , " ImageData " , & DataLen ) ;
if ( TmpData ) {
2020-05-16 21:30:29 +02:00
if ( ! EFI_ERROR ( Entry - > DriveImage . Image . FromPNG ( TmpData , DataLen ) ) ) {
Entry - > DriveImage . setFilled ( ) ;
}
2020-04-03 22:00:42 +02:00
FreePool ( TmpData ) ;
}
}
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hotkey " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
Entry - > Hotkey = * ( Prop - > string ) ;
}
// Whether or not to draw boot screen
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CustomLogo " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_APPLE ;
} else if ( ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( AsciiStriCmp ( Prop - > string , " Apple " ) = = 0 ) {
Entry - > CustomBoot = CUSTOM_BOOT_APPLE ;
} else if ( AsciiStriCmp ( Prop - > string , " Alternate " ) = = 0 ) {
Entry - > CustomBoot = CUSTOM_BOOT_ALT_APPLE ;
} else if ( AsciiStriCmp ( Prop - > string , " Theme " ) = = 0 ) {
Entry - > CustomBoot = CUSTOM_BOOT_THEME ;
} else {
2020-04-14 22:33:36 +02:00
// CHAR16 *customLogo = PoolPrint(L"%a", Prop->string);
2020-04-11 14:34:59 +02:00
XStringW customLogo = XStringW ( ) . takeValueFrom ( Prop - > string ) ;
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_USER ;
2020-04-11 14:34:59 +02:00
Entry - > CustomLogo . LoadXImage ( SelfRootDir , customLogo ) ;
if ( Entry - > CustomLogo . isEmpty ( ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot logo not found at path `%ls`! \n " , customLogo . wc_str ( ) ) ;
2020-04-14 22:33:36 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
}
} else if ( ( Prop - > type = = kTagTypeData ) & &
( Prop - > data ! = NULL ) & & ( Prop - > dataLen > 0 ) ) {
Entry - > CustomBoot = CUSTOM_BOOT_USER ;
2020-04-11 14:34:59 +02:00
Entry - > CustomLogo . FromPNG ( Prop - > data , Prop - > dataLen ) ;
if ( Entry - > CustomLogo . isEmpty ( ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot logo not decoded from data! \n " /*, Prop->string*/ ) ;
2020-04-14 22:33:36 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
} else {
Entry - > CustomBoot = CUSTOM_BOOT_USER_DISABLED ;
}
2020-04-23 18:05:21 +02:00
DBG ( " Custom entry boot %s LogoWidth = (0x%lld) \n " , CustomBootModeToStr ( Entry - > CustomBoot ) , Entry - > CustomLogo . GetWidth ( ) ) ;
2020-04-14 22:33:36 +02:00
} else {
Entry - > CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( DictPointer , " BootBgColor " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > type = = kTagTypeString ) {
UINTN Color ;
2020-04-11 14:34:59 +02:00
Color = AsciiStrHexToUintn ( Prop - > string ) ;
2020-04-01 14:57:32 +02:00
Entry - > BootBgColor . Red = ( Color > > 24 ) & 0xFF ;
Entry - > BootBgColor . Green = ( Color > > 16 ) & 0xFF ;
Entry - > BootBgColor . Blue = ( Color > > 8 ) & 0xFF ;
Entry - > BootBgColor . Reserved = ( Color > > 0 ) & 0xFF ;
2019-09-03 11:58:42 +02:00
}
// Hidden Property, Values:
// - No (show the entry)
// - Yes (hide the entry but can be show with F3)
// - Always (always hide the entry)
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( DictPointer , " Hidden " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( ( Prop - > type = = kTagTypeString ) & &
2020-04-11 14:34:59 +02:00
( AsciiStriCmp ( Prop - > string , " Always " ) = = 0 ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
} else {
Entry - > Flags = OSFLAG_UNSET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-11 14:34:59 +02:00
if ( ( AsciiStriCmp ( Prop - > string , " OSX " ) = = 0 ) | |
( AsciiStriCmp ( Prop - > string , " macOS " ) = = 0 ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_OSX ;
2020-04-11 14:34:59 +02:00
} else if ( AsciiStriCmp ( Prop - > string , " OSXInstaller " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_OSX_INSTALLER ;
2020-04-11 14:34:59 +02:00
} else if ( AsciiStriCmp ( Prop - > string , " OSXRecovery " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_RECOVERY ;
2020-04-11 14:34:59 +02:00
} else if ( AsciiStriCmp ( Prop - > string , " Windows " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_WINEFI ;
2020-04-11 14:34:59 +02:00
} else if ( AsciiStriCmp ( Prop - > string , " Linux " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_LIN ;
2020-04-30 20:17:54 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTARGS ) ;
2020-04-11 14:34:59 +02:00
} else if ( AsciiStriCmp ( Prop - > string , " LinuxKernel " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_LINEFI ;
} else {
2020-04-23 18:05:21 +02:00
DBG ( " ** Warning: unknown custom entry Type '%s' \n " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_OTHER ;
}
} else {
2020-04-27 11:50:49 +02:00
if ( Entry - > Type = = 0 & & Entry - > Path . notEmpty ( ) ) {
2019-09-03 11:58:42 +02:00
// Try to set Entry->type from Entry->Path
2020-04-11 14:34:59 +02:00
Entry - > Type = GetOSTypeFromPath ( Entry - > Path ) ;
2019-09-03 11:58:42 +02:00
}
}
Entry - > VolumeType = GetVolumeType ( DictPointer ) ;
2020-04-26 15:07:30 +02:00
if ( Entry - > LoadOptions . isEmpty ( ) & & OSTYPE_IS_WINDOWS ( Entry - > Type ) ) {
Entry - > LoadOptions . Add ( " -s " ) ;
Entry - > LoadOptions . Add ( " -h " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-03 22:00:42 +02:00
if ( Entry - > Title . isEmpty ( ) ) {
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Title = L " Recovery " _XSW ;
2020-04-11 14:34:59 +02:00
} else if ( OSTYPE_IS_OSX_INSTALLER ( Entry - > Type ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Title = L " Install macOS " _XSW ;
}
}
if ( Entry - > Image . isEmpty ( ) & & ( Entry - > ImagePath = = NULL ) ) {
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) ) {
2020-04-03 22:00:42 +02:00
Entry - > ImagePath = L " mac " ;
}
}
if ( Entry - > DriveImage . isEmpty ( ) & & ( Entry - > DriveImagePath = = NULL ) ) {
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) ) {
2020-04-03 22:00:42 +02:00
Entry - > DriveImagePath = L " recovery " ;
}
}
2019-09-03 11:58:42 +02:00
// OS Specific flags
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX ( Entry - > Type ) | | OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) | | OSTYPE_IS_OSX_INSTALLER ( Entry - > Type ) ) {
2019-09-03 11:58:42 +02:00
// InjectKexts default values
Entry - > Flags = OSFLAG_UNSET ( Entry - > Flags , OSFLAG_CHECKFAKESMC ) ;
// Entry->Flags = OSFLAG_UNSET(Entry->Flags, OSFLAG_WITHKEXTS);
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " InjectKexts " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeTrue ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
} else if ( ( Prop - > type = = kTagTypeString ) & &
2020-04-11 14:34:59 +02:00
( AsciiStriCmp ( Prop - > string , " Yes " ) = = 0 ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
} else if ( ( Prop - > type = = kTagTypeString ) & &
2020-04-11 14:34:59 +02:00
( AsciiStriCmp ( Prop - > string , " Detect " ) = = 0 ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_CHECKFAKESMC ) ;
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
} else {
2020-04-23 18:05:21 +02:00
DBG ( " ** Warning: unknown custom entry InjectKexts value '%s' \n " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
} else {
// Use global settings
if ( gSettings . WithKexts ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
}
if ( gSettings . WithKextsIfNoFakeSMC ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_CHECKFAKESMC ) ;
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
}
}
// NoCaches default value
Entry - > Flags = OSFLAG_UNSET ( Entry - > Flags , OSFLAG_NOCACHES ) ;
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( DictPointer , " NoCaches " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-11 14:34:59 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NOCACHES ) ;
} else {
// Use global settings
if ( gSettings . NoCaches ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NOCACHES ) ;
}
}
}
// KernelAndKextPatches
if ( ! SubEntry ) { // CopyKernelAndKextPatches already in: DuplicateCustomEntry if SubEntry == TRUE
2020-04-23 18:05:21 +02:00
//DBG("Copying global patch settings\n");
2020-04-03 22:00:42 +02:00
// CopyKernelAndKextPatches ((KERNEL_AND_KEXT_PATCHES *)(((UINTN)Entry) + OFFSET_OF(CUSTOM_LOADER_ENTRY, KernelAndKextPatches)),
// (KERNEL_AND_KEXT_PATCHES *)(((UINTN)&gSettings) + OFFSET_OF(SETTINGS_DATA, KernelAndKextPatches)));
CopyKernelAndKextPatches ( & Entry - > KernelAndKextPatches , & gSettings . KernelAndKextPatches ) ;
2019-09-03 11:58:42 +02:00
//#ifdef DUMP_KERNEL_KEXT_PATCHES
// DumpKernelAndKextPatches ((KERNEL_AND_KEXT_PATCHES *)(((UINTN)Entry) + OFFSET_OF(CUSTOM_LOADER_ENTRY, KernelAndKextPatches)));
//#endif
}
}
if ( Entry - > Type = = OSTYPE_LINEFI ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Kernel " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( ( Prop - > string [ 0 ] = = ' N ' ) | | ( Prop - > string [ 0 ] = = ' n ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_NEWEST ;
} else if ( ( Prop - > string [ 0 ] = = ' O ' ) | | ( Prop - > string [ 0 ] = = ' o ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_OLDEST ;
} else if ( ( Prop - > string [ 0 ] = = ' F ' ) | | ( Prop - > string [ 0 ] = = ' f ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_FIRST ;
} else if ( ( Prop - > string [ 0 ] = = ' L ' ) | | ( Prop - > string [ 0 ] = = ' l ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_LAST ;
} else if ( ( Prop - > string [ 0 ] = = ' M ' ) | | ( Prop - > string [ 0 ] = = ' m ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_MOSTRECENT ;
} else if ( ( Prop - > string [ 0 ] = = ' E ' ) | | ( Prop - > string [ 0 ] = = ' e ' ) ) {
Entry - > KernelScan = KERNEL_SCAN_EARLIEST ;
}
}
}
}
// Sub entries
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SubEntries " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeFalse ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTMENU ) ;
} else if ( Prop - > type ! = kTagTypeTrue ) {
CUSTOM_LOADER_ENTRY * CustomSubEntry ;
INTN i , Count = GetTagCount ( Prop ) ;
TagPtr Dict = NULL ;
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTMENU ) ;
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict = = NULL ) {
break ;
}
// Allocate a sub entry
CustomSubEntry = DuplicateCustomEntry ( Entry ) ;
if ( CustomSubEntry ) {
if ( ! FillinCustomEntry ( CustomSubEntry , Dict , TRUE ) | | ! AddCustomSubEntry ( Entry , CustomSubEntry ) ) {
if ( CustomSubEntry ) {
2020-04-23 11:08:10 +02:00
FreePool ( CustomSubEntry ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
}
}
return TRUE ;
}
2020-04-10 12:04:21 +02:00
2020-04-03 22:00:42 +02:00
BOOLEAN
FillingCustomLegacy (
IN OUT CUSTOM_LEGACY_ENTRY * Entry ,
TagPtr DictPointer
)
{
TagPtr Prop ;
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Volume " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
if ( Entry - > Volume ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > Volume ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Entry - > Volume = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FullTitle " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > FullTitle . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Title " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > Title . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeString ) {
Entry - > Image . LoadXImage ( ThemeX . ThemeDir , Prop - > string ) ;
}
} else {
UINTN DataLen = 0 ;
UINT8 * TmpData = GetDataSetting ( DictPointer , " ImageData " , & DataLen ) ;
if ( TmpData ) {
2020-05-16 21:30:29 +02:00
if ( ! EFI_ERROR ( Entry - > Image . Image . FromPNG ( TmpData , DataLen ) ) ) {
Entry - > Image . setFilled ( ) ;
}
2020-04-03 22:00:42 +02:00
FreePool ( TmpData ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DriveImage " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeString ) {
Entry - > Image . LoadXImage ( ThemeX . ThemeDir , Prop - > string ) ;
}
} else {
UINTN DataLen = 0 ;
UINT8 * TmpData = GetDataSetting ( DictPointer , " DriveImageData " , & DataLen ) ;
if ( TmpData ) {
2020-05-16 21:30:29 +02:00
if ( ! EFI_ERROR ( Entry - > DriveImage . Image . FromPNG ( TmpData , DataLen ) ) ) {
Entry - > DriveImage . setFilled ( ) ;
}
2020-04-03 22:00:42 +02:00
FreePool ( TmpData ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hotkey " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
Entry - > Hotkey = * ( Prop - > string ) ;
}
// Hidden Property, Values:
// - No (show the entry)
// - Yes (hide the entry but can be show with F3)
// - Always (always hide the entry)
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hidden " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( ( Prop - > type = = kTagTypeString ) & &
( AsciiStriCmp ( Prop - > string , " Always " ) = = 0 ) ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
} else {
Entry - > Flags = OSFLAG_UNSET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Type " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
if ( AsciiStriCmp ( Prop - > string , " Windows " ) = = 0 ) {
Entry - > Type = OSTYPE_WIN ;
} else if ( AsciiStriCmp ( Prop - > string , " Linux " ) = = 0 ) {
Entry - > Type = OSTYPE_LIN ;
} else {
Entry - > Type = OSTYPE_OTHER ;
}
}
Entry - > VolumeType = GetVolumeType ( DictPointer ) ;
return TRUE ;
}
BOOLEAN
FillingCustomTool ( IN OUT CUSTOM_TOOL_ENTRY * Entry , TagPtr DictPointer )
{
TagPtr Prop ;
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
return FALSE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Volume " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
if ( Entry - > Volume ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > Volume ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Entry - > Volume = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Path " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-27 11:50:49 +02:00
Entry - > Path . SWPrintf ( " %s " , Prop - > string ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Arguments " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-05 14:25:39 +02:00
// if (!Entry->Options.isEmpty()) {
// Entry->Options.setEmpty();
// } else {
// Entry->Options.SPrintf("%s", Prop->string);
// }
2020-04-26 15:07:30 +02:00
Entry - > LoadOptions = Split < XStringArray > ( Prop - > string , " " ) ;
2020-04-03 22:00:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FullTitle " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > FullTitle . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Title " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
Entry - > Title . takeValueFrom ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( Entry - > ImagePath ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry - > ImagePath ) ;
2020-04-03 22:00:42 +02:00
Entry - > ImagePath = NULL ;
}
if ( Prop - > type = = kTagTypeString ) {
2020-04-23 11:08:10 +02:00
Entry - > ImagePath = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-03 22:00:42 +02:00
}
Entry - > Image . LoadXImage ( ThemeX . ThemeDir , Entry - > ImagePath ) ;
} else {
UINTN DataLen = 0 ;
UINT8 * TmpData = GetDataSetting ( DictPointer , " ImageData " , & DataLen ) ;
if ( TmpData ) {
2020-05-16 21:30:29 +02:00
if ( ! EFI_ERROR ( Entry - > Image . Image . FromPNG ( TmpData , DataLen ) ) ) {
Entry - > Image . setFilled ( ) ;
}
2020-04-03 22:00:42 +02:00
FreePool ( TmpData ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hotkey " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
Entry - > Hotkey = * ( Prop - > string ) ;
}
// Hidden Property, Values:
// - No (show the entry)
// - Yes (hide the entry but can be show with F3)
// - Always (always hide the entry)
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hidden " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
if ( ( Prop - > type = = kTagTypeString ) & &
( AsciiStriCmp ( Prop - > string , " Always " ) = = 0 ) ) {
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
} else {
Entry - > Flags = OSFLAG_UNSET ( Entry - > Flags , OSFLAG_HIDDEN ) ;
}
}
Entry - > VolumeType = GetVolumeType ( DictPointer ) ;
return TRUE ;
}
2019-09-03 11:58:42 +02:00
2020-04-10 12:04:21 +02:00
// EDID reworked by Sherlocks
VOID
GetEDIDSettings ( TagPtr DictPointer )
2019-09-03 11:58:42 +02:00
{
2020-04-10 12:04:21 +02:00
TagPtr Prop , Dict ;
UINTN j = 128 ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " EDID " ) ;
2020-04-10 12:04:21 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " Inject " ) ;
2020-04-10 12:04:21 +02:00
gSettings . InjectEDID = IsPropertyTrue ( Prop ) ; // default = false!
2019-09-03 11:58:42 +02:00
2020-04-10 12:04:21 +02:00
if ( gSettings . InjectEDID ) {
2020-04-23 18:05:21 +02:00
//DBG("Inject EDID\n");
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " Custom " ) ;
2020-04-10 12:04:21 +02:00
if ( Prop ! = NULL ) {
gSettings . CustomEDID = GetDataSetting ( Dict , " Custom " , & j ) ;
if ( ( j % 128 ) ! = 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom EDID has wrong length=%llu \n " , j ) ;
2020-04-10 12:04:21 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Custom EDID is ok \n " ) ;
2020-04-10 12:04:21 +02:00
gSettings . CustomEDIDsize = ( UINT16 ) j ;
InitializeEdidOverride ( ) ;
}
}
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " VendorID " ) ;
2020-04-10 12:04:21 +02:00
if ( Prop ) {
gSettings . VendorEDID = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . VendorEDID ) ;
//DBG(" VendorID = 0x%04lx\n", gSettings.VendorEDID);
}
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
gSettings . ProductEDID = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . ProductEDID ) ;
//DBG(" ProductID = 0x%04lx\n", gSettings.ProductEDID);
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " HorizontalSyncPulseWidth " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
gSettings . EdidFixHorizontalSyncPulseWidth = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . EdidFixHorizontalSyncPulseWidth ) ;
//DBG(" EdidFixHorizontalSyncPulseWidth = 0x%02lx\n", gSettings.EdidFixHorizontalSyncPulseWidth);
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " VideoInputSignal " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
gSettings . EdidFixVideoInputSignal = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . EdidFixVideoInputSignal ) ;
//DBG(" EdidFixVideoInputSignal = 0x%02lx\n", gSettings.EdidFixVideoInputSignal);
}
} else {
2020-04-23 18:05:21 +02:00
//DBG("Not Inject EDID\n");
2019-09-03 11:58:42 +02:00
}
}
}
EFI_STATUS
GetEarlyUserSettings (
IN EFI_FILE * RootDir ,
TagPtr CfgDict
)
{
EFI_STATUS Status = EFI_SUCCESS ;
TagPtr Dict ;
TagPtr Dict2 ;
TagPtr DictPointer ;
TagPtr Prop ;
VOID * Value = NULL ;
UINTN Size = 0 ;
BOOLEAN SpecialBootMode = FALSE ;
//read aptiofixflag from nvram for special boot
Status = GetVariable2 ( L " aptiofixflag " , & gEfiAppleBootGuid , & Value , & Size ) ;
if ( ! EFI_ERROR ( Status ) ) {
SpecialBootMode = TRUE ;
FreePool ( Value ) ;
}
gSettings . KextPatchesAllowed = TRUE ;
gSettings . KernelAndKextPatches . KPAppleRTC = TRUE ;
gSettings . KernelAndKextPatches . KPDELLSMBIOS = FALSE ; // default is false
gSettings . KernelPatchesAllowed = TRUE ;
Dict = CfgDict ;
if ( Dict ! = NULL ) {
2020-04-23 18:05:21 +02:00
//DBG("Loading early settings\n");
2019-09-03 11:58:42 +02:00
DbgHeader ( " GetEarlyUserSettings " ) ;
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " Boot " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Timeout " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
GlobalConfig . Timeout = ( INT32 ) GetPropertyInteger ( Prop , GlobalConfig . Timeout ) ;
2020-04-23 18:05:21 +02:00
DBG ( " timeout set to %lld \n " , GlobalConfig . Timeout ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SkipHibernateTimeout " ) ;
2019-09-03 11:58:42 +02:00
gSettings . SkipHibernateTimeout = IsPropertyTrue ( Prop ) ;
//DisableCloverHotkeys
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DisableCloverHotkeys " ) ;
2020-05-11 08:30:45 +02:00
gSettings . DisableCloverHotkeys = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Arguments " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ! = NULL ) {
AsciiStrnCpyS ( gSettings . BootArgs , 256 , Prop - > string , 255 ) ;
}
// defaults if "DefaultVolume" is not present or is empty
gSettings . LastBootedVolume = FALSE ;
// gSettings.DefaultVolume = NULL;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DefaultVolume " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
Size = AsciiStrSize ( Prop - > string ) ;
if ( Size > 0 ) {
if ( gSettings . DefaultVolume ! = NULL ) { //override value from Boot Option
FreePool ( gSettings . DefaultVolume ) ;
gSettings . DefaultVolume = NULL ;
}
// check for special value for remembering boot volume
if ( AsciiStriCmp ( Prop - > string , " LastBootedVolume " ) = = 0 ) {
gSettings . LastBootedVolume = TRUE ;
} else {
2020-04-28 12:49:24 +02:00
gSettings . DefaultVolume = ( __typeof__ ( gSettings . DefaultVolume ) ) AllocateZeroPool ( Size * sizeof ( CHAR16 ) ) ;
2019-09-03 11:58:42 +02:00
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . DefaultVolume , Size ) ;
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DefaultLoader " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-28 12:49:24 +02:00
gSettings . DefaultLoader = ( __typeof__ ( gSettings . DefaultLoader ) ) AllocateZeroPool ( AsciiStrSize ( Prop - > string ) * sizeof ( CHAR16 ) ) ;
2019-09-03 11:58:42 +02:00
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . DefaultLoader , AsciiStrSize ( Prop - > string ) ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Debug " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . DebugLog = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Fast " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . FastBoot = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NoEarlyProgress " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . NoEarlyProgress = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
if ( SpecialBootMode ) {
GlobalConfig . FastBoot = TRUE ;
2020-04-23 18:05:21 +02:00
DBG ( " Fast option enabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NeverHibernate " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . NeverHibernate = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " StrictHibernate " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . StrictHibernate = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " RtcHibernateAware " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . RtcHibernateAware = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " HibernationFixup " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-05-11 08:30:45 +02:00
GlobalConfig . HibernationFixup = IsPropertyTrue ( Prop ) ; //it will be set automatically
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SignatureFixup " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . SignatureFixup = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
// Prop = GetProperty(DictPointer, "GetLegacyLanAddress");
2020-05-11 08:30:45 +02:00
// GetLegacyLanAddress = IsPropertyTrue(Prop);
2019-09-03 11:58:42 +02:00
// Secure boot
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Secure " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeFalse ) {
// Only disable setup mode, we want always secure boot
gSettings . SecureBootSetupMode = 0 ;
} else if ( ( Prop - > type = = kTagTypeTrue ) & & ! gSettings . SecureBoot ) {
// This mode will force boot policy even when no secure boot or it is disabled
gSettings . SecureBootSetupMode = 1 ;
gSettings . SecureBoot = 1 ;
}
}
// Secure boot policy
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Policy " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( ( Prop - > string [ 0 ] = = ' D ' ) | | ( Prop - > string [ 0 ] = = ' d ' ) ) {
// Deny all images
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_DENY ;
} else if ( ( Prop - > string [ 0 ] = = ' A ' ) | | ( Prop - > string [ 0 ] = = ' a ' ) ) {
// Allow all images
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_ALLOW ;
} else if ( ( Prop - > string [ 0 ] = = ' Q ' ) | | ( Prop - > string [ 0 ] = = ' q ' ) ) {
// Query user
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_QUERY ;
} else if ( ( Prop - > string [ 0 ] = = ' I ' ) | | ( Prop - > string [ 0 ] = = ' i ' ) ) {
// Insert
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_INSERT ;
} else if ( ( Prop - > string [ 0 ] = = ' W ' ) | | ( Prop - > string [ 0 ] = = ' w ' ) ) {
// White list
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_WHITELIST ;
} else if ( ( Prop - > string [ 0 ] = = ' B ' ) | | ( Prop - > string [ 0 ] = = ' b ' ) ) {
// Black list
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_BLACKLIST ;
} else if ( ( Prop - > string [ 0 ] = = ' U ' ) | | ( Prop - > string [ 0 ] = = ' u ' ) ) {
// User policy
gSettings . SecureBootPolicy = SECURE_BOOT_POLICY_USER ;
}
}
// Secure boot white list
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " WhiteList " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeArray ) ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
gSettings . SecureBootWhiteListCount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . SecureBootWhiteList = ( __typeof__ ( gSettings . SecureBootWhiteList ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . SecureBootWhiteList ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict2 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict2 = = NULL ) {
break ;
}
if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
gSettings . SecureBootWhiteList [ gSettings . SecureBootWhiteListCount + + ] = PoolPrint ( L " %a " , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// Secure boot black list
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BlackList " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeArray ) ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
gSettings . SecureBootBlackListCount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . SecureBootBlackList = ( __typeof__ ( gSettings . SecureBootBlackList ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . SecureBootBlackList ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict2 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict2 = = NULL ) {
break ;
}
if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
gSettings . SecureBootBlackList [ gSettings . SecureBootBlackListCount + + ] = PoolPrint ( L " %a " , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// XMP memory profiles
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " XMPDetection " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
gSettings . XMPDetection = 0 ;
if ( Prop - > type = = kTagTypeFalse ) {
gSettings . XMPDetection = - 1 ;
} else if ( Prop - > type = = kTagTypeString ) {
if ( ( Prop - > string [ 0 ] = = ' n ' ) | |
( Prop - > string [ 0 ] = = ' N ' ) | |
( Prop - > string [ 0 ] = = ' - ' ) ) {
gSettings . XMPDetection = - 1 ;
} else {
gSettings . XMPDetection = ( INT8 ) AsciiStrDecimalToUintn ( Prop - > string ) ;
}
} else if ( Prop - > type = = kTagTypeInteger ) {
gSettings . XMPDetection = ( INT8 ) ( UINTN ) Prop - > string ;
}
// Check that the setting value is sane
if ( ( gSettings . XMPDetection < - 1 ) | | ( gSettings . XMPDetection > 2 ) ) {
gSettings . XMPDetection = - 1 ;
}
}
// Legacy bios protocol
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Legacy " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . LegacyBoot , 32 ) ;
} else if ( gFirmwareClover ) {
// default for CLOVER EFI boot
2020-04-04 15:50:13 +02:00
snwprintf ( gSettings . LegacyBoot , sizeof ( gSettings . LegacyBoot ) , " PBR " ) ;
2019-09-03 11:58:42 +02:00
} else {
// default for UEFI boot
2020-04-04 15:50:13 +02:00
snwprintf ( gSettings . LegacyBoot , sizeof ( gSettings . LegacyBoot ) , " LegacyBiosDefault " ) ;
2019-09-03 11:58:42 +02:00
}
// Entry for LegacyBiosDefault
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " LegacyBiosDefaultEntry " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . LegacyBiosDefaultEntry = ( UINT16 ) GetPropertyInteger ( Prop , 0 ) ; // disabled by default
2019-09-03 11:58:42 +02:00
}
// Whether or not to draw boot screen
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CustomLogo " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . CustomBoot = CUSTOM_BOOT_APPLE ;
} else if ( ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( AsciiStriCmp ( Prop - > string , " Apple " ) = = 0 ) {
gSettings . CustomBoot = CUSTOM_BOOT_APPLE ;
} else if ( AsciiStriCmp ( Prop - > string , " Alternate " ) = = 0 ) {
gSettings . CustomBoot = CUSTOM_BOOT_ALT_APPLE ;
} else if ( AsciiStriCmp ( Prop - > string , " Theme " ) = = 0 ) {
gSettings . CustomBoot = CUSTOM_BOOT_THEME ;
} else {
2020-04-23 11:08:10 +02:00
// CHAR16 *customLogo = PoolPrint(L"%a", Prop->string);
2020-04-14 22:33:36 +02:00
XStringW customLogo = XStringW ( ) . takeValueFrom ( Prop - > string ) ;
2019-09-03 11:58:42 +02:00
gSettings . CustomBoot = CUSTOM_BOOT_USER ;
if ( gSettings . CustomLogo ! = NULL ) {
2020-04-11 14:34:59 +02:00
delete gSettings . CustomLogo ;
2019-09-03 11:58:42 +02:00
}
2020-04-11 14:34:59 +02:00
gSettings . CustomLogo = new XImage ;
gSettings . CustomLogo - > LoadXImage ( RootDir , customLogo ) ;
2020-04-14 22:33:36 +02:00
if ( gSettings . CustomLogo - > isEmpty ( ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot logo not found at path `%ls`! \n " , customLogo . wc_str ( ) ) ;
2020-04-14 22:33:36 +02:00
gSettings . CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
}
} else if ( ( Prop - > type = = kTagTypeData ) & &
( Prop - > data ! = NULL ) & & ( Prop - > dataLen > 0 ) ) {
gSettings . CustomBoot = CUSTOM_BOOT_USER ;
if ( gSettings . CustomLogo ! = NULL ) {
2020-04-11 14:34:59 +02:00
delete gSettings . CustomLogo ;
2019-09-03 11:58:42 +02:00
}
2020-04-11 14:34:59 +02:00
gSettings . CustomLogo = new XImage ;
gSettings . CustomLogo - > FromPNG ( Prop - > data , Prop - > dataLen ) ;
if ( gSettings . CustomLogo - > isEmpty ( ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot logo not decoded from data! \n " /*, Prop->string*/ ) ;
2020-04-14 22:33:36 +02:00
gSettings . CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
} else {
gSettings . CustomBoot = CUSTOM_BOOT_USER_DISABLED ;
}
} else {
gSettings . CustomBoot = CUSTOM_BOOT_DISABLED ;
}
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot %s (0x%llX) \n " , CustomBootModeToStr ( gSettings . CustomBoot ) , ( uintptr_t ) gSettings . CustomLogo ) ;
2019-09-03 11:58:42 +02:00
}
//*** SYSTEM ***
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " SystemParameters " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
// Inject kexts
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " InjectKexts " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . WithKexts = TRUE ;
} else if ( ( Prop - > type = = kTagTypeString ) & &
( AsciiStriCmp ( Prop - > string , " Detect " ) = = 0 ) ) {
// gSettings.WithKexts = TRUE;
gSettings . WithKextsIfNoFakeSMC = TRUE ;
}
} else {
gSettings . WithKexts = TRUE ; //default
}
// No caches - obsolete
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NoCaches " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . NoCaches = TRUE ;
}
2020-04-22 19:52:21 +02:00
//test float
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BlueValue " ) ;
2020-04-22 19:52:21 +02:00
float tmpF = GetPropertyFloat ( Prop , 1.2f ) ;
DBG ( " get BlueValue=%f \n " , tmpF ) ;
2019-09-03 11:58:42 +02:00
}
// KernelAndKextPatches
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " KernelAndKextPatches " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
FillinKextPatches ( ( KERNEL_AND_KEXT_PATCHES * ) ( ( ( UINTN ) & gSettings ) + OFFSET_OF ( SETTINGS_DATA , KernelAndKextPatches ) ) , DictPointer ) ;
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " GUI " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Timezone " ) ;
GlobalConfig . Timezone = ( INT32 ) GetPropertyInteger ( Prop , GlobalConfig . Timezone ) ;
2019-09-03 11:58:42 +02:00
//initialize Daylight when we know timezone
EFI_TIME Now ;
gRT - > GetTime ( & Now , NULL ) ;
INT32 NowHour = Now . Hour + GlobalConfig . Timezone ;
if ( NowHour < 0 ) NowHour + = 24 ;
if ( NowHour > = 24 ) NowHour - = 24 ;
2020-04-16 13:04:24 +02:00
ThemeX . Daylight = ( NowHour > 8 ) & & ( NowHour < 20 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Theme " ) ;
2020-04-19 12:26:13 +02:00
if ( Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
ThemeX . Theme . takeValueFrom ( Prop - > string ) ;
2020-04-23 11:08:10 +02:00
GlobalConfig . Theme = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Default theme: %ls \n " , GlobalConfig . Theme ) ;
2020-04-19 12:26:13 +02:00
OldChosenTheme = 0xFFFF ; //default for embedded
for ( UINTN i = 0 ; i < ThemesNum ; i + + ) {
//now comparison is case sensitive
if ( StriCmp ( GlobalConfig . Theme , ThemesList [ i ] ) = = 0 ) {
OldChosenTheme = i ;
break ;
2020-03-26 09:18:28 +01:00
}
}
2020-04-19 12:26:13 +02:00
}
// get embedded theme property even when starting with other themes, as they may be changed later
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " EmbeddedThemeType " ) ;
2020-04-19 12:26:13 +02:00
if ( Prop & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( AsciiStriCmp ( Prop - > string , " Dark " ) = = 0 ) {
ThemeX . DarkEmbedded = TRUE ;
//ThemeX.Font = FONT_GRAY;
} else if ( AsciiStriCmp ( Prop - > string , " Light " ) = = 0 ) {
ThemeX . DarkEmbedded = FALSE ;
//ThemeX.Font = FONT_ALFA;
} else if ( AsciiStriCmp ( Prop - > string , " Daytime " ) = = 0 ) {
ThemeX . DarkEmbedded = ! ThemeX . Daylight ;
//ThemeX.Font = ThemeX.Daylight?FONT_ALFA:FONT_GRAY;
2020-03-26 09:18:28 +01:00
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " PlayAsync " ) ; //PlayAsync
2020-05-11 08:30:45 +02:00
gSettings . PlayAsync = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
// CustomIcons
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CustomIcons " ) ;
2020-03-26 09:18:28 +01:00
GlobalConfig . CustomIcons = IsPropertyTrue ( Prop ) ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " TextOnly " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . TextOnly = IsPropertyTrue ( Prop ) ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ShowOptimus " ) ;
2020-05-11 08:30:45 +02:00
GlobalConfig . ShowOptimus = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ScreenResolution " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
2020-04-23 11:08:10 +02:00
GlobalConfig . ScreenResolution = PoolPrint ( L " %a " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ConsoleMode " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeInteger ) {
GlobalConfig . ConsoleMode = ( INT32 ) ( UINTN ) Prop - > string ;
} else if ( ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
if ( AsciiStrStr ( Prop - > string , " Max " ) ! = NULL ) {
GlobalConfig . ConsoleMode = - 1 ;
2020-04-23 18:05:21 +02:00
DBG ( " ConsoleMode will be set to highest mode \n " ) ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Min " ) ! = NULL ) {
GlobalConfig . ConsoleMode = - 2 ;
2020-04-23 18:05:21 +02:00
DBG ( " ConsoleMode will be set to lowest mode \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
GlobalConfig . ConsoleMode = ( INT32 ) AsciiStrDecimalToUintn ( Prop - > string ) ;
}
}
if ( GlobalConfig . ConsoleMode > 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " ConsoleMode will be set to mode #%lld \n " , GlobalConfig . ConsoleMode ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Language " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . Language , 16 , Prop - > string ) ;
if ( AsciiStrStr ( Prop - > string , " en " ) ) {
gLanguage = english ;
GlobalConfig . Codepage = 0xC0 ;
GlobalConfig . CodepageSize = 0 ;
} else if ( AsciiStrStr ( Prop - > string , " ru " ) ) {
gLanguage = russian ;
GlobalConfig . Codepage = 0x410 ;
GlobalConfig . CodepageSize = 0x40 ;
} else if ( AsciiStrStr ( Prop - > string , " ua " ) ) {
gLanguage = ukrainian ;
GlobalConfig . Codepage = 0x400 ;
GlobalConfig . CodepageSize = 0x60 ;
} else if ( AsciiStrStr ( Prop - > string , " fr " ) ) {
gLanguage = french ; //default is extended latin
} else if ( AsciiStrStr ( Prop - > string , " it " ) ) {
gLanguage = italian ;
} else if ( AsciiStrStr ( Prop - > string , " es " ) ) {
gLanguage = spanish ;
} else if ( AsciiStrStr ( Prop - > string , " pt " ) ) {
gLanguage = portuguese ;
} else if ( AsciiStrStr ( Prop - > string , " br " ) ) {
gLanguage = brasil ;
} else if ( AsciiStrStr ( Prop - > string , " de " ) ) {
gLanguage = german ;
} else if ( AsciiStrStr ( Prop - > string , " nl " ) ) {
gLanguage = dutch ;
} else if ( AsciiStrStr ( Prop - > string , " pl " ) ) {
gLanguage = polish ;
} else if ( AsciiStrStr ( Prop - > string , " cz " ) ) {
gLanguage = czech ;
} else if ( AsciiStrStr ( Prop - > string , " hr " ) ) {
gLanguage = croatian ;
} else if ( AsciiStrStr ( Prop - > string , " id " ) ) {
gLanguage = indonesian ;
} else if ( AsciiStrStr ( Prop - > string , " zh_CN " ) ) {
gLanguage = chinese ;
GlobalConfig . Codepage = 0x3400 ;
GlobalConfig . CodepageSize = 0x19C0 ;
} else if ( AsciiStrStr ( Prop - > string , " ro " ) ) {
gLanguage = romanian ;
} else if ( AsciiStrStr ( Prop - > string , " ko " ) ) {
gLanguage = korean ;
GlobalConfig . Codepage = 0x1100 ;
GlobalConfig . CodepageSize = 0x100 ;
}
}
2020-03-11 14:24:29 +01:00
// if (gSettings.Language != NULL) { // gSettings.Language != NULL cannot be false because gSettings.Language is dclared as CHAR8 Language[16]; Must we replace by gSettings.Language[0] != NULL
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " KbdPrevLang " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . KbdPrevLang = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-03-11 14:24:29 +01:00
// }
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Mouse " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Speed " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . PointerSpeed = ( INT32 ) GetPropertyInteger ( Dict2 , 0 ) ;
2019-09-03 11:58:42 +02:00
gSettings . PointerEnabled = ( gSettings . PointerSpeed ! = 0 ) ;
}
//but we can disable mouse even if there was positive speed
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Enabled " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyFalse ( Dict2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . PointerEnabled = FALSE ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Mirror " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Dict2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . PointerMirror = TRUE ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " DoubleClickTime " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . DoubleClickTime = ( UINT64 ) GetPropertyInteger ( Dict2 , 500 ) ;
2019-09-03 11:58:42 +02:00
}
}
// hide by name/uuid
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Hide " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
gSettings . HVCount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . HVHideStrings = ( __typeof__ ( gSettings . HVHideStrings ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . HVHideStrings ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict2 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict2 = = NULL ) {
break ;
}
if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
gSettings . HVHideStrings [ gSettings . HVCount ] = PoolPrint ( L " %a " , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . HVHideStrings [ gSettings . HVCount ] ) {
2020-04-23 18:05:21 +02:00
DBG ( " Hiding entries with string %ls \n " , gSettings . HVHideStrings [ gSettings . HVCount ] ) ;
2019-09-03 11:58:42 +02:00
gSettings . HVCount + + ;
}
}
}
}
}
}
gSettings . LinuxScan = TRUE ;
// Disable loader scan
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Scan " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyFalse ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DisableEntryScan = TRUE ;
gSettings . DisableToolScan = TRUE ;
GlobalConfig . NoLegacy = TRUE ;
} else if ( Prop - > type = = kTagTypeDict ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Entries " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyFalse ( Dict2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DisableEntryScan = TRUE ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Tool " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyFalse ( Dict2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DisableToolScan = TRUE ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Linux " ) ;
2020-05-11 08:30:45 +02:00
gSettings . LinuxScan = ! IsPropertyFalse ( Dict2 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Legacy " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
if ( Dict2 - > type = = kTagTypeFalse ) {
GlobalConfig . NoLegacy = TRUE ;
} else if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
if ( ( Dict2 - > string [ 0 ] = = ' N ' ) | | ( Dict2 - > string [ 0 ] = = ' n ' ) ) {
GlobalConfig . NoLegacy = TRUE ;
} else if ( ( Dict2 - > string [ 0 ] = = ' F ' ) | | ( Dict2 - > string [ 0 ] = = ' f ' ) ) {
GlobalConfig . LegacyFirst = TRUE ;
}
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop , " Kernel " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
if ( Dict2 - > type = = kTagTypeFalse ) {
gSettings . KernelScan = KERNEL_SCAN_NONE ;
} else if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
if ( ( Dict2 - > string [ 0 ] = = ' N ' ) | | ( Dict2 - > string [ 0 ] = = ' n ' ) ) {
gSettings . KernelScan = ( ( Dict2 - > string [ 1 ] = = ' E ' ) | | ( Dict2 - > string [ 1 ] = = ' e ' ) ) ? KERNEL_SCAN_NEWEST : KERNEL_SCAN_NONE ;
} else if ( ( Dict2 - > string [ 0 ] = = ' O ' ) | | ( Dict2 - > string [ 0 ] = = ' o ' ) ) {
gSettings . KernelScan = KERNEL_SCAN_OLDEST ;
} else if ( ( Dict2 - > string [ 0 ] = = ' F ' ) | | ( Dict2 - > string [ 0 ] = = ' f ' ) ) {
gSettings . KernelScan = KERNEL_SCAN_FIRST ;
} else if ( ( Dict2 - > string [ 0 ] = = ' L ' ) | | ( Dict2 - > string [ 0 ] = = ' l ' ) ) {
gSettings . KernelScan = KERNEL_SCAN_LAST ;
} else if ( ( Dict2 - > string [ 0 ] = = ' M ' ) | | ( Dict2 - > string [ 0 ] = = ' m ' ) ) {
gSettings . KernelScan = KERNEL_SCAN_MOSTRECENT ;
} else if ( ( Dict2 - > string [ 0 ] = = ' E ' ) | | ( Dict2 - > string [ 0 ] = = ' e ' ) ) {
gSettings . KernelScan = KERNEL_SCAN_EARLIEST ;
}
}
}
}
}
// Custom entries
2020-04-11 14:34:59 +02:00
Dict2 = GetProperty ( DictPointer , " Custom " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( Dict2 , " Entries " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-05 14:25:39 +02:00
// CUSTOM_LOADER_ENTRY *Entry;
2020-04-11 14:34:59 +02:00
INTN i , Count = GetTagCount ( Prop ) ;
2019-09-03 11:58:42 +02:00
TagPtr Dict3 ;
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict3 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict3 = = NULL ) {
break ;
}
// Allocate an entry
2020-04-28 12:49:24 +02:00
// Entry = (CUSTOM_LOADER_ENTRY *)AllocateZeroPool(sizeof(CUSTOM_LOADER_ENTRY));
2020-04-05 14:25:39 +02:00
CUSTOM_LOADER_ENTRY * Entry = new CUSTOM_LOADER_ENTRY ;
2019-09-03 11:58:42 +02:00
// Fill it in
2020-05-16 21:30:29 +02:00
if ( Entry ! = NULL & & ( ! FillinCustomEntry ( Entry , Dict3 , FALSE ) | | ! AddCustomLoaderEntry ( Entry ) ) ) {
2020-04-05 14:25:39 +02:00
delete Entry ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( Dict2 , " Legacy " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
CUSTOM_LEGACY_ENTRY * Entry ;
2020-04-11 14:34:59 +02:00
INTN i , Count = GetTagCount ( Prop ) ;
2019-09-03 11:58:42 +02:00
TagPtr Dict3 ;
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-04-11 14:34:59 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict3 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict3 = = NULL ) {
break ;
}
// Allocate an entry
2020-04-11 14:34:59 +02:00
Entry = ( CUSTOM_LEGACY_ENTRY * ) AllocateZeroPool ( sizeof ( CUSTOM_LEGACY_ENTRY ) ) ;
2019-09-03 11:58:42 +02:00
if ( Entry ) {
// Fill it in
2020-04-11 14:34:59 +02:00
if ( ! FillingCustomLegacy ( Entry , Dict3 ) | | ! AddCustomLegacyEntry ( Entry ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry ) ;
2020-04-03 22:00:42 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( Dict2 , " Tool " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
CUSTOM_TOOL_ENTRY * Entry ;
2020-04-11 14:34:59 +02:00
INTN i , Count = GetTagCount ( Prop ) ;
2019-09-03 11:58:42 +02:00
TagPtr Dict3 ;
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict3 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict3 = = NULL ) {
break ;
}
// Allocate an entry
2020-04-11 14:34:59 +02:00
Entry = ( CUSTOM_TOOL_ENTRY * ) AllocateZeroPool ( sizeof ( CUSTOM_TOOL_ENTRY ) ) ;
2019-09-03 11:58:42 +02:00
if ( Entry ) {
// Fill it in
2020-04-11 14:34:59 +02:00
if ( ! FillingCustomTool ( Entry , Dict3 ) | | ! AddCustomToolEntry ( Entry ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( Entry ) ;
2020-04-03 22:00:42 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
}
}
}
}
2020-04-11 14:34:59 +02:00
DictPointer = GetProperty ( Dict , " Graphics " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-11 14:34:59 +02:00
Prop = GetProperty ( DictPointer , " PatchVBios " ) ;
gSettings . PatchVBios = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
gSettings . PatchVBiosBytesCount = 0 ;
2020-04-11 14:34:59 +02:00
Dict2 = GetProperty ( DictPointer , " PatchVBiosBytes " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-04-11 14:34:59 +02:00
INTN i , Count = GetTagCount ( Dict2 ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
VBIOS_PATCH_BYTES * VBiosPatch ;
UINTN FindSize = 0 ;
UINTN ReplaceSize = 0 ;
BOOLEAN Valid ;
// alloc space for up to 16 entries
2020-04-11 14:34:59 +02:00
gSettings . PatchVBiosBytes = ( __typeof__ ( gSettings . PatchVBiosBytes ) ) AllocateZeroPool ( Count * sizeof ( VBIOS_PATCH_BYTES ) ) ;
2019-09-03 11:58:42 +02:00
// get all entries
for ( i = 0 ; i < Count ; i + + ) {
// Get the next entry
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Dict2 , i , & Prop ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop = = NULL ) {
break ;
}
Valid = TRUE ;
// read entry
VBiosPatch = & gSettings . PatchVBiosBytes [ gSettings . PatchVBiosBytesCount ] ;
VBiosPatch - > Find = GetDataSetting ( Prop , " Find " , & FindSize ) ;
VBiosPatch - > Replace = GetDataSetting ( Prop , " Replace " , & ReplaceSize ) ;
if ( VBiosPatch - > Find = = NULL | | FindSize = = 0 ) {
Valid = FALSE ;
2020-04-23 18:05:21 +02:00
DBG ( " PatchVBiosBytes[%lld]: missing Find data \n " , i ) ;
2019-09-03 11:58:42 +02:00
}
if ( VBiosPatch - > Replace = = NULL | | ReplaceSize = = 0 ) {
Valid = FALSE ;
2020-04-23 18:05:21 +02:00
DBG ( " PatchVBiosBytes[%lld]: missing Replace data \n " , i ) ;
2019-09-03 11:58:42 +02:00
}
if ( FindSize ! = ReplaceSize ) {
Valid = FALSE ;
2020-04-23 18:05:21 +02:00
DBG ( " PatchVBiosBytes[%lld]: Find and Replace data are not the same size \n " , i ) ;
2019-09-03 11:58:42 +02:00
}
if ( Valid ) {
VBiosPatch - > NumberOfBytes = FindSize ;
// go to next entry
+ + gSettings . PatchVBiosBytesCount ;
} else {
// error - release mem
if ( VBiosPatch - > Find ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( VBiosPatch - > Find ) ;
2019-09-03 11:58:42 +02:00
VBiosPatch - > Find = NULL ;
}
if ( VBiosPatch - > Replace ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( VBiosPatch - > Replace ) ;
2019-09-03 11:58:42 +02:00
VBiosPatch - > Replace = NULL ;
}
}
}
if ( gSettings . PatchVBiosBytesCount = = 0 ) {
2020-04-23 11:08:10 +02:00
FreePool ( gSettings . PatchVBiosBytes ) ;
2019-09-03 11:58:42 +02:00
gSettings . PatchVBiosBytes = NULL ;
}
}
}
GetEDIDSettings ( DictPointer ) ;
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " DisableDrivers " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
INTN i , Count = GetTagCount ( DictPointer ) ;
if ( Count > 0 ) {
gSettings . BlackListCount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . BlackList = ( __typeof__ ( gSettings . BlackList ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( ! EFI_ERROR ( GetElement ( DictPointer , i , & Prop ) ) & &
2019-09-03 11:58:42 +02:00
Prop ! = NULL & & ( Prop - > type = = kTagTypeString ) ) {
2020-04-23 11:08:10 +02:00
gSettings . BlackList [ gSettings . BlackListCount + + ] = PoolPrint ( L " %a " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " Devices " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( DictPointer , " Audio " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
// HDA
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " ResetHDA " ) ;
2020-05-11 08:30:45 +02:00
gSettings . ResetHDA = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " RtVariables " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ROM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( ( AsciiStriCmp ( Prop - > string , " UseMacAddr0 " ) = = 0 ) | |
( AsciiStriCmp ( Prop - > string , " UseMacAddr1 " ) = = 0 ) ) {
GetLegacyLanAddress = TRUE ;
}
}
}
}
return Status ;
}
VOID
GetListOfConfigs ( )
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
INTN NameLen ;
ConfigsNum = 0 ;
OldChosenConfig = 0 ;
DirIterOpen ( SelfRootDir , OEMPath , & DirIter ) ;
DbgHeader ( " Found config plists " ) ;
while ( DirIterNext ( & DirIter , 2 , L " config*.plist " , & DirEntry ) ) {
CHAR16 FullName [ 256 ] ;
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
2020-04-04 15:50:13 +02:00
snwprintf ( FullName , 512 , " %ls \\ %ls " , OEMPath , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
if ( FileExists ( SelfRootDir , FullName ) ) {
if ( StriCmp ( DirEntry - > FileName , L " config.plist " ) = = 0 ) {
OldChosenConfig = ConfigsNum ;
}
NameLen = StrLen ( DirEntry - > FileName ) - 6 ; //without ".plist"
2020-04-27 17:16:43 +02:00
ConfigsList [ ConfigsNum ] = ( CHAR16 * ) AllocateCopyPool ( NameLen * sizeof ( CHAR16 ) + 2 , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
ConfigsList [ ConfigsNum + + ] [ NameLen ] = L ' \0 ' ;
2020-03-25 19:32:44 +01:00
DBG ( " - %ls \n " , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
}
}
DirIterClose ( & DirIter ) ;
}
VOID
GetListOfDsdts ( )
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
INTN NameLen ;
CHAR16 * AcpiPath = PoolPrint ( L " %s \\ ACPI \\ patched " , OEMPath ) ;
2020-05-01 02:14:11 +02:00
if ( DsdtsNum > 0 ) {
for ( UINTN i = 0 ; i < DsdtsNum ; i + + ) {
if ( DsdtsList [ DsdtsNum ] ! = NULL ) {
FreePool ( DsdtsList [ DsdtsNum ] ) ;
}
}
}
2019-09-03 11:58:42 +02:00
DsdtsNum = 0 ;
OldChosenDsdt = 0xFFFF ;
DirIterOpen ( SelfRootDir , AcpiPath , & DirIter ) ;
DbgHeader ( " Found DSDT tables " ) ;
while ( DirIterNext ( & DirIter , 2 , L " DSDT*.aml " , & DirEntry ) ) {
CHAR16 FullName [ 256 ] ;
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
2020-05-01 02:14:11 +02:00
snwprintf ( FullName , 512 , " %ls \\ %ls " , AcpiPath , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
if ( FileExists ( SelfRootDir , FullName ) ) {
if ( StriCmp ( DirEntry - > FileName , gSettings . DsdtName ) = = 0 ) {
OldChosenDsdt = DsdtsNum ;
}
NameLen = StrLen ( DirEntry - > FileName ) ; //with ".aml"
2020-05-01 02:14:11 +02:00
DsdtsList [ DsdtsNum ] = ( CHAR16 * ) AllocateCopyPool ( NameLen * sizeof ( CHAR16 ) + 2 , DirEntry - > FileName ) ; // if changing, notice freepool above
2019-09-03 11:58:42 +02:00
DsdtsList [ DsdtsNum + + ] [ NameLen ] = L ' \0 ' ;
2020-03-25 19:32:44 +01:00
DBG ( " - %ls \n " , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
}
}
DirIterClose ( & DirIter ) ;
}
VOID
GetListOfACPI ( )
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
ACPI_PATCHED_AML * ACPIPatchedAMLTmp ;
INTN i , Count = gSettings . DisabledAMLCount ;
CHAR16 * AcpiPath = PoolPrint ( L " %s \\ ACPI \\ patched " , OEMPath ) ;
2020-05-01 02:14:11 +02:00
while ( ACPIPatchedAML ! = NULL ) {
if ( ACPIPatchedAML - > FileName ) {
FreePool ( ACPIPatchedAML - > FileName ) ;
}
ACPIPatchedAMLTmp = ACPIPatchedAML ;
ACPIPatchedAML = ACPIPatchedAML - > Next ;
FreePool ( ACPIPatchedAMLTmp ) ;
}
2019-09-03 11:58:42 +02:00
ACPIPatchedAML = NULL ;
DirIterOpen ( SelfRootDir , AcpiPath , & DirIter ) ;
while ( DirIterNext ( & DirIter , 2 , L " *.aml " , & DirEntry ) ) {
CHAR16 FullName [ 256 ] ;
if ( DirEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
if ( StriStr ( DirEntry - > FileName , L " DSDT " ) ) {
continue ;
}
2020-05-01 02:14:11 +02:00
snwprintf ( FullName , 512 , " %ls \\ %ls " , AcpiPath , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
if ( FileExists ( SelfRootDir , FullName ) ) {
BOOLEAN ACPIDisabled = FALSE ;
2020-05-01 02:14:11 +02:00
ACPIPatchedAMLTmp = ( __typeof__ ( ACPIPatchedAMLTmp ) ) AllocateZeroPool ( sizeof ( ACPI_PATCHED_AML ) ) ; // if changing, notice freepool above
ACPIPatchedAMLTmp - > FileName = PoolPrint ( L " %s " , DirEntry - > FileName ) ; // if changing, notice freepool above
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
if ( ( gSettings . DisabledAML [ i ] ! = NULL ) & &
( StriCmp ( ACPIPatchedAMLTmp - > FileName , gSettings . DisabledAML [ i ] ) = = 0 )
) {
ACPIDisabled = TRUE ;
break ;
}
}
ACPIPatchedAMLTmp - > MenuItem . BValue = ACPIDisabled ;
ACPIPatchedAMLTmp - > Next = ACPIPatchedAML ;
ACPIPatchedAML = ACPIPatchedAMLTmp ;
}
}
DirIterClose ( & DirIter ) ;
FreePool ( AcpiPath ) ;
}
CHAR16 * GetBundleVersion ( CHAR16 * FullName )
{
EFI_STATUS Status ;
CHAR16 * CFBundleVersion = NULL ;
CHAR16 * InfoPlistPath ;
CHAR8 * InfoPlistPtr = NULL ;
TagPtr InfoPlistDict = NULL ;
TagPtr Prop = NULL ;
UINTN Size ;
InfoPlistPath = PoolPrint ( L " %s \\ %s " , FullName , L " Contents \\ Info.plist " ) ;
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( SelfRootDir , InfoPlistPath , ( UINT8 * * ) & InfoPlistPtr , & Size ) ;
2019-09-03 11:58:42 +02:00
if ( EFI_ERROR ( Status ) ) {
FreePool ( InfoPlistPath ) ;
InfoPlistPath = PoolPrint ( L " %s " , FullName , L " Info.plist " ) ; //special kexts like IOGraphics
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( SelfRootDir , InfoPlistPath , ( UINT8 * * ) & InfoPlistPtr , & Size ) ;
2019-09-03 11:58:42 +02:00
}
if ( ! EFI_ERROR ( Status ) ) {
2020-05-15 05:23:33 +02:00
Status = ParseXML ( ( const CHAR8 * ) InfoPlistPtr , & InfoPlistDict , ( UINT32 ) Size ) ;
2019-09-03 11:58:42 +02:00
if ( ! EFI_ERROR ( Status ) ) {
Prop = GetProperty ( InfoPlistDict , " CFBundleVersion " ) ;
if ( Prop ! = NULL & & Prop - > string ! = NULL ) {
2020-04-23 11:08:10 +02:00
CFBundleVersion = PoolPrint ( L " %a " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
if ( InfoPlistPtr ) {
FreePool ( InfoPlistPtr ) ;
}
FreePool ( InfoPlistPath ) ;
return CFBundleVersion ;
}
2019-12-09 11:22:15 +01:00
VOID GetListOfInjectKext ( CHAR16 * KextDirNameUnderOEMPath )
2019-09-03 11:58:42 +02:00
{
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
SIDELOAD_KEXT * mKext ;
SIDELOAD_KEXT * mPlugInKext ;
CHAR16 * FullName ;
2019-12-09 11:22:15 +01:00
CHAR16 * FullPath = PoolPrint ( L " %s \\ KEXTS \\ %s " , OEMPath , KextDirNameUnderOEMPath ) ;
2019-09-03 11:58:42 +02:00
REFIT_DIR_ITER PlugInsIter ;
EFI_FILE_INFO * PlugInEntry ;
CHAR16 * PlugInsPath ;
CHAR16 * PlugInsName ;
BOOLEAN Blocked = FALSE ;
2019-12-09 11:22:15 +01:00
if ( StrCmp ( KextDirNameUnderOEMPath , L " Off " ) = = 0 ) {
2019-09-03 11:58:42 +02:00
Blocked = TRUE ;
}
DirIterOpen ( SelfRootDir , FullPath , & DirIter ) ;
while ( DirIterNext ( & DirIter , 1 , L " *.kext " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = L ' . ' | | StrStr ( DirEntry - > FileName , L " .kext " ) = = NULL ) {
continue ;
}
/*
< key > CFBundleVersion < / key >
< string > 8.8 .8 < / string >
*/
FullName = PoolPrint ( L " %s \\ %s " , FullPath , DirEntry - > FileName ) ;
2020-04-28 12:49:24 +02:00
mKext = ( __typeof__ ( mKext ) ) AllocateZeroPool ( sizeof ( SIDELOAD_KEXT ) ) ;
2019-09-03 11:58:42 +02:00
mKext - > FileName = PoolPrint ( L " %s " , DirEntry - > FileName ) ;
mKext - > MenuItem . BValue = Blocked ;
2019-12-09 11:22:15 +01:00
mKext - > KextDirNameUnderOEMPath = PoolPrint ( L " %s " , KextDirNameUnderOEMPath ) ;
2019-09-03 11:58:42 +02:00
mKext - > Next = InjectKextList ;
mKext - > Version = GetBundleVersion ( FullName ) ;
InjectKextList = mKext ;
2020-03-25 19:32:44 +01:00
// DBG("Added mKext=%ls, MatchOS=%ls\n", mKext->FileName, mKext->MatchOS);
2019-09-03 11:58:42 +02:00
// Obtain PlugInList
// Iterate over PlugIns directory
PlugInsPath = PoolPrint ( L " %s \\ %s " , FullName , L " Contents \\ PlugIns " ) ;
DirIterOpen ( SelfRootDir , PlugInsPath , & PlugInsIter ) ;
while ( DirIterNext ( & PlugInsIter , 1 , L " *.kext " , & PlugInEntry ) ) {
if ( PlugInEntry - > FileName [ 0 ] = = L ' . ' | | StrStr ( PlugInEntry - > FileName , L " .kext " ) = = NULL ) {
continue ;
}
PlugInsName = PoolPrint ( L " %s \\ %s " , PlugInsPath , PlugInEntry - > FileName ) ;
2019-12-21 01:31:49 +01:00
mPlugInKext = ( __typeof__ ( mPlugInKext ) ) AllocateZeroPool ( sizeof ( SIDELOAD_KEXT ) ) ;
2019-09-03 11:58:42 +02:00
mPlugInKext - > FileName = PoolPrint ( L " %s " , PlugInEntry - > FileName ) ;
mPlugInKext - > MenuItem . BValue = Blocked ;
2019-12-09 11:22:15 +01:00
mPlugInKext - > KextDirNameUnderOEMPath = PoolPrint ( L " %s " , KextDirNameUnderOEMPath ) ;
2019-09-03 11:58:42 +02:00
mPlugInKext - > Next = mKext - > PlugInList ;
mPlugInKext - > Version = GetBundleVersion ( PlugInsName ) ;
mKext - > PlugInList = mPlugInKext ;
2020-03-25 19:32:44 +01:00
// DBG("---| added plugin=%ls, MatchOS=%ls\n", mPlugInKext->FileName, mPlugInKext->MatchOS);
2019-09-03 11:58:42 +02:00
FreePool ( PlugInsName ) ;
}
FreePool ( PlugInsPath ) ;
FreePool ( FullName ) ;
DirIterClose ( & PlugInsIter ) ;
}
DirIterClose ( & DirIter ) ;
FreePool ( FullPath ) ;
}
VOID InitKextList ( )
{
REFIT_DIR_ITER KextsIter ;
EFI_FILE_INFO * FolderEntry = NULL ;
CHAR16 * KextsPath ;
if ( InjectKextList ) {
return ; //don't scan again
}
KextsPath = PoolPrint ( L " %s \\ kexts " , OEMPath ) ;
// Iterate over kexts directory
DirIterOpen ( SelfRootDir , KextsPath , & KextsIter ) ;
while ( DirIterNext ( & KextsIter , 1 , L " * " , & FolderEntry ) ) {
if ( FolderEntry - > FileName [ 0 ] = = L ' . ' ) {
continue ;
}
GetListOfInjectKext ( FolderEntry - > FileName ) ;
}
DirIterClose ( & KextsIter ) ;
FreePool ( KextsPath ) ;
}
# define CONFIG_THEME_FILENAME L"theme.plist"
# define CONFIG_THEME_SVG L"theme.svg"
VOID
GetListOfThemes ( )
{
EFI_STATUS Status = EFI_NOT_FOUND ;
REFIT_DIR_ITER DirIter ;
EFI_FILE_INFO * DirEntry ;
CHAR16 * ThemeTestPath ;
EFI_FILE * ThemeTestDir = NULL ;
CHAR8 * ThemePtr = NULL ;
UINTN Size = 0 ;
DbgHeader ( " GetListOfThemes " ) ;
ThemesNum = 0 ;
2020-04-23 11:08:10 +02:00
DirIterOpen ( SelfRootDir , L " \\ EFI \\ CLOVER \\ themes " , & DirIter ) ;
2019-09-03 11:58:42 +02:00
while ( DirIterNext ( & DirIter , 1 , L " * " , & DirEntry ) ) {
if ( DirEntry - > FileName [ 0 ] = = ' . ' ) {
2020-03-25 19:32:44 +01:00
//DBG("Skip theme: %ls\n", DirEntry->FileName);
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-23 18:05:21 +02:00
//DBG("Found theme directory: %ls", DirEntry->FileName);
DBG ( " - [%02llu]: %ls " , ThemesNum , DirEntry - > FileName ) ;
2020-04-23 11:08:10 +02:00
ThemeTestPath = PoolPrint ( L " EFI \\ CLOVER \\ themes \\ %s " , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
if ( ThemeTestPath ! = NULL ) {
2020-04-23 11:08:10 +02:00
Status = SelfRootDir - > Open ( SelfRootDir , & ThemeTestDir , ThemeTestPath , 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 ) ) {
2019-09-03 11:58:42 +02:00
Status = EFI_NOT_FOUND ;
2020-04-23 18:05:21 +02:00
DBG ( " - bad theme because %ls nor %ls can't be load " , CONFIG_THEME_FILENAME , CONFIG_THEME_SVG ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
//we found a theme
if ( ( StriCmp ( DirEntry - > FileName , L " embedded " ) = = 0 ) | |
( StriCmp ( DirEntry - > FileName , L " random " ) = = 0 ) ) {
ThemePtr = NULL ;
} else {
2020-04-23 11:08:10 +02:00
ThemesList [ ThemesNum + + ] = ( CHAR16 * ) AllocateCopyPool ( StrSize ( DirEntry - > FileName ) , DirEntry - > FileName ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-04-23 11:08:10 +02:00
FreePool ( ThemeTestPath ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2019-09-03 11:58:42 +02:00
if ( ThemePtr ) {
FreePool ( ThemePtr ) ;
}
}
2020-04-23 11:08:10 +02:00
DirIterClose ( & DirIter ) ;
2019-09-03 11:58:42 +02:00
}
2020-03-26 15:24:20 +01:00
EFI_STATUS
2020-04-23 11:08:10 +02:00
XTheme : : GetThemeTagSettings ( void * DictP )
2020-03-26 15:24:20 +01:00
{
TagPtr Dict , Dict2 , Dict3 ;
TagPtr DictPointer = ( TagPtr ) DictP ;
//fill default to have an ability change theme
//assume Xtheme is already inited by embedded values
2020-04-02 16:03:58 +02:00
//theme variables
2020-03-26 15:24:20 +01:00
ScrollWidth = 16 ;
ScrollButtonsHeight = 20 ;
ScrollBarDecorationsHeight = 5 ;
ScrollScrollDecorationsHeight = 7 ;
2020-04-02 16:03:58 +02:00
Font = FONT_LOAD ; //not default
2020-03-26 15:24:20 +01:00
// if NULL parameter, quit after setting default values, this is embedded theme
2020-03-31 14:35:04 +02:00
if ( DictP = = NULL ) {
2020-03-26 15:24:20 +01:00
return EFI_SUCCESS ;
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " BootCampStyle " ) ;
2020-03-26 15:24:20 +01:00
BootCampStyle = IsPropertyTrue ( Dict ) ;
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Background " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Type " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
if ( ( Dict2 - > string [ 0 ] = = ' S ' ) | | ( Dict2 - > string [ 0 ] = = ' s ' ) ) {
BackgroundScale = imScale ;
} else if ( ( Dict2 - > string [ 0 ] = = ' T ' ) | | ( Dict2 - > string [ 0 ] = = ' t ' ) ) {
BackgroundScale = imTile ;
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Path " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
BackgroundName . takeValueFrom ( Dict2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Sharp " ) ;
BackgroundSharp = GetPropertyInteger ( Dict2 , BackgroundSharp ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Dark " ) ;
2020-03-26 15:24:20 +01:00
BackgroundDark = IsPropertyTrue ( Dict2 ) ;
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Banner " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
// retain for legacy themes.
if ( ( Dict - > type = = kTagTypeString ) & & Dict - > string ) {
BannerFileName . takeValueFrom ( Dict - > string ) ;
} else {
// for new placement settings
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Path " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL ) {
if ( ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
BannerFileName . takeValueFrom ( Dict2 - > string ) ;
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " ScreenEdgeX " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( Dict2 - > string , " left " ) = = 0 ) {
2020-03-26 15:24:20 +01:00
BannerEdgeHorizontal = SCREEN_EDGE_LEFT ;
2020-04-23 11:08:10 +02:00
} else if ( AsciiStrCmp ( Dict2 - > string , " right " ) = = 0 ) {
2020-03-26 15:24:20 +01:00
BannerEdgeHorizontal = SCREEN_EDGE_RIGHT ;
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " ScreenEdgeY " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( Dict2 - > string , " top " ) = = 0 ) {
2020-03-26 15:24:20 +01:00
BannerEdgeVertical = SCREEN_EDGE_TOP ;
2020-04-23 11:08:10 +02:00
} else if ( AsciiStrCmp ( Dict2 - > string , " bottom " ) = = 0 ) {
2020-03-26 15:24:20 +01:00
BannerEdgeVertical = SCREEN_EDGE_BOTTOM ;
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " DistanceFromScreenEdgeX% " ) ;
BannerPosX = GetPropertyInteger ( Dict2 , 0 ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " DistanceFromScreenEdgeY% " ) ;
BannerPosY = GetPropertyInteger ( Dict2 , 0 ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " NudgeX " ) ;
BannerNudgeX = GetPropertyInteger ( Dict2 , 0 ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " NudgeY " ) ;
BannerNudgeY = GetPropertyInteger ( Dict2 , 0 ) ;
2020-03-26 15:24:20 +01:00
}
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Badges " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Swap " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & Dict2 - > type = = kTagTypeTrue ) {
HideBadges | = HDBADGES_SWAP ;
2020-04-23 18:05:21 +02:00
DBG ( " OS main and drive as badge \n " ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Show " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & Dict2 - > type = = kTagTypeTrue ) {
HideBadges | = HDBADGES_SHOW ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Inline " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 ! = NULL & & Dict2 - > type = = kTagTypeTrue ) {
HideBadges | = HDBADGES_INLINE ;
}
// blackosx added X and Y position for badge offset.
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " OffsetX " ) ;
BadgeOffsetX = GetPropertyInteger ( Dict2 , BadgeOffsetX ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " OffsetY " ) ;
BadgeOffsetY = GetPropertyInteger ( Dict2 , BadgeOffsetY ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Scale " ) ;
ThemeX . BadgeScale = GetPropertyInteger ( Dict2 , BadgeScale ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Origination " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " DesignWidth " ) ;
ThemeDesignWidth = GetPropertyInteger ( Dict2 , ThemeDesignWidth ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " DesignHeight " ) ;
ThemeDesignHeight = GetPropertyInteger ( Dict2 , ThemeDesignHeight ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Layout " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " BannerOffset " ) ;
LayoutBannerOffset = GetPropertyInteger ( Dict2 , LayoutBannerOffset ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " ButtonOffset " ) ;
LayoutButtonOffset = GetPropertyInteger ( Dict2 , LayoutButtonOffset ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " TextOffset " ) ;
LayoutTextOffset = GetPropertyInteger ( Dict2 , LayoutTextOffset ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " AnimAdjustForMenuX " ) ;
LayoutAnimMoveForMenuX = GetPropertyInteger ( Dict2 , LayoutAnimMoveForMenuX ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Vertical " ) ;
2020-03-26 15:24:20 +01:00
VerticalLayout = IsPropertyTrue ( Dict2 ) ;
// GlobalConfig.MainEntriesSize
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " MainEntriesSize " ) ;
MainEntriesSize = GetPropertyInteger ( Dict2 , MainEntriesSize ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " TileXSpace " ) ;
TileXSpace = GetPropertyInteger ( Dict2 , TileXSpace ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " TileYSpace " ) ;
TileYSpace = GetPropertyInteger ( Dict2 , TileYSpace ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " SelectionBigWidth " ) ;
row0TileSize = GetPropertyInteger ( Dict2 , row0TileSize ) ;
2020-03-26 15:24:20 +01:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " SelectionSmallWidth " ) ;
row1TileSize = ( INTN ) GetPropertyInteger ( Dict2 , row1TileSize ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Components " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Banner " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
HideUIFlags | = HIDEUI_FLAG_BANNER ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Functions " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
HideUIFlags | = HIDEUI_FLAG_FUNCS ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Tools " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-03-27 17:50:17 +01:00
HideUIFlags | = HIDEUI_FLAG_TOOLS ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Label " ) ;
2020-03-26 15:24:20 +01:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-04-10 12:04:21 +02:00
HideUIFlags | = HIDEUI_FLAG_LABEL ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Revision " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-04-10 12:04:21 +02:00
HideUIFlags | = HIDEUI_FLAG_REVISION ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Help " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-04-10 12:04:21 +02:00
HideUIFlags | = HIDEUI_FLAG_HELP ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " MenuTitle " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-04-10 12:04:21 +02:00
HideUIFlags | = HIDEUI_FLAG_MENU_TITLE ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " MenuTitleImage " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeFalse ) {
2020-04-10 12:04:21 +02:00
HideUIFlags | = HIDEUI_FLAG_MENU_TITLE_IMAGE ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Selection " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Color " ) ;
SelectionColor = ( UINTN ) GetPropertyInteger ( Dict2 , SelectionColor ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Small " ) ;
2020-03-04 22:54:59 +01:00
if ( Dict2 & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-10 12:04:21 +02:00
SelectionSmallFileName . takeValueFrom ( Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Big " ) ;
2020-03-04 22:54:59 +01:00
if ( Dict2 & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-10 12:04:21 +02:00
SelectionBigFileName . takeValueFrom ( Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Indicator " ) ;
2020-03-04 22:54:59 +01:00
if ( Dict2 & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-10 12:04:21 +02:00
SelectionIndicatorName . takeValueFrom ( Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " OnTop " ) ;
2020-05-11 08:30:45 +02:00
SelectionOnTop = IsPropertyTrue ( Dict2 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " ChangeNonSelectedGrey " ) ;
2020-05-11 08:30:45 +02:00
NonSelectedGrey = IsPropertyTrue ( Dict2 ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Scroll " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Width " ) ;
ScrollWidth = ( UINTN ) GetPropertyInteger ( Dict2 , ScrollWidth ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Height " ) ;
ScrollButtonsHeight = ( UINTN ) GetPropertyInteger ( Dict2 , ScrollButtonsHeight ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " BarHeight " ) ;
ScrollBarDecorationsHeight = ( UINTN ) GetPropertyInteger ( Dict2 , ScrollBarDecorationsHeight ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " ScrollHeight " ) ;
ScrollScrollDecorationsHeight = ( UINTN ) GetPropertyInteger ( Dict2 , ScrollScrollDecorationsHeight ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Font " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
if ( ( Dict2 - > string [ 0 ] = = ' A ' ) | | ( Dict2 - > string [ 0 ] = = ' B ' ) ) {
2020-04-10 12:04:21 +02:00
Font = FONT_ALFA ;
2019-09-03 11:58:42 +02:00
} else if ( ( Dict2 - > string [ 0 ] = = ' G ' ) | | ( Dict2 - > string [ 0 ] = = ' W ' ) ) {
2020-04-10 12:04:21 +02:00
Font = FONT_GRAY ;
2019-09-03 11:58:42 +02:00
} else if ( ( Dict2 - > string [ 0 ] = = ' L ' ) | | ( Dict2 - > string [ 0 ] = = ' l ' ) ) {
2020-04-10 12:04:21 +02:00
Font = FONT_LOAD ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-10 12:04:21 +02:00
if ( Font = = FONT_LOAD ) {
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Path " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-10 12:04:21 +02:00
FontFileName . takeValueFrom ( Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " CharWidth " ) ;
CharWidth = ( UINTN ) GetPropertyInteger ( Dict2 , CharWidth ) ;
2020-04-10 12:04:21 +02:00
if ( CharWidth & 1 ) {
MsgLog ( " Warning! Character width %lld should be even! \n " , CharWidth ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict , " Proportional " ) ;
2020-05-11 08:30:45 +02:00
Proportional = IsPropertyTrue ( Dict2 ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict = GetProperty ( DictPointer , " Anime " ) ;
2020-04-14 18:52:13 +02:00
if ( Dict ! = NULL ) {
2020-04-15 11:13:51 +02:00
INTN Count = GetTagCount ( Dict ) ;
for ( INTN i = 0 ; i < Count ; i + + ) {
2020-04-14 18:52:13 +02:00
FILM * NewFilm = new FILM ( ) ;
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Dict , i , & Dict3 ) ) ) {
2020-04-14 18:52:13 +02:00
continue ;
}
if ( Dict3 = = NULL ) {
break ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " ID " ) ;
NewFilm - > SetIndex ( ( UINTN ) GetPropertyInteger ( Dict2 , 1 ) ) ; //default=main screen
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " Path " ) ;
2020-04-14 18:52:13 +02:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
NewFilm - > Path . takeValueFrom ( Dict2 - > string ) ;
}
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " Frames " ) ;
NewFilm - > NumFrames = ( UINTN ) GetPropertyInteger ( Dict2 , 0 ) ;
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " FrameTime " ) ;
NewFilm - > FrameTime = ( UINTN ) GetPropertyInteger ( Dict2 , 50 ) ; //default will be 50ms
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " ScreenEdgeX " ) ;
2020-04-14 18:52:13 +02:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( Dict2 - > string , " left " ) = = 0 ) {
2020-04-14 18:52:13 +02:00
NewFilm - > ScreenEdgeHorizontal = SCREEN_EDGE_LEFT ;
2020-04-23 11:08:10 +02:00
} else if ( AsciiStrCmp ( Dict2 - > string , " right " ) = = 0 ) {
2020-04-14 18:52:13 +02:00
NewFilm - > ScreenEdgeHorizontal = SCREEN_EDGE_RIGHT ;
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " ScreenEdgeY " ) ;
2020-04-14 18:52:13 +02:00
if ( Dict2 ! = NULL & & ( Dict2 - > type = = kTagTypeString ) & & Dict2 - > string ) {
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( Dict2 - > string , " top " ) = = 0 ) {
2020-04-14 18:52:13 +02:00
NewFilm - > ScreenEdgeVertical = SCREEN_EDGE_TOP ;
2020-04-23 11:08:10 +02:00
} else if ( AsciiStrCmp ( Dict2 - > string , " bottom " ) = = 0 ) {
2020-04-14 18:52:13 +02:00
NewFilm - > ScreenEdgeVertical = SCREEN_EDGE_BOTTOM ;
}
}
//default values are centre
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " DistanceFromScreenEdgeX% " ) ;
NewFilm - > FilmX = GetPropertyInteger ( Dict2 , INITVALUE ) ;
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " DistanceFromScreenEdgeY% " ) ;
NewFilm - > FilmY = GetPropertyInteger ( Dict2 , INITVALUE ) ;
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " NudgeX " ) ;
NewFilm - > NudgeX = GetPropertyInteger ( Dict2 , INITVALUE ) ;
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " NudgeY " ) ;
NewFilm - > NudgeY = GetPropertyInteger ( Dict2 , INITVALUE ) ;
2020-04-14 18:52:13 +02:00
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Dict3 , " Once " ) ;
2020-05-11 08:30:45 +02:00
NewFilm - > RunOnce = IsPropertyTrue ( Dict2 ) ;
2020-04-14 18:52:13 +02:00
2020-04-15 11:13:51 +02:00
NewFilm - > GetFrames ( ThemeX ) ; //used properties: ID, Path, NumFrames
2020-04-14 18:52:13 +02:00
ThemeX . Cinema . AddFilm ( NewFilm ) ;
// delete NewFilm; //looks like already deleted
}
}
2019-09-03 11:58:42 +02:00
2020-04-10 12:04:21 +02:00
//not sure if it needed
if ( BackgroundName . isEmpty ( ) ) {
BackgroundName . takeValueFrom ( " background " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-10 12:04:21 +02:00
if ( BannerFileName . isEmpty ( ) ) {
BannerFileName . takeValueFrom ( " logo " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-10 12:04:21 +02:00
if ( SelectionSmallFileName . isEmpty ( ) ) {
SelectionSmallFileName . takeValueFrom ( " selection_small " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-10 12:04:21 +02:00
if ( SelectionBigFileName . isEmpty ( ) ) {
SelectionBigFileName . takeValueFrom ( " selection_big " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-10 12:04:21 +02:00
if ( SelectionIndicatorName . isEmpty ( ) ) {
SelectionIndicatorName . takeValueFrom ( " selection_indicator " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-10 12:04:21 +02:00
if ( FontFileName . isEmpty ( ) ) {
FontFileName . takeValueFrom ( " font " ) ;
2019-09-03 11:58:42 +02:00
}
return EFI_SUCCESS ;
}
2020-04-03 22:00:42 +02:00
void * XTheme : : LoadTheme ( const CHAR16 * TestTheme )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status = EFI_UNSUPPORTED ;
TagPtr ThemeDict = NULL ;
CHAR8 * ThemePtr = NULL ;
UINTN Size = 0 ;
2020-04-04 04:59:17 +02:00
if ( TestTheme = = NULL ) {
return NULL ;
}
if ( ThemePath ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( ThemePath ) ;
2020-04-04 04:59:17 +02:00
}
if ( UGAHeight > HEIGHT_2K ) {
ThemePath = PoolPrint ( L " EFI \\ CLOVER \\ themes \\ %s@2x " , TestTheme ) ;
} else {
ThemePath = PoolPrint ( L " EFI \\ CLOVER \\ themes \\ %s " , TestTheme ) ;
}
Status = SelfRootDir - > Open ( SelfRootDir , & ThemeDir , ThemePath , EFI_FILE_MODE_READ , 0 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-04 04:59:17 +02:00
if ( ThemeDir ! = NULL ) {
ThemeDir - > Close ( ThemeDir ) ;
ThemeDir = NULL ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
FreePool ( ThemePath ) ;
2020-04-04 04:59:17 +02:00
ThemePath = PoolPrint ( L " EFI \\ CLOVER \\ themes \\ %s " , TestTheme ) ;
Status = SelfRootDir - > Open ( SelfRootDir , & ThemeDir , ThemePath , EFI_FILE_MODE_READ , 0 ) ;
}
2020-04-03 22:00:42 +02:00
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-04-04 04:59:17 +02:00
Status = egLoadFile ( ThemeDir , CONFIG_THEME_SVG , ( UINT8 * * ) & ThemePtr , & Size ) ;
if ( ! EFI_ERROR ( Status ) & & ( ThemePtr ! = NULL ) & & ( Size ! = 0 ) ) {
Status = ParseSVGXTheme ( ( const CHAR8 * ) ThemePtr ) ;
if ( EFI_ERROR ( Status ) ) {
ThemeDict = NULL ;
} else {
ThemeDict = ( __typeof__ ( ThemeDict ) ) AllocateZeroPool ( sizeof ( TagStruct ) ) ;
ThemeDict - > type = kTagTypeNone ;
}
if ( ThemeDict = = NULL ) {
DBG ( " svg file %ls not parsed \n " , CONFIG_THEME_SVG ) ;
} else {
DBG ( " Using vector theme '%ls' (%ls) \n " , TestTheme , ThemePath ) ;
}
} else {
Status = egLoadFile ( ThemeDir , CONFIG_THEME_FILENAME , ( UINT8 * * ) & ThemePtr , & Size ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) & & ( ThemePtr ! = NULL ) & & ( Size ! = 0 ) ) {
2020-04-04 04:59:17 +02:00
Status = ParseXML ( ( const CHAR8 * ) ThemePtr , & ThemeDict , 0 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-04 04:59:17 +02:00
ThemeDict = NULL ;
}
if ( ThemeDict = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " xml file %ls not parsed \n " , CONFIG_THEME_FILENAME ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using theme '%ls' (%ls) \n " , TestTheme , ThemePath ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
if ( ThemePtr ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( ThemePtr ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-03 22:00:42 +02:00
return ( void * ) ThemeDict ;
2019-09-03 11:58:42 +02:00
}
2020-03-26 15:24:20 +01:00
EFI_STATUS
2020-05-18 22:10:38 +02:00
InitTheme ( BOOLEAN UseThemeDefinedInNVRam )
2020-03-26 15:24:20 +01:00
{
EFI_STATUS Status = EFI_NOT_FOUND ;
UINTN Size = 0 ;
UINTN i ;
TagPtr ThemeDict = NULL ;
CHAR8 * ChosenTheme = NULL ;
CHAR16 * TestTheme = NULL ;
UINTN Rnd ;
2020-04-16 13:04:24 +02:00
EFI_TIME Now ;
2020-05-18 22:10:38 +02:00
gRT - > GetTime ( & Now , NULL ) ;
2020-05-17 20:56:10 +02:00
DbgHeader ( " InitXTheme " ) ;
ThemeX . Init ( ) ;
2020-04-16 13:04:24 +02:00
//initialize Daylight when we know timezone
if ( GlobalConfig . Timezone ! = 0xFF ) { // 0xFF:default=timezone not set
INT32 NowHour = Now . Hour + GlobalConfig . Timezone ;
if ( NowHour < 0 ) NowHour + = 24 ;
if ( NowHour > = 24 ) NowHour - = 24 ;
ThemeX . Daylight = ( NowHour > 8 ) & & ( NowHour < 20 ) ;
} else {
ThemeX . Daylight = TRUE ; // when timezone is not set
}
if ( ThemeX . Daylight ) {
DBG ( " use Daylight theme \n " ) ;
2020-03-26 15:24:20 +01:00
} else {
DBG ( " use night theme \n " ) ;
}
for ( i = 0 ; i < 3 ; i + + ) {
// DBG("validate %d face\n", i);
textFace [ i ] . valid = FALSE ;
}
NSVGfontChain * fontChain = fontsDB ;
while ( fontChain ) {
NSVGfont * font = fontChain - > font ;
// DBG("free font %s\n", font->fontFamily);
NSVGfontChain * nextChain = fontChain - > next ;
if ( font ) {
nsvg__deleteFont ( font ) ;
fontChain - > font = NULL ;
}
FreePool ( fontChain ) ;
fontChain = nextChain ;
}
//as all font freed then free the chain
fontsDB = NULL ;
/*
if ( mainParser ) {
nsvg__deleteParser ( mainParser ) ;
DBG ( " parser deleted \n " ) ;
mainParser = NULL ;
}
*/
2020-04-07 21:48:36 +02:00
ThemeX . FontImage . setEmpty ( ) ;
2020-03-26 15:24:20 +01:00
2020-05-18 22:10:38 +02:00
Rnd = ( ThemesNum ! = 0 ) ? Now . Second % ThemesNum : 0 ;
2020-03-26 15:24:20 +01:00
// DBG("...done\n");
ThemeX . GetThemeTagSettings ( NULL ) ;
2020-03-31 14:35:04 +02:00
if ( ThemesNum > 0 & &
( ! GlobalConfig . Theme | | StriCmp ( GlobalConfig . Theme , L " embedded " ) ! = 0 ) ) {
2020-03-26 15:24:20 +01:00
// Try special theme first
2020-05-18 22:10:38 +02:00
// if (Time != NULL) {
if ( ( Now . Month = = 12 ) & & ( ( Now . Day > = 25 ) & & ( Now . Day < = 31 ) ) ) {
2020-04-23 11:08:10 +02:00
TestTheme = PoolPrint ( L " christmas " ) ;
2020-05-18 22:10:38 +02:00
} else if ( ( Now . Month = = 1 ) & & ( ( Now . Day > = 1 ) & & ( Now . Day < = 3 ) ) ) {
2020-04-23 11:08:10 +02:00
TestTheme = PoolPrint ( L " newyear " ) ;
2020-03-26 15:24:20 +01:00
}
if ( TestTheme ! = NULL ) {
2020-04-03 22:00:42 +02:00
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( TestTheme ) ;
2020-03-26 15:24:20 +01:00
if ( ThemeDict ! = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " special theme %ls found and %ls parsed \n " , TestTheme , CONFIG_THEME_FILENAME ) ;
2020-03-31 16:25:07 +02:00
// ThemeX.Theme.takeValueFrom(TestTheme);
if ( GlobalConfig . Theme ) {
2020-04-23 11:08:10 +02:00
FreePool ( GlobalConfig . Theme ) ;
2020-03-31 16:25:07 +02:00
}
GlobalConfig . Theme = TestTheme ;
2020-03-26 15:24:20 +01:00
} else { // special theme not loaded
2020-04-23 18:05:21 +02:00
DBG ( " special theme %ls not found, skipping \n " , TestTheme /*, CONFIG_THEME_FILENAME*/ ) ;
2020-04-23 11:08:10 +02:00
FreePool ( TestTheme ) ;
2020-03-26 15:24:20 +01:00
}
TestTheme = NULL ;
}
2020-05-18 22:10:38 +02:00
// }
2020-03-26 15:24:20 +01:00
// Try theme from nvram
if ( ThemeDict = = NULL & & UseThemeDefinedInNVRam ) {
ChosenTheme = ( __typeof__ ( ChosenTheme ) ) GetNvramVariable ( L " Clover.Theme " , & gEfiAppleBootGuid , NULL , & Size ) ;
if ( ChosenTheme ! = NULL ) {
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( ChosenTheme , " embedded " ) = = 0 ) {
2020-03-26 15:24:20 +01:00
goto finish ;
}
2020-04-23 11:08:10 +02:00
if ( AsciiStrCmp ( ChosenTheme , " random " ) = = 0 ) {
2020-04-03 22:00:42 +02:00
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( ThemesList [ Rnd ] ) ;
2020-03-26 15:24:20 +01:00
goto finish ;
}
2020-04-23 11:08:10 +02:00
TestTheme = PoolPrint ( L " %a " , ChosenTheme ) ;
2020-03-26 15:24:20 +01:00
if ( TestTheme ! = NULL ) {
2020-04-03 22:00:42 +02:00
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( TestTheme ) ;
2020-03-26 15:24:20 +01:00
if ( ThemeDict ! = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " theme %s defined in NVRAM found and %ls parsed \n " , ChosenTheme , CONFIG_THEME_FILENAME ) ;
2020-03-31 16:25:07 +02:00
// ThemeX.Theme.takeValueFrom(TestTheme);
if ( GlobalConfig . Theme ) {
2020-04-23 11:08:10 +02:00
FreePool ( GlobalConfig . Theme ) ;
2020-03-31 16:25:07 +02:00
}
GlobalConfig . Theme = TestTheme ;
2020-03-26 15:24:20 +01:00
} else { // theme from nvram not loaded
2020-03-31 16:25:07 +02:00
if ( GlobalConfig . Theme ) {
2020-04-23 18:05:21 +02:00
DBG ( " theme %s chosen from nvram is absent, using theme defined in config: %ls \n " , ChosenTheme , GlobalConfig . Theme ) ;
2020-03-26 15:24:20 +01:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " theme %s chosen from nvram is absent, get first theme \n " , ChosenTheme ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-23 11:08:10 +02:00
FreePool ( TestTheme ) ;
2020-03-26 15:24:20 +01:00
}
TestTheme = NULL ;
}
2020-04-23 11:08:10 +02:00
FreePool ( ChosenTheme ) ;
2020-03-26 15:24:20 +01:00
ChosenTheme = NULL ;
}
}
// Try to get theme from settings
if ( ThemeDict = = NULL ) {
2020-03-31 14:35:04 +02:00
if ( ! GlobalConfig . Theme ) {
2020-05-18 22:10:38 +02:00
DBG ( " no default theme, get random theme %ls \n " , ThemesList [ Rnd ] ) ;
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( ThemesList [ Rnd ] ) ;
2020-03-26 15:24:20 +01:00
} else {
2020-03-31 14:35:04 +02:00
if ( StriCmp ( GlobalConfig . Theme , L " random " ) = = 0 ) {
2020-04-03 22:00:42 +02:00
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( ThemesList [ Rnd ] ) ;
2020-03-26 15:24:20 +01:00
} else {
2020-04-03 22:00:42 +02:00
ThemeDict = ( TagPtr ) ThemeX . LoadTheme ( GlobalConfig . Theme ) ;
2020-03-26 15:24:20 +01:00
if ( ThemeDict = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " GlobalConfig: %ls not found, get embedded theme \n " , GlobalConfig . Theme ) ;
2020-03-31 14:35:04 +02:00
} else {
DBG ( " chosen theme %ls \n " , GlobalConfig . Theme ) ;
2020-03-26 15:24:20 +01:00
}
}
}
}
} // ThemesNum>0
finish :
if ( ! ThemeDict ) { // No theme could be loaded, use embedded
2020-04-23 18:05:21 +02:00
DBG ( " using embedded theme \n " ) ;
2020-04-16 13:04:24 +02:00
if ( ThemeX . DarkEmbedded ) { // when using embedded, set Daylight according to darkembedded
ThemeX . Daylight = FALSE ;
} else {
ThemeX . Daylight = TRUE ;
}
ThemeX . FillByEmbedded ( ) ;
2020-03-26 15:24:20 +01:00
OldChosenTheme = 0xFFFF ;
if ( ThemePath ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( ThemePath ) ;
2020-03-26 15:24:20 +01:00
ThemePath = NULL ;
}
2020-04-03 22:00:42 +02:00
if ( ThemeX . ThemeDir ! = NULL ) {
ThemeX . ThemeDir - > Close ( ThemeX . ThemeDir ) ;
ThemeX . ThemeDir = NULL ;
2020-03-26 15:24:20 +01:00
}
2020-03-31 14:35:04 +02:00
// ThemeX.GetThemeTagSettings(NULL); already done
2020-03-26 15:24:20 +01:00
//fill some fields
2020-04-19 12:54:05 +02:00
//ThemeX.Font = FONT_ALFA; //to be inverted later. At start we have FONT_GRAY
2020-03-29 18:17:27 +02:00
ThemeX . embedded = true ;
2020-04-03 22:00:42 +02:00
Status = StartupSoundPlay ( ThemeX . ThemeDir , NULL ) ;
2020-03-26 15:24:20 +01:00
} else { // theme loaded successfully
2020-03-31 16:25:07 +02:00
ThemeX . embedded = false ;
2020-04-15 11:13:51 +02:00
ThemeX . Theme . takeValueFrom ( GlobalConfig . Theme ) ; //XStringW from CHAR16*)
2020-03-26 15:24:20 +01:00
// read theme settings
if ( ! ThemeX . TypeSVG ) {
TagPtr DictPointer = GetProperty ( ThemeDict , " Theme " ) ;
if ( DictPointer ! = NULL ) {
Status = ThemeX . GetThemeTagSettings ( ( void * ) DictPointer ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Config theme error: %s \n " , strerror ( Status ) ) ;
2020-04-01 19:07:57 +02:00
} else {
ThemeX . FillByDir ( ) ;
2020-03-26 15:24:20 +01:00
}
}
}
FreeTag ( ThemeDict ) ;
2020-04-16 13:04:24 +02:00
if ( ! ThemeX . Daylight ) {
2020-04-03 22:00:42 +02:00
Status = StartupSoundPlay ( ThemeX . ThemeDir , L " sound_night.wav " ) ;
2020-03-26 15:24:20 +01:00
if ( EFI_ERROR ( Status ) ) {
2020-04-03 22:00:42 +02:00
Status = StartupSoundPlay ( ThemeX . ThemeDir , L " sound.wav " ) ;
2020-03-26 15:24:20 +01:00
}
} else {
2020-04-03 22:00:42 +02:00
Status = StartupSoundPlay ( ThemeX . ThemeDir , L " sound.wav " ) ;
2020-03-26 15:24:20 +01:00
}
}
for ( i = 0 ; i < ThemesNum ; i + + ) {
if ( ! ThemeX . Theme . isEmpty ( ) & & StriCmp ( ThemeX . Theme . data ( ) , ThemesList [ i ] ) = = 0 ) {
OldChosenTheme = i ;
break ;
}
}
if ( ChosenTheme ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( ChosenTheme ) ;
2020-03-26 15:24:20 +01:00
}
2020-04-07 21:48:36 +02:00
if ( ! ThemeX . TypeSVG ) {
ThemeX . PrepareFont ( ) ;
}
2020-04-16 18:21:13 +02:00
//ThemeX.ClearScreen();
2020-03-26 15:24:20 +01:00
return Status ;
}
2019-09-03 11:58:42 +02:00
VOID
ParseSMBIOSSettings (
TagPtr DictPointer
)
{
2019-12-21 01:12:51 +01:00
CHAR8 * i , * j ;
2019-12-21 01:31:49 +01:00
CHAR8 * Res1 = ( __typeof__ ( Res1 ) ) AllocateZeroPool ( 9 ) ;
CHAR8 * Res2 = ( __typeof__ ( Res2 ) ) AllocateZeroPool ( 11 ) ;
2019-09-03 11:58:42 +02:00
CHAR16 UStr [ 64 ] ;
TagPtr Prop , Prop1 ;
BOOLEAN Default = FALSE ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ProductName " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
MACHINE_TYPES Model ;
AsciiStrCpyS ( gSettings . ProductName , 64 , Prop - > string ) ;
// let's fill all other fields based on this ProductName
// to serve as default
Model = GetModelFromString ( gSettings . ProductName ) ;
if ( Model ! = MaxMachineType ) {
SetDMISettingsForModel ( Model , FALSE ) ;
Default = TRUE ;
} else {
//if new model then fill at least as iMac13,2, except custom ProductName
// something else?
SetDMISettingsForModel ( iMac132 , FALSE ) ;
}
2020-04-23 18:05:21 +02:00
DBG ( " Using ProductName from config: %s \n " , gSettings . ProductName ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using ProductName from clover: %s \n " , gSettings . ProductName ) ;
2019-09-03 11:58:42 +02:00
}
2019-11-15 13:50:12 +01:00
Prop = GetProperty ( DictPointer , " SmbiosVersion " ) ;
gSettings . SmbiosVersion = ( UINT16 ) GetPropertyInteger ( Prop , 0x204 ) ;
2019-09-03 11:58:42 +02:00
// Check for BiosVersion and BiosReleaseDate by Sherlocks
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BiosVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
i = gSettings . RomVersion ;
j = Prop - > string ;
2020-04-28 12:49:24 +02:00
i + = AsciiStrLen ( i ) ;
2019-09-03 11:58:42 +02:00
while ( * i ! = ' . ' ) {
i - - ;
}
2020-04-28 12:49:24 +02:00
j + = AsciiStrLen ( j ) ;
2019-09-03 11:58:42 +02:00
while ( * j ! = ' . ' ) {
j - - ;
}
if ( ( ( i [ 1 ] > ' 0 ' ) & & ( j [ 1 ] = = ' 0 ' ) ) | | ( ( i [ 1 ] > = j [ 1 ] ) & & ( i [ 2 ] > j [ 2 ] ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from clover \n " ) ;
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 1 ] = = j [ 1 ] ) & & ( i [ 2 ] = = j [ 2 ] ) ) {
if ( ( ( i [ 3 ] > ' 0 ' ) & & ( j [ 3 ] = = ' 0 ' ) ) | | ( ( i [ 3 ] > = j [ 3 ] ) & & ( i [ 4 ] > j [ 4 ] ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from clover \n " ) ;
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
if ( ( ( i [ 5 ] > ' 0 ' ) & & ( j [ 5 ] = = ' 0 ' ) ) | | ( ( i [ 5 ] > ' 1 ' ) & & ( j [ 5 ] = = ' 1 ' ) ) | |
( ( i [ 5 ] > ' 2 ' ) & & ( j [ 5 ] = = ' 2 ' ) ) | | ( ( i [ 5 ] > = j [ 5 ] ) & & ( i [ 6 ] > j [ 6 ] ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from clover \n " ) ;
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 5 ] = = j [ 5 ] ) & & ( i [ 6 ] = = j [ 6 ] ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Found same BiosVersion in clover and config \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
AsciiStrCpyS ( gSettings . RomVersion , 64 , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from config \n " ) ;
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . RomVersion , 64 , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from config \n " ) ;
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . RomVersion , 64 , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using latest BiosVersion from config \n " ) ;
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-23 18:05:21 +02:00
DBG ( " BiosVersion: not set, Using BiosVersion from clover \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " BiosVersion: %s \n " , gSettings . RomVersion ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop1 = GetProperty ( DictPointer , " BiosReleaseDate " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop1 ! = NULL ) {
if ( Prop ! = NULL ) {
i = gSettings . ReleaseDate ;
j = Prop1 - > string ;
if ( ( AsciiStrLen ( i ) = = 8 ) & & ( AsciiStrLen ( j ) = = 8 ) ) {
if ( ( ( i [ 6 ] > ' 0 ' ) & & ( j [ 6 ] = = ' 0 ' ) ) | | ( ( i [ 6 ] > = j [ 6 ] ) & & ( i [ 7 ] > j [ 7 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 6 ] = = j [ 6 ] ) & & ( i [ 7 ] = = j [ 7 ] ) ) {
if ( ( ( i [ 0 ] > ' 0 ' ) & & ( j [ 0 ] = = ' 0 ' ) ) | | ( ( i [ 0 ] > = j [ 0 ] ) & & ( i [ 1 ] > j [ 1 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 0 ] = = j [ 0 ] ) & & ( i [ 1 ] = = j [ 1 ] ) ) {
if ( ( ( i [ 3 ] > ' 0 ' ) & & ( j [ 3 ] = = ' 0 ' ) ) | | ( ( i [ 3 ] > ' 1 ' ) & & ( j [ 3 ] = = ' 1 ' ) ) | |
( ( i [ 3 ] > ' 2 ' ) & & ( j [ 3 ] = = ' 2 ' ) ) | | ( ( i [ 3 ] > = j [ 3 ] ) & & ( i [ 4 ] > j [ 4 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found same BiosReleaseDate in clover and config\n");
2019-09-03 11:58:42 +02:00
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else if ( ( AsciiStrLen ( i ) = = 8 ) & & ( AsciiStrLen ( j ) = = 10 ) ) {
if ( ( ( i [ 6 ] > ' 0 ' ) & & ( j [ 8 ] = = ' 0 ' ) ) | | ( ( i [ 6 ] > = j [ 8 ] ) & & ( i [ 7 ] > j [ 9 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 6 ] = = j [ 8 ] ) & & ( i [ 7 ] = = j [ 9 ] ) ) {
if ( ( ( i [ 0 ] > ' 0 ' ) & & ( j [ 0 ] = = ' 0 ' ) ) | | ( ( i [ 0 ] > = j [ 0 ] ) & & ( i [ 1 ] > j [ 1 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 0 ] = = j [ 0 ] ) & & ( i [ 1 ] = = j [ 1 ] ) ) {
if ( ( ( i [ 3 ] > ' 0 ' ) & & ( j [ 3 ] = = ' 0 ' ) ) | | ( ( i [ 3 ] > ' 1 ' ) & & ( j [ 3 ] = = ' 1 ' ) ) | |
( ( i [ 3 ] > ' 2 ' ) & & ( j [ 3 ] = = ' 2 ' ) ) | | ( ( i [ 3 ] > = j [ 3 ] ) & & ( i [ 4 ] > j [ 4 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found same BiosReleaseDate in clover and config\n");
2019-09-03 11:58:42 +02:00
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res1 , 9 , " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res1 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res1 , 9 , " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res1 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res1 , 9 , " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res1 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else if ( ( AsciiStrLen ( i ) = = 10 ) & & ( AsciiStrLen ( j ) = = 10 ) ) {
if ( ( ( i [ 8 ] > ' 0 ' ) & & ( j [ 8 ] = = ' 0 ' ) ) | | ( ( i [ 8 ] > = j [ 8 ] ) & & ( i [ 9 ] > j [ 9 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 8 ] = = j [ 8 ] ) & & ( i [ 9 ] = = j [ 9 ] ) ) {
if ( ( ( i [ 0 ] > ' 0 ' ) & & ( j [ 0 ] = = ' 0 ' ) ) | | ( ( i [ 0 ] > = j [ 0 ] ) & & ( i [ 1 ] > j [ 1 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 0 ] = = j [ 0 ] ) & & ( i [ 1 ] = = j [ 1 ] ) ) {
if ( ( ( i [ 3 ] > ' 0 ' ) & & ( j [ 3 ] = = ' 0 ' ) ) | | ( ( i [ 3 ] > ' 1 ' ) & & ( j [ 3 ] = = ' 1 ' ) ) | |
( ( i [ 3 ] > ' 2 ' ) & & ( j [ 3 ] = = ' 2 ' ) ) | | ( ( i [ 3 ] > = j [ 3 ] ) & & ( i [ 4 ] > j [ 4 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found same BiosReleaseDate in clover and config\n");
2019-09-03 11:58:42 +02:00
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Prop1 - > string ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else if ( ( AsciiStrLen ( i ) = = 10 ) & & ( AsciiStrLen ( j ) = = 8 ) ) {
if ( ( ( i [ 8 ] > ' 0 ' ) & & ( j [ 6 ] = = ' 0 ' ) ) | | ( ( i [ 8 ] > = j [ 6 ] ) & & ( i [ 9 ] > j [ 7 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 8 ] = = j [ 6 ] ) & & ( i [ 9 ] = = j [ 7 ] ) ) {
if ( ( ( i [ 0 ] > ' 0 ' ) & & ( j [ 0 ] = = ' 0 ' ) ) | | ( ( i [ 0 ] > = j [ 0 ] ) & & ( i [ 1 ] > j [ 1 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 0 ] = = j [ 0 ] ) & & ( i [ 1 ] = = j [ 1 ] ) ) {
if ( ( ( i [ 3 ] > ' 0 ' ) & & ( j [ 3 ] = = ' 0 ' ) ) | | ( ( i [ 3 ] > ' 1 ' ) & & ( j [ 3 ] = = ' 1 ' ) ) | |
( ( i [ 3 ] > ' 2 ' ) & & ( j [ 3 ] = = ' 2 ' ) ) | | ( ( i [ 3 ] > = j [ 3 ] ) & & ( i [ 4 ] > j [ 4 ] ) ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
2020-04-23 18:05:21 +02:00
//DBG("Found same BiosReleaseDate in clover and config\n");
2019-09-03 11:58:42 +02:00
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res2 , 11 , " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res2 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res2 , 11 , " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res2 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-10 14:26:35 +02:00
snprintf ( Res2 , 11 , " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res2 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-23 18:05:21 +02:00
//DBG("Found unknown date format from config\n");
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
i = gSettings . ReleaseDate ;
j = gSettings . RomVersion ;
2020-04-28 12:49:24 +02:00
j + = AsciiStrLen ( j ) ;
2019-09-03 11:58:42 +02:00
while ( * j ! = ' . ' ) {
j - - ;
}
if ( ( AsciiStrLen ( i ) = = 8 ) ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res1 , 9 , " %c%c/%c%c/%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res1 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using the date of used BiosVersion\n");
2019-09-03 11:58:42 +02:00
} else if ( ( AsciiStrLen ( i ) = = 10 ) ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res2 , 11 , " %c%c/%c%c/20%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res2 ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using the date of used BiosVersion\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-23 18:05:21 +02:00
//DBG("Using BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
}
}
} else {
2020-04-23 18:05:21 +02:00
//DBG("BiosReleaseDate: set to %s from config, Ignore BiosReleaseDate\n", Prop1->string);
//DBG("Using BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
}
} else {
if ( Prop ! = NULL ) {
i = gSettings . ReleaseDate ;
j = gSettings . RomVersion ;
2020-04-28 12:49:24 +02:00
j + = AsciiStrLen ( j ) ;
2019-09-03 11:58:42 +02:00
while ( * j ! = ' . ' ) {
j - - ;
}
if ( ( AsciiStrLen ( i ) = = 8 ) ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res1 , 9 , " %c%c/%c%c/%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res1 ) ;
2020-04-23 18:05:21 +02:00
//DBG("BiosReleaseDate: not set, Using the date of used BiosVersion\n");
2019-09-03 11:58:42 +02:00
} else if ( ( AsciiStrLen ( i ) = = 10 ) ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res2 , 11 , " %c%c/%c%c/20%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . ReleaseDate , 64 , Res2 ) ;
2020-04-23 18:05:21 +02:00
//DBG("BiosReleaseDate: not set, Using the date of used BiosVersion\n");
2019-09-03 11:58:42 +02:00
}
} else {
2020-04-23 18:05:21 +02:00
//DBG("BiosReleaseDate: not set, Using BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 18:05:21 +02:00
DBG ( " BiosReleaseDate: %s \n " , gSettings . ReleaseDate ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " EfiVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( AsciiStrVersionToUint64 ( gSettings . EfiVersion , 4 , 5 ) > AsciiStrVersionToUint64 ( Prop - > string , 4 , 5 ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using latest EfiVersion from clover: %s \n " , gSettings . EfiVersion ) ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrVersionToUint64 ( gSettings . EfiVersion , 4 , 5 ) < AsciiStrVersionToUint64 ( Prop - > string , 4 , 5 ) ) {
AsciiStrCpyS ( gSettings . EfiVersion , 64 , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using latest EfiVersion from config: %s \n " , gSettings . EfiVersion ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using EfiVersion from clover: %s \n " , gSettings . EfiVersion ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( iStrLen ( gSettings . EfiVersion , 64 ) > 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " Using EfiVersion from clover: %s \n " , gSettings . EfiVersion ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FirmwareFeatures " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gFwFeatures = ( UINT32 ) GetPropertyInteger ( Prop , gFwFeatures ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using FirmwareFeatures from config: 0x%08X \n " , gFwFeatures ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using FirmwareFeatures from clover: 0x%08X \n " , gFwFeatures ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FirmwareFeaturesMask " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gFwFeaturesMask = ( UINT32 ) GetPropertyInteger ( Prop , gFwFeaturesMask ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Using FirmwareFeaturesMask from config: 0x%08X \n " , gFwFeaturesMask ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using FirmwareFeaturesMask from clover: 0x%08X \n " , gFwFeaturesMask ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " PlatformFeature " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
gPlatformFeature = ( UINT64 ) GetPropertyInteger ( Prop , ( INTN ) gPlatformFeature ) ;
} else {
if ( gPlatformFeature = = 0xFFFF ) {
2020-04-23 18:05:21 +02:00
DBG ( " PlatformFeature will not set in SMBIOS \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Using PlatformFeature from clover: 0x%llX \n " , gPlatformFeature ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BiosVendor " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . VendorName , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Manufacturer " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . ManufactureName , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Version " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . VersionNr , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Family " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . FamilyName , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SerialNumber " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
ZeroMem ( gSettings . SerialNr , 64 ) ;
AsciiStrCpyS ( gSettings . SerialNr , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SmUUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( IsValidGuidAsciiString ( Prop - > string ) ) {
AsciiStrToUnicodeStrS ( Prop - > string , ( CHAR16 * ) & UStr [ 0 ] , 64 ) ;
StrToGuidLE ( ( CHAR16 * ) & UStr [ 0 ] , & gSettings . SmUUID ) ;
gSettings . SmUUIDConfig = TRUE ;
} else {
2020-04-23 18:05:21 +02:00
DBG ( " Error: invalid SmUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BoardManufacturer " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . BoardManufactureName , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BoardSerialNumber " ) ;
2020-04-28 12:49:24 +02:00
if ( Prop ! = NULL & & AsciiStrLen ( Prop - > string ) > 0 ) {
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . BoardSerialNumber , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Board-ID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . BoardNumber , 64 , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Board-ID set from config as %s \n " , gSettings . BoardNumber ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BoardVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . BoardVersion , 64 , Prop - > string ) ;
} else if ( ! Default ) {
AsciiStrCpyS ( gSettings . BoardVersion , 64 , gSettings . ProductName ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BoardType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . BoardType = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . BoardType ) ;
2020-04-23 18:05:21 +02:00
DBG ( " BoardType: 0x%hhX \n " , gSettings . BoardType ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Mobile " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( IsPropertyFalse ( Prop ) )
gSettings . Mobile = FALSE ;
else if ( IsPropertyTrue ( Prop ) )
gSettings . Mobile = TRUE ;
} else if ( ! Default ) {
gSettings . Mobile = ( AsciiStrStr ( gSettings . ProductName , " MacBook " ) ! = NULL ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " LocationInChassis " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . LocationInChassis , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ChassisManufacturer " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . ChassisManufacturer , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ChassisAssetTag " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrCpyS ( gSettings . ChassisAssetTag , 64 , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ChassisType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . ChassisType = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . ChassisType ) ;
2020-04-23 18:05:21 +02:00
DBG ( " ChassisType: 0x%hhX \n " , gSettings . ChassisType ) ;
2019-09-03 11:58:42 +02:00
}
2019-12-12 15:51:55 +01:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NoRomInfo " ) ;
2019-12-12 15:51:55 +01:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . NoRomInfo = IsPropertyTrue ( Prop ) ;
2019-12-12 15:51:55 +01:00
}
2019-09-03 11:58:42 +02:00
}
EFI_STATUS
GetUserSettings (
IN EFI_FILE * RootDir ,
TagPtr CfgDict
)
{
EFI_STATUS Status = EFI_NOT_FOUND ;
TagPtr Dict ;
TagPtr Dict2 ;
TagPtr Prop ;
TagPtr Prop2 ;
TagPtr Prop3 ;
TagPtr DictPointer ;
BOOLEAN IsValidCustomUUID = FALSE ;
//UINTN i;
Dict = CfgDict ;
if ( Dict ! = NULL ) {
2020-04-23 18:05:21 +02:00
// DBG("Loading main settings\n");
2019-09-03 11:58:42 +02:00
DbgHeader ( " GetUserSettings " ) ;
// Boot settings.
// Discussion. Why Arguments is here? It should be SystemParameters property!
// we will read them again because of change in GUI menu. It is not only EarlySettings
//
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " Boot " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Arguments " ) ;
2019-09-03 11:58:42 +02:00
//if (Prop != NULL && (Prop->type == kTagTypeString) && Prop->string != NULL) {
if ( ( Prop ! = NULL ) & & ( Prop - > type = = kTagTypeString ) & & ( Prop - > string ! = NULL ) & & ( AsciiStrStr ( gSettings . BootArgs , Prop - > string ) = = NULL ) ) {
AsciiStrnCpyS ( gSettings . BootArgs , 256 , Prop - > string , 255 ) ;
//gBootArgsChanged = TRUE;
//gBootChanged = TRUE;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NeverDoRecovery " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NeverDoRecovery = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
//Graphics
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " Graphics " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
INTN i ;
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( DictPointer , " Inject " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Dict2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . GraphicsInjector = TRUE ;
gSettings . InjectIntel = TRUE ;
gSettings . InjectATI = TRUE ;
gSettings . InjectNVidia = TRUE ;
} else if ( Dict2 - > type = = kTagTypeDict ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Intel " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . InjectIntel = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " ATI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . InjectATI = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " NVidia " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . InjectNVidia = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
} else {
gSettings . GraphicsInjector = FALSE ;
gSettings . InjectIntel = FALSE ;
gSettings . InjectATI = FALSE ;
gSettings . InjectNVidia = FALSE ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " RadeonDeInit " ) ;
2020-05-11 08:30:45 +02:00
gSettings . DeInit = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " VRAM " ) ;
2019-09-03 11:58:42 +02:00
gSettings . VRAM = ( UINTN ) GetPropertyInteger ( Prop , ( INTN ) gSettings . VRAM ) ; //Mb
//
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " RefCLK " ) ;
gSettings . RefCLK = ( UINT16 ) GetPropertyInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " LoadVBios " ) ;
2020-05-11 08:30:45 +02:00
gSettings . LoadVBios = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < ( INTN ) NGFX ; i + + ) {
gGraphics [ i ] . LoadVBios = gSettings . LoadVBios ; //default
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " VideoPorts " ) ;
gSettings . VideoPorts = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . VideoPorts ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BootDisplay " ) ;
gSettings . BootDisplay = ( INT8 ) GetPropertyInteger ( Prop , - 1 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FBName " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . FBName , 16 ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NVCAP " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
hex2bin ( Prop - > string , ( UINT8 * ) & gSettings . NVCAP [ 0 ] , 20 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Read NVCAP: " ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < 20 ; i + + ) {
2020-04-23 18:05:21 +02:00
DBG ( " %02hhX " , gSettings . NVCAP [ i ] ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2019-09-03 11:58:42 +02:00
//thus confirmed this procedure is working
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " display-cfg " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
hex2bin ( Prop - > string , ( UINT8 * ) & gSettings . Dcfg [ 0 ] , 8 ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DualLink " ) ;
gSettings . DualLink = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . DualLink ) ;
2019-09-03 11:58:42 +02:00
//InjectEDID - already done in earlysettings
//No! Take again
GetEDIDSettings ( DictPointer ) ;
// ErmaC: NvidiaGeneric
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NvidiaGeneric " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NvidiaGeneric = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NvidiaNoEFI " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NvidiaNoEFI = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NvidiaSingle " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NvidiaSingle = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ig-platform-id " ) ;
gSettings . IgPlatform = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . IgPlatform ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " snb-platform-id " ) ;
gSettings . IgPlatform = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . IgPlatform ) ;
2019-09-03 11:58:42 +02:00
FillCardList ( DictPointer ) ; //#@ Getcardslist
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " Devices " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Inject " ) ;
2020-05-11 08:30:45 +02:00
gSettings . StringInjector = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SetIntelBacklight " ) ;
2020-05-11 08:30:45 +02:00
gSettings . IntelBacklight = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SetIntelMaxBacklight " ) ;
2020-05-11 08:30:45 +02:00
gSettings . IntelMaxBacklight = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " IntelMaxValue " ) ;
gSettings . IntelMaxValue = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . IntelMaxValue ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Properties " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( Prop - > type = = kTagTypeString ) {
EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ; //0xFE000000;
UINTN strlength = AsciiStrLen ( Prop - > string ) ;
2019-12-21 01:31:49 +01:00
cDeviceProperties = ( __typeof__ ( cDeviceProperties ) ) AllocateZeroPool ( strlength + 1 ) ;
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( cDeviceProperties , strlength + 1 , Prop - > string ) ;
//-------
Status = gBS - > AllocatePages (
AllocateMaxAddress ,
EfiACPIReclaimMemory ,
EFI_SIZE_TO_PAGES ( strlength ) + 1 ,
& BufferPtr
) ;
if ( ! EFI_ERROR ( Status ) ) {
cProperties = ( UINT8 * ) ( UINTN ) BufferPtr ;
cPropSize = ( UINT32 ) ( strlength > > 1 ) ;
cPropSize = hex2bin ( cDeviceProperties , cProperties , cPropSize ) ;
DBG ( " Injected EFIString of length %d \n " , cPropSize ) ;
}
//---------
}
else if ( Prop - > type = = kTagTypeDict ) {
//analyze dict-array
INTN i , Count = GetTagCount ( Prop ) ;
2019-12-21 01:31:49 +01:00
gSettings . AddProperties = ( __typeof__ ( gSettings . AddProperties ) ) AllocateZeroPool ( Count * sizeof ( DEV_PROPERTY ) ) ;
2019-09-03 11:58:42 +02:00
DEV_PROPERTY * DevPropDevice ;
DEV_PROPERTY * DevProps ;
DEV_PROPERTY * * Child ;
if ( Count > 0 ) {
2020-03-25 19:32:44 +01:00
DBG ( " Add %lld devices (kTagTypeDict): \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
Prop2 = NULL ;
EFI_DEVICE_PATH_PROTOCOL * DevicePath = NULL ;
if ( ! EFI_ERROR ( GetElement ( Prop , i , & Prop2 ) ) ) { //take a <key> with DevicePath
if ( ( Prop2 ! = NULL ) & & ( Prop2 - > type = = kTagTypeKey ) ) {
CHAR16 * DevicePathStr = PoolPrint ( L " %a " , Prop2 - > string ) ;
2020-03-25 19:32:44 +01:00
// DBG("Device: %ls\n", DevicePathStr);
2019-09-03 11:58:42 +02:00
// when key in Devices/Properties is one of the strings "PrimaryGPU" / "SecondaryGPU", use device path of first / second gpu accordingly
if ( StriCmp ( DevicePathStr , L " PrimaryGPU " ) = = 0 ) {
DevicePath = DevicePathFromHandle ( gGraphics [ 0 ] . Handle ) ; // first gpu
} else if ( StriCmp ( DevicePathStr , L " SecondaryGPU " ) = = 0 & & NGFX > 1 ) {
DevicePath = DevicePathFromHandle ( gGraphics [ 1 ] . Handle ) ; // second gpu
} else {
DevicePath = ConvertTextToDevicePath ( DevicePathStr ) ; //TODO
}
FreePool ( DevicePathStr ) ;
if ( DevicePath = = NULL ) {
continue ;
}
}
else continue ;
//Create Device node
DevPropDevice = gSettings . ArbProperties ;
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties = ( __typeof__ ( gSettings . ArbProperties ) ) AllocateZeroPool ( sizeof ( DEV_PROPERTY ) ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > Next = DevPropDevice ; //next device
gSettings . ArbProperties - > Child = NULL ;
gSettings . ArbProperties - > Device = 0 ; //to differ from arbitrary
gSettings . ArbProperties - > DevicePath = DevicePath ; //this is pointer
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Label = ( __typeof__ ( gSettings . ArbProperties - > Label ) ) AllocateCopyPool ( AsciiStrSize ( Prop2 - > string ) , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
Child = & ( gSettings . ArbProperties - > Child ) ;
Prop2 = Prop2 - > tag ; //take a <dict> for this device
if ( ( Prop2 ! = NULL ) & & ( Prop2 - > type = = kTagTypeDict ) ) {
2020-02-28 19:12:57 +01:00
INTN PropCount = 0 ;
2019-09-03 11:58:42 +02:00
PropCount = GetTagCount ( Prop2 ) ; //properties count for this device
// DBG("Add %d properties:\n", PropCount);
2020-02-28 19:12:57 +01:00
for ( INTN j = 0 ; j < PropCount ; j + + ) {
2019-09-03 11:58:42 +02:00
Prop3 = NULL ;
DevProps = * Child ;
2020-03-02 14:46:30 +01:00
* Child = ( __typeof_am__ ( * Child ) ) AllocateZeroPool ( sizeof ( * * Child ) ) ;
// *Child = new (__typeof_am__(**Child))();
2019-09-03 11:58:42 +02:00
( * Child ) - > Next = DevProps ;
if ( EFI_ERROR ( GetElement ( Prop2 , j , & Prop3 ) ) ) { // Prop3 -> <key>
continue ;
}
if ( ( Prop3 ! = NULL ) & & ( Prop3 - > type = = kTagTypeKey ) & &
( Prop3 - > string ! = NULL )
) {
if ( Prop3 - > string [ 0 ] ! = ' # ' ) {
( * Child ) - > MenuItem . BValue = TRUE ;
2019-12-21 01:31:49 +01:00
( * Child ) - > Key = ( __typeof__ ( ( * Child ) - > Key ) ) AllocateCopyPool ( AsciiStrSize ( Prop3 - > string ) , Prop3 - > string ) ;
2019-09-03 11:58:42 +02:00
}
else {
( * Child ) - > MenuItem . BValue = FALSE ;
2019-12-21 01:31:49 +01:00
( * Child ) - > Key = ( __typeof__ ( ( * Child ) - > Key ) ) AllocateCopyPool ( AsciiStrSize ( Prop3 - > string ) - 1 , Prop3 - > string + 1 ) ;
2019-09-03 11:58:42 +02:00
}
Prop3 = Prop3 - > tag ; //expected value
2020-03-25 19:32:44 +01:00
// DBG("<key>%s\n <value> type %d\n", (*Child)->Key, Prop3->type);
2019-09-03 11:58:42 +02:00
if ( Prop3 & & ( Prop3 - > type = = kTagTypeString ) & & Prop3 - > string ) {
//first suppose it is Ascii string
2019-12-21 01:31:49 +01:00
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocateCopyPool ( AsciiStrSize ( Prop3 - > string ) , Prop3 - > string ) ;
2019-09-03 11:58:42 +02:00
( * Child ) - > ValueLen = AsciiStrLen ( Prop3 - > string ) + 1 ;
( * Child ) - > ValueType = kTagTypeString ;
}
else if ( Prop3 & & ( Prop3 - > type = = kTagTypeInteger ) ) {
2019-12-21 01:31:49 +01:00
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocatePool ( 4 ) ;
2019-09-03 11:58:42 +02:00
CopyMem ( ( * Child ) - > Value , & ( Prop3 - > string ) , 4 ) ;
( * Child ) - > ValueLen = 4 ;
( * Child ) - > ValueType = kTagTypeInteger ;
}
else if ( Prop3 & & ( Prop3 - > type = = kTagTypeTrue ) ) {
2019-12-21 01:31:49 +01:00
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocateZeroPool ( 4 ) ;
2019-09-03 11:58:42 +02:00
( * Child ) - > Value [ 0 ] = TRUE ;
( * Child ) - > ValueLen = 1 ;
( * Child ) - > ValueType = kTagTypeTrue ;
}
else if ( Prop3 & & ( Prop3 - > type = = kTagTypeFalse ) ) {
2019-12-21 01:31:49 +01:00
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocateZeroPool ( 4 ) ;
2019-09-03 11:58:42 +02:00
//(*Child)->Value[0] = FALSE;
( * Child ) - > ValueLen = 1 ;
( * Child ) - > ValueType = kTagTypeFalse ;
}
else if ( Prop3 & & ( Prop3 - > type = = kTagTypeData ) ) {
UINTN Size = Prop3 - > dataLen ;
// (*Child)->Value = GetDataSetting(Prop3, "Value", &Size); //TODO
2019-12-21 01:31:49 +01:00
UINT8 * Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Size ) ;
2019-09-03 11:58:42 +02:00
CopyMem ( Data , Prop3 - > data , Size ) ;
( * Child ) - > Value = Data ;
( * Child ) - > ValueLen = Size ;
( * Child ) - > ValueType = kTagTypeData ;
}
}
}
}
}
}
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " LANInjection " ) ;
2020-05-11 08:30:45 +02:00
gSettings . LANInjection = ! IsPropertyFalse ( Prop ) ; //default = TRUE
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " HDMIInjection " ) ;
2020-05-11 08:30:45 +02:00
gSettings . HDMIInjection = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NoDefaultProperties " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NoDefaultProperties = ! IsPropertyFalse ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Arbitrary " ) ; //yyyy
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN Index , Count = GetTagCount ( Prop ) ;
DEV_PROPERTY * DevProp ;
if ( Count > 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " Add %lld devices (Arbitrary): \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( Index = 0 ; Index < Count ; Index + + ) {
UINTN DeviceAddr = 0U ;
CHAR8 * Label ;
2020-04-23 18:05:21 +02:00
DBG ( " - [%02lld]: " , Index ) ;
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , Index , & Prop2 ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " continue \n " /*, Index*/ ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop2 , " PciAddr " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-04-10 15:52:49 +02:00
UINT8 Bus , Dev , Func ;
2019-09-03 11:58:42 +02:00
CHAR8 * Str = Dict2 - > string ;
if ( Str [ 2 ] ! = ' : ' ) {
2020-03-25 19:32:44 +01:00
DBG ( " wrong PciAddr string: %s \n " , Str ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2019-12-21 01:31:49 +01:00
Label = ( __typeof__ ( Label ) ) AllocatePool ( 64 ) ;
2019-09-03 11:58:42 +02:00
Bus = hexstrtouint8 ( Str ) ;
Dev = hexstrtouint8 ( & Str [ 3 ] ) ;
Func = hexstrtouint8 ( & Str [ 6 ] ) ;
DeviceAddr = PCIADDR ( Bus , Dev , Func ) ;
2020-04-17 15:14:24 +02:00
snprintf ( Label , 64 , " [%02hhX:%02hhX.%02hhX] " , Bus , Dev , Func ) ;
2020-03-25 19:32:44 +01:00
DBG ( " %s " , Label ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " no PciAddr \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop2 , " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
AsciiStrCatS ( Label , 64 , Dict2 - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " (%s) " , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop2 , " CustomProperties " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
TagPtr Dict3 ;
INTN PropIndex , PropCount = GetTagCount ( Dict2 ) ;
for ( PropIndex = 0 ; PropIndex < PropCount ; PropIndex + + ) {
UINTN Size = 0 ;
if ( ! EFI_ERROR ( GetElement ( Dict2 , PropIndex , & Dict3 ) ) ) {
DevProp = gSettings . ArbProperties ;
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties = ( __typeof__ ( gSettings . ArbProperties ) ) AllocateZeroPool ( sizeof ( DEV_PROPERTY ) ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > Next = DevProp ;
gSettings . ArbProperties - > Device = ( UINT32 ) DeviceAddr ;
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Label = ( __typeof__ ( gSettings . ArbProperties - > Label ) ) AllocateCopyPool ( AsciiStrSize ( Label ) , Label ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop3 = GetProperty ( Dict3 , " Disabled " ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > MenuItem . BValue = ! IsPropertyTrue ( Prop3 ) ;
2020-04-23 11:08:10 +02:00
Prop3 = GetProperty ( Dict3 , " Key " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop3 & & ( Prop3 - > type = = kTagTypeString ) & & Prop3 - > string ) {
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Key = ( __typeof__ ( gSettings . ArbProperties - > Key ) ) AllocateCopyPool ( AsciiStrSize ( Prop3 - > string ) , Prop3 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop3 = GetProperty ( Dict3 , " Value " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop3 & & ( Prop3 - > type = = kTagTypeString ) & & Prop3 - > string ) {
//first suppose it is Ascii string
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Value = ( __typeof__ ( gSettings . ArbProperties - > Value ) ) AllocateCopyPool ( AsciiStrSize ( Prop3 - > string ) , Prop3 - > string ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > ValueLen = AsciiStrLen ( Prop3 - > string ) + 1 ;
gSettings . ArbProperties - > ValueType = kTagTypeString ;
} else if ( Prop3 & & ( Prop3 - > type = = kTagTypeInteger ) ) {
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Value = ( __typeof__ ( gSettings . ArbProperties - > Value ) ) AllocatePool ( 4 ) ;
2020-05-01 18:26:28 +02:00
CopyMem ( gSettings . ArbProperties - > Value , & ( Prop3 - > string ) , 4 ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > ValueLen = 4 ;
gSettings . ArbProperties - > ValueType = kTagTypeInteger ;
} else if ( Prop3 & & ( Prop3 - > type = = kTagTypeTrue ) ) {
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Value = ( __typeof__ ( gSettings . ArbProperties - > Value ) ) AllocateZeroPool ( 4 ) ;
2019-09-03 11:58:42 +02:00
gSettings . ArbProperties - > Value [ 0 ] = TRUE ;
gSettings . ArbProperties - > ValueLen = 1 ;
gSettings . ArbProperties - > ValueType = kTagTypeTrue ;
} else if ( Prop3 & & ( Prop3 - > type = = kTagTypeFalse ) ) {
2019-12-21 01:31:49 +01:00
gSettings . ArbProperties - > Value = ( __typeof__ ( gSettings . ArbProperties - > Value ) ) AllocateZeroPool ( 4 ) ;
2019-09-03 11:58:42 +02:00
//gSettings.ArbProperties->Value[0] = FALSE;
gSettings . ArbProperties - > ValueLen = 1 ;
gSettings . ArbProperties - > ValueType = kTagTypeFalse ;
} else {
//else data
gSettings . ArbProperties - > Value = GetDataSetting ( Dict3 , " Value " , & Size ) ;
gSettings . ArbProperties - > ValueLen = Size ;
gSettings . ArbProperties - > ValueType = kTagTypeData ;
}
//Special case. In future there must be more such cases
if ( ( AsciiStrStr ( gSettings . ArbProperties - > Key , " -platform-id " ) ! = NULL ) ) {
2020-05-01 18:26:28 +02:00
CopyMem ( ( CHAR8 * ) & gSettings . IgPlatform , gSettings . ArbProperties - > Value , 4 ) ;
2019-09-03 11:58:42 +02:00
}
}
} //for() device properties
}
FreePool ( Label ) ;
} //for() devices
}
// gSettings.NrAddProperties = 0xFFFE;
}
//can use AddProperties with ArbProperties
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AddProperties " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
INTN Index = 0 ; //begin from 0 if second enter
if ( Count > 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " Add %lld properties: \n " , Count ) ;
2020-04-28 12:49:24 +02:00
gSettings . AddProperties = ( __typeof__ ( gSettings . AddProperties ) ) AllocateZeroPool ( Count * sizeof ( DEV_PROPERTY ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
UINTN Size = 0 ;
2020-04-23 18:05:21 +02:00
DBG ( " - [%02lld]: " , i ) ;
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict2 ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " continue \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict2 = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " break \n " /*, i*/ ) ;
2019-09-03 11:58:42 +02:00
break ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Device " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
DEV_PROPERTY * Property = & gSettings . AddProperties [ Index ] ;
if ( AsciiStriCmp ( Prop2 - > string , " ATI " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_ATI ;
} else if ( AsciiStriCmp ( Prop2 - > string , " NVidia " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_NVIDIA ;
} else if ( AsciiStriCmp ( Prop2 - > string , " IntelGFX " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_INTEL ;
} else if ( AsciiStriCmp ( Prop2 - > string , " LAN " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_LAN ;
} else if ( AsciiStriCmp ( Prop2 - > string , " WIFI " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_WIFI ;
} else if ( AsciiStriCmp ( Prop2 - > string , " Firewire " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_FIREWIRE ;
} else if ( AsciiStriCmp ( Prop2 - > string , " SATA " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_SATA ;
} else if ( AsciiStriCmp ( Prop2 - > string , " IDE " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_IDE ;
} else if ( AsciiStriCmp ( Prop2 - > string , " HDA " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_HDA ;
} else if ( AsciiStriCmp ( Prop2 - > string , " HDMI " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_HDMI ;
} else if ( AsciiStriCmp ( Prop2 - > string , " LPC " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_LPC ;
} else if ( AsciiStriCmp ( Prop2 - > string , " SmBUS " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_SMBUS ;
} else if ( AsciiStriCmp ( Prop2 - > string , " USB " ) = = 0 ) {
Property - > Device = ( UINT32 ) DEV_USB ;
} else {
2020-04-23 18:05:21 +02:00
DBG ( " unknown device, ignored \n " /*, i*/ ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
}
2020-04-23 18:05:21 +02:00
DBG ( " %s " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
gSettings . AddProperties [ Index ] . MenuItem . BValue = ! IsPropertyTrue ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Key " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
2020-04-27 17:16:43 +02:00
gSettings . AddProperties [ Index ] . Key = ( __typeof__ ( gSettings . AddProperties [ Index ] . Key ) ) AllocateCopyPool ( AsciiStrSize ( Prop2 - > string ) , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Value " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
//first suppose it is Ascii string
2020-04-27 17:16:43 +02:00
gSettings . AddProperties [ Index ] . Value = ( __typeof__ ( gSettings . AddProperties [ Index ] . Value ) ) AllocateCopyPool ( AsciiStrSize ( Prop2 - > string ) , Prop2 - > string ) ;
2020-04-28 12:49:24 +02:00
gSettings . AddProperties [ Index ] . ValueLen = AsciiStrLen ( Prop2 - > string ) + 1 ;
2019-09-03 11:58:42 +02:00
} else if ( Prop2 & & ( Prop2 - > type = = kTagTypeInteger ) ) {
2019-12-21 01:31:49 +01:00
gSettings . AddProperties [ Index ] . Value = ( __typeof__ ( gSettings . AddProperties [ Index ] . Value ) ) AllocatePool ( 4 ) ;
2020-05-01 18:26:28 +02:00
CopyMem ( gSettings . AddProperties [ Index ] . Value , & ( Prop2 - > string ) , 4 ) ;
2019-09-03 11:58:42 +02:00
gSettings . AddProperties [ Index ] . ValueLen = 4 ;
} else {
//else data
gSettings . AddProperties [ Index ] . Value = GetDataSetting ( Dict2 , " Value " , & Size ) ;
gSettings . AddProperties [ Index ] . ValueLen = Size ;
}
2020-04-23 18:05:21 +02:00
DBG ( " Key: %s, len: %llu \n " , gSettings . AddProperties [ Index ] . Key , gSettings . AddProperties [ Index ] . ValueLen ) ;
2019-09-03 11:58:42 +02:00
if ( ! gSettings . AddProperties [ Index ] . MenuItem . BValue ) {
2020-04-23 18:05:21 +02:00
DBG ( " property disabled at config \n " ) ;
2019-09-03 11:58:42 +02:00
}
+ + Index ;
}
gSettings . NrAddProperties = Index ;
}
}
//end AddProperties
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FakeID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " ATI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeATI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " NVidia " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeNVidia = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " IntelGFX " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeIntel = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " LAN " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeLAN = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " WIFI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeWIFI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " SATA " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeSATA = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " XHCI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeXHCI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " IMEI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) ) {
gSettings . FakeIMEI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > string ) ;
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " UseIntelHDMI " ) ;
2020-05-11 08:30:45 +02:00
gSettings . UseIntelHDMI = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ForceHPET " ) ;
2020-05-11 08:30:45 +02:00
gSettings . ForceHPET = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DisableFunctions " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop & & ( Prop - > type = = kTagTypeString ) ) {
gSettings . DisableFunctions = ( UINT32 ) AsciiStrHexToUint64 ( Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AirportBridgeDeviceName " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop & & ( Prop - > type = = kTagTypeString ) ) {
AsciiStrCpyS ( gSettings . AirportBridgeDeviceName , sizeof ( gSettings . AirportBridgeDeviceName ) , Prop - > string ) ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( DictPointer , " Audio " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
// HDA
2020-04-23 11:08:10 +02:00
// Prop = GetProperty(Prop2, "ResetHDA");
2020-05-11 08:30:45 +02:00
// gSettings.ResetHDA = IsPropertyTrue(Prop);
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " Inject " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
// enabled by default
// syntax:
// - HDAInjection=No or 0 - disables injection
// - HDAInjection=887 - injects layout-id 887 decimal (0x00000377)
// - HDAInjection=0x377 - injects layout-id 887 decimal (0x00000377)
// - HDAInjection=Detect - reads codec device id (eg. 0x0887)
// converts it to decimal 887 and injects this as layout-id.
// if hex device is cannot be converted to decimal, injects legacy value 12 decimal
// - all other values are equal to HDAInjection=Detect
if ( Prop - > type = = kTagTypeInteger ) {
gSettings . HDALayoutId = ( INT32 ) ( UINTN ) Prop - > string ; //must be signed
gSettings . HDAInjection = ( gSettings . HDALayoutId > 0 ) ;
} else if ( Prop - > type = = kTagTypeString ) {
if ( ( Prop - > string [ 0 ] = = ' n ' ) | | ( Prop - > string [ 0 ] = = ' N ' ) ) {
// if starts with n or N, then no HDA injection
gSettings . HDAInjection = FALSE ;
} else if ( ( Prop - > string [ 0 ] = = ' 0 ' ) & &
( Prop - > string [ 1 ] = = ' x ' | | Prop - > string [ 1 ] = = ' X ' ) ) {
// assume it's a hex layout id
gSettings . HDALayoutId = ( INT32 ) AsciiStrHexToUintn ( Prop - > string ) ;
gSettings . HDAInjection = TRUE ;
} else {
// assume it's a decimal layout id
gSettings . HDALayoutId = ( INT32 ) AsciiStrDecimalToUintn ( Prop - > string ) ;
gSettings . HDAInjection = TRUE ;
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " AFGLowPowerState " ) ;
2020-05-11 08:30:45 +02:00
gSettings . AFGLowPowerState = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( DictPointer , " USB " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
// USB
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " Inject " ) ;
2020-05-11 08:30:45 +02:00
gSettings . USBInjection = ! IsPropertyFalse ( Prop ) ; // enabled by default
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " AddClockID " ) ;
2020-05-11 08:30:45 +02:00
gSettings . InjectClockID = IsPropertyTrue ( Prop ) ; // disabled by default
2019-09-03 11:58:42 +02:00
// enabled by default for CloverEFI
// disabled for others
gSettings . USBFixOwnership = gFirmwareClover ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " FixOwnership " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . USBFixOwnership = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " USB FixOwnership: %s \n " , gSettings . USBFixOwnership ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " HighCurrent " ) ;
2020-05-11 08:30:45 +02:00
gSettings . HighCurrent = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " NameEH00 " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NameEH00 = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
}
//*** ACPI ***//
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " ACPI " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DropTables " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
INTN i , Count = GetTagCount ( Prop ) ;
BOOLEAN Dropped ;
if ( Count > 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " Dropping %lld tables: \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
UINT32 Signature = 0 ;
UINT32 TabLength = 0 ;
UINT64 TableId = 0 ;
2020-04-20 18:33:42 +02:00
BOOLEAN OtherOS = FALSE ;
2019-09-03 11:58:42 +02:00
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , i , & Dict2 ) ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " - [%02lld]: Drop table continue \n " , i ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Dict2 = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " - [%02lld]: Drop table break \n " , i ) ;
2019-09-03 11:58:42 +02:00
break ;
}
2020-04-23 18:05:21 +02:00
DBG ( " - [%02lld]: Drop table " , i ) ;
2019-09-03 11:58:42 +02:00
// Get the table signatures to drop
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Signature " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
CHAR8 s1 = 0 , s2 = 0 , s3 = 0 , s4 = 0 ;
CHAR8 * str = Prop2 - > string ;
if ( str ) {
if ( * str ) {
s1 = * str + + ;
}
if ( * str ) {
s2 = * str + + ;
}
if ( * str ) {
s3 = * str + + ;
}
if ( * str ) {
s4 = * str + + ;
2020-04-23 18:05:21 +02:00
}
2019-09-03 11:58:42 +02:00
}
Signature = SIGNATURE_32 ( s1 , s2 , s3 , s4 ) ;
2020-04-23 18:34:01 +02:00
DBG ( " signature= \" %c%c%c%c \" (%8.8X) \n " , s1 , s2 , s3 , s4 , Signature ) ;
2019-09-03 11:58:42 +02:00
}
// Get the table ids to drop
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " TableId " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
UINTN IdIndex = 0 ;
2020-04-23 18:05:21 +02:00
CHAR8 Id [ 9 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
2019-09-03 11:58:42 +02:00
CHAR8 * Str = Prop2 - > string ;
if ( Str ) {
while ( * Str & & ( IdIndex < 8 ) ) {
2020-04-23 18:05:21 +02:00
// DBG("%c", *Str);
2019-09-03 11:58:42 +02:00
Id [ IdIndex + + ] = * Str + + ;
}
}
2020-05-01 18:26:28 +02:00
CopyMem ( & TableId , ( CHAR8 * ) & Id [ 0 ] , 8 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " table-id= \" %s \" (%16.16llX) \n " , Id , TableId ) ;
2019-09-03 11:58:42 +02:00
}
// Get the table len to drop
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Length " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
2020-04-23 11:08:10 +02:00
TabLength = ( UINT32 ) GetPropertyInteger ( Prop2 , 0 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " length=%d(0x%X) " , TabLength , TabLength ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-20 18:33:42 +02:00
// Check if to drop for other OS as well
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " DropForAllOS " ) ;
2020-04-22 18:37:28 +02:00
if ( Prop2 ! = NULL ) {
2020-05-11 08:30:45 +02:00
OtherOS = IsPropertyTrue ( Prop2 ) ;
2020-04-20 18:33:42 +02:00
}
2019-09-03 11:58:42 +02:00
2020-04-23 18:05:21 +02:00
DBG ( " ---- \n " ) ;
2019-09-03 11:58:42 +02:00
//set to drop
if ( gSettings . ACPIDropTables ) {
ACPI_DROP_TABLE * DropTable = gSettings . ACPIDropTables ;
2020-04-23 18:05:21 +02:00
DBG ( " - set table: %08X, %16llx to drop: " , Signature , TableId ) ;
2019-09-03 11:58:42 +02:00
Dropped = FALSE ;
while ( DropTable ) {
if ( ( ( Signature = = DropTable - > Signature ) & &
( ! TableId | | ( DropTable - > TableId = = TableId ) ) & &
( ! TabLength | | ( DropTable - > Length = = TabLength ) ) ) | |
( ! Signature & & ( DropTable - > TableId = = TableId ) ) ) {
DropTable - > MenuItem . BValue = TRUE ;
2020-04-20 18:33:42 +02:00
DropTable - > OtherOS = OtherOS ;
2019-09-03 11:58:42 +02:00
gSettings . DropSSDT = FALSE ; //if one item=true then dropAll=false by default
2020-04-23 18:05:21 +02:00
//DBG(" true");
2019-09-03 11:58:42 +02:00
Dropped = TRUE ;
}
DropTable = DropTable - > Next ;
}
2020-04-23 18:05:21 +02:00
DBG ( " %s \n " , Dropped ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( DictPointer , " DSDT " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ) {
//gSettings.DsdtName by default is "DSDT.aml", but name "BIOS" will mean autopatch
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Name " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . DsdtName , 28 ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Debug " ) ;
2020-05-11 08:30:45 +02:00
gSettings . DebugDSDT = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Rtc8Allowed " ) ;
2020-05-11 08:30:45 +02:00
gSettings . Rtc8Allowed = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " PNLF_UID " ) ;
gSettings . PNLF_UID = ( UINT8 ) GetPropertyInteger ( Prop , 0x0A ) ;
2020-01-02 07:29:08 +01:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " FixMask " ) ;
gSettings . FixDsdt = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . FixDsdt ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Fixes " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
UINTN Index ;
2020-04-23 18:05:21 +02:00
// DBG("Fixes will override DSDT fix mask %08X!\n", gSettings.FixDsdt);
2019-09-03 11:58:42 +02:00
if ( Prop - > type = = kTagTypeDict ) {
gSettings . FixDsdt = 0 ;
for ( Index = 0 ; Index < sizeof ( FixesConfig ) / sizeof ( FixesConfig [ 0 ] ) ; Index + + ) {
Prop2 = GetProperty ( Prop , FixesConfig [ Index ] . newName ) ;
if ( ! Prop2 & & FixesConfig [ Index ] . oldName ) {
Prop2 = GetProperty ( Prop , FixesConfig [ Index ] . oldName ) ;
}
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . FixDsdt | = FixesConfig [ Index ] . bitData ;
}
}
}
}
2020-04-23 18:05:21 +02:00
DBG ( " - final DSDT Fix mask=%08X \n " , gSettings . FixDsdt ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " Patches " ) ; //yyyy
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
gSettings . PatchDsdtNum = ( UINT32 ) Count ;
2020-04-28 12:49:24 +02:00
gSettings . PatchDsdtFind = ( __typeof__ ( gSettings . PatchDsdtFind ) ) AllocateZeroPool ( Count * sizeof ( UINT8 * ) ) ;
gSettings . PatchDsdtReplace = ( __typeof__ ( gSettings . PatchDsdtReplace ) ) AllocateZeroPool ( Count * sizeof ( UINT8 * ) ) ;
gSettings . PatchDsdtTgt = ( __typeof__ ( gSettings . PatchDsdtTgt ) ) AllocateZeroPool ( Count * sizeof ( UINT8 * ) ) ;
gSettings . LenToFind = ( __typeof__ ( gSettings . LenToFind ) ) AllocateZeroPool ( Count * sizeof ( UINT32 ) ) ;
gSettings . LenToReplace = ( __typeof__ ( gSettings . LenToReplace ) ) AllocateZeroPool ( Count * sizeof ( UINT32 ) ) ;
gSettings . PatchDsdtLabel = ( __typeof__ ( gSettings . PatchDsdtLabel ) ) AllocateZeroPool ( Count * sizeof ( UINT8 * ) ) ;
gSettings . PatchDsdtMenuItem = ( __typeof__ ( gSettings . PatchDsdtMenuItem ) ) AllocateZeroPool ( Count * sizeof ( INPUT_ITEM ) ) ;
2020-04-23 18:05:21 +02:00
DBG ( " PatchesDSDT: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
UINTN Size = 0 ;
CHAR8 * DSDTPatchesLabel ;
2020-05-11 08:30:45 +02:00
Status = GetElement ( Prop , i , & Prop2 ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " error %s getting next element of PatchesDSDT at index %lld \n " , strerror ( Status ) , i ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop2 = = NULL ) {
break ;
}
2020-03-25 19:32:44 +01:00
DBG ( " - [%02lld]: " , i ) ;
2019-12-21 01:31:49 +01:00
DSDTPatchesLabel = ( __typeof__ ( DSDTPatchesLabel ) ) AllocateZeroPool ( 256 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop3 = GetProperty ( Prop2 , " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop3 ! = NULL & & ( Prop3 - > type = = kTagTypeString ) & & Prop3 - > string ) {
2020-03-29 15:44:08 +02:00
snprintf ( DSDTPatchesLabel , 255 , " %s " , Prop3 - > string ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-03-29 15:44:08 +02:00
snprintf ( DSDTPatchesLabel , 255 , " (NoLabel) " ) ;
2019-09-03 11:58:42 +02:00
}
2020-02-21 22:22:30 +01:00
gSettings . PatchDsdtLabel [ i ] = ( __typeof_am__ ( gSettings . PatchDsdtLabel [ i ] ) ) AllocateZeroPool ( 256 ) ;
2020-03-29 15:44:08 +02:00
snprintf ( gSettings . PatchDsdtLabel [ i ] , 255 , " %s " , DSDTPatchesLabel ) ;
2020-03-25 19:32:44 +01:00
DBG ( " (%s) " , gSettings . PatchDsdtLabel [ i ] ) ;
2019-09-03 11:58:42 +02:00
FreePool ( DSDTPatchesLabel ) ;
2020-04-23 11:08:10 +02:00
Prop3 = GetProperty ( Prop2 , " Disabled " ) ;
2020-05-11 08:30:45 +02:00
gSettings . PatchDsdtMenuItem [ i ] . BValue = ! IsPropertyTrue ( Prop3 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 18:05:21 +02:00
//DBG(" DSDT bin patch #%d ", i);
2019-09-03 11:58:42 +02:00
gSettings . PatchDsdtFind [ i ] = GetDataSetting ( Prop2 , " Find " , & Size ) ;
2020-04-23 18:05:21 +02:00
DBG ( " lenToFind: %llu " , Size ) ;
2019-09-03 11:58:42 +02:00
gSettings . LenToFind [ i ] = ( UINT32 ) Size ;
gSettings . PatchDsdtReplace [ i ] = GetDataSetting ( Prop2 , " Replace " , & Size ) ;
2020-04-23 18:05:21 +02:00
DBG ( " , lenToReplace: %llu " , Size ) ;
2019-09-03 11:58:42 +02:00
gSettings . LenToReplace [ i ] = ( UINT32 ) Size ;
2019-12-27 18:01:40 +01:00
gSettings . PatchDsdtTgt [ i ] = ( CHAR8 * ) GetDataSetting ( Prop2 , " TgtBridge " , & Size ) ;
2020-04-23 18:05:21 +02:00
DBG ( " , Target Bridge: %s \n " , gSettings . PatchDsdtTgt [ i ] ) ;
2019-09-03 11:58:42 +02:00
if ( ! gSettings . PatchDsdtMenuItem [ i ] . BValue ) {
DBG ( " patch disabled at config \n " ) ;
}
}
} //if count > 0
} //if prop PatchesDSDT
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " ReuseFFFF " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . ReuseFFFF = TRUE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " SuspendOverride " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . SuspendOverride = TRUE ;
}
2020-05-09 11:15:03 +02:00
/*
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " DropOEM_DSM " ) ;
2019-09-03 11:58:42 +02:00
defDSM = FALSE ;
if ( Prop ! = NULL ) {
defDSM = TRUE ; //set by user
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM = 0xFFFF ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyFalse ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM = 0 ;
} else if ( Prop - > type = = kTagTypeInteger ) {
gSettings . DropOEM_DSM = ( UINT16 ) ( UINTN ) Prop - > string ;
} else if ( Prop - > type = = kTagTypeDict ) {
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " ATI " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_ATI ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " NVidia " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_NVIDIA ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " IntelGFX " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_INTEL ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " HDA " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_HDA ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " HDMI " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_HDMI ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " SATA " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_SATA ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " LAN " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_LAN ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " WIFI " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_WIFI ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " USB " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_USB ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " LPC " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_LPC ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " SmBUS " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_SMBUS ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " Firewire " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_FIREWIRE ;
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " IDE " ) ;
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . DropOEM_DSM | = DEV_IDE ;
}
}
}
2020-05-09 11:15:03 +02:00
*/
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( DictPointer , " SSDT " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ) {
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict2 , " Generate " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyTrue ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . GeneratePStates = TRUE ;
gSettings . GenerateCStates = TRUE ;
gSettings . GenerateAPSN = TRUE ;
gSettings . GenerateAPLF = TRUE ;
gSettings . GeneratePluginType = TRUE ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyFalse ( Prop2 ) ) {
2019-09-03 11:58:42 +02:00
gSettings . GeneratePStates = FALSE ;
gSettings . GenerateCStates = FALSE ;
gSettings . GenerateAPSN = FALSE ;
gSettings . GenerateAPLF = FALSE ;
gSettings . GeneratePluginType = FALSE ;
} else if ( Prop2 - > type = = kTagTypeDict ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " PStates " ) ;
2020-05-11 08:30:45 +02:00
gSettings . GeneratePStates = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
gSettings . GenerateAPSN = gSettings . GeneratePStates ;
gSettings . GenerateAPLF = gSettings . GeneratePStates ;
gSettings . GeneratePluginType = gSettings . GeneratePStates ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " CStates " ) ;
2020-05-11 08:30:45 +02:00
gSettings . GenerateCStates = IsPropertyTrue ( Prop ) ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " APSN " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-05-11 08:30:45 +02:00
gSettings . GenerateAPSN = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " APLF " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-05-11 08:30:45 +02:00
gSettings . GenerateAPLF = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Prop2 , " PluginType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-05-11 08:30:45 +02:00
gSettings . GeneratePluginType = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " DropOem " ) ;
2020-05-11 08:30:45 +02:00
gSettings . DropSSDT = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " NoOemTableId " ) ; // to disable OEM table ID on ACPI/orgin/SSDT file names
2020-05-11 08:30:45 +02:00
gSettings . NoOemTableId = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " NoDynamicExtract " ) ; // to disable extracting child SSDTs
2020-05-11 08:30:45 +02:00
gSettings . NoDynamicExtract = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " UseSystemIO " ) ;
2020-05-11 08:30:45 +02:00
gSettings . EnableISS = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " EnableC7 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC7 = IsPropertyTrue ( Prop ) ;
2020-04-23 18:05:21 +02:00
DBG ( " EnableC7: %s \n " , gSettings . EnableC7 ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " EnableC6 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC6 = IsPropertyTrue ( Prop ) ;
2020-04-23 18:05:21 +02:00
DBG ( " EnableC6: %s \n " , gSettings . EnableC6 ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " EnableC4 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC4 = IsPropertyTrue ( Prop ) ;
2020-04-23 18:05:21 +02:00
DBG ( " EnableC4: %s \n " , gSettings . EnableC4 ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " EnableC2 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC2 = IsPropertyTrue ( Prop ) ;
2020-04-23 18:05:21 +02:00
DBG ( " EnableC2: %s \n " , gSettings . EnableC2 ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " C3Latency " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . C3Latency = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . C3Latency ) ;
2020-04-23 18:05:21 +02:00
DBG ( " C3Latency: %d \n " , gSettings . C3Latency ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " PLimitDict " ) ;
gSettings . PLimitDict = ( UINT8 ) GetPropertyInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " UnderVoltStep " ) ;
gSettings . UnderVoltStep = ( UINT8 ) GetPropertyInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " DoubleFirstState " ) ;
2020-05-11 08:30:45 +02:00
gSettings . DoubleFirstState = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " MinMultiplier " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . MinMultiplier = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . MinMultiplier ) ;
2020-04-23 18:05:21 +02:00
DBG ( " MinMultiplier: %d \n " , gSettings . MinMultiplier ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " MaxMultiplier " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . MaxMultiplier = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . MaxMultiplier ) ;
2020-04-23 18:05:21 +02:00
DBG ( " MaxMultiplier: %d \n " , gSettings . MaxMultiplier ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict2 , " PluginType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . PluginType = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . PluginType ) ;
2020-04-23 18:05:21 +02:00
DBG ( " PluginType: %d \n " , gSettings . PluginType ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-04-23 11:08:10 +02:00
// Prop = GetProperty(DictPointer, "DropMCFG");
2020-05-11 08:30:45 +02:00
// gSettings.DropMCFG = IsPropertyTrue(Prop);
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ResetAddress " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-04-23 11:08:10 +02:00
gSettings . ResetAddr = ( UINT32 ) GetPropertyInteger ( Prop , 0x64 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " ResetAddr: 0x%llX \n " , gSettings . ResetAddr ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . ResetAddr = = 0x64 ) {
gSettings . ResetVal = 0xFE ;
} else if ( gSettings . ResetAddr = = 0xCF9 ) {
gSettings . ResetVal = 0x06 ;
}
2020-04-23 18:05:21 +02:00
DBG ( " Calc ResetVal: 0x%hhX \n " , gSettings . ResetVal ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ResetValue " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-04-23 11:08:10 +02:00
gSettings . ResetVal = ( UINT8 ) GetPropertyInteger ( Prop , gSettings . ResetVal ) ;
2020-04-23 18:05:21 +02:00
DBG ( " ResetVal: 0x%hhX \n " , gSettings . ResetVal ) ;
2019-09-03 11:58:42 +02:00
}
//other known pair is 0x0CF9/0x06. What about 0x92/0x01 ?
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " HaltEnabler " ) ;
2020-05-11 08:30:45 +02:00
gSettings . SlpSmiEnable = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
//
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FixHeaders " ) ;
2020-05-11 08:30:45 +02:00
gSettings . FixHeaders = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FixMCFG " ) ;
2020-05-11 08:30:45 +02:00
gSettings . FixMCFG = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DisableASPM " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NoASPM = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " smartUPS " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-05-11 08:30:45 +02:00
gSettings . smartUPS = IsPropertyTrue ( Prop ) ;
2020-04-23 18:05:21 +02:00
DBG ( " smartUPS: present \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " PatchAPIC " ) ;
2020-05-11 08:30:45 +02:00
gSettings . PatchNMI = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SortedOrder " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
INTN i , Count = GetTagCount ( Prop ) ;
Prop2 = NULL ;
if ( Count > 0 ) {
gSettings . SortedACPICount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . SortedACPI = ( __typeof__ ( gSettings . SortedACPI ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( ! EFI_ERROR ( GetElement ( Prop , i , & Prop2 ) ) & &
2019-09-03 11:58:42 +02:00
( Prop2 ! = NULL ) & & ( Prop2 - > type = = kTagTypeString ) ) {
2020-04-23 11:08:10 +02:00
gSettings . SortedACPI [ gSettings . SortedACPICount + + ] = PoolPrint ( L " %a " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " AutoMerge " ) ;
2020-05-11 08:30:45 +02:00
gSettings . AutoMerge = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DisabledAML " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
INTN i , Count = GetTagCount ( Prop ) ;
Prop2 = NULL ;
if ( Count > 0 ) {
gSettings . DisabledAMLCount = 0 ;
2020-04-28 12:49:24 +02:00
gSettings . DisabledAML = ( __typeof__ ( gSettings . DisabledAML ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . DisabledAML ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
if ( ! EFI_ERROR ( GetElement ( Prop , i , & Prop2 ) ) & &
2019-09-03 11:58:42 +02:00
( Prop2 ! = NULL ) & &
( Prop2 - > type = = kTagTypeString )
) {
2020-04-23 11:08:10 +02:00
gSettings . DisabledAML [ gSettings . DisabledAMLCount + + ] = PoolPrint ( L " %a " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
Prop = GetProperty ( DictPointer , " RenameDevices " ) ;
if ( Prop & & Prop - > type = = kTagTypeDict ) {
INTN i , Count = GetTagCount ( Prop ) ;
if ( Count > 0 ) {
gSettings . DeviceRenameCount = 0 ;
2019-12-21 01:31:49 +01:00
gSettings . DeviceRename = ( __typeof__ ( gSettings . DeviceRename ) ) AllocateZeroPool ( Count * sizeof ( ACPI_NAME_LIST ) ) ;
2020-03-25 19:32:44 +01:00
DBG ( " Devices to rename %lld \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
Prop2 = NULL ;
if ( ! EFI_ERROR ( GetElement ( Prop , i , & Prop2 ) ) & &
( Prop2 ! = NULL ) & &
( Prop2 - > type = = kTagTypeKey ) ) {
ACPI_NAME_LIST * List = ParseACPIName ( Prop2 - > string ) ;
gSettings . DeviceRename [ gSettings . DeviceRenameCount ] . Next = List ;
while ( List ) {
2020-03-25 19:32:44 +01:00
DBG ( " %s: " , List - > Name ) ;
2019-09-03 11:58:42 +02:00
List = List - > Next ;
}
Prop2 = Prop2 - > tag ;
if ( Prop2 - > type = = kTagTypeString ) {
2019-12-21 01:31:49 +01:00
gSettings . DeviceRename [ gSettings . DeviceRenameCount + + ] . Name = ( __typeof__ ( gSettings . DeviceRename [ gSettings . DeviceRenameCount + + ] . Name ) ) AllocateCopyPool ( 5 , Prop2 - > string ) ;
2020-03-25 19:32:44 +01:00
DBG ( " ->will be renamed to %s \n " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
}
//*** SMBIOS ***//
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " SMBIOS " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
ParseSMBIOSSettings ( DictPointer ) ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Trust " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
if ( IsPropertyFalse ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . TrustSMBIOS = FALSE ;
2020-05-11 08:30:45 +02:00
} else if ( IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
gSettings . TrustSMBIOS = TRUE ;
}
}
2019-11-15 13:17:19 +01:00
Prop = GetProperty ( DictPointer , " MemoryRank " ) ;
2019-11-27 12:16:02 +01:00
gSettings . Attribute = ( INT8 ) GetPropertyInteger ( Prop , - 1 ) ; //1==Single Rank, 2 == Dual Rank, 0==undefined -1 == keep as is
2019-11-15 13:17:19 +01:00
2019-12-21 11:29:57 +01:00
// Delete the user memory when a new config is selected
INTN i = 0 ;
for ( i = 0 ; i < gRAM . UserInUse & & i < MAX_RAM_SLOTS ; i + + ) {
gRAM . User [ i ] . ModuleSize = 0 ;
gRAM . User [ i ] . InUse = 0 ;
}
gRAM . UserInUse = 0 ;
gRAM . UserChannels = 0 ;
gSettings . InjectMemoryTables = FALSE ;
2019-09-03 11:58:42 +02:00
// Inject memory tables into SMBIOS
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Memory " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
// Get memory table count
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " SlotCount " ) ;
gRAM . UserInUse = ( UINT8 ) GetPropertyInteger ( Prop2 , 0 ) ;
2019-09-03 11:58:42 +02:00
// Get memory channels
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " Channels " ) ;
gRAM . UserChannels = ( UINT8 ) GetPropertyInteger ( Prop2 , 0 ) ;
2019-09-03 11:58:42 +02:00
// Get memory tables
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop , " Modules " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
2020-02-20 15:28:24 +01:00
INTN Count = GetTagCount ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
Prop3 = NULL ;
for ( i = 0 ; i < Count ; i + + ) {
UINT8 Slot = MAX_RAM_SLOTS ;
RAM_SLOT_INFO * SlotPtr ;
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop2 , i , & Prop3 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop3 = = NULL ) {
break ;
}
// Get memory slot
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Slot " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 = = NULL ) {
continue ;
}
if ( Dict2 - > type = = kTagTypeString & & Dict2 - > string ) {
Slot = ( UINT8 ) AsciiStrDecimalToUintn ( Dict2 - > string ) ;
} else if ( Dict2 - > type = = kTagTypeInteger ) {
Slot = ( UINT8 ) ( UINTN ) Dict2 - > string ;
} else {
continue ;
}
if ( Slot > = MAX_RAM_SLOTS ) {
continue ;
}
SlotPtr = & gRAM . User [ Slot ] ;
// Get memory size
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Size " ) ;
SlotPtr - > ModuleSize = ( UINT32 ) GetPropertyInteger ( Dict2 , SlotPtr - > ModuleSize ) ;
2019-09-03 11:58:42 +02:00
// Get memory frequency
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Frequency " ) ;
SlotPtr - > Frequency = ( UINT32 ) GetPropertyInteger ( Dict2 , SlotPtr - > Frequency ) ;
2019-09-03 11:58:42 +02:00
// Get memory vendor
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Vendor " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeString & & Dict2 - > string ! = NULL ) {
2020-04-09 19:01:23 +02:00
SlotPtr - > Vendor = ( __typeof__ ( SlotPtr - > Vendor ) ) AllocateCopyPool ( AsciiStrSize ( Dict2 - > string ) , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory part number
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Part " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeString & & Dict2 - > string ! = NULL ) {
2020-04-09 19:01:23 +02:00
SlotPtr - > PartNo = ( __typeof__ ( SlotPtr - > PartNo ) ) AllocateCopyPool ( AsciiStrSize ( Dict2 - > string ) , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory serial number
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Serial " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeString & & Dict2 - > string ! = NULL ) {
2020-04-09 19:01:23 +02:00
SlotPtr - > SerialNo = ( __typeof__ ( SlotPtr - > SerialNo ) ) AllocateCopyPool ( AsciiStrSize ( Dict2 - > string ) , Dict2 - > string ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory type
SlotPtr - > Type = MemoryTypeDdr3 ;
2020-04-23 11:08:10 +02:00
Dict2 = GetProperty ( Prop3 , " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 & & Dict2 - > type = = kTagTypeString & & Dict2 - > string ! = NULL ) {
if ( AsciiStriCmp ( Dict2 - > string , " DDR2 " ) = = 0 ) {
SlotPtr - > Type = MemoryTypeDdr2 ;
} else if ( AsciiStriCmp ( Dict2 - > string , " DDR3 " ) = = 0 ) {
SlotPtr - > Type = MemoryTypeDdr3 ;
} else if ( AsciiStriCmp ( Dict2 - > string , " DDR4 " ) = = 0 ) {
SlotPtr - > Type = MemoryTypeDdr4 ;
} else if ( AsciiStriCmp ( Dict2 - > string , " DDR " ) = = 0 ) {
SlotPtr - > Type = MemoryTypeDdr ;
}
}
SlotPtr - > InUse = ( SlotPtr - > ModuleSize > 0 ) ;
if ( SlotPtr - > InUse ) {
if ( gRAM . UserInUse < = Slot ) {
gRAM . UserInUse = Slot + 1 ;
}
}
}
if ( gRAM . UserInUse > 0 ) {
gSettings . InjectMemoryTables = TRUE ;
}
}
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Slots " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
INTN DeviceN ;
2020-02-20 15:28:24 +01:00
INTN Count = GetTagCount ( Prop ) ;
2019-09-03 11:58:42 +02:00
Prop3 = NULL ;
2020-02-20 15:28:24 +01:00
for ( INTN Index = 0 ; Index < Count ; + + Index ) {
2020-05-11 08:30:45 +02:00
if ( EFI_ERROR ( GetElement ( Prop , Index , & Prop3 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
if ( Prop3 = = NULL ) {
break ;
}
if ( ! Index ) {
2020-04-23 18:05:21 +02:00
DBG ( " Slots->Devices: \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop3 , " Device " ) ;
2019-09-03 11:58:42 +02:00
DeviceN = - 1 ;
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
if ( AsciiStriCmp ( Prop2 - > string , " ATI " ) = = 0 ) {
DeviceN = 0 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " NVidia " ) = = 0 ) {
DeviceN = 1 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " IntelGFX " ) = = 0 ) {
DeviceN = 2 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " LAN " ) = = 0 ) {
DeviceN = 5 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " WIFI " ) = = 0 ) {
DeviceN = 6 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " Firewire " ) = = 0 ) {
DeviceN = 12 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " HDMI " ) = = 0 ) {
DeviceN = 4 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " USB " ) = = 0 ) {
DeviceN = 11 ;
} else if ( AsciiStriCmp ( Prop2 - > string , " NVME " ) = = 0 ) {
DeviceN = 13 ;
} else {
2020-04-23 18:05:21 +02:00
DBG ( " - add properties to unknown device %s, ignored \n " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
} else {
2020-04-23 18:05:21 +02:00
DBG ( " - no device property for slot \n " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
if ( DeviceN > = 0 ) {
SLOT_DEVICE * SlotDevice = & SlotDevices [ DeviceN ] ;
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop3 , " ID " ) ;
SlotDevice - > SlotID = ( UINT8 ) GetPropertyInteger ( Prop2 , DeviceN ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotType = SlotTypePci ;
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop3 , " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
switch ( ( UINT8 ) GetPropertyInteger ( Prop2 , 0 ) ) {
case 0 :
SlotDevice - > SlotType = SlotTypePci ;
break ;
case 1 :
SlotDevice - > SlotType = SlotTypePciExpressX1 ;
break ;
case 2 :
SlotDevice - > SlotType = SlotTypePciExpressX2 ;
break ;
case 4 :
SlotDevice - > SlotType = SlotTypePciExpressX4 ;
break ;
case 8 :
SlotDevice - > SlotType = SlotTypePciExpressX8 ;
break ;
case 16 :
SlotDevice - > SlotType = SlotTypePciExpressX16 ;
break ;
default :
SlotDevice - > SlotType = SlotTypePciExpress ;
break ;
}
}
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Prop3 , " Name " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 & & ( Prop2 - > type = = kTagTypeString ) & & Prop2 - > string ) {
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " %s " , Prop2 - > string ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-10 14:35:25 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " PCI Slot %lld " , DeviceN ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " - %s \n " , SlotDevice - > SlotName ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
//CPU
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " CPU " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " QPI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . QPI = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . QPI ) ;
2020-04-23 18:05:21 +02:00
DBG ( " QPI: %dMHz \n " , gSettings . QPI ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " FrequencyMHz " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . CpuFreqMHz = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . CpuFreqMHz ) ;
2020-04-23 18:05:21 +02:00
DBG ( " CpuFreq: %dMHz \n " , gSettings . CpuFreqMHz ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Type " ) ;
2019-09-03 11:58:42 +02:00
gSettings . CpuType = GetAdvancedCpuType ( ) ;
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . CpuType = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . CpuType ) ;
2020-04-23 18:05:21 +02:00
DBG ( " CpuType: %hX \n " , gSettings . CpuType ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " QEMU " ) ;
2020-05-11 08:30:45 +02:00
gSettings . QEMU = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . QEMU ) {
2020-04-23 18:05:21 +02:00
DBG ( " QEMU: true \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " UseARTFrequency " ) ;
2020-05-11 08:30:45 +02:00
gSettings . UseARTFreq = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
gSettings . UserChange = FALSE ;
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BusSpeedkHz " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . BusSpeed = ( UINT32 ) GetPropertyInteger ( Prop , gSettings . BusSpeed ) ;
2020-04-23 18:05:21 +02:00
DBG ( " BusSpeed: %dkHz \n " , gSettings . BusSpeed ) ;
2019-09-03 11:58:42 +02:00
gSettings . UserChange = TRUE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " C6 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC6 = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " C4 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC4 = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " C2 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-05-11 08:30:45 +02:00
gSettings . EnableC2 = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
//Usually it is 0x03e9, but if you want Turbo, you may set 0x00FA
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Latency " ) ;
gSettings . C3Latency = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . C3Latency ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " SavingMode " ) ;
gSettings . SavingMode = ( UINT8 ) GetPropertyInteger ( Prop , 0xFF ) ; //the default value means not set
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " HWPEnable " ) ;
2020-05-11 08:30:45 +02:00
if ( Prop & & IsPropertyTrue ( Prop ) & & ( gCPUStructure . Model > = CPU_MODEL_SKYLAKE_U ) ) {
2019-09-03 11:58:42 +02:00
gSettings . HWP = TRUE ;
AsmWriteMsr64 ( MSR_IA32_PM_ENABLE , 1 ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " HWPValue " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop & & gSettings . HWP ) {
gSettings . HWPValue = ( UINT32 ) GetPropertyInteger ( Prop , 0 ) ;
AsmWriteMsr64 ( MSR_IA32_HWP_REQUEST , gSettings . HWPValue ) ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " TDP " ) ;
gSettings . TDP = ( UINT8 ) GetPropertyInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " TurboDisable " ) ;
2020-05-11 08:30:45 +02:00
if ( Prop & & IsPropertyTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
UINT64 msr = AsmReadMsr64 ( MSR_IA32_MISC_ENABLE ) ;
gSettings . Turbo = 0 ;
msr & = ~ ( 1ULL < < 38 ) ;
AsmWriteMsr64 ( MSR_IA32_MISC_ENABLE , msr ) ;
}
}
// RtVariables
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " RtVariables " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
// ROM: <data>bin data</data> or <string>base 64 encoded bin data</string>
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " ROM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( AsciiStriCmp ( Prop - > string , " UseMacAddr0 " ) = = 0 ) {
gSettings . RtROM = & gLanMac [ 0 ] [ 0 ] ;
gSettings . RtROMLen = 6 ;
} else if ( AsciiStriCmp ( Prop - > string , " UseMacAddr1 " ) = = 0 ) {
gSettings . RtROM = & gLanMac [ 1 ] [ 0 ] ;
gSettings . RtROMLen = 6 ;
} else {
UINTN ROMLength = 0 ;
gSettings . RtROM = GetDataSetting ( DictPointer , " ROM " , & ROMLength ) ;
gSettings . RtROMLen = ROMLength ;
}
if ( gSettings . RtROM = = NULL | | gSettings . RtROMLen = = 0 ) {
gSettings . RtROM = NULL ;
gSettings . RtROMLen = 0 ;
}
}
// MLB: <string>some value</string>
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " MLB " ) ;
2020-04-28 12:49:24 +02:00
if ( Prop ! = NULL & & AsciiStrLen ( Prop - > string ) > 0 ) {
2020-04-27 17:16:43 +02:00
gSettings . RtMLB = ( __typeof__ ( gSettings . RtMLB ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
// CsrActiveConfig
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CsrActiveConfig " ) ;
gSettings . CsrActiveConfig = ( UINT32 ) GetPropertyInteger ( Prop , 0x267 ) ; //the value 0xFFFF means not set
2019-09-03 11:58:42 +02:00
//BooterConfig
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BooterConfig " ) ;
gSettings . BooterConfig = ( UINT16 ) GetPropertyInteger ( Prop , 0 ) ; //the value 0 means not set
2019-09-03 11:58:42 +02:00
//let it be string like "log=0"
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BooterCfg " ) ;
2020-04-28 12:49:24 +02:00
if ( Prop ! = NULL & & AsciiStrLen ( Prop - > string ) > 0 ) {
2019-09-03 11:58:42 +02:00
AsciiStrCpyS ( gSettings . BooterCfgStr , 64 , Prop - > string ) ;
}
2019-09-12 12:37:33 +02:00
//Block external variables
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Block " ) ;
2019-09-12 08:03:34 +02:00
if ( Prop ! = NULL ) {
INTN i , Count = GetTagCount ( Prop ) ;
2019-09-12 12:37:33 +02:00
CHAR16 UStr [ 64 ] ;
RtVariablesNum = 0 ;
2019-12-21 01:31:49 +01:00
RtVariables = ( __typeof__ ( RtVariables ) ) AllocateZeroPool ( Count * sizeof ( RT_VARIABLES ) ) ;
2019-09-12 08:03:34 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-05-11 08:30:45 +02:00
Status = GetElement ( Prop , i , & Dict ) ;
2019-09-12 08:03:34 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-04-23 11:08:10 +02:00
Prop2 = GetProperty ( Dict , " Comment " ) ;
2019-10-08 22:57:18 +02:00
if ( Prop2 & & Prop2 - > string ) {
2020-03-25 19:32:44 +01:00
DBG ( " %s \n " , Prop2 - > string ) ;
2019-09-12 12:37:33 +02:00
}
Prop2 = GetProperty ( Dict , " Disabled " ) ;
if ( IsPropertyFalse ( Prop2 ) ) {
continue ;
}
Prop2 = GetProperty ( Dict , " Guid " ) ;
if ( Prop2 ! = NULL & & AsciiStrLen ( Prop2 - > string ) > 0 ) {
ZeroMem ( UStr , 64 * sizeof ( CHAR16 ) ) ;
if ( IsValidGuidAsciiString ( Prop2 - > string ) ) {
AsciiStrToUnicodeStrS ( Prop2 - > string , ( CHAR16 * ) & UStr [ 0 ] , 64 ) ;
StrToGuidLE ( ( CHAR16 * ) & UStr [ 0 ] , & RtVariables [ RtVariablesNum ] . VarGuid ) ;
}
else {
2020-03-25 19:32:44 +01:00
DBG ( " Error: invalid GUID for RT var '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > string ) ;
2019-09-12 12:37:33 +02:00
}
}
Prop2 = GetProperty ( Dict , " Name " ) ;
RtVariables [ RtVariablesNum ] . Name = NULL ;
if ( Prop2 ! = NULL & & AsciiStrLen ( Prop2 - > string ) > 0 ) {
AsciiStrToUnicodeStrS ( Prop2 - > string , ( CHAR16 * ) & UStr [ 0 ] , 64 ) ;
2019-12-21 01:31:49 +01:00
// RtVariables[RtVariablesNum].Name = (__typeof__(RtVariables[RtVariablesNum].Name))AllocateCopyPool(128, UStr);
2019-09-12 12:37:33 +02:00
StrCpyS ( RtVariables [ RtVariablesNum ] . Name , 64 , UStr ) ;
}
RtVariablesNum + + ;
2019-09-12 08:03:34 +02:00
}
}
}
2019-09-03 11:58:42 +02:00
}
if ( gSettings . RtROM = = NULL ) {
gSettings . RtROM = ( UINT8 * ) & gSettings . SmUUID . Data4 [ 2 ] ;
gSettings . RtROMLen = 6 ;
}
if ( gSettings . RtMLB = = NULL ) {
gSettings . RtMLB = & gSettings . BoardSerialNumber [ 0 ] ;
}
// if CustomUUID and InjectSystemID are not specified
// then use InjectSystemID=TRUE and SMBIOS UUID
// to get Chameleon's default behaviour (to make user's life easier)
2020-05-01 18:26:28 +02:00
CopyMem ( ( VOID * ) & gUuid , ( VOID * ) & gSettings . SmUUID , sizeof ( EFI_GUID ) ) ;
2019-09-03 11:58:42 +02:00
gSettings . InjectSystemID = TRUE ;
// SystemParameters again - values that can depend on previous params
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " SystemParameters " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
//BacklightLevel
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " BacklightLevel " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-04-23 11:08:10 +02:00
gSettings . BacklightLevel = ( UINT16 ) GetPropertyInteger ( Prop , gSettings . BacklightLevel ) ;
2019-09-03 11:58:42 +02:00
gSettings . BacklightLevelConfig = TRUE ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " CustomUUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
if ( IsValidGuidAsciiString ( Prop - > string ) ) {
AsciiStrToUnicodeStrS ( Prop - > string , gSettings . CustomUuid , 40 ) ;
2020-03-25 19:32:44 +01:00
DBG ( " Converted CustomUUID %ls \n " , gSettings . CustomUuid ) ;
2019-09-03 11:58:42 +02:00
Status = StrToGuidLE ( gSettings . CustomUuid , & gUuid ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
IsValidCustomUUID = TRUE ;
// if CustomUUID specified, then default for InjectSystemID=FALSE
// to stay compatibile with previous Clover behaviour
gSettings . InjectSystemID = FALSE ;
// DBG("The UUID is valid\n");
}
}
if ( ! IsValidCustomUUID ) {
2020-04-23 18:05:21 +02:00
DBG ( " Error: invalid CustomUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
//else gUuid value from SMBIOS
2020-03-25 19:32:44 +01:00
// DBG("Finally use %s\n", strguid(&gUuid));
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " InjectSystemID " ) ;
2020-05-11 08:30:45 +02:00
gSettings . InjectSystemID = gSettings . InjectSystemID ? ! IsPropertyFalse ( Prop ) : IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " NvidiaWeb " ) ;
2020-05-11 08:30:45 +02:00
gSettings . NvidiaWeb = IsPropertyTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " BootGraphics " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " DefaultBackgroundColor " ) ;
gSettings . DefaultBackgroundColor = ( UINT32 ) GetPropertyInteger ( Prop , 0x80000000 ) ; //the value 0x80000000 means not set
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " UIScale " ) ;
gSettings . UIScale = ( UINT32 ) GetPropertyInteger ( Prop , 0x80000000 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " EFILoginHiDPI " ) ;
gSettings . EFILoginHiDPI = ( UINT32 ) GetPropertyInteger ( Prop , 0x80000000 ) ;
2019-09-03 11:58:42 +02:00
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " flagstate " ) ;
* ( UINT32 * ) & gSettings . flagstate [ 0 ] = ( UINT32 ) GetPropertyInteger ( Prop , 0x80000000 ) ;
2019-09-03 11:58:42 +02:00
}
/*
//Example
< key > RMde < / key >
< array >
< string > char < / string >
< data >
QQ = =
< / data >
< / array >
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " SMCKeys " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) { //sss
TagPtr Key , ValArray ;
for ( Key = DictPointer - > tag ; Key ! = NULL ; Key = Key - > tagNext ) {
ValArray = Prop - > tag ;
if ( Key - > type ! = kTagTypeKey | | ValArray = = NULL ) {
2020-04-23 18:05:21 +02:00
DBG ( " ERROR: Tag is not <key>, type = %d \n " , Key - > type ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
//....
}
}
*/
/*
{
EFI_GUID AppleGuid ;
2020-05-01 18:26:28 +02:00
CopyMem ( ( VOID * ) & AppleGuid , ( VOID * ) & gUuid , sizeof ( EFI_GUID ) ) ;
2019-09-03 11:58:42 +02:00
AppleGuid . Data1 = SwapBytes32 ( AppleGuid . Data1 ) ;
AppleGuid . Data2 = SwapBytes16 ( AppleGuid . Data2 ) ;
AppleGuid . Data3 = SwapBytes16 ( AppleGuid . Data3 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Platform Uuid: %s, InjectSystemID: %s \n " , strguid ( & AppleGuid ) , gSettings . InjectSystemID ? " Yes " : " No " ) ;
2019-09-03 11:58:42 +02:00
}
*/
if ( gBootChanged ) {
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " KernelAndKextPatches " ) ;
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
DBG ( " refill kernel patches bcoz gBootChanged \n " ) ;
FillinKextPatches ( ( KERNEL_AND_KEXT_PATCHES * ) ( ( ( UINTN ) & gSettings ) + OFFSET_OF ( SETTINGS_DATA , KernelAndKextPatches ) ) , DictPointer ) ;
}
} else {
2020-03-25 19:32:44 +01:00
//DBG("\n ConfigName: %ls n", gSettings.ConfigName);
2019-09-03 11:58:42 +02:00
}
2020-04-15 18:30:39 +02:00
if ( gThemeChanged ) {
if ( GlobalConfig . Theme ) {
FreePool ( GlobalConfig . Theme ) ;
}
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " GUI " ) ;
2020-03-27 17:50:17 +01:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " Theme " ) ;
2020-03-27 17:50:17 +01:00
if ( ( Prop ! = NULL ) & & ( Prop - > type = = kTagTypeString ) & & Prop - > string ) {
2020-04-15 18:30:39 +02:00
// GlobalConfig.Theme = XStringW().takeValueFrom(Prop->string).forgetDataWithoutFreeing();
GlobalConfig . Theme = PoolPrint ( L " %a " , Prop - > string ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Theme from new config: %ls \n " , GlobalConfig . Theme ) ;
2020-03-27 17:50:17 +01:00
}
}
}
2019-09-03 11:58:42 +02:00
SaveSettings ( ) ;
}
2020-04-23 18:05:21 +02:00
//DBG("config.plist read and return %s\n", strerror(Status));
2019-09-03 11:58:42 +02:00
return EFI_SUCCESS ;
}
2020-02-18 19:49:54 +01:00
/*
static CONST CHAR8 * SearchString (
2020-02-17 21:41:09 +01:00
IN CONST CHAR8 * Source ,
2019-09-03 11:58:42 +02:00
IN UINT64 SourceSize ,
2020-02-17 21:41:09 +01:00
IN CONST CHAR8 * Search ,
2019-09-03 11:58:42 +02:00
IN UINTN SearchSize
)
{
2020-02-17 21:41:09 +01:00
CONST CHAR8 * End = Source + SourceSize ;
2019-09-03 11:58:42 +02:00
while ( Source < End ) {
if ( CompareMem ( Source , Search , SearchSize ) = = 0 ) {
return Source ;
} else {
Source + + ;
}
}
return NULL ;
}
2020-02-18 19:49:54 +01:00
*/
2019-09-03 11:58:42 +02:00
CHAR8 * GetOSVersion ( IN LOADER_ENTRY * Entry )
{
CHAR8 * OSVersion = NULL ;
EFI_STATUS Status = EFI_NOT_FOUND ;
CHAR8 * PlistBuffer = NULL ;
UINTN PlistLen ;
TagPtr DictPointer = NULL ;
TagPtr Dict = NULL ;
TagPtr Prop = NULL ;
UINTN i = 0 ;
UINTN j = 0 ;
if ( ! Entry | | ! Entry - > Volume ) {
return OSVersion ;
}
if ( OSTYPE_IS_OSX ( Entry - > LoaderType ) ) {
// Detect exact version for Mac OS X Regular/Server
i = 0 ;
while ( SystemPlists [ i ] ! = NULL & & ! FileExists ( Entry - > Volume - > RootDir , SystemPlists [ i ] ) ) {
i + + ;
}
if ( SystemPlists [ i ] ! = NULL ) { // found macOS System
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , SystemPlists [ i ] , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductBuildVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
if ( OSTYPE_IS_OSX_INSTALLER ( Entry - > LoaderType ) ) {
// Detect exact version for 2nd stage Installer (thanks to dmazar for this idea)
// This should work for most installer cases. Rest cases will be read from boot.efi before booting.
// Reworked by Sherlocks. 2018.04.12
// 1st stage - 1
// Check for plist - createinstallmedia/BaseSystem/InstallDVD/InstallESD
2020-02-17 21:41:09 +01:00
CONST CHAR16 * InstallerPlist = L " \\ .IABootFilesSystemVersion.plist " ; // 10.9 - 10.13.3
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) & & FileExists ( Entry - > Volume - > RootDir , L " \\ System \\ Library \\ CoreServices \\ boot.efi " ) & &
( ( FileExists ( Entry - > Volume - > RootDir , L " \\ BaseSystem.dmg " ) & & FileExists ( Entry - > Volume - > RootDir , L " \\ mach_kernel " ) ) | | // 10.7/10.8
FileExists ( Entry - > Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ Mac OS X Installer.app " ) | | // 10.6/10.7
FileExists ( Entry - > Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ OS X Installer.app " ) | | // 10.8 - 10.11
FileExists ( Entry - > Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ macOS Installer.app " ) | | // 10.12+
FileExists ( Entry - > Volume - > RootDir , L " \\ .IAPhysicalMedia " ) ) ) { // 10.13.4+
InstallerPlist = L " \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " ;
}
if ( FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , InstallerPlist , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductBuildVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
// 1st stage - 2
// Check for plist - createinstallmedia/NetInstall
if ( OSVersion = = NULL ) {
2020-07-13 09:12:18 +02:00
InstallerPlist = L " \\ .IABootFiles \\ com.apple.Boot.plist " ; // 10.9 - ...
2019-09-03 11:58:42 +02:00
if ( FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , InstallerPlist , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " Kernel Flags " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-07-13 09:12:18 +02:00
if ( AsciiStrStr ( Prop - > string , " Install%20macOS%20BigSur " ) | | AsciiStrStr ( Prop - > string , " Install%20macOS%2011.0 " ) ) {
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 5 , " 11.0 " ) ;
} else if ( AsciiStrStr ( Prop - > string , " Install%20macOS%2010.16 " ) ) {
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.16 " ) ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20macOS%20Catalina " ) | | AsciiStrStr ( Prop - > string , " Install%20macOS%2010.15 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.15 " ) ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20macOS%20Mojave " ) | | AsciiStrStr ( Prop - > string , " Install%20macOS%2010.14 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.14 " ) ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20macOS%20High%20Sierra " ) | | AsciiStrStr ( Prop - > string , " Install%20macOS%2010.13 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.13 " ) ;
2020-04-17 15:14:24 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20macOS%20Sierra " ) | | AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%2010.12 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.12 " ) ;
2020-04-17 15:14:24 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%20El%20Capitan " ) | | AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%2010.11 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.11 " ) ;
2020-04-17 15:14:24 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%20Yosemite " ) | | AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%2010.10 " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 6 , " 10.10 " ) ;
2020-07-13 09:12:18 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%20Mavericks.app " ) ) {
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 5 , " 10.9 " ) ;
2020-04-17 15:14:24 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20OS%20hhX%20Mountain%20Lion " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 5 , " 10.8 " ) ;
2020-04-17 15:14:24 +02:00
} else if ( AsciiStrStr ( Prop - > string , " Install%20Mac%20OS%20hhX%20Lion " ) ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 5 , " 10.7 " ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// 2nd stage - 1
// Check for plist - AppStore/createinstallmedia/startosinstall/Fusion Drive
if ( OSVersion = = NULL ) {
InstallerPlist = L " \\ macOS Install Data \\ Locked Files \\ Boot Files \\ SystemVersion.plist " ; // 10.12.4+
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
InstallerPlist = L " \\ macOS Install Data \\ InstallInfo.plist " ; // 10.12+
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
InstallerPlist = L " \\ com.apple.boot.R \\ SystemVersion.plist " ; // 10.12+
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
InstallerPlist = L " \\ com.apple.boot.P \\ SystemVersion.plist " ; // 10.12+
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
InstallerPlist = L " \\ com.apple.boot.S \\ SystemVersion.plist " ; // 10.12+
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) & &
( FileExists ( Entry - > Volume - > RootDir , L " \\ com.apple.boot.R \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) | |
FileExists ( Entry - > Volume - > RootDir , L " \\ com.apple.boot.P \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) | |
FileExists ( Entry - > Volume - > RootDir , L " \\ com.apple.boot.S \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) ) ) {
InstallerPlist = L " \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " ; // 10.11
}
}
}
}
}
if ( FileExists ( Entry - > Volume - > RootDir , InstallerPlist ) ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , InstallerPlist , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductBuildVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
// In InstallInfo.plist, there is no a version key only when updating from AppStore in 10.13+
// If use the startosinstall in 10.13+, this version key exists in InstallInfo.plist
2020-04-23 11:08:10 +02:00
DictPointer = GetProperty ( Dict , " System Image Info " ) ; // 10.12+
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( DictPointer , " version " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// 2nd stage - 2
// Check for ia.log - InstallESD/createinstallmedia/startosinstall
// Implemented by Sherlocks
if ( OSVersion = = NULL ) {
2020-02-17 21:41:09 +01:00
CONST CHAR8 * s , * fileBuffer , * targetString ;
2019-12-21 01:31:49 +01:00
CHAR8 * Res5 = ( __typeof__ ( Res5 ) ) AllocateZeroPool ( 5 ) ;
CHAR8 * Res6 = ( __typeof__ ( Res6 ) ) AllocateZeroPool ( 6 ) ;
CHAR8 * Res7 = ( __typeof__ ( Res7 ) ) AllocateZeroPool ( 7 ) ;
CHAR8 * Res8 = ( __typeof__ ( Res8 ) ) AllocateZeroPool ( 8 ) ;
2019-09-03 11:58:42 +02:00
UINTN fileLen = 0 ;
2020-02-17 21:41:09 +01:00
CONST CHAR16 * InstallerLog = L " \\ Mac OS X Install Data \\ ia.log " ; // 10.7
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerLog ) ) {
InstallerLog = L " \\ OS X Install Data \\ ia.log " ; // 10.8 - 10.11
if ( ! FileExists ( Entry - > Volume - > RootDir , InstallerLog ) ) {
InstallerLog = L " \\ macOS Install Data \\ ia.log " ; // 10.12+
}
}
if ( FileExists ( Entry - > Volume - > RootDir , InstallerLog ) ) {
Status = egLoadFile ( Entry - > Volume - > RootDir , InstallerLog , ( UINT8 * * ) & fileBuffer , & fileLen ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
targetString = ( CHAR8 * ) AllocateZeroPool ( fileLen + 1 ) ;
CopyMem ( ( VOID * ) targetString , ( VOID * ) fileBuffer , fileLen ) ;
2020-02-18 19:49:54 +01:00
// s = SearchString(targetString, fileLen, "Running OS Build: Mac OS X ", 27);
s = AsciiStrStr ( targetString , " Running OS Build: Mac OS X " ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 31 ] = = ' ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res5 , 5 , " %c%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] ) ;
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res5 ) , Res5 ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 38 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res6 , 6 , " %c%c%c%c%c \n " , s [ 33 ] , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res6 ) , Res6 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 39 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res7 , 7 , " %c%c%c%c%c%c \n " , s [ 33 ] , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res7 ) , Res7 ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 31 ] = = ' . ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res7 , 7 , " %c%c.%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 32 ] ) ;
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res7 ) , Res7 ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 40 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res6 , 6 , " %c%c%c%c%c \n " , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res6 ) , Res6 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 41 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res7 , 7 , " %c%c%c%c%c%c \n " , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res7 ) , Res7 ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 32 ] = = ' ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res6 , 6 , " %c%c.%c%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 31 ] ) ;
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res6 ) , Res6 ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 39 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res6 , 6 , " %c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res6 ) , Res6 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 40 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res7 , 7 , " %c%c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res7 ) , Res7 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 41 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res8 , 8 , " %c%c%c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res8 ) , Res8 ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 32 ] = = ' . ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res8 , 8 , " %c%c.%c%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 31 ] , s [ 33 ] ) ;
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res8 ) , Res8 ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 41 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res6 , 6 , " %c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res6 ) , Res6 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 42 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res7 , 7 , " %c%c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] , s [ 41 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res7 ) , Res7 ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 43 ] = = ' ) ' ) {
2020-04-10 14:26:35 +02:00
snprintf ( Res8 , 8 , " %c%c%c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] , s [ 41 ] , s [ 42 ] ) ;
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Res8 ) , Res8 ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-02-21 22:22:30 +01:00
FreePool ( fileBuffer ) ;
FreePool ( targetString ) ;
2019-09-03 11:58:42 +02:00
}
}
}
// 2nd stage - 3
// Check for plist - Preboot of APFS
if ( OSVersion = = NULL & & APFSSupport = = TRUE ) {
i = 0 ;
while ( InstallPlists [ i ] ! = NULL & & ! FileExists ( Entry - > Volume - > RootDir , InstallPlists [ i ] ) ) {
i + + ;
}
if ( InstallPlists [ i ] ! = NULL ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , InstallPlists [ i ] , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductBuildVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > LoaderType ) ) {
j = 0 ;
while ( RecoveryPlists [ j ] ! = NULL & & ! FileExists ( Entry - > Volume - > RootDir , RecoveryPlists [ j ] ) ) {
j + + ;
}
// Detect exact version for OS X Recovery
if ( RecoveryPlists [ j ] ! = NULL ) {
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Entry - > Volume - > RootDir , RecoveryPlists [ j ] , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " ProductBuildVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL & & Prop - > string ! = NULL & & Prop - > string [ 0 ] ! = ' \0 ' ) {
2020-04-27 17:16:43 +02:00
Entry - > BuildVersion = ( __typeof__ ( Entry - > BuildVersion ) ) AllocateCopyPool ( AsciiStrSize ( Prop - > string ) , Prop - > string ) ;
2019-09-03 11:58:42 +02:00
}
}
} else if ( FileExists ( Entry - > Volume - > RootDir , L " \\ com.apple.recovery.boot \\ boot.efi " ) ) {
// Special case - com.apple.recovery.boot/boot.efi exists but SystemVersion.plist doesn't --> 10.9 recovery
2020-04-27 17:16:43 +02:00
OSVersion = ( __typeof__ ( OSVersion ) ) AllocateCopyPool ( 5 , " 10.9 " ) ;
2019-09-03 11:58:42 +02:00
}
}
if ( PlistBuffer ! = NULL ) {
2020-04-23 11:08:10 +02:00
FreePool ( PlistBuffer ) ;
2019-09-03 11:58:42 +02:00
}
return OSVersion ;
}
2020-04-27 11:50:49 +02:00
//constexpr XStringW iconMac = L"mac"_XSW;
CONST XStringW
GetOSIconName (
2020-02-17 21:41:09 +01:00
IN CONST CHAR8 * OSVersion
2019-09-03 11:58:42 +02:00
)
{
2020-04-27 11:50:49 +02:00
XStringW OSIconName ;
2019-09-03 11:58:42 +02:00
if ( OSVersion = = NULL ) {
2020-04-27 11:50:49 +02:00
OSIconName = L " mac " _XSW ;
2020-07-13 08:59:31 +02:00
} else if ( ( AsciiStrStr ( OSVersion , " 10.16 " ) ! = 0 ) | |
( AsciiStrStr ( OSVersion , " 11.0 " ) ! = 0 ) ) {
2020-06-22 20:47:45 +02:00
// Big Sur
OSIconName = L " bigsur,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.15 " ) ! = 0 ) {
// Catalina
2020-04-27 11:50:49 +02:00
OSIconName = L " cata,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.14 " ) ! = 0 ) {
// Mojave
2020-04-27 11:50:49 +02:00
OSIconName = L " moja,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.13 " ) ! = 0 ) {
// High Sierra
2020-04-27 11:50:49 +02:00
OSIconName = L " hsierra,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.12 " ) ! = 0 ) {
// Sierra
2020-04-27 11:50:49 +02:00
OSIconName = L " sierra,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.11 " ) ! = 0 ) {
// El Capitan
2020-04-27 11:50:49 +02:00
OSIconName = L " cap,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.10 " ) ! = 0 ) {
// Yosemite
2020-04-27 11:50:49 +02:00
OSIconName = L " yos,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.9 " ) ! = 0 ) {
// Mavericks
2020-04-27 11:50:49 +02:00
OSIconName = L " mav,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.8 " ) ! = 0 ) {
// Mountain Lion
2020-04-27 11:50:49 +02:00
OSIconName = L " cougar,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.7 " ) ! = 0 ) {
// Lion
2020-04-27 11:50:49 +02:00
OSIconName = L " lion,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.6 " ) ! = 0 ) {
// Snow Leopard
2020-04-27 11:50:49 +02:00
OSIconName = L " snow,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.5 " ) ! = 0 ) {
// Leopard
2020-04-27 11:50:49 +02:00
OSIconName = L " leo,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else if ( AsciiStrStr ( OSVersion , " 10.4 " ) ! = 0 ) {
// Tiger
2020-04-27 11:50:49 +02:00
OSIconName = L " tiger,mac " _XSW ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-27 11:50:49 +02:00
OSIconName = L " mac " _XSW ;
2019-09-03 11:58:42 +02:00
}
return OSIconName ;
}
//Get the UUID of the AppleRaid or CoreStorage volume from the boot helper partition
EFI_STATUS
GetRootUUID ( IN REFIT_VOLUME * Volume )
{
EFI_STATUS Status ;
CHAR8 * PlistBuffer ;
UINTN PlistLen ;
TagPtr Dict ;
TagPtr Prop ;
CHAR16 Uuid [ 40 ] ;
2020-02-17 21:41:09 +01:00
CONST CHAR16 * SystemPlistR ;
CONST CHAR16 * SystemPlistP ;
CONST CHAR16 * SystemPlistS ;
2019-09-03 11:58:42 +02:00
BOOLEAN HasRock ;
BOOLEAN HasPaper ;
BOOLEAN HasScissors ;
Status = EFI_NOT_FOUND ;
if ( Volume = = NULL ) {
return EFI_NOT_FOUND ;
}
SystemPlistR = L " \\ com.apple.boot.R \\ Library \\ Preferences \\ SystemConfiguration \\ com.apple.Boot.plist " ;
if ( FileExists ( Volume - > RootDir , SystemPlistR ) ) {
HasRock = FileExists ( Volume - > RootDir , SystemPlistR ) ;
} else {
SystemPlistR = L " \\ com.apple.boot.R \\ com.apple.Boot.plist " ;
HasRock = FileExists ( Volume - > RootDir , SystemPlistR ) ;
}
SystemPlistP = L " \\ com.apple.boot.P \\ Library \\ Preferences \\ SystemConfiguration \\ com.apple.Boot.plist " ;
if ( FileExists ( Volume - > RootDir , SystemPlistP ) ) {
HasPaper = FileExists ( Volume - > RootDir , SystemPlistP ) ;
} else {
SystemPlistP = L " \\ com.apple.boot.P \\ com.apple.Boot.plist " ;
HasPaper = FileExists ( Volume - > RootDir , SystemPlistP ) ;
}
SystemPlistS = L " \\ com.apple.boot.S \\ Library \\ Preferences \\ SystemConfiguration \\ com.apple.Boot.plist " ;
if ( FileExists ( Volume - > RootDir , SystemPlistS ) ) {
HasScissors = FileExists ( Volume - > RootDir , SystemPlistS ) ;
} else {
SystemPlistS = L " \\ com.apple.boot.S \\ com.apple.Boot.plist " ;
HasScissors = FileExists ( Volume - > RootDir , SystemPlistS ) ;
}
PlistBuffer = NULL ;
// Playing Rock, Paper, Scissors to chose which settings to load.
if ( HasRock & & HasPaper & & HasScissors ) {
// Rock wins when all three are around
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistR , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( HasRock & & HasPaper ) {
// Paper beats rock
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistP , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( HasRock & & HasScissors ) {
// Rock beats scissors
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistR , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( HasPaper & & HasScissors ) {
// Scissors beat paper
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistS , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( HasPaper ) {
// No match
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistP , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( HasScissors ) {
// No match
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistS , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
} else {
// Rock wins by default
2020-05-15 05:23:33 +02:00
Status = egLoadFile ( Volume - > RootDir , SystemPlistR , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
Dict = NULL ;
2020-05-15 05:23:33 +02:00
if ( ParseXML ( PlistBuffer , & Dict , 0 ) ! = EFI_SUCCESS ) {
2020-04-23 11:08:10 +02:00
FreePool ( PlistBuffer ) ;
2019-09-03 11:58:42 +02:00
return EFI_NOT_FOUND ;
}
2020-04-23 11:08:10 +02:00
Prop = GetProperty ( Dict , " Root UUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
AsciiStrToUnicodeStrS ( Prop - > string , Uuid , 40 ) ;
Status = StrToGuidLE ( Uuid , & Volume - > RootUUID ) ;
}
2020-04-23 11:08:10 +02:00
FreePool ( PlistBuffer ) ;
2019-09-03 11:58:42 +02:00
}
return Status ;
}
VOID
GetDevices ( )
{
EFI_STATUS Status ;
UINTN HandleCount = 0 ;
EFI_HANDLE * HandleArray = NULL ;
EFI_PCI_IO_PROTOCOL * PciIo ;
PCI_TYPE00 Pci ;
UINTN Index ;
UINTN Segment = 0 ;
UINTN Bus = 0 ;
UINTN Device = 0 ;
UINTN Function = 0 ;
UINTN i ;
UINT32 Bar0 ;
// UINT8 *Mmio = NULL;
radeon_card_info_t * info ;
SLOT_DEVICE * SlotDevice ;
NGFX = 0 ;
NHDA = 0 ;
AudioNum = 0 ;
//Arpt.Valid = FALSE; //global variables initialized by 0 - c-language
CHAR16 * GopDevicePathStr = NULL ;
CHAR16 * DevicePathStr = NULL ;
DbgHeader ( " GetDevices " ) ;
// Get GOP handle, in order to check to which GPU the monitor is currently connected
Status = gBS - > LocateHandleBuffer ( ByProtocol , & gEfiGraphicsOutputProtocolGuid , NULL , & HandleCount , & HandleArray ) ;
if ( ! EFI_ERROR ( Status ) ) {
GopDevicePathStr = DevicePathToStr ( DevicePathFromHandle ( HandleArray [ 0 ] ) ) ;
2020-03-25 19:32:44 +01:00
DBG ( " GOP found at: %ls \n " , GopDevicePathStr ) ;
2019-09-03 11:58:42 +02:00
}
// Scan PCI handles
Status = gBS - > LocateHandleBuffer (
ByProtocol ,
& gEfiPciIoProtocolGuid ,
NULL ,
& HandleCount ,
& HandleArray
) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
for ( Index = 0 ; Index < HandleCount ; + + Index ) {
Status = gBS - > HandleProtocol ( HandleArray [ Index ] , & gEfiPciIoProtocolGuid , ( VOID * * ) & PciIo ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// Read PCI BUS
PciIo - > GetLocation ( PciIo , & Segment , & Bus , & Device , & Function ) ;
Status = PciIo - > Pci . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
sizeof ( Pci ) / sizeof ( UINT32 ) ,
& Pci
) ;
2020-04-23 18:05:21 +02:00
DBG ( " PCI (%02llX|%02llX:%02llX.%02llX) : %04hX %04hX class=%02hhX%02hhX%02hhX \n " ,
2019-09-03 11:58:42 +02:00
Segment ,
Bus ,
Device ,
Function ,
Pci . Hdr . VendorId ,
Pci . Hdr . DeviceId ,
Pci . Hdr . ClassCode [ 2 ] ,
Pci . Hdr . ClassCode [ 1 ] ,
Pci . Hdr . ClassCode [ 0 ]
) ;
// GFX
//if ((Pci.Hdr.ClassCode[2] == PCI_CLASS_DISPLAY) &&
// (Pci.Hdr.ClassCode[1] == PCI_CLASS_DISPLAY_VGA) &&
// (NGFX < 4)) {
if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_DISPLAY ) & &
( ( Pci . Hdr . ClassCode [ 1 ] = = ( PCI_CLASS_DISPLAY_VGA ) ) | |
( Pci . Hdr . ClassCode [ 1 ] = = ( PCI_CLASS_DISPLAY_OTHER ) ) ) & &
( NGFX < 4 ) ) {
2020-02-17 21:41:09 +01:00
CONST CHAR8 * CardFamily = " " ;
2019-09-03 11:58:42 +02:00
UINT16 UFamily ;
GFX_PROPERTIES * gfx = & gGraphics [ NGFX ] ;
// GOP device path should contain the device path of the GPU to which the monitor is connected
DevicePathStr = DevicePathToStr ( DevicePathFromHandle ( HandleArray [ Index ] ) ) ;
if ( StrStr ( GopDevicePathStr , DevicePathStr ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " - GOP: Provided by device \n " ) ;
2019-09-03 11:58:42 +02:00
if ( NGFX ! = 0 ) {
// we found GOP on a GPU scanned later, make space for this GPU at first position
for ( i = NGFX ; i > 0 ; i - - ) {
2020-05-01 18:26:28 +02:00
CopyMem ( & gGraphics [ i ] , & gGraphics [ i - 1 ] , sizeof ( GFX_PROPERTIES ) ) ;
2019-09-03 11:58:42 +02:00
}
ZeroMem ( & gGraphics [ 0 ] , sizeof ( GFX_PROPERTIES ) ) ;
gfx = & gGraphics [ 0 ] ; // GPU with active GOP will be added at the first position
}
}
if ( DevicePathStr ! = NULL ) {
FreePool ( DevicePathStr ) ;
}
gfx - > DeviceID = Pci . Hdr . DeviceId ;
gfx - > Segment = Segment ;
gfx - > Bus = Bus ;
gfx - > Device = Device ;
gfx - > Function = Function ;
gfx - > Handle = HandleArray [ Index ] ;
switch ( Pci . Hdr . VendorId ) {
case 0x1002 :
info = NULL ;
gfx - > Vendor = Ati ;
i = 0 ;
do {
info = & radeon_cards [ i ] ;
if ( info - > device_id = = Pci . Hdr . DeviceId ) {
break ;
}
} while ( radeon_cards [ i + + ] . device_id ! = 0 ) ;
2020-03-29 15:44:08 +02:00
snprintf ( gfx - > Model , 64 , " %s " , info - > model_name ) ;
snprintf ( gfx - > Config , 64 , " %s " , card_configs [ info - > cfg_name ] . name ) ;
2019-09-03 11:58:42 +02:00
gfx - > Ports = card_configs [ info - > cfg_name ] . ports ;
2020-04-23 18:05:21 +02:00
DBG ( " - GFX: Model=%s (ATI/AMD) \n " , gfx - > Model ) ;
2019-09-03 11:58:42 +02:00
//get mmio
if ( info - > chip_family < CHIP_FAMILY_HAINAN ) {
gfx - > Mmio = ( UINT8 * ) ( UINTN ) ( Pci . Device . Bar [ 2 ] & ~ 0x0f ) ;
} else {
gfx - > Mmio = ( UINT8 * ) ( UINTN ) ( Pci . Device . Bar [ 5 ] & ~ 0x0f ) ;
}
gfx - > Connectors = * ( UINT32 * ) ( gfx - > Mmio + RADEON_BIOS_0_SCRATCH ) ;
2020-03-25 19:32:44 +01:00
// DBG(" - RADEON_BIOS_0_SCRATCH = 0x%08X\n", gfx->Connectors);
2019-09-03 11:58:42 +02:00
gfx - > ConnChanged = FALSE ;
SlotDevice = & SlotDevices [ 0 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " PCI Slot 0 " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 1 ;
SlotDevice - > SlotType = SlotTypePciExpressX16 ;
break ;
case 0x8086 :
gfx - > Vendor = Intel ;
2020-03-29 15:44:08 +02:00
snprintf ( gfx - > Model , 64 , " %s " , get_gma_model ( Pci . Hdr . DeviceId ) ) ;
2020-04-23 18:05:21 +02:00
DBG ( " - GFX: Model=%s (Intel) \n " , gfx - > Model ) ;
2019-09-03 11:58:42 +02:00
gfx - > Ports = 1 ;
gfx - > Connectors = ( 1 < < NGFX ) ;
gfx - > ConnChanged = FALSE ;
break ;
case 0x10de :
gfx - > Vendor = Nvidia ;
Bar0 = Pci . Device . Bar [ 0 ] ;
gfx - > Mmio = ( UINT8 * ) ( UINTN ) ( Bar0 & ~ 0x0f ) ;
2020-04-23 18:05:21 +02:00
//DBG("BAR: 0x%p\n", Mmio);
2019-09-03 11:58:42 +02:00
// get card type
2019-11-08 20:49:29 +01:00
gfx - > Family = ( REG32 ( gfx - > Mmio , 0 ) > > 20 ) & 0x1ff ;
2019-10-18 15:31:50 +02:00
UFamily = gfx - > Family & 0x1F0 ;
2019-09-03 11:58:42 +02:00
if ( ( UFamily = = NV_ARCH_KEPLER1 ) | |
( UFamily = = NV_ARCH_KEPLER2 ) | |
( UFamily = = NV_ARCH_KEPLER3 ) ) {
CardFamily = " Kepler " ;
}
else if ( ( UFamily = = NV_ARCH_FERMI1 ) | |
( UFamily = = NV_ARCH_FERMI2 ) ) {
CardFamily = " Fermi " ;
}
else if ( ( UFamily = = NV_ARCH_MAXWELL1 ) | |
( UFamily = = NV_ARCH_MAXWELL2 ) ) {
CardFamily = " Maxwell " ;
}
2019-11-08 20:28:15 +01:00
else if ( UFamily = = NV_ARCH_PASCAL ) {
2019-09-03 11:58:42 +02:00
CardFamily = " Pascal " ;
}
2019-11-08 20:28:15 +01:00
else if ( UFamily = = NV_ARCH_VOLTA ) {
CardFamily = " Volta " ;
}
else if ( UFamily = = NV_ARCH_TURING ) {
CardFamily = " Turing " ;
}
2019-09-03 11:58:42 +02:00
else if ( ( UFamily > = NV_ARCH_TESLA ) & & ( UFamily < 0xB0 ) ) { //not sure if 0xB0 is Tesla or Fermi
CardFamily = " Tesla " ;
} else {
CardFamily = " NVidia unknown " ;
}
2020-03-29 15:44:08 +02:00
snprintf (
2020-04-10 09:15:36 +02:00
gfx - > Model ,
64 ,
" %s " ,
get_nvidia_model ( ( ( Pci . Hdr . VendorId < < 16 ) | Pci . Hdr . DeviceId ) ,
( ( Pci . Device . SubsystemVendorID < < 16 ) | Pci . Device . SubsystemID ) ,
2019-09-03 11:58:42 +02:00
NULL ) //NULL: get from generic lists
2020-04-10 09:15:36 +02:00
) ;
2019-09-03 11:58:42 +02:00
2020-04-17 15:14:24 +02:00
DBG ( " - GFX: Model=%s family %hX (%s) \n " , gfx - > Model , gfx - > Family , CardFamily ) ;
2019-09-03 11:58:42 +02:00
gfx - > Ports = 0 ;
SlotDevice = & SlotDevices [ 1 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " PCI Slot 0 " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 1 ;
SlotDevice - > SlotType = SlotTypePciExpressX16 ;
break ;
default :
gfx - > Vendor = Unknown ;
2020-04-17 14:27:38 +02:00
snprintf ( gfx - > Model , 64 , " pci%hx,%hx " , Pci . Hdr . VendorId , Pci . Hdr . DeviceId ) ;
2019-09-03 11:58:42 +02:00
gfx - > Ports = 1 ;
gfx - > Connectors = ( 1 < < NGFX ) ;
gfx - > ConnChanged = FALSE ;
break ;
}
NGFX + + ;
} //if gfx
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_NETWORK ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_NETWORK_OTHER ) ) {
SlotDevice = & SlotDevices [ 6 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " AirPort " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 0 ;
SlotDevice - > SlotType = SlotTypePciExpressX1 ;
2020-06-09 13:11:05 +02:00
DBG ( " - WIFI: Vendor= " ) ;
2019-09-03 11:58:42 +02:00
switch ( Pci . Hdr . VendorId ) {
case 0x11ab :
DBG ( " Marvell \n " ) ;
break ;
case 0x10ec :
DBG ( " Realtek \n " ) ;
break ;
case 0x14e4 :
DBG ( " Broadcom \n " ) ;
break ;
case 0x1969 :
case 0x168C :
DBG ( " Atheros \n " ) ;
break ;
case 0x1814 :
DBG ( " Ralink \n " ) ;
break ;
case 0x8086 :
DBG ( " Intel \n " ) ;
break ;
default :
2020-06-09 13:11:05 +02:00
DBG ( " 0x%04X \n " , Pci . Hdr . VendorId ) ;
2019-09-03 11:58:42 +02:00
break ;
}
}
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_NETWORK ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_NETWORK_ETHERNET ) ) {
SlotDevice = & SlotDevices [ 5 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " Ethernet " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 2 ;
SlotDevice - > SlotType = SlotTypePciExpressX1 ;
gLanVendor [ nLanCards ] = Pci . Hdr . VendorId ;
Bar0 = Pci . Device . Bar [ 0 ] ;
gLanMmio [ nLanCards + + ] = ( UINT8 * ) ( UINTN ) ( Bar0 & ~ 0x0f ) ;
if ( nLanCards > = 4 ) {
DBG ( " - [!] too many LAN card in the system (upto 4 limit exceeded), overriding the last one \n " ) ;
nLanCards = 3 ; // last one will be rewritten
}
2020-06-09 13:11:05 +02:00
DBG ( " - LAN: %llu Vendor= " , nLanCards - 1 ) ;
2019-09-03 11:58:42 +02:00
switch ( Pci . Hdr . VendorId ) {
case 0x11ab :
DBG ( " Marvell \n " ) ;
break ;
case 0x10ec :
DBG ( " Realtek \n " ) ;
break ;
case 0x14e4 :
DBG ( " Broadcom \n " ) ;
break ;
case 0x1969 :
case 0x168C :
DBG ( " Atheros \n " ) ;
break ;
case 0x8086 :
DBG ( " Intel \n " ) ;
break ;
case 0x10de :
DBG ( " Nforce \n " ) ;
break ;
default :
DBG ( " Unknown \n " ) ;
break ;
}
}
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_SERIAL ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_SERIAL_FIREWIRE ) ) {
SlotDevice = & SlotDevices [ 12 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " FireWire " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 3 ;
SlotDevice - > SlotType = SlotTypePciExpressX4 ;
}
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_MEDIA ) & &
( ( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_HDA ) | |
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_AUDIO ) ) & &
( NHDA < 4 ) ) {
HDA_PROPERTIES * hda = & gAudios [ NHDA ] ;
// Populate Controllers IDs
hda - > controller_vendor_id = Pci . Hdr . VendorId ;
hda - > controller_device_id = Pci . Hdr . DeviceId ;
// HDA Controller Info
2019-11-27 12:16:02 +01:00
HdaControllerGetName ( ( ( hda - > controller_device_id < < 16 ) | hda - > controller_vendor_id ) , & hda - > controller_name ) ;
2019-09-03 11:58:42 +02:00
if ( IsHDMIAudio ( HandleArray [ Index ] ) ) {
DBG ( " - HDMI Audio: \n " ) ;
SlotDevice = & SlotDevices [ 4 ] ;
SlotDevice - > SegmentGroupNum = ( UINT16 ) Segment ;
SlotDevice - > BusNum = ( UINT8 ) Bus ;
SlotDevice - > DevFuncNum = ( UINT8 ) ( ( Device < < 3 ) | ( Function & 0x07 ) ) ;
SlotDevice - > Valid = TRUE ;
2020-03-29 15:44:08 +02:00
snprintf ( SlotDevice - > SlotName , 31 , " HDMI port " ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotID = 5 ;
SlotDevice - > SlotType = SlotTypePciExpressX4 ;
}
if ( gSettings . ResetHDA ) {
//Slice method from VoodooHDA
2020-06-05 14:15:31 +02:00
//PCI_HDA_TCSEL_OFFSET = 0x44
2019-09-03 11:58:42 +02:00
UINT8 Value = 0 ;
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
Value & = 0xf8 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
//ResetControllerHDA();
}
NHDA + + ;
} // if Audio device
}
}
}
if ( GopDevicePathStr ! = NULL ) {
FreePool ( GopDevicePathStr ) ;
}
}
VOID
SetDevices ( LOADER_ENTRY * Entry )
{
// EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *modeInfo;
EFI_STATUS Status ;
EFI_PCI_IO_PROTOCOL * PciIo ;
PCI_TYPE00 Pci ;
UINTN HandleCount ;
UINTN i , j ;
EFI_HANDLE * HandleBuffer ;
pci_dt_t PCIdevice ;
UINTN Segment ;
UINTN Bus ;
UINTN Device ;
UINTN Function ;
BOOLEAN StringDirty = FALSE ;
BOOLEAN TmpDirty = FALSE ;
UINT16 PmCon ;
UINT32 Rcba ;
UINT32 Hptc ;
DEV_PROPERTY * Prop = NULL ;
DEV_PROPERTY * Prop2 = NULL ;
DevPropDevice * device = NULL ;
GetEdidDiscovered ( ) ;
//First make string from Device->Properties
Prop = gSettings . ArbProperties ;
device = NULL ;
if ( ! device_inject_string ) {
device_inject_string = devprop_create_string ( ) ;
}
while ( Prop ) {
if ( Prop - > Device ! = 0 ) {
Prop = Prop - > Next ; //skip CustomProperties
continue ;
}
device = devprop_add_device_pci ( device_inject_string , NULL , Prop - > DevicePath ) ;
2020-03-25 19:32:44 +01:00
DBG ( " add device: %ls \n " , DevicePathToStr ( Prop - > DevicePath ) ) ;
2019-09-03 11:58:42 +02:00
Prop2 = Prop - > Child ;
while ( Prop2 ) {
if ( Prop2 - > MenuItem . BValue ) {
if ( AsciiStrStr ( Prop2 - > Key , " -platform-id " ) ! = NULL ) {
2020-04-07 21:48:36 +02:00
if ( gSettings . IgPlatform = = 0 & & Prop2 - > Value ) {
2019-09-03 11:58:42 +02:00
CopyMem ( ( UINT8 * ) & gSettings . IgPlatform , ( UINT8 * ) Prop2 - > Value , Prop2 - > ValueLen ) ;
}
devprop_add_value ( device , Prop2 - > Key , ( UINT8 * ) & gSettings . IgPlatform , 4 ) ;
2020-04-07 21:48:36 +02:00
DBG ( " Add key=%s valuelen=%llu \n " , Prop2 - > Key , Prop2 - > ValueLen ) ;
2019-09-03 11:58:42 +02:00
} else if ( ( AsciiStrStr ( Prop2 - > Key , " override-no-edid " ) | | AsciiStrStr ( Prop2 - > Key , " override-no-connect " ) )
& & gSettings . InjectEDID & & gSettings . CustomEDID ) {
// special case for EDID properties
devprop_add_value ( device , Prop2 - > Key , gSettings . CustomEDID , 128 ) ;
2020-03-25 19:32:44 +01:00
DBG ( " Add key=%s from custom EDID \n " , Prop2 - > Key ) ;
2019-09-03 11:58:42 +02:00
} else {
devprop_add_value ( device , Prop2 - > Key , ( UINT8 * ) Prop2 - > Value , Prop2 - > ValueLen ) ;
2020-04-07 21:48:36 +02:00
DBG ( " Add key=%s valuelen=%llu \n " , Prop2 - > Key , Prop2 - > ValueLen ) ;
2019-09-03 11:58:42 +02:00
}
}
StringDirty = TRUE ;
Prop2 = Prop2 - > Next ;
}
Prop = Prop - > Next ;
}
devices_number = 1 ; //should initialize for reentering GUI
// Scan PCI handles
Status = gBS - > LocateHandleBuffer (
ByProtocol ,
& gEfiPciIoProtocolGuid ,
NULL ,
& HandleCount ,
& HandleBuffer
) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < HandleCount ; i + + ) {
Status = gBS - > HandleProtocol ( HandleBuffer [ i ] , & gEfiPciIoProtocolGuid , ( VOID * * ) & PciIo ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// Read PCI BUS
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint32 , 0 , sizeof ( Pci ) / sizeof ( UINT32 ) , & Pci ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
Status = PciIo - > GetLocation ( PciIo , & Segment , & Bus , & Device , & Function ) ;
PCIdevice . DeviceHandle = HandleBuffer [ i ] ;
PCIdevice . dev . addr = ( UINT32 ) PCIADDR ( Bus , Device , Function ) ;
PCIdevice . vendor_id = Pci . Hdr . VendorId ;
PCIdevice . device_id = Pci . Hdr . DeviceId ;
PCIdevice . revision = Pci . Hdr . RevisionID ;
PCIdevice . subclass = Pci . Hdr . ClassCode [ 0 ] ;
PCIdevice . class_id = * ( ( UINT16 * ) ( Pci . Hdr . ClassCode + 1 ) ) ;
PCIdevice . subsys_id . subsys . vendor_id = Pci . Device . SubsystemVendorID ;
PCIdevice . subsys_id . subsys . device_id = Pci . Device . SubsystemID ;
PCIdevice . used = FALSE ;
//if (gSettings.NrAddProperties == 0xFFFE) { //yyyy it means Arbitrary
//------------------
Prop = gSettings . ArbProperties ; //check for additional properties
device = NULL ;
/* if (!string) {
string = devprop_create_string ( ) ;
} */
while ( Prop ) {
if ( Prop - > Device ! = PCIdevice . dev . addr ) {
Prop = Prop - > Next ;
continue ;
}
if ( ! PCIdevice . used ) {
device = devprop_add_device_pci ( device_inject_string , & PCIdevice , NULL ) ;
PCIdevice . used = TRUE ;
}
//special corrections
if ( Prop - > MenuItem . BValue ) {
if ( AsciiStrStr ( Prop - > Key , " -platform-id " ) ! = NULL ) {
devprop_add_value ( device , Prop - > Key , ( UINT8 * ) & gSettings . IgPlatform , 4 ) ;
} else {
devprop_add_value ( device , Prop - > Key , ( UINT8 * ) Prop - > Value , Prop - > ValueLen ) ;
}
}
StringDirty = TRUE ;
Prop = Prop - > Next ;
}
//------------------
if ( PCIdevice . used ) {
2020-04-07 21:48:36 +02:00
DBG ( " custom properties for device %02llX:%02llX.%02llX injected \n " , Bus , Device , Function ) ;
2019-09-03 11:58:42 +02:00
//continue;
}
//}
// GFX
if ( /* gSettings.GraphicsInjector && */
( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_DISPLAY ) & &
( ( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_DISPLAY_VGA ) | |
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_DISPLAY_OTHER ) ) ) {
//gGraphics.DeviceID = Pci.Hdr.DeviceId;
switch ( Pci . Hdr . VendorId ) {
case 0x1002 :
if ( gSettings . InjectATI ) {
//can't do this in one step because of C-conventions
TmpDirty = setup_ati_devprop ( Entry , & PCIdevice ) ;
StringDirty | = TmpDirty ;
} else {
MsgLog ( " ATI injection not set \n " ) ;
}
for ( j = 0 ; j < 4 ; j + + ) {
if ( gGraphics [ j ] . Handle = = PCIdevice . DeviceHandle ) {
if ( gGraphics [ j ] . ConnChanged ) {
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + RADEON_BIOS_0_SCRATCH ) = gGraphics [ j ] . Connectors ;
}
break ;
}
}
if ( gSettings . DeInit ) {
for ( j = 0 ; j < 4 ; j + + ) {
if ( gGraphics [ j ] . Handle = = PCIdevice . DeviceHandle ) {
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x6848 ) = 0 ; //EVERGREEN_GRPH_FLIP_CONTROL, 1<<0 SURFACE_UPDATE_H_RETRACE_EN
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x681C ) = 0 ; //EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x6820 ) = 0 ; //EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x6808 ) = 0 ; //EVERGREEN_GRPH_LUT_10BIT_BYPASS_CONTROL, EVERGREEN_LUT_10BIT_BYPASS_EN (1 << 8)
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x6800 ) = 1 ; //EVERGREEN_GRPH_ENABLE
* ( UINT32 * ) ( gGraphics [ j ] . Mmio + 0x6EF8 ) = 0 ; //EVERGREEN_MASTER_UPDATE_MODE
//*(UINT32*)(gGraphics[j].Mmio + R600_BIOS_0_SCRATCH) = 0x00810000;
2020-04-07 21:48:36 +02:00
DBG ( " Device %llu deinited \n " , j ) ;
2019-09-03 11:58:42 +02:00
}
}
}
break ;
case 0x8086 :
if ( gSettings . InjectIntel ) {
TmpDirty = setup_gma_devprop ( Entry , & PCIdevice ) ;
StringDirty | = TmpDirty ;
2020-04-17 15:14:24 +02:00
MsgLog ( " Intel GFX revision = 0x%hhX \n " , PCIdevice . revision ) ;
2019-09-03 11:58:42 +02:00
} else {
MsgLog ( " Intel GFX injection not set \n " ) ;
}
// IntelBacklight reworked by Sherlocks. 2018.10.07
if ( gSettings . IntelBacklight | | gSettings . IntelMaxBacklight ) {
UINT32 LEV2 = 0 , LEVL = 0 , P0BL = 0 , GRAN = 0 ;
UINT32 LEVW = 0 , LEVX = 0 , LEVD = 0 , PCHL = 0 ;
UINT32 ShiftLEVX = 0 , FBLEVX = 0 ;
UINT32 SYSLEVW = 0x80000000 ;
UINT32 MACLEVW = 0xC0000000 ;
MsgLog ( " Intel GFX IntelBacklight \n " ) ;
// Read LEV2
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48250 ,
1 ,
& LEV2
) ;
// Read LEVL
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48254 ,
1 ,
& LEVL
) ;
// Read P0BL -- what is the sense to read if not used?
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x70040 ,
1 ,
& P0BL
) ;
// Read GRAN
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC2000 ,
1 ,
& GRAN
) ;
// Read LEVW
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& LEVW
) ;
// Read LEVX
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
ShiftLEVX = LEVX > > 16 ;
// Read LEVD
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8258 ,
1 ,
& LEVD
) ;
// Read PCHL
/*Status = */ PciIo - > Mem . Read (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xE1180 ,
1 ,
& PCHL
) ;
2020-03-25 19:32:44 +01:00
MsgLog ( " LEV2 = 0x%X, LEVL = 0x%X, P0BL = 0x%X, GRAN = 0x%X \n " , LEV2 , LEVL , P0BL , GRAN ) ;
MsgLog ( " LEVW = 0x%X, LEVX = 0x%X, LEVD = 0x%X, PCHL = 0x%X \n " , LEVW , LEVX , LEVD , PCHL ) ;
2019-09-03 11:58:42 +02:00
// Maximum brightness level of each framebuffers
// Sandy Bridge/Ivy Bridge: 0x0710
// Haswell/Broadwell: 0x056C/0x07A1/0x0AD9/0x1499
// Skylake/KabyLake: 0x056C
// Coffee Lake: 0xFFFF
switch ( Pci . Hdr . DeviceId ) {
case 0x0102 : // "Intel HD Graphics 2000"
case 0x0106 : // "Intel HD Graphics 2000"
case 0x010A : // "Intel HD Graphics P3000"
case 0x0112 : // "Intel HD Graphics 3000"
case 0x0116 : // "Intel HD Graphics 3000"
case 0x0122 : // "Intel HD Graphics 3000"
case 0x0126 : // "Intel HD Graphics 3000"
if ( gSettings . IgPlatform ) {
switch ( gSettings . IgPlatform ) {
case ( UINT32 ) 0x00030010 :
case ( UINT32 ) 0x00050000 :
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0x0710 ;
break ;
}
} else {
FBLEVX = 0x0710 ;
}
break ;
case 0x0152 : // "Intel HD Graphics 2500"
case 0x0156 : // "Intel HD Graphics 2500"
case 0x015A : // "Intel HD Graphics 2500"
case 0x0162 : // "Intel HD Graphics 4000"
case 0x0166 : // "Intel HD Graphics 4000"
case 0x016A : // "Intel HD Graphics P4000"
FBLEVX = 0x0710 ;
break ;
case 0x0412 : // "Intel HD Graphics 4600"
case 0x0416 : // "Intel HD Graphics 4600"
case 0x041A : // "Intel HD Graphics P4600"
case 0x041E : // "Intel HD Graphics 4400"
case 0x0422 : // "Intel HD Graphics 5000"
case 0x0426 : // "Intel HD Graphics 5000"
case 0x042A : // "Intel HD Graphics 5000"
case 0x0A06 : // "Intel HD Graphics"
case 0x0A16 : // "Intel HD Graphics 4400"
case 0x0A1E : // "Intel HD Graphics 4200"
case 0x0A22 : // "Intel Iris Graphics 5100"
case 0x0A26 : // "Intel HD Graphics 5000"
case 0x0A2A : // "Intel Iris Graphics 5100"
case 0x0A2B : // "Intel Iris Graphics 5100"
case 0x0A2E : // "Intel Iris Graphics 5100"
case 0x0D12 : // "Intel HD Graphics 4600"
case 0x0D16 : // "Intel HD Graphics 4600"
case 0x0D22 : // "Intel Iris Pro Graphics 5200"
case 0x0D26 : // "Intel Iris Pro Graphics 5200"
case 0x0D2A : // "Intel Iris Pro Graphics 5200"
case 0x0D2B : // "Intel Iris Pro Graphics 5200"
case 0x0D2E : // "Intel Iris Pro Graphics 5200"
if ( gSettings . IgPlatform ) {
switch ( gSettings . IgPlatform ) {
case ( UINT32 ) 0x04060000 :
case ( UINT32 ) 0x0c060000 :
case ( UINT32 ) 0x04160000 :
case ( UINT32 ) 0x0c160000 :
case ( UINT32 ) 0x04260000 :
case ( UINT32 ) 0x0c260000 :
case ( UINT32 ) 0x0d260000 :
case ( UINT32 ) 0x0d220003 :
FBLEVX = 0x1499 ;
break ;
case ( UINT32 ) 0x0a160000 :
case ( UINT32 ) 0x0a260000 :
case ( UINT32 ) 0x0a260005 :
case ( UINT32 ) 0x0a260006 :
FBLEVX = 0x0AD9 ;
break ;
case ( UINT32 ) 0x0d260007 :
FBLEVX = 0x07A1 ;
break ;
case ( UINT32 ) 0x04120004 :
case ( UINT32 ) 0x0412000b :
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
switch ( Pci . Hdr . DeviceId ) {
case 0x0406 :
case 0x0C06 :
case 0x0416 :
case 0x0C16 :
case 0x0426 :
case 0x0C26 :
case 0x0D22 :
FBLEVX = 0x1499 ;
break ;
case 0x0A16 :
case 0x0A26 :
FBLEVX = 0x0AD9 ;
break ;
case 0x0D26 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
}
break ;
case 0x1612 : // "Intel HD Graphics 5600"
case 0x1616 : // "Intel HD Graphics 5500"
case 0x161E : // "Intel HD Graphics 5300"
case 0x1626 : // "Intel HD Graphics 6000"
case 0x162B : // "Intel Iris Graphics 6100"
case 0x162D : // "Intel Iris Pro Graphics P6300"
case 0x1622 : // "Intel Iris Pro Graphics 6200"
case 0x162A : // "Intel Iris Pro Graphics P6300"
if ( gSettings . IgPlatform ) {
switch ( gSettings . IgPlatform ) {
case ( UINT32 ) 0x16060000 :
case ( UINT32 ) 0x160e0000 :
case ( UINT32 ) 0x16160000 :
case ( UINT32 ) 0x161e0000 :
case ( UINT32 ) 0x16220000 :
case ( UINT32 ) 0x16260000 :
case ( UINT32 ) 0x162b0000 :
case ( UINT32 ) 0x16260004 :
case ( UINT32 ) 0x162b0004 :
case ( UINT32 ) 0x16220007 :
case ( UINT32 ) 0x16260008 :
case ( UINT32 ) 0x162b0008 :
FBLEVX = 0x1499 ;
break ;
case ( UINT32 ) 0x16260005 :
case ( UINT32 ) 0x16260006 :
FBLEVX = 0x0AD9 ;
break ;
case ( UINT32 ) 0x16120003 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
switch ( Pci . Hdr . DeviceId ) {
case 0x1606 :
case 0x160E :
case 0x1616 :
case 0x161E :
case 0x1622 :
FBLEVX = 0x1499 ;
break ;
case 0x1626 :
FBLEVX = 0x0AD9 ;
break ;
case 0x1612 :
FBLEVX = 0x07A1 ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
}
break ;
case 0x1902 : // "Intel HD Graphics 510"
case 0x1906 : // "Intel HD Graphics 510"
case 0x190B : // "Intel HD Graphics 510"
case 0x1912 : // "Intel HD Graphics 530"
case 0x1916 : // "Intel HD Graphics 520"
case 0x191B : // "Intel HD Graphics 530"
case 0x191D : // "Intel HD Graphics P530"
case 0x191E : // "Intel HD Graphics 515"
case 0x1921 : // "Intel HD Graphics 520"
case 0x1923 : // "Intel HD Graphics 535"
case 0x1926 : // "Intel Iris Graphics 540"
case 0x1927 : // "Intel Iris Graphics 550"
case 0x192B : // "Intel Iris Graphics 555"
case 0x192D : // "Intel Iris Graphics P555"
case 0x1932 : // "Intel Iris Pro Graphics 580"
case 0x193A : // "Intel Iris Pro Graphics P580"
case 0x193B : // "Intel Iris Pro Graphics 580"
case 0x193D : // "Intel Iris Pro Graphics P580"
if ( gSettings . IgPlatform ) {
switch ( gSettings . IgPlatform ) {
case ( UINT32 ) 0x19120001 :
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0x056C ;
break ;
}
} else {
FBLEVX = 0x056C ;
}
break ;
case 0x5902 : // "Intel HD Graphics 610"
case 0x5906 : // "Intel HD Graphics 610"
case 0x5912 : // "Intel HD Graphics 630"
case 0x5916 : // "Intel HD Graphics 620"
case 0x591A : // "Intel HD Graphics P630"
case 0x591B : // "Intel HD Graphics 630"
case 0x591D : // "Intel HD Graphics P630"
case 0x591E : // "Intel HD Graphics 615"
case 0x5923 : // "Intel HD Graphics 635"
case 0x5926 : // "Intel Iris Plus Graphics 640"
case 0x5927 : // "Intel Iris Plus Graphics 650"
case 0x5917 : // "Intel UHD Graphics 620"
case 0x591C : // "Intel UHD Graphics 615"
case 0x87C0 : // "Intel UHD Graphics 617"
2019-10-12 13:12:59 +02:00
case 0x87CA : // "Intel UHD Graphics 615"
2019-09-03 11:58:42 +02:00
FBLEVX = 0x056C ;
break ;
case 0x3E90 : // "Intel UHD Graphics 610"
case 0x3E93 : // "Intel UHD Graphics 610"
case 0x3E91 : // "Intel UHD Graphics 630"
case 0x3E92 : // "Intel UHD Graphics 630"
case 0x3E98 : // "Intel UHD Graphics 630"
case 0x3E9B : // "Intel UHD Graphics 630"
case 0x3EA5 : // "Intel Iris Plus Graphics 655"
case 0x3EA0 : // "Intel UHD Graphics 620"
2019-10-12 02:56:20 +02:00
case 0x9B41 : // "Intel UHD Graphics 620"
case 0x9BCA : // "Intel UHD Graphics 620"
2019-09-03 11:58:42 +02:00
FBLEVX = 0xFFFF ;
break ;
default :
FBLEVX = 0xFFFF ;
break ;
}
// Write LEVW
if ( LEVW ! = SYSLEVW ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVW, set System LEVW: 0x%X \n " , SYSLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& SYSLEVW
) ;
}
switch ( gCPUStructure . Model ) {
case CPU_MODEL_SANDY_BRIDGE :
case CPU_MODEL_IVY_BRIDGE :
case CPU_MODEL_IVY_BRIDGE_E5 :
// if change SYS LEVW to macOS LEVW, the brightness of the pop-up may decrease or increase.
// but the brightness of the monitor will not actually change. so we should not use this.
2020-03-25 19:32:44 +01:00
MsgLog ( " Skip writing macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
break ;
case CPU_MODEL_HASWELL :
case CPU_MODEL_HASWELL_ULT :
case CPU_MODEL_HASWELL_U5 : // Broadwell
case CPU_MODEL_BROADWELL_HQ :
case CPU_MODEL_BROADWELL_E5 :
case CPU_MODEL_BROADWELL_DE :
// if not change SYS LEVW to macOS LEVW, backlight will be dark and don't work keys for backlight.
// so we should use this.
2020-03-25 19:32:44 +01:00
MsgLog ( " Write macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& MACLEVW
) ;
break ;
default :
if ( gSettings . IntelBacklight ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Write macOS LEVW: 0x%X \n " , MACLEVW ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8250 ,
1 ,
& MACLEVW
) ;
}
break ;
}
switch ( Pci . Hdr . DeviceId ) {
case 0x0042 : // "Intel HD Graphics"
case 0x0046 : // "Intel HD Graphics"
case 0x0102 : // "Intel HD Graphics 2000"
case 0x0106 : // "Intel HD Graphics 2000"
case 0x010A : // "Intel HD Graphics P3000"
case 0x0112 : // "Intel HD Graphics 3000"
case 0x0116 : // "Intel HD Graphics 3000"
case 0x0122 : // "Intel HD Graphics 3000"
case 0x0126 : // "Intel HD Graphics 3000"
case 0x0152 : // "Intel HD Graphics 2500"
case 0x0156 : // "Intel HD Graphics 2500"
case 0x015A : // "Intel HD Graphics 2500"
case 0x0162 : // "Intel HD Graphics 4000"
case 0x0166 : // "Intel HD Graphics 4000"
case 0x016A : // "Intel HD Graphics P4000"
// Write LEVL/LEVX
if ( gSettings . IntelMaxBacklight ) {
if ( ! LEVL ) {
LEVL = FBLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVL, set LEVL: 0x%X \n " , LEVL ) ;
2019-09-03 11:58:42 +02:00
}
if ( ! LEVX ) {
ShiftLEVX = FBLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVX, set LEVX: 0x%X \n " , ShiftLEVX ) ;
2019-09-03 11:58:42 +02:00
}
if ( gSettings . IntelMaxValue ) {
FBLEVX = gSettings . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
}
LEVL = ( LEVL * FBLEVX ) / ShiftLEVX ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVL: 0x%X \n " , LEVL ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0x48254 ,
1 ,
& LEVL
) ;
LEVX = FBLEVX | FBLEVX < < 16 ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVX: 0x%X \n " , LEVX ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
}
break ;
case 0x3E90 : // "Intel UHD Graphics 610"
case 0x3E93 : // "Intel UHD Graphics 610"
case 0x3E91 : // "Intel UHD Graphics 630"
case 0x3E92 : // "Intel UHD Graphics 630"
case 0x3E98 : // "Intel UHD Graphics 630"
case 0x3E9B : // "Intel UHD Graphics 630"
case 0x3EA5 : // "Intel Iris Plus Graphics 655"
case 0x3EA0 : // "Intel UHD Graphics 620"
2019-10-12 02:56:20 +02:00
case 0x9B41 : // "Intel UHD Graphics 620"
case 0x9BCA : // "Intel UHD Graphics 620"
2019-09-03 11:58:42 +02:00
// Write LEVD
if ( gSettings . IntelMaxBacklight ) {
if ( gSettings . IntelMaxValue ) {
FBLEVX = gSettings . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
}
LEVD = ( UINT32 ) DivU64x32 ( MultU64x32 ( FBLEVX , LEVX ) , 0xFFFF ) ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVD: 0x%X \n " , LEVD ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8258 ,
1 ,
& LEVD
) ;
}
break ;
default :
// Write LEVX
if ( gSettings . IntelMaxBacklight ) {
if ( gSettings . IntelMaxValue ) {
FBLEVX = gSettings . IntelMaxValue ;
2020-03-25 19:32:44 +01:00
MsgLog ( " Read IntelMaxValue: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = FBLEVX | FBLEVX < < 16 ;
} else if ( ! LEVX ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Found invalid LEVX, set LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = FBLEVX | FBLEVX < < 16 ;
} else if ( ShiftLEVX ! = FBLEVX ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Read default Framebuffer LEVX: 0x%X \n " , FBLEVX ) ;
2019-09-03 11:58:42 +02:00
LEVX = ( ( ( LEVX & 0xFFFF ) * FBLEVX / ShiftLEVX ) | FBLEVX < < 16 ) ;
}
2020-03-25 19:32:44 +01:00
MsgLog ( " Write new LEVX: 0x%X \n " , LEVX ) ;
2019-09-03 11:58:42 +02:00
/*Status = */ PciIo - > Mem . Write (
PciIo ,
EfiPciIoWidthUint32 ,
0 ,
0xC8254 ,
1 ,
& LEVX
) ;
}
break ;
}
if ( gSettings . FakeIntel = = 0x00008086 ) {
UINT32 IntelDisable = 0x03 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint32 , 0x50 , 1 , & IntelDisable ) ;
}
}
break ;
case 0x10de :
if ( gSettings . InjectNVidia ) {
TmpDirty = setup_nvidia_devprop ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
} else {
MsgLog ( " NVidia GFX injection not set \n " ) ;
}
break ;
default :
break ;
}
}
//LAN
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_NETWORK ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_NETWORK_ETHERNET ) ) {
//MsgLog ("Ethernet device found\n");
TmpDirty = set_eth_props ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
}
//USB
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_SERIAL ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_SERIAL_USB ) ) {
if ( gSettings . USBInjection ) {
TmpDirty = set_usb_props ( & PCIdevice ) ;
StringDirty | = TmpDirty ;
}
}
// HDA
2020-06-05 14:15:31 +02:00
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_MEDIA ) & &
2019-09-03 11:58:42 +02:00
( ( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_HDA ) | |
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_MEDIA_AUDIO ) ) ) {
// HDMI injection inside
2020-06-05 14:15:31 +02:00
if ( gSettings . HDAInjection ) {
TmpDirty = setup_hda_devprop ( PciIo , & PCIdevice , Entry - > OSVersion ) ;
StringDirty | = TmpDirty ;
}
if ( gSettings . ResetHDA ) {
//PCI_HDA_TCSEL_OFFSET = 0x44
UINT8 Value = 0 ;
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
if ( EFI_ERROR ( Status ) ) {
continue ;
}
Value & = 0xf8 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint8 , 0x44 , 1 , & Value ) ;
}
}
2019-09-03 11:58:42 +02:00
//LPC
else if ( ( Pci . Hdr . ClassCode [ 2 ] = = PCI_CLASS_BRIDGE ) & &
( Pci . Hdr . ClassCode [ 1 ] = = PCI_CLASS_BRIDGE_ISA ) )
{
if ( gSettings . LpcTune ) {
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint16 , GEN_PMCON_1 , 1 , & PmCon ) ;
2020-06-05 14:15:31 +02:00
MsgLog ( " Initial PmCon value=%hX \n " , PmCon ) ;
2019-09-03 11:58:42 +02:00
if ( gSettings . EnableC6 ) {
PmCon | = 1 < < 11 ;
2020-04-23 18:05:21 +02:00
DBG ( " C6 enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
PmCon & = ~ ( 1 < < 11 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " C6 disabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
/*
if ( gSettings . EnableC2 ) {
PmCon | = 1 < < 10 ;
2020-04-23 18:05:21 +02:00
DBG ( " BIOS_PCIE enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
PmCon & = ~ ( 1 < < 10 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " BIOS_PCIE disabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
*/
if ( gSettings . EnableC4 ) {
PmCon | = 1 < < 7 ;
2020-04-23 18:05:21 +02:00
DBG ( " C4 enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
PmCon & = ~ ( 1 < < 7 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " C4 disabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
if ( gSettings . EnableISS ) {
PmCon | = 1 < < 3 ;
2020-04-23 18:05:21 +02:00
DBG ( " SpeedStep enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
PmCon & = ~ ( 1 < < 3 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " SpeedStep disabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint16 , GEN_PMCON_1 , 1 , & PmCon ) ;
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint16 , GEN_PMCON_1 , 1 , & PmCon ) ;
2020-06-05 14:15:31 +02:00
MsgLog ( " Set PmCon value=%hX \n " , PmCon ) ;
2019-09-03 11:58:42 +02:00
}
Rcba = 0 ;
/* Scan Port */
Status = PciIo - > Pci . Read ( PciIo , EfiPciIoWidthUint32 , 0xF0 , 1 , & Rcba ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) continue ;
2019-09-03 11:58:42 +02:00
// Rcba &= 0xFFFFC000;
if ( ( Rcba & 0xFFFFC000 ) = = 0 ) {
MsgLog ( " RCBA disabled; cannot use it \n " ) ;
continue ;
}
if ( ( Rcba & 1 ) = = 0 ) {
MsgLog ( " RCBA access disabled; trying to enable \n " ) ;
Rcba | = 1 ;
PciIo - > Pci . Write ( PciIo , EfiPciIoWidthUint32 , 0xF0 , 1 , & Rcba ) ;
}
Rcba & = 0xFFFFC000 ;
if ( gSettings . ForceHPET ) {
Hptc = REG32 ( ( UINTN ) Rcba , 0x3404 ) ;
if ( ( Hptc & 0x80 ) ! = 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is already enabled \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is disabled, trying to enable... \n " ) ;
2019-09-03 11:58:42 +02:00
REG32 ( ( UINTN ) Rcba , 0x3404 ) = Hptc | 0x80 ;
}
// Re-Check if HPET is enabled.
Hptc = REG32 ( ( UINTN ) Rcba , 0x3404 ) ;
if ( ( Hptc & 0x80 ) = = 0 ) {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is disabled in HPTC. Cannot enable! \n " ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-23 18:05:21 +02:00
DBG ( " HPET is enabled \n " ) ;
2019-09-03 11:58:42 +02:00
}
}
if ( gSettings . DisableFunctions ) {
UINT32 FD = REG32 ( ( UINTN ) Rcba , 0x3418 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " Initial value of FD register 0x%X \n " , FD ) ;
2019-09-03 11:58:42 +02:00
FD | = gSettings . DisableFunctions ;
REG32 ( ( UINTN ) Rcba , 0x3418 ) = FD ;
FD = REG32 ( ( UINTN ) Rcba , 0x3418 ) ;
2020-04-23 18:05:21 +02:00
DBG ( " recheck value after patch 0x%X \n " , FD ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
if ( StringDirty ) {
EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ; //0xFE000000;
device_inject_stringlength = device_inject_string - > length * 2 ;
2020-04-23 18:05:21 +02:00
DBG ( " stringlength = %d \n " , device_inject_stringlength ) ;
2019-12-21 01:31:49 +01:00
// gDeviceProperties = (__typeof__(gDeviceProperties))AllocateAlignedPages EFI_SIZE_TO_PAGES (device_inject_stringlength + 1), 64);
2019-09-03 11:58:42 +02:00
Status = gBS - > AllocatePages (
AllocateMaxAddress ,
EfiACPIReclaimMemory ,
2020-02-26 20:44:16 +01:00
EFI_SIZE_TO_PAGES ( ( UINTN ) device_inject_stringlength + 1 ) ,
2019-09-03 11:58:42 +02:00
& BufferPtr
) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
mProperties = ( UINT8 * ) ( UINTN ) BufferPtr ;
2019-12-27 18:01:40 +01:00
gDeviceProperties = devprop_generate_string ( device_inject_string ) ;
2019-09-03 11:58:42 +02:00
gDeviceProperties [ device_inject_stringlength ] = 0 ;
2020-04-23 18:05:21 +02:00
// DBG(gDeviceProperties);
// DBG("\n");
2019-09-03 11:58:42 +02:00
// StringDirty = FALSE;
//-------
2020-04-28 12:49:24 +02:00
mPropSize = ( UINT32 ) AsciiStrLen ( gDeviceProperties ) / 2 ;
2020-04-23 18:05:21 +02:00
// DBG("Preliminary size of mProperties=%d\n", mPropSize);
2019-09-03 11:58:42 +02:00
mPropSize = hex2bin ( gDeviceProperties , mProperties , mPropSize ) ;
2020-04-23 18:05:21 +02:00
// DBG("Final size of mProperties=%d\n", mPropSize);
2019-09-03 11:58:42 +02:00
//---------
// Status = egSaveFile(SelfRootDir, L"EFI\\CLOVER\\misc\\devprop.bin", (UINT8*)mProperties, mPropSize);
//and now we can free memory?
if ( gSettings . AddProperties ) {
FreePool ( gSettings . AddProperties ) ;
}
if ( gSettings . ArbProperties ) {
DEV_PROPERTY * Props ;
DEV_PROPERTY * Next ;
Prop = gSettings . ArbProperties ;
while ( Prop ) {
Props = Prop - > Child ;
if ( Prop - > Label ) {
FreePool ( Prop - > Label ) ;
}
if ( Prop - > Key ) {
FreePool ( Prop - > Key ) ;
}
if ( Prop - > Value ) {
FreePool ( Prop - > Value ) ;
}
if ( Prop - > DevicePath ) {
FreePool ( Prop - > DevicePath ) ;
}
while ( Props ) {
if ( Props - > Label ) {
FreePool ( Props - > Label ) ;
}
if ( Props - > Key ) {
FreePool ( Props - > Key ) ;
}
if ( Props - > Value ) {
FreePool ( Props - > Value ) ;
}
if ( Props - > DevicePath ) {
FreePool ( Props - > DevicePath ) ;
}
Next = Props - > Next ;
FreePool ( Props ) ;
2020-02-28 19:12:57 +01:00
//delete Props;
2019-09-03 11:58:42 +02:00
Props = Next ;
}
Next = Prop - > Next ;
FreePool ( Prop ) ;
Prop = Next ;
}
}
}
}
2020-03-25 19:32:44 +01:00
MsgLog ( " CurrentMode: Width=%lld Height=%lld \n " , UGAWidth , UGAHeight ) ;
2019-09-03 11:58:42 +02:00
}
EFI_STATUS
SaveSettings ( )
{
// TODO: SetVariable()..
// here we can apply user settings instead of default one
gMobile = gSettings . Mobile ;
if ( ( gSettings . BusSpeed ! = 0 ) & & ( gSettings . BusSpeed > 10 * kilo ) & & ( gSettings . BusSpeed < 500 * kilo ) ) {
switch ( gCPUStructure . Model ) {
case CPU_MODEL_PENTIUM_M :
case CPU_MODEL_ATOM : // Atom
case CPU_MODEL_DOTHAN : // Pentium M, Dothan, 90nm
case CPU_MODEL_YONAH : // Core Duo/Solo, Pentium M DC
case CPU_MODEL_MEROM : // Core Xeon, Core 2 Duo, 65nm, Mobile
//case CPU_MODEL_CONROE:// Core Xeon, Core 2 Duo, 65nm, Desktop like Merom but not mobile
case CPU_MODEL_CELERON :
case CPU_MODEL_PENRYN : // Core 2 Duo/Extreme, Xeon, 45nm , Mobile
case CPU_MODEL_NEHALEM : // Core i7 LGA1366, Xeon 5500, "Bloomfield", "Gainstown", 45nm
case CPU_MODEL_FIELDS : // Core i7, i5 LGA1156, "Clarksfield", "Lynnfield", "Jasper", 45nm
case CPU_MODEL_DALES : // Core i7, i5, Nehalem
case CPU_MODEL_CLARKDALE : // Core i7, i5, i3 LGA1156, "Westmere", "Clarkdale", , 32nm
case CPU_MODEL_WESTMERE : // Core i7 LGA1366, Six-core, "Westmere", "Gulftown", 32nm
case CPU_MODEL_NEHALEM_EX : // Core i7, Nehalem-Ex Xeon, "Beckton"
case CPU_MODEL_WESTMERE_EX : // Core i7, Nehalem-Ex Xeon, "Eagleton"
gCPUStructure . ExternalClock = gSettings . BusSpeed ;
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, kilo)));
break ;
default :
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gSettings.BusSpeed, kilo)));
// for sandy bridge or newer
// to match ExternalClock 25 MHz like real mac, divide BusSpeed by 4
gCPUStructure . ExternalClock = ( gSettings . BusSpeed + 3 ) / 4 ;
//DBG("Corrected ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, kilo)));
break ;
}
gCPUStructure . FSBFrequency = MultU64x64 ( gSettings . BusSpeed , kilo ) ; //kHz -> Hz
gCPUStructure . MaxSpeed = ( UINT32 ) ( DivU64x32 ( ( UINT64 ) gSettings . BusSpeed * gCPUStructure . MaxRatio , 10000 ) ) ; //kHz->MHz
}
if ( ( gSettings . CpuFreqMHz > 100 ) & & ( gSettings . CpuFreqMHz < 20000 ) ) {
gCPUStructure . MaxSpeed = gSettings . CpuFreqMHz ;
}
// to determine the use of Table 132
if ( gSettings . QPI ) {
gSettings . SetTable132 = TRUE ;
2020-04-23 18:05:21 +02:00
//DBG("QPI: use Table 132\n");
2019-09-03 11:58:42 +02:00
}
else {
switch ( gCPUStructure . Model ) {
case CPU_MODEL_NEHALEM : // Core i7 LGA1366, Xeon 5500, "Bloomfield", "Gainstown", 45nm
case CPU_MODEL_WESTMERE : // Core i7 LGA1366, Six-core, "Westmere", "Gulftown", 32nm
case CPU_MODEL_NEHALEM_EX : // Core i7, Nehalem-Ex Xeon, "Beckton"
case CPU_MODEL_WESTMERE_EX : // Core i7, Nehalem-Ex Xeon, "Eagleton"
gSettings . SetTable132 = TRUE ;
2020-04-23 18:05:21 +02:00
DBG ( " QPI: use Table 132 \n " ) ;
2019-09-03 11:58:42 +02:00
break ;
default :
2020-04-23 18:05:21 +02:00
//DBG("QPI: disable Table 132\n");
2019-09-03 11:58:42 +02:00
break ;
}
}
gCPUStructure . CPUFrequency = MultU64x64 ( gCPUStructure . MaxSpeed , Mega ) ;
return EFI_SUCCESS ;
}
CHAR16
* GetOtherKextsDir ( BOOLEAN On )
{
CHAR16 * SrcDir = NULL ;
2020-04-23 11:08:10 +02:00
SrcDir = PoolPrint ( L " %s \\ kexts \\ %a " , OEMPath , On ? " Other " : " Off " ) ;
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( SelfVolume - > RootDir , SrcDir ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( SrcDir ) ;
SrcDir = PoolPrint ( L " \\ EFI \\ CLOVER \\ kexts \\ %a " , On ? " Other " : " Off " ) ;
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( SelfVolume - > RootDir , SrcDir ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( SrcDir ) ;
2019-09-03 11:58:42 +02:00
SrcDir = NULL ;
}
}
return SrcDir ;
}
//dmazar
// caller is responsible for FreePool the result
CHAR16
* GetOSVersionKextsDir (
CHAR8 * OSVersion
)
{
CHAR16 * SrcDir = NULL ;
CHAR8 FixedVersion [ 16 ] ;
CHAR8 * DotPtr ;
if ( OSVersion ! = NULL ) {
AsciiStrnCpyS ( FixedVersion , 16 , OSVersion , 5 ) ;
2020-03-25 19:32:44 +01:00
// DBG("%s\n", FixedVersion);
2019-09-03 11:58:42 +02:00
// OSVersion may contain minor version too (can be 10.x or 10.x.y)
if ( ( DotPtr = AsciiStrStr ( FixedVersion , " . " ) ) ! = NULL ) {
DotPtr = AsciiStrStr ( DotPtr + 1 , " . " ) ; // second dot
}
if ( DotPtr ! = NULL ) {
* DotPtr = 0 ;
}
}
2020-03-25 19:32:44 +01:00
//MsgLog ("OS=%ls\n", OSTypeStr);
2019-09-03 11:58:42 +02:00
// find source injection folder with kexts
// note: we are just checking for existance of particular folder, not checking if it is empty or not
// check OEM subfolders: version specific or default to Other
2020-04-23 11:08:10 +02:00
SrcDir = PoolPrint ( L " %s \\ kexts \\ %a " , OEMPath , FixedVersion ) ;
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( SelfVolume - > RootDir , SrcDir ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( SrcDir ) ;
SrcDir = PoolPrint ( L " \\ EFI \\ CLOVER \\ kexts \\ %a " , FixedVersion ) ;
2019-09-03 11:58:42 +02:00
if ( ! FileExists ( SelfVolume - > RootDir , SrcDir ) ) {
2020-04-23 11:08:10 +02:00
FreePool ( SrcDir ) ;
2019-09-03 11:58:42 +02:00
SrcDir = NULL ;
}
}
return SrcDir ;
}
EFI_STATUS
InjectKextsFromDir (
EFI_STATUS Status ,
CHAR16 * SrcDir
)
{
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
MsgLog ( " - ERROR: Kext injection failed! \n " ) ;
return EFI_NOT_STARTED ;
}
return Status ;
}
2020-05-01 18:26:28 +02:00
EFI_STATUS LOADER_ENTRY : : SetFSInjection ( )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status ;
FSINJECTION_PROTOCOL * FSInject ;
CHAR16 * SrcDir = NULL ;
//BOOLEAN InjectionNeeded = FALSE;
//BOOLEAN BlockCaches = FALSE;
FSI_STRING_LIST * Blacklist = 0 ;
FSI_STRING_LIST * ForceLoadKexts = NULL ;
MsgLog ( " Beginning FSInjection \n " ) ;
// get FSINJECTION_PROTOCOL
Status = gBS - > LocateProtocol ( & gFSInjectProtocolGuid , NULL , ( void * * ) & FSInject ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-04-04 15:50:13 +02:00
//Print (L"- No FSINJECTION_PROTOCOL, Status = %s\n", strerror(Status));
2019-09-03 11:58:42 +02:00
MsgLog ( " - ERROR: gFSInjectProtocolGuid not found! \n " ) ;
return EFI_NOT_STARTED ;
}
// check if blocking of caches is needed
2020-05-01 18:26:28 +02:00
if ( OSFLAG_ISSET ( Flags , OSFLAG_NOCACHES ) | | LoadOptions . contains ( " -f " ) ) {
2019-09-03 11:58:42 +02:00
MsgLog ( " Blocking kext caches \n " ) ;
// BlockCaches = TRUE;
// add caches to blacklist
2020-05-01 18:26:28 +02:00
Blacklist = FSInject - > CreateStringList ( ) ;
2019-09-03 11:58:42 +02:00
if ( Blacklist = = NULL ) {
MsgLog ( " - ERROR: Not enough memory! \n " ) ;
return EFI_NOT_STARTED ;
}
/*
From 10.7 to 10.9 , status of directly restoring ESD files or update from Appstore cannot block kernel cache . because there are boot . efi and kernelcache file without kernel file .
After macOS installed , boot . efi can call kernel file from S / L / Kernels .
For this reason , long time ago , chameleon ' s user restored Base System . dmg to made USB installer and added kernel file in root and custom kexts in S / L / E . then used " -f " option .
From 10.10 + , boot . efi call only prelinkedkernel file without kernel file . we can never block only kernelcache .
The use of these block caches is meaningless in modern macOS . Unlike the old days , we do not have to do the tedious task of putting the files needed for booting into the S / L / E .
Caution ! Do not add this list . If add this list , will see " Kernel cache load error (0xe) " . This is just a guideline .
by Sherlocks , 2017.11
*/
// Installed/createinstallmedia
//FSInject->AddStringToList(Blacklist, L"\\System\\Library\\PrelinkedKernels\\prelinkedkernel"); // 10.10+/10.13.4+
// Recovery
//FSInject->AddStringToList(Blacklist, L"\\com.apple.recovery.boot\\kernelcache"); // 10.7 - 10.10
//FSInject->AddStringToList(Blacklist, L"\\com.apple.recovery.boot\\prelinkedkernel"); // 10.11+
// BaseSytem/InstallESD
//FSInject->AddStringToList(Blacklist, L"\\kernelcache"); // 10.7 - 10.9/(10.7/10.8)
// 1st stage - createinstallmedia
//FSInject->AddStringToList(Blacklist, L"\\.IABootFiles\\kernelcache"); // 10.9/10.10
//FSInject->AddStringToList(Blacklist, L"\\.IABootFiles\\prelinkedkernel"); // 10.11 - 10.13.3
// 2nd stage - InstallESD/AppStore/startosinstall
//FSInject->AddStringToList(Blacklist, L"\\Mac OS X Install Data\\kernelcache"); // 10.7
//FSInject->AddStringToList(Blacklist, L"\\OS X Install Data\\kernelcache"); // 10.8 - 10.10
//FSInject->AddStringToList(Blacklist, L"\\OS X Install Data\\prelinkedkernel"); // 10.11
//FSInject->AddStringToList(Blacklist, L"\\macOS Install Data\\prelinkedkernel"); // 10.12 - 10.12.3
//FSInject->AddStringToList(Blacklist, L"\\macOS Install Data\\Locked Files\\Boot Files\\prelinkedkernel");// 10.12.4+
// 2nd stage - Fusion Drive
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.R\\System\\Library\\PrelinkedKernels\\prelinkedkernel"); // 10.11
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.P\\System\\Library\\PrelinkedKernels\\prelinkedkernel"); // 10.11
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.S\\System\\Library\\PrelinkedKernels\\prelinkedkernel"); // 10.11
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.R\\prelinkedkernel"); // 10.12+
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.P\\prelinkedkernel"); // 10.12+
//FSInject->AddStringToList(Blacklist, L"\\com.apple.boot.S\\prelinkedkernel"); // 10.12+
// NetInstall
//FSInject->AddStringToList(Blacklist, L"\\NetInstall macOS High Sierra.nbi\\i386\\x86_64\\kernelcache");
// Block Caches list
// InstallDVD/Installed
FSInject - > AddStringToList ( Blacklist , L " \\ System \\ Library \\ Caches \\ com.apple.kext.caches \\ Startup \\ Extensions.mkext " ) ; // 10.6
FSInject - > AddStringToList ( Blacklist , L " \\ System \\ Library \\ Extensions.mkext " ) ; // 10.6
FSInject - > AddStringToList ( Blacklist , L " \\ System \\ Library \\ Caches \\ com.apple.kext.caches \\ Startup \\ kernelcache " ) ; // 10.6/10.6 - 10.9
if ( gSettings . BlockKexts [ 0 ] ! = L ' \0 ' ) {
2020-04-23 11:08:10 +02:00
FSInject - > AddStringToList ( Blacklist , PoolPrint ( L " \\ System \\ Library \\ Extensions \\ %s " , gSettings . BlockKexts ) ) ;
2019-09-03 11:58:42 +02:00
}
}
// check if kext injection is needed
// (will be done only if caches are blocked or if boot.efi refuses to load kernelcache)
//SrcDir = NULL;
2020-05-01 18:26:28 +02:00
if ( OSFLAG_ISSET ( Flags , OSFLAG_WITHKEXTS ) ) {
2019-09-03 11:58:42 +02:00
SrcDir = GetOtherKextsDir ( TRUE ) ;
2020-05-01 18:26:28 +02:00
Status = FSInject - > Install (
2019-09-03 11:58:42 +02:00
Volume - > DeviceHandle ,
L " \\ System \\ Library \\ Extensions " ,
SelfVolume - > DeviceHandle ,
//GetOtherKextsDir (),
SrcDir ,
Blacklist ,
ForceLoadKexts
) ;
//InjectKextsFromDir(Status, GetOtherKextsDir());
InjectKextsFromDir ( Status , SrcDir ) ;
2020-04-23 11:08:10 +02:00
FreePool ( SrcDir ) ;
2019-09-03 11:58:42 +02:00
2020-05-01 18:26:28 +02:00
SrcDir = GetOSVersionKextsDir ( OSVersion ) ;
Status = FSInject - > Install (
2019-09-03 11:58:42 +02:00
Volume - > DeviceHandle ,
L " \\ System \\ Library \\ Extensions " ,
SelfVolume - > DeviceHandle ,
2020-05-01 18:26:28 +02:00
//GetOSVersionKextsDir(OSVersion),
2019-09-03 11:58:42 +02:00
SrcDir ,
Blacklist ,
ForceLoadKexts
) ;
2020-05-01 18:26:28 +02:00
//InjectKextsFromDir(Status, GetOSVersionKextsDir(OSVersion));
2019-09-03 11:58:42 +02:00
InjectKextsFromDir ( Status , SrcDir ) ;
FreePool ( SrcDir ) ;
} else {
2020-05-01 18:26:28 +02:00
MsgLog ( " skipping kext injection (not requested) \n " ) ;
2019-09-03 11:58:42 +02:00
}
// prepare list of kext that will be forced to load
2020-05-01 18:26:28 +02:00
ForceLoadKexts = FSInject - > CreateStringList ( ) ;
2019-09-03 11:58:42 +02:00
if ( ForceLoadKexts = = NULL ) {
2020-05-01 18:26:28 +02:00
MsgLog ( " - Error: not enough memory! \n " ) ;
2019-09-03 11:58:42 +02:00
return EFI_NOT_STARTED ;
}
2020-05-01 18:26:28 +02:00
KextPatcherRegisterKexts ( FSInject , ForceLoadKexts ) ;
2019-09-03 11:58:42 +02:00
// reinit Volume->RootDir? it seems it's not needed.
return Status ;
}