If no fdt is provided on command line and the new field get_dtb in struct arm_boot_info is set then call it to get a device tree blob.
Signed-off-by: John Rigby <john.ri...@linaro.org> --- changes in v3: - split patch hw/arm/boot.c | 30 +++++++++++++++++++----------- include/hw/arm/arm.h | 6 ++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index f451529..64b56ac 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -235,19 +235,27 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) int size, rc; uint32_t acells, scells, hival; - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename); - if (!filename) { - fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename); - return -1; - } + if (binfo->dtb_filename) { + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename); + if (!filename) { + fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename); + return -1; + } - fdt = load_device_tree(filename, &size); - if (!fdt) { - fprintf(stderr, "Couldn't open dtb file %s\n", filename); + fdt = load_device_tree(filename, &size); + if (!fdt) { + fprintf(stderr, "Couldn't open dtb file %s\n", filename); + g_free(filename); + return -1; + } g_free(filename); - return -1; + } else if (binfo->get_dtb) { + fdt = binfo->get_dtb(addr, binfo, &size); + if (!fdt) { + fprintf(stderr, "Couldn't get dtb blob from board func\n"); + return -1; + } } - g_free(filename); acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells"); scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells"); @@ -440,7 +448,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) /* for device tree boot, we pass the DTB directly in r2. Otherwise * we point to the kernel args. */ - if (info->dtb_filename) { + if (info->dtb_filename || info->get_dtb) { /* Place the DTB after the initrd in memory. Note that some * kernels will trash anything in the 4K page the initrd * ends in, so make sure the DTB isn't caught up in that. diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index 7b2b02d..4c56a1b 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -31,6 +31,10 @@ struct arm_boot_info { const char *kernel_cmdline; const char *initrd_filename; const char *dtb_filename; + /* if a board is able to create a dtb without a dtb file then it + * sets get_dtb. This will only be used if no dtb file is provided. + */ + void *(*get_dtb)(hwaddr addr, const struct arm_boot_info *binfo, int *size); hwaddr loader_start; /* multicore boards that use the default secondary core boot functions * need to put the address of the secondary boot code, the boot reg, @@ -59,6 +63,8 @@ struct arm_boot_info { int is_linux; hwaddr initrd_start; hwaddr initrd_size; + void *dtb_blob; + int dtb_blob_size; hwaddr entry; }; void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); -- 1.8.2.2