int load_uboot(const char *filename, target_ulong *ep, int *is_linux)

{



    int fd;

    int size;

    uboot_image_header_t h;

    uboot_image_header_t *hdr = &h;

    uint8_t *data = NULL;



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0)

        return -1;



    size = read(fd, hdr, sizeof(uboot_image_header_t));

    if (size < 0)

        goto fail;



    bswap_uboot_header(hdr);



    if (hdr->ih_magic != IH_MAGIC)

        goto fail;



    /* TODO: Implement Multi-File images.  */

    if (hdr->ih_type == IH_TYPE_MULTI) {

        fprintf(stderr, "Unable to load multi-file u-boot images\n");

        goto fail;

    }



    /* TODO: Implement compressed images.  */

    if (hdr->ih_comp != IH_COMP_NONE) {

        fprintf(stderr, "Unable to load compressed u-boot images\n");

        goto fail;

    }



    /* TODO: Check CPU type.  */

    if (is_linux) {

        if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_os == IH_OS_LINUX)

            *is_linux = 1;

        else

            *is_linux = 0;

    }



    *ep = hdr->ih_ep;

    data = qemu_malloc(hdr->ih_size);

    if (!data)

        goto fail;



    if (read(fd, data, hdr->ih_size) != hdr->ih_size) {

        fprintf(stderr, "Error reading file\n");

        goto fail;

    }



    cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);



    return hdr->ih_size;



fail:

    if (data)

        qemu_free(data);

    close(fd);

    return -1;

}

int load_uboot(const char *filename, target_ulong *ep, int *is_linux)

{



    int fd;

    int size;

    uboot_image_header_t h;

    uboot_image_header_t *hdr = &h;

    uint8_t *data = NULL;



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0)

        return -1;



    size = read(fd, hdr, sizeof(uboot_image_header_t));

    if (size < 0)

        goto fail;



    bswap_uboot_header(hdr);



    if (hdr->ih_magic != IH_MAGIC)

        goto fail;



    

    if (hdr->ih_type == IH_TYPE_MULTI) {

        fprintf(stderr, "Unable to load multi-file u-boot images\n");

        goto fail;

    }



    

    if (hdr->ih_comp != IH_COMP_NONE) {

        fprintf(stderr, "Unable to load compressed u-boot images\n");

        goto fail;

    }



    

    if (is_linux) {

        if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_os == IH_OS_LINUX)

            *is_linux = 1;

        else

            *is_linux = 0;

    }



    *ep = hdr->ih_ep;

    data = qemu_malloc(hdr->ih_size);

    if (!data)

        goto fail;



    if (read(fd, data, hdr->ih_size) != hdr->ih_size) {

        fprintf(stderr, "Error reading file\n");

        goto fail;

    }



    cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);



    return hdr->ih_size;



fail:

    if (data)

        qemu_free(data);

    close(fd);

    return -1;

}

        goto fail;         goto fail;         goto fail;         goto fail;         goto fail;         goto fail;     return hdr->ih_size; fail:     return -1;
int FUNC_0(const char *VAR_0, target_ulong *VAR_1, int *VAR_2)

{



    int VAR_3;

    int VAR_4;

    uboot_image_header_t h;

    uboot_image_header_t *hdr = &h;

    uint8_t *data = NULL;



    VAR_3 = open(VAR_0, O_RDONLY | O_BINARY);

    if (VAR_3 < 0)

        return -1;



    VAR_4 = read(VAR_3, hdr, sizeof(uboot_image_header_t));

    if (VAR_4 < 0)

        goto fail;



    bswap_uboot_header(hdr);



    if (hdr->ih_magic != IH_MAGIC)

        goto fail;



    

    if (hdr->ih_type == IH_TYPE_MULTI) {

        fprintf(stderr, "Unable to load multi-file u-boot images\n");

        goto fail;

    }



    

    if (hdr->ih_comp != IH_COMP_NONE) {

        fprintf(stderr, "Unable to load compressed u-boot images\n");

        goto fail;

    }



    

    if (VAR_2) {

        if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_os == IH_OS_LINUX)

            *VAR_2 = 1;

        else

            *VAR_2 = 0;

    }



    *VAR_1 = hdr->ih_ep;

    data = qemu_malloc(hdr->ih_size);

    if (!data)

        goto fail;



    if (read(VAR_3, data, hdr->ih_size) != hdr->ih_size) {

        fprintf(stderr, "Error reading file\n");

        goto fail;

    }



    cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);



    return hdr->ih_size;



fail:

    if (data)

        qemu_free(data);

    close(VAR_3);

    return -1;

}

int FUNC_0(const char *VAR_0, target_ulong *VAR_1, int *VAR_2)
{ int VAR_3; int VAR_4; uboot_image_header_t h; uboot_image_header_t *hdr = &h; uint8_t *data = NULL; VAR_3 = open(VAR_0, O_RDONLY | O_BINARY); if (VAR_3 < 0)
return -1; VAR_4 = read(VAR_3, hdr, sizeof(uboot_image_header_t)); if (VAR_4 < 0)
goto fail; bswap_uboot_header(hdr); if (hdr->ih_magic != IH_MAGIC)
goto fail; if (hdr->ih_type == IH_TYPE_MULTI) { fprintf(stderr, "Unable to load multi-file u-boot images\n"); goto fail; } if (hdr->ih_comp != IH_COMP_NONE) { fprintf(stderr, "Unable to load compressed u-boot images\n"); goto fail; } if (VAR_2) { if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_os == IH_OS_LINUX)
*VAR_2 = 1; else
*VAR_2 = 0; } *VAR_1 = hdr->ih_ep; data = qemu_malloc(hdr->ih_size); if (!data)
goto fail; if (read(VAR_3, data, hdr->ih_size) != hdr->ih_size) { fprintf(stderr, "Error reading file\n"); goto fail; } cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size); return hdr->ih_size; fail:
if (data)
qemu_free(data); close(VAR_3); return -1; }