Skip to content

Commit

Permalink
feat: Ensure VBIOS override is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualEhrmanntraut committed Nov 8, 2024
1 parent fb05602 commit 04d76ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
50 changes: 31 additions & 19 deletions NootedRed/NRed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,7 @@ void NRed::hwLateInit() {
this->iGPU->setMemoryEnable(true);
this->iGPU->setBusMasterEnable(true);

auto *atombiosImageProp = OSDynamicCast(OSData, this->iGPU->getProperty("ATY,bin_image"));
if (atombiosImageProp == nullptr) {
if (this->getVBIOSFromVFCT()) {
DBGLOG("NRed", "Got VBIOS from VFCT.");
} else {
SYSLOG("NRed", "Failed to get VBIOS from VFCT, trying to get it from VRAM!");
if (this->getVBIOSFromVRAM()) {
DBGLOG("NRed", "Got VBIOS from VRAM.");
} else {
SYSLOG("NRed", "Failed to get VBIOS from VRAM, trying to get it from PCI Expansion ROM!");
PANIC_COND(!this->getVBIOSFromExpansionROM(), "NRed", "Failed to get VBIOS!");
DBGLOG("NRed", "Got VBIOS from PCI Expansion ROM.");
}
}

} else {
this->vbiosData = OSData::withData(atombiosImageProp);
SYSLOG("NRed", "!!! VBIOS MANUALLY OVERRIDDEN, MAKE SURE YOU KNOW WHAT YOU'RE DOING !!!");
}
PANIC_COND(!this->getVBIOS(), "NRed", "Failed to get VBIOS!");

auto len = this->vbiosData->getLength();
if (len < ATOMBIOS_IMAGE_SIZE) {
Expand Down Expand Up @@ -451,6 +433,36 @@ bool NRed::getVBIOSFromVRAM() {
return true;
}

bool NRed::getVBIOS() {
auto *biosImageProp = OSDynamicCast(OSData, this->iGPU->getProperty("ATY,bin_image"));
if (biosImageProp != nullptr) {
if (checkAtomBios(static_cast<const UInt8 *>(biosImageProp->getBytesNoCopy()), biosImageProp->getLength())) {
this->vbiosData = OSData::withData(biosImageProp);
SYSLOG("NRed", "Warning: VBIOS manually overridden, make sure you know what you're doing.");
return true;
} else {
SYSLOG("NRed", "Error: VBIOS override is invalid.");
}
}
if (this->getVBIOSFromVFCT()) {
DBGLOG("NRed", "Got VBIOS from VFCT.");
} else {
SYSLOG("NRed", "Error: Failed to get VBIOS from VFCT, trying to get it from VRAM.");
if (this->getVBIOSFromVRAM()) {
DBGLOG("NRed", "Got VBIOS from VRAM.");
} else {
SYSLOG("NRed", "Error: Failed to get VBIOS from VRAM, trying to get it from PCI Expansion ROM!");
if (this->getVBIOSFromExpansionROM()) {
DBGLOG("NRed", "Got VBIOS from PCI Expansion ROM.");
} else {
SYSLOG("NRed", "Error: Failed to get VBIOS from PCI Expansion ROM!");
return false;
}
}
}
return true;
}

static const char *getDriverXMLForBundle(const char *bundleIdentifier, size_t *len) {
const auto identifierLen = strlen(bundleIdentifier);
const auto totalLen = identifierLen + 5;
Expand Down
1 change: 1 addition & 0 deletions NootedRed/PrivateHeaders/NRed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class NRed {
bool getVBIOSFromExpansionROM();
bool getVBIOSFromVFCT();
bool getVBIOSFromVRAM();
bool getVBIOS();

static bool wrapAddDrivers(void *that, OSArray *array, bool doNubMatching);
static OSMetaClassBase *wrapSafeMetaCast(const OSMetaClassBase *anObject, const OSMetaClass *toMeta);
Expand Down

0 comments on commit 04d76ef

Please sign in to comment.