Skip to content

Commit

Permalink
Bump version to 1.0.6. Fix reading of key rtc-blacklist from NVRAM (o…
Browse files Browse the repository at this point in the history
…nly 4 bytes could be read).
  • Loading branch information
lvs1974 committed May 9, 2020
1 parent 17638d9 commit f54dfc7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
RTCMemoryFixup Changelog
============================
#### v.1.0.6
- Fix reading of key rtc-blacklist from NVRAM (only 4 bytes could be read)
- rtcfx_exclude can be combined with rtc-blacklist

#### v1.0.5
- Support key rtc-blacklist set by OpenCore in NVRAM

Expand Down
4 changes: 2 additions & 2 deletions RTCMemoryFixup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.8;
MODULE_NAME = as.lvs1974.RTCMemoryFixup;
MODULE_VERSION = 1.0.5;
MODULE_VERSION = 1.0.6;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -406,7 +406,7 @@
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MODULE_NAME = as.lvs1974.RTCMemoryFixup;
MODULE_VERSION = 1.0.5;
MODULE_VERSION = 1.0.6;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down
30 changes: 15 additions & 15 deletions RTCMemoryFixup/RTCMemoryFixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ void RTCMemoryFixup::ioWrite8(IOService * that, UInt16 offset, UInt8 value, IOMe

//==============================================================================

void RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)
bool RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)
{
bool result = false;
char *tok = rtcfx_exclude, *end = rtcfx_exclude;
char *dash = nullptr;
while (tok != nullptr)
Expand All @@ -238,7 +239,7 @@ void RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)
DBGLOG("RTCFX", "rtc offset %02X is not valid", offset);
break;
}
emulated_flag[offset] = true;
result = emulated_flag[offset] = true;
DBGLOG("RTCFX", "rtc offset %02X is marked as emulated", offset);
}
else
Expand Down Expand Up @@ -267,7 +268,7 @@ void RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)
}

for (unsigned int i = soffset; i <= eoffset; ++i)
emulated_flag[i] = true;
result = emulated_flag[i] = true;
DBGLOG("RTCFX", "rtc range from offset %02X to offset %02X is marked as emulated", soffset, eoffset);
}
else
Expand All @@ -279,6 +280,7 @@ void RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)

tok = end;
}
return result;
}

//==============================================================================
Expand All @@ -287,31 +289,30 @@ void RTCMemoryFixup::hookProvider(IOService *provider)
{
if (orgIoRead8 == nullptr || orgIoWrite8 == nullptr)
{
bool suppress_errors = false;
OSData* data = nullptr;
static constexpr size_t rtcfx_exclude_size = 512;
auto rtcfx_exclude_tmp = Buffer::create<char>(rtcfx_exclude_size);
if (rtcfx_exclude_tmp && PE_parse_boot_argn("rtcfx_exclude", rtcfx_exclude_tmp, rtcfx_exclude_size))
{
DBGLOG("RTCFX", "boot-arg rtcfx_exclude specified, value = %s", rtcfx_exclude_tmp);
excludeAddresses(rtcfx_exclude_tmp);
suppress_errors = excludeAddresses(rtcfx_exclude_tmp);
}
else if (rtcfx_exclude_tmp && (data = OSDynamicCast(OSData, provider->getProperty("rtcfx_exclude"))) != nullptr)
{
if (data->getLength() < rtcfx_exclude_size)
{
lilu_os_strncpy(rtcfx_exclude_tmp, reinterpret_cast<const char*>(data->getBytesNoCopy()), data->getLength());
DBGLOG("RTCFX", "property rtcfx_exclude specified, value = %s", rtcfx_exclude_tmp);
excludeAddresses(rtcfx_exclude_tmp);
suppress_errors = excludeAddresses(rtcfx_exclude_tmp);
}
else
{
SYSLOG("RTCFX", "RTCMemoryFixup::hookProvider: length of rtcfx_exclude cannot excceed 512 bytes");
}
}
else
{
readAndApplyRtcBlacklistFromNvram();
}

readAndApplyRtcBlacklistFromNvram(suppress_errors);

if (rtcfx_exclude_tmp)
Buffer::deleter(rtcfx_exclude_tmp);
Expand All @@ -336,7 +337,7 @@ void RTCMemoryFixup::hookProvider(IOService *provider)

//==============================================================================

void RTCMemoryFixup::readAndApplyRtcBlacklistFromNvram() {
void RTCMemoryFixup::readAndApplyRtcBlacklistFromNvram(bool suppress_errors) {
NVStorage storage;
if (storage.init()) {
uint32_t size = 0;
Expand All @@ -349,15 +350,15 @@ void RTCMemoryFixup::readAndApplyRtcBlacklistFromNvram() {
DBGLOG("RTCFX", "successfully got %u bytes from nvram for key %s", size, OcRtcBlacklistKey);
Buffer::deleter(buf);
}
else
else if (!suppress_errors || ADDPR(debugEnabled))
SYSLOG("RTCFX", "failed to load rtc-blacklist config from nvram");

storage.deinit();
} else {
// Otherwise use EFI services if available.
auto rt = EfiRuntimeServices::get(true);
if (rt) {
uint64_t size = sizeof(RTC_SIZE);
uint64_t size = RTC_SIZE;
auto buf = Buffer::create<uint8_t>(size);
if (buf) {
uint32_t attr = 0;
Expand All @@ -369,15 +370,14 @@ void RTCMemoryFixup::readAndApplyRtcBlacklistFromNvram() {
emulated_flag[buf[i]] = true;
DBGLOG("RTCFX", "successfully got %u bytes from UEFI nvram for key %s", size, OcRtcBlacklistKey);
}
else
else if (!suppress_errors || ADDPR(debugEnabled))
SYSLOG("RTCFX", "failed to load rtc-blacklist config from UEFI nvram");
Buffer::deleter(buf);
}
else
SYSLOG("RTCFX", "failed to create temporary buffer");
rt->put();
} else {
} else
SYSLOG("RTCFX", "failed to load efi rt services for rtc-blacklist");
}
}
}
4 changes: 2 additions & 2 deletions RTCMemoryFixup/RTCMemoryFixup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class EXPORT RTCMemoryFixup : public IOService
virtual void free() override;

private:
static void excludeAddresses(char* rtcfx_exclude);
static bool excludeAddresses(char* rtcfx_exclude);
static void hookProvider(IOService* provider);
static void readAndApplyRtcBlacklistFromNvram();
static void readAndApplyRtcBlacklistFromNvram(bool suppress_errors);

using t_io_read8 = UInt8 (*)(IOService * that, UInt16 offset, IOMemoryMap * map);
using t_io_write8 = void (*)(IOService * that, UInt16 offset, UInt8 value, IOMemoryMap * map);
Expand Down

0 comments on commit f54dfc7

Please sign in to comment.