adopt to new DeviceTree declarstions

Signed-off-by: SergeySlice <isakov-sl@bk.ru>
This commit is contained in:
SergeySlice 2019-12-18 21:41:07 +03:00
parent 56ec54a919
commit 49380a97ec
13 changed files with 256 additions and 247 deletions

View File

@ -63,6 +63,9 @@ typedef OpaqueDTEntryIterator *DTEntryIterator;
typedef struct OpaqueDTPropertyIterator_ OpaqueDTPropertyIterator;
typedef OpaqueDTPropertyIterator *DTPropertyIterator;
//Old compatibility
typedef DTProperty DeviceTreeNodeProperty;
//
// Structures for a Flattened Device Tree.
//

View File

@ -11,13 +11,14 @@
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DeviceTreeLib.h>
#include "BootFixes.h"
#include "AsmFuncs.h"
#include "BootArgs.h"
#include "VMem.h"
#include "Lib.h"
#include "FlatDevTree/device_tree.h"
//#include "FlatDevTree/device_tree.h"
#include "Mach-O/Mach-O.h"
#include "Hibernate.h"
#include "NVRAMDebug.h"
@ -599,12 +600,12 @@ DevTreeFix(BootArgs *BA)
{
DTEntry DevTree;
DTEntry MemMap;
struct OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator PropIter = &OPropIter;
CHAR8 *PropName;
DTMemMapEntry *PropValue;
BooterKextFileInfo *KextInfo;
OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator PropIter = &OPropIter;
DevTree = (DTEntry)(UINTN)(*BA->deviceTreeP);
@ -613,22 +614,22 @@ DevTreeFix(BootArgs *BA)
DTInit(DevTree, BA->deviceTreeLength);
if (!EFI_ERROR(DTLookupEntry(NULL, "/chosen/memory-map", &MemMap))) {
DBG("Found /chosen/memory-map\n");
if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) {
if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, &OPropIter))) {
DBG("DTCreatePropertyIterator OK\n");
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)
// values. we need to correct the address
// basic check that value is 2 * UINT32
if (PropIter->currentProperty->length != 2 * sizeof(UINT32)) {
if (PropIter->CurrentProperty->Length != 2 * sizeof(UINT32)) {
// not DTMemMapEntry, usually "name" property
DBG("NOT DTMemMapEntry\n");
continue;
}
// get value (Address and Length)
PropValue = (DTMemMapEntry*)(((UINT8*)PropIter->currentProperty) + sizeof(DeviceTreeNodeProperty));
PropValue = (DTMemMapEntry*)(((UINT8*)PropIter->CurrentProperty) + sizeof(DeviceTreeNodeProperty));
DBG("MM Addr = %x, Len = %x ", PropValue->Address, PropValue->Length);
// second check - Address is in our reloc block

View File

@ -1,90 +1,91 @@
/**
Methods for setting callback jump from kernel entry point, callback, fixes to kernel boot image.
by dmazar
**/
/* DevTree may contain /chosen/memory-map
* with properties with values = UINT32 address, UINT32 length:
* "BootCLUT" = 8bit boot time colour lookup table
* "Pict-FailedBoot" = picture shown if booting fails
* "RAMDisk" = ramdisk
* "Driver-<hex addr of DriverInfo>" = Kext, UINT32 address points to BooterKextFileInfo
* "DriversPackage-..." = MKext, UINT32 address points to mkext_header (libkern/libkern/mkext.h), UINT32 length
*
*/
#define BOOTER_KEXT_PREFIX "Driver-"
#define BOOTER_MKEXT_PREFIX "DriversPackage-"
#define BOOTER_RAMDISK_PREFIX "RAMDisk"
/** Struct at the beginning of every loaded kext.
* Pointers to every loaded kext (to this struct) are
* properties Driver-<hex addr of DriverInfo> in DevTree /chosen/memory-map
*/
typedef struct _BooterKextFileInfo {
UINT32 infoDictPhysAddr;
UINT32 infoDictLength;
UINT32 executablePhysAddr;
UINT32 executableLength;
UINT32 bundlePathPhysAddr;
UINT32 bundlePathLength;
} BooterKextFileInfo;
struct DTMemMapEntry {
UINT32 Address;
UINT32 Length;
};
typedef struct DTMemMapEntry DTMemMapEntry;
extern EFI_PHYSICAL_ADDRESS gRelocBase;
extern EFI_PHYSICAL_ADDRESS gSysTableRtArea;
extern BOOLEAN gHibernateWake;
extern UINTN gLastMemoryMapSize;
extern EFI_MEMORY_DESCRIPTOR *gLastMemoryMap;
extern UINTN gLastDescriptorSize;
extern UINT32 gLastDescriptorVersion;
EFI_STATUS PrepareJumpFromKernel(VOID);
EFI_STATUS KernelEntryPatchJump(UINT32 KernelEntry);
EFI_STATUS KernelEntryFromMachOPatchJump(VOID *MachOImage, UINTN SlideAddr);
//EFI_STATUS KernelEntryPatchJumpFill(VOID);
EFI_STATUS KernelEntryPatchHalt(UINT32 KernelEntry);
EFI_STATUS KernelEntryPatchZero(UINT32 KernelEntry);
EFI_STATUS
ExecSetVirtualAddressesToMemMap(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
CopyEfiSysTableToSeparateRtDataArea(IN OUT UINT32 *EfiSystemTable);
VOID
ProtectRtDataFromRelocation(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
DefragmentRuntimeServices(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap,
IN OUT UINT32 *EfiSystemTable,
IN BOOLEAN SkipOurSysTableRtArea
);
/** Fixes stuff for booting with relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithoutRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for hibernate wake booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixHibernateWakeWithoutRelocBlock(UINTN imageHeaderPage, BOOLEAN ModeX64);
/**
Methods for setting callback jump from kernel entry point, callback, fixes to kernel boot image.
by dmazar
**/
/* DevTree may contain /chosen/memory-map
* with properties with values = UINT32 address, UINT32 length:
* "BootCLUT" = 8bit boot time colour lookup table
* "Pict-FailedBoot" = picture shown if booting fails
* "RAMDisk" = ramdisk
* "Driver-<hex addr of DriverInfo>" = Kext, UINT32 address points to BooterKextFileInfo
* "DriversPackage-..." = MKext, UINT32 address points to mkext_header (libkern/libkern/mkext.h), UINT32 length
*
*/
#define BOOTER_KEXT_PREFIX "Driver-"
#define BOOTER_MKEXT_PREFIX "DriversPackage-"
#define BOOTER_RAMDISK_PREFIX "RAMDisk"
/** Struct at the beginning of every loaded kext.
* Pointers to every loaded kext (to this struct) are
* properties Driver-<hex addr of DriverInfo> in DevTree /chosen/memory-map
*/
typedef struct _BooterKextFileInfo {
UINT32 infoDictPhysAddr;
UINT32 infoDictLength;
UINT32 executablePhysAddr;
UINT32 executableLength;
UINT32 bundlePathPhysAddr;
UINT32 bundlePathLength;
} BooterKextFileInfo;
/*
struct DTMemMapEntry {
UINT32 Address;
UINT32 Length;
};
typedef struct DTMemMapEntry DTMemMapEntry;
*/
extern EFI_PHYSICAL_ADDRESS gRelocBase;
extern EFI_PHYSICAL_ADDRESS gSysTableRtArea;
extern BOOLEAN gHibernateWake;
extern UINTN gLastMemoryMapSize;
extern EFI_MEMORY_DESCRIPTOR *gLastMemoryMap;
extern UINTN gLastDescriptorSize;
extern UINT32 gLastDescriptorVersion;
EFI_STATUS PrepareJumpFromKernel(VOID);
EFI_STATUS KernelEntryPatchJump(UINT32 KernelEntry);
EFI_STATUS KernelEntryFromMachOPatchJump(VOID *MachOImage, UINTN SlideAddr);
//EFI_STATUS KernelEntryPatchJumpFill(VOID);
EFI_STATUS KernelEntryPatchHalt(UINT32 KernelEntry);
EFI_STATUS KernelEntryPatchZero(UINT32 KernelEntry);
EFI_STATUS
ExecSetVirtualAddressesToMemMap(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
CopyEfiSysTableToSeparateRtDataArea(IN OUT UINT32 *EfiSystemTable);
VOID
ProtectRtDataFromRelocation(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
DefragmentRuntimeServices(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap,
IN OUT UINT32 *EfiSystemTable,
IN BOOLEAN SkipOurSysTableRtArea
);
/** Fixes stuff for booting with relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithoutRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for hibernate wake booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixHibernateWakeWithoutRelocBlock(UINTN imageHeaderPage, BOOLEAN ModeX64);

View File

@ -12,13 +12,14 @@
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DeviceTreeLib.h>
#include "BootFixes3.h"
#include "AsmFuncs.h"
#include "BootArgs.h"
#include "VMem.h"
#include "Lib.h"
#include "FlatDevTree/device_tree.h"
//#include "FlatDevTree/device_tree.h"
#include "Mach-O/Mach-O.h"
#include "Hibernate.h"
#include "NVRAMDebug.h"
@ -771,7 +772,7 @@ DevTreeFix(BootArgs *BA)
DTMemMapEntry *PropValue;
BooterKextFileInfo *KextInfo;
struct OpaqueDTPropertyIterator OPropIter;
OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator PropIter = &OPropIter;
@ -785,19 +786,19 @@ DevTreeFix(BootArgs *BA)
if (!EFI_ERROR(DTCreatePropertyIterator(MemMap, PropIter))) {
DBG("DTCreatePropertyIterator OK\n");
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)
// values. we need to correct the address
// basic check that value is 2 * UINT32
if (PropIter->currentProperty->length != 2 * sizeof(UINT32)) {
if (PropIter->CurrentProperty->Length != 2 * sizeof(UINT32)) {
// not DTMemMapEntry, usually "name" property
DBG("NOT DTMemMapEntry\n");
continue;
}
// get value (Address and Length)
PropValue = (DTMemMapEntry*)(((UINT8*)PropIter->currentProperty) + sizeof(DeviceTreeNodeProperty));
PropValue = (DTMemMapEntry*)(((UINT8*)PropIter->CurrentProperty) + sizeof(DeviceTreeNodeProperty));
DBG("MM Addr = %x, Len = %x ", PropValue->Address, PropValue->Length);
// second check - Address is in our reloc block

View File

@ -1,105 +1,105 @@
/**
Methods for setting callback jump from kernel entry point, callback, fixes to kernel boot image.
by dmazar
**/
/* DevTree may contain /chosen/memory-map
* with properties with values = UINT32 address, UINT32 length:
* "BootCLUT" = 8bit boot time colour lookup table
* "Pict-FailedBoot" = picture shown if booting fails
* "RAMDisk" = ramdisk
* "Driver-<hex addr of DriverInfo>" = Kext, UINT32 address points to BooterKextFileInfo
* "DriversPackage-..." = MKext, UINT32 address points to mkext_header (libkern/libkern/mkext.h), UINT32 length
*
*/
#define BOOTER_KEXT_PREFIX "Driver-"
#define BOOTER_MKEXT_PREFIX "DriversPackage-"
#define BOOTER_RAMDISK_PREFIX "RAMDisk"
/** Struct at the beginning of every loaded kext.
* Pointers to every loaded kext (to this struct) are
* properties Driver-<hex addr of DriverInfo> in DevTree /chosen/memory-map
*/
typedef struct _BooterKextFileInfo {
UINT32 infoDictPhysAddr;
UINT32 infoDictLength;
UINT32 executablePhysAddr;
UINT32 executableLength;
UINT32 bundlePathPhysAddr;
UINT32 bundlePathLength;
} BooterKextFileInfo;
struct DTMemMapEntry {
UINT32 Address;
UINT32 Length;
};
typedef struct DTMemMapEntry DTMemMapEntry;
typedef struct {
EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_MEMORY_TYPE Type;
} RT_RELOC_PROTECT_INFO;
typedef struct {
UINTN NumEntries;
RT_RELOC_PROTECT_INFO RelocInfo[50]; // You probably want to adapt this.
} RT_RELOC_PROTECT_DATA;
extern EFI_PHYSICAL_ADDRESS gRelocBase;
extern EFI_PHYSICAL_ADDRESS gSysTableRtArea;
extern BOOLEAN gHibernateWake;
extern UINTN gLastMemoryMapSize;
extern EFI_MEMORY_DESCRIPTOR *gLastMemoryMap;
extern UINTN gLastDescriptorSize;
extern UINT32 gLastDescriptorVersion;
EFI_STATUS PrepareJumpFromKernel(VOID);
EFI_STATUS KernelEntryPatchJump(UINT32 KernelEntry);
EFI_STATUS KernelEntryFromMachOPatchJump(VOID *MachOImage, UINTN SlideAddr);
//EFI_STATUS KernelEntryPatchJumpFill(VOID);
EFI_STATUS KernelEntryPatchHalt(UINT32 KernelEntry);
EFI_STATUS KernelEntryPatchZero(UINT32 KernelEntry);
EFI_STATUS
ExecSetVirtualAddressesToMemMap(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
CopyEfiSysTableToSeparateRtDataArea(IN OUT UINT32 *EfiSystemTable);
VOID
ProtectRtDataFromRelocation(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
VirtualizeRTShimPointers (UINTN MemoryMapSize, UINTN DescriptorSize, EFI_MEMORY_DESCRIPTOR *MemoryMap);
VOID
DefragmentRuntimeServices(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap,
IN OUT UINT32 *EfiSystemTable,
IN BOOLEAN SkipOurSysTableRtArea
);
/** Fixes stuff for booting with relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithoutRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for hibernate wake booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixHibernateWakeWithoutRelocBlock(UINTN imageHeaderPage, BOOLEAN ModeX64);
/**
Methods for setting callback jump from kernel entry point, callback, fixes to kernel boot image.
by dmazar
**/
/* DevTree may contain /chosen/memory-map
* with properties with values = UINT32 address, UINT32 length:
* "BootCLUT" = 8bit boot time colour lookup table
* "Pict-FailedBoot" = picture shown if booting fails
* "RAMDisk" = ramdisk
* "Driver-<hex addr of DriverInfo>" = Kext, UINT32 address points to BooterKextFileInfo
* "DriversPackage-..." = MKext, UINT32 address points to mkext_header (libkern/libkern/mkext.h), UINT32 length
*
*/
#define BOOTER_KEXT_PREFIX "Driver-"
#define BOOTER_MKEXT_PREFIX "DriversPackage-"
#define BOOTER_RAMDISK_PREFIX "RAMDisk"
/** Struct at the beginning of every loaded kext.
* Pointers to every loaded kext (to this struct) are
* properties Driver-<hex addr of DriverInfo> in DevTree /chosen/memory-map
*/
typedef struct _BooterKextFileInfo {
UINT32 infoDictPhysAddr;
UINT32 infoDictLength;
UINT32 executablePhysAddr;
UINT32 executableLength;
UINT32 bundlePathPhysAddr;
UINT32 bundlePathLength;
} BooterKextFileInfo;
/*
struct DTMemMapEntry {
UINT32 Address;
UINT32 Length;
};
typedef struct DTMemMapEntry DTMemMapEntry;
*/
typedef struct {
EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_MEMORY_TYPE Type;
} RT_RELOC_PROTECT_INFO;
typedef struct {
UINTN NumEntries;
RT_RELOC_PROTECT_INFO RelocInfo[50]; // You probably want to adapt this.
} RT_RELOC_PROTECT_DATA;
extern EFI_PHYSICAL_ADDRESS gRelocBase;
extern EFI_PHYSICAL_ADDRESS gSysTableRtArea;
extern BOOLEAN gHibernateWake;
extern UINTN gLastMemoryMapSize;
extern EFI_MEMORY_DESCRIPTOR *gLastMemoryMap;
extern UINTN gLastDescriptorSize;
extern UINT32 gLastDescriptorVersion;
EFI_STATUS PrepareJumpFromKernel(VOID);
EFI_STATUS KernelEntryPatchJump(UINT32 KernelEntry);
EFI_STATUS KernelEntryFromMachOPatchJump(VOID *MachOImage, UINTN SlideAddr);
//EFI_STATUS KernelEntryPatchJumpFill(VOID);
EFI_STATUS KernelEntryPatchHalt(UINT32 KernelEntry);
EFI_STATUS KernelEntryPatchZero(UINT32 KernelEntry);
EFI_STATUS
ExecSetVirtualAddressesToMemMap(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
CopyEfiSysTableToSeparateRtDataArea(IN OUT UINT32 *EfiSystemTable);
VOID
ProtectRtDataFromRelocation(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap
);
VOID
VirtualizeRTShimPointers (UINTN MemoryMapSize, UINTN DescriptorSize, EFI_MEMORY_DESCRIPTOR *MemoryMap);
VOID
DefragmentRuntimeServices(
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *MemoryMap,
IN OUT UINT32 *EfiSystemTable,
IN BOOLEAN SkipOurSysTableRtArea
);
/** Fixes stuff for booting with relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixBootingWithoutRelocBlock(UINTN bootArgs, BOOLEAN ModeX64);
/** Fixes stuff for hibernate wake booting without relocation block. Called when boot.efi jumps to kernel. */
UINTN FixHibernateWakeWithoutRelocBlock(UINTN imageHeaderPage, BOOLEAN ModeX64);

View File

@ -16,6 +16,7 @@
ENTRY_POINT = OsxAptioFixDrvEntrypoint
[Packages]
CloverPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec

View File

@ -16,6 +16,7 @@
ENTRY_POINT = OsxAptioFixDrvEntrypoint
[Packages]
CloverPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec

View File

@ -16,6 +16,7 @@
ENTRY_POINT = OsxAptioFixDrvEntrypoint
[Packages]
CloverPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec

View File

@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "entry_scan.h"
#include "device_tree.h"
//#include "device_tree.h"
#include "kernel_patcher.h"
#define PATCH_DEBUG 0

View File

@ -8,7 +8,7 @@
#include "Platform.h"
#include "LoaderUefi.h"
#include "device_tree.h"
//#include "device_tree.h"
#include "kernel_patcher.h"
#include "sse3_patcher.h"
@ -1678,7 +1678,7 @@ FindBootArgs(IN LOADER_ENTRY *Entry)
) {
// set vars
dtRoot = (CHAR8*)(UINTN)bootArgs2->deviceTreeP;
dtLength = bootArgs2->deviceTreeLength;
dtLength = &bootArgs2->deviceTreeLength;
KernelSlide = bootArgs2->kslide;
DBG_RT(Entry, "Found bootArgs2 at 0x%08x, DevTree at %p\n", ptr, dtRoot);
@ -1708,7 +1708,7 @@ FindBootArgs(IN LOADER_ENTRY *Entry)
) {
// set vars
dtRoot = (CHAR8*)(UINTN)bootArgs1->deviceTreeP;
dtLength = bootArgs1->deviceTreeLength;
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);

View File

@ -562,29 +562,29 @@ 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 dtLen = (UINTN) *deviceTreeLength;
UINT8 *dtEntry = (UINT8*)(UINTN) deviceTreeP;
UINTN dtLen = (UINTN) *deviceTreeLength;
DTEntry platformEntry;
DTEntry memmapEntry;
DTEntry platformEntry;
DTEntry memmapEntry;
CHAR8 *ptr;
struct OpaqueDTPropertyIterator OPropIter;
OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator iter = &OPropIter;
DeviceTreeNodeProperty *prop = NULL;
UINT8 *infoPtr = 0;
UINT8 *extraPtr = 0;
UINT8 *drvPtr = 0;
UINTN offset = 0;
UINT8 *infoPtr = 0;
UINT8 *extraPtr = 0;
UINT8 *drvPtr = 0;
UINTN offset = 0;
LIST_ENTRY *Link;
KEXT_ENTRY *KextEntry;
UINTN KextBase = 0;
_DeviceTreeBuffer *mm;
_BooterKextFileInfo *drvinfo;
UINTN KextBase = 0;
_DeviceTreeBuffer *mm;
_BooterKextFileInfo *drvinfo;
UINT32 KextCount;
UINTN Index;
UINTN Index;
DBG_RT(Entry, "\nInjectKexts: ");
@ -610,27 +610,27 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP,
// drvinfo->bundlePathPhysAddr += (UINT32)kextsBase;
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;
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) {
if(AsciiStrnCmp(prop->Name, "Driver-", 7)==0 || AsciiStrnCmp(prop->Name, "DriversPackage-", 15)==0) {
break;
}
}
}
}
if(!EFI_ERROR(DTLookupEntry(NULL,"/efi/platform",&platformEntry))) {
if(!EFI_ERROR(DTCreatePropertyIterator(platformEntry,iter))) {
while(!EFI_ERROR(DTIterateProperties(iter,&ptr))) {
prop = iter->currentProperty;
if(AsciiStrnCmp(prop->name, "mm_extra", 8)==0) {
infoPtr = (UINT8*) prop;
if(!EFI_ERROR(DTLookupEntry(NULL, "/efi/platform", &platformEntry))) {
if(!EFI_ERROR(DTCreatePropertyIterator(platformEntry, iter))) {
while(!EFI_ERROR(DTIterateProperties(iter, &ptr))) {
prop = iter->CurrentProperty;
if(AsciiStrnCmp(prop->Name, "mm_extra", 8)==0) {
infoPtr = (UINT8*)prop;
}
if(AsciiStrnCmp(prop->name, "extra", 5)==0) {
extraPtr = (UINT8*) prop;
if(AsciiStrnCmp(prop->Name, "extra", 5)==0) {
extraPtr = (UINT8*)prop;
}
}
}
@ -643,13 +643,13 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP,
}
// make space for memory map entries
platformEntry->nProperties -= 2;
offset = sizeof(DeviceTreeNodeProperty) + ((DeviceTreeNodeProperty*) infoPtr)->length;
platformEntry->NumProperties -= 2;
offset = sizeof(DeviceTreeNodeProperty) + ((DeviceTreeNodeProperty*) infoPtr)->Length;
CopyMem(drvPtr+offset, drvPtr, infoPtr-drvPtr);
// make space behind device tree
// platformEntry->nProperties--;
offset = sizeof(DeviceTreeNodeProperty)+((DeviceTreeNodeProperty*) extraPtr)->length;
offset = sizeof(DeviceTreeNodeProperty)+((DeviceTreeNodeProperty*) extraPtr)->Length;
CopyMem(extraPtr, extraPtr+offset, dtLen-(UINTN)(extraPtr-dtEntry)-offset);
*deviceTreeLength -= (UINT32)offset;
@ -665,13 +665,13 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP,
drvinfo->executablePhysAddr += (UINT32) KextBase;
drvinfo->bundlePathPhysAddr += (UINT32) KextBase;
memmapEntry->nProperties++;
memmapEntry->NumProperties++;
prop = ((DeviceTreeNodeProperty*) drvPtr);
prop->length = sizeof(_DeviceTreeBuffer);
prop->Length = sizeof(_DeviceTreeBuffer);
mm = (_DeviceTreeBuffer*) (((UINT8*)prop) + sizeof(DeviceTreeNodeProperty));
mm->paddr = (UINT32)KextBase;
mm->length = KextEntry->kext.length;
AsciiSPrint(prop->name, 31, "Driver-%x", KextBase);
AsciiSPrint(prop->Name, 31, "Driver-%x", KextBase);
drvPtr += sizeof(DeviceTreeNodeProperty) + sizeof(_DeviceTreeBuffer);
KextBase = RoundPage(KextBase + KextEntry->kext.length);

View File

@ -6,7 +6,7 @@ kext injection
#define __KEXT_INJECT_H__
#include "LoaderUefi.h"
#include "device_tree.h"
//#include "device_tree.h"
#include "kernel_patcher.h"
////////////////////

View File

@ -5,7 +5,7 @@
#include "Platform.h"
#include "LoaderUefi.h"
#include "device_tree.h"
//#include "device_tree.h"
#include "kernel_patcher.h"
@ -1377,7 +1377,7 @@ VOID PatchLoadedKexts(LOADER_ENTRY *Entry)
_DeviceTreeBuffer *PropEntry;
CHAR8 SavedValue;
CHAR8 *InfoPlist;
struct OpaqueDTPropertyIterator OPropIter;
OpaqueDTPropertyIterator OPropIter;
DTPropertyIterator PropIter = &OPropIter;
//UINTN DbgCount = 0;
@ -1396,7 +1396,7 @@ VOID PatchLoadedKexts(LOADER_ENTRY *Entry)
//DBG(L"Prop: %a\n", PropName);
if (AsciiStrStr(PropName,"Driver-")) {
// PropEntry _DeviceTreeBuffer is the value of Driver-XXXXXX property
PropEntry = (_DeviceTreeBuffer*)(((UINT8*)PropIter->currentProperty) + sizeof(DeviceTreeNodeProperty));
PropEntry = (_DeviceTreeBuffer*)(((UINT8*)PropIter->CurrentProperty) + sizeof(DeviceTreeNodeProperty));
//if (DbgCount < 3) DBG(L"%a: paddr = %x, length = %x\n", PropName, PropEntry->paddr, PropEntry->length);
// PropEntry->paddr points to _BooterKextFileInfo