qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Olivia Yin <hong-hua.yin@freescale.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: Olivia Yin <hong-hua.yin@freescale.com>
Subject: [Qemu-devel] [RFC PATCH v5 2/4] use uimage_reset to reload uimage
Date: Wed, 21 Nov 2012 15:38:03 +0800	[thread overview]
Message-ID: <1353483485-17019-3-git-send-email-hong-hua.yin@freescale.com> (raw)
In-Reply-To: <1353483485-17019-1-git-send-email-hong-hua.yin@freescale.com>

Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com>
---
 hw/loader.c |   64 +++++++++++++++++++++++++++++++++++++++++++---------------
 hw/loader.h |    8 ++++++-
 2 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/hw/loader.c b/hw/loader.c
index a8a0a09..e1e2a20 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -472,15 +472,15 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src,
     return dstbytes;
 }
 
-/* Load a U-Boot image.  */
-int load_uimage(const char *filename, hwaddr *ep,
-                hwaddr *loadaddr, int *is_linux)
+/* write uimage into memory */
+static int uimage_physical_loader(const char *filename, hwaddr *ep, 
+                                  uint8_t **data, hwaddr *loadaddr,
+                                  int *is_linux, int reset)
 {
     int fd;
     int size;
     uboot_image_header_t h;
     uboot_image_header_t *hdr = &h;
-    uint8_t *data = NULL;
     int ret = -1;
 
     fd = open(filename, O_RDONLY | O_BINARY);
@@ -522,9 +522,9 @@ int load_uimage(const char *filename, hwaddr *ep,
     }
 
     *ep = hdr->ih_ep;
-    data = g_malloc(hdr->ih_size);
+    *data = g_malloc(hdr->ih_size);
 
-    if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
+    if (read(fd, *data, hdr->ih_size) != hdr->ih_size) {
         fprintf(stderr, "Error reading file\n");
         goto out;
     }
@@ -534,11 +534,11 @@ int load_uimage(const char *filename, hwaddr *ep,
         size_t max_bytes;
         ssize_t bytes;
 
-        compressed_data = data;
+        compressed_data = *data;
         max_bytes = UBOOT_MAX_GUNZIP_BYTES;
-        data = g_malloc(max_bytes);
+        *data = g_malloc(max_bytes);
 
-        bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
+        bytes = gunzip(*data, max_bytes, compressed_data, hdr->ih_size);
         g_free(compressed_data);
         if (bytes < 0) {
             fprintf(stderr, "Unable to decompress gzipped image!\n");
@@ -547,7 +547,11 @@ int load_uimage(const char *filename, hwaddr *ep,
         hdr->ih_size = bytes;
     }
 
-    rom_add_blob_fixed(filename, data, hdr->ih_size, hdr->ih_load);
+    if (!reset) {
+        rom_add_blob_fixed(filename, *data, hdr->ih_size, hdr->ih_load);
+    } else {
+        cpu_physical_memory_write(hdr->ih_load, *data, hdr->ih_size);
+    }
 
     if (loadaddr)
         *loadaddr = hdr->ih_load;
@@ -555,12 +559,41 @@ int load_uimage(const char *filename, hwaddr *ep,
     ret = hdr->ih_size;
 
 out:
-    if (data)
-        g_free(data);
     close(fd);
     return ret;
 }
 
+static void uimage_reset(void *opaque)
+{
+    ImageFile *image = opaque;
+    uint8_t *data = NULL;
+
+    uimage_physical_loader(image->name, image->ep, &data, &image->addr, 
+                           image->is_linux, 1);
+    g_free(data);
+}
+
+/* Load a U-Boot image.  */
+int load_uimage(const char *filename, hwaddr *ep,
+                hwaddr *loadaddr, int *is_linux)
+{
+    int size;
+    ImageFile *image;
+    uint8_t *data = NULL;
+
+    size= uimage_physical_loader(filename, ep, &data, loadaddr, is_linux, 0);
+    if (size > 0) {
+        g_free(data);
+        image = g_malloc0(sizeof(*image));
+        image->name = g_strdup(filename);
+        image->addr = *loadaddr;
+        image->ep = ep;
+        image->is_linux = is_linux;
+        qemu_register_reset(uimage_reset, image);
+    }
+    return size;
+}
+
 /*
  * Functions for reboot-persistent memory regions.
  *  - used for vga bios and option roms.
@@ -708,11 +741,8 @@ static void rom_reset(void *unused)
             continue;
         }
         cpu_physical_memory_write_rom(rom->addr, rom->data, rom->romsize);
-        if (rom->isrom) {
-            /* rom needs to be written only once */
-            g_free(rom->data);
-            rom->data = NULL;
-        }
+        g_free(rom->data);
+        rom->data = NULL;
     }
 }
 
diff --git a/hw/loader.h b/hw/loader.h
index d021629..08a2f6c 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -4,8 +4,14 @@
 typedef struct ImageFile ImageFile;
 struct ImageFile {
     char *name;
-    char *dir;
     hwaddr addr;
+    int reset;
+    /* rom file */
+    char *dir;
+    /* uimage */
+    hwaddr *ep;
+    int *is_linux; 
+    
 };
 
 /* loader.c */
-- 
1.7.1

  parent reply	other threads:[~2012-11-21  7:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21  7:38 [Qemu-devel] [RFC PATCH v5 0/4] reload images from host rootfs once reset to save footprint Olivia Yin
2012-11-21  7:38 ` [Qemu-devel] [RFC PATCH v5 1/4] use image_file_reset to reload initrd image Olivia Yin
2012-11-21  7:38 ` Olivia Yin [this message]
2012-11-21  7:38 ` [Qemu-devel] [RFC PATCH v5 3/4] use elf_reset to reload elf image Olivia Yin
2012-11-21  7:38 ` [Qemu-devel] [RFC PATCH v5 4/4] free the memory malloced by load_at() Olivia Yin
2012-11-21 18:39   ` Stuart Yoder
2012-11-21 18:41     ` Alexander Graf
2012-11-26  1:53       ` Yin Olivia-R63875
2012-11-26 13:03         ` Alexander Graf
2012-11-27  2:11           ` Yin Olivia-R63875

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1353483485-17019-3-git-send-email-hong-hua.yin@freescale.com \
    --to=hong-hua.yin@freescale.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).