2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
/// @file rEFIt_UEFI/Platform/DataHubCpu.c
|
|
|
|
///
|
|
|
|
/// VirtualBox CPU descriptors
|
|
|
|
///
|
|
|
|
/// VirtualBox CPU descriptors also used to set OS X-used NVRAM variables and DataHub data
|
|
|
|
///
|
|
|
|
|
|
|
|
// Copyright(C) 2009-2010 Oracle Corporation
|
|
|
|
//
|
|
|
|
// This file is part of VirtualBox Open Source Edition(OSE), as
|
|
|
|
// available from http://www.virtualbox.org. This file is free software;
|
|
|
|
// you can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
// General Public License(GPL) as published by the Free Software
|
|
|
|
// Foundation, in version 2 as it comes in the "COPYING" file of the
|
|
|
|
// VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
|
|
|
// hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
|
|
|
|
|
|
|
//
|
|
|
|
// CHANGELOG:
|
|
|
|
//
|
|
|
|
// 2019/06/08
|
|
|
|
// vector sigma
|
|
|
|
// don't inject REV, RBr and EPCI keys if gSettings.REV is zeroed
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
|
|
|
#define DEBUG_DH 1
|
|
|
|
#else
|
|
|
|
#define DEBUG_DH DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_DH == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_DH, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2021-02-06 18:16:46 +01:00
|
|
|
#include "../include/OSTypes.h"
|
2020-04-16 09:15:26 +02:00
|
|
|
#include "Nvram.h"
|
|
|
|
#include "platformdata.h"
|
|
|
|
#include "smbios.h"
|
|
|
|
#include "cpu.h"
|
2020-09-28 11:05:37 +02:00
|
|
|
#include "DataHubCpu.h"
|
2020-04-16 09:15:26 +02:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
#include <Guid/DataHubRecords.h>
|
|
|
|
|
|
|
|
#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
|
|
|
|
|
|
|
|
// gDataHub
|
|
|
|
/// A pointer to the DataHubProtocol
|
|
|
|
EFI_DATA_HUB_PROTOCOL *gDataHub;
|
|
|
|
|
|
|
|
EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {
|
|
|
|
EFI_PROCESSOR_SUBCLASS_VERSION, // Version
|
|
|
|
sizeof(EFI_SUBCLASS_TYPE1_HEADER), // Header Size
|
|
|
|
0, // Instance (initialize later)
|
|
|
|
EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance
|
|
|
|
0 // RecordType (initialize later)
|
|
|
|
};
|
|
|
|
|
|
|
|
// gDataHubPlatformGuid
|
|
|
|
/// The GUID of the DataHubProtocol
|
|
|
|
EFI_GUID gDataHubPlatformGuid = {
|
|
|
|
0x64517cc8, 0x6561, 0x4051, { 0xb0, 0x3c, 0x59, 0x64, 0xb6, 0x0f, 0x4c, 0x7a }
|
|
|
|
};
|
|
|
|
|
2019-09-12 12:37:33 +02:00
|
|
|
extern EFI_GUID gDataHubPlatformGuid;
|
2019-09-03 11:58:42 +02:00
|
|
|
extern APPLE_SMC_IO_PROTOCOL *gAppleSmc;
|
2019-09-12 12:37:33 +02:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
typedef union {
|
|
|
|
EFI_CPU_DATA_RECORD *DataRecord;
|
|
|
|
UINT8 *Raw;
|
|
|
|
} EFI_CPU_DATA_RECORD_BUFFER;
|
|
|
|
|
|
|
|
// PLATFORM_DATA
|
|
|
|
/// The struct passed to "LogDataHub" holing key and value to be added
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct {
|
|
|
|
EFI_SUBCLASS_TYPE1_HEADER Hdr; /// 0x48
|
|
|
|
UINT32 NameLen; /// 0x58 (in bytes)
|
|
|
|
UINT32 ValLen; /// 0x5c
|
|
|
|
UINT8 Data[1]; /// 0x60 Name Value
|
2020-08-15 15:47:56 +02:00
|
|
|
} PLATFORM_DATA_RECORD;
|
2019-09-03 11:58:42 +02:00
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
// CopyRecord
|
|
|
|
/// Copy the data provided in arguments into a PLATFORM_DATA buffer
|
|
|
|
///
|
|
|
|
/// @param Rec The buffer the data should be copied into
|
|
|
|
/// @param Name The value for the member "name"
|
|
|
|
/// @param Val The data the object should have
|
|
|
|
/// @param ValLen The length of the parameter "Val"
|
|
|
|
///
|
|
|
|
/// @return The size of the new PLATFORM_DATA object is returned
|
|
|
|
UINT32 EFIAPI
|
2020-08-15 15:47:56 +02:00
|
|
|
CopyRecord(IN PLATFORM_DATA_RECORD *Rec,
|
2019-09-03 11:58:42 +02:00
|
|
|
IN CONST CHAR16 *Name,
|
2020-10-03 19:02:31 +02:00
|
|
|
IN const void *Val,
|
2019-09-03 11:58:42 +02:00
|
|
|
IN UINT32 ValLen)
|
|
|
|
{
|
|
|
|
CopyMem(&Rec->Hdr, &mCpuDataRecordHeader, sizeof(EFI_SUBCLASS_TYPE1_HEADER));
|
|
|
|
Rec->NameLen = (UINT32)StrLen(Name) * sizeof(CHAR16);
|
|
|
|
Rec->ValLen = ValLen;
|
|
|
|
CopyMem(Rec->Data, Name, Rec->NameLen);
|
|
|
|
CopyMem(Rec->Data + Rec->NameLen, Val, ValLen);
|
|
|
|
|
|
|
|
return (sizeof(EFI_SUBCLASS_TYPE1_HEADER) + 8 + Rec->NameLen + Rec->ValLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogDataHub
|
|
|
|
/// Adds a key-value-pair to the DataHubProtocol
|
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
LogDataHub(IN EFI_GUID *TypeGuid,
|
2020-02-17 21:41:09 +01:00
|
|
|
IN CONST CHAR16 *Name,
|
2020-10-03 19:02:31 +02:00
|
|
|
IN const void *Data,
|
2020-08-15 15:47:56 +02:00
|
|
|
IN UINT32 DataSize)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
UINT32 RecordSize;
|
|
|
|
EFI_STATUS Status;
|
2020-08-15 15:47:56 +02:00
|
|
|
PLATFORM_DATA_RECORD *platform_data_record;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
platform_data_record = (PLATFORM_DATA_RECORD*)AllocatePool(sizeof(PLATFORM_DATA_RECORD) + DataSize + EFI_CPU_DATA_MAXIMUM_LENGTH);
|
|
|
|
if (platform_data_record == NULL) {
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
RecordSize = CopyRecord(platform_data_record, Name, Data, DataSize);
|
2019-09-03 11:58:42 +02:00
|
|
|
Status = gDataHub->LogData(gDataHub,
|
|
|
|
TypeGuid, // DataRecordGuid
|
|
|
|
&gDataHubPlatformGuid, // ProducerName (always)
|
|
|
|
EFI_DATA_RECORD_CLASS_DATA,
|
2020-08-15 15:47:56 +02:00
|
|
|
platform_data_record,
|
2019-09-03 11:58:42 +02:00
|
|
|
RecordSize);
|
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
FreePool(platform_data_record);
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
LogDataHubXString8(IN EFI_GUID *TypeGuid,
|
|
|
|
IN CONST CHAR16 *Name,
|
|
|
|
const XString8& s)
|
|
|
|
{
|
|
|
|
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) panic("LogDataHub s.length > MAX_UINT32");
|
|
|
|
return LogDataHub(TypeGuid, Name, (void*)s.c_str(), (UINT32)s.sizeInBytesIncludingTerminator());
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
LogDataHubXStringW(IN EFI_GUID *TypeGuid,
|
|
|
|
IN CONST CHAR16 *Name,
|
|
|
|
const XStringW& s)
|
|
|
|
{
|
|
|
|
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) panic("LogDataHub s.length > MAX_UINT32");
|
|
|
|
return LogDataHub(TypeGuid, Name, (void*)s.wc_str(), (UINT32)s.sizeInBytesIncludingTerminator());
|
|
|
|
}
|
2020-05-14 09:03:06 +02:00
|
|
|
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
// SetVariablesForOSX
|
2020-02-16 13:00:20 +01:00
|
|
|
/** Installs our runtime services overrides. */
|
|
|
|
/** Original runtime services. */
|
|
|
|
EFI_RUNTIME_SERVICES gOrgRS;
|
|
|
|
|
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
OvrSetVariable(
|
|
|
|
IN CHAR16 *VariableName,
|
|
|
|
IN EFI_GUID *VendorGuid,
|
|
|
|
IN UINT32 Attributes,
|
|
|
|
IN UINTN DataSize,
|
2020-10-03 19:02:31 +02:00
|
|
|
IN void *Data
|
2020-02-16 13:00:20 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN i;
|
|
|
|
|
2020-08-31 08:22:21 +02:00
|
|
|
for (i = 0; i < BlockRtVariableArray.size(); i++) {
|
|
|
|
if (!CompareGuid(&BlockRtVariableArray[i].VarGuid, VendorGuid)) {
|
2020-02-16 13:00:20 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-08-31 08:22:21 +02:00
|
|
|
if (BlockRtVariableArray[i].Name.isEmpty() || BlockRtVariableArray[i].Name[0] == L'*' || BlockRtVariableArray[i].Name == LStringW(VariableName) ) {
|
2020-02-16 13:00:20 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Status = gOrgRS.SetVariable(VariableName, VendorGuid, Attributes, DataSize, Data);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
OvrRuntimeServices(EFI_RUNTIME_SERVICES *RS)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
CopyMem(&gOrgRS, RS, sizeof(EFI_RUNTIME_SERVICES));
|
2020-02-17 21:41:09 +01:00
|
|
|
RS->SetVariable = (EFI_SET_VARIABLE)OvrSetVariable;
|
2020-02-16 13:00:20 +01:00
|
|
|
RS->Hdr.CRC32 = 0;
|
|
|
|
Status = gBS->CalculateCrc32(RS, RS->Hdr.HeaderSize, &RS->Hdr.CRC32);
|
|
|
|
return Status;
|
2019-09-12 12:37:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
/// Sets the volatile and non-volatile variables used by OS X
|
|
|
|
EFI_STATUS EFIAPI
|
|
|
|
SetVariablesForOSX(LOADER_ENTRY *Entry)
|
|
|
|
{
|
|
|
|
// The variable names used should be made global constants to prevent them being allocated multiple times
|
|
|
|
|
|
|
|
UINT32 Attributes;
|
|
|
|
UINT32 Color;
|
2020-02-17 21:41:09 +01:00
|
|
|
CONST CHAR8 *None;
|
|
|
|
CONST CHAR8 *NvidiaWebValue;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-02-17 21:41:09 +01:00
|
|
|
CONST CHAR16 *KbdPrevLang;
|
2019-09-03 11:58:42 +02:00
|
|
|
UINTN LangLen;
|
2020-10-03 19:02:31 +02:00
|
|
|
void *OldData;
|
2020-11-12 22:25:56 +01:00
|
|
|
// UINT64 os_version = AsciiOSVersionToUint64(Entry->OSVersion);
|
2019-09-03 11:58:42 +02:00
|
|
|
CHAR8 *PlatformLang;
|
|
|
|
|
2020-09-23 15:47:47 +02:00
|
|
|
EFI_GUID uuid;
|
|
|
|
gSettings.getUUID(&uuid);
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
// firmware Variables
|
|
|
|
//
|
2020-08-31 08:22:21 +02:00
|
|
|
if (BlockRtVariableArray.size() > 0) {
|
2020-02-16 13:00:20 +01:00
|
|
|
OvrRuntimeServices(gRT);
|
2019-09-12 12:37:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
// As found on a real Mac, the system-id variable solely has the BS flag
|
|
|
|
SetNvramVariable(L"system-id",
|
|
|
|
&gEfiAppleNvramGuid,
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
2020-09-23 15:47:47 +02:00
|
|
|
sizeof(uuid),
|
|
|
|
&uuid);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
|
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
if (gSettings.RtMLB.notEmpty()) {
|
|
|
|
if ( gSettings.RtMLB.length() != 17 ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
DBG("** Warning: Your MLB is not suitable for iMessage(must be 17 chars long) !\n");
|
|
|
|
}
|
|
|
|
|
2020-08-15 15:47:56 +02:00
|
|
|
SetNvramXString8(L"MLB",
|
2019-09-03 11:58:42 +02:00
|
|
|
&gEfiAppleNvramGuid,
|
|
|
|
Attributes,
|
|
|
|
gSettings.RtMLB);
|
|
|
|
}
|
|
|
|
|
2020-09-23 15:47:47 +02:00
|
|
|
if (gSettings.RtROM.notEmpty()) {
|
2019-09-03 11:58:42 +02:00
|
|
|
SetNvramVariable(L"ROM",
|
|
|
|
&gEfiAppleNvramGuid,
|
|
|
|
Attributes,
|
2020-09-23 15:47:47 +02:00
|
|
|
gSettings.RtROM.size(),
|
|
|
|
gSettings.RtROM.vdata());
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetNvramVariable(L"FirmwareFeatures",
|
|
|
|
&gEfiAppleNvramGuid,
|
|
|
|
Attributes,
|
|
|
|
sizeof(gFwFeatures),
|
|
|
|
&gFwFeatures);
|
|
|
|
|
|
|
|
// Download-Fritz: Should be added to SMBIOS or at least to some other config section
|
|
|
|
AddNvramVariable(L"FirmwareFeaturesMask",
|
|
|
|
&gEfiAppleNvramGuid,
|
|
|
|
Attributes,
|
|
|
|
sizeof(gFwFeaturesMask),
|
|
|
|
&gFwFeaturesMask);
|
|
|
|
|
|
|
|
// HW_MLB and HW_ROM are also around on some Macs with the same values as MLB and ROM
|
2020-08-15 15:47:56 +02:00
|
|
|
AddNvramXString8(L"HW_BID", &gEfiAppleNvramGuid, Attributes, gSettings.BoardNumber);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OS X non-volatile Variables
|
|
|
|
//
|
|
|
|
|
|
|
|
// note: some gEfiAppleBootGuid vars present in nvram.plist are already set by PutNvramPlistToRtVars()
|
|
|
|
// we should think how to handle those vars from nvram.plist and ones set here from gSettings
|
|
|
|
|
|
|
|
if ((gFirmwareClover && gDriversFlags.EmuVariableLoaded) || gSettings.KbdPrevLang) {
|
|
|
|
// using AddNvramVariable content instead of calling the function to do LangLen calculation only when necessary
|
|
|
|
// Do not mess with prev-lang:kbd on UEFI systems without NVRAM emulation; it's OS X's business
|
|
|
|
KbdPrevLang = L"prev-lang:kbd";
|
2019-12-27 16:10:42 +01:00
|
|
|
OldData = (__typeof__(OldData))GetNvramVariable(KbdPrevLang, &gEfiAppleBootGuid, NULL, NULL);
|
2020-08-17 21:40:52 +02:00
|
|
|
if (OldData == NULL) {
|
|
|
|
gSettings.Language.trim();
|
|
|
|
SetNvramXString8(KbdPrevLang, &gEfiAppleBootGuid, Attributes, gSettings.Language);
|
|
|
|
} else {
|
|
|
|
FreePool(OldData);
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
|
|
|
Attributes |= EFI_VARIABLE_NON_VOLATILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#define EFI_PLATFORM_LANG_VARIABLE_NAME L"PlatformLang"
|
2019-12-27 16:10:42 +01:00
|
|
|
PlatformLang = (__typeof__(PlatformLang))GetNvramVariable(EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, NULL, NULL);
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
// On some platforms with missing gEfiUnicodeCollation2ProtocolGuid EFI_PLATFORM_LANG_VARIABLE_NAME is set
|
|
|
|
// to the value different from "en-...". This is not going to work with our driver UEFI Shell load failures.
|
|
|
|
// We did not overwrite EFI_PLATFORM_LANG_VARIABLE_NAME, but it uses some other language.
|
|
|
|
//
|
|
|
|
// if (!PlatformLang || AsciiStrnCmp (PlatformLang, "en-", 3)) {
|
|
|
|
if (!PlatformLang) {
|
|
|
|
SetNvramVariable(EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid,
|
|
|
|
Attributes,
|
|
|
|
6, "en-US");
|
|
|
|
}
|
|
|
|
if (PlatformLang) {
|
|
|
|
FreePool(PlatformLang);
|
|
|
|
}
|
|
|
|
|
|
|
|
None = "none";
|
2020-10-03 19:02:31 +02:00
|
|
|
AddNvramVariable(L"security-mode", &gEfiAppleBootGuid, Attributes, 5, (void*)None);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
// we should have two UUID: platform and system
|
|
|
|
// NO! Only Platform is the best solution
|
2020-09-23 15:47:47 +02:00
|
|
|
if (!gSettings.ShouldInjectSystemID()) {
|
|
|
|
if (gSettings.SmUUID.notEmpty()) {
|
|
|
|
SetNvramVariable(L"platform-uuid", &gEfiAppleBootGuid, Attributes, sizeof(uuid), &uuid);
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
2020-09-23 15:47:47 +02:00
|
|
|
AddNvramVariable(L"platform-uuid", &gEfiAppleBootGuid, Attributes, sizeof(uuid), &uuid);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download-Fritz: Do not mess with BacklightLevel; it's OS X's business
|
|
|
|
if (gMobile) {
|
|
|
|
if (gSettings.BacklightLevelConfig) {
|
|
|
|
SetNvramVariable(L"backlight-level", &gEfiAppleBootGuid, Attributes, sizeof(gSettings.BacklightLevel), &gSettings.BacklightLevel);
|
|
|
|
} else {
|
|
|
|
AddNvramVariable(L"backlight-level", &gEfiAppleBootGuid, Attributes, sizeof(gSettings.BacklightLevel), &gSettings.BacklightLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.DefaultBackgroundColor == 0x80000000) {
|
|
|
|
DeleteNvramVariable(L"DefaultBackgroundColor", &gEfiAppleNvramGuid);
|
|
|
|
} else {
|
|
|
|
UINT16 ActualDensity = 0xE1;
|
|
|
|
UINT16 DensityThreshold = 0x96;
|
|
|
|
UINT64 ConfigStatus = 0;
|
|
|
|
Color = gSettings.DefaultBackgroundColor;
|
2020-06-18 18:08:00 +02:00
|
|
|
DBG("set DefaultBackgroundColor=0x%x\n", Color);
|
|
|
|
SetNvramVariable(L"DefaultBackgroundColor", &gEfiAppleNvramGuid, Attributes, 4, &Color);
|
2019-09-03 11:58:42 +02:00
|
|
|
// add some UI variables
|
2020-06-18 18:08:00 +02:00
|
|
|
SetNvramVariable(L"ActualDensity", &gEfiAppleBootGuid, Attributes, 2, &ActualDensity);
|
|
|
|
SetNvramVariable(L"DensityThreshold", &gEfiAppleBootGuid, Attributes, 2, &DensityThreshold);
|
|
|
|
SetNvramVariable(L"gfx-saved-config-restore-status", &gEfiAppleNvramGuid, Attributes, 8, &ConfigStatus);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.UIScale == 0x80000000) {
|
|
|
|
DeleteNvramVariable(L"UIScale", &gEfiAppleNvramGuid);
|
|
|
|
} else {
|
|
|
|
SetNvramVariable(L"UIScale", &gEfiAppleNvramGuid, Attributes, 1, &gSettings.UIScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.EFILoginHiDPI == 0x80000000) {
|
|
|
|
DeleteNvramVariable(L"EFILoginHiDPI", &gEfiAppleBootGuid);
|
|
|
|
} else {
|
|
|
|
SetNvramVariable(L"EFILoginHiDPI", &gEfiAppleBootGuid, Attributes, 4, &gSettings.EFILoginHiDPI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ->GetVariable(flagstate, gEfiAppleBootGuid, 0/0, 20, 10FE110) = Not Found
|
|
|
|
if (gSettings.flagstate[3] == 0x80) {
|
|
|
|
DeleteNvramVariable(L"flagstate", &gEfiAppleBootGuid);
|
|
|
|
} else {
|
|
|
|
SetNvramVariable(L"flagstate", &gEfiAppleBootGuid, Attributes, 32, &gSettings.flagstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hack for recovery by Asgorath
|
|
|
|
if (gSettings.CsrActiveConfig != 0xFFFF) {
|
|
|
|
SetNvramVariable(L"csr-active-config", &gEfiAppleBootGuid, Attributes, sizeof(gSettings.CsrActiveConfig), &gSettings.CsrActiveConfig);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (gSettings.BooterConfig != 0) {
|
|
|
|
SetNvramVariable(L"bootercfg", &gEfiAppleBootGuid, Attributes, sizeof(gSettings.BooterConfig), &gSettings.BooterConfig);
|
|
|
|
}
|
|
|
|
*/
|
2020-08-15 15:47:56 +02:00
|
|
|
if ( gSettings.BooterCfgStr.notEmpty() ) {
|
|
|
|
SetNvramXString8(L"bootercfg", &gEfiAppleBootGuid, Attributes, gSettings.BooterCfgStr);
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
|
|
|
DeleteNvramVariable(L"bootercfg", &gEfiAppleBootGuid);
|
|
|
|
}
|
|
|
|
if (gSettings.NvidiaWeb) {
|
|
|
|
NvidiaWebValue = "1";
|
2020-10-03 19:02:31 +02:00
|
|
|
SetNvramVariable(L"nvda_drv", &gEfiAppleBootGuid, Attributes, 2, (void*)NvidiaWebValue);
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
|
|
|
DeleteNvramVariable(L"nvda_drv", &gEfiAppleBootGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gDriversFlags.AptioMemFixLoaded) {
|
|
|
|
DeleteNvramVariable(L"recovery-boot-mode", &gEfiAppleBootGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for AptioFix2Drv loaded to store efi-boot-device for special boot
|
|
|
|
if (gDriversFlags.AptioFix2Loaded || gDriversFlags.AptioFixLoaded ||
|
|
|
|
gDriversFlags.AptioFix3Loaded || gDriversFlags.AptioMemFixLoaded) {
|
|
|
|
EFI_STATUS Status;
|
|
|
|
REFIT_VOLUME *Volume = Entry->Volume;
|
2020-09-28 17:57:50 +02:00
|
|
|
const EFI_DEVICE_PATH_PROTOCOL *DevicePath = Volume->DevicePath;
|
2019-09-03 11:58:42 +02:00
|
|
|
// We need to remember from which device we boot, to make silence boot while special recovery boot
|
|
|
|
Status = gRT->SetVariable(L"specialbootdevice", &gEfiAppleBootGuid,
|
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
|
GetDevicePathSize(DevicePath), (UINT8 *)DevicePath);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
DBG("can't set specialbootdevice!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sherlocks: to fix "OSInstall.mpkg appears to be missing or damaged" in 10.13+, we should remove this variables.
|
|
|
|
if (Entry->LoaderType == OSTYPE_OSX_INSTALLER) {
|
2021-01-31 10:50:23 +01:00
|
|
|
if (Entry->macOSVersion.isEmpty() || Entry->macOSVersion > MacOsVersion("10.12"_XS8)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
DeleteNvramVariable(L"install-product-url", &gEfiAppleBootGuid);
|
|
|
|
DeleteNvramVariable(L"previous-system-uuid", &gEfiAppleBootGuid);
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 21:51:07 +02:00
|
|
|
|
|
|
|
//one more variable can be set for 10.15.4
|
|
|
|
//sudo nvram wake-failure=%00%00%00%00%00
|
2020-04-22 06:42:10 +02:00
|
|
|
LangLen = 0;
|
|
|
|
AddNvramVariable(L"wake-failure", &gEfiAppleBootGuid, Attributes, 5, &LangLen);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
AddSMCkey(SMC_KEY Key, SMC_DATA_SIZE Size, SMC_KEY_TYPE Type, SMC_DATA *Data)
|
|
|
|
{
|
|
|
|
if (gAppleSmc && (gAppleSmc->Signature == NON_APPLE_SMC_SIGNATURE)) {
|
|
|
|
gAppleSmc->SmcAddKey(gAppleSmc, Key, Size, Type, 0xC0);
|
|
|
|
gAppleSmc->SmcWriteValue(gAppleSmc, Key, Size, Data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetupDataForOSX
|
|
|
|
/// Sets the DataHub data used by OS X
|
2020-10-03 19:02:31 +02:00
|
|
|
void EFIAPI
|
2019-09-03 11:58:42 +02:00
|
|
|
SetupDataForOSX(BOOLEAN Hibernate)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
UINT32 DevPathSupportedVal;
|
|
|
|
UINT64 FrontSideBus;
|
|
|
|
UINT64 CpuSpeed;
|
|
|
|
UINT64 TscFrequency;
|
|
|
|
UINT64 ARTFrequency;
|
|
|
|
UINTN Revision;
|
|
|
|
UINT16 Zero = 0;
|
|
|
|
BOOLEAN isRevLess = (gSettings.REV[0] == 0 &&
|
|
|
|
gSettings.REV[1] == 0 &&
|
|
|
|
gSettings.REV[2] == 0 &&
|
|
|
|
gSettings.REV[3] == 0 &&
|
|
|
|
gSettings.REV[4] == 0 &&
|
|
|
|
gSettings.REV[5] == 0);
|
|
|
|
|
|
|
|
Revision = StrDecimalToUintn(gFirmwareRevision);
|
|
|
|
|
|
|
|
// fool proof
|
|
|
|
FrontSideBus = gCPUStructure.FSBFrequency;
|
|
|
|
if ((FrontSideBus < (50 * Mega)) || (FrontSideBus > (1000 * Mega))) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("Wrong FrontSideBus=%llu, set to 100MHz\n", FrontSideBus);
|
2019-09-03 11:58:42 +02:00
|
|
|
FrontSideBus = 100 * Mega;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.QEMU) {
|
|
|
|
FrontSideBus = gCPUStructure.TSCFrequency;
|
|
|
|
switch (gCPUStructure.Model) {
|
|
|
|
case CPU_MODEL_DOTHAN:
|
|
|
|
case CPU_MODEL_YONAH:
|
|
|
|
case CPU_MODEL_MEROM:
|
|
|
|
case CPU_MODEL_PENRYN:
|
|
|
|
FrontSideBus = DivU64x32(FrontSideBus, 4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("Using QEMU FrontSideBus=%llull\n", FrontSideBus);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save values into gSettings for the genconfig aim
|
2021-02-06 18:16:46 +01:00
|
|
|
gSettings.BusSpeed = (UINT32)DivU64x32(FrontSideBus, Kilo);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
CpuSpeed = gCPUStructure.CPUFrequency;
|
|
|
|
gSettings.CpuFreqMHz = (UINT32)DivU64x32(CpuSpeed, Mega);
|
|
|
|
|
|
|
|
// Locate DataHub Protocol
|
2020-10-03 19:02:31 +02:00
|
|
|
Status = gBS->LocateProtocol(&gEfiDataHubProtocolGuid, NULL, (void**)&gDataHub);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2020-08-09 17:55:30 +02:00
|
|
|
XStringW ProductName;
|
|
|
|
ProductName.takeValueFrom(gSettings.ProductName);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-09 17:55:30 +02:00
|
|
|
XStringW SerialNumber;
|
|
|
|
SerialNumber.takeValueFrom(gSettings.SerialNr);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"FSBFrequency", &FrontSideBus, sizeof(UINT64));
|
|
|
|
|
|
|
|
if (gCPUStructure.ARTFrequency && gSettings.UseARTFreq) {
|
|
|
|
ARTFrequency = gCPUStructure.ARTFrequency;
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"ARTFrequency", &ARTFrequency, sizeof(UINT64));
|
|
|
|
}
|
|
|
|
|
|
|
|
TscFrequency = 0; //gCPUStructure.TSCFrequency;
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"InitialTSC", &TscFrequency, sizeof(UINT64));
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"CPUFrequency", &CpuSpeed, sizeof(UINT64));
|
|
|
|
|
|
|
|
//gSettings.BoardNumber
|
2020-08-15 15:47:56 +02:00
|
|
|
LogDataHubXString8(&gEfiMiscSubClassGuid, L"board-id", gSettings.BoardNumber);
|
2019-09-03 11:58:42 +02:00
|
|
|
TscFrequency++;
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"board-rev", &TscFrequency, 1);
|
|
|
|
|
|
|
|
DevPathSupportedVal = 1;
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"DevicePathsSupported", &DevPathSupportedVal, sizeof(UINT32));
|
2020-08-15 15:47:56 +02:00
|
|
|
LogDataHubXStringW(&gEfiMiscSubClassGuid, L"Model", ProductName);
|
|
|
|
LogDataHubXStringW(&gEfiMiscSubClassGuid, L"SystemSerialNumber", SerialNumber);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-09-23 15:47:47 +02:00
|
|
|
if (gSettings.ShouldInjectSystemID()) {
|
|
|
|
EFI_GUID uuid;
|
|
|
|
gSettings.getUUID(&uuid);
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"system-id", &uuid, sizeof(uuid));
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LogDataHub(&gEfiProcessorSubClassGuid, L"clovergui-revision", &Revision, sizeof(UINT32));
|
|
|
|
|
|
|
|
// collect info about real hardware
|
2020-08-15 15:47:56 +02:00
|
|
|
LogDataHubXString8(&gEfiMiscSubClassGuid, L"OEMVendor", gSettings.OEMVendor);
|
|
|
|
LogDataHubXString8(&gEfiMiscSubClassGuid, L"OEMProduct", gSettings.OEMProduct);
|
|
|
|
LogDataHubXString8(&gEfiMiscSubClassGuid, L"OEMBoard", gSettings.OEMBoard);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
// SMC helper
|
|
|
|
if (!isRevLess) {
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"RBr", &gSettings.RBr, 8);
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"EPCI", &gSettings.EPCI, 4);
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"REV", &gSettings.REV, 6);
|
|
|
|
}
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"RPlt", &gSettings.RPlt, 8);
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"BEMB", &gSettings.Mobile, 1);
|
|
|
|
|
|
|
|
// all current settings
|
2020-08-13 14:07:40 +02:00
|
|
|
XBuffer<UINT8> xb = gSettings.serialize();
|
|
|
|
LogDataHub(&gEfiMiscSubClassGuid, L"Settings", xb.data(), (UINT32)xb.size());
|
2020-11-18 22:49:02 +01:00
|
|
|
}else{
|
|
|
|
MsgLog("DataHub protocol not located. Smbios not send to datahub\n");
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
if (!gAppleSmc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!isRevLess) {
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('R','B','r',' '), 8, SmcKeyTypeCh8, (SMC_DATA *)&gSettings.RBr);
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('E','P','C','I'), 4, SmcKeyTypeUint32, (SMC_DATA *)&gSettings.EPCI);
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('R','E','V',' '), 6, SmcKeyTypeCh8, (SMC_DATA *)&gSettings.REV);
|
|
|
|
}
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('R','P','l','t'), 8, SmcKeyTypeCh8, (SMC_DATA *)&gSettings.RPlt);
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('B','E','M','B'), 1, SmcKeyTypeFlag, (SMC_DATA *)&gSettings.Mobile);
|
|
|
|
//laptop battery keys will be better to import from nvram.plist or read from ACPI(?)
|
|
|
|
//they are needed for FileVault2 who want to draw battery status
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('B','A','T','P'), 1, SmcKeyTypeFlag, (SMC_DATA *)&Zero); //isBatteryPowered
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('B','N','u','m'), 1, SmcKeyTypeUint8, (SMC_DATA *)&gSettings.Mobile); // Num Batteries
|
|
|
|
if (gSettings.Mobile) {
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('B','B','I','N'), 1, SmcKeyTypeUint8, (SMC_DATA *)&gSettings.Mobile); //Battery inserted
|
|
|
|
}
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('M','S','T','c'), 1, SmcKeyTypeUint8, (SMC_DATA *)&Zero); // CPU Plimit
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('M','S','A','c'), 2, SmcKeyTypeUint16, (SMC_DATA *)&Zero);// GPU Plimit
|
|
|
|
// AddSMCkey(SMC_MAKE_KEY('M','S','L','D'), 1, SmcKeyTypeUint8, (SMC_DATA *)&Zero); //isLidClosed
|
2021-02-02 10:02:21 +01:00
|
|
|
Zero = Hibernate?((ResumeFromCoreStorage||gSettings.Boot.HibernationFixup)?25:29):0;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('M','S','W','r'), 1, SmcKeyTypeUint8, (SMC_DATA *)&Zero);
|
|
|
|
Zero = 1;
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('M','S','F','W'), 2, SmcKeyTypeUint8, (SMC_DATA *)&Zero);
|
|
|
|
Zero = 0x300;
|
|
|
|
AddSMCkey(SMC_MAKE_KEY('M','S','P','S'), 2, SmcKeyTypeUint16, (SMC_DATA *)&Zero);
|
|
|
|
}
|