Signed-off-by: Olivia Yin <hong-hua....@freescale.com> --- hw/loader.c | 24 ++++++++++++++++++++++++ hw/loader.h | 6 ++++++ 2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/hw/loader.c b/hw/loader.c index ba01ca6..f62aa7c 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -86,6 +86,24 @@ int load_image(const char *filename, uint8_t *addr) return size; } +static void image_file_reset(void *opaque) +{ + ImageFile *image = opaque; + GError *err = NULL; + gboolean res; + gchar *content; + gsize size; + + res = g_file_get_contents(image->name, &content, &size, &err); + if (res == FALSE) { + error_report("failed to read image file: %s\n", image->name); + g_error_free(err); + } else { + cpu_physical_memory_write(image->addr, (uint8_t *)content, size); + g_free(content); + } +} + /* read()-like version */ ssize_t read_targphys(const char *name, int fd, hwaddr dst_addr, size_t nbytes) @@ -113,6 +131,12 @@ int load_image_targphys(const char *filename, } if (size > 0) { rom_add_file_fixed(filename, addr, -1); + + ImageFile *image; + image = g_malloc0(sizeof(*image)); + image->name = g_strdup(filename); + image->addr = addr; + qemu_register_reset(image_file_reset, image); } return size; } diff --git a/hw/loader.h b/hw/loader.h index 26480ad..9e76ebd 100644 --- a/hw/loader.h +++ b/hw/loader.h @@ -1,6 +1,12 @@ #ifndef LOADER_H #define LOADER_H +typedef struct ImageFile ImageFile; +struct ImageFile { + char *name; + hwaddr addr; +}; + /* loader.c */ int get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */ -- 1.7.1