use unified DeviceTreeLib

Signed-off-by: Сергей Исаков <sergey@Sergejs-iMac.local>
This commit is contained in:
SergeySlice 2019-12-18 20:34:26 +03:00
parent 6c7ec5f7c5
commit 0979cd808a
17 changed files with 59 additions and 47 deletions

View File

@ -468,7 +468,7 @@ DumpDeviceTreeNodeRecusively (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
PropertyParent = "/"; 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) { if ((Status = DTGetProperty (Entry, (CHAR8 *)PropertyName, (void *)&PropertyValue, &PropertySize)) != EFI_SUCCESS) {
DEBUG ((DEBUG_WARN, "DeviceTree is probably invalid - %r\n", Status)); DEBUG ((DEBUG_WARN, "DeviceTree is probably invalid - %r\n", Status));
break; break;
@ -553,7 +553,7 @@ DumpDeviceTree (
/// ///
/// ///
/// @param[in] Base Pointer to the Device Tree /// @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 VOID

View File

@ -610,12 +610,12 @@ DevTreeFix(BootArgs *BA)
DBG("Fixing DevTree at %p\n", DevTree); DBG("Fixing DevTree at %p\n", DevTree);
DBGnvr("Fixing DevTree at %p\n", DevTree); DBGnvr("Fixing DevTree at %p\n", DevTree);
DTInit(DevTree); DTInit(DevTree, BA->deviceTreeLength);
if (DTLookupEntry(NULL, "/chosen/memory-map", &MemMap) == kSuccess) { if (!EFI_ERROR(DTLookupEntry(NULL, "/chosen/memory-map", &MemMap))) {
DBG("Found /chosen/memory-map\n"); DBG("Found /chosen/memory-map\n");
if (DTCreatePropertyIteratorNoAlloc(MemMap, PropIter) == kSuccess) { if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) {
DBG("DTCreatePropertyIterator OK\n"); DBG("DTCreatePropertyIterator OK\n");
while (DTIterateProperties(PropIter, &PropName) == kSuccess) { while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) {
DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length); DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length);
// all /chosen/memory-map props have DTMemMapEntry (address, length) // all /chosen/memory-map props have DTMemMapEntry (address, length)
// values. we need to correct the address // values. we need to correct the address

View File

@ -765,25 +765,26 @@ RuntimeServicesFix(BootArgs *BA)
VOID VOID
DevTreeFix(BootArgs *BA) DevTreeFix(BootArgs *BA)
{ {
DTEntry DevTree; DTEntry DevTree;
DTEntry MemMap; DTEntry MemMap;
struct OpaqueDTPropertyIterator OPropIter; CHAR8 *PropName;
DTPropertyIterator PropIter = &OPropIter; DTMemMapEntry *PropValue;
CHAR8 *PropName;
DTMemMapEntry *PropValue;
BooterKextFileInfo *KextInfo; BooterKextFileInfo *KextInfo;
struct OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator PropIter = &OPropIter;
DevTree = (DTEntry)(UINTN)(*BA->deviceTreeP); DevTree = (DTEntry)(UINTN)(*BA->deviceTreeP);
DBG("Fixing DevTree at %p\n", DevTree); DBG("Fixing DevTree at %p\n", DevTree);
DBGnvr("Fixing DevTree at %p\n", DevTree); DBGnvr("Fixing DevTree at %p\n", DevTree);
DTInit(DevTree); DTInit(DevTree, BA->deviceTreeLength);
if (DTLookupEntry(NULL, "/chosen/memory-map", &MemMap) == kSuccess) { if (!EFI_ERROR(DTLookupEntry(NULL, "/chosen/memory-map", &MemMap))) {
DBG("Found /chosen/memory-map\n"); DBG("Found /chosen/memory-map\n");
if (DTCreatePropertyIteratorNoAlloc(MemMap, PropIter) == kSuccess) { if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) {
DBG("DTCreatePropertyIterator OK\n"); DBG("DTCreatePropertyIterator OK\n");
while (DTIterateProperties(PropIter, &PropName) == kSuccess) { while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) {
DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length); DBG("= %a, val len=%d: ", PropName, PropIter->currentProperty->length);
// all /chosen/memory-map props have DTMemMapEntry (address, length) // all /chosen/memory-map props have DTMemMapEntry (address, length)
// values. we need to correct the address // values. we need to correct the address
@ -801,8 +802,8 @@ DevTreeFix(BootArgs *BA)
// second check - Address is in our reloc block // second check - Address is in our reloc block
// (note: *BA->kaddr is not fixed yet and points to reloc block) // (note: *BA->kaddr is not fixed yet and points to reloc block)
if ((PropValue->Address < *BA->kaddr) if ((PropValue->Address < *BA->kaddr) ||
|| (PropValue->Address >= *BA->kaddr + *BA->ksize)) (PropValue->Address >= *BA->kaddr + *BA->ksize))
{ {
DBG("DTMemMapEntry->Address is not in reloc block, skipping\n"); DBG("DTMemMapEntry->Address is not in reloc block, skipping\n");
continue; 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. * This breaks sleep on some UEFIs and we'll return the content back.
* We'll find previous RT areas by reusing gVirtualMemoryMap. * We'll find previous RT areas by reusing gVirtualMemoryMap.
* *

View File

@ -191,7 +191,9 @@ INTN find_entry(CONST CHAR8 *propName, CONST CHAR8 *propValue, DTEntry *entryH)
} }
return(kError); return(kError);
} }
//if(DTLookupEntry(NULL,"/",&efiPlatform)==kSuccess) //if(DTLookupEntry(NULL,"/",&efiPlatform)==kSuccess)
INTN INTN
DTLookupEntry(CONST DTEntry searchPoint, CONST CHAR8 *pathName, DTEntry *foundEntry) DTLookupEntry(CONST DTEntry searchPoint, CONST CHAR8 *pathName, DTEntry *foundEntry)
{ {

View File

@ -14,6 +14,7 @@
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PrintLib.h> #include <Library/PrintLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DeviceTreeLib.h>
#include <Protocol/LoadedImage.h> #include <Protocol/LoadedImage.h>
#include <Protocol/BlockIo.h> #include <Protocol/BlockIo.h>

View File

@ -29,6 +29,7 @@
BaseLib BaseLib
CpuLib CpuLib
DevicePathLib DevicePathLib
DeviceTreeLib
[Sources] [Sources]
OsxAptioFix2Drv.c OsxAptioFix2Drv.c
@ -43,8 +44,8 @@
VMem.h VMem.h
Lib.c Lib.c
Lib.h Lib.h
FlatDevTree/device_tree.h # FlatDevTree/device_tree.h
FlatDevTree/device_tree.c # FlatDevTree/device_tree.c
NVRAMDebug.h NVRAMDebug.h
NVRAMDebug.c NVRAMDebug.c
Mach-O/UefiLoader.h Mach-O/UefiLoader.h

View File

@ -29,6 +29,7 @@
BaseLib BaseLib
CpuLib CpuLib
DevicePathLib DevicePathLib
DeviceTreeLib
[Sources] [Sources]
OsxAptioFix3Drv.c OsxAptioFix3Drv.c
@ -43,8 +44,8 @@
VMem.h VMem.h
Lib.c Lib.c
Lib.h Lib.h
FlatDevTree/device_tree.h # FlatDevTree/device_tree.h
FlatDevTree/device_tree.c # FlatDevTree/device_tree.c
NVRAMDebug.h NVRAMDebug.h
NVRAMDebug.c NVRAMDebug.c
Mach-O/UefiLoader.h Mach-O/UefiLoader.h

View File

@ -29,6 +29,7 @@
BaseLib BaseLib
CpuLib CpuLib
DevicePathLib DevicePathLib
DeviceTreeLib
[Sources] [Sources]
OsxAptioFixDrv.c OsxAptioFixDrv.c
@ -43,8 +44,8 @@
VMem.h VMem.h
Lib.c Lib.c
Lib.h Lib.h
FlatDevTree/device_tree.h # FlatDevTree/device_tree.h
FlatDevTree/device_tree.c # FlatDevTree/device_tree.c
NVRAMDebug.h NVRAMDebug.h
NVRAMDebug.c NVRAMDebug.c
Mach-O/UefiLoader.h Mach-O/UefiLoader.h

View File

@ -14,6 +14,7 @@
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PrintLib.h> #include <Library/PrintLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DeviceTreeLib.h>
#include <Protocol/LoadedImage.h> #include <Protocol/LoadedImage.h>
#include <Protocol/BlockIo.h> #include <Protocol/BlockIo.h>

View File

@ -14,6 +14,7 @@
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PrintLib.h> #include <Library/PrintLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DeviceTreeLib.h>
#include <Protocol/LoadedImage.h> #include <Protocol/LoadedImage.h>
#include <Protocol/BlockIo.h> #include <Protocol/BlockIo.h>

View File

@ -22,6 +22,7 @@ Headers collection for procedures
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DeviceTreeLib.h>
#include <Library/GenericBdsLib.h> #include <Library/GenericBdsLib.h>
#include <Library/HiiLib.h> #include <Library/HiiLib.h>
#include <Library/HdaModels.h> #include <Library/HdaModels.h>

View File

@ -30,6 +30,7 @@ EFI_PHYSICAL_ADDRESS KernelRelocBase = 0;
BootArgs1 *bootArgs1 = NULL; BootArgs1 *bootArgs1 = NULL;
BootArgs2 *bootArgs2 = NULL; BootArgs2 *bootArgs2 = NULL;
CHAR8 *dtRoot = NULL; CHAR8 *dtRoot = NULL;
UINT32 *dtLength;
VOID *KernelData = NULL; VOID *KernelData = NULL;
UINT32 KernelSlide = 0; UINT32 KernelSlide = 0;
BOOLEAN isKernelcache = FALSE; BOOLEAN isKernelcache = FALSE;
@ -1677,6 +1678,7 @@ FindBootArgs(IN LOADER_ENTRY *Entry)
) { ) {
// set vars // set vars
dtRoot = (CHAR8*)(UINTN)bootArgs2->deviceTreeP; dtRoot = (CHAR8*)(UINTN)bootArgs2->deviceTreeP;
dtLength = bootArgs2->deviceTreeLength;
KernelSlide = bootArgs2->kslide; KernelSlide = bootArgs2->kslide;
DBG_RT(Entry, "Found bootArgs2 at 0x%08x, DevTree at %p\n", ptr, dtRoot); 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 // set vars
dtRoot = (CHAR8*)(UINTN)bootArgs1->deviceTreeP; dtRoot = (CHAR8*)(UINTN)bootArgs1->deviceTreeP;
dtLength = bootArgs1->deviceTreeLength;
DBG_RT(Entry, "Found bootArgs1 at 0x%08x, DevTree at %p\n", ptr, dtRoot); 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); //DBG("bootArgs1->kaddr = 0x%08x and bootArgs1->ksize = 0x%08x\n", bootArgs1->kaddr, bootArgs1->ksize);

View File

@ -76,6 +76,7 @@ extern EFI_PHYSICAL_ADDRESS KernelRelocBase;
extern BootArgs1 *bootArgs1; extern BootArgs1 *bootArgs1;
extern BootArgs2 *bootArgs2; extern BootArgs2 *bootArgs2;
extern CHAR8 *dtRoot; extern CHAR8 *dtRoot;
extern UINT32 *dtLength;
extern VOID *KernelData; extern VOID *KernelData;
extern UINT32 KernelSlide; extern UINT32 KernelSlide;
extern BOOLEAN isKernelcache; extern BOOLEAN isKernelcache;

View File

@ -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) EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, IN UINT32* deviceTreeLength, LOADER_ENTRY *Entry)
{ {
UINT8 *dtEntry = (UINT8*)(UINTN) deviceTreeP; UINT8 *dtEntry = (UINT8*)(UINTN) deviceTreeP;
UINTN dtLength = (UINTN) *deviceTreeLength; UINTN dtLen = (UINTN) *deviceTreeLength;
DTEntry platformEntry; DTEntry platformEntry;
DTEntry memmapEntry; DTEntry memmapEntry;
@ -609,10 +609,10 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP,
// drvinfo->executablePhysAddr += (UINT32)kextsBase; // drvinfo->executablePhysAddr += (UINT32)kextsBase;
// drvinfo->bundlePathPhysAddr += (UINT32)kextsBase; // drvinfo->bundlePathPhysAddr += (UINT32)kextsBase;
DTInit(dtEntry); DTInit(dtEntry, deviceTreeLength);
if(DTLookupEntry(NULL,"/chosen/memory-map",&memmapEntry)==kSuccess) { if(!EFI_ERROR(DTLookupEntry(NULL,"/chosen/memory-map",&memmapEntry))) {
if(DTCreatePropertyIteratorNoAlloc(memmapEntry,iter)==kSuccess) { if(!EFI_ERROR(DTCreatePropertyIterator(memmapEntry,iter))) {
while(DTIterateProperties(iter,&ptr)==kSuccess) { while(!EFI_ERROR(DTIterateProperties(iter,&ptr))) {
prop = iter->currentProperty; prop = iter->currentProperty;
drvPtr = (UINT8*) prop; drvPtr = (UINT8*) prop;
if(AsciiStrnCmp(prop->name, "Driver-", 7)==0 || AsciiStrnCmp(prop->name, "DriversPackage-", 15)==0) { 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(!EFI_ERROR(DTLookupEntry(NULL,"/efi/platform",&platformEntry))) {
if(DTCreatePropertyIteratorNoAlloc(platformEntry,iter)==kSuccess) { if(!EFI_ERROR(DTCreatePropertyIterator(platformEntry,iter))) {
while(DTIterateProperties(iter,&ptr)==kSuccess) { while(!EFI_ERROR(DTIterateProperties(iter,&ptr))) {
prop = iter->currentProperty; prop = iter->currentProperty;
if(AsciiStrCmp(prop->name,"mm_extra")==0) { if(AsciiStrnCmp(prop->name, "mm_extra", 8)==0) {
infoPtr = (UINT8*) prop; infoPtr = (UINT8*) prop;
} }
if(AsciiStrCmp(prop->name,"extra")==0) { if(AsciiStrnCmp(prop->name, "extra", 5)==0) {
extraPtr = (UINT8*) prop; extraPtr = (UINT8*) prop;
} }
} }
@ -650,7 +650,7 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP,
// make space behind device tree // make space behind device tree
// platformEntry->nProperties--; // platformEntry->nProperties--;
offset = sizeof(DeviceTreeNodeProperty)+((DeviceTreeNodeProperty*) extraPtr)->length; 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; *deviceTreeLength -= (UINT32)offset;
KextBase = RoundPage(dtEntry + *deviceTreeLength); KextBase = RoundPage(dtEntry + *deviceTreeLength);

View File

@ -1384,15 +1384,15 @@ VOID PatchLoadedKexts(LOADER_ENTRY *Entry)
DBG(L"\nPatchLoadedKexts ... dtRoot = %p\n", dtRoot); DBG(L"\nPatchLoadedKexts ... dtRoot = %p\n", dtRoot);
if (!dtRoot) { if (!dtRoot || !dtLength) {
return; return;
} }
DTInit(dtRoot); DTInit(dtRoot, dtLength);
if (DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry) == kSuccess) { if (!EFI_ERROR(DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry))) {
if (DTCreatePropertyIteratorNoAlloc(MMEntry, PropIter) == kSuccess) { if (!EFI_ERROR(DTCreatePropertyIterator(MMEntry, PropIter))) {
while (DTIterateProperties(PropIter, &PropName) == kSuccess) { while (!EFI_ERROR(DTIterateProperties(PropIter, &PropName))) {
//DBG(L"Prop: %a\n", PropName); //DBG(L"Prop: %a\n", PropName);
if (AsciiStrStr(PropName,"Driver-")) { if (AsciiStrStr(PropName,"Driver-")) {
// PropEntry _DeviceTreeBuffer is the value of Driver-XXXXXX property // PropEntry _DeviceTreeBuffer is the value of Driver-XXXXXX property
@ -1415,11 +1415,7 @@ VOID PatchLoadedKexts(LOADER_ENTRY *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; InfoPlist[KextFileInfo->infoDictLength] = SavedValue;
//DbgCount++;
} }
//if(AsciiStrStr(PropName,"DriversPackage-")!=0) //if(AsciiStrStr(PropName,"DriversPackage-")!=0)
//{ //{

View File

@ -102,6 +102,7 @@
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/DeviceTreeLib.h>
#include <Library/DxeServicesLib.h> #include <Library/DxeServicesLib.h>
#include <Library/DxeServicesTableLib.h> #include <Library/DxeServicesTableLib.h>
//#include <Library/EblCmdLib.h> //#include <Library/EblCmdLib.h>

View File

@ -98,8 +98,8 @@
# Platform/DataHubRecords.h # Platform/DataHubRecords.h
Platform/device_inject.c Platform/device_inject.c
Platform/device_inject.h Platform/device_inject.h
Platform/device_tree.c # Platform/device_tree.c
Platform/device_tree.h # Platform/device_tree.h
Platform/Edid.c Platform/Edid.c
Platform/Events.c Platform/Events.c
Platform/hda.c Platform/hda.c
@ -178,6 +178,7 @@
BaseMemoryLib BaseMemoryLib
BaseLib BaseLib
DevicePathLib DevicePathLib
DeviceTreeLib
DebugLib DebugLib
DxeServicesLib DxeServicesLib
DxeServicesTableLib DxeServicesTableLib