Patchwork [1/5] define image_file_reset and image_blob_reset

login
register
mail settings
Submitter Olivia Yin
Date Oct. 26, 2012, 8:02 a.m.
Message ID <1351238526-2551-2-git-send-email-hong-hua.yin@freescale.com>
Download mbox | patch
Permalink /patch/194399/
State New
Headers show

Comments

Olivia Yin - Oct. 26, 2012, 8:02 a.m.
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com>
---
 hw/loader.c |   39 +++++++++++++++++++++++++++++++++++++++
 hw/loader.h |   18 ++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
陳韋任 - Oct. 26, 2012, 9:28 a.m.
> +typedef struct ImageFile ImageFile;
> +struct ImageFile {
> +    char *name;
> +    char *dir;
> +    target_phys_addr_t addr;

   target_phys_addr_t has been replaced with hwaddr,
see [1].

> +};
> +
> +typedef struct ImageBlob ImageBlob;
> +struct ImageBlob {
> +    char *name;
> +    target_phys_addr_t addr;
  
  ditto.

Regards,
chenwj

[1]
http://git.qemu.org/qemu.git/commit/?id=51ef67270b1d10e1fcf3de7368dccad1ba0bf9d1

Patch

diff --git a/hw/loader.c b/hw/loader.c
index 33acc2f..726c0e7 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -86,6 +86,45 @@  int load_image(const char *filename, uint8_t *addr)
     return size;
 }
 
+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);
+    }
+}
+
+void image_blob_reset(void *opaque)
+{
+    ImageBlob *blob = opaque;
+    cpu_physical_memory_rw(blob->addr, blob->data, blob->size, 1);
+}
+
 /* read()-like version */
 ssize_t read_targphys(const char *name,
                       int fd, target_phys_addr_t dst_addr, size_t nbytes)
diff --git a/hw/loader.h b/hw/loader.h
index 6da291e..e9dc4df 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -46,4 +46,22 @@  void do_info_roms(Monitor *mon);
 int rom_add_vga(const char *file);
 int rom_add_option(const char *file, int32_t bootindex);
 
+typedef struct ImageFile ImageFile;
+struct ImageFile {
+    char *name;
+    char *dir;
+    target_phys_addr_t addr;
+};
+
+typedef struct ImageBlob ImageBlob;
+struct ImageBlob {
+    char *name;
+    target_phys_addr_t addr;
+    ssize_t size;
+    uint8_t *data;
+};
+
+void image_blob_reset(void *opaque);
+void image_file_reset(void *opaque);
+
 #endif