Patchwork [RFC,v3,1/3] define image_file_reset

login
register
mail settings
Submitter Olivia Yin
Date Nov. 1, 2012, 8:50 a.m.
Message ID <1351759856-20677-2-git-send-email-hong-hua.yin@freescale.com>
Download mbox | patch
Permalink /patch/196139/
State New
Headers show

Comments

Olivia Yin - Nov. 1, 2012, 8:50 a.m.
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com>
---
 hw/loader.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/loader.c b/hw/loader.c
index ba01ca6..a4c095e 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -56,6 +56,13 @@ 
 
 static int roms_loaded;
 
+typedef struct ImageFile ImageFile;
+struct ImageFile {
+    char *name;
+    char *dir;
+    hwaddr addr;
+};
+
 /* return the size or -1 if error */
 int get_image_size(const char *filename)
 {
@@ -86,6 +93,39 @@  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;
+
+    if(image->dir) {
+        const char *basename;
+        char fw_file_name[56];
+
+        basename = strrchr(image->name, '/');
+        if (basename) {
+            basename++;
+        } else {
+            basename = image->name;
+        }
+        snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", image->dir,
+                 basename);
+        image->name = g_strdup(fw_file_name);
+    }
+
+    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_rw(image->addr, (uint8_t *)content, size, 1);
+       g_free(content);
+    }
+}
+
 /* read()-like version */
 ssize_t read_targphys(const char *name,
                       int fd, hwaddr dst_addr, size_t nbytes)