/** * enter additional data into the DeviceTree */ int prepare_devicetree_stage2(void) { void *deviceTreeP; uint32_t deviceTreeLength; Node *memory_map = CreateMemoryMapNode(); assert(memory_map); /* Insert the cool iBoot-like stuff. */ uint32_t one = 1; uint64_t ecid = 0xBEEFBEEFBEEFBEEF; assert(gChosen); CreateDeviceTreeNode(gChosen, "firmware-version", "iBoot-1234.5.6~93", sizeof("iBoot-1234.5.6~93")); CreateDeviceTreeNode(gChosen, "debug-enabled", &one, sizeof(uint32_t)); CreateDeviceTreeNode(gChosen, "secure-boot", &one, sizeof(uint32_t)); CreateDeviceTreeNode(gChosen, "die-id", &ecid, sizeof(uint64_t)); CreateDeviceTreeNode(gChosen, "unique-chip-id", &ecid, sizeof(uint64_t)); CreateDeviceTreeNode(DT__RootNode(), "serial-number", "SOMESRNLNMBR", sizeof("SOMESRNLNMBR")); /* Verify we have a ramdisk. */ if (ramdisk_base) { void *reloc_ramdisk_base = (void *)memory_region_reserve(&kernel_region, ramdisk_size, 4096); printf ("creating ramdisk at 0x%x of size 0x%x, from image at 0x%x\n", reloc_ramdisk_base, ramdisk_size, ramdisk_base); bcopy((void *)ramdisk_base, reloc_ramdisk_base, ramdisk_size); AllocateMemoryRange(memory_map, "RAMDisk", (uint32_t) reloc_ramdisk_base, ramdisk_size, kBootDriverTypeInvalid); } /* Flatten the finalized device-tree image. */ DT__FlattenDeviceTree(NULL, &deviceTreeLength); /* Allocate memory for it. */ deviceTreeP = memory_region_reserve(&kernel_region, deviceTreeLength, 0); /* Flatten. */ DT__FlattenDeviceTree((void **)&deviceTreeP, &deviceTreeLength); /* Enter into Boot-Args */ gBootArgs.deviceTreeLength = deviceTreeLength; gBootArgs.deviceTreeP = (void *)phystov(deviceTreeP, gBootArgs.virtBase, gBootArgs.physBase); printf("creating device tree at 0x%x of size 0x%x\n", deviceTreeP, deviceTreeLength); return true; }
Node *CreateMemoryMapNode(void) { Node *root = DT__RootNode(); Node *chosen; Node *memory_map; /* /chosen/memory-map */ chosen = DT__AddChild(root, "chosen"); memory_map = DT__AddChild(chosen, "memory-map"); gChosen = chosen; return memory_map; }
/** * 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; }
/** * dtre_root_node * * Returns a pointer to the root node of the device tree. */ Node *dtre_root_node(void) { return DT__RootNode(); }