diff --git a/Changelog.md b/Changelog.md index b3a7a4e11052dcbf5991cd4c9965a5aab24ead50..f6ff688faa3384687d8b432dc2836d7c143ece78 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ OpenCore Changelog - Added memory region reservation support - Added RtcRw tool to manipulate RTC memory - Added `PatchAppleRtcChecksum` kernel quirk +- Added `AppleRtcRam` protocol implementation #### v0.5.7 - Added TimeMachine detection to picker diff --git a/Docs/Configuration.pdf b/Docs/Configuration.pdf index 4931c4ffd412b267b2b91b50237455ea927fc326..f406b44422974fd0e2632ebd78b634a44724aef6 100644 Binary files a/Docs/Configuration.pdf and b/Docs/Configuration.pdf differ diff --git a/Docs/Configuration.tex b/Docs/Configuration.tex index cdfb2c9dce987ebb6844d39094821e5cc35b4d17..7ff7213563961ad0d74bbfaa696ad69690e780b2 100755 --- a/Docs/Configuration.tex +++ b/Docs/Configuration.tex @@ -1987,8 +1987,8 @@ blocking. kernel extension if this is desired. \emph{Note 2}: This option will not protect areas from being overwritten - at firmware stage (e.g. macOS bootloader), see \texttt{RTC} (FIXME) section - if this is desired. + at firmware stage (e.g. macOS bootloader), see \texttt{AppleRtc} protocol + description if this is desired. \item \texttt{DummyPowerManagement}\\ @@ -4826,6 +4826,18 @@ functioning. Feature highlights: \textbf{Description}: Reinstalls Apple Key Map protocols with builtin versions. +\item + \texttt{AppleRtc}\\ + \textbf{Type}: \texttt{plist\ boolean}\\ + \textbf{Failsafe}: \texttt{false}\\ + \textbf{Description}: Reinstalls Apple RTC RAM protocol with builtin + version. + + \emph{Note}: Builtin version of Apple RTC RAM protocol may filter out + I/O attempts to select RTC memory addresses. The list of addresses + can be specified in \texttt{4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:rtc-blacklist} + variable as a data array. + \item \texttt{AppleSmcIo}\\ \textbf{Type}: \texttt{plist\ boolean}\\ diff --git a/Docs/Differences/Differences.pdf b/Docs/Differences/Differences.pdf index b032a70c35feed85a9b1064dec1dff593b4a0d62..52f56680c285abea6f039054dcd4d34cf84dc001 100644 Binary files a/Docs/Differences/Differences.pdf and b/Docs/Differences/Differences.pdf differ diff --git a/Docs/Differences/Differences.tex b/Docs/Differences/Differences.tex index 08db585e1ee5f762a29f43265fba784f16f71474..1455e30a87ffe74f1bb0602bf855deed1d9c6117 100644 --- a/Docs/Differences/Differences.tex +++ b/Docs/Differences/Differences.tex @@ -1,7 +1,7 @@ \documentclass[]{article} %DIF LATEXDIFF DIFFERENCE FILE %DIF DEL PreviousConfiguration.tex Tue Apr 7 19:32:13 2020 -%DIF ADD ../Configuration.tex Sat Apr 18 15:39:07 2020 +%DIF ADD ../Configuration.tex Sat Apr 18 22:12:54 2020 \usepackage{lmodern} \usepackage{amssymb,amsmath} @@ -2050,8 +2050,8 @@ blocking. } \emph{\DIFadd{Note 2}}\DIFadd{: This option will not protect areas from being overwritten - at firmware stage (e.g. macOS bootloader), see }\texttt{\DIFadd{RTC}} \DIFadd{(FIXME) section - if this is desired. + at firmware stage (e.g. macOS bootloader), see }\texttt{\DIFadd{AppleRtc}} \DIFadd{protocol + description if this is desired. } \item @@ -4911,7 +4911,21 @@ functioning. Feature highlights: versions. \item - \texttt{AppleSmcIo}\\ + \DIFaddbegin \texttt{\DIFadd{AppleRtc}}\\ + \textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\ + \textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{false}}\\ + \textbf{\DIFadd{Description}}\DIFadd{: Reinstalls Apple RTC RAM protocol with builtin + version. +} + + \emph{\DIFadd{Note}}\DIFadd{: Builtin version of Apple RTC RAM protocol may filter out + I/O attempts to select RTC memory addresses. The list of addresses + can be specified in }\texttt{\DIFadd{4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:rtc-blacklist}} + \DIFadd{variable as a data array. +} + +\item + \DIFaddend \texttt{AppleSmcIo}\\ \textbf{Type}: \texttt{plist\ boolean}\\ \textbf{Failsafe}: \texttt{false}\\ \textbf{Description}: Reinstalls Apple SMC I/O protocol with a builtin diff --git a/Docs/Sample.plist b/Docs/Sample.plist index c179ccd48c2256fe722200d1620d72039154523a..ba31873a06d46cc2e7a9f19f9eb6cd4d7f438aa3 100644 --- a/Docs/Sample.plist +++ b/Docs/Sample.plist @@ -683,6 +683,11 @@ prev-lang:kbd cnUtUlU6MjUy + 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102 + + rtc-blacklist + + Block @@ -695,6 +700,10 @@ boot-args + 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102 + + rtc-blacklist + LegacyEnable @@ -864,6 +873,8 @@ AppleKeyMap + AppleRtcRam + AppleSmcIo AppleUserInterfaceTheme diff --git a/Docs/SampleFull.plist b/Docs/SampleFull.plist index 6d4ab9bd7618b5fe2547adf985e852be5c96ff0e..f550f897c2992d63261eae0236a6f0c6e7cd324a 100644 --- a/Docs/SampleFull.plist +++ b/Docs/SampleFull.plist @@ -683,6 +683,11 @@ prev-lang:kbd cnUtUlU6MjUy + 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102 + + rtc-blacklist + + Block @@ -695,6 +700,10 @@ boot-args + 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102 + + rtc-blacklist + LegacyEnable @@ -967,6 +976,8 @@ AppleKeyMap + AppleRtcRam + AppleSmcIo AppleUserInterfaceTheme diff --git a/Include/Guid/OcVariables.h b/Include/Guid/OcVariables.h index 4064325eb32a258b45271e194b9a674409802f0c..d67e2eed0837e798245010bd77af91834eeb3871 100644 --- a/Include/Guid/OcVariables.h +++ b/Include/Guid/OcVariables.h @@ -77,6 +77,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // #define OC_ACPI_CPU_FREQUENCY_VARIABLE_NAME L"acpi-cpu-frequency" +// +// Variable used to mark blacklisted RTC values. +// +#define OC_RTC_BLACKLIST_VARIABLE_NAME L"rtc-blacklist" + // // 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102 // This GUID is specifically used for normal variable access by Lilu kernel extension and its plugins. diff --git a/Include/Library/OcConfigurationLib.h b/Include/Library/OcConfigurationLib.h index ea0dde894916160c950ba80be197c0c9ad48d007..9907b98ec9e4dfd2e0890e72f2551fb8f622c4d3 100644 --- a/Include/Library/OcConfigurationLib.h +++ b/Include/Library/OcConfigurationLib.h @@ -535,6 +535,7 @@ typedef enum { _(BOOLEAN , AppleEvent , , FALSE , ()) \ _(BOOLEAN , AppleImageConversion , , FALSE , ()) \ _(BOOLEAN , AppleKeyMap , , FALSE , ()) \ + _(BOOLEAN , AppleRtcRam , , FALSE , ()) \ _(BOOLEAN , AppleSmcIo , , FALSE , ()) \ _(BOOLEAN , AppleUserInterfaceTheme , , FALSE , ()) \ _(BOOLEAN , DataHub , , FALSE , ()) \ diff --git a/Library/OcConfigurationLib/OcConfigurationLib.c b/Library/OcConfigurationLib/OcConfigurationLib.c index 4a3e5914d58b5fa48ff218ec9d82fb018c21f5d2..a196af46b2fbc5b2fb1ad4148972a5796c6789db 100644 --- a/Library/OcConfigurationLib/OcConfigurationLib.c +++ b/Library/OcConfigurationLib/OcConfigurationLib.c @@ -547,6 +547,7 @@ mUefiProtocolsSchema[] = { OC_SCHEMA_BOOLEAN_IN ("AppleEvent", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleEvent), OC_SCHEMA_BOOLEAN_IN ("AppleImageConversion", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleImageConversion), OC_SCHEMA_BOOLEAN_IN ("AppleKeyMap", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleKeyMap), + OC_SCHEMA_BOOLEAN_IN ("AppleRtcRam", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleRtcRam), OC_SCHEMA_BOOLEAN_IN ("AppleSmcIo", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleSmcIo), OC_SCHEMA_BOOLEAN_IN ("AppleUserInterfaceTheme", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleUserInterfaceTheme), OC_SCHEMA_BOOLEAN_IN ("DataHub", OC_GLOBAL_CONFIG, Uefi.Protocols.DataHub), diff --git a/Library/OcRtcLib/AppleRtcRam.c b/Library/OcRtcLib/AppleRtcRam.c index 272a95c3d2f0b241528d3d1aaae90de712d7aaf8..bc06dcbbe98eb7676aeb35d4780b34abeefe6c13 100644 --- a/Library/OcRtcLib/AppleRtcRam.c +++ b/Library/OcRtcLib/AppleRtcRam.c @@ -16,9 +16,11 @@ **/ +#include #include #include #include +#include #include #include #include @@ -26,6 +28,9 @@ #include "OcRtcLibInternal.h" STATIC EFI_LOCK mAppleRtcRamLock; +STATIC UINT8 mEmulatedRtcArea[APPLE_RTC_TOTAL_SIZE]; +STATIC BOOLEAN mEmulatedRtcStatus[APPLE_RTC_TOTAL_SIZE]; + STATIC EFI_STATUS @@ -36,6 +41,10 @@ SyncRtcRead ( { EFI_STATUS Status; + if (mEmulatedRtcStatus[Address]) { + return mEmulatedRtcArea[Address]; + } + Status = EfiAcquireLockOrFail (&mAppleRtcRamLock); if (EFI_ERROR (Status)) { return Status; @@ -55,6 +64,11 @@ SyncRtcWrite ( { EFI_STATUS Status; + if (mEmulatedRtcStatus[Address]) { + mEmulatedRtcArea[Address] = Value; + return EFI_SUCCESS; + } + Status = EfiAcquireLockOrFail (&mAppleRtcRamLock); if (EFI_ERROR (Status)) { return Status; @@ -150,7 +164,7 @@ AppleRtcRamReadData ( return Status; } - if (((UINT32) Temp ^ (UINT32) *Buffer) != 0xFF) { + if ((Temp ^ *Buffer) != 0xFF) { *Buffer = 0; } } @@ -275,8 +289,11 @@ OcAppleRtcRamInstallProtocol ( IN BOOLEAN Reinstall ) { - EFI_STATUS Status; - APPLE_RTC_RAM_PROTOCOL *Protocol; + EFI_STATUS Status; + APPLE_RTC_RAM_PROTOCOL *Protocol; + UINT8 *RtcBlacklist; + UINTN Index; + UINTN RtcBlacklistSize; DEBUG ((DEBUG_VERBOSE, "OcAppleRtcRamInstallProtocol\n")); @@ -298,6 +315,31 @@ OcAppleRtcRamInstallProtocol ( } } + DEBUG (( + DEBUG_INFO, + "OCRTC: Wake log is 0x%02X 0x%02X % 3d 0x%02X\n", + OcRtcRead (APPLE_RTC_TRACE_DATA_ADDR), + OcRtcRead (APPLE_RTC_WL_MASK_ADDR), + OcRtcRead (APPLE_RTC_WL_EVENT_ADDR), + OcRtcRead (APPLE_RTC_WL_EVENT_EXTRA_ADDR) + )); + + Status = GetVariable2 ( + OC_RTC_BLACKLIST_VARIABLE_NAME, + &gOcVendorVariableGuid, + (VOID **) &RtcBlacklist, + &RtcBlacklistSize + ); + + if (!EFI_ERROR (Status)) { + for (Index = 0; Index < APPLE_RTC_TOTAL_SIZE; ++Index) { + mEmulatedRtcStatus[RtcBlacklist[Index]] = TRUE; + DEBUG ((DEBUG_INFO, "OCRTC: Blacklisted %02x address\n", RtcBlacklist[Index])); + } + + FreePool (RtcBlacklist); + } + // // Note, for debugging on QEMU this will need to changed to TPL_CALLBACK. // By default we follow AppleRtcRam implementation. diff --git a/Library/OcRtcLib/OcRtcLib.inf b/Library/OcRtcLib/OcRtcLib.inf index 61bb0b78c8540c72f070427b12188b2e57c586d1..558e7a58dda04089c37c176959b05d6cc01b3f08 100644 --- a/Library/OcRtcLib/OcRtcLib.inf +++ b/Library/OcRtcLib/OcRtcLib.inf @@ -38,6 +38,9 @@ MdePkg/MdePkg.dec OpenCorePkg/OpenCorePkg.dec +[Guids] + gOcVendorVariableGuid + [Protocols] gAppleRtcRamProtocolGuid @@ -45,6 +48,7 @@ BaseMemoryLib DebugLib IoLib + MemoryAllocationLib OcMiscLib UefiLib UefiBootServicesTableLib diff --git a/Platform/OpenCore/OpenCoreUefi.c b/Platform/OpenCore/OpenCoreUefi.c index bfff9d35e7e4370530ef809342f23c022af7f3ec..4dbb6edeb632cd7793ec73f7f8211f7b8d8fc50f 100644 --- a/Platform/OpenCore/OpenCoreUefi.c +++ b/Platform/OpenCore/OpenCoreUefi.c @@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -339,6 +340,10 @@ OcReinstallProtocols ( if (OcOSInfoInstallProtocol (Config->Uefi.Protocols.OSInfo) == NULL) { DEBUG ((DEBUG_ERROR, "OC: Failed to install os info protocol\n")); } + + if (OcAppleRtcRamInstallProtocol (Config->Uefi.Protocols.AppleRtcRam) == NULL) { + DEBUG ((DEBUG_ERROR, "OC: Failed to install rtc ram protocol\n")); + } } VOID