/** * prepare_devicetree * * Prepare and flatten the devicetree. */ int prepare_devicetree(void) { void *deviceTreeImage, *deviceTreeData; uint32_t deviceTreeSize, length, pos = 0; Node *root; TagPtr tag; char *xmlRepresentation; deviceTreeImage = get_image3(kImage3TypeXmlDeviceTree); assert(deviceTreeImage != NULL); image3_get_tag_data(deviceTreeImage, kImage3TagData, &deviceTreeData, &deviceTreeSize); /* Create root of DT */ DT__Initialize(); root = DT__RootNode(); xmlRepresentation = (char *)deviceTreeData; /* Enter everything into the DeviceTree. (not mine) */ assert(root); while (1) { length = XMLParseNextTag(xmlRepresentation + pos, &tag); if (length == -1) break; pos += length; if (!tag) continue; if (tag->type == kTagTypeDict) { PopulateDeviceTreeNode(tag, root); XMLFreeTag(tag); return true; } XMLFreeTag(tag); } return false; }
void initKernBootStruct( void ) { static int init_done = 0; if ( !init_done ) { int convmem; // conventional memory int extmem; // extended memory unsigned long memoryMapCount = 0; bootArgs = (boot_args *)malloc(sizeof(boot_args)); bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); if (bootArgs == NULL || bootInfo == NULL) { stop("Couldn't allocate boot info\n"); return; } else { bzero(bootArgs, sizeof(boot_args)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the // conventional/extended memory for backwards compatibility. memoryMapCount = getMemoryMap( memoryMap, kMemoryMapCountMax, (unsigned long *) &convmem, (unsigned long *) &extmem ); if ( memoryMapCount == 0 ) { // BIOS did not provide a memory map, systems with // discontiguous memory or unusual memory hole locations // may have problems. convmem = getConventionalMemorySize(); extmem = getExtendedMemorySize(); } bootArgs->Video.v_display = VGA_TEXT_MODE; DT__Initialize(); { Node *node; node = DT__FindNode("/", true); if (node == 0) { stop("Couldn't create root node"); return; } getPlatformName(platformName, sizeof(platformName)); { int nameLen; nameLen = strlen(platformName) + 1; DT__AddProperty(node, "compatible", nameLen, platformName); DT__AddProperty(node, "model", nameLen, platformName); } } Node *gMemoryMapNode = DT__FindNode("/chosen/memory-map", true); set_env(envConvMem, convmem); set_env(envExtMem, extmem); set_env(envMemoryMap, (uint32_t)memoryMap); set_env(envMemoryMapCnt, memoryMapCount); set_env(envMemoryMapNode, (uint32_t)gMemoryMapNode); init_done = 1; } } }
void initKernBootStruct( void ) { Node *node; int nameLen; static int init_done = 0; if ( !init_done ) { bootArgs = (boot_args *)malloc(sizeof(boot_args)); bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion)); bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); if (bootArgs == 0 || bootInfo == 0) stop("Couldn't allocate boot info\n"); bzero(bootArgs, sizeof(boot_args)); bzero(bootArgsPreLion, sizeof(boot_args_pre_lion)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the // conventional/extended memory for backwards compatibility. bootInfo->memoryMapCount = getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax, (unsigned long *) &bootInfo->convmem, (unsigned long *) &bootInfo->extmem ); if ( bootInfo->memoryMapCount == 0 ) { // BIOS did not provide a memory map, systems with // discontiguous memory or unusual memory hole locations // may have problems. bootInfo->convmem = getConventionalMemorySize(); bootInfo->extmem = getExtendedMemorySize(); } bootInfo->configEnd = bootInfo->config; bootArgs->Video.v_display = VGA_TEXT_MODE; DT__Initialize(); node = DT__FindNode("/", true); if (node == 0) { stop("Couldn't create root node"); } getPlatformName(platformName); nameLen = strlen(platformName) + 1; DT__AddProperty(node, "compatible", nameLen, platformName); DT__AddProperty(node, "model", nameLen, platformName); gMemoryMapNode = DT__FindNode("/chosen/memory-map", true); bootArgs->Version = kBootArgsVersion; bootArgs->Revision = kBootArgsRevision; bootArgsPreLion->Version = kBootArgsPreLionVersion; bootArgsPreLion->Revision = kBootArgsPreLionRevision; init_done = 1; } }
void initEFITree(void) { _EFI_DEBUG_DUMP("Entering initEFITree(%x)\n", gPlatform.ACPI.Guid.Data1); static char ACPI[] = "ACPI"; // The required information should be added to private_data.h static EFI_CHAR16 const MODEL_NAME[] = STATIC_MODEL_NAME; static EFI_CHAR16 const SYSTEM_SERIAL_NUMBER[] = STATIC_SYSTEM_SERIAL_NUMBER; DT__Initialize(); // Add and initialize gPlatform.DT.RootNode /* * The root node is available until the call to DT__Finalize, or the first call * to DT__AddChild with NULL as first argument. Which we don't do and thus we * can use it in the meantime, instead of defining a local / global variable. */ DT__AddProperty(gPlatform.DT.RootNode, "model", 5, ACPI); DT__AddProperty(gPlatform.DT.RootNode, "compatible", 5, ACPI); Node * efiNode = DT__AddChild(gPlatform.DT.RootNode, "efi"); DT__AddProperty(efiNode, "firmware-abi", 6, (gPlatform.ArchCPUType == CPU_TYPE_X86_64) ? "EFI64" : "EFI32"); DT__AddProperty(efiNode, "firmware-revision", sizeof(FIRMWARE_REVISION), (EFI_UINT32*) &FIRMWARE_REVISION); DT__AddProperty(efiNode, "firmware-vendor", sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*) FIRMWARE_VENDOR); // Initialize a global var, used by function setupEFITables later on, to // add the address to the boot arguments (done to speed up the process). gPlatform.EFI.Nodes.RuntimeServices = DT__AddChild(efiNode, "runtime-services"); // Initialize a global var, used by function addConfigurationTable later on, // to add the SMBIOS and ACPI tables (done to speed up the process). gPlatform.EFI.Nodes.ConfigurationTable = DT__AddChild(efiNode, "configuration-table"); Node * platformNode = DT__AddChild(efiNode, "platform"); gPlatform.EFI.Nodes.Platform = platformNode; // Satisfying AppleACPIPlatform.kext static EFI_UINT8 const DEVICE_PATHS_SUPPORTED[] = { 0x01, 0x00, 0x00, 0x00 }; DT__AddProperty(platformNode, "DevicePathsSupported", sizeof(DEVICE_PATHS_SUPPORTED), (EFI_UINT8*) &DEVICE_PATHS_SUPPORTED); // The use of sizeof() here is mandatory (to prevent breakage). DT__AddProperty(platformNode, "Model", sizeof(MODEL_NAME), (EFI_CHAR16*) MODEL_NAME); DT__AddProperty(platformNode, "SystemSerialNumber", sizeof(SYSTEM_SERIAL_NUMBER), (EFI_CHAR16*) SYSTEM_SERIAL_NUMBER); if (gPlatform.CPU.FSBFrequency) { _EFI_DEBUG_DUMP("Adding FSBFrequency property (%dMHz)\n", (gPlatform.CPU.FSBFrequency / 1000)); DT__AddProperty(platformNode, "FSBFrequency", sizeof(uint64_t), &gPlatform.CPU.FSBFrequency); } Node * chosenNode = DT__AddChild(gPlatform.DT.RootNode, "chosen"); if (chosenNode == 0) { stop("Couldn't create /chosen node"); // Mimics boot.efi } gPlatform.EFI.Nodes.MemoryMap = DT__AddChild(chosenNode, "memory-map"); // Adding the root path for kextcache. DT__AddProperty(chosenNode, "boot-device-path", 38, "\\System\\Library\\CoreServices\\boot.efi"); /* static EFI_UINT8 const BOOT_DEVICE_PATH[] = { 0x02, 0x01, 0x0C, 0x00, 0xD0, 0x41, 0x08, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x02, 0x1F, 0x03, 0x12, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x2A, 0x00, 0x02, 0x00, 0x00, 0x00, 0x28, 0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x0B, 0x63, 0x34, 0x00, 0x00, 0x00, 0x00, 0x65, 0x8C, 0x53, 0x3F, 0x1B, 0xCA, 0x83, 0x38, 0xA9, 0xD0, 0xF0, 0x46, 0x19, 0x14, 0x8E, 0x31, 0x02, 0x02, 0x7F, 0xFF, 0x04, 0x00 }; DT__AddProperty(chosenNode, "boot-device-path", sizeof(BOOT_DEVICE_PATH), &BOOT_DEVICE_PATH); */ // Adding the default kernel name (mach_kernel) for kextcache. DT__AddProperty(chosenNode, "boot-file", sizeof(bootInfo->bootFile), bootInfo->bootFile); #if APPLE_STYLE_EFI static EFI_UINT8 const BOOT_FILE_PATH[] = { 0x04, 0x04, 0x50, 0x00, 0x5c, 0x00, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x5c, 0x00, 0x4c, 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79, 0x00, 0x5c, 0x00, 0x43, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x53, 0x00, 0x65, 0x00, 0x72, 0x00, 0x76, 0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x5c, 0x00, 0x62, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x2e, 0x00, 0x65, 0x00, 0x66, 0x00, 0x69, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x04, 0x00 }; DT__AddProperty(chosenNode, "boot-file-path", sizeof(BOOT_FILE_PATH), (EFI_UINT8*) &BOOT_FILE_PATH); static EFI_UINT8 const BOOT_ARGS[] = { 0x00 }; DT__AddProperty(chosenNode, "boot-args", sizeof(BOOT_ARGS), (EFI_UINT8*) &BOOT_ARGS); /* Adding kIOHibernateMachineSignatureKey (IOHibernatePrivate.h). * * This 'Hardware Signature' (offset 8 in the FACS table) is calculated by the BIOS on a best effort * basis to indicate the base hardware configuration of the system such that different base hardware * configurations can have different hardware signature values. OSPM uses this information in waking * from an S4 state, by comparing the current hardware signature to the signature values saved in the * non-volatile sleep image. If the values are not the same, OSPM assumes that the saved non-volatile * image is from a different hardware configuration and cannot be restored. */ static EFI_UINT8 const MACHINE_SIGNATURE[] = { 0x00, 0x00, 0x00, 0x00 }; DT__AddProperty(chosenNode, "machine-signature", sizeof(MACHINE_SIGNATURE), (EFI_UINT8*) &MACHINE_SIGNATURE); #if ((MAKE_TARGET_OS & LION) == LION) // Used by boot.efi - cosmetic only node/properties on hacks. Node * kernelCompatNode = DT__AddChild(efiNode, "kernel-compatibility"); static EFI_UINT8 const COMPAT_MODE[] = { 0x01, 0x00, 0x00, 0x00 }; DT__AddProperty(kernelCompatNode, "i386", sizeof(COMPAT_MODE), (EFI_UINT8*) &COMPAT_MODE); DT__AddProperty(kernelCompatNode, "x86_64", sizeof(COMPAT_MODE), (EFI_UINT8*) &COMPAT_MODE); #endif // Adding the options node breaks AppleEFINVRAM (missing hardware UUID). // Node *optionsNode = DT__AddChild(gPlatform.DT.RootNode, "options"); // DT__AddProperty(optionsNode, "EFICapsuleResult", 4, "STAR"); // 53 54 41 52 #endif // DT__AddProperty(chosenNode, "boot-kernelcache-adler32", sizeof(uint64_t), adler32); gPlatform.EFI.Nodes.Chosen = chosenNode; #if INJECT_EFI_DEVICE_PROPERTIES static EFI_UINT8 const EFI_DEVICE_PROPERTIES[] = { STATIC_EFI_DEVICE_PROPERTIES }; _EFI_DEBUG_DUMP("Injecting EFI device-properties\n"); DT__AddProperty(efiNode, "device-properties", sizeof(EFI_DEVICE_PROPERTIES), (EFI_CHAR8*) &EFI_DEVICE_PROPERTIES); #endif _EFI_DEBUG_DUMP("Exiting initEFITree()\n"); _EFI_DEBUG_SLEEP(5); }