static void generate_cpu_nodes(void *fdt, struct kvm *kvm) { int cpu; _FDT(fdt_begin_node(fdt, "cpus")); _FDT(fdt_property_cell(fdt, "#address-cells", 0x1)); _FDT(fdt_property_cell(fdt, "#size-cells", 0x0)); for (cpu = 0; cpu < kvm->nrcpus; ++cpu) { char cpu_name[CPU_NAME_MAX_LEN]; struct kvm_cpu *vcpu = kvm->cpus[cpu]; unsigned long mpidr = kvm_cpu__get_vcpu_mpidr(vcpu); mpidr &= ARM_MPIDR_HWID_BITMASK; snprintf(cpu_name, CPU_NAME_MAX_LEN, "cpu@%lx", mpidr); _FDT(fdt_begin_node(fdt, cpu_name)); _FDT(fdt_property_string(fdt, "device_type", "cpu")); _FDT(fdt_property_string(fdt, "compatible", vcpu->cpu_compatible)); if (kvm->nrcpus > 1) _FDT(fdt_property_string(fdt, "enable-method", "psci")); _FDT(fdt_property_cell(fdt, "reg", mpidr)); _FDT(fdt_end_node(fdt)); } _FDT(fdt_end_node(fdt)); }
/** * fit_write_images() - Write out a list of images to the FIT * * We always include the main image (params->datafile). If there are device * tree files, we include an fdt@ node for each of those too. */ static int fit_write_images(struct image_tool_params *params, char *fdt) { struct content_info *cont; const char *typename; char str[100]; int upto; int ret; fdt_begin_node(fdt, "images"); /* First the main image */ typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s@1", typename); fdt_begin_node(fdt, str); fdt_property_string(fdt, "description", params->imagename); fdt_property_string(fdt, "type", typename); fdt_property_string(fdt, "arch", genimg_get_arch_name(params->arch)); fdt_property_string(fdt, "os", genimg_get_os_short_name(params->os)); fdt_property_string(fdt, "compression", genimg_get_comp_short_name(params->comp)); fdt_property_u32(fdt, "load", params->addr); fdt_property_u32(fdt, "entry", params->ep); /* * Put data last since it is large. SPL may only load the first part * of the DT, so this way it can access all the above fields. */ ret = fdt_property_file(params, fdt, "data", params->datafile); if (ret) return ret; fdt_end_node(fdt); /* Now the device tree files if available */ upto = 0; for (cont = params->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; snprintf(str, sizeof(str), "%s@%d", FIT_FDT_PROP, ++upto); fdt_begin_node(fdt, str); get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, "description", str); ret = fdt_property_file(params, fdt, "data", cont->fname); if (ret) return ret; fdt_property_string(fdt, "type", typename); fdt_property_string(fdt, "arch", genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, "compression", genimg_get_comp_short_name(IH_COMP_NONE)); fdt_end_node(fdt); } fdt_end_node(fdt); return 0; }
void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs) { const char compatible[] = "arm,armv8-timer\0arm,armv7-timer"; u32 cpu_mask = (((1 << kvm->nrcpus) - 1) << GIC_FDT_IRQ_PPI_CPU_SHIFT) \ & GIC_FDT_IRQ_PPI_CPU_MASK; u32 irq_prop[] = { cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), cpu_to_fdt32(irqs[0]), cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), cpu_to_fdt32(irqs[1]), cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), cpu_to_fdt32(irqs[2]), cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), cpu_to_fdt32(irqs[3]), cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), }; _FDT(fdt_begin_node(fdt, "timer")); _FDT(fdt_property(fdt, "compatible", compatible, sizeof(compatible))); _FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop))); if (kvm->cfg.arch.force_cntfrq > 0) _FDT(fdt_property_cell(fdt, "clock-frequency", kvm->cfg.arch.force_cntfrq)); _FDT(fdt_end_node(fdt)); }
void *create_device_tree(int *sizep) { void *fdt; int ret; *sizep = FDT_MAX_SIZE; fdt = g_malloc0(FDT_MAX_SIZE); ret = fdt_create(fdt, FDT_MAX_SIZE); if (ret < 0) { goto fail; } ret = fdt_begin_node(fdt, ""); if (ret < 0) { goto fail; } ret = fdt_end_node(fdt); if (ret < 0) { goto fail; } ret = fdt_finish(fdt); if (ret < 0) { goto fail; } ret = fdt_open_into(fdt, fdt, *sizep); if (ret) { fprintf(stderr, "Unable to copy device tree in memory\n"); exit(1); } return fdt; fail: fprintf(stderr, "%s Couldn't create dt: %s\n", __func__, fdt_strerror(ret)); exit(1); }
int fdt_create_empty_tree(void *buf, int bufsize) { int err; err = fdt_create(buf, bufsize); if (err) return err; err = fdt_finish_reservemap(buf); if (err) return err; err = fdt_begin_node(buf, ""); if (err) return err; err = fdt_end_node(buf); if (err) return err; err = fdt_finish(buf); if (err) return err; return fdt_open_into(buf, buf, bufsize); }
/** * fit_write_configs() - Write out a list of configurations to the FIT * * If there are device tree files, we include a configuration for each, which * selects the main image (params->datafile) and its corresponding device * tree file. * * Otherwise we just create a configuration with the main image in it. */ static void fit_write_configs(struct image_tool_params *params, char *fdt) { struct content_info *cont; const char *typename; char str[100]; int upto; fdt_begin_node(fdt, "configurations"); fdt_property_string(fdt, FIT_DEFAULT_PROP, "conf-1"); upto = 0; for (cont = params->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; typename = genimg_get_type_short_name(cont->type); snprintf(str, sizeof(str), "conf-%d", ++upto); fdt_begin_node(fdt, str); get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, FIT_DESC_PROP, str); typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_property_string(fdt, typename, str); if (params->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, FIT_RAMDISK_PROP "-1"); snprintf(str, sizeof(str), FIT_FDT_PROP "-%d", upto); fdt_property_string(fdt, FIT_FDT_PROP, str); fdt_end_node(fdt); } if (!upto) { fdt_begin_node(fdt, "conf-1"); typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_property_string(fdt, typename, str); if (params->fit_ramdisk) fdt_property_string(fdt, FIT_RAMDISK_PROP, FIT_RAMDISK_PROP "-1"); fdt_end_node(fdt); }
int main(int argc, char *argv[]) { void *fdt; int err; int offset, s1, s2; test_init(argc, argv); fdt = xmalloc(SPACE); /* First create empty tree with SW */ CHECK(fdt_create(fdt, SPACE)); CHECK(fdt_finish_reservemap(fdt)); CHECK(fdt_begin_node(fdt, "")); CHECK(fdt_end_node(fdt)); CHECK(fdt_finish(fdt)); verbose_printf("Built empty tree, totalsize = %d\n", fdt_totalsize(fdt)); CHECK(fdt_open_into(fdt, fdt, SPACE)); CHECK(fdt_add_mem_rsv(fdt, TEST_ADDR_1, TEST_SIZE_1)); CHECK(fdt_add_mem_rsv(fdt, TEST_ADDR_2, TEST_SIZE_2)); CHECK(fdt_setprop_string(fdt, 0, "compatible", "test_tree1")); CHECK(fdt_setprop_cell(fdt, 0, "prop-int", TEST_VALUE_1)); CHECK(fdt_setprop_string(fdt, 0, "prop-str", TEST_STRING_1)); OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode@1")); s1 = offset; CHECK(fdt_setprop_string(fdt, s1, "compatible", "subnode1")); CHECK(fdt_setprop_cell(fdt, s1, "prop-int", TEST_VALUE_1)); OFF_CHECK(offset, fdt_add_subnode(fdt, s1, "subsubnode")); CHECK(fdt_setprop(fdt, offset, "compatible", "subsubnode1\0subsubnode", 23)); CHECK(fdt_setprop_cell(fdt, offset, "prop-int", TEST_VALUE_1)); OFF_CHECK(offset, fdt_add_subnode(fdt, s1, "ss1")); OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode@2")); s2 = offset; CHECK(fdt_setprop_cell(fdt, s2, "linux,phandle", PHANDLE_1)); CHECK(fdt_setprop_cell(fdt, s2, "prop-int", TEST_VALUE_2)); OFF_CHECK(offset, fdt_add_subnode(fdt, s2, "subsubnode@0")); CHECK(fdt_setprop_cell(fdt, offset, "linux,phandle", PHANDLE_2)); CHECK(fdt_setprop(fdt, offset, "compatible", "subsubnode2\0subsubnode", 23)); CHECK(fdt_setprop_cell(fdt, offset, "prop-int", TEST_VALUE_2)); OFF_CHECK(offset, fdt_add_subnode(fdt, s2, "ss2")); CHECK(fdt_pack(fdt)); save_blob("rw_tree1.test.dtb", fdt); PASS(); }
/* * Make a test fdt * * @param fdt Device tree pointer * @param size Size of device tree blob * @param aliases Specifies alias assignments. Format is a list of items * separated by space. Items are #a where * # is the alias number * a is the node to point to * @param nodes Specifies nodes to generate (a=0, b=1), upper case * means to create a disabled node */ static int make_fdt(void *fdt, int size, const char *aliases, const char *nodes) { char name[20], value[20]; const char *s; int fd; CHECK(fdt_create(fdt, size)); CHECK(fdt_finish_reservemap(fdt)); CHECK(fdt_begin_node(fdt, "")); CHECK(fdt_begin_node(fdt, "aliases")); for (s = aliases; *s;) { sprintf(name, "i2c%c", *s); sprintf(value, "/i2c%d@0", s[1] - 'a'); CHECK(fdt_property_string(fdt, name, value)); s += 2 + (s[2] != '\0'); } CHECK(fdt_end_node(fdt)); for (s = nodes; *s; s++) { sprintf(value, "i2c%d@0", (*s & 0xdf) - 'A'); CHECK(fdt_begin_node(fdt, value)); CHECK(fdt_property_string(fdt, "compatible", fdtdec_get_compatible(COMPAT_UNKNOWN))); if (*s <= 'Z') CHECK(fdt_property_string(fdt, "status", "disabled")); CHECK(fdt_end_node(fdt)); } CHECK(fdt_end_node(fdt)); CHECK(fdt_finish(fdt)); CHECK(fdt_pack(fdt)); #if defined(DEBUG) && defined(CONFIG_SANDBOX) fd = os_open("/tmp/fdtdec-text.dtb", OS_O_CREAT | OS_O_WRONLY); if (fd == -1) { printf("Could not open .dtb file to write\n"); return -1; } os_write(fd, fdt, size); os_close(fd); #endif return 0; }
static void generate_virtio_mmio_node(void *fdt, struct virtio_mmio *vmmio) { char dev_name[DEVICE_NAME_MAX_LEN]; u64 addr = vmmio->addr; u64 reg_prop[] = { cpu_to_fdt64(addr), cpu_to_fdt64(VIRTIO_MMIO_IO_SIZE) }; u32 irq_prop[] = { cpu_to_fdt32(GIC_FDT_IRQ_TYPE_SPI), cpu_to_fdt32(vmmio->irq - GIC_SPI_IRQ_BASE), cpu_to_fdt32(GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), }; snprintf(dev_name, DEVICE_NAME_MAX_LEN, "virtio@%llx", addr); _FDT(fdt_begin_node(fdt, dev_name)); _FDT(fdt_property_string(fdt, "compatible", "virtio,mmio")); _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); _FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop))); _FDT(fdt_end_node(fdt)); }
/* Create /hypervisor/uefi node for efi properties. */ int __init acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]) { int res; res = fdt_begin_node(fdt, "uefi"); if ( res ) return res; res = fdt_property_u64(fdt, "xen,uefi-system-table", tbl_add[TBL_EFIT].start); if ( res ) return res; res = fdt_property_u64(fdt, "xen,uefi-mmap-start", tbl_add[TBL_MMAP].start); if ( res ) return res; res = fdt_property_u32(fdt, "xen,uefi-mmap-size", tbl_add[TBL_MMAP].size); if ( res ) return res; res = fdt_property_u32(fdt, "xen,uefi-mmap-desc-size", sizeof(EFI_MEMORY_DESCRIPTOR)); if ( res ) return res; res = fdt_property_u32(fdt, "xen,uefi-mmap-desc-ver", 1); if ( res ) return res; res = fdt_end_node(fdt); return res; }
static void *spapr_create_fdt_skel(const char *cpu_model, target_phys_addr_t initrd_base, target_phys_addr_t initrd_size, const char *boot_device, const char *kernel_cmdline, long hash_shift) { void *fdt; CPUState *env; uint64_t mem_reg_property[] = { 0, cpu_to_be64(ram_size) }; uint32_t start_prop = cpu_to_be32(initrd_base); uint32_t end_prop = cpu_to_be32(initrd_base + initrd_size); uint32_t pft_size_prop[] = {0, cpu_to_be32(hash_shift)}; char hypertas_prop[] = "hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" "\0hcall-tce\0hcall-vio\0hcall-splpar"; uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)}; int i; char *modelname; #define _FDT(exp) \ do { \ int ret = (exp); \ if (ret < 0) { \ fprintf(stderr, "qemu: error creating device tree: %s: %s\n", \ #exp, fdt_strerror(ret)); \ exit(1); \ } \ } while (0) fdt = qemu_mallocz(FDT_MAX_SIZE); _FDT((fdt_create(fdt, FDT_MAX_SIZE))); _FDT((fdt_finish_reservemap(fdt))); /* Root node */ _FDT((fdt_begin_node(fdt, ""))); _FDT((fdt_property_string(fdt, "device_type", "chrp"))); _FDT((fdt_property_string(fdt, "model", "qemu,emulated-pSeries-LPAR"))); _FDT((fdt_property_cell(fdt, "#address-cells", 0x2))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x2))); /* /chosen */ _FDT((fdt_begin_node(fdt, "chosen"))); _FDT((fdt_property_string(fdt, "bootargs", kernel_cmdline))); _FDT((fdt_property(fdt, "linux,initrd-start", &start_prop, sizeof(start_prop)))); _FDT((fdt_property(fdt, "linux,initrd-end", &end_prop, sizeof(end_prop)))); _FDT((fdt_property_string(fdt, "qemu,boot-device", boot_device))); _FDT((fdt_end_node(fdt))); /* memory node */ _FDT((fdt_begin_node(fdt, "memory@0"))); _FDT((fdt_property_string(fdt, "device_type", "memory"))); _FDT((fdt_property(fdt, "reg", mem_reg_property, sizeof(mem_reg_property)))); _FDT((fdt_end_node(fdt))); /* cpus */ _FDT((fdt_begin_node(fdt, "cpus"))); _FDT((fdt_property_cell(fdt, "#address-cells", 0x1))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x0))); modelname = qemu_strdup(cpu_model); for (i = 0; i < strlen(modelname); i++) { modelname[i] = toupper(modelname[i]); } for (env = first_cpu; env != NULL; env = env->next_cpu) { int index = env->cpu_index; uint32_t gserver_prop[] = {cpu_to_be32(index), 0}; /* HACK! */ char *nodename; uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), 0xffffffff, 0xffffffff}; if (asprintf(&nodename, "%s@%x", modelname, index) < 0) { fprintf(stderr, "Allocation failure\n"); exit(1); } _FDT((fdt_begin_node(fdt, nodename))); free(nodename); _FDT((fdt_property_cell(fdt, "reg", index))); _FDT((fdt_property_string(fdt, "device_type", "cpu"))); _FDT((fdt_property_cell(fdt, "cpu-version", env->spr[SPR_PVR]))); _FDT((fdt_property_cell(fdt, "dcache-block-size", env->dcache_line_size))); _FDT((fdt_property_cell(fdt, "icache-block-size", env->icache_line_size))); _FDT((fdt_property_cell(fdt, "timebase-frequency", TIMEBASE_FREQ))); /* Hardcode CPU frequency for now. It's kind of arbitrary on * full emu, for kvm we should copy it from the host */ _FDT((fdt_property_cell(fdt, "clock-frequency", 1000000000))); _FDT((fdt_property_cell(fdt, "ibm,slb-size", env->slb_nr))); _FDT((fdt_property(fdt, "ibm,pft-size", pft_size_prop, sizeof(pft_size_prop)))); _FDT((fdt_property_string(fdt, "status", "okay"))); _FDT((fdt_property(fdt, "64-bit", NULL, 0))); _FDT((fdt_property_cell(fdt, "ibm,ppc-interrupt-server#s", index))); _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s", gserver_prop, sizeof(gserver_prop)))); if (env->mmu_model & POWERPC_MMU_1TSEG) { _FDT((fdt_property(fdt, "ibm,processor-segment-sizes", segs, sizeof(segs)))); } _FDT((fdt_end_node(fdt))); } qemu_free(modelname); _FDT((fdt_end_node(fdt))); /* RTAS */ _FDT((fdt_begin_node(fdt, "rtas"))); _FDT((fdt_property(fdt, "ibm,hypertas-functions", hypertas_prop, sizeof(hypertas_prop)))); _FDT((fdt_end_node(fdt))); /* interrupt controller */ _FDT((fdt_begin_node(fdt, "interrupt-controller@0"))); _FDT((fdt_property_string(fdt, "device_type", "PowerPC-External-Interrupt-Presentation"))); _FDT((fdt_property_string(fdt, "compatible", "IBM,ppc-xicp"))); _FDT((fdt_property_cell(fdt, "reg", 0))); _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); _FDT((fdt_property(fdt, "ibm,interrupt-server-ranges", interrupt_server_ranges_prop, sizeof(interrupt_server_ranges_prop)))); _FDT((fdt_end_node(fdt))); /* vdevice */ _FDT((fdt_begin_node(fdt, "vdevice"))); _FDT((fdt_property_string(fdt, "device_type", "vdevice"))); _FDT((fdt_property_string(fdt, "compatible", "IBM,vdevice"))); _FDT((fdt_property_cell(fdt, "#address-cells", 0x1))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x0))); _FDT((fdt_property_cell(fdt, "#interrupt-cells", 0x2))); _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); _FDT((fdt_end_node(fdt))); _FDT((fdt_end_node(fdt))); /* close root node */ _FDT((fdt_finish(fdt))); return fdt; }
static int setup_fdt(struct kvm *kvm) { struct device_header *dev_hdr; u8 staging_fdt[FDT_MAX_SIZE]; u32 gic_phandle = fdt__alloc_phandle(); u64 mem_reg_prop[] = { cpu_to_fdt64(kvm->arch.memory_guest_start), cpu_to_fdt64(kvm->ram_size), }; void *fdt = staging_fdt; void *fdt_dest = guest_flat_to_host(kvm, kvm->arch.dtb_guest_start); void (*generate_mmio_fdt_nodes)(void *, struct device_header *, void (*)(void *, u8)); void (*generate_cpu_peripheral_fdt_nodes)(void *, struct kvm *, u32) = kvm->cpus[0]->generate_fdt_nodes; /* Create new tree without a reserve map */ _FDT(fdt_create(fdt, FDT_MAX_SIZE)); _FDT(fdt_finish_reservemap(fdt)); /* Header */ _FDT(fdt_begin_node(fdt, "")); _FDT(fdt_property_cell(fdt, "interrupt-parent", gic_phandle)); _FDT(fdt_property_string(fdt, "compatible", "linux,dummy-virt")); _FDT(fdt_property_cell(fdt, "#address-cells", 0x2)); _FDT(fdt_property_cell(fdt, "#size-cells", 0x2)); /* /chosen */ _FDT(fdt_begin_node(fdt, "chosen")); _FDT(fdt_property_cell(fdt, "linux,pci-probe-only", 1)); _FDT(fdt_property_string(fdt, "bootargs", kern_cmdline)); /* Initrd */ if (kvm->arch.initrd_size != 0) { u32 ird_st_prop = cpu_to_fdt64(kvm->arch.initrd_guest_start); u32 ird_end_prop = cpu_to_fdt64(kvm->arch.initrd_guest_start + kvm->arch.initrd_size); _FDT(fdt_property(fdt, "linux,initrd-start", &ird_st_prop, sizeof(ird_st_prop))); _FDT(fdt_property(fdt, "linux,initrd-end", &ird_end_prop, sizeof(ird_end_prop))); } _FDT(fdt_end_node(fdt)); /* Memory */ _FDT(fdt_begin_node(fdt, "memory")); _FDT(fdt_property_string(fdt, "device_type", "memory")); _FDT(fdt_property(fdt, "reg", mem_reg_prop, sizeof(mem_reg_prop))); _FDT(fdt_end_node(fdt)); /* CPU and peripherals (interrupt controller, timers, etc) */ generate_cpu_nodes(fdt, kvm); if (generate_cpu_peripheral_fdt_nodes) generate_cpu_peripheral_fdt_nodes(fdt, kvm, gic_phandle); /* Virtio MMIO devices */ dev_hdr = device__first_dev(DEVICE_BUS_MMIO); while (dev_hdr) { generate_mmio_fdt_nodes = dev_hdr->data; generate_mmio_fdt_nodes(fdt, dev_hdr, generate_irq_prop); dev_hdr = device__next_dev(dev_hdr); } /* IOPORT devices (!) */ dev_hdr = device__first_dev(DEVICE_BUS_IOPORT); while (dev_hdr) { generate_mmio_fdt_nodes = dev_hdr->data; generate_mmio_fdt_nodes(fdt, dev_hdr, generate_irq_prop); dev_hdr = device__next_dev(dev_hdr); } /* PCI host controller */ pci__generate_fdt_nodes(fdt, gic_phandle); /* PSCI firmware */ _FDT(fdt_begin_node(fdt, "psci")); _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); _FDT(fdt_property_string(fdt, "method", "hvc")); _FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND)); _FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF)); _FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON)); _FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE)); _FDT(fdt_end_node(fdt)); /* Finalise. */ _FDT(fdt_end_node(fdt)); _FDT(fdt_finish(fdt)); _FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE)); _FDT(fdt_pack(fdt_dest)); if (kvm->cfg.arch.dump_dtb_filename) dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); return 0; }
/** * build_tree() - Build a tree * * @fdt: Pointer to place to put tree, assumed to be large enough * @flags: Flags to control the tree creation (FDT_REG_...) * @space: Amount of space to create for later tree additions * * This creates a tree modelled on a U-Boot FIT image, with various nodes * and properties which are useful for testing the hashing features of * fdt_find_regions(). * * See h_include() below for a list of the nodes we later search for. */ static void build_tree(void *fdt, int flags, int space) { int direct_subnodes = flags & FDT_REG_DIRECT_SUBNODES; int all_subnodes = flags & FDT_REG_ALL_SUBNODES; int supernodes = flags & FDT_REG_SUPERNODES; int either = !all_subnodes && (direct_subnodes || supernodes); int err; CHECK(fdt_create(fdt, SPACE)); CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_1, TEST_SIZE_1)); CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_2, TEST_SIZE_2)); CHECK(fdt_finish_reservemap(fdt)); /* * This is the start of a new region because in the fdt_xxx_region() * call, we pass "/" as one of the nodes to find. */ start(fdt); /* region 0 */ CHECK(fdt_begin_node(fdt, "")); CHECK(fdt_property_string(fdt, "description", "kernel image")); CHECK(fdt_property_u32(fdt, "#address-cells", 1)); /* /images */ if (!either && !all_subnodes) stop(fdt); CHECK(fdt_begin_node(fdt, "images")); if (either) stop(fdt); CHECK(fdt_property_u32(fdt, "image-prop", 1)); /* /images/kernel@1 */ if (!all_subnodes) start(fdt); /* region 1 */ CHECK(fdt_begin_node(fdt, "kernel@1")); CHECK(fdt_property_string(fdt, "description", "exynos kernel")); stop(fdt); CHECK(fdt_property_string(fdt, "data", "this is the kernel image")); start(fdt); /* region 2 */ /* /images/kernel/hash@1 */ CHECK(fdt_begin_node(fdt, "hash@1")); CHECK(fdt_property_string(fdt, "algo", "sha1")); CHECK(fdt_end_node(fdt)); /* /images/kernel/hash@2 */ if (!direct_subnodes) stop(fdt); CHECK(fdt_begin_node(fdt, "hash@2")); if (direct_subnodes) stop(fdt); CHECK(fdt_property_string(fdt, "algo", "sha1")); if (direct_subnodes) start(fdt); /* region 3 */ CHECK(fdt_end_node(fdt)); if (!direct_subnodes) start(fdt); /* region 3 */ CHECK(fdt_end_node(fdt)); /* /images/fdt@1 */ CHECK(fdt_begin_node(fdt, "fdt@1")); CHECK(fdt_property_string(fdt, "description", "snow FDT")); if (!all_subnodes) stop(fdt); CHECK(fdt_property_string(fdt, "data", "FDT data")); if (!all_subnodes) start(fdt); /* region 4 */ /* /images/kernel/hash@1 */ CHECK(fdt_begin_node(fdt, "hash@1")); CHECK(fdt_property_string(fdt, "algo", "sha1")); CHECK(fdt_end_node(fdt)); CHECK(fdt_end_node(fdt)); if (!either && !all_subnodes) stop(fdt); CHECK(fdt_end_node(fdt)); /* /configurations */ CHECK(fdt_begin_node(fdt, "configurations")); if (either) stop(fdt); CHECK(fdt_property_string(fdt, "default", "conf@1")); /* /configurations/conf@1 */ if (!all_subnodes) start(fdt); /* region 6 */ CHECK(fdt_begin_node(fdt, "conf@1")); CHECK(fdt_property_string(fdt, "kernel", "kernel@1")); CHECK(fdt_property_string(fdt, "fdt", "fdt@1")); CHECK(fdt_end_node(fdt)); if (!all_subnodes) stop(fdt); /* /configurations/conf@2 */ CHECK(fdt_begin_node(fdt, "conf@2")); CHECK(fdt_property_string(fdt, "kernel", "kernel@1")); CHECK(fdt_property_string(fdt, "fdt", "fdt@2")); CHECK(fdt_end_node(fdt)); if (either) start(fdt); /* region 7 */ CHECK(fdt_end_node(fdt)); if (!either && !all_subnodes) start(fdt); /* region 7 */ CHECK(fdt_end_node(fdt)); CHECK(fdt_finish(fdt)); stop(fdt); /* Add in the strings */ if (flags & FDT_REG_ADD_STRING_TAB) { expect[expect_count].offset = fdt_off_dt_strings(fdt); expect[expect_count].size = fdt_size_dt_strings(fdt); expect_count++; } /* Make a bit of space */ if (space) CHECK(fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + space)); verbose_printf("Completed tree, totalsize = %d\n", fdt_totalsize(fdt)); }
/** * fit_write_images() - Write out a list of images to the FIT * * We always include the main image (params->datafile). If there are device * tree files, we include an fdt- node for each of those too. */ static int fit_write_images(struct image_tool_params *params, char *fdt) { struct content_info *cont; const char *typename; char str[100]; int upto; int ret; fdt_begin_node(fdt, "images"); /* First the main image */ typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s-1", typename); fdt_begin_node(fdt, str); fdt_property_string(fdt, FIT_DESC_PROP, params->imagename); fdt_property_string(fdt, FIT_TYPE_PROP, typename); fdt_property_string(fdt, FIT_ARCH_PROP, genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, FIT_OS_PROP, genimg_get_os_short_name(params->os)); fdt_property_string(fdt, FIT_COMP_PROP, genimg_get_comp_short_name(params->comp)); fdt_property_u32(fdt, FIT_LOAD_PROP, params->addr); fdt_property_u32(fdt, FIT_ENTRY_PROP, params->ep); /* * Put data last since it is large. SPL may only load the first part * of the DT, so this way it can access all the above fields. */ ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile); if (ret) return ret; fdt_end_node(fdt); /* Now the device tree files if available */ upto = 0; for (cont = params->content_head; cont; cont = cont->next) { if (cont->type != IH_TYPE_FLATDT) continue; snprintf(str, sizeof(str), "%s-%d", FIT_FDT_PROP, ++upto); fdt_begin_node(fdt, str); get_basename(str, sizeof(str), cont->fname); fdt_property_string(fdt, FIT_DESC_PROP, str); ret = fdt_property_file(params, fdt, FIT_DATA_PROP, cont->fname); if (ret) return ret; fdt_property_string(fdt, FIT_TYPE_PROP, typename); fdt_property_string(fdt, FIT_ARCH_PROP, genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, FIT_COMP_PROP, genimg_get_comp_short_name(IH_COMP_NONE)); fdt_end_node(fdt); } /* And a ramdisk file if available */ if (params->fit_ramdisk) { fdt_begin_node(fdt, FIT_RAMDISK_PROP "-1"); fdt_property_string(fdt, FIT_TYPE_PROP, FIT_RAMDISK_PROP); fdt_property_string(fdt, FIT_OS_PROP, genimg_get_os_short_name(params->os)); ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->fit_ramdisk); if (ret) return ret; fdt_end_node(fdt); } fdt_end_node(fdt); return 0; }