├── .gitignore ├── Include └── Protocol │ └── OcQuirks.h ├── LICENSE ├── OcQuirks.dsc ├── OcQuirks.plist ├── Platform └── OcQuirks │ ├── OcQuirks.c │ └── OcQuirks.inf ├── README.md └── macbuild.tool /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | Binaries/ 3 | UDK/ 4 | -------------------------------------------------------------------------------- /Include/Protocol/OcQuirks.h: -------------------------------------------------------------------------------- 1 | #define OCQUIRKS_PROTOCOL_REVISION 24 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, ReddestDream 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /OcQuirks.dsc: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Copyright (C) 2017, vit9696. All rights reserved.
3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | # 6 | # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | # 8 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | # 10 | # 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | # 14 | ## 15 | 16 | [Defines] 17 | PLATFORM_NAME = OcQuirks 18 | PLATFORM_GUID = 4FBFC810-9D3C-4BF3-ABF5-89A793C235B1 19 | PLATFORM_VERSION = 1.0 20 | SUPPORTED_ARCHITECTURES = X64 21 | BUILD_TARGETS = RELEASE|DEBUG|NOOPT 22 | SKUID_IDENTIFIER = DEFAULT 23 | DSC_SPECIFICATION = 0x00010006 24 | 25 | [LibraryClasses] 26 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 27 | BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf 28 | DebugLib|OpenCorePkg/Library/OcDebugLogLib/OcDebugLogLib.inf 29 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 30 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 31 | FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf 32 | FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf 33 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 34 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 35 | OcAfterBootCompatLib|OpenCorePkg/Library/OcAfterBootCompatLib/OcAfterBootCompatLib.inf 36 | OcApfsLib|OpenCorePkg/Library/OcApfsLib/OcApfsLib.inf 37 | OcAppleBootPolicyLib|OpenCorePkg/Library/OcAppleBootPolicyLib/OcAppleBootPolicyLib.inf 38 | OcAppleChunklistLib|OpenCorePkg/Library/OcAppleChunklistLib/OcAppleChunklistLib.inf 39 | OcBootManagementLib|OpenCorePkg/Library/OcBootManagementLib/OcBootManagementLib.inf 40 | OcAppleDiskImageLib|OpenCorePkg/Library/OcAppleDiskImageLib/OcAppleDiskImageLib.inf 41 | OcAppleKeysLib|OpenCorePkg/Library/OcAppleKeysLib/OcAppleKeysLib.inf 42 | OcAppleKeyMapLib|OpenCorePkg/Library/OcAppleKeyMapLib/OcAppleKeyMapLib.inf 43 | OcAppleRamDiskLib|OpenCorePkg/Library/OcAppleRamDiskLib/OcAppleRamDiskLib.inf 44 | OcAppleSecureBootLib|OpenCorePkg/Library/OcAppleSecureBootLib/OcAppleSecureBootLib.inf 45 | OcAppleImageVerificationLib|OpenCorePkg/Library/OcAppleImageVerificationLib/OcAppleImageVerificationLib.inf 46 | OcCompressionLib|OpenCorePkg/Library/OcCompressionLib/OcCompressionLib.inf 47 | OcCpuLib|OpenCorePkg/Library/OcCpuLib/OcCpuLib.inf 48 | OcCryptoLib|OpenCorePkg/Library/OcCryptoLib/OcCryptoLib.inf 49 | OcDataHubLib|OpenCorePkg/Library/OcDataHubLib/OcDataHubLib.inf 50 | OcDevicePathLib|OpenCorePkg/Library/OcDevicePathLib/OcDevicePathLib.inf 51 | OcDeviceTreeLib|OpenCorePkg/Library/OcDeviceTreeLib/OcDeviceTreeLib.inf 52 | OcDriverConnectionLib|OpenCorePkg/Library/OcDriverConnectionLib/OcDriverConnectionLib.inf 53 | OcFileLib|OpenCorePkg/Library/OcFileLib/OcFileLib.inf 54 | OcGuardLib|OpenCorePkg/Library/OcGuardLib/OcGuardLib.inf 55 | OcMachoLib|OpenCorePkg/Library/OcMachoLib/OcMachoLib.inf 56 | OcMemoryLib|OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf 57 | OcMiscLib|OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf 58 | OcOSInfoLib|OpenCorePkg/Library/OcOSInfoLib/OcOSInfoLib.inf 59 | OcPeCoffLib|OpenCorePkg/Library/OcPeCoffLib/OcPeCoffLib.inf 60 | OcRngLib|OpenCorePkg/Library/OcRngLib/OcRngLib.inf 61 | OcRtcLib|OpenCorePkg/Library/OcRtcLib/OcRtcLib.inf 62 | OcStringLib|OpenCorePkg/Library/OcStringLib/OcStringLib.inf 63 | TimerLib|OpenCorePkg/Library/OcTimerLib/OcTimerLib.inf 64 | OcTemplateLib|OpenCorePkg/Library/OcTemplateLib/OcTemplateLib.inf 65 | OcSerializeLib|OpenCorePkg/Library/OcSerializeLib/OcSerializeLib.inf 66 | OcStorageLib|OpenCorePkg/Library/OcStorageLib/OcStorageLib.inf 67 | OcXmlLib|OpenCorePkg/Library/OcXmlLib/OcXmlLib.inf 68 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 69 | PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf 70 | PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf 71 | PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf 72 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 73 | SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf 74 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 75 | UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 76 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 77 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 78 | OcConsoleLib|OpenCorePkg/Library/OcConsoleLib/OcConsoleLib.inf 79 | MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf 80 | CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf 81 | 82 | [Components] 83 | OcQuirks/Platform/OcQuirks/OcQuirks.inf 84 | OpenCorePkg/Platform/OpenRuntime/OpenRuntime.inf 85 | 86 | [PcdsFixedAtBuild] 87 | gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|0 88 | !if $(TARGET) == RELEASE 89 | # DEBUG_PRINT_ENABLED 90 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|2 91 | # DEBUG_ERROR | DEBUG_WARN 92 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000002 93 | gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel|0x80000002 94 | !else 95 | # DEBUG_ASSERT_ENABLED | DEBUG_PRINT_ENABLED | DEBUG_CODE_ENABLED | CLEAR_MEMORY_ENABLED | ASSERT_DEADLOOP_ENABLED 96 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f 97 | # DEBUG_ERROR | DEBUG_WARN | DEBUG_INFO 98 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000042 99 | gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel|0x80000042 100 | !endif 101 | 102 | [BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER] 103 | GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000 104 | XCODE:*_*_*_DLINK_FLAGS = -seg1addr 0x1000 -segalign 0x1000 105 | XCODE:*_*_*_MTOC_FLAGS = -align 0x1000 106 | CLANGPDB:*_*_*_DLINK_FLAGS = /ALIGN:4096 107 | 108 | [BuildOptions] 109 | 110 | GCC:DEBUG_*_*_CC_FLAGS = -D OC_TARGET_DEBUG=1 111 | GCC:NOOPT_*_*_CC_FLAGS = -D OC_TARGET_NOOPT=1 112 | MSFT:DEBUG_*_*_CC_FLAGS = -D OC_TARGET_DEBUG=1 113 | MSFT:NOOPT_*_*_CC_FLAGS = -D OC_TARGET_NOOPT=1 114 | XCODE:DEBUG_*_*_CC_FLAGS = -D OC_TARGET_DEBUG=1 115 | XCODE:NOOPT_*_*_CC_FLAGS = -D OC_TARGET_NOOPT=1 116 | XCODE:RELEASE_*_*_CC_FLAGS = -D OC_TARGET_RELEASE=1 -Oz -flto 117 | -------------------------------------------------------------------------------- /OcQuirks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AvoidRuntimeDefrag 6 | 7 | DevirtualiseMmio 8 | 9 | DisableSingleUser 10 | 11 | DisableVariableWrite 12 | 13 | DiscardHibernateMap 14 | 15 | EnableSafeModeSlide 16 | 17 | EnableWriteUnprotector 18 | 19 | ForceExitBootServices 20 | 21 | MmioWhitelist 22 | 23 | ProtectMemoryRegions 24 | 25 | ProtectSecureBoot 26 | 27 | ProtectUefiServices 28 | 29 | ProvideConsoleGopEnable 30 | 31 | ProvideCustomSlide 32 | 33 | ProvideMaxSlide 34 | 0 35 | RebuildAppleMemoryMap 36 | 37 | SetupVirtualMap 38 | 39 | SignalAppleOS 40 | 41 | SyncRuntimePermissions 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Platform/OcQuirks/OcQuirks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #define ROOT_PATH L"EFI\\CLOVER" 13 | #define CONFIG_PATH L"drivers\\UEFI\\OcQuirks.plist" 14 | 15 | #define MAX_DATA_SIZE 10000 16 | 17 | #define OC_MMIO_WL_STRUCT_FIELDS(_, __) \ 18 | _(BOOLEAN , Enabled , , FALSE , ()) \ 19 | _(UINT64 , Address , , 0 , ()) \ 20 | _(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) 21 | OC_DECLARE (OC_MMIO_WL_STRUCT) 22 | 23 | #define OC_MMIO_WL_ARRAY_FIELDS(_, __) \ 24 | OC_ARRAY (OC_MMIO_WL_STRUCT, _, __) 25 | OC_DECLARE (OC_MMIO_WL_ARRAY) 26 | 27 | #define OC_QUIRKS_FIELDS(_, __) \ 28 | _(BOOLEAN , AvoidRuntimeDefrag , , TRUE ,()) \ 29 | _(BOOLEAN , DevirtualiseMmio , , FALSE ,()) \ 30 | _(BOOLEAN , DisableSingleUser , , FALSE ,()) \ 31 | _(BOOLEAN , DisableVariableWrite , , FALSE ,()) \ 32 | _(BOOLEAN , DiscardHibernateMap , , FALSE ,()) \ 33 | _(BOOLEAN , EnableSafeModeSlide , , TRUE ,()) \ 34 | _(BOOLEAN , EnableWriteUnprotector , , FALSE ,()) \ 35 | _(BOOLEAN , ForceExitBootServices , , TRUE ,()) \ 36 | _(OC_MMIO_WL_ARRAY , MmioWhitelist , , OC_CONSTR2 (OC_MMIO_WL_ARRAY, _, __) , OC_DESTR (OC_MMIO_WL_ARRAY)) \ 37 | _(BOOLEAN , ProtectMemoryRegions , , FALSE ,()) \ 38 | _(BOOLEAN , ProtectSecureBoot , , FALSE ,()) \ 39 | _(BOOLEAN , ProtectUefiServices , , FALSE ,()) \ 40 | _(BOOLEAN , ProvideConsoleGopEnable , , TRUE ,()) \ 41 | _(UINT8 , ProvideMaxSlide , , 0 ,()) \ 42 | _(BOOLEAN , ProvideCustomSlide , , TRUE ,()) \ 43 | _(BOOLEAN , RebuildAppleMemoryMap , , TRUE ,()) \ 44 | _(BOOLEAN , SetupVirtualMap , , TRUE ,()) \ 45 | _(BOOLEAN , SignalAppleOS , , FALSE ,()) \ 46 | _(BOOLEAN , SyncRuntimePermissions , , TRUE ,()) 47 | 48 | OC_DECLARE (OC_QUIRKS) 49 | 50 | OC_STRUCTORS (OC_MMIO_WL_STRUCT, ()) 51 | OC_ARRAY_STRUCTORS (OC_MMIO_WL_ARRAY) 52 | OC_STRUCTORS (OC_QUIRKS, ()) 53 | 54 | STATIC 55 | OC_SCHEMA 56 | mMmioWhitelistEntry[] = { 57 | OC_SCHEMA_INTEGER_IN ("Address", OC_MMIO_WL_STRUCT, Address), 58 | OC_SCHEMA_STRING_IN ("Comment", OC_MMIO_WL_STRUCT, Comment), 59 | OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_MMIO_WL_STRUCT, Enabled), 60 | }; 61 | 62 | STATIC 63 | OC_SCHEMA 64 | mMmioWhitelist = OC_SCHEMA_DICT (NULL, mMmioWhitelistEntry); 65 | 66 | STATIC 67 | OC_SCHEMA 68 | mConfigNodes[] = { 69 | OC_SCHEMA_BOOLEAN_IN ("AvoidRuntimeDefrag" , OC_QUIRKS, AvoidRuntimeDefrag), 70 | OC_SCHEMA_BOOLEAN_IN ("DevirtualiseMmio" , OC_QUIRKS, DevirtualiseMmio), 71 | OC_SCHEMA_BOOLEAN_IN ("DisableSingleUser" , OC_QUIRKS, DisableSingleUser), 72 | OC_SCHEMA_BOOLEAN_IN ("DisableVariableWrite" , OC_QUIRKS, DisableVariableWrite), 73 | OC_SCHEMA_BOOLEAN_IN ("DiscardHibernateMap" , OC_QUIRKS, DiscardHibernateMap), 74 | OC_SCHEMA_BOOLEAN_IN ("EnableSafeModeSlide" , OC_QUIRKS, EnableSafeModeSlide), 75 | OC_SCHEMA_BOOLEAN_IN ("EnableWriteUnprotector" , OC_QUIRKS, EnableWriteUnprotector), 76 | OC_SCHEMA_BOOLEAN_IN ("ForceExitBootServices" , OC_QUIRKS, ForceExitBootServices), 77 | OC_SCHEMA_ARRAY_IN ("MmioWhitelist" , OC_QUIRKS, MmioWhitelist, &mMmioWhitelist), 78 | OC_SCHEMA_BOOLEAN_IN ("ProtectMemoryRegions" , OC_QUIRKS, ProtectMemoryRegions), 79 | OC_SCHEMA_BOOLEAN_IN ("ProtectSecureBoot" , OC_QUIRKS, ProtectSecureBoot), 80 | OC_SCHEMA_BOOLEAN_IN ("ProtectUefiServices" , OC_QUIRKS, ProtectUefiServices), 81 | OC_SCHEMA_BOOLEAN_IN ("ProvideConsoleGopEnable" , OC_QUIRKS, ProvideConsoleGopEnable), 82 | OC_SCHEMA_BOOLEAN_IN ("ProvideCustomSlide" , OC_QUIRKS, ProvideCustomSlide), 83 | OC_SCHEMA_INTEGER_IN ("ProvideMaxSlide" , OC_QUIRKS, ProvideMaxSlide), 84 | OC_SCHEMA_BOOLEAN_IN ("RebuildAppleMemoryMap" , OC_QUIRKS, RebuildAppleMemoryMap), 85 | OC_SCHEMA_BOOLEAN_IN ("SetupVirtualMap" , OC_QUIRKS, SetupVirtualMap), 86 | OC_SCHEMA_BOOLEAN_IN ("SignalAppleOS" , OC_QUIRKS, SignalAppleOS), 87 | OC_SCHEMA_BOOLEAN_IN ("SyncRuntimePermissions" , OC_QUIRKS, SyncRuntimePermissions) 88 | }; 89 | 90 | STATIC 91 | OC_SCHEMA_INFO 92 | mConfigInfo = { 93 | .Dict = {mConfigNodes, ARRAY_SIZE (mConfigNodes)} 94 | }; 95 | 96 | STATIC 97 | BOOLEAN 98 | QuirksProvideConfig ( 99 | OUT OC_QUIRKS *Config, 100 | IN EFI_HANDLE Handle 101 | ) 102 | { 103 | EFI_STATUS Status; 104 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; 105 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; 106 | OC_STORAGE_CONTEXT Storage; 107 | CHAR8 *ConfigData; 108 | UINT32 ConfigDataSize; 109 | 110 | // Load SimpleFileSystem Protocol 111 | Status = gBS->HandleProtocol ( 112 | Handle, 113 | &gEfiLoadedImageProtocolGuid, 114 | (VOID **) &LoadedImage 115 | ); 116 | 117 | if (EFI_ERROR (Status)) { 118 | return FALSE; 119 | } 120 | 121 | FileSystem = LocateFileSystem ( 122 | LoadedImage->DeviceHandle, 123 | LoadedImage->FilePath 124 | ); 125 | 126 | if (FileSystem == NULL) { 127 | return FALSE; 128 | } 129 | 130 | // Init OcStorage as it already handles 131 | // reading Unicode files 132 | Status = OcStorageInitFromFs ( 133 | &Storage, 134 | FileSystem, 135 | ROOT_PATH, 136 | NULL 137 | ); 138 | 139 | if (EFI_ERROR (Status)) { 140 | return FALSE; 141 | } 142 | 143 | ConfigData = OcStorageReadFileUnicode ( 144 | &Storage, 145 | CONFIG_PATH, 146 | &ConfigDataSize 147 | ); 148 | 149 | // If no config data or greater than max size, fail and use defaults 150 | if (ConfigDataSize == 0 || ConfigDataSize > MAX_DATA_SIZE) { 151 | if (ConfigData != NULL) { 152 | FreePool(ConfigData); 153 | } 154 | 155 | return FALSE; 156 | } 157 | 158 | BOOLEAN Success = ParseSerialized (Config, &mConfigInfo, ConfigData, ConfigDataSize); 159 | 160 | FreePool(ConfigData); 161 | 162 | return Success; 163 | } 164 | 165 | EFI_STATUS 166 | EFIAPI 167 | QuirksEntryPoint ( 168 | IN EFI_HANDLE Handle, 169 | IN EFI_SYSTEM_TABLE *SystemTable 170 | ) 171 | { 172 | OC_QUIRKS Config; 173 | 174 | OC_QUIRKS_CONSTRUCT (&Config, sizeof (Config)); 175 | QuirksProvideConfig(&Config, Handle); 176 | 177 | OC_ABC_SETTINGS AbcSettings = { 178 | 179 | .AvoidRuntimeDefrag = Config.AvoidRuntimeDefrag, 180 | .DevirtualiseMmio = Config.DevirtualiseMmio, 181 | .DisableSingleUser = Config.DisableSingleUser, 182 | .DisableVariableWrite = Config.DisableVariableWrite, 183 | .DiscardHibernateMap = Config.DiscardHibernateMap, 184 | .EnableSafeModeSlide = Config.EnableSafeModeSlide, 185 | .EnableWriteUnprotector = Config.EnableWriteUnprotector, 186 | .ForceExitBootServices = Config.ForceExitBootServices, 187 | .ProtectMemoryRegions = Config.ProtectMemoryRegions, 188 | .ProtectSecureBoot = Config.ProtectSecureBoot, 189 | .ProtectUefiServices = Config.ProtectUefiServices, 190 | .ProvideCustomSlide = Config.ProvideCustomSlide, 191 | .ProvideMaxSlide = Config.ProvideMaxSlide, 192 | .RebuildAppleMemoryMap = Config.RebuildAppleMemoryMap, 193 | .SetupVirtualMap = Config.SetupVirtualMap, 194 | .SignalAppleOS = Config.SignalAppleOS, 195 | .SyncRuntimePermissions = Config.SyncRuntimePermissions 196 | }; 197 | 198 | if (Config.DevirtualiseMmio && Config.MmioWhitelist.Count > 0) { 199 | AbcSettings.MmioWhitelist = AllocatePool ( 200 | Config.MmioWhitelist.Count * sizeof (AbcSettings.MmioWhitelist[0]) 201 | ); 202 | 203 | if (AbcSettings.MmioWhitelist != NULL) { 204 | UINT32 abcIndex = 0; 205 | UINT32 configIndex = 0; 206 | 207 | for (configIndex = 0; configIndex < Config.MmioWhitelist.Count; configIndex++) { 208 | if (Config.MmioWhitelist.Values[configIndex]->Enabled) { 209 | AbcSettings.MmioWhitelist[abcIndex] = Config.MmioWhitelist.Values[configIndex]->Address; 210 | abcIndex++; 211 | } 212 | } 213 | 214 | AbcSettings.MmioWhitelistSize = abcIndex; 215 | } // Else couldn't allocate slots for mmio addresses 216 | } 217 | 218 | if (Config.ProvideConsoleGopEnable) { 219 | OcProvideConsoleGop (TRUE); 220 | } 221 | 222 | OC_QUIRKS_DESTRUCT (&Config, sizeof (Config)); 223 | 224 | return OcAbcInitialize (&AbcSettings); 225 | } 226 | -------------------------------------------------------------------------------- /Platform/OcQuirks/OcQuirks.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010005 3 | BASE_NAME = OcQuirks 4 | FILE_GUID = 43C8CFCA-03C0-4AA8-8BEB-5AF6AB3570A2 5 | MODULE_TYPE = UEFI_DRIVER 6 | VERSION_STRING = 1.0 7 | ENTRY_POINT = QuirksEntryPoint 8 | 9 | [Packages] 10 | MdeModulePkg/MdeModulePkg.dec 11 | MdePkg/MdePkg.dec 12 | OpenCorePkg/OpenCorePkg.dec 13 | 14 | [LibraryClasses] 15 | MemoryAllocationLib 16 | DebugLib 17 | OcAfterBootCompatLib 18 | OcBootManagementLib 19 | OcMachoLib 20 | OcOSInfoLib 21 | OcStorageLib 22 | OcConsoleLib 23 | OcSerializeLib 24 | OcTemplateLib 25 | UefiBootServicesTableLib 26 | UefiDriverEntryPoint 27 | 28 | [Protocols] 29 | gEfiSimpleFileSystemProtocolGuid 30 | gEfiLoadedImageProtocolGuid 31 | 32 | [Sources] 33 | OcQuirks.c 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # OcQuirks 3 | 4 | OcQuirks is a drop in replacement EFI driver for Clover that replaces AptioMemoryFix and all OsxAptioFix variants. It is built against the OpenCore source tree, and supports OpenCore's quirks model. 5 | 6 | ## Prerequisites 7 | The OcQuirks EFI driver has a dependency on OpenRuntime.efi, and they must be installed together in the CLOVER EFI drivers directory. OpenRuntime.efi can be found in the release zip and is built along with OcQuirks. 8 | 9 | ## Installation 10 | To install OcQuirks, download the latest release or build it using the instructions below and then install it into your EFI replacing any existing memory fix driver. 11 | 12 | - Mount your EFI volume. 13 | - Back your EFI volume up to a bootable USB drive and verify that it works. 14 | - Remove AptioMemoryFix, and any OsxAptioFix variants from the Clover drivers folder on your EFI volume. 15 | - Add OcQuirks.efi, OpenRuntime.efi, and OcQuirks.plist to the Clover drivers folder on your EFI volume. 16 | - Reboot. 17 | 18 | If your system has trouble booting, use your USB stick to boot back into macOS and revert by reversing the process. Inspect the parameters below and configure OcQuirks.plist with parameters that better match your system. 19 | 20 | Default settings are based on AptioMemoryFix and are designed with new Intel systems in mind. Your system may require custom settings, (e.g., Z390 may need DevirtualiseMmio+ProtectUefiServices, Older 100-200 series might need EnableWriteUnprotector). It is also assumed that all slides are valid (no slide=X). 21 | 22 | ## Configuration 23 | The parameters listed below can be changed by dropping in OcQuirks.plist into your Clover drivers folder. This can be found in either the release zip or the root of the OcQuirks repository. If no plist is found, then the defaults below are used. 24 | 25 | |Quirk|Default Value|Description| 26 | |---|---|---| 27 | |AvoidRuntimeDefrag|True|Fix UEFI runtime services support on many firmwares.| 28 | |DevirtualiseMmio|False|Reduce stolen memory footprint from memory map, incompatible with some systems| 29 | |DisableSingleUser|False|A security option to ignore single user mode arguments.| 30 | |DisableVariableWrite|False|A security option to protect macOS NVRAM write access.| 31 | |DiscardHibernateMap|False|A legacy parameter to work around buggy memory maps. Preserves runtime memory size and location after wake from S4 sleep.| 32 | |EnableSafeModeSlide|True|Patch the bootloader to enable KASLR in safe mode.| 33 | |EnableWriteUnprotector|False|Permits write access to UEFI runtime services code. Use RebuildAppleMemoryMap if possible.| 34 | |ForceExitBootServices|True|Ensures that calls to ExitBootServices succeed even with an outdated MemoryMap key.| 35 | |MmioWhitelist|Array|Designed to be filled with plist dict values, describing addresses critical for particular firmware functioning when DevirtualiseMmio quirk is in use. 36 | |ProtectMemoryRegions|False|Protect memory regions from incorrect access. Only needed by very old firmwares.| 37 | |ProtectSecureBoot|False|Protect UEFI Secure Boot variables from being written.| 38 | |ProtectUefiServices|False|Protect UEFI services from being overridden by the firmware.| 39 | |ProvideConsoleGopEnable|True|Install Graphics Output Protocol if missing from the console handle.| 40 | |ProvideCustomSlide|True|Force macOS to use a pseudorandom value among available slide values.| 41 | |ProvideMaxSlide|0|Overrides the maximum slide instead of 256 when ProvideCustomSlide is enabled.| 42 | |RebuildAppleMemoryMap|True|Generate Memory Map compatible with macOS.| 43 | |SetupVirtualMap|True|Workaround issues in some firmwares that access memory after SetVirtualAddress calls often resulting in boot crashes.| 44 | |SignalAppleOS|False|This quirk is useful on Mac firmwares, which behave differently in different OS.| 45 | |SyncRuntimePermissions|True|Update memory permissions for runtime environment.| 46 | 47 | For a more indepth description of quirks, review the [OpenCore Configuration Manual](https://github.com/acidanthera/OpenCorePkg/blob/master/Docs/Configuration.pdf). 48 | 49 | ## Building 50 | Building OcQuirks is simple, you just need macOS and time. You do not need to configure OcQuirks before building now, so all you need to do is follow the process below to build. 51 | 52 | ### Clone the Repository 53 | 54 | ``` 55 | $ git clone https://github.com/ReddestDream/OcQuirks.git 56 | $ cd OcQuirks 57 | ``` 58 | 59 | ### Build OcQuirks 60 | Now build OcQuirks using the macbuild tool. You may be prompted to install additional tools before compilation begins. 61 | 62 | ``` 63 | $ ./macbuild.tool 64 | ``` 65 | 66 | ### Installation 67 | Follow the installation procedures found earlier in the documentation, using the newly compiled version of OcQuirks which can be found in the OcQuirks/Binaries/RELEASE folder. 68 | 69 | ## Credits 70 | - [Apple](https://www.apple.com) for macOS 71 | - [vit9696](https://github.com/vit9696) for [OpenCore](https://github.com/acidanthera/OpenCorePkg/blob/master/README.md) and AptioMemoryFix 72 | - [Download-Fritz](https://github.com/Download-Fritz) and [al3x](https://github.com/al3xtjames) for ideas and code contributions 73 | - [CorpNewt](https://github.com/corpnewt) for the configuration scripts 74 | -------------------------------------------------------------------------------- /macbuild.tool: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | package() { 4 | if [ ! -d "$1" ]; then 5 | echo "Missing package directory" 6 | exit 1 7 | fi 8 | 9 | local ver=$(cat Include/Protocol/OcQuirks.h | grep OCQUIRKS_PROTOCOL_REVISION | cut -f4 -d' ' | cut -f2 -d'"' | grep -E '^[0-9.]+$') 10 | if [ "$ver" = "" ]; then 11 | echo "Invalid version $ver" 12 | fi 13 | 14 | rm -rf "$1"/tmp || exit 1 15 | mkdir -p "$1"/tmp/Drivers || exit 1 16 | cp OcQuirks.plist "$1"/tmp/Drivers || exit 1 17 | pushd "$1" || exit 1 18 | cp OcQuirks.efi tmp/Drivers/ || exit 1 19 | cp OpenRuntime.efi tmp/Drivers/ || exit 1 20 | pushd tmp || exit 1 21 | zip -qry -FS ../"OcQuirks-${ver}-${2}.zip" * || exit 1 22 | popd || exit 1 23 | rm -rf tmp || exit 1 24 | popd || exit 1 25 | } 26 | 27 | cd $(dirname "$0") 28 | ARCHS=(X64) 29 | SELFPKG=OcQuirks 30 | DEPNAMES=('EfiPkg' 'OpenCorePkg') 31 | DEPURLS=('https://github.com/acidanthera/EfiPkg' 'https://github.com/acidanthera/OpenCorePkg') 32 | DEPBRANCHES=('master' 'master') 33 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/efibuild.sh) && eval "$src" || exit 1 --------------------------------------------------------------------------------