2019-09-03 11:58:42 +02:00
/*
Slice 2012
*/
2020-10-12 16:49:43 +02:00
# include <Platform.h>
2021-02-06 18:16:46 +01:00
# include "Settings.h"
# include "FixBiosDsdt.h"
# include "../include/VolumeTypes.h"
# include "../include/OSFlags.h"
# include "../include/OSTypes.h"
# include "../include/BootTypes.h"
2020-04-11 08:21:06 +02:00
# include "../entry_scan/loader.h"
2021-02-06 18:16:46 +01:00
# include "../Platform/BootLog.h"
# include "../entry_scan/secureboot.h"
# include "../libeg/XTheme.h"
# include "cpu.h"
# include "VersionString.h"
2020-04-16 09:15:26 +02:00
# include "card_vlist.h"
# include "Injectors.h"
2020-04-16 11:09:22 +02:00
# include "../include/Pci.h"
# include "../include/Devices.h"
2021-02-06 18:16:46 +01:00
# include "smbios.h"
2020-10-03 19:02:31 +02:00
# include "Net.h"
2021-02-06 18:16:46 +01:00
# include "Nvram.h"
# include "BootOptions.h"
# include "SelfOem.h"
# include "ati_reg.h"
# include "ati.h"
# include "nvidia.h"
# include "gma.h"
# include "Edid.h"
# include "hda.h"
2021-02-07 07:15:09 +01:00
# include "../../Version.h"
2020-07-15 19:29:27 +02:00
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
//SYSVARIABLES *SysVariables;
CHAR16 * IconFormat = NULL ;
2020-08-25 17:35:19 +02:00
TagDict * gConfigDict [ NUM_OF_CONFIGS ] = { NULL , NULL , NULL } ;
2019-09-03 11:58:42 +02:00
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
2020-08-31 09:22:11 +02:00
XStringWArray ThemeNameArray ;
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 ] ;
2020-08-31 09:07:36 +02:00
XObjArray < HDA_OUTPUTS > AudioList ;
2020-08-31 08:22:21 +02:00
XObjArray < RT_VARIABLES > BlockRtVariableArray ;
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 ;
// 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
2021-02-06 18:16:46 +01:00
CONST CHAR16 * gFirmwareRevision = L " unknown " ;
2020-04-16 14:24:21 +02:00
CONST CHAR8 * gRevisionStr = " unknown " ;
CONST CHAR8 * gFirmwareBuildDate = " unknown " ;
CONST CHAR8 * gBuildInfo = NULL ;
2020-04-16 09:15:26 +02:00
# endif
2020-10-07 18:57:34 +02:00
# ifdef BUILD_ID
2020-10-28 18:11:50 +01:00
const LString8 gBuildId __attribute__ ( ( used ) ) = BUILD_ID ;
2020-10-23 08:04:01 +02:00
const LString8 gBuildIdGrepTag __attribute__ ( ( used ) ) = " CloverBuildIdGrepTag: " BUILD_ID ;
2020-10-07 18:57:34 +02:00
# else
2020-10-28 18:11:50 +01:00
const LString8 gBuildId __attribute__ ( ( used ) ) = " unknown " ;
2020-10-23 08:04:01 +02:00
const LString8 gBuildIdGrepTag __attribute__ ( ( used ) ) = " CloverBuildIdGrepTag: " " unknown " ;
2020-10-07 18:57:34 +02:00
# endif
2020-04-16 09:15:26 +02:00
2020-10-20 21:50:30 +02:00
// __attribute__((used)) seems to not always work. So, in AboutRefit(), there is a trick to let the compiler thinks it's used.
2020-10-28 18:11:50 +01:00
const LString8 path_independant __attribute__ ( ( used ) ) = " path_independant " ;
2020-10-03 19:02:31 +02:00
2020-04-16 09:15:26 +02:00
EMU_VARIABLE_CONTROL_PROTOCOL * gEmuVariableControl = NULL ;
2019-09-03 11:58:42 +02:00
// global configuration with default values
2020-08-09 17:55:30 +02:00
REFIT_CONFIG GlobalConfig ;
2019-09-03 11:58:42 +02:00
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 }
} ;
2021-02-06 18:16:46 +01:00
CONST CHAR8 * AudioOutputNames [ ] = {
" LineOut " ,
" Speaker " ,
" Headphones " ,
" SPDIF " ,
" Garniture " ,
" HDMI " ,
" Other "
} ;
EFI_STATUS
SaveSettings ( ) ;
2020-02-23 06:53:21 +01:00
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 ;
}
2019-09-03 11:58:42 +02:00
ACPI_NAME_LIST *
2020-08-15 15:47:56 +02:00
ParseACPIName ( const XString8 & String )
2019-09-03 11:58:42 +02:00
{
ACPI_NAME_LIST * List = NULL ;
ACPI_NAME_LIST * Next = NULL ;
INTN i , j , Len , pos0 , pos1 ;
2020-08-15 15:47:56 +02:00
Len = String . length ( ) ;
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 ) {
2020-08-15 15:47:56 +02:00
List = ( __typeof__ ( List ) ) AllocateZeroPool ( sizeof ( ACPI_NAME_LIST ) ) ;
2019-09-03 11:58:42 +02:00
List - > Next = Next ;
2020-08-15 15:47:56 +02: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 + + ) {
2020-11-02 14:45:11 +01:00
List - > Name [ j + + ] = String . data ( ) [ i ] ; // String[i] return a char32_t. what if there is an utf8 char ?
2019-09-03 11:58:42 +02:00
}
// 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 ;
}
2020-10-03 19:02:31 +02:00
void
2019-09-03 11:58:42 +02:00
ParseLoadOptions (
2020-08-09 17:55:30 +02:00
OUT XStringW * ConfNamePtr ,
2020-08-25 17:35:19 +02:00
OUT TagDict * * Dict
2019-09-03 11:58:42 +02:00
)
{
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 ;
* Dict = NULL ;
2020-08-09 17:55:30 +02:00
XStringW & ConfName = * ConfNamePtr ;
2020-09-28 17:57:50 +02:00
Start = ( CHAR8 * ) self . getSelfLoadedImage ( ) . LoadOptions ;
End = ( CHAR8 * ) ( ( CHAR8 * ) self . getSelfLoadedImage ( ) . LoadOptions + self . getSelfLoadedImage ( ) . LoadOptionsSize ) ;
2019-09-03 11:58:42 +02:00
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-08-25 17:35:19 +02:00
if ( ParseXML ( Start , Dict , 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-08-09 17:55:30 +02:00
ConfName . strncpy ( Start , TailSize + 1 ) ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
2019-09-03 11:58:42 +02:00
//
2020-09-28 17:57:50 +02:00
// analyze self.getSelfLoadedImage().LoadOptions to extract Default Volume and Default Loader
2019-09-03 11:58:42 +02:00
// input and output data are global
//
2020-10-03 19:02:31 +02:00
void
GetBootFromOption ( void )
2019-09-03 11:58:42 +02:00
{
2020-09-28 17:57:50 +02:00
UINT8 * Data = ( UINT8 * ) self . getSelfLoadedImage ( ) . LoadOptions ;
UINTN Len = self . getSelfLoadedImage ( ) . LoadOptionsSize ;
2019-09-03 11:58:42 +02:00
UINTN NameSize , Name2Size ;
Data + = 4 ; //skip signature as we already here
NameSize = * ( UINT16 * ) Data ;
Data + = 2 ; // pointer to Volume name
2021-02-02 10:02:21 +01:00
gSettings . Boot . DefaultVolume . strncpy ( ( __typeof__ ( gSettings . Boot . DefaultVolume . wc_str ( ) ) ) Data , NameSize ) ;
2019-09-03 11:58:42 +02:00
Data + = NameSize ;
Name2Size = Len - NameSize ;
if ( Name2Size ! = 0 ) {
2021-02-02 10:02:21 +01:00
gSettings . Boot . DefaultLoader . strncpy ( ( __typeof__ ( gSettings . Boot . DefaultVolume . wc_str ( ) ) ) Data , NameSize ) ;
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 " ,
2021-02-02 10:02:21 +01:00
gSettings . Boot . DefaultLoader . notEmpty ( ) ? gSettings . Boot . DefaultLoader . wc_str ( ) : L " legacy " ,
gSettings . Boot . DefaultVolume . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
//
// check if this entry corresponds to Boot# variable and then set BootCurrent
//
2020-10-03 19:02:31 +02:00
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 ;
2020-08-09 17:55:30 +02:00
XStringW VarName ;
2019-09-03 11:58:42 +02:00
UINTN VarSize = 0 ;
UINT8 * BootVariable ;
UINTN NameSize ;
UINT8 * Data ;
UINT16 * BootOrder ;
UINT16 * BootOrderNew ;
UINT16 * Ptr ;
UINTN BootOrderSize ;
INTN BootIndex = 0 , Index ;
2020-08-09 17:55:30 +02:00
VarName = SWPrintf ( " Boot%04llX " , Entry - > BootNum ) ;
BootVariable = ( UINT8 * ) GetNvramVariable ( VarName . wc_str ( ) , & gEfiGlobalVariableGuid , NULL , & VarSize ) ;
2019-09-03 11:58:42 +02:00
if ( ( BootVariable = = NULL ) | | ( VarSize = = 0 ) ) {
2020-08-09 17:55:30 +02:00
DBG ( " Boot option %ls not found \n " , VarName . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
return ;
}
//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 ;
2020-08-09 17:55:30 +02:00
if ( StriCmp ( ( CHAR16 * ) Data , Entry - > Volume - > VolName . wc_str ( ) ) ! = 0 ) {
2021-02-06 18:16:46 +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-10-18 05:04:08 +02: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-08-25 17:35:19 +02:00
DBG ( " Can't save BootCurrent, status=%s \n " , efiStrError ( 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-08-25 17:35:19 +02:00
DBG ( " Can't save BootOrder, status=%s \n " , efiStrError ( 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
//
2021-02-06 18:16:46 +01:00
static UINT8
2019-09-03 11:58:42 +02:00
* GetDataSetting (
2020-08-25 17:35:19 +02:00
IN const TagDict * Dict ,
2020-02-17 21:41:09 +01:00
IN CONST CHAR8 * PropName ,
2020-08-18 18:45:44 +02:00
OUT UINTN * DataLen
2019-09-03 11:58:42 +02:00
)
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2019-09-03 11:58:42 +02:00
UINT8 * Data = NULL ;
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( PropName ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isData ( ) /*&& Prop->dataLen > 0*/ ) { //rehabman: allow zero length data
2019-09-03 11:58:42 +02:00
// data property
2020-08-25 17:35:19 +02:00
Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Prop - > getData ( ) - > dataLenValue ( ) ) ;
CopyMem ( Data , Prop - > getData ( ) - > dataValue ( ) , Prop - > getData ( ) - > dataLenValue ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( DataLen ! = NULL ) * DataLen = Prop - > getData ( ) - > dataLenValue ( ) ;
2019-09-03 11:58:42 +02:00
/*
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
*/
2020-08-18 18:45:44 +02:00
} else if ( Prop - > isString ( ) ) {
2019-09-03 11:58:42 +02:00
// assume data in hex encoded string property
2020-08-25 17:35:19 +02:00
UINT32 Len = ( UINT32 ) Prop - > getString ( ) - > stringValue ( ) . length ( ) > > 1 ; // number of hex digits
2020-08-15 15:47:56 +02:00
Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Len ) ; // 2 chars per byte, one more byte for odd number
2020-08-25 17:35:19 +02:00
Len = hex2bin ( Prop - > getString ( ) - > stringValue ( ) . c_str ( ) , Data , Len ) ;
2019-09-03 11:58:42 +02:00
2020-08-19 15:56:19 +02:00
if ( DataLen ! = NULL ) * DataLen = Len ;
2019-09-03 11:58:42 +02:00
/*
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
*/
2020-08-18 18:45:44 +02:00
} else {
MsgLog ( " ATTENTION : PropName '%s' is not data or string. Ignored " , PropName ) ;
if ( DataLen ! = NULL ) * DataLen = 0 ;
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +02:00
} else {
if ( DataLen ! = NULL ) * DataLen = 0 ;
2019-09-03 11:58:42 +02:00
}
2020-08-19 15:56:19 +02:00
return Data ;
2019-09-03 11:58:42 +02:00
}
EFI_STATUS
LoadUserSettings (
2020-08-09 17:55:30 +02:00
IN const XStringW & ConfName ,
2020-08-25 17:35:19 +02:00
TagDict * * Dict )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status = EFI_NOT_FOUND ;
UINTN Size = 0 ;
2020-08-19 09:52:07 +02:00
CHAR8 * ConfigPtr = NULL ;
2020-10-03 19:02:31 +02:00
// XStringW ConfigPlistPath;
// XStringW ConfigOemPath;
2019-09-03 11:58:42 +02:00
// DbgHeader("LoadUserSettings");
// load config
2020-08-09 17:55:30 +02:00
if ( ConfName . isEmpty ( ) | | Dict = = NULL ) {
2019-09-03 11:58:42 +02:00
return EFI_NOT_FOUND ;
}
2020-10-03 19:02:31 +02:00
// ConfigPlistPath = SWPrintf("%ls.plist", ConfName.wc_str());
// ConfigOemPath = SWPrintf("%ls\\%ls.plist", selfOem.getOOEMPath.wc_str(), ConfName.wc_str());
2020-10-17 15:01:33 +02:00
Status = EFI_NOT_FOUND ;
2020-10-03 19:02:31 +02:00
XStringW configFilename = SWPrintf ( " %ls.plist " , ConfName . wc_str ( ) ) ;
2020-10-17 15:01:33 +02:00
if ( selfOem . oemDirExists ( ) ) {
if ( FileExists ( & selfOem . getOemDir ( ) , configFilename ) ) {
Status = egLoadFile ( & selfOem . getOemDir ( ) , configFilename . wc_str ( ) , ( UINT8 * * ) & ConfigPtr , & Size ) ;
if ( EFI_ERROR ( Status ) ) {
DBG ( " Cannot find %ls at path (%s): '%ls', trying '%ls' \n " , configFilename . wc_str ( ) , efiStrError ( Status ) , selfOem . getOemFullPath ( ) . wc_str ( ) , self . getCloverDirFullPath ( ) . wc_str ( ) ) ;
} else {
DBG ( " Using %ls at path: %ls \n " , configFilename . wc_str ( ) , selfOem . getOemFullPath ( ) . wc_str ( ) ) ;
}
}
2019-09-03 11:58:42 +02:00
}
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2020-10-03 19:02:31 +02:00
if ( FileExists ( & self . getCloverDir ( ) , configFilename . wc_str ( ) ) ) {
Status = egLoadFile ( & self . getCloverDir ( ) , configFilename . wc_str ( ) , ( UINT8 * * ) & ConfigPtr , & Size ) ;
2019-09-03 11:58:42 +02:00
}
2020-10-17 15:01:33 +02:00
if ( EFI_ERROR ( Status ) ) {
DBG ( " Cannot find %ls at path '%ls' : %s \n " , configFilename . wc_str ( ) , self . getCloverDirFullPath ( ) . wc_str ( ) , efiStrError ( Status ) ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-10-17 15:01:33 +02:00
DBG ( " Using %ls at path: %ls \n " , configFilename . wc_str ( ) , self . getCloverDirFullPath ( ) . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-19 09:52:07 +02:00
if ( ! EFI_ERROR ( Status ) & & ConfigPtr ! = NULL ) {
2020-08-25 17:35:19 +02:00
Status = ParseXML ( ( const CHAR8 * ) ConfigPtr , Dict , Size ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// Dict = NULL;
2020-08-25 17:35:19 +02:00
DBG ( " config.plist parse error Status=%s \n " , efiStrError ( Status ) ) ;
2019-09-03 11:58:42 +02:00
return Status ;
}
}
2020-08-25 17:35:19 +02:00
// free configPtr ?
2019-09-03 11:58:42 +02:00
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 ;
}
STATIC
CUSTOM_LOADER_ENTRY
* DuplicateCustomEntry (
IN CUSTOM_LOADER_ENTRY * Entry
)
{
if ( Entry = = NULL ) {
return NULL ;
}
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 ) {
2020-08-09 17:55:30 +02:00
DuplicateEntry - > Volume = Entry - > Volume ;
DuplicateEntry - > Path = Entry - > Path ;
DuplicateEntry - > LoadOptions = Entry - > LoadOptions ;
DuplicateEntry - > FullTitle = Entry - > FullTitle ;
DuplicateEntry - > Title = Entry - > Title ;
DuplicateEntry - > ImagePath = Entry - > ImagePath ;
DuplicateEntry - > DriveImagePath = Entry - > DriveImagePath ;
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-08-12 17:15:47 +02:00
// CopyKernelAndKextPatches (&DuplicateEntry->KernelAndKextPatches, &Entry->KernelAndKextPatches);
DuplicateEntry - > KernelAndKextPatches = Entry - > KernelAndKextPatches ;
2019-09-03 11:58:42 +02:00
}
return DuplicateEntry ;
}
STATIC
BOOLEAN
FillinKextPatches ( IN OUT KERNEL_AND_KEXT_PATCHES * Patches ,
2020-08-25 17:35:19 +02:00
const TagDict * DictPointer )
2019-09-03 11:58:42 +02:00
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2020-08-25 17:35:19 +02:00
const TagArray * arrayProp ;
2019-09-03 11:58:42 +02:00
// UINTN i;
if ( Patches = = NULL | | DictPointer = = NULL ) {
return FALSE ;
}
2020-10-08 22:03:41 +02:00
// Prop = DictPointer->propertyForKey("OcFuzzyMatch");
//if ( Prop ) panic("config.plist/KernelAndKextPatches/OcFuzzyMatch has been moved in section config.plist/Quirks. Update your config.plist");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->FuzzyMatch = IsPropertyNotNullAndTrue(Prop);
// }
//
2020-10-08 22:03:41 +02:00
// Prop = DictPointer->propertyForKey("OcKernelCache");
//if ( Prop ) panic("config.plist/KernelAndKextPatches/OcKernelCache has been moved in section config.plist/Quirks. Update your config.plist");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// if ( Prop->isString() ) {
// if ( Prop->getString()->stringValue().notEmpty() ) {
// Patches->OcKernelCache = Prop->getString()->stringValue();
// }else{
// Patches->OcKernelCache = "Auto"_XS8;
// }
// }else{
// MsgLog("MALFORMED PLIST : KernelAndKextPatches/KernelCache must be a string");
// Patches->OcKernelCache = "Auto"_XS8;
// }
// }
2020-09-07 19:33:38 +02:00
{
2020-10-03 16:16:11 +02:00
// const TagDict* OcQuirksDict = DictPointer->dictPropertyForKey("OcQuirks");
//if ( OcQuirksDict ) panic("config.plist/KernelAndKextPatches/OcQuirks has been merged in the config.plist/Quirks section. Update your config.plist");
2020-09-30 20:56:55 +02:00
// if ( OcQuirksDict )
// {
// Prop = OcQuirksDict->propertyForKey("AppleCpuPmCfgLock");
//if ( !Prop ) panic("Cannot find AppleCpuPmCfgLock in OcQuirks under KernelAndKextPatches (OC kernel quirks)");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.AppleCpuPmCfgLock = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("AppleXcpmCfgLock");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.AppleXcpmCfgLock = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("AppleXcpmExtraMsrs");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.AppleXcpmExtraMsrs = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("AppleXcpmForceBoost");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.AppleXcpmForceBoost = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("CustomSMBIOSGuid");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.CustomSmbiosGuid = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("DisableIoMapper");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.DisableIoMapper = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("DisableLinkeditJettison");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.DisableLinkeditJettison = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("DisableRtcChecksum");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.DisableRtcChecksum = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("DummyPowerManagement");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.DummyPowerManagement = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("ExternalDiskIcons");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.ExternalDiskIcons = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("IncreasePciBarSize");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.IncreasePciBarSize = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("LapicKernelPanic");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.LapicKernelPanic = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("PanicNoKextDump");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.PanicNoKextDump = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("PowerTimeoutKernelPanic");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.PowerTimeoutKernelPanic = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("ThirdPartyDrives");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.ThirdPartyDrives = IsPropertyNotNullAndTrue(Prop);
// }
//
// Prop = OcQuirksDict->propertyForKey("XhciPortLimit");
2021-02-06 18:16:46 +01:00
// if (Prop != NULL || GlobalConfig.gBootChanged) {
2020-09-30 20:56:55 +02:00
// Patches->OcKernelQuirks.XhciPortLimit = IsPropertyNotNullAndTrue(Prop);
// }
// }
2020-09-07 19:33:38 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Debug " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPDebug = IsPropertyNotNullAndTrue ( 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 " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " KernelLapic " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPKernelLapic = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " KernelXCPM " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPKernelXCPM = IsPropertyNotNullAndTrue ( Prop ) ;
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
DBG ( " KernelXCPM: enabled \n " ) ;
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " KernelPm " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPKernelPm = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " PanicNoKextDump " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPPanicNoKextDump = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " AppleIntelCPUPM " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPAppleIntelCPUPM = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-05-04 21:31:12 +02:00
//anyway
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . NeedPMfix ) {
2020-05-04 21:31:12 +02:00
Patches - > KPKernelPm = TRUE ;
Patches - > KPAppleIntelCPUPM = TRUE ;
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " AppleRTC " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > KPAppleRTC = ! IsPropertyNotNullAndFalse ( Prop ) ; //default = TRUE
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " EightApple " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > EightApple = IsPropertyNotNullAndTrue ( Prop ) ;
2020-05-27 20:04:31 +02:00
}
2019-09-03 11:58:42 +02:00
//
// Dell SMBIOS Patch
//
2021-02-06 18:16:46 +01:00
// syscl: we do not need GlobalConfig.gBootChanged and Prop is empty condition
2019-09-03 11:58:42 +02:00
// this change will boost Dell SMBIOS Patch a bit
// but the major target is to make code clean
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " DellSMBIOSPatch " ) ;
2020-08-22 15:39:24 +02:00
Patches - > KPDELLSMBIOS = IsPropertyNotNullAndTrue ( Prop ) ; // default == FALSE
2019-09-03 11:58:42 +02:00
gRemapSmBiosIsRequire = Patches - > KPDELLSMBIOS ;
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " FakeCPUID " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-08-22 15:39:24 +02:00
Patches - > FakeCPUID = ( UINT32 ) GetPropertyAsInteger ( 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " ATIConnectorsController " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & Prop - > isString ( ) ) {
2019-09-03 11:58:42 +02:00
UINTN len = 0 , i = 0 ;
// ATIConnectors patch
2020-08-25 17:35:19 +02:00
Patches - > KPATIConnectorsController = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
UINT8 * p = GetDataSetting ( DictPointer , " ATIConnectorsData " , & len ) ;
Patches - > KPATIConnectorsData . stealValueFrom ( p , len ) ;
p = GetDataSetting ( DictPointer , " ATIConnectorsPatch " , & i ) ;
Patches - > KPATIConnectorsPatch . stealValueFrom ( p , i ) ;
2019-09-03 11:58:42 +02:00
2020-08-30 21:53:40 +02:00
if ( Patches - > KPATIConnectorsData . isEmpty ( )
| | Patches - > KPATIConnectorsPatch . isEmpty ( )
2020-08-12 17:15:47 +02:00
| | Patches - > KPATIConnectorsData . size ( ) = = 0
| | Patches - > KPATIConnectorsData . size ( ) ! = i ) {
2019-09-03 11:58:42 +02:00
// 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
2020-08-12 17:15:47 +02:00
Patches - > KPATIConnectorsController . setEmpty ( ) ;
Patches - > KPATIConnectorsData . setEmpty ( ) ;
Patches - > KPATIConnectorsPatch . setEmpty ( ) ;
Patches - > KPATIConnectorsController . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-22 15:39:24 +02:00
/*
* ForceKextsToLoad is an array of string
*/
2020-08-25 17:35:19 +02:00
arrayProp = DictPointer - > arrayPropertyForKey ( " ForceKextsToLoad " ) ;
if ( arrayProp ! = NULL ) {
INTN i ;
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
if ( Count > 0 ) {
const TagStruct * Prop2 = NULL ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
DBG ( " ForceKextsToLoad: %lld requested \n " , Count ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
for ( i = 0 ; i < Count ; i + + ) {
Prop2 = & arrayProp - > arrayContent ( ) [ i ] ;
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ForceKextsToLoad \n " ) ;
continue ;
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
const CHAR8 * p = Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ;
if ( * p = = ' \\ ' ) {
+ + p ;
}
2020-08-22 15:39:24 +02:00
2021-02-06 18:16:46 +01:00
if ( strlen ( p ) > 1 ) {
2020-08-25 17:35:19 +02:00
Patches - > ForceKexts . Add ( p ) ;
DBG ( " - [%zu]: %ls \n " , Patches - > ForceKexts . size ( ) , Patches - > ForceKexts [ Patches - > ForceKexts . size ( ) - 1 ] . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
2020-08-22 15:39:24 +02:00
// KextsToPatch is an array of dict
2020-08-25 17:35:19 +02:00
arrayProp = DictPointer - > arrayPropertyForKey ( " KextsToPatch " ) ;
if ( arrayProp ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2020-08-12 17:15:47 +02:00
Patches - > KextPatches . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2020-08-25 17:35:19 +02:00
const TagDict * Prop2 = NULL ;
2020-08-19 14:50:26 +02:00
const TagStruct * Dict = NULL ;
2019-09-03 11:58:42 +02:00
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 + + ) {
2019-10-08 22:57:18 +02:00
UINTN FindLen = 0 , ReplaceLen = 0 , MaskLen = 0 ;
2020-08-25 17:35:19 +02:00
Prop2 = arrayProp - > dictElementAt ( i ) ;
2020-08-19 15:56:19 +02:00
if ( ! Prop2 - > isDict ( ) ) {
2021-02-06 18:16:46 +01:00
MsgLog ( " ATTENTION : property not dict in KextsToPatch \n " ) ;
2020-08-18 18:45:44 +02:00
continue ;
}
2020-04-25 18:18:18 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " Name " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict = = NULL ) {
DBG ( " patch without Name, skipped \n " ) ;
continue ;
}
2020-08-18 18:45:44 +02:00
if ( ! Dict - > isString ( ) ) {
2021-02-06 18:16:46 +01:00
MsgLog ( " ATTENTION : Name property not string in KextsToPatch \n " ) ;
2020-08-18 18:45:44 +02:00
continue ;
}
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
KEXT_PATCH * newPatchPtr = new KEXT_PATCH ( ) ;
KEXT_PATCH & newPatch = * newPatchPtr ;
2020-08-25 17:35:19 +02:00
newPatch . Name = Dict - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
newPatch . Label . takeValueFrom ( newPatch . Name ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " Comment " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict ! = NULL ) {
2020-08-12 17:15:47 +02:00
newPatch . Label + = " ( " ;
2020-08-25 17:35:19 +02:00
newPatch . Label + = Dict - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
newPatch . Label + = " ) " ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-12 17:15:47 +02:00
newPatch . Label + = " (NoLabel) " ;
2019-09-03 11:58:42 +02:00
}
2020-08-12 17:15:47 +02:00
DBG ( " %s " , newPatch . Label . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-10-08 22:03:41 +02:00
// newPatch.MenuItem.BValue = TRUE;
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " Disabled " ) ;
2020-10-08 22:03:41 +02:00
newPatch . MenuItem . BValue = ! IsPropertyNotNullAndTrue ( Dict ) ; //if absent then false, BValue = !Disabled
// if ((Dict != NULL) && IsPropertyNotNullAndTrue(Dict)) {
// newPatch.MenuItem.BValue = FALSE;
// }
2020-04-25 18:18:18 +02:00
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " RangeFind " ) ;
2020-08-22 15:39:24 +02:00
newPatch . SearchLen = GetPropertyAsInteger ( Dict , 0 ) ; //default 0 will be calculated later
2020-10-08 22:03:41 +02:00
Dict = Prop2 - > propertyForKey ( " Skip " ) ;
newPatch . Skip = GetPropertyAsInteger ( Dict , 0 ) ; //default 0 will be calculated later
2020-08-12 17:15:47 +02:00
UINT8 * TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
2020-04-25 18:18:18 +02:00
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newPatch . StartPattern . stealValueFrom ( TmpData , FindLen ) ;
2020-04-25 18:18:18 +02:00
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-08-12 17:15:47 +02:00
newPatch . StartMask . memset ( 0xFF , FindLen ) ;
2020-04-25 18:18:18 +02:00
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newPatch . StartMask . ncpy ( TmpData , ReplaceLen ) ;
2020-04-25 18:18:18 +02:00
}
}
if ( TmpData ! = NULL ) {
FreePool ( TmpData ) ;
}
2019-09-03 11:58:42 +02:00
TmpData = GetDataSetting ( Prop2 , " Find " , & FindLen ) ;
2020-08-12 17:15:47 +02:00
UINT8 * TmpPatch = GetDataSetting ( Prop2 , " Replace " , & ReplaceLen ) ;
2019-09-03 11:58:42 +02:00
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
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " Procedure " ) ;
2020-08-18 18:45:44 +02:00
if ( Dict ! = NULL ) {
2021-02-06 18:16:46 +01:00
if ( Dict - > isString ( ) ) {
newPatch . ProcedureName = Dict - > getString ( ) - > stringValue ( ) ;
} else {
MsgLog ( " ATTENTION : Procedure property not string in KextsToPatch \n " ) ;
}
2020-04-27 17:16:43 +02:00
}
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
newPatch . Data . stealValueFrom ( TmpData , FindLen ) ;
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 ) {
} else {
2020-11-02 14:45:11 +01:00
newPatch . MaskFind . memset ( 0xFF , FindLen ) ;
2020-08-12 17:15:47 +02:00
newPatch . MaskFind . ncpy ( TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
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-08-12 17:15:47 +02:00
newPatch . Patch . memset ( 0 , FindLen ) ;
2020-04-24 11:01:28 +02:00
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
2020-08-12 17:15:47 +02:00
newPatch . Patch . ncpy ( TmpPatch , ReplaceLen ) ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpPatch ) ;
2020-08-12 17:15:47 +02:00
2019-10-08 22:57:18 +02:00
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 ) {
} else {
2020-08-12 17:15:47 +02:00
newPatch . MaskReplace . memset ( 0 , FindLen ) ;
newPatch . MaskReplace . ncpy ( TmpData , MaskLen ) ; //other bytes are zeros, means no replace
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-10-06 22:02:14 +02:00
newPatch . Count = 1 ;
Dict = Prop2 - > propertyForKey ( " Count " ) ;
if ( Dict ! = NULL ) {
newPatch . Count = GetPropertyAsInteger ( Dict , 1 ) ;
}
2019-09-03 11:58:42 +02:00
// check enable/disabled patch (OS based) by Micky1979
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " MatchOS " ) ;
2020-08-18 18:45:44 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
newPatch . MatchOS = Dict - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchOS: %s " , newPatch . MatchOS . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " MatchBuild " ) ;
2020-08-18 18:45:44 +02:00
if ( ( Dict ! = NULL ) & & ( Dict - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
newPatch . MatchBuild = Dict - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchBuild: %s " , newPatch . MatchBuild . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
// check if this is Info.plist patch or kext binary patch
2020-08-25 17:35:19 +02:00
Dict = Prop2 - > propertyForKey ( " InfoPlistPatch " ) ;
2020-08-22 15:39:24 +02:00
newPatch . IsPlistPatch = IsPropertyNotNullAndTrue ( Dict ) ;
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
if ( newPatch . 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-08-12 17:15:47 +02:00
DBG ( " :: data len: %zu \n " , newPatch . Data . size ( ) ) ;
2020-08-23 13:54:35 +02:00
if ( ! newPatch . MenuItem . BValue ) {
2019-09-03 11:58:42 +02:00
DBG ( " - patch disabled at config \n " ) ;
}
2020-08-12 17:15:47 +02:00
Patches - > KextPatches . AddReference ( newPatchPtr , true ) ;
2019-09-03 11:58:42 +02:00
}
}
//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
}
2020-08-22 15:39:24 +02:00
/*
* KernelToPatch is an array of dict
*/
2020-08-25 17:35:19 +02:00
arrayProp = DictPointer - > arrayPropertyForKey ( " KernelToPatch " ) ;
2020-09-03 22:05:11 +02:00
if ( arrayProp ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
//delete old and create new
2020-08-12 17:15:47 +02:00
Patches - > KernelPatches . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2020-08-25 17:35:19 +02:00
const TagDict * Prop2 = NULL ;
const TagStruct * prop3 = NULL ;
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 + + ) {
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-08-25 17:35:19 +02:00
Prop2 = arrayProp - > dictElementAt ( i , " KernelToPatch " _XS8 ) ;
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
KEXT_PATCH * newKernelPatchPtr = new KEXT_PATCH ;
KEXT_PATCH & newKernelPatch = * newKernelPatchPtr ;
2020-08-18 18:45:44 +02:00
newKernelPatch . Label = " NoLabel " _XS8 ;
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Comment " ) ;
if ( prop3 ! = NULL ) {
2021-02-06 18:16:46 +01:00
if ( prop3 - > isString ( ) ) {
newKernelPatch . Label = prop3 - > getString ( ) - > stringValue ( ) ;
} else {
MsgLog ( " ATTENTION : Comment property not string in KernelToPatch \n " ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-12 17:15:47 +02:00
DBG ( " %s " , newKernelPatch . Label . c_str ( ) ) ;
2020-10-03 16:16:11 +02:00
newKernelPatch . Name = " kernel " _XS8 ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Disabled " ) ;
newKernelPatch . MenuItem . BValue = ! IsPropertyNotNullAndTrue ( prop3 ) ;
2020-04-25 18:18:18 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " RangeFind " ) ;
newKernelPatch . SearchLen = GetPropertyAsInteger ( prop3 , 0 ) ; //default 0 will be calculated later
2020-10-08 22:03:41 +02:00
prop3 = Prop2 - > propertyForKey ( " Skip " ) ;
newKernelPatch . Skip = GetPropertyAsInteger ( prop3 , 0 ) ; //default 0 will be calculated later
2020-04-25 18:18:18 +02:00
TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newKernelPatch . StartPattern . stealValueFrom ( TmpData , FindLen ) ;
2020-04-25 18:18:18 +02:00
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-08-12 17:15:47 +02:00
newKernelPatch . StartMask . memset ( 0xFF , FindLen ) ;
2020-04-25 18:18:18 +02:00
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newKernelPatch . StartMask . ncpy ( TmpData , ReplaceLen ) ;
2020-04-25 18:18:18 +02:00
}
}
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
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Procedure " ) ;
if ( prop3 ! = NULL ) {
2021-02-06 18:16:46 +01:00
if ( prop3 - > isString ( ) ) {
newKernelPatch . ProcedureName = prop3 - > getString ( ) - > stringValue ( ) ;
} else {
MsgLog ( " ATTENTION : Procedure property not string in KernelToPatch \n " ) ;
}
2020-04-27 17:16:43 +02:00
}
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
newKernelPatch . Data . stealValueFrom ( TmpData , FindLen ) ;
2019-10-08 22:57:18 +02:00
TmpData = GetDataSetting ( Prop2 , " MaskFind " , & MaskLen ) ;
MaskLen = ( MaskLen > FindLen ) ? FindLen : MaskLen ;
if ( TmpData = = NULL | | MaskLen = = 0 ) {
} else {
2020-08-12 17:15:47 +02:00
newKernelPatch . MaskFind . memset ( 0xFF , FindLen ) ;
newKernelPatch . MaskFind . ncpy ( 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-08-12 17:15:47 +02:00
newKernelPatch . Patch . memset ( 0 , FindLen ) ;
newKernelPatch . Patch . ncpy ( 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 ) {
} else {
2020-08-12 17:15:47 +02:00
newKernelPatch . MaskReplace . memset ( 0 , FindLen ) ;
newKernelPatch . MaskReplace . ncpy ( TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-08-12 17:15:47 +02:00
newKernelPatch . Count = 0 ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Count " ) ;
if ( prop3 ! = NULL ) {
newKernelPatch . Count = GetPropertyAsInteger ( prop3 , 0 ) ;
2019-09-03 11:58:42 +02:00
}
// check enable/disabled patch (OS based) by Micky1979
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " MatchOS " ) ;
if ( ( prop3 ! = NULL ) & & ( prop3 - > isString ( ) ) ) {
newKernelPatch . MatchOS = prop3 - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchOS: %s " , newKernelPatch . MatchOS . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " MatchBuild " ) ;
if ( ( prop3 ! = NULL ) & & ( prop3 - > isString ( ) ) ) {
newKernelPatch . MatchBuild = prop3 - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchBuild: %s " , newKernelPatch . MatchBuild . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-12 17:15:47 +02:00
DBG ( " :: data len: %zu \n " , newKernelPatch . Data . size ( ) ) ;
Patches - > KernelPatches . AddReference ( newKernelPatchPtr , true ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-22 15:39:24 +02:00
/*
* BootPatches is an array of dict
*/
2020-08-25 17:35:19 +02:00
arrayProp = DictPointer - > arrayPropertyForKey ( " BootPatches " ) ;
2020-09-03 22:05:11 +02:00
if ( arrayProp ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
//delete old and create new
2020-08-12 17:15:47 +02:00
Patches - > BootPatches . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2020-08-25 17:35:19 +02:00
const TagDict * Prop2 = NULL ;
const TagStruct * prop3 = NULL ;
2019-09-03 11:58:42 +02:00
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 + + ) {
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-08-22 15:39:24 +02:00
2020-08-25 17:35:19 +02:00
Prop2 = arrayProp - > dictElementAt ( i , " BootPatches " _XS8 ) ;
2020-04-24 11:01:28 +02:00
DBG ( " - [%02lld]: " , i ) ;
2019-09-03 11:58:42 +02:00
2020-08-12 17:15:47 +02:00
KEXT_PATCH * newBootPatchPtr = new KEXT_PATCH ;
KEXT_PATCH & newBootPatch = * newBootPatchPtr ;
2020-08-18 18:45:44 +02:00
newBootPatch . Label = " NoLabel " _XS8 ;
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Comment " ) ;
if ( prop3 ! = NULL ) {
2021-02-06 18:16:46 +01:00
if ( prop3 - > isString ( ) ) {
newBootPatch . Label = prop3 - > getString ( ) - > stringValue ( ) ;
} else {
MsgLog ( " ATTENTION : Comment property not string in KernelToPatch \n " ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-12 17:15:47 +02:00
DBG ( " %s " , newBootPatch . Label . c_str ( ) ) ;
2020-10-03 16:16:11 +02:00
newBootPatch . Name = " boot.efi " _XS8 ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Disabled " ) ;
newBootPatch . MenuItem . BValue = ! IsPropertyNotNullAndTrue ( prop3 ) ;
2020-08-12 17:15:47 +02:00
newBootPatch . MenuItem . ItemType = BoolValue ;
2020-04-25 18:18:18 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " RangeFind " ) ;
newBootPatch . SearchLen = GetPropertyAsInteger ( prop3 , 0 ) ; //default 0 will be calculated later
2020-10-08 22:03:41 +02:00
prop3 = Prop2 - > propertyForKey ( " Skip " ) ;
newBootPatch . Skip = GetPropertyAsInteger ( prop3 , 0 ) ; //default 0 will be calculated later
2020-04-25 18:18:18 +02:00
TmpData = GetDataSetting ( Prop2 , " StartPattern " , & FindLen ) ;
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newBootPatch . StartPattern . stealValueFrom ( TmpData , FindLen ) ;
2020-04-25 18:18:18 +02:00
}
TmpData = GetDataSetting ( Prop2 , " MaskStart " , & ReplaceLen ) ;
ReplaceLen = MIN ( ReplaceLen , FindLen ) ;
if ( FindLen ! = 0 ) {
2020-08-12 17:15:47 +02:00
newBootPatch . StartMask . memset ( 0xFF , FindLen ) ;
2020-04-25 18:18:18 +02:00
if ( TmpData ! = NULL ) {
2020-08-12 17:15:47 +02:00
newBootPatch . StartMask . ncpy ( TmpData , ReplaceLen ) ;
2020-04-25 18:18:18 +02:00
}
}
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-08-12 17:15:47 +02:00
newBootPatch . Data . stealValueFrom ( TmpData , FindLen ) ;
2020-04-24 11:01:28 +02:00
MaskLen = 0 ;
2020-08-12 17:15:47 +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 ) {
} else {
2020-08-12 17:15:47 +02:00
newBootPatch . MaskFind . memset ( 0xFF , FindLen ) ;
newBootPatch . MaskFind . ncpy ( TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-08-12 17:15:47 +02:00
newBootPatch . Patch . memset ( 0 , FindLen ) ;
newBootPatch . Patch . ncpy ( TmpPatch , ReplaceLen ) ;
2019-10-08 22:57:18 +02:00
FreePool ( TmpPatch ) ;
2020-04-24 11:01:28 +02:00
MaskLen = 0 ;
2020-08-12 17:15:47 +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 ) {
} else {
2020-08-12 17:15:47 +02:00
newBootPatch . MaskReplace . memset ( 0 , FindLen ) ;
newBootPatch . MaskReplace . ncpy ( TmpData , MaskLen ) ;
2019-10-08 22:57:18 +02:00
}
FreePool ( TmpData ) ;
2020-08-12 17:15:47 +02:00
newBootPatch . Count = 0 ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " Count " ) ;
if ( prop3 ! = NULL ) {
newBootPatch . Count = GetPropertyAsInteger ( prop3 , 0 ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " MatchOS " ) ;
if ( ( prop3 ! = NULL ) & & ( prop3 - > isString ( ) ) ) {
newBootPatch . MatchOS = prop3 - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchOS: %s " , newBootPatch . MatchOS . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop3 = Prop2 - > propertyForKey ( " MatchBuild " ) ;
if ( ( prop3 ! = NULL ) & & ( prop3 - > isString ( ) ) ) {
newBootPatch . MatchBuild = prop3 - > getString ( ) - > stringValue ( ) ;
2020-08-12 17:15:47 +02:00
DBG ( " :: MatchBuild: %s " , newBootPatch . MatchBuild . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-12 17:15:47 +02:00
DBG ( " :: data len: %zu \n " , newBootPatch . Data . size ( ) ) ;
Patches - > BootPatches . AddReference ( newBootPatchPtr , true ) ;
2019-09-03 11:58:42 +02:00
}
}
}
return TRUE ;
}
2020-11-12 22:25:56 +01:00
2019-09-03 11:58:42 +02:00
2020-11-12 22:25:56 +01:00
//BOOLEAN IsOSValid(const XString8& MatchOS, const MacOsVersion& 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;
//
// if (MatchOS.isEmpty() || CurrOS.isEmpty()) {
// return TRUE; //undefined matched corresponds to old behavior
// }
//
//// osToc = GetStrArraySeparatedByChar(MatchOS, '.');
// XString8Array osToc = Split<XString8Array>(MatchOS, "."_XS8).trimEachString();
// XString8Array currOStoc = Split<XString8Array>(CurrOS, "."_XS8).trimEachString();
//
// if ( osToc.size() > 0 && currOStoc.size() > 0 && osToc[0] == "11"_XS8 && currOStoc[0] == "11"_XS8 ) {
// if (osToc.size() == 1 ) return true;
// if (osToc.size() == 2 ) {
// if ( osToc[1].equalIC("x") ) return true;
// if ( currOStoc.size() == 2 && osToc[1] == currOStoc[1] ) return true;
// }
// }
// if (osToc.size() == 2) {
// if (currOStoc.size() == 2) {
// if ( osToc[0] == currOStoc[0] && osToc[1] == currOStoc[1]) {
// ret = TRUE;
// }
// }
// } else if (osToc.size() == 3) {
// if (currOStoc.size() == 3) {
// if ( osToc[0] == currOStoc[0]
// && osToc[1] == currOStoc[1]
// && osToc[2] == currOStoc[2]) {
// ret = TRUE;
// } else if ( osToc[0] == currOStoc[0]
// && osToc[1] == currOStoc[1]
// && osToc[2].equalIC("x") ) {
// ret = TRUE;
// }
// } else if (currOStoc.size() == 2) {
// if ( osToc[0] == currOStoc[0]
// && osToc[1] == currOStoc[1] ) {
// ret = TRUE;
// } else if ( osToc[0] == currOStoc[0]
// && osToc[1] == currOStoc[1]
// && osToc[2].equalIC("x") == 0 ) {
// ret = TRUE;
// }
// }
// }
// return ret;
//}
2021-02-06 18:16:46 +01:00
static UINT8 CheckVolumeType ( UINT8 VolumeType , const TagStruct * Prop )
2019-09-03 11:58:42 +02:00
{
2021-02-06 18:16:46 +01:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : Prop property not string in CheckVolumeType \n " ) ;
return 0 ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
UINT8 VolumeTypeTmp = VolumeType ;
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Internal " ) ) {
2019-09-03 11:58:42 +02:00
VolumeTypeTmp | = VOLTYPE_INTERNAL ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " External " ) ) {
2019-09-03 11:58:42 +02:00
VolumeTypeTmp | = VOLTYPE_EXTERNAL ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Optical " ) ) {
2019-09-03 11:58:42 +02:00
VolumeTypeTmp | = VOLTYPE_OPTICAL ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " FireWire " ) ) {
2019-09-03 11:58:42 +02:00
VolumeTypeTmp | = VOLTYPE_FIREWIRE ;
}
return VolumeTypeTmp ;
}
2021-02-06 18:16:46 +01:00
static UINT8 GetVolumeType ( const TagDict * DictPointer )
2019-09-03 11:58:42 +02:00
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2019-09-03 11:58:42 +02:00
UINT8 VolumeType = 0 ;
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " VolumeType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2019-09-03 11:58:42 +02:00
VolumeType = CheckVolumeType ( 0 , Prop ) ;
2020-08-18 18:45:44 +02:00
} else if ( Prop - > isArray ( ) ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = Prop - > getArray ( ) - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagStruct * Prop2 = & Prop - > getArray ( ) - > arrayContent ( ) [ i ] ;
if ( ! Prop2 - > isString ( ) | | Prop2 - > getString ( ) - > stringValue ( ) . isEmpty ( ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
VolumeType = CheckVolumeType ( VolumeType , Prop2 ) ;
}
}
}
}
return VolumeType ;
}
2021-02-06 18:16:46 +01:00
static CONST CHAR8 * CustomBootModeStr [ ] = {
" CUSTOM_BOOT_DISABLED " ,
" CUSTOM_BOOT_USER_DISABLED " ,
" CUSTOM_BOOT_NONE " ,
" CUSTOM_BOOT_APPLE " ,
" CUSTOM_BOOT_ALT_APPLE " ,
" CUSTOM_BOOT_THEME " ,
" CUSTOM_BOOT_USER " ,
} ;
static CONST CHAR8 * CustomBootModeToStr ( IN UINT8 Mode )
{
if ( Mode > = ( sizeof ( CustomBootModeStr ) / sizeof ( CustomBootModeStr [ 0 ] ) ) ) {
return CustomBootModeStr [ 0 ] ;
}
return CustomBootModeStr [ Mode ] ;
}
2019-09-03 11:58:42 +02:00
STATIC
BOOLEAN
FillinCustomEntry (
IN OUT CUSTOM_LOADER_ENTRY * Entry ,
2020-08-25 17:35:19 +02:00
const TagDict * DictPointer ,
2019-09-03 11:58:42 +02:00
IN BOOLEAN SubEntry
)
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2019-09-03 11:58:42 +02:00
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Disabled " ) ;
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Volume " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Volume = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Path " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Path = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Settings " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Settings = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " CommonSettings " ) ;
2020-08-22 15:39:24 +02:00
Entry - > CommonSettings = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " AddArguments " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-04-26 15:07:30 +02:00
// if (Entry->LoadOptions.notEmpty()) {
2020-08-25 17:35:19 +02:00
// Entry->Options.SPrintf("%s %s", Entry->Options.c_str(), Prop->getString()->stringValue());
2020-04-26 15:07:30 +02:00
// } else {
2020-08-25 17:35:19 +02:00
// Entry->Options.SPrintf("%s", Prop->getString()->stringValue());
2020-04-26 15:07:30 +02:00
// }
2021-02-06 18:16:46 +01:00
Entry - > LoadOptions . import ( Split < XString8Array > ( Prop - > getString ( ) - > stringValue ( ) , " " ) ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Arguments " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
// Entry->Options.SPrintf("%s", Prop->getString()->stringValue());
Entry - > LoadOptions = Split < XString8Array > ( Prop - > getString ( ) - > stringValue ( ) , " " ) ;
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTARGS ) ;
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Title " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Title = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " FullTitle " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > FullTitle = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-09 17:55:30 +02:00
Entry - > ImagePath . setEmpty ( ) ;
2020-04-13 17:43:32 +02:00
Entry - > Image . setEmpty ( ) ;
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2020-08-25 17:35:19 +02:00
Entry - > ImagePath = SWPrintf ( " %s " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " DriveImage " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-09 17:55:30 +02:00
Entry - > DriveImagePath . setEmpty ( ) ;
2020-04-13 17:43:32 +02:00
Entry - > DriveImage . setEmpty ( ) ;
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2020-08-25 17:35:19 +02:00
Entry - > DriveImagePath = SWPrintf ( " %s " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
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 ;
2020-10-14 15:40:07 +02:00
UINT8 * TmpData = GetDataSetting ( DictPointer , " DriveImageData " , & DataLen ) ;
2020-04-03 22:00:42 +02:00
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hotkey " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
if ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] < __WCHAR_MAX__ ) {
Entry - > Hotkey = ( wchar_t ) ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] ) ;
}
2019-09-03 11:58:42 +02:00
}
// Whether or not to draw boot screen
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " CustomLogo " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Apple " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Alternate " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_ALT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Theme " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_THEME ;
} else {
2020-08-25 17:35:19 +02:00
XStringW customLogo = XStringW ( ) = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_USER ;
2020-10-03 19:02:31 +02:00
Entry - > CustomLogo . LoadXImage ( & self . getSelfVolumeRootDir ( ) , customLogo ) ;
2020-04-11 14:34:59 +02:00
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
}
}
2020-08-25 17:35:19 +02:00
} else if ( Prop - > isData ( ) & & Prop - > getData ( ) - > dataLenValue ( ) > 0 ) {
2019-09-03 11:58:42 +02:00
Entry - > CustomBoot = CUSTOM_BOOT_USER ;
2020-08-25 17:35:19 +02:00
Entry - > CustomLogo . FromPNG ( Prop - > getData ( ) - > dataValue ( ) , Prop - > getData ( ) - > dataLenValue ( ) ) ;
2020-04-11 14:34:59 +02:00
if ( Entry - > CustomLogo . isEmpty ( ) ) {
2020-08-25 17:35:19 +02:00
DBG ( " Custom boot logo not decoded from data! \n " /*, Prop->getString()->stringValue().c_str()*/ ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BootBgColor " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & Prop - > isString ( ) ) {
2019-09-03 11:58:42 +02:00
UINTN Color ;
2020-08-25 17:35:19 +02:00
Color = AsciiStrHexToUintn ( Prop - > getString ( ) - > stringValue ( ) ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hidden " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ( Prop - > isString ( ) ) & &
2020-08-25 17:35:19 +02:00
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Always " ) ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-08-22 15:39:24 +02:00
} else if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-04 15:04:31 +01:00
DBG ( " hiding entry because Hidden flag is YES \n " ) ;
2020-08-15 22:39:25 +02:00
Entry - > Hidden = true ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-15 22:39:25 +02:00
Entry - > Hidden = false ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Type " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
if ( ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " OSX " ) ) | |
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " macOS " ) ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_OSX ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " OSXInstaller " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_OSX_INSTALLER ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " OSXRecovery " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_RECOVERY ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Windows " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_WINEFI ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Linux " ) ) {
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-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " LinuxKernel " ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Type = OSTYPE_LINEFI ;
} else {
2020-08-25 17:35:19 +02:00
DBG ( " ** Warning: unknown custom entry Type '%s' \n " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
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 ;
}
}
2020-08-09 17:55:30 +02:00
if ( Entry - > Image . isEmpty ( ) & & ( Entry - > ImagePath . isEmpty ( ) ) ) {
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) ) {
2020-08-09 17:55:30 +02:00
Entry - > ImagePath = L " mac " _XSW ;
2020-04-03 22:00:42 +02:00
}
}
2020-08-09 17:55:30 +02:00
if ( Entry - > DriveImage . isEmpty ( ) & & ( Entry - > DriveImagePath . isEmpty ( ) ) ) {
2020-04-11 14:34:59 +02:00
if ( OSTYPE_IS_OSX_RECOVERY ( Entry - > Type ) ) {
2020-08-09 17:55:30 +02:00
Entry - > DriveImagePath = L " recovery " _XSW ;
2020-04-03 22:00:42 +02:00
}
}
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " InjectKexts " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isTrueOrYes ( ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_WITHKEXTS ) ;
2020-09-03 23:34:44 +02:00
} else if ( Prop - > isFalseOrNn ( ) ) {
// nothing to do
2020-08-25 17:35:19 +02:00
} else if ( Prop - > isString ( ) & & Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Detect " ) ) {
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-08-25 17:35:19 +02:00
DBG ( " ** Warning: unknown custom entry InjectKexts value '%s' \n " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " NoCaches " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( 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)));
2020-08-12 17:15:47 +02:00
// CopyKernelAndKextPatches(&Entry->KernelAndKextPatches, &gSettings.KernelAndKextPatches);
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Kernel " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-25 17:35:19 +02:00
if ( ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' N ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' n ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_NEWEST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' O ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' o ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_OLDEST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' F ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' f ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_FIRST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' L ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' l ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_LAST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' M ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' m ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_MOSTRECENT ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' E ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' e ' ) ) {
2019-09-03 11:58:42 +02:00
Entry - > KernelScan = KERNEL_SCAN_EARLIEST ;
}
}
}
}
2020-08-22 15:39:24 +02:00
/*
* Sub entries
* an array of dict OR a bool
*/
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " SubEntries " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-25 17:35:19 +02:00
if ( Prop - > isBool ( ) & & Prop - > getBool ( ) - > boolValue ( ) ) {
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTMENU ) ;
2020-08-22 15:39:24 +02:00
} else if ( Prop - > isArray ( ) ) {
2019-09-03 11:58:42 +02:00
CUSTOM_LOADER_ENTRY * CustomSubEntry ;
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = Prop - > getArray ( ) - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_NODEFAULTMENU ) ;
2020-08-22 15:39:24 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * Dict = Prop - > getArray ( ) - > dictElementAt ( i , " SubEntries " _XS8 ) ;
2020-08-22 15:39:24 +02:00
// Allocate a sub entry
CustomSubEntry = DuplicateCustomEntry ( Entry ) ;
if ( CustomSubEntry ) {
if ( ! FillinCustomEntry ( CustomSubEntry , Dict , TRUE ) | | ! AddCustomSubEntry ( Entry , CustomSubEntry ) ) {
if ( CustomSubEntry ) {
FreePool ( CustomSubEntry ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-08-22 15:39:24 +02:00
} else {
MsgLog ( " MALFORMED PLIST : SubEntries must be a bool OR an array of dict " ) ;
2019-09-03 11:58:42 +02:00
}
}
return TRUE ;
}
2020-04-10 12:04:21 +02:00
2021-02-06 18:16:46 +01:00
static BOOLEAN
2020-04-03 22:00:42 +02:00
FillingCustomLegacy (
IN OUT CUSTOM_LEGACY_ENTRY * Entry ,
2020-08-25 17:35:19 +02:00
const TagDict * DictPointer
2020-04-03 22:00:42 +02:00
)
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2020-04-03 22:00:42 +02:00
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Disabled " ) ;
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Volume " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Volume = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " FullTitle " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > FullTitle = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Title " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Title = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2020-10-03 19:02:31 +02:00
Entry - > Image . LoadXImage ( & ThemeX . getThemeDir ( ) , Prop - > getString ( ) - > stringValue ( ) ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " DriveImage " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2020-10-03 19:02:31 +02:00
Entry - > Image . LoadXImage ( & ThemeX . getThemeDir ( ) , Prop - > getString ( ) - > stringValue ( ) ) ;
2020-04-03 22:00:42 +02:00
}
} 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hotkey " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
if ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] < __WCHAR_MAX__ ) {
Entry - > Hotkey = ( wchar_t ) ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] ) ;
}
2020-04-03 22:00: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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hidden " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ( Prop - > isString ( ) ) & &
2020-08-25 17:35:19 +02:00
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Always " ) ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-08-22 15:39:24 +02:00
} else if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-04 15:04:31 +01:00
DBG ( " hiding entry because Hidden flag is YES \n " ) ;
2020-08-15 22:39:25 +02:00
Entry - > Hidden = true ;
2020-04-03 22:00:42 +02:00
} else {
2020-08-15 22:39:25 +02:00
Entry - > Hidden = false ;
2020-04-03 22:00:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Type " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Windows " ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Type = OSTYPE_WIN ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Linux " ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Type = OSTYPE_LIN ;
} else {
Entry - > Type = OSTYPE_OTHER ;
}
}
Entry - > VolumeType = GetVolumeType ( DictPointer ) ;
return TRUE ;
}
2021-02-06 18:16:46 +01:00
static BOOLEAN
2020-08-25 17:35:19 +02:00
FillingCustomTool ( IN OUT CUSTOM_TOOL_ENTRY * Entry , const TagDict * DictPointer )
2020-04-03 22:00:42 +02:00
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2020-04-03 22:00:42 +02:00
if ( ( Entry = = NULL ) | | ( DictPointer = = NULL ) ) {
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Disabled " ) ;
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2020-04-03 22:00:42 +02:00
return FALSE ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Volume " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Volume . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Path " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-08-25 17:35:19 +02:00
Entry - > Path . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Arguments " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-04-05 14:25:39 +02:00
// if (!Entry->Options.isEmpty()) {
// Entry->Options.setEmpty();
// } else {
2020-08-25 17:35:19 +02:00
// Entry->Options.SPrintf("%s", Prop->getString()->stringValue());
2020-04-05 14:25:39 +02:00
// }
2020-08-25 17:35:19 +02:00
Entry - > LoadOptions = Split < XString8Array > ( Prop - > getString ( ) - > stringValue ( ) , " " ) ;
2020-04-03 22:00:42 +02:00
}
2020-10-14 15:40:07 +02:00
Prop = DictPointer - > propertyForKey ( " Title " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-10-14 15:40:07 +02:00
Entry - > Title = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-10-14 15:40:07 +02:00
Prop = DictPointer - > propertyForKey ( " FullTitle " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) ) {
2020-10-14 15:40:07 +02:00
Entry - > FullTitle = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Image " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-09 17:55:30 +02:00
Entry - > ImagePath . setEmpty ( ) ;
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2020-08-25 17:35:19 +02:00
Entry - > ImagePath = Prop - > getString ( ) - > stringValue ( ) ;
2020-04-03 22:00:42 +02:00
}
2020-10-03 19:02:31 +02:00
Entry - > Image . LoadXImage ( & ThemeX . getThemeDir ( ) , Entry - > ImagePath ) ;
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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hotkey " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
if ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] < __WCHAR_MAX__ ) {
Entry - > Hotkey = ( wchar_t ) ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] ) ;
}
2020-04-03 22:00: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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Hidden " ) ;
2020-04-03 22:00:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ( Prop - > isString ( ) ) & &
2020-08-25 17:35:19 +02:00
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Always " ) ) ) {
2020-04-03 22:00:42 +02:00
Entry - > Flags = OSFLAG_SET ( Entry - > Flags , OSFLAG_DISABLED ) ;
2020-08-22 15:39:24 +02:00
} else if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-04 15:04:31 +01:00
DBG ( " hiding entry because Hidden flag is YES \n " ) ;
2020-08-15 22:39:25 +02:00
Entry - > Hidden = true ;
2020-04-03 22:00:42 +02:00
} else {
2020-08-15 22:39:25 +02:00
Entry - > Hidden = false ;
2020-04-03 22:00:42 +02:00
}
}
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
2021-02-06 18:16:46 +01:00
static void
2020-08-25 17:35:19 +02:00
GetEDIDSettings ( const TagDict * DictPointer )
2019-09-03 11:58:42 +02:00
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2020-08-25 17:35:19 +02:00
const TagDict * Dict ;
2020-04-10 12:04:21 +02:00
UINTN j = 128 ;
2019-09-03 11:58:42 +02:00
2020-08-22 15:39:24 +02:00
Dict = DictPointer - > dictPropertyForKey ( " EDID " ) ;
2020-04-10 12:04:21 +02:00
if ( Dict ! = NULL ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " Inject " ) ;
2020-08-22 15:39:24 +02:00
gSettings . InjectEDID = IsPropertyNotNullAndTrue ( 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-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " 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-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " VendorID " ) ;
2020-04-10 12:04:21 +02:00
if ( Prop ) {
2020-08-22 15:39:24 +02:00
gSettings . VendorEDID = ( UINT16 ) GetPropertyAsInteger ( Prop , gSettings . VendorEDID ) ;
2020-04-10 12:04:21 +02:00
//DBG(" VendorID = 0x%04lx\n", gSettings.VendorEDID);
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-08-22 15:39:24 +02:00
gSettings . ProductEDID = ( UINT16 ) GetPropertyAsInteger ( Prop , gSettings . ProductEDID ) ;
2019-09-03 11:58:42 +02:00
//DBG(" ProductID = 0x%04lx\n", gSettings.ProductEDID);
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " HorizontalSyncPulseWidth " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-08-22 15:39:24 +02:00
gSettings . EdidFixHorizontalSyncPulseWidth = ( UINT16 ) GetPropertyAsInteger ( Prop , gSettings . EdidFixHorizontalSyncPulseWidth ) ;
2019-09-03 11:58:42 +02:00
//DBG(" EdidFixHorizontalSyncPulseWidth = 0x%02lx\n", gSettings.EdidFixHorizontalSyncPulseWidth);
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " VideoInputSignal " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2020-08-22 15:39:24 +02:00
gSettings . EdidFixVideoInputSignal = ( UINT8 ) GetPropertyAsInteger ( Prop , gSettings . EdidFixVideoInputSignal ) ;
2019-09-03 11:58:42 +02:00
//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 (
2021-02-06 18:16:46 +01:00
const TagDict * CfgDict ,
SETTINGS_DATA & settingsData
2019-09-03 11:58:42 +02:00
)
{
EFI_STATUS Status = EFI_SUCCESS ;
2020-08-25 17:35:19 +02:00
// const TagDict* Dict;
// const TagDict* Dict2;
// const TagDict* DictPointer;
// const TagStruct* Prop;
// const TagArray* arrayProp;
2021-02-02 10:02:21 +01:00
// void *Value = NULL;
// BOOLEAN SpecialBootMode = FALSE;
// {
// UINTN Size = 0;
// //read aptiofixflag from nvram for special boot
// Status = GetVariable2(L"aptiofixflag", &gEfiAppleBootGuid, &Value, &Size);
// if (!EFI_ERROR(Status)) {
// SpecialBootMode = TRUE;
// FreePool(Value);
// }
// }
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
settingsData . KextPatchesAllowed = TRUE ;
settingsData . KernelAndKextPatches . KPAppleRTC = TRUE ;
settingsData . KernelAndKextPatches . KPDELLSMBIOS = FALSE ; // default is false
settingsData . KernelPatchesAllowed = TRUE ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( CfgDict ! = 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-08-25 17:35:19 +02:00
const TagDict * BootDict = CfgDict - > dictPropertyForKey ( " Boot " ) ;
if ( BootDict ! = NULL ) {
const TagStruct * Prop = BootDict - > propertyForKey ( " Timeout " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . Timeout = ( INT32 ) GetPropertyAsInteger ( Prop , settingsData . Boot . Timeout ) ;
DBG ( " timeout set to %lld \n " , settingsData . Boot . Timeout ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " SkipHibernateTimeout " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . SkipHibernateTimeout = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
//DisableCloverHotkeys
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " DisableCloverHotkeys " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . DisableCloverHotkeys = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Arguments " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . BootArgs = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
}
// defaults if "DefaultVolume" is not present or is empty
2021-02-06 18:16:46 +01:00
settingsData . Boot . LastBootedVolume = FALSE ;
// settingsData.Boot.DefaultVolume = NULL;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " DefaultVolume " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-25 17:35:19 +02:00
if ( Prop - > isString ( ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . DefaultVolume . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
// check for special value for remembering boot volume
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " LastBootedVolume " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . LastBootedVolume = TRUE ;
2019-09-03 11:58:42 +02:00
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . DefaultVolume = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " DefaultLoader " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in DefaultLoader \n " ) ;
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . DefaultLoader = Prop - > getString ( ) - > stringValue ( ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Debug " ) ;
2020-09-18 12:50:49 +02:00
if ( Prop ) {
if ( Prop - > isString ( ) ) {
2021-02-06 18:16:46 +01:00
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " true " ) ) settingsData . Boot . DebugLog = true ;
else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " false " ) ) settingsData . Boot . DebugLog = false ;
2020-09-18 12:50:49 +02:00
else MsgLog ( " MALFORMED config.plist : property Boot/Debug must be true, false, or scratch \n " ) ;
} else if ( Prop - > isBool ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . DebugLog = Prop - > getBool ( ) - > boolValue ( ) ;
2020-09-18 12:50:49 +02:00
} else {
2020-11-24 13:41:47 +01:00
MsgLog ( " MALFORMED config.plist : property Boot/Debug must be a string (true, false) or <true/> or <false/> \n " ) ;
2020-09-18 12:50:49 +02:00
}
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Fast " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . FastBoot = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " NoEarlyProgress " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . NoEarlyProgress = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2021-02-02 10:02:21 +01:00
// if (SpecialBootMode) {
// GlobalConfig.isFastBoot() = TRUE;
// DBG("Fast option enabled\n");
// }
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " NeverHibernate " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . NeverHibernate = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " StrictHibernate " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . StrictHibernate = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " RtcHibernateAware " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . RtcHibernateAware = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " HibernationFixup " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . HibernationFixup = IsPropertyNotNullAndTrue ( Prop ) ; //it will be set automatically
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " SignatureFixup " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . SignatureFixup = IsPropertyNotNullAndTrue ( 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
2021-02-07 15:39:03 +01:00
/* this parameter, which should be called SecureBootSetupMode, is ignored if :
* it is true
* SecureBoot is already true .
*/
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Secure " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isFalse ( ) ) {
2019-09-03 11:58:42 +02:00
// Only disable setup mode, we want always secure boot
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootSetupMode = 0 ;
} else if ( Prop - > isTrue ( ) & & ! settingsData . Boot . SecureBoot ) {
2019-09-03 11:58:42 +02:00
// This mode will force boot policy even when no secure boot or it is disabled
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootSetupMode = 1 ;
settingsData . Boot . SecureBoot = 1 ;
2019-09-03 11:58:42 +02:00
}
}
// Secure boot policy
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Policy " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' D ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' d ' ) ) {
2019-09-03 11:58:42 +02:00
// Deny all images
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_DENY ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' A ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' a ' ) ) {
2019-09-03 11:58:42 +02:00
// Allow all images
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_ALLOW ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' Q ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' q ' ) ) {
2019-09-03 11:58:42 +02:00
// Query user
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_QUERY ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' I ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' i ' ) ) {
2019-09-03 11:58:42 +02:00
// Insert
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_INSERT ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' W ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' w ' ) ) {
2019-09-03 11:58:42 +02:00
// White list
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_WHITELIST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' B ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' b ' ) ) {
2019-09-03 11:58:42 +02:00
// Black list
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_BLACKLIST ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' U ' ) | | ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' u ' ) ) {
2019-09-03 11:58:42 +02:00
// User policy
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootPolicy = SECURE_BOOT_POLICY_USER ;
2019-09-03 11:58:42 +02:00
}
}
// Secure boot white list
2020-08-25 17:35:19 +02:00
const TagArray * arrayProp = BootDict - > arrayPropertyForKey ( " WhiteList " ) ;
2020-09-03 22:05:11 +02:00
if ( arrayProp ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootWhiteListCount = 0 ;
settingsData . Boot . SecureBootWhiteList = ( __typeof__ ( settingsData . Boot . SecureBootWhiteList ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
if ( settingsData . Boot . SecureBootWhiteList ) {
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagStruct * prop2 = & arrayProp - > arrayContent ( ) [ i ] ;
if ( ! prop2 - > isString ( ) ) {
2020-08-22 15:39:24 +02:00
MsgLog ( " MALFORMED PLIST : WhiteList must be an array of string " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-08-25 17:35:19 +02:00
if ( prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootWhiteList [ settingsData . Boot . SecureBootWhiteListCount + + ] = SWPrintf ( " %s " , prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// Secure boot black list
2020-08-25 17:35:19 +02:00
arrayProp = BootDict - > arrayPropertyForKey ( " BlackList " ) ;
if ( arrayProp ! = NULL & & arrayProp - > isArray ( ) ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootBlackListCount = 0 ;
settingsData . Boot . SecureBootBlackList = ( __typeof__ ( settingsData . Boot . SecureBootBlackList ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
if ( settingsData . Boot . SecureBootBlackList ) {
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagStruct * prop2 = & arrayProp - > arrayContent ( ) [ i ] ;
if ( ! prop2 - > isString ( ) ) {
2020-08-22 15:39:24 +02:00
MsgLog ( " MALFORMED PLIST : BlackList must be an array of string " ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-08-25 17:35:19 +02:00
if ( prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . SecureBootBlackList [ settingsData . Boot . SecureBootBlackListCount + + ] = SWPrintf ( " %s " , prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// XMP memory profiles
2021-02-07 15:39:03 +01:00
// -1 = do not detect
// 0 = Detect the better XMP profile
// 1 = Use first profile if present
// 2 = Use second profile
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " XMPDetection " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . XMPDetection = 0 ;
2020-08-18 18:45:44 +02:00
if ( Prop - > isFalse ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . XMPDetection = - 1 ;
2020-08-18 18:45:44 +02:00
} else if ( Prop - > isString ( ) ) {
2020-08-25 17:35:19 +02:00
if ( ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' n ' ) | |
( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' N ' ) | |
( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' - ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . XMPDetection = - 1 ;
2019-09-03 11:58:42 +02:00
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . XMPDetection = ( INT8 ) AsciiStrDecimalToUintn ( Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
} else if ( Prop - > isInt64 ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . XMPDetection = ( INT8 ) Prop - > getInt64 ( ) - > intValue ( ) ;
2019-09-03 11:58:42 +02:00
}
// Check that the setting value is sane
2021-02-06 18:16:46 +01:00
if ( ( settingsData . Boot . XMPDetection < - 1 ) | | ( settingsData . Boot . XMPDetection > 2 ) ) {
settingsData . Boot . XMPDetection = - 1 ;
2019-09-03 11:58:42 +02:00
}
}
// Legacy bios protocol
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " Legacy " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : Prop property not string in Legacy \n " ) ;
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . LegacyBoot = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
} else if ( gFirmwareClover ) {
// default for CLOVER EFI boot
2021-02-06 18:16:46 +01:00
settingsData . Boot . LegacyBoot = " PBR " _XS8 ;
2019-09-03 11:58:42 +02:00
} else {
// default for UEFI boot
2021-02-06 18:16:46 +01:00
settingsData . Boot . LegacyBoot = " LegacyBiosDefault " _XS8 ;
2019-09-03 11:58:42 +02:00
}
// Entry for LegacyBiosDefault
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " LegacyBiosDefaultEntry " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . LegacyBiosDefaultEntry = ( UINT16 ) GetPropertyAsInteger ( Prop , 0 ) ; // disabled by default
2019-09-03 11:58:42 +02:00
}
// Whether or not to draw boot screen
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " CustomLogo " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Apple " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Alternate " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_ALT_APPLE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Theme " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_THEME ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-25 17:35:19 +02:00
XStringW customLogo = XStringW ( ) = Prop - > getString ( ) - > stringValue ( ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_USER ;
if ( settingsData . Boot . CustomLogo ! = NULL ) {
delete settingsData . Boot . CustomLogo ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomLogo = new XImage ;
settingsData . Boot . CustomLogo - > LoadXImage ( & self . getSelfVolumeRootDir ( ) , customLogo ) ;
if ( settingsData . Boot . CustomLogo - > isEmpty ( ) ) {
2020-04-23 18:05:21 +02:00
DBG ( " Custom boot logo not found at path `%ls`! \n " , customLogo . wc_str ( ) ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
} else if ( Prop - > isData ( ) & & Prop - > getData ( ) - > dataLenValue ( ) > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_USER ;
if ( settingsData . Boot . CustomLogo ! = NULL ) {
delete settingsData . Boot . CustomLogo ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomLogo = new XImage ;
settingsData . Boot . CustomLogo - > FromPNG ( Prop - > getData ( ) - > dataValue ( ) , Prop - > getData ( ) - > dataLenValue ( ) ) ;
if ( settingsData . Boot . CustomLogo - > isEmpty ( ) ) {
2020-08-25 17:35:19 +02:00
DBG ( " Custom boot logo not decoded from data! \n " /*, Prop->getString()->stringValue().c_str()*/ ) ;
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_USER_DISABLED ;
2019-09-03 11:58:42 +02:00
}
} else {
2021-02-06 18:16:46 +01:00
settingsData . Boot . CustomBoot = CUSTOM_BOOT_DISABLED ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
DBG ( " Custom boot %s (0x%llX) \n " , CustomBootModeToStr ( settingsData . Boot . CustomBoot ) , ( uintptr_t ) settingsData . Boot . CustomLogo ) ;
2019-09-03 11:58:42 +02:00
}
//*** SYSTEM ***
2021-02-06 18:16:46 +01:00
settingsData . WithKexts = TRUE ; //default
2020-08-25 17:35:19 +02:00
const TagDict * SystemParametersDict = CfgDict - > dictPropertyForKey ( " SystemParameters " ) ;
if ( SystemParametersDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
// Inject kexts
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = SystemParametersDict - > propertyForKey ( " InjectKexts " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . WithKexts = TRUE ;
2020-08-18 18:45:44 +02:00
} else if ( ( Prop - > isString ( ) ) & &
2020-08-25 17:35:19 +02:00
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Detect " ) ) ) {
2021-02-06 18:16:46 +01:00
// settingsData.WithKexts = TRUE;
settingsData . WithKextsIfNoFakeSMC = TRUE ;
2019-09-03 11:58:42 +02:00
}
}
// No caches - obsolete
2020-08-25 17:35:19 +02:00
Prop = SystemParametersDict - > propertyForKey ( " NoCaches " ) ;
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . NoCaches = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-10-27 19:51:28 +01:00
//test float - success
// Prop = SystemParametersDict->propertyForKey("BlueValue");
// float tmpF = GetPropertyFloat(Prop, 1.2f);
// DBG(" get BlueValue=%f\n", tmpF);
2020-04-22 19:52:21 +02:00
2019-09-03 11:58:42 +02:00
}
// KernelAndKextPatches
2020-08-25 17:35:19 +02:00
const TagDict * KernelAndKextPatchesDict = CfgDict - > dictPropertyForKey ( " KernelAndKextPatches " ) ;
if ( KernelAndKextPatchesDict ! = NULL ) {
2021-02-06 18:16:46 +01:00
FillinKextPatches ( & settingsData . KernelAndKextPatches , KernelAndKextPatchesDict ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagDict * GUIDict = CfgDict - > dictPropertyForKey ( " GUI " ) ;
if ( GUIDict ! = NULL ) {
const TagStruct * Prop = GUIDict - > propertyForKey ( " Timezone " ) ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Timezone = ( INT32 ) GetPropertyAsInteger ( Prop , settingsData . GUI . Timezone ) ;
2019-09-03 11:58:42 +02:00
//initialize Daylight when we know timezone
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
2019-09-03 11:58:42 +02:00
EFI_TIME Now ;
gRT - > GetTime ( & Now , NULL ) ;
2021-02-06 18:16:46 +01:00
INT32 NowHour = Now . Hour + settingsData . GUI . Timezone ;
2019-09-03 11:58:42 +02:00
if ( NowHour < 0 ) NowHour + = 24 ;
if ( NowHour > = 24 ) NowHour - = 24 ;
2020-04-16 13:04:24 +02:00
ThemeX . Daylight = ( NowHour > 8 ) & & ( NowHour < 20 ) ;
2021-02-06 18:16:46 +01:00
# endif
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " Theme " ) ;
if ( Prop ! = NULL & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
ThemeX . Theme . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Theme . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
DBG ( " Default theme: %ls \n " , settingsData . GUI . Theme . wc_str ( ) ) ;
2020-04-19 12:26:13 +02:00
OldChosenTheme = 0xFFFF ; //default for embedded
2020-08-31 09:22:11 +02:00
for ( UINTN i = 0 ; i < ThemeNameArray . size ( ) ; i + + ) {
2020-04-19 12:26:13 +02:00
//now comparison is case sensitive
2021-02-06 18:16:46 +01:00
if ( settingsData . GUI . Theme . equalIC ( ThemeNameArray [ i ] ) ) {
2020-04-19 12:26:13 +02:00
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-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " EmbeddedThemeType " ) ;
if ( Prop & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Dark " ) ) {
2020-04-19 12:26:13 +02:00
ThemeX . DarkEmbedded = TRUE ;
//ThemeX.Font = FONT_GRAY;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Light " ) ) {
2020-04-19 12:26:13 +02:00
ThemeX . DarkEmbedded = FALSE ;
//ThemeX.Font = FONT_ALFA;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " Daytime " ) ) {
2020-04-19 12:26:13 +02:00
ThemeX . DarkEmbedded = ! ThemeX . Daylight ;
//ThemeX.Font = ThemeX.Daylight?FONT_ALFA:FONT_GRAY;
2020-03-26 09:18:28 +01:00
}
}
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " PlayAsync " ) ; //PlayAsync
2021-02-06 18:16:46 +01:00
settingsData . PlayAsync = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
// CustomIcons
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " CustomIcons " ) ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . CustomIcons = IsPropertyNotNullAndTrue ( Prop ) ;
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " TextOnly " ) ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . TextOnly = IsPropertyNotNullAndTrue ( Prop ) ;
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " ShowOptimus " ) ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . ShowOptimus = IsPropertyNotNullAndTrue ( Prop ) ;
2020-08-22 15:39:24 +02:00
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " ScreenResolution " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-25 17:35:19 +02:00
if ( ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . ScreenResolution . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-09-29 14:15:11 +02:00
Prop = GUIDict - > propertyForKey ( " ProvideConsoleGop " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ProvideConsoleGop = ! IsPropertyNotNullAndFalse ( Prop ) ; //default is true
2020-09-29 14:15:11 +02:00
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " ConsoleMode " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-25 17:35:19 +02:00
if ( Prop - > isInt64 ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . ConsoleMode = Prop - > getInt64 ( ) - > intValue ( ) ;
2020-08-25 17:35:19 +02:00
} else if ( ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Max " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . ConsoleMode = - 1 ;
2020-04-23 18:05:21 +02:00
DBG ( " ConsoleMode will be set to highest mode \n " ) ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Min " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . 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 {
2021-02-06 18:16:46 +01:00
settingsData . GUI . ConsoleMode = ( INT32 ) AsciiStrDecimalToUintn ( Prop - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
2021-02-06 18:16:46 +01:00
if ( settingsData . GUI . ConsoleMode > 0 ) {
DBG ( " ConsoleMode will be set to mode #%lld \n " , settingsData . GUI . ConsoleMode ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " Language " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . Language = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " en " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = english ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Codepage = 0xC0 ;
settingsData . GUI . CodepageSize = 0 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " ru " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = russian ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Codepage = 0x410 ;
settingsData . GUI . CodepageSize = 0x40 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " ua " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = ukrainian ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Codepage = 0x400 ;
settingsData . GUI . CodepageSize = 0x60 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " fr " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = french ; //default is extended latin
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " it " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = italian ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " es " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = spanish ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " pt " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = portuguese ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " br " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = brasil ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " de " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = german ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " nl " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = dutch ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " pl " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = polish ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " cz " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = czech ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " hr " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = croatian ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " id " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = indonesian ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " zh_CN " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = chinese ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Codepage = 0x3400 ;
settingsData . GUI . CodepageSize = 0x19C0 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " ro " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = romanian ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " ko " ) ) {
2019-09-03 11:58:42 +02:00
gLanguage = korean ;
2021-02-06 18:16:46 +01:00
settingsData . GUI . Codepage = 0x1100 ;
settingsData . GUI . CodepageSize = 0x100 ;
2019-09-03 11:58:42 +02:00
}
}
2021-02-06 18:16:46 +01:00
// if (settingsData.Language != NULL) { // settingsData.Language != NULL cannot be false because settingsData.Language is dclared as CHAR8 Language[16]; Must we replace by settingsData.Language[0] != NULL
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " KbdPrevLang " ) ;
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . KbdPrevLang = IsPropertyNotNullAndTrue ( Prop ) ;
2020-08-25 17:35:19 +02:00
}
2020-03-11 14:24:29 +01:00
// }
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagDict * MouseDict = GUIDict - > dictPropertyForKey ( " Mouse " ) ;
if ( MouseDict ! = NULL ) {
const TagStruct * prop = MouseDict - > propertyForKey ( " Speed " ) ;
if ( prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . PointerSpeed = ( INT32 ) GetPropertyAsInteger ( prop , 0 ) ;
settingsData . PointerEnabled = ( settingsData . PointerSpeed ! = 0 ) ;
2019-09-03 11:58:42 +02:00
}
//but we can disable mouse even if there was positive speed
2020-08-25 17:35:19 +02:00
prop = MouseDict - > propertyForKey ( " Enabled " ) ;
if ( IsPropertyNotNullAndFalse ( prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . PointerEnabled = FALSE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop = MouseDict - > propertyForKey ( " Mirror " ) ;
if ( IsPropertyNotNullAndTrue ( prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . PointerMirror = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop = MouseDict - > propertyForKey ( " DoubleClickTime " ) ;
if ( prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . DoubleClickTime = ( UINT64 ) GetPropertyAsInteger ( prop , 500 ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-22 15:39:24 +02:00
// hide by name/uuid. Array of string
2020-08-25 17:35:19 +02:00
const TagArray * HideArray = GUIDict - > arrayPropertyForKey ( " Hide " ) ;
if ( HideArray ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = HideArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . HVHideStrings . setEmpty ( ) ;
2020-08-15 22:39:25 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagStruct * prop2 = & HideArray - > arrayContent ( ) [ i ] ;
if ( ! prop2 - > isString ( ) ) {
2020-08-22 15:39:24 +02:00
MsgLog ( " MALFORMED PLIST : Hide must be an array of string " ) ;
2020-08-15 22:39:25 +02:00
continue ;
}
2020-08-25 17:35:19 +02:00
if ( prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . HVHideStrings . Add ( prop2 - > getString ( ) - > stringValue ( ) ) ;
2020-08-25 17:35:19 +02:00
DBG ( " Hiding entries with string %s \n " , prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2021-02-06 18:16:46 +01:00
settingsData . LinuxScan = TRUE ;
2019-09-03 11:58:42 +02:00
// Disable loader scan
2020-08-25 17:35:19 +02:00
Prop = GUIDict - > propertyForKey ( " Scan " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndFalse ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . DisableEntryScan = TRUE ;
settingsData . DisableToolScan = TRUE ;
settingsData . GUI . NoLegacy = TRUE ;
2020-08-18 18:45:44 +02:00
} else if ( Prop - > isDict ( ) ) {
2020-08-25 17:35:19 +02:00
const TagStruct * prop2 = Prop - > getDict ( ) - > propertyForKey ( " Entries " ) ;
if ( IsPropertyNotNullAndFalse ( prop2 ) ) {
2021-02-06 18:16:46 +01:00
settingsData . DisableEntryScan = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop2 = Prop - > getDict ( ) - > propertyForKey ( " Tool " ) ;
if ( IsPropertyNotNullAndFalse ( prop2 ) ) {
2021-02-06 18:16:46 +01:00
settingsData . DisableToolScan = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
prop2 = Prop - > getDict ( ) - > propertyForKey ( " Linux " ) ;
2021-02-06 18:16:46 +01:00
settingsData . LinuxScan = ! IsPropertyNotNullAndFalse ( prop2 ) ;
2020-08-25 17:35:19 +02:00
prop2 = Prop - > getDict ( ) - > propertyForKey ( " Legacy " ) ;
if ( prop2 ! = NULL ) {
if ( prop2 - > isFalse ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . NoLegacy = TRUE ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > isString ( ) ) & & prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' N ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' n ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . NoLegacy = TRUE ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' F ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' f ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . LegacyFirst = TRUE ;
2020-08-30 16:21:54 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
prop2 = Prop - > getDict ( ) - > propertyForKey ( " Kernel " ) ;
if ( prop2 ! = NULL ) {
if ( prop2 - > isFalse ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_NONE ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > isString ( ) ) & & prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' N ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' n ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = ( prop2 - > getString ( ) - > stringValue ( ) . length ( ) > 1 & & ( prop2 - > getString ( ) - > stringValue ( ) [ 1 ] = = ' E ' | | prop2 - > getString ( ) - > stringValue ( ) [ 1 ] = = ' e ' ) ) ? KERNEL_SCAN_NEWEST : KERNEL_SCAN_NONE ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' O ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' o ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_OLDEST ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' F ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' f ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_FIRST ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' L ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' l ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_LAST ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' M ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' m ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_MOSTRECENT ;
2020-08-25 17:35:19 +02:00
} else if ( ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' E ' ) | | ( prop2 - > getString ( ) - > stringValue ( ) [ 0 ] = = ' e ' ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelScan = KERNEL_SCAN_EARLIEST ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// Custom entries
2020-08-25 17:35:19 +02:00
const TagDict * CustomDict2 = GUIDict - > dictPropertyForKey ( " Custom " ) ;
if ( CustomDict2 ! = NULL ) {
const TagArray * arrayProp = CustomDict2 - > arrayPropertyForKey ( " Entries " ) ; // Entries is an array of dict
2020-08-30 16:21:54 +02:00
if ( arrayProp ! = NULL ) {
2020-08-25 17:35:19 +02:00
INTN Count = arrayProp - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2020-08-30 16:21:54 +02:00
for ( INTN i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * Dict3 = arrayProp - > dictElementAt ( i , " Custom/Entries " _XS8 ) ;
2019-09-03 11:58:42 +02:00
// Allocate an 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-09-03 23:34:44 +02:00
if ( ! 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-08-25 17:35:19 +02:00
const TagArray * LegacyArray = CustomDict2 - > arrayPropertyForKey ( " Legacy " ) ; // is an array of dict
if ( LegacyArray ! = NULL ) {
2019-09-03 11:58:42 +02:00
CUSTOM_LEGACY_ENTRY * Entry ;
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = LegacyArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * Dict3 = LegacyArray - > dictElementAt ( i , " Legacy " _XS8 ) ;
2019-09-03 11:58:42 +02:00
// Allocate an entry
2020-08-09 17:55:30 +02:00
Entry = new CUSTOM_LEGACY_ENTRY ;
2020-09-03 23:34:44 +02:00
// Fill it in
if ( ! FillingCustomLegacy ( Entry , Dict3 ) | | ! AddCustomLegacyEntry ( Entry ) ) {
delete Entry ;
2019-09-03 11:58:42 +02:00
}
}
}
}
2020-08-25 17:35:19 +02:00
const TagArray * ToolArray = CustomDict2 - > arrayPropertyForKey ( " Tool " ) ; // is an array of dict
if ( ToolArray ! = NULL ) {
2019-09-03 11:58:42 +02:00
CUSTOM_TOOL_ENTRY * Entry ;
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = ToolArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * Dict3 = ToolArray - > dictElementAt ( i , " Tool " _XS8 ) ;
2019-09-03 11:58:42 +02:00
// Allocate an entry
2020-08-09 17:55:30 +02:00
Entry = new CUSTOM_TOOL_ENTRY ;
2020-10-08 22:03:41 +02:00
// Fill it in
if ( ! FillingCustomTool ( Entry , Dict3 ) | | ! AddCustomToolEntry ( Entry ) ) {
delete Entry ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
}
2020-08-25 17:35:19 +02:00
const TagDict * GraphicsDict = CfgDict - > dictPropertyForKey ( " Graphics " ) ;
if ( GraphicsDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = GraphicsDict - > propertyForKey ( " PatchVBios " ) ;
2021-02-06 18:16:46 +01:00
settingsData . PatchVBios = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
settingsData . PatchVBiosBytesCount = 0 ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagArray * Dict2 = GraphicsDict - > arrayPropertyForKey ( " PatchVBiosBytes " ) ; // array of dict
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
INTN Count = Dict2 - > arrayContent ( ) . size ( ) ;
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
2021-02-06 18:16:46 +01:00
settingsData . PatchVBiosBytes = ( __typeof__ ( settingsData . PatchVBiosBytes ) ) AllocateZeroPool ( Count * sizeof ( VBIOS_PATCH_BYTES ) ) ;
2019-09-03 11:58:42 +02:00
// get all entries
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * dict3 = Dict2 - > dictElementAt ( i , " Graphics/PatchVBiosBytes " _XS8 ) ;
2019-09-03 11:58:42 +02:00
Valid = TRUE ;
// read entry
2021-02-06 18:16:46 +01:00
VBiosPatch = & settingsData . PatchVBiosBytes [ settingsData . PatchVBiosBytesCount ] ;
2020-08-25 17:35:19 +02:00
VBiosPatch - > Find = GetDataSetting ( dict3 , " Find " , & FindSize ) ;
VBiosPatch - > Replace = GetDataSetting ( dict3 , " Replace " , & ReplaceSize ) ;
2019-09-03 11:58:42 +02:00
if ( VBiosPatch - > Find = = NULL | | FindSize = = 0 ) {
Valid = FALSE ;
2021-01-27 17:49:58 +01: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 ;
2021-01-27 17:49:58 +01:00
DBG ( " PatchVBiosBytes[%lld]: missing Replace data \n " , i ) ;
2019-09-03 11:58:42 +02:00
}
if ( FindSize ! = ReplaceSize ) {
Valid = FALSE ;
2021-01-27 17:49:58 +01: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
2021-02-06 18:16:46 +01:00
+ + settingsData . PatchVBiosBytesCount ;
2019-09-03 11:58:42 +02:00
} 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 ;
}
}
}
2021-02-06 18:16:46 +01:00
if ( settingsData . PatchVBiosBytesCount = = 0 ) {
FreePool ( settingsData . PatchVBiosBytes ) ;
settingsData . PatchVBiosBytes = NULL ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-25 17:35:19 +02:00
GetEDIDSettings ( GraphicsDict ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagArray * DisableDriversArray = CfgDict - > arrayPropertyForKey ( " DisableDrivers " ) ; // array of string
if ( DisableDriversArray ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = DisableDriversArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . DisabledDriverArray . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = & DisableDriversArray - > arrayContent ( ) [ i ] ;
2020-08-22 15:39:24 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " MALFORMED PLIST : DisableDrivers must be an array of string " ) ;
continue ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
settingsData . DisabledDriverArray . Add ( Prop - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-25 17:35:19 +02:00
const TagDict * DevicesDict = CfgDict - > dictPropertyForKey ( " Devices " ) ;
if ( DevicesDict ! = NULL ) {
const TagDict * Dict2 = DevicesDict - > dictPropertyForKey ( " Audio " ) ;
2019-09-03 11:58:42 +02:00
if ( Dict2 ! = NULL ) {
// HDA
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = Dict2 - > propertyForKey ( " ResetHDA " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ResetHDA = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
const TagDict * RtVariablesDict = CfgDict - > dictPropertyForKey ( " RtVariables " ) ;
if ( RtVariablesDict ! = NULL ) {
const TagStruct * Prop = RtVariablesDict - > propertyForKey ( " ROM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
2020-08-27 15:02:25 +02:00
// that's ok. Property can be data, but not when the value is 'UseMacAddr0' or 'UseMacAddr1';
2020-08-18 18:45:44 +02:00
} else {
2020-08-25 17:35:19 +02:00
if ( ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " UseMacAddr0 " ) ) | |
( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " UseMacAddr1 " ) ) ) {
2020-08-18 18:45:44 +02:00
GetLegacyLanAddress = TRUE ;
}
2019-09-03 11:58:42 +02:00
}
}
}
2021-02-06 18:16:46 +01:00
settingsData . mmioWhiteListArray . setEmpty ( ) ;
2020-10-08 22:03:41 +02:00
// const TagDict* OcQuirksDict = CfgDict->dictPropertyForKey("OcQuirks");
//if ( OcQuirksDict ) panic("config.plist/OcQuirks has been renamed Quirks. Update your config.plist");
2020-09-30 20:56:55 +02:00
2020-10-08 22:03:41 +02:00
const TagDict * OcQuirksDict = CfgDict - > dictPropertyForKey ( " Quirks " ) ;
//if ( !OcQuirksDict ) panic("Cannot find config.plist/Quirks");
2020-09-17 01:01:36 +02:00
if ( OcQuirksDict ! = NULL ) {
const TagStruct * Prop ;
Prop = OcQuirksDict - > propertyForKey ( " AvoidRuntimeDefrag " ) ;
2020-10-08 22:03:41 +02:00
//if ( !Prop ) panic("Cannot find AvoidRuntimeDefrag in OcQuirks under root (OC booter quirks)");
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . AvoidRuntimeDefrag = ! IsPropertyNotNullAndFalse ( Prop ) ; //true if absent so no panic
settingsData . QuirksMask | = settingsData . ocBooterQuirks . AvoidRuntimeDefrag ? QUIRK_DEFRAG : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DevirtualiseMmio " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . DevirtualiseMmio = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . DevirtualiseMmio ? QUIRK_MMIO : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DisableSingleUser " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . DisableSingleUser = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . DisableSingleUser ? QUIRK_SU : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DisableVariableWrite " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . DisableVariableWrite = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . DisableVariableWrite ? QUIRK_VAR : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DiscardHibernateMap " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . DiscardHibernateMap = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . DiscardHibernateMap ? QUIRK_HIBER : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " EnableSafeModeSlide " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . EnableSafeModeSlide = ! IsPropertyNotNullAndFalse ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . EnableSafeModeSlide ? QUIRK_SAFE : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " EnableWriteUnprotector " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . EnableWriteUnprotector = ! IsPropertyNotNullAndFalse ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . EnableWriteUnprotector ? QUIRK_UNPROT : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ForceExitBootServices " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ForceExitBootServices = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . ForceExitBootServices ? QUIRK_EXIT : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ProtectMemoryRegions " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ProtectMemoryRegions = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . ProtectMemoryRegions ? QUIRK_REGION : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ProtectSecureBoot " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ProtectSecureBoot = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . ProtectSecureBoot ? QUIRK_SECURE : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ProtectUefiServices " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ProtectUefiServices = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . ProtectUefiServices ? QUIRK_UEFI : 0 ;
2020-10-27 19:51:28 +01:00
//it is in GUI section
// Prop = OcQuirksDict->propertyForKey( "ProvideConsoleGopEnable");
2021-02-06 18:16:46 +01:00
// settingsData.ProvideConsoleGop = !IsPropertyNotNullAndFalse(Prop);
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ProvideCustomSlide " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ProvideCustomSlide = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . ProvideCustomSlide ? QUIRK_CUSTOM : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ProvideMaxSlide " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . ProvideMaxSlide = ( UINT8 ) GetPropertyAsInteger ( Prop , 0 ) ; // cast will be safe when the new parser will ensure that the value is UINT8
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " RebuildAppleMemoryMap " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . RebuildAppleMemoryMap = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . RebuildAppleMemoryMap ? QUIRK_MAP : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " SetupVirtualMap " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . SetupVirtualMap = ! IsPropertyNotNullAndFalse ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . SetupVirtualMap ? QUIRK_VIRT : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " SignalAppleOS " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . SignalAppleOS = IsPropertyNotNullAndTrue ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . SignalAppleOS ? QUIRK_OS : 0 ;
2020-09-17 01:01:36 +02:00
Prop = OcQuirksDict - > propertyForKey ( " SyncRuntimePermissions " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ocBooterQuirks . SyncRuntimePermissions = ! IsPropertyNotNullAndFalse ( Prop ) ;
settingsData . QuirksMask | = settingsData . ocBooterQuirks . SyncRuntimePermissions ? QUIRK_PERM : 0 ;
settingsData . mmioWhiteListArray . setEmpty ( ) ;
2020-09-17 01:01:36 +02:00
const TagArray * Dict2 = OcQuirksDict - > arrayPropertyForKey ( " MmioWhitelist " ) ; // array of dict
2020-07-15 19:29:27 +02:00
if ( Dict2 ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN Count = Dict2 - > arrayContent ( ) . size ( ) ;
2020-07-15 19:29:27 +02:00
//OC_SCHEMA_INTEGER_IN ("Address", OC_MMIO_WL_STRUCT, Address),
//OC_SCHEMA_STRING_IN ("Comment", OC_MMIO_WL_STRUCT, Comment),
//OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_MMIO_WL_STRUCT, Enabled),
if ( Count > 0 ) {
2020-09-09 19:06:34 +02:00
for ( INTN i = 0 ; i < Count ; i + + )
{
2020-08-25 17:35:19 +02:00
const TagDict * Dict3 = Dict2 - > dictElementAt ( i , " MmioWhitelist " _XS8 ) ;
2020-09-09 19:06:34 +02:00
MMIOWhiteList * mmioWhiteListPtr = new MMIOWhiteList ( ) ;
MMIOWhiteList & mmioWhiteList = * mmioWhiteListPtr ;
2020-07-15 19:29:27 +02:00
2020-08-25 17:35:19 +02:00
const TagStruct * Prop2 = Dict3 - > propertyForKey ( " Comment " ) ;
2020-09-09 19:06:34 +02:00
if ( Prop2 ! = NULL & & Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
mmioWhiteList . comment = Prop2 - > getString ( ) - > stringValue ( ) ;
2020-07-15 19:29:27 +02:00
} else {
2020-09-09 19:06:34 +02:00
mmioWhiteList . comment = " (NoLabel) " _XS8 ;
2020-07-15 19:29:27 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = Dict3 - > propertyForKey ( " Address " ) ;
if ( Prop2 ! = 0 ) {
2020-09-09 19:06:34 +02:00
mmioWhiteList . address = GetPropertyAsInteger ( Prop2 , 0 ) ;
2020-08-25 17:35:19 +02:00
Prop2 = Dict3 - > propertyForKey ( " Enabled " ) ;
2020-09-09 19:06:34 +02:00
mmioWhiteList . enabled = IsPropertyNotNullAndTrue ( Prop2 ) ;
2020-07-15 19:29:27 +02:00
}
2021-02-06 18:16:46 +01:00
settingsData . mmioWhiteListArray . AddReference ( mmioWhiteListPtr , true ) ;
2020-07-15 19:29:27 +02:00
}
}
}
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " FuzzyMatch " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
settingsData . KernelAndKextPatches . FuzzyMatch = ! IsPropertyNotNullAndFalse ( Prop ) ;
2020-09-30 20:56:55 +02:00
}
Prop = OcQuirksDict - > propertyForKey ( " KernelCache " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL | | GlobalConfig . gBootChanged ) {
2020-09-30 20:56:55 +02:00
if ( Prop - > isString ( ) ) {
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelCache = Prop - > getString ( ) - > stringValue ( ) ;
2020-09-30 20:56:55 +02:00
} else {
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelCache = " Auto " _XS8 ;
2020-09-30 20:56:55 +02:00
}
} else {
2020-10-11 08:06:50 +02:00
MsgLog ( " MALFORMED PLIST : Quirks/KernelCache must be a string " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelCache = " Auto " _XS8 ;
2020-09-30 20:56:55 +02:00
}
}
// Booter Quirks
2020-10-08 22:03:41 +02:00
// Prop = OcQuirksDict->propertyForKey("AppleCpuPmCfgLock");
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.AppleCpuPmCfgLock = IsPropertyNotNullAndTrue(Prop);
settingsData . KernelAndKextPatches . OcKernelQuirks . AppleCpuPmCfgLock = settingsData . KernelAndKextPatches . KPAppleIntelCPUPM ;
2020-09-30 20:56:55 +02:00
2020-10-08 22:03:41 +02:00
// Prop = OcQuirksDict->propertyForKey("AppleXcpmCfgLock"); //
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.AppleXcpmCfgLock = IsPropertyNotNullAndTrue(Prop);
settingsData . KernelAndKextPatches . OcKernelQuirks . AppleXcpmCfgLock = settingsData . KernelAndKextPatches . KPKernelPm ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " AppleXcpmExtraMsrs " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . AppleXcpmExtraMsrs = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " AppleXcpmForceBoost " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . AppleXcpmForceBoost = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
2020-09-30 21:03:13 +02:00
// We can't use that Quirks because we don't delegate SMBios to OC.
// Prop = OcQuirksDict->propertyForKey("CustomSMBIOSGuid");
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.CustomSmbiosGuid = IsPropertyNotNullAndTrue(Prop);
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DisableIoMapper " ) ;
2020-10-08 22:03:41 +02:00
//if ( !Prop ) panic("Cannot find DisableIoMapper in config.plist/Quirks. You forgot to merge your quirks into one section. Update your config.plist");
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . DisableIoMapper = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DisableLinkeditJettison " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . DisableLinkeditJettison = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
2020-10-15 09:05:37 +02:00
// Prop = OcQuirksDict->propertyForKey("DisableRtcChecksum");
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.DisableRtcChecksum = IsPropertyNotNullAndTrue(Prop);
settingsData . KernelAndKextPatches . OcKernelQuirks . DisableRtcChecksum = settingsData . KernelAndKextPatches . KPAppleRTC ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " DummyPowerManagement " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . DummyPowerManagement = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ExternalDiskIcons " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . ExternalDiskIcons = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " IncreasePciBarSize " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . IncreasePciBarSize = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
2020-10-08 22:03:41 +02:00
// Prop = OcQuirksDict->propertyForKey("LapicKernelPanic");
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.LapicKernelPanic = IsPropertyNotNullAndTrue(Prop);
settingsData . KernelAndKextPatches . OcKernelQuirks . LapicKernelPanic = settingsData . KernelAndKextPatches . KPKernelLapic ;
2020-09-30 20:56:55 +02:00
2020-10-08 22:03:41 +02:00
// Prop = OcQuirksDict->propertyForKey("PanicNoKextDump");
2021-02-06 18:16:46 +01:00
// settingsData.KernelAndKextPatches.OcKernelQuirks.PanicNoKextDump = IsPropertyNotNullAndTrue(Prop); //KPPanicNoKextDump
settingsData . KernelAndKextPatches . OcKernelQuirks . PanicNoKextDump = settingsData . KernelAndKextPatches . KPPanicNoKextDump ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " PowerTimeoutKernelPanic " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . PowerTimeoutKernelPanic = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " ThirdPartyDrives " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . ThirdPartyDrives = IsPropertyNotNullAndTrue ( Prop ) ;
2020-09-30 20:56:55 +02:00
Prop = OcQuirksDict - > propertyForKey ( " XhciPortLimit " ) ;
2021-02-06 18:16:46 +01:00
settingsData . KernelAndKextPatches . OcKernelQuirks . XhciPortLimit = IsPropertyNotNullAndTrue ( Prop ) ;
2020-07-15 19:29:27 +02:00
}
2019-09-03 11:58:42 +02:00
}
return Status ;
}
2020-03-26 15:24:20 +01:00
2020-10-03 19:02:31 +02:00
void
2019-09-03 11:58:42 +02:00
ParseSMBIOSSettings (
2020-08-25 17:35:19 +02:00
const TagDict * DictPointer
2019-09-03 11:58:42 +02:00
)
{
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
const TagStruct * Prop1 ;
2019-09-03 11:58:42 +02:00
BOOLEAN Default = FALSE ;
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " ProductName " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductName \n " ) ;
} else {
MACHINE_TYPES Model ;
2020-08-25 17:35:19 +02:00
gSettings . ProductName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
// 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 ) ;
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-18 18:45:44 +02:00
DBG ( " Using ProductName from config: %s \n " , gSettings . ProductName . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " SmbiosVersion " ) ;
2020-08-22 15:39:24 +02:00
gSettings . SmbiosVersion = ( UINT16 ) GetPropertyAsInteger ( Prop , 0x204 ) ;
2019-11-15 13:50:12 +01:00
2019-09-03 11:58:42 +02:00
// Check for BiosVersion and BiosReleaseDate by Sherlocks
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BiosVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
DBG ( " BiosVersion: not set, Using BiosVersion from clover \n " ) ;
} else {
const CHAR8 * i = gSettings . RomVersion . c_str ( ) ;
2020-08-25 17:35:19 +02:00
const CHAR8 * j = Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ;
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
i + = AsciiStrLen ( i ) ;
while ( * i ! = ' . ' ) {
i - - ;
}
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
j + = AsciiStrLen ( j ) ;
while ( * j ! = ' . ' ) {
j - - ;
}
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
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 " ) ;
2020-08-18 18:45:44 +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 " ) ;
2020-08-18 18:45:44 +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 ] ) ) ) {
DBG ( " Using latest BiosVersion from clover \n " ) ;
} else if ( ( i [ 5 ] = = j [ 5 ] ) & & ( i [ 6 ] = = j [ 6 ] ) ) {
DBG ( " Found same BiosVersion in clover and config \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . RomVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
DBG ( " Using latest BiosVersion from config \n " ) ;
}
2019-09-03 11:58:42 +02:00
} else {
2020-08-25 17:35:19 +02:00
gSettings . RomVersion = Prop - > getString ( ) - > stringValue ( ) ;
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-08-25 17:35:19 +02:00
gSettings . RomVersion = Prop - > getString ( ) - > stringValue ( ) ;
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-08-15 15:47:56 +02:00
DBG ( " BiosVersion: %s \n " , gSettings . RomVersion . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop1 = DictPointer - > propertyForKey ( " BiosReleaseDate " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop1 ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop1 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in BiosReleaseDate \n " ) ;
} else {
if ( Prop ! = NULL ) {
const CHAR8 * i = gSettings . ReleaseDate . c_str ( ) ;
2020-08-25 17:35:19 +02:00
const CHAR8 * j = Prop1 - > getString ( ) - > stringValue ( ) . c_str ( ) ;
2020-08-18 18:45:44 +02:00
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");
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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 ] ) ) ) {
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
//DBG("Found same BiosReleaseDate in clover and config\n");
} else {
2020-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
}
2019-09-03 11:58:42 +02:00
} else {
2020-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
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-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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 ] ) ) ) {
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
//DBG("Found same BiosReleaseDate in clover and config\n");
} else {
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
//DBG("Using latest BiosReleaseDate from config\n");
}
2019-09-03 11:58:42 +02:00
} else {
2020-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
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-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 8 ] , j [ 9 ] ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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 ] ) ) ) {
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
//DBG("Found same BiosReleaseDate in clover and config\n");
} else {
2020-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
}
2019-09-03 11:58:42 +02:00
} else {
2020-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
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-08-25 17:35:19 +02:00
gSettings . ReleaseDate = Prop1 - > getString ( ) - > stringValue ( ) ;
2020-04-23 18:05:21 +02:00
//DBG("Using latest BiosReleaseDate from config\n");
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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");
2020-08-18 18:45:44 +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 ] ) ) ) {
//DBG("Found old BiosReleaseDate from config\n");
//DBG("Using latest BiosReleaseDate from clover\n");
} else if ( ( i [ 3 ] = = j [ 3 ] ) & & ( i [ 4 ] = = j [ 4 ] ) ) {
//DBG("Found same BiosReleaseDate in clover and config\n");
} else {
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
//DBG("Using latest BiosReleaseDate from config\n");
}
2019-09-03 11:58:42 +02:00
} else {
2020-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
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-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/20%c%c \n " , j [ 0 ] , j [ 1 ] , j [ 3 ] , j [ 4 ] , j [ 6 ] , j [ 7 ] ) ;
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-08-18 18:45:44 +02:00
//DBG("Found unknown date format from config\n");
if ( Prop ! = NULL ) {
i = gSettings . ReleaseDate . c_str ( ) ;
j = gSettings . RomVersion . c_str ( ) ;
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
j + = AsciiStrLen ( j ) ;
while ( * j ! = ' . ' ) {
j - - ;
}
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
if ( ( AsciiStrLen ( i ) = = 8 ) ) {
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
//DBG("Using the date of used BiosVersion\n");
} else if ( ( AsciiStrLen ( i ) = = 10 ) ) {
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/20%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
//DBG("Using the date of used BiosVersion\n");
}
} else {
//DBG("Using BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
}
}
2020-08-18 18:45:44 +02:00
} else {
2020-08-25 17:35:19 +02:00
//DBG("BiosReleaseDate: set to %s from config, Ignore BiosReleaseDate\n", Prop1->getString()->stringValue().c_str());
2020-08-18 18:45:44 +02:00
//DBG("Using BiosReleaseDate from clover\n");
2019-09-03 11:58:42 +02:00
}
}
} else {
if ( Prop ! = NULL ) {
2020-08-15 15:47:56 +02:00
const CHAR8 * i = gSettings . ReleaseDate . c_str ( ) ;
const CHAR8 * j = gSettings . RomVersion . c_str ( ) ;
2019-09-03 11:58:42 +02:00
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-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
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-08-15 15:47:56 +02:00
gSettings . ReleaseDate . S8Printf ( " %c%c/%c%c/20%c%c \n " , j [ 3 ] , j [ 4 ] , j [ 5 ] , j [ 6 ] , j [ 1 ] , j [ 2 ] ) ;
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-08-15 15:47:56 +02:00
DBG ( " BiosReleaseDate: %s \n " , gSettings . ReleaseDate . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " EfiVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in EfiVersion \n " ) ;
if ( gSettings . EfiVersion . notEmpty ( ) ) {
DBG ( " Using EfiVersion from clover: %s \n " , gSettings . EfiVersion . c_str ( ) ) ;
}
} else {
2020-08-25 17:35:19 +02:00
if ( AsciiStrVersionToUint64 ( gSettings . EfiVersion , 4 , 5 ) > AsciiStrVersionToUint64 ( Prop - > getString ( ) - > stringValue ( ) , 4 , 5 ) ) {
2020-08-18 18:45:44 +02:00
DBG ( " Using latest EfiVersion from clover: %s \n " , gSettings . EfiVersion . c_str ( ) ) ;
2020-08-25 17:35:19 +02:00
} else if ( AsciiStrVersionToUint64 ( gSettings . EfiVersion , 4 , 5 ) < AsciiStrVersionToUint64 ( Prop - > getString ( ) - > stringValue ( ) , 4 , 5 ) ) {
gSettings . EfiVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
gSettings . EfiVersion . trim ( ) ;
DBG ( " Using latest EfiVersion from config: %s \n " , gSettings . EfiVersion . c_str ( ) ) ;
} else {
DBG ( " Using EfiVersion from clover: %s \n " , gSettings . EfiVersion . c_str ( ) ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +02:00
} else if ( gSettings . EfiVersion . notEmpty ( ) ) {
2020-08-12 17:15:47 +02:00
DBG ( " Using EfiVersion from clover: %s \n " , gSettings . EfiVersion . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " FirmwareFeatures " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gFwFeatures = ( UINT32 ) GetPropertyAsInteger ( 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " FirmwareFeaturesMask " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gFwFeaturesMask = ( UINT32 ) GetPropertyAsInteger ( 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " PlatformFeature " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gPlatformFeature = ( UINT64 ) GetPropertyAsInteger ( Prop , ( INTN ) gPlatformFeature ) ;
2019-09-03 11:58:42 +02:00
} 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 {
2021-02-06 18:16:46 +01:00
DBG ( " Using PlatformFeature from clover: 0x%llX \n " , gPlatformFeature ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BiosVendor " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in BiosVendor \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . VendorName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Manufacturer " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Manufacturer \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . ManufactureName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Version " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Version \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . VersionNr = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Family " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Family \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . FamilyName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " SerialNumber " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in SerialNumber \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . SerialNr = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " SmUUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in SmUUID \n " ) ;
} else {
2021-01-31 10:50:23 +01:00
if ( IsValidGuidString ( Prop - > getString ( ) - > stringValue ( ) ) ) {
2020-09-23 15:47:47 +02:00
gSettings . SmUUID = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
} else {
2020-08-25 17:35:19 +02:00
DBG ( " Error: invalid SmUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BoardManufacturer " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in BoardManufacturer \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
gSettings . BoardManufactureName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BoardSerialNumber " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in BoardSerialNumber \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
gSettings . BoardSerialNumber = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Board-ID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Board-ID \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . BoardNumber = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
DBG ( " Board-ID set from config as %s \n " , gSettings . BoardNumber . c_str ( ) ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +02:00
if ( ! Default ) {
gSettings . BoardVersion = gSettings . ProductName ;
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BoardVersion " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in BoardVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . BoardVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " BoardType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gSettings . BoardType = ( UINT8 ) GetPropertyAsInteger ( 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " Mobile " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndFalse ( Prop ) )
2019-09-03 11:58:42 +02:00
gSettings . Mobile = FALSE ;
2020-08-22 15:39:24 +02:00
else if ( IsPropertyNotNullAndTrue ( Prop ) )
2019-09-03 11:58:42 +02:00
gSettings . Mobile = TRUE ;
} else if ( ! Default ) {
2020-08-15 15:47:56 +02:00
gSettings . Mobile = gSettings . ProductName . contains ( " MacBook " ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " LocationInChassis " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in LocationInChassis \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . LocationInChassis = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " ChassisManufacturer " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ChassisManufacturer \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . ChassisManufacturer = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " ChassisAssetTag " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ChassisAssetTag \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
gSettings . ChassisAssetTag = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " ChassisType " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gSettings . ChassisType = ( UINT8 ) GetPropertyAsInteger ( 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-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " NoRomInfo " ) ;
2019-12-12 15:51:55 +01:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
gSettings . NoRomInfo = IsPropertyNotNullAndTrue ( Prop ) ;
2019-12-12 15:51:55 +01:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
static void getACPISettings ( const TagDict * CfgDict )
{
const TagDict * ACPIDict = CfgDict - > dictPropertyForKey ( " ACPI " ) ;
if ( ACPIDict ) {
const TagArray * DropTablesArray = ACPIDict - > arrayPropertyForKey ( " DropTables " ) ; // array of dict
if ( DropTablesArray ) {
INTN i ;
INTN Count = DropTablesArray - > arrayContent ( ) . size ( ) ;
BOOLEAN Dropped ;
if ( Count > 0 ) {
DBG ( " Dropping %lld tables: \n " , Count ) ;
for ( i = 0 ; i < Count ; i + + ) {
UINT32 Signature = 0 ;
UINT32 TabLength = 0 ;
UINT64 TableId = 0 ;
BOOLEAN OtherOS = FALSE ;
const TagDict * Dict2 = DropTablesArray - > dictElementAt ( i , " ACPI/DropTables " _XS8 ) ;
DBG ( " - [%02lld]: Drop table " , i ) ;
// Get the table signatures to drop
const TagStruct * Prop2 = Dict2 - > propertyForKey ( " Signature " ) ;
if ( Prop2 & & ( Prop2 - > isString ( ) ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
CHAR8 s1 = 0 , s2 = 0 , s3 = 0 , s4 = 0 ;
const CHAR8 * str = Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ;
if ( * str ) {
s1 = * str + + ;
}
if ( * str ) {
s2 = * str + + ;
}
if ( * str ) {
s3 = * str + + ;
}
if ( * str ) {
s4 = * str + + ;
}
Signature = SIGNATURE_32 ( s1 , s2 , s3 , s4 ) ;
DBG ( " signature= \" %c%c%c%c \" (%8.8X) \n " , s1 , s2 , s3 , s4 , Signature ) ;
}
// Get the table ids to drop
Prop2 = Dict2 - > propertyForKey ( " TableId " ) ;
if ( Prop2 ! = NULL ) {
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in TableId \n " ) ;
} else {
UINTN IdIndex = 0 ;
CHAR8 Id [ 9 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
const CHAR8 * Str = Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ;
if ( Str ) {
while ( * Str & & ( IdIndex < 8 ) ) {
// DBG("%c", *Str);
Id [ IdIndex + + ] = * Str + + ;
}
}
CopyMem ( & TableId , ( CHAR8 * ) & Id [ 0 ] , 8 ) ;
DBG ( " table-id= \" %s \" (%16.16llX) \n " , Id , TableId ) ;
}
}
// Get the table len to drop
Prop2 = Dict2 - > propertyForKey ( " Length " ) ;
if ( Prop2 ! = NULL ) {
TabLength = ( UINT32 ) GetPropertyAsInteger ( Prop2 , 0 ) ;
DBG ( " length=%d(0x%X) " , TabLength , TabLength ) ;
}
// Check if to drop for other OS as well
Prop2 = Dict2 - > propertyForKey ( " DropForAllOS " ) ;
if ( Prop2 ! = NULL ) {
OtherOS = IsPropertyNotNullAndTrue ( Prop2 ) ;
}
DBG ( " ---- \n " ) ;
//set to drop
if ( gSettings . ACPIDropTables ) {
ACPI_DROP_TABLE * DropTable = gSettings . ACPIDropTables ;
DBG ( " - set table: %08X, %16llx to drop: " , Signature , TableId ) ;
Dropped = FALSE ;
while ( DropTable ) {
if ( ( ( Signature = = DropTable - > Signature ) & &
( ! TableId | | ( DropTable - > TableId = = TableId ) ) & &
( ! TabLength | | ( DropTable - > Length = = TabLength ) ) ) | |
( ! Signature & & ( DropTable - > TableId = = TableId ) ) ) {
DropTable - > MenuItem . BValue = TRUE ;
DropTable - > OtherOS = OtherOS ;
gSettings . DropSSDT = FALSE ; //if one item=true then dropAll=false by default
//DBG(" true");
Dropped = TRUE ;
}
DropTable = DropTable - > Next ;
}
DBG ( " %s \n " , Dropped ? " yes " : " no " ) ;
}
}
}
}
const TagDict * DSDTDict = ACPIDict - > dictPropertyForKey ( " DSDT " ) ;
if ( DSDTDict ) {
//gSettings.DsdtName by default is "DSDT.aml", but name "BIOS" will mean autopatch
const TagStruct * Prop = DSDTDict - > propertyForKey ( " Name " ) ;
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in DSDT/Name \n " ) ;
} else {
gSettings . DsdtName = Prop - > getString ( ) - > stringValue ( ) ;
}
}
Prop = DSDTDict - > propertyForKey ( " Debug " ) ;
gSettings . DebugDSDT = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = DSDTDict - > propertyForKey ( " Rtc8Allowed " ) ;
gSettings . Rtc8Allowed = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = DSDTDict - > propertyForKey ( " PNLF_UID " ) ;
gSettings . PNLF_UID = ( UINT8 ) GetPropertyAsInteger ( Prop , 0x0A ) ;
Prop = DSDTDict - > propertyForKey ( " FixMask " ) ;
gSettings . FixDsdt = ( UINT32 ) GetPropertyAsInteger ( Prop , gSettings . FixDsdt ) ;
const TagDict * FixesDict = DSDTDict - > dictPropertyForKey ( " Fixes " ) ;
if ( FixesDict ! = NULL ) {
UINTN Index ;
// DBG("Fixes will override DSDT fix mask %08X!\n", gSettings.FixDsdt);
gSettings . FixDsdt = 0 ;
for ( Index = 0 ; Index < sizeof ( FixesConfig ) / sizeof ( FixesConfig [ 0 ] ) ; Index + + ) {
const TagStruct * Prop2 = FixesDict - > propertyForKey ( FixesConfig [ Index ] . newName ) ;
if ( ! Prop2 & & FixesConfig [ Index ] . oldName ) {
Prop2 = FixesDict - > propertyForKey ( FixesConfig [ Index ] . oldName ) ;
}
if ( IsPropertyNotNullAndTrue ( Prop2 ) ) {
gSettings . FixDsdt | = FixesConfig [ Index ] . bitData ;
}
}
}
DBG ( " - final DSDT Fix mask=%08X \n " , gSettings . FixDsdt ) ;
const TagArray * PatchesArray = DSDTDict - > arrayPropertyForKey ( " Patches " ) ; // array of dict
if ( PatchesArray ! = NULL ) {
INTN i ;
INTN Count = PatchesArray - > arrayContent ( ) . size ( ) ;
if ( Count > 0 ) {
2020-08-27 20:47:56 +02:00
// gSettings.DSDTPatchArray.size() = (UINT32)Count;
// 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 = new INPUT_ITEM[Count];
2020-08-25 17:35:19 +02:00
DBG ( " PatchesDSDT: %lld requested \n " , Count ) ;
2020-08-27 20:47:56 +02:00
gSettings . DSDTPatchArray . setEmpty ( ) ;
for ( i = 0 ; i < Count ; i + + )
{
DSDT_Patch * dsdtPatchPtr = new DSDT_Patch ( ) ;
DSDT_Patch & dsdtPatch = * dsdtPatchPtr ;
2020-08-25 17:35:19 +02:00
UINTN Size = 0 ;
const TagDict * Prop2 = PatchesArray - > dictElementAt ( i , " DSDT/Patches " _XS8 ) ;
DBG ( " - [%02lld]: " , i ) ;
XString8 DSDTPatchesLabel ;
const TagStruct * Prop3 = Prop2 - > propertyForKey ( " Comment " ) ;
if ( Prop3 ! = NULL & & ( Prop3 - > isString ( ) ) & & Prop3 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
DSDTPatchesLabel = Prop3 - > getString ( ) - > stringValue ( ) ;
} else {
DSDTPatchesLabel = " (NoLabel) " _XS8 ;
}
2020-08-27 20:47:56 +02:00
dsdtPatch . PatchDsdtLabel = DSDTPatchesLabel ;
DBG ( " (%s) " , dsdtPatch . PatchDsdtLabel . c_str ( ) ) ;
2020-08-25 17:35:19 +02:00
Prop3 = Prop2 - > propertyForKey ( " Disabled " ) ;
2020-08-27 20:47:56 +02:00
dsdtPatch . PatchDsdtMenuItem . BValue = ! IsPropertyNotNullAndTrue ( Prop3 ) ;
2020-08-25 17:35:19 +02:00
//DBG(" DSDT bin patch #%d ", i);
2020-08-27 20:47:56 +02:00
UINT8 * data = GetDataSetting ( Prop2 , " Find " , & Size ) ;
dsdtPatch . PatchDsdtFind . stealValueFrom ( data , Size ) ;
DBG ( " lenToFind: %zu " , dsdtPatch . PatchDsdtFind . size ( ) ) ;
data = GetDataSetting ( Prop2 , " Replace " , & Size ) ;
dsdtPatch . PatchDsdtReplace . stealValueFrom ( data , Size ) ;
DBG ( " , lenToReplace: %zu " , dsdtPatch . PatchDsdtReplace . size ( ) ) ;
data = GetDataSetting ( Prop2 , " TgtBridge " , & Size ) ;
2020-10-07 11:15:21 +02:00
if ( Size ! = 0 ) {
if ( Size ! = 4 ) {
DBG ( " \n TgtBridge must 4 bytes. It's %llu byte(s). Ignored \n " , Size ) ;
} else {
dsdtPatch . PatchDsdtTgt . stealValueFrom ( data , Size ) ;
DBG ( " , Target Bridge: %c%c%c%c " , dsdtPatch . PatchDsdtTgt [ 0 ] , dsdtPatch . PatchDsdtTgt [ 1 ] , dsdtPatch . PatchDsdtTgt [ 2 ] , dsdtPatch . PatchDsdtTgt [ 3 ] ) ;
}
}
DBG ( " \n " ) ;
2020-08-27 20:47:56 +02:00
if ( ! dsdtPatch . PatchDsdtMenuItem . BValue ) {
2020-08-25 17:35:19 +02:00
DBG ( " patch disabled at config \n " ) ;
}
2020-08-27 20:47:56 +02:00
gSettings . DSDTPatchArray . AddReference ( dsdtPatchPtr , true ) ;
2020-08-25 17:35:19 +02:00
}
} //if count > 0
} //if prop PatchesDSDT
Prop = DSDTDict - > propertyForKey ( " ReuseFFFF " ) ;
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
gSettings . ReuseFFFF = TRUE ;
}
Prop = DSDTDict - > propertyForKey ( " SuspendOverride " ) ;
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
gSettings . SuspendOverride = TRUE ;
}
/*
Prop = GetProperty ( Dict2 , " DropOEM_DSM " ) ;
defDSM = FALSE ;
if ( Prop ! = NULL ) {
defDSM = TRUE ; //set by user
if ( IsPropertyTrue ( Prop ) ) {
gSettings . DropOEM_DSM = 0xFFFF ;
} else if ( IsPropertyFalse ( Prop ) ) {
gSettings . DropOEM_DSM = 0 ;
} else if ( Prop - > isInt ( ) ) {
gSettings . DropOEM_DSM = ( UINT16 ) ( UINTN ) Prop - > ? ? ;
} else if ( Prop - > type = = kTagTypeDict ) {
Prop2 = GetProperty ( Prop , " ATI " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_ATI ;
}
Prop2 = GetProperty ( Prop , " NVidia " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_NVIDIA ;
}
Prop2 = GetProperty ( Prop , " IntelGFX " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_INTEL ;
}
Prop2 = GetProperty ( Prop , " HDA " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_HDA ;
}
Prop2 = GetProperty ( Prop , " HDMI " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_HDMI ;
}
Prop2 = GetProperty ( Prop , " SATA " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_SATA ;
}
Prop2 = GetProperty ( Prop , " LAN " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_LAN ;
}
Prop2 = GetProperty ( Prop , " WIFI " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_WIFI ;
}
Prop2 = GetProperty ( Prop , " USB " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_USB ;
}
Prop2 = GetProperty ( Prop , " LPC " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_LPC ;
}
Prop2 = GetProperty ( Prop , " SmBUS " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_SMBUS ;
}
Prop2 = GetProperty ( Prop , " Firewire " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_FIREWIRE ;
}
Prop2 = GetProperty ( Prop , " IDE " ) ;
if ( IsPropertyTrue ( Prop2 ) ) {
gSettings . DropOEM_DSM | = DEV_IDE ;
}
}
}
*/
}
const TagDict * SSDTDict = ACPIDict - > dictPropertyForKey ( " SSDT " ) ;
if ( SSDTDict ) {
const TagStruct * Prop2 = SSDTDict - > propertyForKey ( " Generate " ) ;
if ( Prop2 ! = NULL ) {
if ( IsPropertyNotNullAndTrue ( Prop2 ) ) {
gSettings . GeneratePStates = TRUE ;
gSettings . GenerateCStates = TRUE ;
gSettings . GenerateAPSN = TRUE ;
gSettings . GenerateAPLF = TRUE ;
gSettings . GeneratePluginType = TRUE ;
} else if ( IsPropertyNotNullAndFalse ( Prop2 ) ) {
gSettings . GeneratePStates = FALSE ;
gSettings . GenerateCStates = FALSE ;
gSettings . GenerateAPSN = FALSE ;
gSettings . GenerateAPLF = FALSE ;
gSettings . GeneratePluginType = FALSE ;
} else if ( Prop2 - > isDict ( ) ) {
const TagStruct * Prop = Prop2 - > getDict ( ) - > propertyForKey ( " PStates " ) ;
gSettings . GeneratePStates = IsPropertyNotNullAndTrue ( Prop ) ;
gSettings . GenerateAPSN = gSettings . GeneratePStates ;
gSettings . GenerateAPLF = gSettings . GeneratePStates ;
gSettings . GeneratePluginType = gSettings . GeneratePStates ;
Prop = Prop2 - > getDict ( ) - > propertyForKey ( " CStates " ) ;
gSettings . GenerateCStates = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = Prop2 - > getDict ( ) - > propertyForKey ( " APSN " ) ;
if ( Prop ) {
gSettings . GenerateAPSN = IsPropertyNotNullAndTrue ( Prop ) ;
}
Prop = Prop2 - > getDict ( ) - > propertyForKey ( " APLF " ) ;
if ( Prop ) {
gSettings . GenerateAPLF = IsPropertyNotNullAndTrue ( Prop ) ;
}
Prop = Prop2 - > getDict ( ) - > propertyForKey ( " PluginType " ) ;
if ( Prop ) {
gSettings . GeneratePluginType = IsPropertyNotNullAndTrue ( Prop ) ;
}
}
}
const TagStruct * Prop = SSDTDict - > propertyForKey ( " DropOem " ) ;
gSettings . DropSSDT = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = SSDTDict - > propertyForKey ( " NoOemTableId " ) ; // to disable OEM table ID on ACPI/orgin/SSDT file names
gSettings . NoOemTableId = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = SSDTDict - > propertyForKey ( " NoDynamicExtract " ) ; // to disable extracting child SSDTs
gSettings . NoDynamicExtract = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = SSDTDict - > propertyForKey ( " UseSystemIO " ) ;
gSettings . EnableISS = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = SSDTDict - > propertyForKey ( " EnableC7 " ) ;
gSettings . EnableC7 = IsPropertyNotNullAndTrue ( Prop ) ;
DBG ( " EnableC7: %s \n " , gSettings . EnableC7 ? " yes " : " no " ) ;
Prop = SSDTDict - > propertyForKey ( " EnableC6 " ) ;
gSettings . EnableC6 = IsPropertyNotNullAndTrue ( Prop ) ;
DBG ( " EnableC6: %s \n " , gSettings . EnableC6 ? " yes " : " no " ) ;
Prop = SSDTDict - > propertyForKey ( " EnableC4 " ) ;
gSettings . EnableC4 = IsPropertyNotNullAndTrue ( Prop ) ;
DBG ( " EnableC4: %s \n " , gSettings . EnableC4 ? " yes " : " no " ) ;
Prop = SSDTDict - > propertyForKey ( " EnableC2 " ) ;
gSettings . EnableC2 = IsPropertyNotNullAndTrue ( Prop ) ;
DBG ( " EnableC2: %s \n " , gSettings . EnableC2 ? " yes " : " no " ) ;
Prop = SSDTDict - > propertyForKey ( " C3Latency " ) ;
gSettings . C3Latency = ( UINT16 ) GetPropertyAsInteger ( Prop , gSettings . C3Latency ) ;
DBG ( " C3Latency: %d \n " , gSettings . C3Latency ) ;
Prop = SSDTDict - > propertyForKey ( " PLimitDict " ) ;
gSettings . PLimitDict = ( UINT8 ) GetPropertyAsInteger ( Prop , 0 ) ;
Prop = SSDTDict - > propertyForKey ( " UnderVoltStep " ) ;
gSettings . UnderVoltStep = ( UINT8 ) GetPropertyAsInteger ( Prop , 0 ) ;
Prop = SSDTDict - > propertyForKey ( " DoubleFirstState " ) ;
gSettings . DoubleFirstState = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = SSDTDict - > propertyForKey ( " MinMultiplier " ) ;
gSettings . MinMultiplier = ( UINT8 ) GetPropertyAsInteger ( Prop , gSettings . MinMultiplier ) ;
DBG ( " MinMultiplier: %d \n " , gSettings . MinMultiplier ) ;
Prop = SSDTDict - > propertyForKey ( " MaxMultiplier " ) ;
gSettings . MaxMultiplier = ( UINT8 ) GetPropertyAsInteger ( Prop , gSettings . MaxMultiplier ) ;
DBG ( " MaxMultiplier: %d \n " , gSettings . MaxMultiplier ) ;
Prop = SSDTDict - > propertyForKey ( " PluginType " ) ;
gSettings . PluginType = ( UINT8 ) GetPropertyAsInteger ( Prop , gSettings . PluginType ) ;
DBG ( " PluginType: %d \n " , gSettings . PluginType ) ;
2021-02-06 18:16:46 +01:00
}
2020-08-25 17:35:19 +02:00
// Prop = GetProperty(DictPointer, "DropMCFG");
// gSettings.DropMCFG = IsPropertyTrue(Prop);
const TagStruct * Prop = ACPIDict - > propertyForKey ( " ResetAddress " ) ;
if ( Prop ) {
gSettings . ResetAddr = ( UINT32 ) GetPropertyAsInteger ( Prop , 0x64 ) ;
DBG ( " ResetAddr: 0x%llX \n " , gSettings . ResetAddr ) ;
if ( gSettings . ResetAddr = = 0x64 ) {
gSettings . ResetVal = 0xFE ;
} else if ( gSettings . ResetAddr = = 0xCF9 ) {
gSettings . ResetVal = 0x06 ;
}
DBG ( " Calc ResetVal: 0x%hhX \n " , gSettings . ResetVal ) ;
}
Prop = ACPIDict - > propertyForKey ( " ResetValue " ) ;
gSettings . ResetVal = ( UINT8 ) GetPropertyAsInteger ( Prop , gSettings . ResetVal ) ;
DBG ( " ResetVal: 0x%hhX \n " , gSettings . ResetVal ) ;
//other known pair is 0x0CF9/0x06. What about 0x92/0x01 ?
Prop = ACPIDict - > propertyForKey ( " HaltEnabler " ) ;
gSettings . SlpSmiEnable = IsPropertyNotNullAndTrue ( Prop ) ;
//
Prop = ACPIDict - > propertyForKey ( " FixHeaders " ) ;
gSettings . FixHeaders = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = ACPIDict - > propertyForKey ( " FixMCFG " ) ;
gSettings . FixMCFG = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = ACPIDict - > propertyForKey ( " DisableASPM " ) ;
gSettings . NoASPM = IsPropertyNotNullAndTrue ( Prop ) ;
Prop = ACPIDict - > propertyForKey ( " smartUPS " ) ;
gSettings . smartUPS = IsPropertyNotNullAndTrue ( Prop ) ;
DBG ( " smartUPS: present \n " ) ;
Prop = ACPIDict - > propertyForKey ( " PatchAPIC " ) ;
gSettings . PatchNMI = IsPropertyNotNullAndTrue ( Prop ) ;
const TagArray * SortedOrderArray = ACPIDict - > arrayPropertyForKey ( " SortedOrder " ) ; // array of string
2020-08-31 11:43:18 +02:00
if ( SortedOrderArray ) {
2020-08-25 17:35:19 +02:00
INTN i ;
INTN Count = SortedOrderArray - > arrayContent ( ) . size ( ) ;
const TagStruct * Prop2 = NULL ;
if ( Count > 0 ) {
gSettings . SortedACPICount = 0 ;
gSettings . SortedACPI = ( __typeof__ ( gSettings . SortedACPI ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
for ( i = 0 ; i < Count ; i + + ) {
Prop2 = & SortedOrderArray - > arrayContent ( ) [ i ] ;
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " MALFORMED PLIST : SortedOrder must be an array of string " ) ;
continue ;
}
gSettings . SortedACPI [ gSettings . SortedACPICount + + ] = SWPrintf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
}
}
}
Prop = ACPIDict - > propertyForKey ( " AutoMerge " ) ;
gSettings . AutoMerge = IsPropertyNotNullAndTrue ( Prop ) ;
const TagArray * DisabledAMLArray = ACPIDict - > arrayPropertyForKey ( " DisabledAML " ) ; // array of string
if ( DisabledAMLArray ) {
INTN i ;
INTN Count = DisabledAMLArray - > arrayContent ( ) . size ( ) ;
const TagStruct * Prop2 = NULL ;
if ( Count > 0 ) {
gSettings . DisabledAMLCount = 0 ;
gSettings . DisabledAML = ( __typeof__ ( gSettings . DisabledAML ) ) AllocateZeroPool ( Count * sizeof ( CHAR16 * ) ) ;
if ( gSettings . DisabledAML ) {
for ( i = 0 ; i < Count ; i + + ) {
Prop2 = & DisabledAMLArray - > arrayContent ( ) [ i ] ;
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " MALFORMED PLIST : DisabledAML must be an array of string " ) ;
continue ;
}
gSettings . DisabledAML [ gSettings . DisabledAMLCount + + ] = SWPrintf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
}
}
}
}
const TagDict * RenameDevicesDict = ACPIDict - > dictPropertyForKey ( " RenameDevices " ) ; // dict of key/string
if ( RenameDevicesDict ) {
INTN i ;
INTN Count = RenameDevicesDict - > dictKeyCount ( ) ;
if ( Count > 0 ) {
gSettings . DeviceRenameCount = 0 ;
gSettings . DeviceRename = ( __typeof__ ( gSettings . DeviceRename ) ) AllocateZeroPool ( Count * sizeof ( ACPI_NAME_LIST ) ) ;
DBG ( " Devices to rename %lld \n " , Count ) ;
for ( i = 0 ; i < Count ; i + + ) {
const TagKey * key ;
const TagStruct * value ;
if ( ! EFI_ERROR ( RenameDevicesDict - > getKeyAndValueAtIndex ( i , & key , & value ) ) ) {
ACPI_NAME_LIST * List = ParseACPIName ( key - > keyStringValue ( ) ) ;
gSettings . DeviceRename [ gSettings . DeviceRenameCount ] . Next = List ;
while ( List ) {
DBG ( " %s: " , List - > Name ) ;
List = List - > Next ;
}
if ( value - > isString ( ) ) {
gSettings . DeviceRename [ gSettings . DeviceRenameCount + + ] . Name = S8Printf ( " %s " , value - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
DBG ( " ->will be renamed to %s \n " , value - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
}
}
}
}
}
}
}
2019-09-03 11:58:42 +02:00
EFI_STATUS
2021-02-06 18:16:46 +01:00
GetUserSettings ( const TagDict * CfgDict , SETTINGS_DATA & settingsData )
2019-09-03 11:58:42 +02:00
{
2021-02-06 18:16:46 +01:00
// EFI_STATUS Status = EFI_NOT_FOUND;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( CfgDict ! = NULL ) {
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-08-25 17:35:19 +02:00
const TagDict * BootDict = CfgDict - > dictPropertyForKey ( " Boot " ) ;
if ( BootDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = BootDict - > propertyForKey ( " Arguments " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop ! = NULL & & Prop - > isString ( ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) & & ! settingsData . Boot . BootArgs . contains ( Prop - > getString ( ) - > stringValue ( ) ) ) {
settingsData . Boot . BootArgs = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
//gBootArgsChanged = TRUE;
2021-02-06 18:16:46 +01:00
//GlobalConfig.gBootChanged = TRUE;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = BootDict - > propertyForKey ( " NeverDoRecovery " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NeverDoRecovery = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
//Graphics
2020-08-25 17:35:19 +02:00
const TagDict * GraphicsDict = CfgDict - > dictPropertyForKey ( " Graphics " ) ;
if ( GraphicsDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = GraphicsDict - > propertyForKey ( " Inject " ) ;
if ( Prop ! = NULL ) {
if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GraphicsInjector = TRUE ;
settingsData . InjectIntel = TRUE ;
settingsData . InjectATI = TRUE ;
settingsData . InjectNVidia = TRUE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > isDict ( ) ) {
const TagDict * Dict2 = Prop - > getDict ( ) ;
const TagStruct * Prop2 = Dict2 - > propertyForKey ( " Intel " ) ;
if ( Prop2 ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . InjectIntel = IsPropertyNotNullAndTrue ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = Dict2 - > propertyForKey ( " ATI " ) ;
if ( Prop2 ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . InjectATI = IsPropertyNotNullAndTrue ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = Dict2 - > propertyForKey ( " NVidia " ) ;
if ( Prop2 ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . InjectNVidia = IsPropertyNotNullAndTrue ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
}
} else {
2021-02-06 18:16:46 +01:00
settingsData . GraphicsInjector = FALSE ;
settingsData . InjectIntel = FALSE ;
settingsData . InjectATI = FALSE ;
settingsData . InjectNVidia = FALSE ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " RadeonDeInit " ) ;
2021-02-06 18:16:46 +01:00
settingsData . DeInit = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " VRAM " ) ;
2021-02-06 18:16:46 +01:00
settingsData . VRAM = ( UINTN ) GetPropertyAsInteger ( Prop , ( INTN ) settingsData . VRAM ) ; //Mb
2019-09-03 11:58:42 +02:00
//
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " RefCLK " ) ;
2021-02-06 18:16:46 +01:00
settingsData . RefCLK = ( UINT16 ) GetPropertyAsInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " LoadVBios " ) ;
2021-02-06 18:16:46 +01:00
settingsData . LoadVBios = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < ( INTN ) NGFX ; i + + ) {
2021-02-06 18:16:46 +01:00
gGraphics [ i ] . LoadVBios = settingsData . LoadVBios ; //default
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " VideoPorts " ) ;
2021-02-06 18:16:46 +01:00
settingsData . VideoPorts = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . VideoPorts ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " BootDisplay " ) ;
2021-02-06 18:16:46 +01:00
settingsData . BootDisplay = ( INT8 ) GetPropertyAsInteger ( Prop , - 1 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " FBName " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in FBName \n " ) ;
} else {
2021-02-06 18:16:46 +01:00
settingsData . FBName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " NVCAP " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in NVCAP \n " ) ;
} else {
2021-02-06 18:16:46 +01:00
hex2bin ( Prop - > getString ( ) - > stringValue ( ) . c_str ( ) , ( UINT8 * ) & settingsData . NVCAP [ 0 ] , 20 ) ;
2020-08-18 18:45:44 +02:00
DBG ( " Read NVCAP: " ) ;
for ( i = 0 ; i < 20 ; i + + ) {
2021-02-06 18:16:46 +01:00
DBG ( " %02hhX " , settingsData . NVCAP [ i ] ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
2020-08-18 18:45:44 +02:00
DBG ( " \n " ) ;
//thus confirmed this procedure is working
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " display-cfg " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in display-cfg \n " ) ;
} else {
2021-02-06 18:16:46 +01:00
hex2bin ( Prop - > getString ( ) - > stringValue ( ) . c_str ( ) , ( UINT8 * ) & settingsData . Dcfg [ 0 ] , 8 ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " DualLink " ) ;
2021-02-06 18:16:46 +01:00
settingsData . DualLink = ( UINT32 ) GetPropertyAsInteger ( Prop , settingsData . DualLink ) ;
2019-09-03 11:58:42 +02:00
//InjectEDID - already done in earlysettings
//No! Take again
2020-08-25 17:35:19 +02:00
GetEDIDSettings ( GraphicsDict ) ;
2019-09-03 11:58:42 +02:00
// ErmaC: NvidiaGeneric
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " NvidiaGeneric " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NvidiaGeneric = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " NvidiaNoEFI " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NvidiaNoEFI = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " NvidiaSingle " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NvidiaSingle = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " ig-platform-id " ) ;
2021-02-06 18:16:46 +01:00
settingsData . IgPlatform = ( UINT32 ) GetPropertyAsInteger ( Prop , settingsData . IgPlatform ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = GraphicsDict - > propertyForKey ( " snb-platform-id " ) ;
2021-02-06 18:16:46 +01:00
settingsData . IgPlatform = ( UINT32 ) GetPropertyAsInteger ( Prop , settingsData . IgPlatform ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
FillCardList ( GraphicsDict ) ; //#@ Getcardslist
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagDict * DevicesDict = CfgDict - > dictPropertyForKey ( " Devices " ) ;
if ( DevicesDict ! = NULL ) {
const TagStruct * Prop = DevicesDict - > propertyForKey ( " Inject " ) ;
2021-02-06 18:16:46 +01:00
settingsData . StringInjector = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " SetIntelBacklight " ) ;
2021-02-06 18:16:46 +01:00
settingsData . IntelBacklight = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " SetIntelMaxBacklight " ) ;
2021-02-06 18:16:46 +01:00
settingsData . IntelMaxBacklight = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " IntelMaxValue " ) ;
2021-02-06 18:16:46 +01:00
settingsData . IntelMaxValue = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . IntelMaxValue ) ;
2019-09-03 11:58:42 +02:00
2020-08-22 15:39:24 +02:00
/*
* Properties is a single string , or a dict
*/
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " Properties " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( Prop - > isString ( ) ) {
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
cDeviceProperties = Prop - > getString ( ) - > stringValue ( ) ;
2019-09-03 11:58:42 +02:00
//-------
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ; //0xFE000000;
EFI_STATUS Status = gBS - > AllocatePages (
2019-09-03 11:58:42 +02:00
AllocateMaxAddress ,
EfiACPIReclaimMemory ,
2020-08-15 15:47:56 +02:00
EFI_SIZE_TO_PAGES ( cDeviceProperties . sizeInBytes ( ) ) + 1 ,
2019-09-03 11:58:42 +02:00
& BufferPtr
) ;
if ( ! EFI_ERROR ( Status ) ) {
cProperties = ( UINT8 * ) ( UINTN ) BufferPtr ;
2020-08-15 15:47:56 +02:00
cPropSize = ( UINT32 ) ( cDeviceProperties . length ( ) > > 1 ) ;
cPropSize = hex2bin ( cDeviceProperties . c_str ( ) , cProperties , cPropSize ) ;
2019-09-03 11:58:42 +02:00
DBG ( " Injected EFIString of length %d \n " , cPropSize ) ;
}
//---------
2021-02-06 18:16:46 +01:00
# endif
2019-09-03 11:58:42 +02:00
}
2020-08-18 18:45:44 +02:00
else if ( Prop - > isDict ( ) ) {
2020-08-25 17:35:19 +02:00
INTN i ;
const TagDict * PropertiesDict = Prop - > getDict ( ) ;
INTN Count = PropertiesDict - > dictKeyCount ( ) ; //ok
2021-02-06 18:16:46 +01:00
settingsData . AddProperties = new DEV_PROPERTY [ Count ] ;
2019-09-03 11:58:42 +02:00
DEV_PROPERTY * DevPropDevice ;
DEV_PROPERTY * DevProps ;
DEV_PROPERTY * * Child ;
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
DBG ( " Add %lld devices (kTagTypeDict): \n " , Count ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagKey * key ;
2020-08-22 15:39:24 +02:00
const TagStruct * value ;
2019-09-03 11:58:42 +02:00
EFI_DEVICE_PATH_PROTOCOL * DevicePath = NULL ;
2020-08-25 17:35:19 +02:00
if ( ! EFI_ERROR ( PropertiesDict - > getKeyAndValueAtIndex ( i , & key , & value ) ) ) { //take a <key> with DevicePath. If GetKeyValueAtIndex return success, key and value != NULL
2020-08-22 15:39:24 +02:00
XStringW DevicePathStr = key - > keyStringValue ( ) ;
// DBG("Device: %ls\n", DevicePathStr);
// when key in Devices/Properties is one of the strings "PrimaryGPU" / "SecondaryGPU", use device path of first / second gpu accordingly
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
2020-08-22 15:39:24 +02:00
if ( DevicePathStr . equalIC ( " PrimaryGPU " ) ) {
DevicePath = DevicePathFromHandle ( gGraphics [ 0 ] . Handle ) ; // first gpu
} else if ( DevicePathStr . equalIC ( " SecondaryGPU " ) & & NGFX > 1 ) {
DevicePath = DevicePathFromHandle ( gGraphics [ 1 ] . Handle ) ; // second gpu
} else {
DevicePath = ConvertTextToDevicePath ( DevicePathStr . wc_str ( ) ) ; //TODO
}
if ( DevicePath = = NULL ) {
continue ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
# endif
2019-09-03 11:58:42 +02:00
//Create Device node
2021-02-06 18:16:46 +01:00
DevPropDevice = settingsData . ArbProperties ;
settingsData . ArbProperties = new DEV_PROPERTY ;
settingsData . ArbProperties - > Next = DevPropDevice ; //next device
settingsData . ArbProperties - > Child = NULL ;
settingsData . ArbProperties - > Device = 0 ; //to differ from arbitrary
settingsData . ArbProperties - > DevicePath = DevicePath ; //this is pointer
settingsData . ArbProperties - > Label = S8Printf ( " %s " , key - > keyStringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
Child = & ( settingsData . ArbProperties - > Child ) ;
2019-09-03 11:58:42 +02:00
2020-08-22 15:39:24 +02:00
if ( ( value ! = NULL ) & & ( value - > isDict ( ) ) ) {
2020-02-28 19:12:57 +01:00
INTN PropCount = 0 ;
2020-08-25 17:35:19 +02:00
const TagDict * valueDict = value - > getDict ( ) ;
PropCount = valueDict - > dictKeyCount ( ) ;
2019-09-03 11:58:42 +02:00
// 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
DevProps = * Child ;
2020-08-09 17:55:30 +02:00
* Child = new DEV_PROPERTY ;
2020-03-02 14:46:30 +01:00
// *Child = new (__typeof_am__(**Child))();
2019-09-03 11:58:42 +02:00
( * Child ) - > Next = DevProps ;
2020-08-25 17:35:19 +02:00
const TagKey * key2 ;
2020-08-22 15:39:24 +02:00
const TagStruct * value2 ;
2020-08-25 17:35:19 +02:00
if ( EFI_ERROR ( valueDict - > getKeyAndValueAtIndex ( j , & key2 , & value2 ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
2020-08-22 15:39:24 +02:00
if ( key2 - > keyStringValue ( ) [ 0 ] ! = ' # ' ) {
( * Child ) - > MenuItem . BValue = TRUE ;
( * Child ) - > Key = S8Printf ( " %s " , key2 - > keyStringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
}
else {
( * Child ) - > MenuItem . BValue = FALSE ;
( * Child ) - > Key = S8Printf ( " %s " , key2 - > keyStringValue ( ) . c_str ( ) - 1 ) . forgetDataWithoutFreeing ( ) ;
}
// DBG("<key>%s\n <value> type %d\n", (*Child)->Key, Prop3->type);
2020-08-25 17:35:19 +02:00
if ( value2 & & ( value2 - > isString ( ) ) & & value2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2020-08-22 15:39:24 +02:00
//first suppose it is Ascii string
2020-08-25 17:35:19 +02:00
( * Child ) - > Value = ( UINT8 * ) S8Printf ( " %s " , value2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
( * Child ) - > ValueLen = value2 - > getString ( ) - > stringValue ( ) . sizeInBytesIncludingTerminator ( ) ;
2020-08-22 15:39:24 +02:00
( * Child ) - > ValueType = kTagTypeString ;
}
2020-08-25 17:35:19 +02:00
else if ( value2 & & ( value2 - > isInt64 ( ) ) ) {
if ( value2 - > getInt64 ( ) - > intValue ( ) < MIN_INT32 | | value2 - > getInt64 ( ) - > intValue ( ) > MAX_INT32 ) {
2020-08-23 13:47:58 +02:00
MsgLog ( " Invalid int value for key %s \n " , key2 - > keyStringValue ( ) . c_str ( ) ) ;
} else {
2020-08-25 17:35:19 +02:00
INT32 intValue = ( INT32 ) value2 - > getInt64 ( ) - > intValue ( ) ;
2020-08-23 13:47:58 +02:00
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocatePool ( sizeof ( intValue ) ) ;
* ( INT32 * ) ( ( * Child ) - > Value ) = intValue ;
( * Child ) - > ValueLen = sizeof ( intValue ) ;
( * Child ) - > ValueType = kTagTypeInteger ;
}
2020-08-22 15:39:24 +02:00
}
else if ( value2 & & value2 - > isTrue ( ) ) {
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocateZeroPool ( 4 ) ;
( * Child ) - > Value [ 0 ] = TRUE ;
( * Child ) - > ValueLen = 1 ;
( * Child ) - > ValueType = kTagTypeTrue ;
}
else if ( value2 & & value2 - > isFalse ( ) ) {
( * Child ) - > Value = ( __typeof__ ( ( * Child ) - > Value ) ) AllocateZeroPool ( 4 ) ;
//(*Child)->Value[0] = FALSE;
( * Child ) - > ValueLen = 1 ;
( * Child ) - > ValueType = kTagTypeFalse ;
}
else if ( value2 & & ( value2 - > isData ( ) ) ) {
2020-08-25 17:35:19 +02:00
UINTN Size = value2 - > getData ( ) - > dataLenValue ( ) ;
2020-08-22 15:39:24 +02:00
// (*Child)->Value = GetDataSetting(value2, "Value", &Size); //TODO
UINT8 * Data = ( __typeof__ ( Data ) ) AllocateZeroPool ( Size ) ;
2020-08-25 17:35:19 +02:00
CopyMem ( Data , value2 - > getData ( ) - > dataValue ( ) , Size ) ;
2020-08-22 15:39:24 +02:00
( * Child ) - > Value = Data ;
( * Child ) - > ValueLen = Size ;
( * Child ) - > ValueType = kTagTypeData ;
2019-09-03 11:58:42 +02:00
}
}
}
}
}
}
}
}
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " LANInjection " ) ;
2021-02-06 18:16:46 +01:00
settingsData . LANInjection = ! IsPropertyNotNullAndFalse ( Prop ) ; //default = TRUE
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " HDMIInjection " ) ;
2021-02-06 18:16:46 +01:00
settingsData . HDMIInjection = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " NoDefaultProperties " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NoDefaultProperties = ! IsPropertyNotNullAndFalse ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagArray * ArbitraryArray = DevicesDict - > arrayPropertyForKey ( " Arbitrary " ) ; // array of dict
if ( ArbitraryArray ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN Index ;
2020-08-25 17:35:19 +02:00
INTN Count = ArbitraryArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
DEV_PROPERTY * DevProp ;
if ( Count > 0 ) {
2020-07-15 19:29:27 +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 ;
2020-08-15 15:47:56 +02:00
XString8 Label ;
2020-07-15 19:29:27 +02:00
DBG ( " - [%02lld]: " , Index ) ;
2020-08-25 17:35:19 +02:00
const TagDict * Dict2 = ArbitraryArray - > dictElementAt ( Index , " Arbitrary " _XS8 ) ;
const TagStruct * Prop3 ;
Prop3 = Dict2 - > propertyForKey ( " PciAddr " ) ;
if ( Prop3 ! = NULL ) {
2020-04-10 15:52:49 +02:00
UINT8 Bus , Dev , Func ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( ! Prop3 - > isString ( ) ) {
2020-08-18 18:45:44 +02:00
MsgLog ( " ATTENTION : property not string in PciAddr \n " ) ;
continue ;
}
2020-08-25 17:35:19 +02:00
if ( Prop3 - > getString ( ) - > stringValue ( ) . length ( ) < 2 | | Prop3 - > getString ( ) - > stringValue ( ) [ 2 ] ! = ' : ' ) {
DBG ( " wrong PciAddr string: %s \n " , Prop3 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
continue ;
}
2020-08-25 17:35:19 +02:00
CONST CHAR8 * Str = Prop3 - > getString ( ) - > stringValue ( ) . c_str ( ) ;
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-08-15 15:47:56 +02:00
Label . S8Printf ( " [%02hhX:%02hhX.%02hhX] " , Bus , Dev , Func ) ;
DBG ( " %s " , Label . c_str ( ) ) ;
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-08-25 17:35:19 +02:00
Prop3 = Dict2 - > propertyForKey ( " Comment " ) ;
if ( Prop3 ! = NULL ) {
if ( ! Prop3 - > isString ( ) ) {
2020-08-18 18:45:44 +02:00
MsgLog ( " ATTENTION : property not string in Comment \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
Label + = Prop3 - > getString ( ) - > stringValue ( ) ;
DBG ( " (%s) " , Prop3 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-04-23 18:05:21 +02:00
DBG ( " \n " ) ;
2020-08-25 17:35:19 +02:00
const TagArray * CustomPropertiesArray = Dict2 - > arrayPropertyForKey ( " CustomProperties " ) ; // array of dict
if ( CustomPropertiesArray ! = NULL ) {
const TagDict * Dict3 ;
2020-08-22 15:39:24 +02:00
INTN PropIndex ;
2020-08-25 17:35:19 +02:00
INTN PropCount = CustomPropertiesArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
for ( PropIndex = 0 ; PropIndex < PropCount ; PropIndex + + ) {
2020-08-25 17:35:19 +02:00
Dict3 = CustomPropertiesArray - > dictElementAt ( PropIndex , " CustomProperties " _XS8 ) ;
2021-02-06 18:16:46 +01:00
DevProp = settingsData . ArbProperties ;
settingsData . ArbProperties = new DEV_PROPERTY ;
settingsData . ArbProperties - > Next = DevProp ;
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Device = ( UINT32 ) DeviceAddr ;
settingsData . ArbProperties - > Label = ( __typeof__ ( settingsData . ArbProperties - > Label ) ) AllocateCopyPool ( Label . sizeInBytesIncludingTerminator ( ) , Label . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagStruct * DisabledProp = Dict3 - > propertyForKey ( " Disabled " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > MenuItem . BValue = ! IsPropertyNotNullAndTrue ( DisabledProp ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
DisabledProp = Dict3 - > propertyForKey ( " Key " ) ;
if ( DisabledProp & & ( DisabledProp - > isString ( ) ) & & DisabledProp - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Key = S8Printf ( " %s " , DisabledProp - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2020-08-22 15:39:24 +02:00
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
DisabledProp = Dict3 - > propertyForKey ( " Value " ) ;
if ( DisabledProp & & ( DisabledProp - > isString ( ) ) & & DisabledProp - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2020-08-22 15:39:24 +02:00
//first suppose it is Ascii string
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Value = ( UINT8 * ) S8Printf ( " %s " , DisabledProp - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
settingsData . ArbProperties - > ValueLen = DisabledProp - > getString ( ) - > stringValue ( ) . sizeInBytesIncludingTerminator ( ) ;
settingsData . ArbProperties - > ValueType = kTagTypeString ;
2020-08-25 17:35:19 +02:00
} else if ( DisabledProp & & ( DisabledProp - > isInt64 ( ) ) ) {
if ( DisabledProp - > getInt64 ( ) - > intValue ( ) < MIN_INT32 | | DisabledProp - > getInt64 ( ) - > intValue ( ) > MAX_INT32 ) {
MsgLog ( " Invalid int value for key 'Value' \n " ) ;
} else {
INT32 intValue = ( INT32 ) DisabledProp - > getInt64 ( ) - > intValue ( ) ;
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Value = ( __typeof__ ( settingsData . ArbProperties - > Value ) ) AllocatePool ( sizeof ( intValue ) ) ;
// CopyMem(settingsData.ArbProperties->Value, &Prop3->intValue, 4);
* ( INT32 * ) ( settingsData . ArbProperties - > Value ) = intValue ;
settingsData . ArbProperties - > ValueLen = sizeof ( intValue ) ;
settingsData . ArbProperties - > ValueType = kTagTypeInteger ;
2020-08-25 17:35:19 +02:00
}
} else if ( DisabledProp & & DisabledProp - > isTrue ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Value = ( __typeof__ ( settingsData . ArbProperties - > Value ) ) AllocateZeroPool ( 4 ) ;
settingsData . ArbProperties - > Value [ 0 ] = TRUE ;
settingsData . ArbProperties - > ValueLen = 1 ;
settingsData . ArbProperties - > ValueType = kTagTypeTrue ;
2020-08-25 17:35:19 +02:00
} else if ( DisabledProp & & DisabledProp - > isFalse ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Value = ( __typeof__ ( settingsData . ArbProperties - > Value ) ) AllocateZeroPool ( 4 ) ;
//settingsData.ArbProperties->Value[0] = FALSE;
settingsData . ArbProperties - > ValueLen = 1 ;
settingsData . ArbProperties - > ValueType = kTagTypeFalse ;
2020-08-22 15:39:24 +02:00
} else {
//else data
UINTN Size = 0 ;
2021-02-06 18:16:46 +01:00
settingsData . ArbProperties - > Value = GetDataSetting ( Dict3 , " Value " , & Size ) ;
settingsData . ArbProperties - > ValueLen = Size ;
settingsData . ArbProperties - > ValueType = kTagTypeData ;
2020-08-22 15:39:24 +02:00
}
2019-09-03 11:58:42 +02:00
2020-08-22 15:39:24 +02:00
//Special case. In future there must be more such cases
2021-02-06 18:16:46 +01:00
if ( ( AsciiStrStr ( settingsData . ArbProperties - > Key , " -platform-id " ) ! = NULL ) ) {
CopyMem ( ( CHAR8 * ) & settingsData . IgPlatform , settingsData . ArbProperties - > Value , 4 ) ;
2019-09-03 11:58:42 +02:00
}
} //for() device properties
}
} //for() devices
}
2021-02-06 18:16:46 +01:00
// settingsData.NrAddProperties = 0xFFFE;
2019-09-03 11:58:42 +02:00
}
//can use AddProperties with ArbProperties
2020-08-25 17:35:19 +02:00
const TagArray * AddPropertiesArray = DevicesDict - > arrayPropertyForKey ( " AddProperties " ) ; // array of dict
2020-08-30 16:21:54 +02:00
if ( AddPropertiesArray ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = AddPropertiesArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
INTN Index = 0 ; //begin from 0 if second enter
2020-08-30 16:21:54 +02:00
//count = 0x1F1E1D1C1B1A1918
2019-09-03 11:58:42 +02:00
if ( Count > 0 ) {
2021-02-06 18:16:46 +01:00
DBG ( " Add %lld properties: \n " , Count ) ;
settingsData . AddProperties = new DEV_PROPERTY [ Count ] ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
UINTN Size = 0 ;
2021-02-06 18:16:46 +01:00
DBG ( " - [%02lld]: " , i ) ;
2020-08-25 17:35:19 +02:00
const TagDict * Dict2 = AddPropertiesArray - > dictElementAt ( i , " AddProperties " _XS8 ) ;
const TagStruct * DeviceProp = Dict2 - > propertyForKey ( " Device " ) ;
if ( DeviceProp & & ( DeviceProp - > isString ( ) ) & & DeviceProp - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
DEV_PROPERTY * Property = & settingsData . AddProperties [ Index ] ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " ATI " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_ATI ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " NVidia " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_NVIDIA ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " IntelGFX " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_INTEL ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " LAN " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_LAN ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " WIFI " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_WIFI ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " Firewire " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_FIREWIRE ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " SATA " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_SATA ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " IDE " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_IDE ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " HDA " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_HDA ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " HDMI " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_HDMI ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " LPC " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_LPC ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " SmBUS " ) ) {
2019-09-03 11:58:42 +02:00
Property - > Device = ( UINT32 ) DEV_SMBUS ;
2020-08-25 17:35:19 +02:00
} else if ( DeviceProp - > getString ( ) - > stringValue ( ) . equalIC ( " USB " ) ) {
2019-09-03 11:58:42 +02:00
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-08-25 17:35:19 +02:00
if ( DeviceProp - > isString ( ) ) DBG ( " %s " , DeviceProp - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
const TagStruct * Prop2 = Dict2 - > propertyForKey ( " Disabled " ) ;
2021-02-06 18:16:46 +01:00
settingsData . AddProperties [ Index ] . MenuItem . BValue = ! IsPropertyNotNullAndTrue ( Prop2 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop2 = Dict2 - > propertyForKey ( " Key " ) ;
if ( Prop2 & & ( Prop2 - > isString ( ) ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . AddProperties [ Index ] . Key = S8Printf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = Dict2 - > propertyForKey ( " Value " ) ;
if ( Prop2 & & ( Prop2 - > isString ( ) ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2019-09-03 11:58:42 +02:00
//first suppose it is Ascii string
2021-02-06 18:16:46 +01:00
settingsData . AddProperties [ Index ] . Value = ( UINT8 * ) S8Printf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
settingsData . AddProperties [ Index ] . ValueLen = Prop2 - > getString ( ) - > stringValue ( ) . sizeInBytesIncludingTerminator ( ) ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 & & ( Prop2 - > isInt64 ( ) ) ) {
if ( Prop2 - > getInt64 ( ) - > intValue ( ) < MIN_INT32 | | Prop2 - > getInt64 ( ) - > intValue ( ) > MAX_INT32 ) {
MsgLog ( " Invalid int value for key 'Value' \n " ) ;
} else {
INT32 intValue = ( INT32 ) Prop2 - > getInt64 ( ) - > intValue ( ) ;
2021-02-06 18:16:46 +01:00
settingsData . AddProperties [ Index ] . Value = ( __typeof__ ( settingsData . AddProperties [ Index ] . Value ) ) AllocatePool ( sizeof ( intValue ) ) ;
// CopyMem(settingsData.AddProperties[Index].Value, &Prop2->intValue, 4);
* ( INT32 * ) ( settingsData . AddProperties [ Index ] . Value ) = intValue ;
settingsData . AddProperties [ Index ] . ValueLen = sizeof ( intValue ) ;
2020-08-25 17:35:19 +02:00
}
2019-09-03 11:58:42 +02:00
} else {
//else data
2021-02-06 18:16:46 +01:00
settingsData . AddProperties [ Index ] . Value = GetDataSetting ( Dict2 , " Value " , & Size ) ;
settingsData . AddProperties [ Index ] . ValueLen = Size ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
DBG ( " Key: %s, len: %llu \n " , settingsData . AddProperties [ Index ] . Key , settingsData . AddProperties [ Index ] . ValueLen ) ;
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
if ( ! settingsData . 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 ;
}
2021-02-06 18:16:46 +01:00
settingsData . NrAddProperties = Index ;
2019-09-03 11:58:42 +02:00
}
}
//end AddProperties
2020-08-25 17:35:19 +02:00
const TagDict * FakeIDDict = DevicesDict - > dictPropertyForKey ( " FakeID " ) ;
if ( FakeIDDict ! = NULL ) {
const TagStruct * Prop2 = FakeIDDict - > propertyForKey ( " ATI " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeATI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " NVidia " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeNVidia = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " IntelGFX " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeIntel = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " LAN " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeLAN = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " WIFI " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeWIFI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " SATA " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeSATA = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " XHCI " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeXHCI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = FakeIDDict - > propertyForKey ( " IMEI " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . FakeIMEI = ( UINT32 ) AsciiStrHexToUint64 ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " UseIntelHDMI " ) ;
2021-02-06 18:16:46 +01:00
settingsData . UseIntelHDMI = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " ForceHPET " ) ;
2021-02-06 18:16:46 +01:00
settingsData . ForceHPET = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " DisableFunctions " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop & & ( Prop - > isString ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . DisableFunctions = ( UINT32 ) AsciiStrHexToUint64 ( Prop - > getString ( ) - > stringValue ( ) ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = DevicesDict - > propertyForKey ( " AirportBridgeDeviceName " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop & & ( Prop - > isString ( ) ) ) {
2020-08-31 11:00:52 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . length ( ) ! = 4 ) {
MsgLog ( " ERROR IN PLIST : AirportBridgeDeviceName must 4 chars long " ) ;
} else {
2021-02-06 18:16:46 +01:00
settingsData . AirportBridgeDeviceName = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-31 11:00:52 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagDict * AudioDict = DevicesDict - > dictPropertyForKey ( " Audio " ) ;
if ( AudioDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
// HDA
2020-04-23 11:08:10 +02:00
// Prop = GetProperty(Prop2, "ResetHDA");
2021-02-06 18:16:46 +01:00
// settingsData.ResetHDA = IsPropertyTrue(Prop);
2020-08-25 17:35:19 +02:00
Prop = AudioDict - > propertyForKey ( " 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
2020-08-25 17:35:19 +02:00
if ( Prop - > isInt64 ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . HDALayoutId = ( INT32 ) Prop - > getInt64 ( ) - > intValue ( ) ; //must be signed
settingsData . HDAInjection = ( settingsData . HDALayoutId > 0 ) ;
2020-08-18 18:45:44 +02:00
} else if ( Prop - > isString ( ) ) {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) & & ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' n ' | | Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' N ' ) ) {
2019-09-03 11:58:42 +02:00
// if starts with n or N, then no HDA injection
2021-02-06 18:16:46 +01:00
settingsData . HDAInjection = FALSE ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . length ( ) > 1 & &
Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' 0 ' & &
( Prop - > getString ( ) - > stringValue ( ) [ 1 ] = = ' x ' | | Prop - > getString ( ) - > stringValue ( ) [ 1 ] = = ' X ' ) ) {
2019-09-03 11:58:42 +02:00
// assume it's a hex layout id
2021-02-06 18:16:46 +01:00
settingsData . HDALayoutId = ( INT32 ) AsciiStrHexToUintn ( Prop - > getString ( ) - > stringValue ( ) ) ;
settingsData . HDAInjection = TRUE ;
2019-09-03 11:58:42 +02:00
} else {
// assume it's a decimal layout id
2021-02-06 18:16:46 +01:00
settingsData . HDALayoutId = ( INT32 ) AsciiStrDecimalToUintn ( Prop - > getString ( ) - > stringValue ( ) ) ;
settingsData . HDAInjection = TRUE ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-25 17:35:19 +02:00
Prop = AudioDict - > propertyForKey ( " AFGLowPowerState " ) ;
2021-02-06 18:16:46 +01:00
settingsData . AFGLowPowerState = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagDict * USBDict = DevicesDict - > dictPropertyForKey ( " USB " ) ;
if ( USBDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
// USB
2020-08-25 17:35:19 +02:00
Prop = USBDict - > propertyForKey ( " Inject " ) ;
2021-02-06 18:16:46 +01:00
settingsData . USBInjection = ! IsPropertyNotNullAndFalse ( Prop ) ; // enabled by default
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = USBDict - > propertyForKey ( " AddClockID " ) ;
2021-02-06 18:16:46 +01:00
settingsData . InjectClockID = IsPropertyNotNullAndTrue ( Prop ) ; // disabled by default
2019-09-03 11:58:42 +02:00
// enabled by default for CloverEFI
// disabled for others
2021-02-06 18:16:46 +01:00
settingsData . USBFixOwnership = gFirmwareClover ;
2020-08-25 17:35:19 +02:00
Prop = USBDict - > propertyForKey ( " FixOwnership " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . USBFixOwnership = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
DBG ( " USB FixOwnership: %s \n " , settingsData . USBFixOwnership ? " yes " : " no " ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = USBDict - > propertyForKey ( " HighCurrent " ) ;
2021-02-06 18:16:46 +01:00
settingsData . HighCurrent = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = USBDict - > propertyForKey ( " NameEH00 " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NameEH00 = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
}
//*** ACPI ***//
2020-08-25 17:35:19 +02:00
getACPISettings ( CfgDict ) ;
2019-09-03 11:58:42 +02:00
//*** SMBIOS ***//
2020-08-25 17:35:19 +02:00
const TagDict * SMBIOSDict = CfgDict - > dictPropertyForKey ( " SMBIOS " ) ;
if ( SMBIOSDict ! = NULL ) {
ParseSMBIOSSettings ( SMBIOSDict ) ;
const TagStruct * Prop = SMBIOSDict - > propertyForKey ( " Trust " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndFalse ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . TrustSMBIOS = FALSE ;
2020-08-22 15:39:24 +02:00
} else if ( IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
settingsData . TrustSMBIOS = TRUE ;
2019-09-03 11:58:42 +02:00
}
}
2020-08-25 17:35:19 +02:00
Prop = SMBIOSDict - > propertyForKey ( " MemoryRank " ) ;
2021-02-06 18:16:46 +01:00
settingsData . Attribute = ( INT8 ) GetPropertyAsInteger ( 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 ;
2021-02-06 18:16:46 +01:00
settingsData . InjectMemoryTables = FALSE ;
2019-12-21 11:29:57 +01:00
2019-09-03 11:58:42 +02:00
// Inject memory tables into SMBIOS
2020-08-25 17:35:19 +02:00
const TagDict * MemoryDict = SMBIOSDict - > dictPropertyForKey ( " Memory " ) ;
if ( MemoryDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
// Get memory table count
2020-08-25 17:35:19 +02:00
const TagStruct * Prop2 = MemoryDict - > propertyForKey ( " SlotCount " ) ;
2020-08-22 15:39:24 +02:00
gRAM . UserInUse = ( UINT8 ) GetPropertyAsInteger ( Prop2 , 0 ) ;
2019-09-03 11:58:42 +02:00
// Get memory channels
2020-08-25 17:35:19 +02:00
Prop2 = MemoryDict - > propertyForKey ( " Channels " ) ;
2020-08-22 15:39:24 +02:00
gRAM . UserChannels = ( UINT8 ) GetPropertyAsInteger ( Prop2 , 0 ) ;
2019-09-03 11:58:42 +02:00
// Get memory tables
2020-08-25 17:35:19 +02:00
const TagArray * ModulesArray = MemoryDict - > arrayPropertyForKey ( " Modules " ) ; // array of dict
if ( ModulesArray ! = NULL ) {
INTN Count = ModulesArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
const TagDict * Prop3 = ModulesArray - > dictElementAt ( i , " SMBIOS/Memory/Modules " _XS8 ) ;
2020-08-22 15:39:24 +02:00
UINT8 Slot = MAX_RAM_SLOTS ;
RAM_SLOT_INFO * SlotPtr ;
2019-09-03 11:58:42 +02:00
// Get memory slot
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Slot " ) ;
if ( Prop2 = = NULL ) {
2019-09-03 11:58:42 +02:00
continue ;
}
2020-08-25 17:35:19 +02:00
if ( Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
Slot = ( UINT8 ) AsciiStrDecimalToUintn ( Prop2 - > getString ( ) - > stringValue ( ) ) ;
} else if ( Prop2 - > isInt64 ( ) ) {
2020-11-02 14:45:11 +01:00
Slot = ( UINT8 ) Prop2 - > getInt64 ( ) - > intValue ( ) ;
2019-09-03 11:58:42 +02:00
} else {
continue ;
}
if ( Slot > = MAX_RAM_SLOTS ) {
continue ;
}
SlotPtr = & gRAM . User [ Slot ] ;
// Get memory size
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Size " ) ;
SlotPtr - > ModuleSize = ( UINT32 ) GetPropertyAsInteger ( Prop2 , SlotPtr - > ModuleSize ) ;
2019-09-03 11:58:42 +02:00
// Get memory frequency
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Frequency " ) ;
SlotPtr - > Frequency = ( UINT32 ) GetPropertyAsInteger ( Prop2 , SlotPtr - > Frequency ) ;
2019-09-03 11:58:42 +02:00
// Get memory vendor
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Vendor " ) ;
if ( Prop2 & & Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
SlotPtr - > Vendor = S8Printf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory part number
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Part " ) ;
if ( Prop2 & & Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
SlotPtr - > PartNo = S8Printf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory serial number
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Serial " ) ;
if ( Prop2 & & Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
SlotPtr - > SerialNo = S8Printf ( " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) . forgetDataWithoutFreeing ( ) ;
2019-09-03 11:58:42 +02:00
}
// Get memory type
SlotPtr - > Type = MemoryTypeDdr3 ;
2020-08-25 17:35:19 +02:00
Prop2 = Prop3 - > propertyForKey ( " Type " ) ;
if ( Prop2 & & Prop2 - > isString ( ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " DDR2 " ) ) {
2019-09-03 11:58:42 +02:00
SlotPtr - > Type = MemoryTypeDdr2 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " DDR3 " ) ) {
2019-09-03 11:58:42 +02:00
SlotPtr - > Type = MemoryTypeDdr3 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " DDR4 " ) ) {
2019-09-03 11:58:42 +02:00
SlotPtr - > Type = MemoryTypeDdr4 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " DDR " ) ) {
2019-09-03 11:58:42 +02:00
SlotPtr - > Type = MemoryTypeDdr ;
}
}
SlotPtr - > InUse = ( SlotPtr - > ModuleSize > 0 ) ;
if ( SlotPtr - > InUse ) {
if ( gRAM . UserInUse < = Slot ) {
gRAM . UserInUse = Slot + 1 ;
}
}
}
if ( gRAM . UserInUse > 0 ) {
2021-02-06 18:16:46 +01:00
settingsData . InjectMemoryTables = TRUE ;
2019-09-03 11:58:42 +02:00
}
}
}
2020-08-25 17:35:19 +02:00
const TagArray * SlotsArray = SMBIOSDict - > arrayPropertyForKey ( " Slots " ) ; // array of dict
if ( SlotsArray ! = NULL ) {
2019-09-03 11:58:42 +02:00
INTN DeviceN ;
2020-08-25 17:35:19 +02:00
INTN Count = SlotsArray - > arrayContent ( ) . size ( ) ;
2019-09-03 11:58:42 +02:00
2020-02-20 15:28:24 +01:00
for ( INTN Index = 0 ; Index < Count ; + + Index ) {
2020-08-25 17:35:19 +02:00
const TagDict * SlotsDict = SlotsArray - > dictElementAt ( Index , " SMBIOS/Slots " _XS8 ) ;
2019-09-03 11:58:42 +02:00
if ( ! Index ) {
2020-04-23 18:05:21 +02:00
DBG ( " Slots->Devices: \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagStruct * Prop2 = SlotsDict - > propertyForKey ( " Device " ) ;
2019-09-03 11:58:42 +02:00
DeviceN = - 1 ;
2020-08-25 17:35:19 +02:00
if ( Prop2 & & ( Prop2 - > isString ( ) ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " ATI " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 0 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " NVidia " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 1 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " IntelGFX " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 2 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " LAN " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 5 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " WIFI " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 6 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " Firewire " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 12 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " HDMI " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 4 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " USB " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 11 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop2 - > getString ( ) - > stringValue ( ) . equalIC ( " NVME " ) ) {
2019-09-03 11:58:42 +02:00
DeviceN = 13 ;
} else {
2020-08-25 17:35:19 +02:00
DBG ( " - add properties to unknown device %s, ignored \n " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
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-08-25 17:35:19 +02:00
Prop2 = SlotsDict - > propertyForKey ( " ID " ) ;
2020-08-22 15:39:24 +02:00
SlotDevice - > SlotID = ( UINT8 ) GetPropertyAsInteger ( Prop2 , DeviceN ) ;
2019-09-03 11:58:42 +02:00
SlotDevice - > SlotType = SlotTypePci ;
2020-08-25 17:35:19 +02:00
Prop2 = SlotsDict - > propertyForKey ( " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop2 ! = NULL ) {
2020-08-22 15:39:24 +02:00
switch ( ( UINT8 ) GetPropertyAsInteger ( Prop2 , 0 ) ) {
2019-09-03 11:58:42 +02:00
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-08-25 17:35:19 +02:00
Prop2 = SlotsDict - > propertyForKey ( " Name " ) ;
if ( Prop2 & & ( Prop2 - > isString ( ) ) & & Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2020-12-13 09:51:50 +01:00
snprintf ( SlotDevice - > SlotName , 31 , " %s " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-12-13 09:51:50 +01: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
2021-02-06 18:16:46 +01:00
settingsData . CpuType = GetAdvancedCpuType ( ) ; //let it be default
settingsData . SavingMode = 0xFF ; //default
2020-08-25 17:35:19 +02:00
const TagDict * CPUDict = CfgDict - > dictPropertyForKey ( " CPU " ) ;
if ( CPUDict ! = NULL ) {
const TagStruct * Prop = CPUDict - > propertyForKey ( " QPI " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . QPI = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . QPI ) ;
DBG ( " QPI: %dMHz \n " , settingsData . QPI ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " FrequencyMHz " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . CpuFreqMHz = ( UINT32 ) GetPropertyAsInteger ( Prop , settingsData . CpuFreqMHz ) ;
DBG ( " CpuFreq: %dMHz \n " , settingsData . CpuFreqMHz ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " Type " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . CpuType = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . CpuType ) ;
DBG ( " CpuType: %hX \n " , settingsData . CpuType ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " QEMU " ) ;
2021-02-06 18:16:46 +01:00
settingsData . QEMU = IsPropertyNotNullAndTrue ( Prop ) ;
if ( settingsData . QEMU ) {
2020-04-23 18:05:21 +02:00
DBG ( " QEMU: true \n " ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " UseARTFrequency " ) ;
2021-02-06 18:16:46 +01:00
settingsData . UseARTFreq = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
2021-02-06 18:16:46 +01:00
settingsData . UserChange = FALSE ;
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " BusSpeedkHz " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . BusSpeed = ( UINT32 ) GetPropertyAsInteger ( Prop , settingsData . BusSpeed ) ;
DBG ( " BusSpeed: %dkHz \n " , settingsData . BusSpeed ) ;
settingsData . UserChange = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " C6 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . EnableC6 = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " C4 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . EnableC4 = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " C2 " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . EnableC2 = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
//Usually it is 0x03e9, but if you want Turbo, you may set 0x00FA
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " Latency " ) ;
2021-02-06 18:16:46 +01:00
settingsData . C3Latency = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . C3Latency ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " SavingMode " ) ;
2021-02-06 18:16:46 +01:00
settingsData . SavingMode = ( UINT8 ) GetPropertyAsInteger ( Prop , 0xFF ) ; //the default value means not set
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " HWPEnable " ) ;
2020-08-22 15:39:24 +02:00
if ( Prop & & IsPropertyNotNullAndTrue ( Prop ) & & ( gCPUStructure . Model > = CPU_MODEL_SKYLAKE_U ) ) {
2021-02-06 18:16:46 +01:00
settingsData . HWP = TRUE ;
# ifdef CLOVER_BUILD
2019-09-03 11:58:42 +02:00
AsmWriteMsr64 ( MSR_IA32_PM_ENABLE , 1 ) ;
2021-02-06 18:16:46 +01:00
# endif
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " HWPValue " ) ;
2021-02-06 18:16:46 +01:00
if ( Prop & & settingsData . HWP ) {
settingsData . HWPValue = ( UINT32 ) GetPropertyAsInteger ( Prop , 0 ) ;
# ifdef CLOVER_BUILD
AsmWriteMsr64 ( MSR_IA32_HWP_REQUEST , settingsData . HWPValue ) ;
# endif
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " TDP " ) ;
2021-02-06 18:16:46 +01:00
settingsData . TDP = ( UINT8 ) GetPropertyAsInteger ( Prop , 0 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = CPUDict - > propertyForKey ( " TurboDisable " ) ;
2020-08-22 15:39:24 +02:00
if ( Prop & & IsPropertyNotNullAndTrue ( Prop ) ) {
2021-02-06 18:16:46 +01:00
# ifdef CLOVER_BUILD
2019-09-03 11:58:42 +02:00
UINT64 msr = AsmReadMsr64 ( MSR_IA32_MISC_ENABLE ) ;
2021-02-06 18:16:46 +01:00
# endif
settingsData . Turbo = 0 ;
# ifdef CLOVER_BUILD
2019-09-03 11:58:42 +02:00
msr & = ~ ( 1ULL < < 38 ) ;
AsmWriteMsr64 ( MSR_IA32_MISC_ENABLE , msr ) ;
2021-02-06 18:16:46 +01:00
# endif
2019-09-03 11:58:42 +02:00
}
}
// RtVariables
2021-02-06 18:16:46 +01:00
settingsData . RtROM . setEmpty ( ) ;
2020-08-25 17:35:19 +02:00
const TagDict * RtVariablesDict = CfgDict - > dictPropertyForKey ( " RtVariables " ) ;
if ( RtVariablesDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
// ROM: <data>bin data</data> or <string>base 64 encoded bin data</string>
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = RtVariablesDict - > propertyForKey ( " ROM " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-27 15:02:25 +02:00
if ( Prop - > isString ( ) & & Prop - > getString ( ) - > stringValue ( ) . equalIC ( " UseMacAddr0 " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . RtROM . ncpy ( & gLanMac [ 0 ] [ 0 ] , 6 ) ;
2020-08-27 15:02:25 +02:00
} else if ( Prop - > isString ( ) & & Prop - > getString ( ) - > stringValue ( ) . equalIC ( " UseMacAddr1 " ) ) {
2021-02-06 18:16:46 +01:00
settingsData . RtROM . ncpy ( & gLanMac [ 1 ] [ 0 ] , 6 ) ;
2020-08-27 15:02:25 +02:00
} else if ( Prop - > isString ( ) | | Prop - > isData ( ) ) { // GetDataSetting accept both
UINTN ROMLength = 0 ;
2020-10-03 19:02:31 +02:00
void * ROM = GetDataSetting ( RtVariablesDict , " ROM " , & ROMLength ) ;
2021-02-06 18:16:46 +01:00
settingsData . RtROM . ncpy ( ROM , ROMLength ) ;
2020-08-27 15:02:25 +02:00
} else {
MsgLog ( " MALFORMED PLIST : property not string or data in RtVariables/ROM \n " ) ;
}
2019-09-03 11:58:42 +02:00
}
// MLB: <string>some value</string>
2020-08-25 17:35:19 +02:00
Prop = RtVariablesDict - > propertyForKey ( " MLB " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in RtVariables/MLB \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . RtMLB = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
// CsrActiveConfig
2020-08-25 17:35:19 +02:00
Prop = RtVariablesDict - > propertyForKey ( " CsrActiveConfig " ) ;
2021-02-06 18:16:46 +01:00
settingsData . CsrActiveConfig = ( UINT32 ) GetPropertyAsInteger ( Prop , 0x2E7 ) ; //the value 0xFFFF means not set
2019-09-03 11:58:42 +02:00
//BooterConfig
2020-08-25 17:35:19 +02:00
Prop = RtVariablesDict - > propertyForKey ( " BooterConfig " ) ;
2021-02-06 18:16:46 +01:00
settingsData . BooterConfig = ( UINT16 ) GetPropertyAsInteger ( Prop , 0 ) ; //the value 0 means not set
2019-09-03 11:58:42 +02:00
//let it be string like "log=0"
2020-08-25 17:35:19 +02:00
Prop = RtVariablesDict - > propertyForKey ( " BooterCfg " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in RtVariables/BooterCfg \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . BooterCfgStr = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2019-09-12 12:37:33 +02:00
//Block external variables
2020-08-25 17:35:19 +02:00
const TagArray * BlockArray = RtVariablesDict - > arrayPropertyForKey ( " Block " ) ; // array of dict
if ( BlockArray ! = NULL ) {
2020-08-22 15:39:24 +02:00
INTN i ;
2020-08-25 17:35:19 +02:00
INTN Count = BlockArray - > arrayContent ( ) . size ( ) ;
2020-08-31 08:22:21 +02:00
BlockRtVariableArray . setEmpty ( ) ;
RT_VARIABLES * RtVariablePtr = new RT_VARIABLES ( ) ;
RT_VARIABLES & RtVariable = * RtVariablePtr ;
2019-09-12 08:03:34 +02:00
for ( i = 0 ; i < Count ; i + + ) {
2020-08-25 17:35:19 +02:00
CfgDict = BlockArray - > dictElementAt ( i , " Block " _XS8 ) ;
const TagStruct * Prop2 = CfgDict - > propertyForKey ( " Comment " ) ;
2020-08-22 15:39:24 +02:00
if ( Prop2 ! = NULL ) {
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Block/Comment \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
DBG ( " %s \n " , Prop2 - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-12 12:37:33 +02:00
}
2020-08-22 15:39:24 +02:00
}
2020-08-25 17:35:19 +02:00
Prop2 = CfgDict - > propertyForKey ( " Disabled " ) ;
2020-08-22 15:39:24 +02:00
if ( IsPropertyNotNullAndFalse ( Prop2 ) ) {
continue ;
}
2020-08-25 17:35:19 +02:00
Prop2 = CfgDict - > propertyForKey ( " Guid " ) ;
2020-08-22 15:39:24 +02:00
if ( Prop2 ! = NULL ) {
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Block/Guid \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-01-31 10:50:23 +01:00
if ( IsValidGuidString ( Prop2 - > getString ( ) - > stringValue ( ) ) ) {
2020-08-31 08:22:21 +02:00
StrToGuidLE ( Prop2 - > getString ( ) - > stringValue ( ) , & RtVariable . VarGuid ) ;
2020-08-22 15:39:24 +02:00
} else {
2020-08-25 17:35:19 +02:00
DBG ( " Error: invalid GUID for RT var '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-12 12:37:33 +02:00
}
}
2020-08-22 15:39:24 +02:00
}
2019-09-12 12:37:33 +02:00
2020-08-25 17:35:19 +02:00
Prop2 = CfgDict - > propertyForKey ( " Name " ) ;
2020-08-31 08:22:21 +02:00
RtVariable . Name . setEmpty ( ) ;
2020-08-22 15:39:24 +02:00
if ( Prop2 ! = NULL ) {
if ( ! Prop2 - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Block/Name \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop2 - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2020-08-31 08:22:21 +02:00
RtVariable . Name = Prop2 - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-12 12:37:33 +02:00
}
2019-09-12 08:03:34 +02:00
}
2020-08-31 08:22:21 +02:00
BlockRtVariableArray . AddReference ( RtVariablePtr , true ) ;
2019-09-12 08:03:34 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
if ( settingsData . RtROM . isEmpty ( ) ) {
2020-09-23 15:47:47 +02:00
EFI_GUID uuid ;
2021-02-06 18:16:46 +01:00
StrToGuidLE ( settingsData . SmUUID , & uuid ) ;
settingsData . RtROM . ncpy ( & uuid . Data4 [ 2 ] , 6 ) ;
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
if ( settingsData . RtMLB . isEmpty ( ) ) {
settingsData . RtMLB = settingsData . BoardSerialNumber ;
2019-09-03 11:58:42 +02:00
}
// 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)
2021-02-06 18:16:46 +01:00
// CopyMem((void*)&gUuid, (void*)&settingsData.SmUUID, sizeof(EFI_GUID));
2019-09-03 11:58:42 +02:00
// SystemParameters again - values that can depend on previous params
2020-08-25 17:35:19 +02:00
const TagDict * SystemParametersDict = CfgDict - > dictPropertyForKey ( " SystemParameters " ) ;
if ( SystemParametersDict ! = NULL ) {
2019-09-03 11:58:42 +02:00
//BacklightLevel
2020-08-25 17:35:19 +02:00
const TagStruct * Prop = SystemParametersDict - > propertyForKey ( " BacklightLevel " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2021-02-06 18:16:46 +01:00
settingsData . BacklightLevel = ( UINT16 ) GetPropertyAsInteger ( Prop , settingsData . BacklightLevel ) ;
settingsData . BacklightLevelConfig = TRUE ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = SystemParametersDict - > propertyForKey ( " CustomUUID " ) ;
2019-09-03 11:58:42 +02:00
if ( Prop ! = NULL ) {
2020-08-18 18:45:44 +02:00
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in SystemParameters/CustomUUID \n " ) ;
} else {
2021-01-31 10:50:23 +01:00
if ( IsValidGuidString ( Prop - > getString ( ) - > stringValue ( ) ) ) {
2021-02-06 18:16:46 +01:00
settingsData . CustomUuid = Prop - > getString ( ) - > stringValue ( ) ;
2020-09-23 15:47:47 +02:00
// if CustomUUID specified, then default for InjectSystemID=FALSE
// to stay compatibile with previous Clover behaviour
DBG ( " The UUID is valid \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
DBG ( " Error: invalid CustomUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \n " , Prop - > getString ( ) - > stringValue ( ) . c_str ( ) ) ;
2021-02-06 18:16:46 +01:00
settingsData . CustomUuid = { 0 } ;
2020-08-18 18:45:44 +02:00
}
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
2021-02-06 18:16:46 +01:00
settingsData . InjectSystemID_ = 2 ;
2020-08-25 17:35:19 +02:00
Prop = SystemParametersDict - > propertyForKey ( " InjectSystemID " ) ;
2020-09-23 15:47:47 +02:00
if ( Prop ) {
2021-02-06 18:16:46 +01:00
if ( Prop - > isBool ( ) ) settingsData . InjectSystemID_ = Prop - > getBool ( ) - > boolValue ( ) ;
2020-09-23 15:47:47 +02:00
else if ( Prop - > isString ( ) ) {
// TODO a function that takes a string and return if it's true or false
2021-02-06 18:16:46 +01:00
if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " true " ) ) settingsData . InjectSystemID_ = 1 ;
else if ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' y ' ) settingsData . InjectSystemID_ = 1 ;
else if ( Prop - > getString ( ) - > stringValue ( ) [ 0 ] = = ' Y ' ) settingsData . InjectSystemID_ = 1 ;
else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " false " ) ) settingsData . InjectSystemID_ = 0 ;
else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " n " ) ) settingsData . InjectSystemID_ = 0 ;
else if ( Prop - > getString ( ) - > stringValue ( ) . equalIC ( " N " ) ) settingsData . InjectSystemID_ = 0 ;
2020-09-23 15:47:47 +02:00
else {
DBG ( " MALFORMED PLIST : SMBIOS/InjectSystemID must be true, yes, false, no, or non existant " ) ;
}
} else {
DBG ( " MALFORMED PLIST : SMBIOS/InjectSystemID must be <true/>, <false/> or non existant " ) ;
}
}
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = SystemParametersDict - > propertyForKey ( " NvidiaWeb " ) ;
2021-02-06 18:16:46 +01:00
settingsData . NvidiaWeb = IsPropertyNotNullAndTrue ( Prop ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
const TagDict * BootGraphicsDict = CfgDict - > dictPropertyForKey ( " BootGraphics " ) ;
if ( BootGraphicsDict ! = NULL ) {
const TagStruct * Prop = BootGraphicsDict - > propertyForKey ( " DefaultBackgroundColor " ) ;
2021-02-06 18:16:46 +01:00
settingsData . DefaultBackgroundColor = ( UINT32 ) GetPropertyAsInteger ( Prop , 0x80000000 ) ; //the value 0x80000000 means not set
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootGraphicsDict - > propertyForKey ( " UIScale " ) ;
2021-02-06 18:16:46 +01:00
settingsData . UIScale = ( UINT32 ) GetPropertyAsInteger ( Prop , 0x80000000 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootGraphicsDict - > propertyForKey ( " EFILoginHiDPI " ) ;
2021-02-06 18:16:46 +01:00
settingsData . EFILoginHiDPI = ( UINT32 ) GetPropertyAsInteger ( Prop , 0x80000000 ) ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
Prop = BootGraphicsDict - > propertyForKey ( " flagstate " ) ;
2021-02-06 18:16:46 +01:00
* ( UINT32 * ) & settingsData . flagstate [ 0 ] = ( UINT32 ) GetPropertyAsInteger ( 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
2020-08-19 14:50:26 +02:00
TagStruct * Key , ValArray ;
2019-09-03 11:58:42 +02:00
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-10-03 19:02:31 +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 ) ;
2021-02-06 18:16:46 +01:00
DBG ( " Platform Uuid: %s, InjectSystemID: %s \n " , strguid ( & AppleGuid ) , settingsData . InjectSystemID ? " Yes " : " No " ) ;
2019-09-03 11:58:42 +02:00
}
*/
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gBootChanged ) {
2020-08-25 17:35:19 +02:00
const TagDict * KernelAndKextPatchesDict = CfgDict - > dictPropertyForKey ( " KernelAndKextPatches " ) ;
if ( KernelAndKextPatchesDict ! = NULL ) {
2021-02-06 18:16:46 +01:00
DBG ( " refill kernel patches bcoz GlobalConfig.gBootChanged \n " ) ;
FillinKextPatches ( & settingsData . KernelAndKextPatches , KernelAndKextPatchesDict ) ;
2019-09-03 11:58:42 +02:00
}
} else {
2021-02-06 18:16:46 +01:00
//DBG("\n ConfigName: %ls n", settingsData.ConfigName);
2019-09-03 11:58:42 +02:00
}
2021-02-06 18:16:46 +01:00
if ( GlobalConfig . gThemeChanged ) {
settingsData . GUI . Theme . setEmpty ( ) ;
2020-08-25 17:35:19 +02:00
const TagDict * GUIDict = CfgDict - > dictPropertyForKey ( " GUI " ) ;
if ( GUIDict ! = NULL ) {
const TagStruct * Prop = GUIDict - > propertyForKey ( " Theme " ) ;
if ( ( Prop ! = NULL ) & & ( Prop - > isString ( ) ) & & Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-02-06 18:16:46 +01:00
settingsData . GUI . Theme . takeValueFrom ( Prop - > getString ( ) - > stringValue ( ) ) ;
DBG ( " Theme from new config: %ls \n " , settingsData . GUI . Theme . wc_str ( ) ) ;
2020-03-27 17:50:17 +01:00
}
}
}
2019-09-03 11:58:42 +02:00
SaveSettings ( ) ;
}
2020-08-25 17:35:19 +02:00
//DBG("config.plist read and return %s\n", efiStrError(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
*/
2021-02-04 15:04:31 +01:00
XString8 GetAuthRootDmg ( const EFI_FILE & dir , const XStringW & path )
{
XString8 returnValue ;
XStringW plist = SWPrintf ( " %ls \\ com.apple.Boot.plist " , path . wc_str ( ) ) ;
if ( ! FileExists ( dir , plist ) ) return NullXString8 ;
CHAR8 * PlistBuffer = NULL ;
UINTN PlistLen ;
TagDict * Dict = NULL ;
const TagStruct * Prop = NULL ;
EFI_STATUS Status = egLoadFile ( & dir , plist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS )
{
Prop = Dict - > propertyForKey ( " Kernel Flags " ) ;
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : Kernel Flags not string in ProductVersion \n " ) ;
} else {
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
const XString8 & kernelFlags = Prop - > getString ( ) - > stringValue ( ) ;
size_t idx = kernelFlags . indexOf ( " auth-root-dmg " ) ;
if ( idx = = MAX_XSIZE ) return NullXString8 ;
idx + = strlen ( " auth-root-dmg " ) ;
while ( idx < kernelFlags . length ( ) & & IS_BLANK ( kernelFlags [ idx ] ) ) + + idx ;
if ( kernelFlags [ idx ] = = ' = ' ) + + idx ;
else return NullXString8 ;
while ( idx < kernelFlags . length ( ) & & IS_BLANK ( kernelFlags [ idx ] ) ) + + idx ;
if ( kernelFlags . equalAtIC ( idx , " file:// " _XS8 ) ) idx + = strlen ( " file:// " ) ;
size_t idxEnd = idx ;
while ( idxEnd < kernelFlags . length ( ) & & ! IS_BLANK ( kernelFlags [ idxEnd ] ) ) + + idxEnd ;
returnValue = kernelFlags . subString ( idx , idxEnd - idx ) ;
}
}
}
}
if ( PlistBuffer ) FreePool ( PlistBuffer ) ;
return returnValue ;
}
MacOsVersion GetMacOSVersionFromFolder ( const EFI_FILE & dir , const XStringW & path )
{
MacOsVersion macOSVersion ;
XStringW plist = SWPrintf ( " %ls \\ SystemVersion.plist " , path . wc_str ( ) ) ;
if ( ! FileExists ( dir , plist ) ) {
plist = SWPrintf ( " %ls \\ ServerVersion.plist " , path . wc_str ( ) ) ;
if ( ! FileExists ( dir , plist ) ) {
plist . setEmpty ( ) ;
}
}
if ( plist . notEmpty ( ) ) { // found macOS System
CHAR8 * PlistBuffer = NULL ;
UINTN PlistLen ;
TagDict * Dict = NULL ;
const TagStruct * Prop = NULL ;
EFI_STATUS Status = egLoadFile ( & dir , plist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
macOSVersion = Prop - > getString ( ) - > stringValue ( ) ;
}
}
}
}
if ( PlistBuffer ) FreePool ( PlistBuffer ) ;
}
return macOSVersion ;
}
2021-01-31 10:50:23 +01:00
MacOsVersion GetOSVersion ( int LoaderType , const XStringW & APFSTargetUUID , const REFIT_VOLUME * Volume , XString8 * BuildVersionPtr )
2019-09-03 11:58:42 +02:00
{
2020-08-12 17:15:47 +02:00
XString8 OSVersion ;
2021-01-31 10:50:23 +01:00
XString8 BuildVersion ;
2019-09-03 11:58:42 +02:00
EFI_STATUS Status = EFI_NOT_FOUND ;
CHAR8 * PlistBuffer = NULL ;
UINTN PlistLen ;
2020-08-25 17:35:19 +02:00
TagDict * Dict = NULL ;
const TagDict * DictPointer = NULL ;
2020-08-19 14:50:26 +02:00
const TagStruct * Prop = NULL ;
2019-09-03 11:58:42 +02:00
2021-01-31 10:50:23 +01:00
if ( ! Volume ) {
2020-08-12 17:15:47 +02:00
return NullXString8 ;
2019-09-03 11:58:42 +02:00
}
2021-01-31 10:50:23 +01:00
if ( OSTYPE_IS_OSX ( LoaderType ) )
2020-08-07 10:23:46 +02:00
{
2021-02-06 18:16:46 +01:00
XString8 uuidPrefix ;
2021-01-31 10:50:23 +01:00
if ( APFSTargetUUID . notEmpty ( ) ) uuidPrefix = S8Printf ( " \\ %ls " , APFSTargetUUID . wc_str ( ) ) ;
2020-08-07 10:23:46 +02:00
2021-02-06 18:16:46 +01:00
XStringW plist = SWPrintf ( " %s \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " , uuidPrefix . c_str ( ) ) ;
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
plist = SWPrintf ( " %s \\ System \\ Library \\ CoreServices \\ ServerVersion.plist " , uuidPrefix . c_str ( ) ) ;
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
plist . setEmpty ( ) ;
}
2019-09-03 11:58:42 +02:00
}
2020-08-07 10:23:46 +02:00
if ( plist . notEmpty ( ) ) { // found macOS System
2021-01-31 10:50:23 +01:00
Status = egLoadFile ( Volume - > RootDir , plist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductBuildVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductBuildVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-01-31 10:50:23 +01:00
BuildVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2021-01-31 10:50:23 +01:00
if ( OSTYPE_IS_OSX_INSTALLER ( LoaderType ) ) {
2019-09-03 11:58:42 +02:00
// 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-11-12 22:25:56 +01:00
XStringW InstallerPlist ;
2021-01-31 10:50:23 +01:00
if ( APFSTargetUUID . notEmpty ( ) ) {
InstallerPlist = SWPrintf ( " %ls \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " , APFSTargetUUID . wc_str ( ) ) ;
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) ) InstallerPlist . setEmpty ( ) ;
2020-11-12 22:25:56 +01:00
}
if ( InstallerPlist . isEmpty ( ) ) {
InstallerPlist = SWPrintf ( " \\ .IABootFilesSystemVersion.plist " ) ; // 10.9 - 10.13.3
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) & & FileExists ( Volume - > RootDir , L " \\ System \\ Library \\ CoreServices \\ boot.efi " ) & &
( ( FileExists ( Volume - > RootDir , L " \\ BaseSystem.dmg " ) & & FileExists ( Volume - > RootDir , L " \\ mach_kernel " ) ) | | // 10.7/10.8
FileExists ( Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ Mac OS X Installer.app " ) | | // 10.6/10.7
FileExists ( Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ OS X Installer.app " ) | | // 10.8 - 10.11
FileExists ( Volume - > RootDir , L " \\ System \\ Installation \\ CDIS \\ macOS Installer.app " ) | | // 10.12+
FileExists ( Volume - > RootDir , L " \\ .IAPhysicalMedia " ) ) ) { // 10.13.4+
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " ) ;
}
2019-09-03 11:58:42 +02:00
}
2021-01-31 10:50:23 +01:00
if ( FileExists ( Volume - > RootDir , InstallerPlist ) ) {
Status = egLoadFile ( Volume - > RootDir , InstallerPlist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductBuildVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductBuildVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-01-31 10:50:23 +01:00
BuildVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-11-12 22:25:56 +01:00
// if ( OSVersion.isEmpty() )
// {
2021-01-31 10:50:23 +01:00
// if ( FileExists(Volume->RootDir, SWPrintf("\\%ls\\com.apple.installer\\BridgeVersion.plist", APFSTargetUUID.wc_str()).wc_str()) ) {
2020-11-12 22:25:56 +01:00
// OSVersion = "11.0"_XS8;
// // TODO so far, is there is a BridgeVersion.plist, it's version 11.0. Has to be improved with next releases.
// }
// }
2020-09-07 16:44:24 +02:00
2019-09-03 11:58:42 +02:00
// 1st stage - 2
// Check for plist - createinstallmedia/NetInstall
2020-08-12 17:15:47 +02:00
if ( OSVersion . isEmpty ( ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ .IABootFiles \\ com.apple.Boot.plist " ) ; // 10.9 - ...
2021-01-31 10:50:23 +01:00
if ( FileExists ( Volume - > RootDir , InstallerPlist ) ) {
Status = egLoadFile ( Volume - > RootDir , InstallerPlist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " Kernel Flags " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Kernel Flags \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%20BigSur " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%2011.0 " ) ) {
2021-01-31 10:50:23 +01:00
OSVersion = " 11 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%2010.16 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.16 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%20Catalina " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%2010.15 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.15 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%20Mojave " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%2010.14 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.14 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%20High%20Sierra " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%2010.13 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.13 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20macOS%20Sierra " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%2010.12 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.12 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%20El%20Capitan " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%2010.11 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.11 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%20Yosemite " ) | | Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%2010.10 " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.10 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%20Mavericks.app " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.9 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20OS%20hhX%20Mountain%20Lion " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.8 " _XS8 ;
2020-08-25 17:35:19 +02:00
} else if ( Prop - > getString ( ) - > stringValue ( ) . contains ( " Install%20Mac%20OS%20hhX%20Lion " ) ) {
2020-08-18 18:45:44 +02:00
OSVersion = " 10.7 " _XS8 ;
}
2019-09-03 11:58:42 +02:00
}
}
}
}
}
// 2nd stage - 1
// Check for plist - AppStore/createinstallmedia/startosinstall/Fusion Drive
2020-08-12 17:15:47 +02:00
if ( OSVersion . isEmpty ( ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ macOS Install Data \\ Locked Files \\ Boot Files \\ SystemVersion.plist " ) ; // 10.12.4+
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ macOS Install Data \\ InstallInfo.plist " ) ; // 10.12+
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ com.apple.boot.R \\ SystemVersion.plist) " ) ; // 10.12+
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ com.apple.boot.P \\ SystemVersion.plist " ) ; // 10.12+
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ com.apple.boot.S \\ SystemVersion.plist " ) ; // 10.12+
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerPlist ) & &
( FileExists ( Volume - > RootDir , L " \\ com.apple.boot.R \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) | |
FileExists ( Volume - > RootDir , L " \\ com.apple.boot.P \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) | |
FileExists ( Volume - > RootDir , L " \\ com.apple.boot.S \\ System \\ Library \\ PrelinkedKernels \\ prelinkedkernel " ) ) ) {
2020-11-12 22:25:56 +01:00
InstallerPlist = SWPrintf ( " \\ System \\ Library \\ CoreServices \\ SystemVersion.plist " ) ; // 10.11
2019-09-03 11:58:42 +02:00
}
}
}
}
}
2021-01-31 10:50:23 +01:00
if ( FileExists ( Volume - > RootDir , InstallerPlist ) ) {
Status = egLoadFile ( Volume - > RootDir , InstallerPlist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductBuildVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductBuildVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
if ( Prop - > getString ( ) - > stringValue ( ) . notEmpty ( ) ) {
2021-01-31 10:50:23 +01:00
BuildVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
}
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-08-22 15:39:24 +02:00
DictPointer = Dict - > dictPropertyForKey ( " System Image Info " ) ; // 10.12+
2019-09-03 11:58:42 +02:00
if ( DictPointer ! = NULL ) {
2020-08-25 17:35:19 +02:00
Prop = DictPointer - > propertyForKey ( " version " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in version \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
// 2nd stage - 2
// Check for ia.log - InstallESD/createinstallmedia/startosinstall
// Implemented by Sherlocks
2020-08-12 17:15:47 +02:00
if ( OSVersion . isEmpty ( ) ) {
2020-08-09 17:55:30 +02:00
CONST CHAR8 * s , * fileBuffer ;
2020-08-15 15:47:56 +02: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-08-09 17:55:30 +02:00
XStringW InstallerLog ;
InstallerLog = L " \\ Mac OS X Install Data \\ ia.log " _XSW ; // 10.7
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerLog ) ) {
2020-08-09 17:55:30 +02:00
InstallerLog = L " \\ OS X Install Data \\ ia.log " _XSW ; // 10.8 - 10.11
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , InstallerLog ) ) {
2020-08-09 17:55:30 +02:00
InstallerLog = L " \\ macOS Install Data \\ ia.log " _XSW ; // 10.12+
2019-09-03 11:58:42 +02:00
}
}
2021-01-31 10:50:23 +01:00
if ( FileExists ( Volume - > RootDir , InstallerLog ) ) {
Status = egLoadFile ( Volume - > RootDir , InstallerLog . wc_str ( ) , ( UINT8 * * ) & fileBuffer , & fileLen ) ;
2020-04-23 11:08:10 +02:00
if ( ! EFI_ERROR ( Status ) ) {
2020-08-09 17:55:30 +02:00
XString8 targetString ;
targetString . strncpy ( fileBuffer , fileLen ) ;
2020-02-18 19:49:54 +01:00
// s = SearchString(targetString, fileLen, "Running OS Build: Mac OS X ", 27);
2020-08-09 17:55:30 +02:00
s = AsciiStrStr ( targetString . c_str ( ) , " Running OS Build: Mac OS X " ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 31 ] = = ' ' ) {
2020-08-12 17:15:47 +02:00
OSVersion . S8Printf ( " %c%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 38 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c \n " , s [ 33 ] , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 39 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c \n " , s [ 33 ] , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 31 ] = = ' . ' ) {
2020-08-12 17:15:47 +02:00
OSVersion . S8Printf ( " %c%c.%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 32 ] ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 40 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c \n " , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 41 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c \n " , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 32 ] = = ' ' ) {
2020-08-12 17:15:47 +02:00
OSVersion . S8Printf ( " %c%c.%c%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 31 ] ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 39 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 40 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 41 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c%c \n " , s [ 34 ] , s [ 35 ] , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2019-09-03 11:58:42 +02:00
}
} else if ( s [ 32 ] = = ' . ' ) {
2020-08-12 17:15:47 +02:00
OSVersion . S8Printf ( " %c%c.%c%c.%c \n " , s [ 27 ] , s [ 28 ] , s [ 30 ] , s [ 31 ] , s [ 33 ] ) ;
2019-09-03 11:58:42 +02:00
if ( s [ 41 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 42 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] , s [ 41 ] ) ;
2019-09-03 11:58:42 +02:00
} else if ( s [ 43 ] = = ' ) ' ) {
2021-01-31 10:50:23 +01:00
BuildVersion . S8Printf ( " %c%c%c%c%c%c%c \n " , s [ 36 ] , s [ 37 ] , s [ 38 ] , s [ 39 ] , s [ 40 ] , s [ 41 ] , s [ 42 ] ) ;
2019-09-03 11:58:42 +02:00
}
}
2020-02-21 22:22:30 +01:00
FreePool ( fileBuffer ) ;
2019-09-03 11:58:42 +02:00
}
}
}
// 2nd stage - 3
// Check for plist - Preboot of APFS
2020-08-12 17:15:47 +02:00
if ( OSVersion . isEmpty ( ) )
2020-08-07 10:23:46 +02:00
{
2021-02-06 18:16:46 +01:00
XStringW plist = L " \\ macOS Install Data \\ Locked Files \\ Boot Files \\ SystemVersion.plist " _XSW ;
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
plist . setEmpty ( ) ;
}
2020-08-07 10:23:46 +02:00
if ( plist . notEmpty ( ) ) { // found macOS System
2019-09-03 11:58:42 +02:00
2021-01-31 10:50:23 +01:00
Status = egLoadFile ( Volume - > RootDir , plist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductBuildVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductBuildVersion \n " ) ;
} else {
2021-01-31 10:50:23 +01:00
BuildVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2019-09-03 11:58:42 +02:00
}
}
}
2021-01-31 10:50:23 +01:00
if ( OSTYPE_IS_OSX_RECOVERY ( LoaderType ) ) {
2020-08-07 10:23:46 +02:00
2021-02-06 18:16:46 +01:00
XString8 uuidPrefix ;
2021-01-31 10:50:23 +01:00
if ( APFSTargetUUID . notEmpty ( ) ) uuidPrefix = S8Printf ( " \\ %ls " , APFSTargetUUID . wc_str ( ) ) ;
2020-08-07 10:23:46 +02:00
2021-02-06 18:16:46 +01:00
XStringW plist = SWPrintf ( " %s \\ SystemVersion.plist " , uuidPrefix . c_str ( ) ) ;
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
plist = SWPrintf ( " %s \\ ServerVersion.plist " , uuidPrefix . c_str ( ) ) ;
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
2020-08-07 10:23:46 +02:00
plist = L " \\ com.apple.recovery.boot \\ SystemVersion.plist " _XSW ;
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
2020-08-07 10:23:46 +02:00
plist = L " \\ com.apple.recovery.boot \\ ServerVersion.plist " _XSW ;
2021-01-31 10:50:23 +01:00
if ( ! FileExists ( Volume - > RootDir , plist ) ) {
2021-02-06 18:16:46 +01:00
plist . setEmpty ( ) ;
}
}
}
2019-09-03 11:58:42 +02:00
}
2020-08-07 10:23:46 +02:00
// Detect exact version for OS X Recovery
if ( plist . notEmpty ( ) ) { // found macOS System
2021-01-31 10:50:23 +01:00
Status = egLoadFile ( Volume - > RootDir , plist . wc_str ( ) , ( UINT8 * * ) & PlistBuffer , & PlistLen ) ;
2020-05-15 05:23:33 +02:00
if ( ! EFI_ERROR ( Status ) & & PlistBuffer ! = NULL & & ParseXML ( PlistBuffer , & Dict , 0 ) = = EFI_SUCCESS ) {
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductVersion \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
OSVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " ProductBuildVersion " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in ProductBuildVersion \n " ) ;
} else {
2021-01-31 10:50:23 +01:00
BuildVersion = Prop - > getString ( ) - > stringValue ( ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2021-01-31 10:50:23 +01:00
} else if ( FileExists ( Volume - > RootDir , L " \\ com.apple.recovery.boot \\ boot.efi " ) ) {
2019-09-03 11:58:42 +02:00
// Special case - com.apple.recovery.boot/boot.efi exists but SystemVersion.plist doesn't --> 10.9 recovery
2020-08-12 17:15:47 +02:00
OSVersion = " 10.9 " _XS8 ;
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
}
2021-01-31 10:50:23 +01:00
( * BuildVersionPtr ) . stealValueFrom ( & BuildVersion ) ;
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
2020-11-12 22:25:56 +01:00
GetOSIconName ( const MacOsVersion & OSVersion )
2019-09-03 11:58:42 +02:00
{
2020-04-27 11:50:49 +02:00
XStringW OSIconName ;
2020-08-12 17:15:47 +02:00
if ( OSVersion . isEmpty ( ) ) {
2020-04-27 11:50:49 +02:00
OSIconName = L " mac " _XSW ;
2020-11-12 22:25:56 +01:00
} else if ( ( OSVersion . elementAt ( 0 ) = = 10 & & OSVersion . elementAt ( 1 ) = = 16 ) | |
2020-11-26 19:42:33 +01:00
( OSVersion . elementAt ( 0 ) = = 11 /*&& OSVersion.elementAt(1) == 0*/ )
2020-11-12 22:25:56 +01:00
) {
2020-06-22 20:47:45 +02:00
// Big Sur
OSIconName = L " bigsur,mac " _XSW ;
2020-11-12 22:25:56 +01:00
} else if ( OSVersion . elementAt ( 0 ) = = 10 ) {
if ( OSVersion . elementAt ( 1 ) = = 15 ) {
// Catalina
OSIconName = L " cata,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 14 ) {
// Mojave
OSIconName = L " moja,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 13 ) {
// High Sierra
OSIconName = L " hsierra,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 12 ) {
// Sierra
OSIconName = L " sierra,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 11 ) {
// El Capitan
OSIconName = L " cap,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 10 ) {
// Yosemite
OSIconName = L " yos,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 9 ) {
// Mavericks
OSIconName = L " mav,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 8 ) {
// Mountain Lion
OSIconName = L " cougar,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 7 ) {
// Lion
OSIconName = L " lion,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 6 ) {
// Snow Leopard
OSIconName = L " snow,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 5 ) {
// Leopard
OSIconName = L " leo,mac " _XSW ;
} else if ( OSVersion . elementAt ( 1 ) = = 4 ) {
// Tiger
OSIconName = L " tiger,mac " _XSW ;
} else {
OSIconName = L " 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 ;
2020-08-25 17:35:19 +02:00
TagDict * Dict ;
2020-08-19 14:50:26 +02:00
const TagStruct * Prop ;
2019-09-03 11:58:42 +02:00
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-08-25 17:35:19 +02:00
Prop = Dict - > propertyForKey ( " Root UUID " ) ;
2020-08-18 18:45:44 +02:00
if ( Prop ! = NULL ) {
if ( ! Prop - > isString ( ) ) {
MsgLog ( " ATTENTION : property not string in Root UUID \n " ) ;
} else {
2020-08-25 17:35:19 +02:00
Status = StrToGuidLE ( Prop - > getString ( ) - > stringValue ( ) , & Volume - > RootUUID ) ;
2020-08-18 18:45:44 +02:00
}
2019-09-03 11:58:42 +02:00
}
2020-08-22 15:39:24 +02:00
Dict - > FreeTag ( ) ;
2020-04-23 11:08:10 +02:00
FreePool ( PlistBuffer ) ;
2019-09-03 11:58:42 +02:00
}
return Status ;
}
2020-10-03 19:02:31 +02:00
void
2019-09-03 11:58:42 +02:00
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 ;
2020-08-31 09:07:36 +02:00
AudioList . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
//Arpt.Valid = FALSE; //global variables initialized by 0 - c-language
2020-08-09 17:55:30 +02:00
XStringW GopDevicePathStr ;
XStringW DevicePathStr ;
2019-09-03 11:58:42 +02:00
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 ) ) {
2020-08-09 17:55:30 +02:00
GopDevicePathStr = DevicePathToXStringW ( DevicePathFromHandle ( HandleArray [ 0 ] ) ) ;
DBG ( " GOP found at: %ls \n " , GopDevicePathStr . wc_str ( ) ) ;
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 ) {
2020-10-03 19:02:31 +02:00
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
) ;
2021-02-06 18:16:46 +01: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
2020-08-09 17:55:30 +02:00
DevicePathStr = DevicePathToXStringW ( DevicePathFromHandle ( HandleArray [ Index ] ) ) ;
if ( StrStr ( GopDevicePathStr . wc_str ( ) , DevicePathStr . wc_str ( ) ) ) {
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
}
}
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 ) ;
2021-02-06 18:16:46 +01: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 ;
2021-02-06 18:16:46 +01: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-12-13 09:51:50 +01: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 ;
2021-02-06 18:16:46 +01: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
}
}
}
}
2020-10-03 19:02:31 +02:00
void
2019-09-03 11:58:42 +02:00
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-08-09 17:55:30 +02:00
DBG ( " add device: %ls \n " , DevicePathToXStringW ( Prop - > DevicePath ) . wc_str ( ) ) ;
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 + + ) {
2020-10-03 19:02:31 +02:00
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 ) {
2021-01-31 10:50:23 +01:00
TmpDirty = setup_hda_devprop ( PciIo , & PCIdevice , Entry - > macOSVersion ) ;
2020-06-05 14:15:31 +02:00
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
//---------
2020-10-17 15:01:33 +02:00
// Status = egSaveFile(&self.getSelfRootDir(), SWPrintf("%ls\\misc\\devprop.bin", self.getCloverDirFullPath().wc_str()).wc_str() , (UINT8*)mProperties, mPropSize);
2019-09-03 11:58:42 +02:00
//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 ;
}
}
}
}
2021-02-06 18:16:46 +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 ;
2021-02-06 18:16:46 +01:00
if ( ( gSettings . BusSpeed ! = 0 ) & & ( gSettings . BusSpeed > 10 * Kilo ) & & ( gSettings . BusSpeed < 500 * Kilo ) ) {
2019-09-03 11:58:42 +02:00
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 ;
2021-02-06 18:16:46 +01:00
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, Kilo)));
2019-09-03 11:58:42 +02:00
break ;
default :
2021-02-06 18:16:46 +01:00
//DBG("Read ExternalClock: %d MHz\n", (INT32)(DivU64x32(gSettings.BusSpeed, Kilo)));
2019-09-03 11:58:42 +02:00
// for sandy bridge or newer
// to match ExternalClock 25 MHz like real mac, divide BusSpeed by 4
gCPUStructure . ExternalClock = ( gSettings . BusSpeed + 3 ) / 4 ;
2021-02-06 18:16:46 +01:00
//DBG("Corrected ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, Kilo)));
2019-09-03 11:58:42 +02:00
break ;
}
2021-02-06 18:16:46 +01:00
gCPUStructure . FSBFrequency = MultU64x64 ( gSettings . BusSpeed , Kilo ) ; //kHz -> Hz
2019-09-03 11:58:42 +02:00
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 ;
}
2020-08-09 17:55:30 +02:00
XStringW GetOtherKextsDir ( BOOLEAN On )
2019-09-03 11:58:42 +02:00
{
2020-10-05 11:14:35 +02:00
if ( ! selfOem . isKextsDirFound ( ) ) return NullXStringW ;
2020-10-03 19:02:31 +02:00
if ( FileExists ( & selfOem . getKextsDir ( ) , On ? L " Other " : L " Off " ) ) {
return On ? L " Other " _XSW : L " Off " _XSW ;
2019-09-03 11:58:42 +02:00
}
2020-10-03 19:02:31 +02:00
return NullXStringW ;
2019-09-03 11:58:42 +02:00
}
2020-10-17 15:01:33 +02:00
2019-09-03 11:58:42 +02:00
//dmazar
2020-10-17 15:01:33 +02:00
// Jief 2020-10: this is only called by SetFSInjection(). SetFSInjection() doesn't check for return value emptiness.
2020-11-12 22:25:56 +01:00
XStringW GetOSVersionKextsDir ( const MacOsVersion & OSVersion )
2019-09-03 11:58:42 +02:00
{
2020-11-12 22:25:56 +01:00
// XString8 FixedVersion;
// CHAR8 *DotPtr;
2019-09-03 11:58:42 +02:00
2020-10-17 15:01:33 +02:00
if ( ! selfOem . isKextsDirFound ( ) ) return NullXStringW ;
2020-11-12 22:25:56 +01:00
// if (OSVersion.notEmpty()) {
// FixedVersion.strncpy(OSVersion.c_str(), 5);
// // DBG("%s\n", FixedVersion);
// // OSVersion may contain minor version too (can be 10.x or 10.x.y)
// if ((DotPtr = AsciiStrStr (FixedVersion.c_str(), ".")) != NULL) {
// DotPtr = AsciiStrStr (DotPtr+1, "."); // second dot
// }
//
// if (DotPtr != NULL) {
// *DotPtr = 0;
// }
// }
2019-09-03 11:58:42 +02:00
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-10-17 15:01:33 +02:00
// Jief : NOTE selfOem.getKextsFullPath() return a path under OEM if exists, or in Clover if not.
2020-11-12 22:25:56 +01:00
XStringW SrcDir = SWPrintf ( " %ls \\ %s " , selfOem . getKextsFullPath ( ) . wc_str ( ) , OSVersion . asString ( 2 ) . c_str ( ) ) ;
2020-10-17 15:01:33 +02:00
if ( FileExists ( & self . getSelfVolumeRootDir ( ) , SrcDir ) ) return SrcDir ;
return NullXStringW ;
2019-09-03 11:58:42 +02:00
}
EFI_STATUS
InjectKextsFromDir (
EFI_STATUS Status ,
2020-08-09 17:55:30 +02:00
CONST CHAR16 * SrcDir
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
MsgLog ( " - ERROR: Kext injection failed! \n " ) ;
return EFI_NOT_STARTED ;
}
return Status ;
}
2020-10-17 15:01:33 +02:00
EFI_STATUS LOADER_ENTRY : : SetFSInjection ( )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status ;
FSINJECTION_PROTOCOL * FSInject ;
2020-08-09 17:55:30 +02:00
XStringW SrcDir ;
2019-09-03 11:58:42 +02:00
//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-08-25 17:35:19 +02:00
//Print (L"- No FSINJECTION_PROTOCOL, Status = %s\n", efiStrError(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-08-09 17:55:30 +02:00
FSInject - > AddStringToList ( Blacklist , SWPrintf ( " \\ System \\ Library \\ Extensions \\ %ls " , gSettings . BlockKexts ) . wc_str ( ) ) ;
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 (),
2020-08-09 17:55:30 +02:00
SrcDir . wc_str ( ) ,
2019-09-03 11:58:42 +02:00
Blacklist ,
ForceLoadKexts
) ;
//InjectKextsFromDir(Status, GetOtherKextsDir());
2020-08-09 17:55:30 +02:00
InjectKextsFromDir ( Status , SrcDir . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
2021-01-31 10:50:23 +01:00
SrcDir = GetOSVersionKextsDir ( macOSVersion ) ;
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 ,
2020-05-01 18:26:28 +02:00
//GetOSVersionKextsDir(OSVersion),
2020-08-09 17:55:30 +02:00
SrcDir . wc_str ( ) ,
2019-09-03 11:58:42 +02:00
Blacklist ,
ForceLoadKexts
) ;
2020-05-01 18:26:28 +02:00
//InjectKextsFromDir(Status, GetOSVersionKextsDir(OSVersion));
2020-08-09 17:55:30 +02:00
InjectKextsFromDir ( Status , SrcDir . wc_str ( ) ) ;
2019-09-03 11:58:42 +02:00
} 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 ;
}
2020-08-15 15:47:56 +02:00
namespace old {
2020-09-01 19:58:59 +02:00
# include "../../CloverApp/Clover/CloverOldHeaders.h"
2020-08-15 15:47:56 +02:00
}
static void breakpoint ( )
{
DBG ( " Bug \n " ) ;
}
# define WriteOldFixLengthString(str, strSize) xb.ncat(str.s(), MIN(str.sizeInBytes(), strSize*sizeof(*str.s()))); xb.memsetAtPos(xb.size(), 0, strSize*sizeof(*str.s())-MIN(str.sizeInBytes(), strSize*sizeof(*str.s())));
# define checkOffset(w) \
{ \
size_t offset = OFFSET_OF ( old : : SETTINGS_DATA , w ) ; \
if ( offset ! = xb . size ( ) ) { \
breakpoint ( ) ; \
} \
}
2020-08-13 14:07:40 +02:00
XBuffer < UINT8 > SETTINGS_DATA : : serialize ( ) const
{
XBuffer < UINT8 > xb ;
// SMBIOS TYPE0
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( VendorName , 64 ) ;
checkOffset ( RomVersion ) ;
WriteOldFixLengthString ( RomVersion , 64 ) ;
WriteOldFixLengthString ( EfiVersion , 64 ) ;
WriteOldFixLengthString ( ReleaseDate , 64 ) ;
2020-08-13 14:07:40 +02:00
// SMBIOS TYPE1
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( ManufactureName , 64 ) ;
WriteOldFixLengthString ( ProductName , 64 ) ;
WriteOldFixLengthString ( VersionNr , 64 ) ;
WriteOldFixLengthString ( SerialNr , 64 ) ;
2020-08-13 14:07:40 +02:00
xb . ncat ( & SmUUID , sizeof ( SmUUID ) ) ;
2020-09-23 15:47:47 +02:00
xb . cat ( ( BOOLEAN ) SmUUID . notEmpty ( ) ) ;
2020-08-13 14:07:40 +02:00
xb . ncat ( & pad0 , sizeof ( pad0 ) ) ;
//CHAR8 Uuid[64]);
//CHAR8 SKUNumber[64]);
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( FamilyName , 64 ) ;
WriteOldFixLengthString ( OEMProduct , 64 ) ;
WriteOldFixLengthString ( OEMVendor , 64 ) ;
2020-08-13 14:07:40 +02:00
// SMBIOS TYPE2
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( BoardManufactureName , 64 ) ;
WriteOldFixLengthString ( BoardSerialNumber , 64 ) ;
WriteOldFixLengthString ( BoardNumber , 64 ) ; //Board-ID
WriteOldFixLengthString ( LocationInChassis , 64 ) ;
WriteOldFixLengthString ( BoardVersion , 64 ) ;
WriteOldFixLengthString ( OEMBoard , 64 ) ;
checkOffset ( BoardType ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( BoardType ) ;
xb . cat ( pad1 ) ;
// SMBIOS TYPE3
xb . cat ( Mobile ) ;
xb . cat ( ChassisType ) ;
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( ChassisManufacturer , 64 ) ;
WriteOldFixLengthString ( ChassisAssetTag , 64 ) ;
2020-08-13 14:07:40 +02:00
// SMBIOS TYPE4
xb . cat ( CpuFreqMHz ) ;
xb . cat ( BusSpeed ) ; //in kHz
xb . cat ( Turbo ) ;
xb . cat ( EnabledCores ) ;
xb . cat ( UserChange ) ;
xb . cat ( QEMU ) ;
// SMBIOS TYPE17
xb . cat ( SmbiosVersion ) ;
xb . cat ( Attribute ) ;
xb . ncat ( & pad17 , sizeof ( pad17 ) ) ;
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( MemoryManufacturer , 64 ) ;
WriteOldFixLengthString ( MemorySerialNumber , 64 ) ;
WriteOldFixLengthString ( MemoryPartNumber , 64 ) ;
WriteOldFixLengthString ( MemorySpeed , 64 ) ;
2020-08-13 14:07:40 +02:00
// SMBIOS TYPE131
2020-08-15 15:47:56 +02:00
checkOffset ( CpuType ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( CpuType ) ;
// SMBIOS TYPE132
xb . cat ( QPI ) ;
xb . cat ( SetTable132 ) ;
xb . cat ( TrustSMBIOS ) ;
xb . cat ( InjectMemoryTables ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . XMPDetection ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( UseARTFreq ) ;
// SMBIOS TYPE133
xb . ncat ( & pad18 , sizeof ( pad18 ) ) ;
xb . cat ( PlatformFeature ) ;
// PatchTableType11
xb . cat ( NoRomInfo ) ;
// OS parameters
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( Language , 16 ) ;
checkOffset ( BootArgs ) ;
2021-02-02 10:02:21 +01:00
WriteOldFixLengthString ( Boot . BootArgs , 256 ) ;
2020-08-15 22:39:25 +02:00
xb . memsetAtPos ( xb . size ( ) , 0 , 1 ) ;
2020-08-15 15:47:56 +02:00
checkOffset ( CustomUuid ) ;
2020-09-23 15:47:47 +02:00
WriteOldFixLengthString ( XStringW ( CustomUuid ) , 40 ) ;
2020-08-13 14:07:40 +02:00
xb . ncat ( & pad20 , sizeof ( pad20 ) ) ;
2020-08-15 15:47:56 +02:00
checkOffset ( DefaultVolume ) ;
xb . cat ( uintptr_t ( 0 ) ) ; //DefaultVolume was CHAR16*
xb . cat ( uintptr_t ( 0 ) ) ; //DefaultLoader was CHAR16*
2020-08-13 14:07:40 +02:00
//Boot
2020-08-15 15:47:56 +02:00
checkOffset ( LastBootedVolume ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . LastBootedVolume ) ;
xb . cat ( Boot . SkipHibernateTimeout ) ;
2020-08-13 14:07:40 +02:00
//Monitor
xb . cat ( IntelMaxBacklight ) ;
xb . ncat ( & pad21 , sizeof ( pad21 ) ) ;
xb . cat ( VendorEDID ) ;
xb . cat ( ProductEDID ) ;
xb . cat ( BacklightLevel ) ;
xb . cat ( BacklightLevelConfig ) ;
xb . cat ( IntelBacklight ) ;
//Boot options
xb . cat ( MemoryFix ) ;
xb . cat ( WithKexts ) ;
xb . cat ( WithKextsIfNoFakeSMC ) ;
xb . cat ( FakeSMCFound ) ;
xb . cat ( NoCaches ) ;
// GUI parameters
xb . cat ( Debug ) ;
// BOOLEAN Proportional); //never used
xb . ncat ( & pad22 , sizeof ( pad22 ) ) ;
xb . cat ( DefaultBackgroundColor ) ;
//ACPI
2020-08-15 15:47:56 +02:00
checkOffset ( ResetAddr ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( ResetAddr ) ;
xb . cat ( ResetVal ) ;
xb . cat ( NoASPM ) ;
xb . cat ( DropSSDT ) ;
xb . cat ( NoOemTableId ) ;
xb . cat ( NoDynamicExtract ) ;
xb . cat ( AutoMerge ) ;
xb . cat ( GeneratePStates ) ;
xb . cat ( GenerateCStates ) ;
xb . cat ( GenerateAPSN ) ;
xb . cat ( GenerateAPLF ) ;
xb . cat ( GeneratePluginType ) ;
xb . cat ( PLimitDict ) ;
xb . cat ( UnderVoltStep ) ;
xb . cat ( DoubleFirstState ) ;
xb . cat ( SuspendOverride ) ;
xb . cat ( EnableC2 ) ;
xb . cat ( EnableC4 ) ;
xb . cat ( EnableC6 ) ;
xb . cat ( EnableISS ) ;
xb . cat ( SlpSmiEnable ) ;
xb . cat ( FixHeaders ) ;
xb . ncat ( & pad23 , sizeof ( pad23 ) ) ;
xb . cat ( C3Latency ) ;
xb . cat ( smartUPS ) ;
xb . cat ( PatchNMI ) ;
xb . cat ( EnableC7 ) ;
xb . cat ( SavingMode ) ;
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( DsdtName , 28 ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( FixDsdt ) ;
xb . cat ( MinMultiplier ) ;
xb . cat ( MaxMultiplier ) ;
xb . cat ( PluginType ) ;
// BOOLEAN DropMCFG);
2020-08-15 15:47:56 +02:00
checkOffset ( FixMCFG ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( FixMCFG ) ;
xb . cat ( DeviceRenameCount ) ;
xb . cat ( DeviceRename ) ;
//Injections
xb . cat ( StringInjector ) ;
2020-09-23 15:47:47 +02:00
xb . cat ( InjectSystemID_ ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( NoDefaultProperties ) ;
xb . cat ( ReuseFFFF ) ;
//PCI devices
xb . cat ( FakeATI ) ; //97
xb . cat ( FakeNVidia ) ;
xb . cat ( FakeIntel ) ;
xb . cat ( FakeLAN ) ; //100
xb . cat ( FakeWIFI ) ;
xb . cat ( FakeSATA ) ;
xb . cat ( FakeXHCI ) ; //103
xb . cat ( FakeIMEI ) ; //106
//Graphics
// UINT16 PCIRootUID);
2020-08-15 15:47:56 +02:00
checkOffset ( GraphicsInjector ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( GraphicsInjector ) ;
xb . cat ( InjectIntel ) ;
xb . cat ( InjectATI ) ;
xb . cat ( InjectNVidia ) ;
xb . cat ( DeInit ) ;
xb . cat ( LoadVBios ) ;
xb . cat ( PatchVBios ) ;
xb . ncat ( & pad24 , sizeof ( pad24 ) ) ;
xb . cat ( PatchVBiosBytes ) ;
xb . cat ( PatchVBiosBytesCount ) ;
xb . cat ( InjectEDID ) ;
xb . cat ( LpcTune ) ;
xb . cat ( DropOEM_DSM ) ; //vacant
xb . ncat ( & pad25 , sizeof ( pad25 ) ) ;
xb . cat ( CustomEDID ) ;
xb . cat ( CustomEDIDsize ) ;
xb . cat ( EdidFixHorizontalSyncPulseWidth ) ;
xb . cat ( EdidFixVideoInputSignal ) ;
xb . ncat ( & pad26 , sizeof ( pad26 ) ) ;
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( FBName , 16 ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( VideoPorts ) ;
xb . cat ( NvidiaGeneric ) ;
xb . cat ( NvidiaNoEFI ) ;
xb . cat ( NvidiaSingle ) ;
xb . ncat ( & pad27 , sizeof ( pad27 ) ) ;
xb . cat ( VRAM ) ;
xb . ncat ( & Dcfg , sizeof ( Dcfg ) ) ;
xb . ncat ( & NVCAP , sizeof ( NVCAP ) ) ;
xb . cat ( BootDisplay ) ;
xb . cat ( NvidiaWeb ) ;
xb . ncat ( & pad41 , sizeof ( pad41 ) ) ;
xb . cat ( DualLink ) ;
xb . cat ( IgPlatform ) ;
// Secure boot white/black list
2020-08-15 15:47:56 +02:00
checkOffset ( SecureBootWhiteListCount ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . SecureBootWhiteListCount ) ;
xb . cat ( Boot . SecureBootBlackListCount ) ;
xb . cat ( Boot . SecureBootWhiteList ) ;
xb . cat ( Boot . SecureBootBlackList ) ;
2020-08-13 14:07:40 +02:00
// Secure boot
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . SecureBoot ) ;
xb . cat ( Boot . SecureBootSetupMode ) ;
xb . cat ( Boot . SecureBootPolicy ) ;
2020-08-13 14:07:40 +02:00
// HDA
xb . cat ( HDAInjection ) ;
xb . cat ( HDALayoutId ) ;
// USB DeviceTree injection
xb . cat ( USBInjection ) ;
xb . cat ( USBFixOwnership ) ;
xb . cat ( InjectClockID ) ;
xb . cat ( HighCurrent ) ;
xb . cat ( NameEH00 ) ;
xb . cat ( NameXH00 ) ;
xb . cat ( LANInjection ) ;
xb . cat ( HDMIInjection ) ;
// UINT8 pad61[2]);
// LegacyBoot
2020-08-15 15:47:56 +02:00
checkOffset ( LegacyBoot ) ;
2021-02-02 10:02:21 +01:00
WriteOldFixLengthString ( Boot . LegacyBoot , 32 ) ;
xb . cat ( Boot . LegacyBiosDefaultEntry ) ;
2020-08-13 14:07:40 +02:00
//SkyLake
xb . cat ( HWP ) ;
xb . cat ( TDP ) ;
xb . cat ( HWPValue ) ;
//Volumes hiding
2020-08-15 22:39:25 +02:00
xb . cat ( uintptr_t ( 0 ) ) ; // HVHideStrings was **
xb . cat ( ( INTN ) 0 ) ;
2020-08-13 14:07:40 +02:00
// KernelAndKextPatches
xb . memsetAtPos ( xb . size ( ) , 0 , 112 ) ; //KernelAndKextPatches was 112 bytes
xb . cat ( KextPatchesAllowed ) ;
xb . cat ( KernelPatchesAllowed ) ; //From GUI: Only for user patches, not internal Clover
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( AirportBridgeDeviceName , 5 ) ;
2020-08-13 14:07:40 +02:00
// Pre-language
xb . cat ( KbdPrevLang ) ;
//Pointer
xb . cat ( PointerEnabled ) ;
xb . ncat ( & pad28 , sizeof ( pad28 ) ) ;
xb . cat ( PointerSpeed ) ;
xb . cat ( DoubleClickTime ) ;
xb . cat ( PointerMirror ) ;
// UINT8 pad7[6]);
2020-08-15 15:47:56 +02:00
checkOffset ( CustomBoot ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . CustomBoot ) ;
2020-08-13 14:07:40 +02:00
xb . ncat ( & pad29 , sizeof ( pad29 ) ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . CustomLogo ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( RefCLK ) ;
// SysVariables
xb . ncat ( & pad30 , sizeof ( pad30 ) ) ;
2020-09-23 15:47:47 +02:00
checkOffset ( RtMLB ) ;
2020-08-15 15:47:56 +02:00
xb . cat ( uintptr_t ( 0 ) ) ; // RtMLB was CHAR8*
2020-09-23 15:47:47 +02:00
xb . cat ( uintptr_t ( 0 ) ) ; // RtROM was UINT8*
checkOffset ( RtROMLen ) ;
xb . cat ( RtROM . size ( ) ) ;
checkOffset ( CsrActiveConfig ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( CsrActiveConfig ) ;
xb . cat ( BooterConfig ) ;
2020-08-15 15:47:56 +02:00
WriteOldFixLengthString ( BooterCfgStr , 64 ) ;
2021-02-02 10:02:21 +01:00
xb . cat ( Boot . DisableCloverHotkeys ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( NeverDoRecovery ) ;
// Multi-config
xb . ncat ( & ConfigName , sizeof ( ConfigName ) ) ;
xb . ncat ( & pad31 , sizeof ( pad31 ) ) ;
2020-08-13 14:57:05 +02:00
xb . cat ( uintptr_t ( 0 ) ) ; // MainConfigName was a CHAR16*
2020-08-13 14:07:40 +02:00
//Drivers
2020-08-31 11:00:52 +02:00
xb . cat ( DisabledDriverArray . size ( ) ) ; // BlackListCount
xb . cat ( uintptr_t ( 0 ) ) ; // BlackList was a pointer
2020-08-13 14:07:40 +02:00
//SMC keys
xb . ncat ( & RPlt , sizeof ( RPlt ) ) ;
xb . ncat ( & RBr , sizeof ( RBr ) ) ;
xb . ncat ( & EPCI , sizeof ( EPCI ) ) ;
xb . ncat ( & REV , sizeof ( REV ) ) ;
//other devices
2020-08-15 15:47:56 +02:00
checkOffset ( Rtc8Allowed ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( Rtc8Allowed ) ;
xb . cat ( ForceHPET ) ;
xb . cat ( ResetHDA ) ;
xb . cat ( PlayAsync ) ;
xb . ncat ( & pad32 , sizeof ( pad32 ) ) ;
xb . cat ( DisableFunctions ) ;
//Patch DSDT arbitrary
2020-08-27 20:47:56 +02:00
xb . cat ( ( UINT32 ) DSDTPatchArray . size ( ) ) ; // PatchDsdtNum
xb . cat ( uintptr_t ( 0 ) ) ; // PatchDsdtFind
xb . cat ( uintptr_t ( 0 ) ) ; // LenToFind
xb . cat ( uintptr_t ( 0 ) ) ; // PatchDsdtReplace
xb . cat ( uintptr_t ( 0 ) ) ; // LenToReplace
checkOffset ( DebugDSDT ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( DebugDSDT ) ;
xb . cat ( SlpWak ) ;
xb . cat ( UseIntelHDMI ) ;
xb . cat ( AFGLowPowerState ) ;
xb . cat ( PNLF_UID ) ;
// UINT8 pad83[4]);
// Table dropping
xb . ncat ( & pad34 , sizeof ( pad34 ) ) ;
xb . cat ( ACPIDropTables ) ;
// Custom entries
xb . cat ( DisableEntryScan ) ;
xb . cat ( DisableToolScan ) ;
2020-08-15 22:39:25 +02:00
xb . cat ( ( BOOLEAN ) 0 ) ; // was ShowHiddenEntries (BOOLEAN)
2020-08-13 14:07:40 +02:00
xb . cat ( KernelScan ) ;
xb . cat ( LinuxScan ) ;
// UINT8 pad84[3]);
xb . ncat ( & pad35 , sizeof ( pad35 ) ) ;
2020-08-15 15:47:56 +02:00
checkOffset ( CustomEntries ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( CustomEntries ) ;
xb . cat ( CustomLegacy ) ;
xb . cat ( CustomTool ) ;
//Add custom properties
xb . cat ( NrAddProperties ) ;
xb . cat ( AddProperties ) ;
//BlackListed kexts
xb . ncat ( & BlockKexts , sizeof ( BlockKexts ) ) ;
//ACPI tables
xb . cat ( SortedACPICount ) ;
xb . cat ( SortedACPI ) ;
// ACPI/PATCHED/AML
xb . cat ( DisabledAMLCount ) ;
xb . ncat ( & pad36 , sizeof ( pad36 ) ) ;
xb . cat ( DisabledAML ) ;
2020-08-27 20:47:56 +02:00
xb . cat ( uintptr_t ( 0 ) ) ; // PatchDsdtLabel
xb . cat ( uintptr_t ( 0 ) ) ; // PatchDsdtTgt
xb . cat ( uintptr_t ( 0 ) ) ; // PatchDsdtMenuItem
2020-08-13 14:07:40 +02:00
//other
xb . cat ( IntelMaxValue ) ;
// UINT32 AudioVolume);
// boot.efi
2020-08-15 15:47:56 +02:00
checkOffset ( OptionsBits ) ;
2020-08-13 14:07:40 +02:00
xb . cat ( OptionsBits ) ;
xb . cat ( FlagsBits ) ;
xb . cat ( UIScale ) ;
xb . cat ( EFILoginHiDPI ) ;
xb . ncat ( & flagstate , sizeof ( flagstate ) ) ;
xb . ncat ( & pad37 , sizeof ( pad37 ) ) ;
xb . cat ( ArbProperties ) ;
// xb.cat(QuirksMask);
// xb.ncat(&pad38, sizeof(pad38));
// xb.cat(MaxSlide);
// if ( xb.size() != sizeof(old::SETTINGS_DATA) ) {
if ( xb . size ( ) ! = 3088 ) {
2020-08-15 15:47:56 +02:00
panic ( " SETTINGS_DATA::serialize wrong size \n " ) ;
2020-08-13 14:07:40 +02:00
}
return xb ;
}
2020-08-25 17:35:19 +02:00
//TagDict* regenerateConfigPlist_addDictToDict(TagDict* dict)
//{
// TagDict* tagDict = TagDict::getEmptyTag();
// dict->dictContent().AddReference(tagDict, true);
// return tagDict;
//}
//TagKey* regenerateConfigPlist_addKeyToDict(TagDict* dict, const XString8& key)
//{
// TagKey* tagKey = TagKey::getEmptyTag();
// tagKey->setKeyValue(key);
// dict->dictContent().AddReference(tagKey, true);
// return tagKey;
//}
//TagBool* regenerateConfigPlist_addBoolToDict(TagDict* dict, const bool value)
//{
// TagBool* tagBool = TagBool::getEmptyTag();
// tagBool->setBoolValue(value);
// dict->dictContent().AddReference(tagBool, true);
// return tagBool;
//}
//void regenerateConfigPlist_addKeyAndBoolToDict(TagDict* dict, const XString8& key, const bool value)
//{
// regenerateConfigPlist_addKeyToDict(dict, key);
// regenerateConfigPlist_addBoolToDict(dict, value);
//}
//
//void testConfigPlist()
//{
// TagDict* plist = TagDict::getEmptyTag();
// regenerateConfigPlist_addKeyToDict(plist, "ACPI"_XS8);
// TagDict* ACPIDict = regenerateConfigPlist_addDictToDict(plist);
// regenerateConfigPlist_addKeyAndBoolToDict(ACPIDict, "AutoMerge"_XS8, gSettings.AutoMerge);
// regenerateConfigPlist_addKeyToDict(ACPIDict, "DSDT"_XS8);
// TagDict* DSDTDict = regenerateConfigPlist_addDictToDict(ACPIDict);
// regenerateConfigPlist_addKeyToDict(DSDTDict, "Debug"_XS8);
// regenerateConfigPlist_addBoolToDict(DSDTDict, gSettings.KernelAndKextPatches.KPDebug);
//// regenerateConfigPlist_addKeyToDict(DSDTDict, "DropOEM_DSM"_XS8);
//// TagDict* DropOEM_DSMDict = regenerateConfigPlist_addDictToDict(DSDTDict);
// regenerateConfigPlist_addKeyToDict(DSDTDict, "Fixes"_XS8);
// TagDict* FixesDict = regenerateConfigPlist_addDictToDict(DSDTDict);
// for (size_t Index = 0; Index < sizeof(FixesConfig)/sizeof(FixesConfig[0]); Index++) {
// if ( gSettings.FixDsdt & FixesConfig[Index].bitData ) {
// regenerateConfigPlist_addKeyToDict(FixesDict, LString8(FixesConfig[Index].newName));
// regenerateConfigPlist_addBoolToDict(FixesDict, true);
// }
// }
// XString8 s;
// plist->sprintf(0, &s);
// MsgLog("%s\n", s.c_str());
//}
//
2020-09-23 15:47:47 +02:00
2021-02-06 18:16:46 +01:00
EFI_GUID nullUUID = { 0 , 0 , 0 , { 0 } } ;
2020-09-23 15:47:47 +02:00
const XString8 & SETTINGS_DATA : : getUUID ( )
{
if ( CustomUuid . notEmpty ( ) ) return CustomUuid ;
return SmUUID ;
}
const XString8 & SETTINGS_DATA : : getUUID ( EFI_GUID * uuid )
{
if ( CustomUuid . notEmpty ( ) ) {
EFI_STATUS Status = StrToGuidLE ( CustomUuid , uuid ) ;
if ( EFI_ERROR ( Status ) ) panic ( " CustomUuid(%s) is not valid " , CustomUuid . c_str ( ) ) ; // we panic, because it's a bug. Validity is checked when imported from settings
return CustomUuid ;
}
EFI_STATUS Status = StrToGuidLE ( SmUUID , uuid ) ;
if ( EFI_ERROR ( Status ) ) panic ( " CustomUuid(%s) is not valid " , CustomUuid . c_str ( ) ) ; // same as before
return SmUUID ;
}