static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,

                    hwaddr addr_limit)

{

    void *fdt = NULL;

    int size, rc;

    uint32_t acells, scells;



    if (binfo->dtb_filename) {

        char *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);

            goto fail;

        }



        fdt = load_device_tree(filename, &size);

        if (!fdt) {

            fprintf(stderr, "Couldn't open dtb file %s\n", filename);

            g_free(filename);

            goto fail;

        }

        g_free(filename);

    } else if (binfo->get_dtb) {

        fdt = binfo->get_dtb(binfo, &size);

        if (!fdt) {

            fprintf(stderr, "Board was unable to create a dtb blob\n");

            goto fail;

        }

    }



    if (addr_limit > addr && size > (addr_limit - addr)) {

        /* Installing the device tree blob at addr would exceed addr_limit.

         * Whether this constitutes failure is up to the caller to decide,

         * so just return 0 as size, i.e., no error.

         */

        g_free(fdt);

        return 0;

    }



    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells");

    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells");

    if (acells == 0 || scells == 0) {

        fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");

        goto fail;

    }



    if (scells < 2 && binfo->ram_size >= (1ULL << 32)) {

        /* This is user error so deserves a friendlier error message

         * than the failure of setprop_sized_cells would provide

         */

        fprintf(stderr, "qemu: dtb file not compatible with "

                "RAM size > 4GB\n");

        goto fail;

    }



    rc = qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg",

                                      acells, binfo->loader_start,

                                      scells, binfo->ram_size);

    if (rc < 0) {

        fprintf(stderr, "couldn't set /memory/reg\n");

        goto fail;

    }



    if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {

        rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",

                                     binfo->kernel_cmdline);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/bootargs\n");

            goto fail;

        }

    }



    if (binfo->initrd_size) {

        rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",

                                   binfo->initrd_start);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");

            goto fail;

        }



        rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",

                                   binfo->initrd_start + binfo->initrd_size);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");

            goto fail;

        }

    }



    if (binfo->modify_dtb) {

        binfo->modify_dtb(binfo, fdt);

    }



    qemu_fdt_dumpdtb(fdt, size);



    /* Put the DTB into the memory map as a ROM image: this will ensure

     * the DTB is copied again upon reset, even if addr points into RAM.

     */

    rom_add_blob_fixed("dtb", fdt, size, addr);



    g_free(fdt);



    return size;



fail:

    g_free(fdt);

    return -1;

}

static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,

                    hwaddr addr_limit)

{

    void *fdt = NULL;

    int size, rc;

    uint32_t acells, scells;



    if (binfo->dtb_filename) {

        char *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);

            goto fail;

        }



        fdt = load_device_tree(filename, &size);

        if (!fdt) {

            fprintf(stderr, "Couldn't open dtb file %s\n", filename);

            g_free(filename);

            goto fail;

        }

        g_free(filename);

    } else if (binfo->get_dtb) {

        fdt = binfo->get_dtb(binfo, &size);

        if (!fdt) {

            fprintf(stderr, "Board was unable to create a dtb blob\n");

            goto fail;

        }

    }



    if (addr_limit > addr && size > (addr_limit - addr)) {

        







        g_free(fdt);

        return 0;

    }



    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells");

    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells");

    if (acells == 0 || scells == 0) {

        fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");

        goto fail;

    }



    if (scells < 2 && binfo->ram_size >= (1ULL << 32)) {

        





        fprintf(stderr, "qemu: dtb file not compatible with "

                "RAM size > 4GB\n");

        goto fail;

    }



    rc = qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg",

                                      acells, binfo->loader_start,

                                      scells, binfo->ram_size);

    if (rc < 0) {

        fprintf(stderr, "couldn't set /memory/reg\n");

        goto fail;

    }



    if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {

        rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",

                                     binfo->kernel_cmdline);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/bootargs\n");

            goto fail;

        }

    }



    if (binfo->initrd_size) {

        rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",

                                   binfo->initrd_start);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");

            goto fail;

        }



        rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",

                                   binfo->initrd_start + binfo->initrd_size);

        if (rc < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");

            goto fail;

        }

    }



    if (binfo->modify_dtb) {

        binfo->modify_dtb(binfo, fdt);

    }



    qemu_fdt_dumpdtb(fdt, size);



    





    rom_add_blob_fixed("dtb", fdt, size, addr);



    g_free(fdt);



    return size;



