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

{

    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;

        }

    }



    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 0;



fail:

    g_free(fdt);

    return -1;

}

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

{

    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;

        }

    }



    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 0;



fail:

    g_free(fdt);

    return -1;

}

static int FUNC_0(hwaddr VAR_0, const struct arm_boot_info *VAR_1)

{

    void *VAR_2 = NULL;

    int VAR_3, VAR_4;

    uint32_t acells, scells;



    if (VAR_1->dtb_filename) {

        char *VAR_5;

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

        if (!VAR_5) {

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

            goto fail;

        }



        VAR_2 = load_device_tree(VAR_5, &VAR_3);

        if (!VAR_2) {

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

            g_free(VAR_5);

            goto fail;

        }

        g_free(VAR_5);

    } else if (VAR_1->get_dtb) {

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

        if (!VAR_2) {

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

            goto fail;

        }

    }



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

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

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

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

        goto fail;

    }



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

        





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

                "RAM VAR_3 > 4GB\n");

        goto fail;

    }



    VAR_4 = qemu_fdt_setprop_sized_cells(VAR_2, "/memory", "reg",

                                      acells, VAR_1->loader_start,

                                      scells, VAR_1->ram_size);

    if (VAR_4 < 0) {

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

        goto fail;

    }



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

        VAR_4 = qemu_fdt_setprop_string(VAR_2, "/chosen", "bootargs",

                                     VAR_1->kernel_cmdline);

        if (VAR_4 < 0) {

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

            goto fail;

        }

    }



    if (VAR_1->initrd_size) {

        VAR_4 = qemu_fdt_setprop_cell(VAR_2, "/chosen", "linux,initrd-start",

                                   VAR_1->initrd_start);

        if (VAR_4 < 0) {

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

            goto fail;

        }



        VAR_4 = qemu_fdt_setprop_cell(VAR_2, "/chosen", "linux,initrd-end",

                                   VAR_1->initrd_start + VAR_1->initrd_size);

        if (VAR_4 < 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_2);

    }



    qemu_fdt_dumpdtb(VAR_2, VAR_3);



    





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



    g_free(VAR_2);



    return 0;



fail:

    g_free(VAR_2);

    return -1;

}

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