diff --git a/Library/DeviceTreeLib/DeviceTreeLib.c b/Library/DeviceTreeLib/DeviceTreeLib.c index ee756b47c..9d5c24f39 100755 --- a/Library/DeviceTreeLib/DeviceTreeLib.c +++ b/Library/DeviceTreeLib/DeviceTreeLib.c @@ -468,7 +468,7 @@ DumpDeviceTreeNodeRecusively ( if (!EFI_ERROR (Status)) { PropertyParent = "/"; - while ((Status = DTIterateProperties (PropIter, &PropertyName)) == EFI_SUCCESS) { + while (!EFI_ERROR(DTIterateProperties (PropIter, &PropertyName))) { if ((Status = DTGetProperty (Entry, (CHAR8 *)PropertyName, (void *)&PropertyValue, &PropertySize)) != EFI_SUCCESS) { DEBUG ((DEBUG_WARN, "DeviceTree is probably invalid - %r\n", Status)); break; @@ -553,7 +553,7 @@ DumpDeviceTree ( /// /// /// @param[in] Base Pointer to the Device Tree -/// @param[in] Length Pointer to location containg the Device Tree length +/// @param[in] Length Pointer to location containing the Device Tree length /// VOID diff --git a/MemoryFix/OsxAptioFixDrv/BootFixes.c b/MemoryFix/OsxAptioFixDrv/BootFixes.c index 05d07520b..3973c1bbb 100644 --- a/MemoryFix/OsxAptioFixDrv/BootFixes.c +++ b/MemoryFix/OsxAptioFixDrv/BootFixes.c @@ -610,12 +610,12 @@ DevTreeFix(BootArgs *BA) DBG("Fixing DevTree at %p\n", DevTree); DBGnvr("Fixing DevTree at %p\n", DevTree); - DTInit(DevTree); - if (DTLookupEntry(NULL, "/chosen/memory-map", &MemMap) == kSuccess) { + DTInit(DevTree, BA->deviceTreeLength); + if (!EFI_ERROR(DTLookupEntry(NULL, "/chosen/memory-map", &MemMap))) { DBG("Found /chosen/memory-map\n"); - if (DTCreatePropertyIteratorNoAlloc(MemMap, PropIter) == kSuccess) { + if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) { DBG("DTCreatePropertyIterator OK\n"); - while (DTIterateProperties(PropIter, &PropName) == kSuccess) { + while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) { DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length); // all /chosen/memory-map props have DTMemMapEntry (address, length) // values. we need to correct the address diff --git a/MemoryFix/OsxAptioFixDrv/BootFixes3.c b/MemoryFix/OsxAptioFixDrv/BootFixes3.c index 40a8c40b9..38a8cb685 100644 --- a/MemoryFix/OsxAptioFixDrv/BootFixes3.c +++ b/MemoryFix/OsxAptioFixDrv/BootFixes3.c @@ -765,25 +765,26 @@ RuntimeServicesFix(BootArgs *BA) VOID DevTreeFix(BootArgs *BA) { - DTEntry DevTree; - DTEntry MemMap; - struct OpaqueDTPropertyIterator OPropIter; - DTPropertyIterator PropIter = &OPropIter; - CHAR8 *PropName; - DTMemMapEntry *PropValue; + DTEntry DevTree; + DTEntry MemMap; + CHAR8 *PropName; + DTMemMapEntry *PropValue; BooterKextFileInfo *KextInfo; + + struct OpaqueDTPropertyIterator OPropIter; + DTPropertyIterator PropIter = &OPropIter; DevTree = (DTEntry)(UINTN)(*BA->deviceTreeP); DBG("Fixing DevTree at %p\n", DevTree); DBGnvr("Fixing DevTree at %p\n", DevTree); - DTInit(DevTree); - if (DTLookupEntry(NULL, "/chosen/memory-map", &MemMap) == kSuccess) { + DTInit(DevTree, BA->deviceTreeLength); + if (!EFI_ERROR(DTLookupEntry(NULL, "/chosen/memory-map", &MemMap))) { DBG("Found /chosen/memory-map\n"); - if (DTCreatePropertyIteratorNoAlloc(MemMap, PropIter) == kSuccess) { + if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) { DBG("DTCreatePropertyIterator OK\n"); - while (DTIterateProperties(PropIter, &PropName) == kSuccess) { + while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) { DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length); // all /chosen/memory-map props have DTMemMapEntry (address, length) // values. we need to correct the address @@ -801,8 +802,8 @@ DevTreeFix(BootArgs *BA) // second check - Address is in our reloc block // (note: *BA->kaddr is not fixed yet and points to reloc block) - if ((PropValue->Address < *BA->kaddr) - || (PropValue->Address >= *BA->kaddr + *BA->ksize)) + if ((PropValue->Address < *BA->kaddr) || + (PropValue->Address >= *BA->kaddr + *BA->ksize)) { DBG("DTMemMapEntry->Address is not in reloc block, skipping\n"); continue; @@ -828,7 +829,7 @@ DevTreeFix(BootArgs *BA) } -/** boot.efi zerod original RT areas after they were relocated to new place. +/** boot.efi zeroed original RT areas after they were relocated to new place. * This breaks sleep on some UEFIs and we'll return the content back. * We'll find previous RT areas by reusing gVirtualMemoryMap. * diff --git a/MemoryFix/OsxAptioFixDrv/FlatDevTree/device_tree.c b/MemoryFix/OsxAptioFixDrv/FlatDevTree/device_tree.c index 99ea3333f..370bee088 100644 --- a/MemoryFix/OsxAptioFixDrv/FlatDevTree/device_tree.c +++ b/MemoryFix/OsxAptioFixDrv/FlatDevTree/device_tree.c @@ -191,7 +191,9 @@ INTN find_entry(CONST CHAR8 *propName, CONST CHAR8 *propValue, DTEntry *entryH) } return(kError); } + //if(DTLookupEntry(NULL,"/",&efiPlatform)==kSuccess) + INTN DTLookupEntry(CONST DTEntry searchPoint, CONST CHAR8 *pathName, DTEntry *foundEntry) { diff --git a/MemoryFix/OsxAptioFixDrv/Lib.c b/MemoryFix/OsxAptioFixDrv/Lib.c index 8faf829e2..e0ad4d2b7 100644 --- a/MemoryFix/OsxAptioFixDrv/Lib.c +++ b/MemoryFix/OsxAptioFixDrv/Lib.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/MemoryFix/OsxAptioFixDrv/OsxAptioFix2Drv.inf b/MemoryFix/OsxAptioFixDrv/OsxAptioFix2Drv.inf index 59cc6a37b..dcb0ecc3a 100644 --- a/MemoryFix/OsxAptioFixDrv/OsxAptioFix2Drv.inf +++ b/MemoryFix/OsxAptioFixDrv/OsxAptioFix2Drv.inf @@ -29,6 +29,7 @@ BaseLib CpuLib DevicePathLib + DeviceTreeLib [Sources] OsxAptioFix2Drv.c @@ -43,8 +44,8 @@ VMem.h Lib.c Lib.h - FlatDevTree/device_tree.h - FlatDevTree/device_tree.c +# FlatDevTree/device_tree.h +# FlatDevTree/device_tree.c NVRAMDebug.h NVRAMDebug.c Mach-O/UefiLoader.h diff --git a/MemoryFix/OsxAptioFixDrv/OsxAptioFix3Drv.inf b/MemoryFix/OsxAptioFixDrv/OsxAptioFix3Drv.inf index 88eea2b56..a39950c2d 100644 --- a/MemoryFix/OsxAptioFixDrv/OsxAptioFix3Drv.inf +++ b/MemoryFix/OsxAptioFixDrv/OsxAptioFix3Drv.inf @@ -29,6 +29,7 @@ BaseLib CpuLib DevicePathLib + DeviceTreeLib [Sources] OsxAptioFix3Drv.c @@ -43,8 +44,8 @@ VMem.h Lib.c Lib.h - FlatDevTree/device_tree.h - FlatDevTree/device_tree.c +# FlatDevTree/device_tree.h +# FlatDevTree/device_tree.c NVRAMDebug.h NVRAMDebug.c Mach-O/UefiLoader.h diff --git a/MemoryFix/OsxAptioFixDrv/OsxAptioFixDrv.inf b/MemoryFix/OsxAptioFixDrv/OsxAptioFixDrv.inf index 27dcd0a79..e34b4f78a 100644 --- a/MemoryFix/OsxAptioFixDrv/OsxAptioFixDrv.inf +++ b/MemoryFix/OsxAptioFixDrv/OsxAptioFixDrv.inf @@ -29,6 +29,7 @@ BaseLib CpuLib DevicePathLib + DeviceTreeLib [Sources] OsxAptioFixDrv.c @@ -43,8 +44,8 @@ VMem.h Lib.c Lib.h - FlatDevTree/device_tree.h - FlatDevTree/device_tree.c +# FlatDevTree/device_tree.h +# FlatDevTree/device_tree.c NVRAMDebug.h NVRAMDebug.c Mach-O/UefiLoader.h diff --git a/MemoryFix/OsxLowMemFixDrv/Lib.c b/MemoryFix/OsxLowMemFixDrv/Lib.c index 4e869cba0..432dbb4ee 100644 --- a/MemoryFix/OsxLowMemFixDrv/Lib.c +++ b/MemoryFix/OsxLowMemFixDrv/Lib.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/Protocols/DumpUefiCalls/Lib.c b/Protocols/DumpUefiCalls/Lib.c index 161376ca9..1a82bc383 100644 --- a/Protocols/DumpUefiCalls/Lib.c +++ b/Protocols/DumpUefiCalls/Lib.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/rEFIt_UEFI/Platform/Platform.h b/rEFIt_UEFI/Platform/Platform.h index 327161d20..a1827c9b8 100644 --- a/rEFIt_UEFI/Platform/Platform.h +++ b/rEFIt_UEFI/Platform/Platform.h @@ -22,6 +22,7 @@ Headers collection for procedures #include #include #include +#include #include #include #include diff --git a/rEFIt_UEFI/Platform/kernel_patcher.c b/rEFIt_UEFI/Platform/kernel_patcher.c index 7861b4427..115443155 100644 --- a/rEFIt_UEFI/Platform/kernel_patcher.c +++ b/rEFIt_UEFI/Platform/kernel_patcher.c @@ -30,6 +30,7 @@ EFI_PHYSICAL_ADDRESS KernelRelocBase = 0; BootArgs1 *bootArgs1 = NULL; BootArgs2 *bootArgs2 = NULL; CHAR8 *dtRoot = NULL; +UINT32 *dtLength; VOID *KernelData = NULL; UINT32 KernelSlide = 0; BOOLEAN isKernelcache = FALSE; @@ -1677,6 +1678,7 @@ FindBootArgs(IN LOADER_ENTRY *Entry) ) { // set vars dtRoot = (CHAR8*)(UINTN)bootArgs2->deviceTreeP; + dtLength = bootArgs2->deviceTreeLength; KernelSlide = bootArgs2->kslide; DBG_RT(Entry, "Found bootArgs2 at 0x%08x, DevTree at %p\n", ptr, dtRoot); @@ -1706,6 +1708,7 @@ FindBootArgs(IN LOADER_ENTRY *Entry) ) { // set vars dtRoot = (CHAR8*)(UINTN)bootArgs1->deviceTreeP; + dtLength = bootArgs1->deviceTreeLength; DBG_RT(Entry, "Found bootArgs1 at 0x%08x, DevTree at %p\n", ptr, dtRoot); //DBG("bootArgs1->kaddr = 0x%08x and bootArgs1->ksize = 0x%08x\n", bootArgs1->kaddr, bootArgs1->ksize); diff --git a/rEFIt_UEFI/Platform/kernel_patcher.h b/rEFIt_UEFI/Platform/kernel_patcher.h index 47fa0594a..c61e0f886 100644 --- a/rEFIt_UEFI/Platform/kernel_patcher.h +++ b/rEFIt_UEFI/Platform/kernel_patcher.h @@ -76,6 +76,7 @@ extern EFI_PHYSICAL_ADDRESS KernelRelocBase; extern BootArgs1 *bootArgs1; extern BootArgs2 *bootArgs2; extern CHAR8 *dtRoot; +extern UINT32 *dtLength; extern VOID *KernelData; extern UINT32 KernelSlide; extern BOOLEAN isKernelcache; diff --git a/rEFIt_UEFI/Platform/kext_inject.c b/rEFIt_UEFI/Platform/kext_inject.c index 5617b8c48..0fbbb4107 100644 --- a/rEFIt_UEFI/Platform/kext_inject.c +++ b/rEFIt_UEFI/Platform/kext_inject.c @@ -563,7 +563,7 @@ EFI_STATUS LoadKexts(IN LOADER_ENTRY *Entry) EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, IN UINT32* deviceTreeLength, LOADER_ENTRY *Entry) { UINT8 *dtEntry = (UINT8*)(UINTN) deviceTreeP; - UINTN dtLength = (UINTN) *deviceTreeLength; + UINTN dtLen = (UINTN) *deviceTreeLength; DTEntry platformEntry; DTEntry memmapEntry; @@ -609,10 +609,10 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, // drvinfo->executablePhysAddr += (UINT32)kextsBase; // drvinfo->bundlePathPhysAddr += (UINT32)kextsBase; - DTInit(dtEntry); - if(DTLookupEntry(NULL,"/chosen/memory-map",&memmapEntry)==kSuccess) { - if(DTCreatePropertyIteratorNoAlloc(memmapEntry,iter)==kSuccess) { - while(DTIterateProperties(iter,&ptr)==kSuccess) { + DTInit(dtEntry, deviceTreeLength); + if(!EFI_ERROR(DTLookupEntry(NULL,"/chosen/memory-map",&memmapEntry))) { + if(!EFI_ERROR(DTCreatePropertyIterator(memmapEntry,iter))) { + while(!EFI_ERROR(DTIterateProperties(iter,&ptr))) { prop = iter->currentProperty; drvPtr = (UINT8*) prop; if(AsciiStrnCmp(prop->name, "Driver-", 7)==0 || AsciiStrnCmp(prop->name, "DriversPackage-", 15)==0) { @@ -622,14 +622,14 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, } } - if(DTLookupEntry(NULL,"/efi/platform",&platformEntry)==kSuccess) { - if(DTCreatePropertyIteratorNoAlloc(platformEntry,iter)==kSuccess) { - while(DTIterateProperties(iter,&ptr)==kSuccess) { + if(!EFI_ERROR(DTLookupEntry(NULL,"/efi/platform",&platformEntry))) { + if(!EFI_ERROR(DTCreatePropertyIterator(platformEntry,iter))) { + while(!EFI_ERROR(DTIterateProperties(iter,&ptr))) { prop = iter->currentProperty; - if(AsciiStrCmp(prop->name,"mm_extra")==0) { + if(AsciiStrnCmp(prop->name, "mm_extra", 8)==0) { infoPtr = (UINT8*) prop; } - if(AsciiStrCmp(prop->name,"extra")==0) { + if(AsciiStrnCmp(prop->name, "extra", 5)==0) { extraPtr = (UINT8*) prop; } } @@ -650,7 +650,7 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, // make space behind device tree // platformEntry->nProperties--; offset = sizeof(DeviceTreeNodeProperty)+((DeviceTreeNodeProperty*) extraPtr)->length; - CopyMem(extraPtr, extraPtr+offset, dtLength-(UINTN)(extraPtr-dtEntry)-offset); + CopyMem(extraPtr, extraPtr+offset, dtLen-(UINTN)(extraPtr-dtEntry)-offset); *deviceTreeLength -= (UINT32)offset; KextBase = RoundPage(dtEntry + *deviceTreeLength); diff --git a/rEFIt_UEFI/Platform/kext_patcher.c b/rEFIt_UEFI/Platform/kext_patcher.c index a96cccbb7..1c9a67019 100644 --- a/rEFIt_UEFI/Platform/kext_patcher.c +++ b/rEFIt_UEFI/Platform/kext_patcher.c @@ -1384,15 +1384,15 @@ VOID PatchLoadedKexts(LOADER_ENTRY *Entry) DBG(L"\nPatchLoadedKexts ... dtRoot = %p\n", dtRoot); - if (!dtRoot) { + if (!dtRoot || !dtLength) { return; } - DTInit(dtRoot); + DTInit(dtRoot, dtLength); - if (DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry) == kSuccess) { - if (DTCreatePropertyIteratorNoAlloc(MMEntry, PropIter) == kSuccess) { - while (DTIterateProperties(PropIter, &PropName) == kSuccess) { + if (!EFI_ERROR(DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry))) { + if (!EFI_ERROR(DTCreatePropertyIterator(MMEntry, PropIter))) { + while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) { //DBG(L"Prop: %a\n", PropName); if (AsciiStrStr(PropName,"Driver-")) { // PropEntry _DeviceTreeBuffer is the value of Driver-XXXXXX property @@ -1415,11 +1415,7 @@ VOID PatchLoadedKexts(LOADER_ENTRY *Entry) Entry ); - // Check for FakeSMC here - // CheckForFakeSMC(InfoPlist, Entry); //Slice - no reason to check loaded kext to disable load kexts - InfoPlist[KextFileInfo->infoDictLength] = SavedValue; - //DbgCount++; } //if(AsciiStrStr(PropName,"DriversPackage-")!=0) //{ diff --git a/rEFIt_UEFI/libeg/libeg.h b/rEFIt_UEFI/libeg/libeg.h index 2a070b4fe..43f0e0436 100644 --- a/rEFIt_UEFI/libeg/libeg.h +++ b/rEFIt_UEFI/libeg/libeg.h @@ -102,6 +102,7 @@ #include #include #include +#include #include #include //#include diff --git a/rEFIt_UEFI/refit.inf b/rEFIt_UEFI/refit.inf index 96664682b..f5b88118c 100644 --- a/rEFIt_UEFI/refit.inf +++ b/rEFIt_UEFI/refit.inf @@ -98,8 +98,8 @@ # Platform/DataHubRecords.h Platform/device_inject.c Platform/device_inject.h - Platform/device_tree.c - Platform/device_tree.h +# Platform/device_tree.c +# Platform/device_tree.h Platform/Edid.c Platform/Events.c Platform/hda.c @@ -178,6 +178,7 @@ BaseMemoryLib BaseLib DevicePathLib + DeviceTreeLib DebugLib DxeServicesLib DxeServicesTableLib