fail:

    g_free(fdt);

    return -1;

}

    } else if (binfo->get_dtb) {
static int FUNC_0(hwaddr VAR_0, const struct arm_boot_info *VAR_1,

                    hwaddr VAR_2)

{

    void *VAR_3 = NULL;

    int VAR_4, VAR_5;

    uint32_t acells, scells;



    if (VAR_1->dtb_filename) {

        char *VAR_6;

        VAR_6 = qemu_find_file(QEMU_FILE_TYPE_BIOS, VAR_1->dtb_filename);

        if (!VAR_6) {

            fprintf(stderr, "Couldn't open dtb file %s\n", VAR_1->dtb_filename);

            goto fail;

        }



        VAR_3 = load_device_tree(VAR_6, &VAR_4);

        if (!VAR_3) {

            fprintf(stderr, "Couldn't open dtb file %s\n", VAR_6);

            g_free(VAR_6);

            goto fail;

        }

        g_free(VAR_6);

    } else if (VAR_1->get_dtb) {

        VAR_3 = VAR_1->get_dtb(VAR_1, &VAR_4);

        if (!VAR_3) {

            fprintf(stderr, "Board was unable to create a dtb blob\n");

            goto fail;

        }

    }



    if (VAR_2 > VAR_0 && VAR_4 > (VAR_2 - VAR_0)) {

        







        g_free(VAR_3);

        return 0;

    }



    acells = qemu_fdt_getprop_cell(VAR_3, "/", "#address-cells");

    scells = qemu_fdt_getprop_cell(VAR_3, "/", "#VAR_4-cells");

    if (acells == 0 || scells == 0) {

        fprintf(stderr, "dtb file invalid (#address-cells or #VAR_4-cells 0)\n");

        goto fail;

    }



    if (scells < 2 && VAR_1->ram_size >= (1ULL << 32)) {

        





        fprintf(stderr, "qemu: dtb file not compatible with "

                "RAM VAR_4 > 4GB\n");

        goto fail;

    }



    VAR_5 = qemu_fdt_setprop_sized_cells(VAR_3, "/memory", "reg",

                                      acells, VAR_1->loader_start,

                                      scells, VAR_1->ram_size);

    if (VAR_5 < 0) {

        fprintf(stderr, "couldn't set /memory/reg\n");

        goto fail;

    }



    if (VAR_1->kernel_cmdline && *VAR_1->kernel_cmdline) {

        VAR_5 = qemu_fdt_setprop_string(VAR_3, "/chosen", "bootargs",

                                     VAR_1->kernel_cmdline);

        if (VAR_5 < 0) {

            fprintf(stderr, "couldn't set /chosen/bootargs\n");

            goto fail;

        }

    }



    if (VAR_1->initrd_size) {

        VAR_5 = qemu_fdt_setprop_cell(VAR_3, "/chosen", "linux,initrd-start",

                                   VAR_1->initrd_start);

        if (VAR_5 < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");

            goto fail;

        }



        VAR_5 = qemu_fdt_setprop_cell(VAR_3, "/chosen", "linux,initrd-end",

                                   VAR_1->initrd_start + VAR_1->initrd_size);

        if (VAR_5 < 0) {

            fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");

            goto fail;

        }

    }



    if (VAR_1->modify_dtb) {

        VAR_1->modify_dtb(VAR_1, VAR_3);

    }



    qemu_fdt_dumpdtb(VAR_3, VAR_4);



    





    rom_add_blob_fixed("dtb", VAR_3, VAR_4, VAR_0);



    g_free(VAR_3);



    return VAR_4;



fail:

    g_free(VAR_3);

    return -1;

}

static int FUNC_0(hwaddr VAR_0, const struct arm_boot_info *VAR_1,
hwaddr VAR_2)
{ void *VAR_3 = NULL; int VAR_4, VAR_5; uint32_t acells, scells; if (VAR_1->dtb_filename) { char *VAR_6; VAR_6 = qemu_find_file(QEMU_FILE_TYPE_BIOS, VAR_1->dtb_filename); if (!VAR_6) { fprintf(stderr, "Couldn't open dtb file %s\n", VAR_1->dtb_filename); goto fail; } VAR_3 = load_device_tree(VAR_6, &VAR_4); if (!VAR_3) { fprintf(stderr, "Couldn't open dtb file %s\n", VAR_6); g_free(VAR_6); goto fail; } g_free(VAR_6); } else if (VAR_1->get_dtb) { VAR_3 = VAR_1->get_dtb(VAR_1, &VAR_4); if (!VAR_3) { fprintf(stderr, "Board was unable to create a dtb blob\n"); goto fail; } } if (VAR_2 > VAR_0 && VAR_4 > (VAR_2 - VAR_0)) { g_free(VAR_3); return 0; } acells = qemu_fdt_getprop_cell(VAR_3, "/", "#address-cells"); scells = qemu_fdt_getprop_cell(VAR_3, "/", "#VAR_4-cells"); if (acells == 0 || scells == 0) { fprintf(stderr, "dtb file invalid (#address-cells or #VAR_4-cells 0)\n"); goto fail; } if (scells < 2 && VAR_1->ram_size >= (1ULL << 32)) { fprintf(stderr, "qemu: dtb file not compatible with "
"RAM VAR_4 > 4GB\n"); goto fail; } VAR_5 = qemu_fdt_setprop_sized_cells(VAR_3, "/memory", "reg",
acells, VAR_1->loader_start,
scells, VAR_1->ram_size); if (VAR_5 < 0) { fprintf(stderr, "couldn't set /memory/reg\n"); goto fail; } if (VAR_1->kernel_cmdline && *VAR_1->kernel_cmdline) { VAR_5 = qemu_fdt_setprop_string(VAR_3, "/chosen", "bootargs",
VAR_1->kernel_cmdline); if (VAR_5 < 0) { fprintf(stderr, "couldn't set /chosen/bootargs\n"); goto fail; } } if (VAR_1->initrd_size) { VAR_5 = qemu_fdt_setprop_cell(VAR_3, "/chosen", "linux,initrd-start",
VAR_1->initrd_start); if (VAR_5 < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); goto fail; } VAR_5 = qemu_fdt_setprop_cell(VAR_3, "/chosen", "linux,initrd-end",
VAR_1->initrd_start + VAR_1->initrd_size); if (VAR_5 < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); goto fail; } } if (VAR_1->modify_dtb) { VAR_1->modify_dtb(VAR_1, VAR_3); } qemu_fdt_dumpdtb(VAR_3, VAR_4); rom_add_blob_fixed("dtb", VAR_3, VAR_4, VAR_0); g_free(VAR_3); return VAR_4; fail:
g_free(VAR_3); return -1; }