Patchwork [2/5] use reset handlers to reload kernel and initrd

login
register
mail settings
Submitter Olivia Yin
Date Oct. 26, 2012, 8:02 a.m.
Message ID <1351238526-2551-3-git-send-email-hong-hua.yin@freescale.com>
Download mbox | patch
Permalink /patch/194400/
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 |   64 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 42 insertions(+), 22 deletions(-)
陳韋任 - Oct. 26, 2012, 9:32 a.m.
> -/* Load a U-Boot image.  */
> -int load_uimage(const char *filename, target_phys_addr_t *ep,
> -                target_phys_addr_t *loadaddr, int *is_linux)
> +/* write uimage into memory */
> +static int uimage_physical_loader(const char *filename, uint8_t **data,
> +                                  target_phys_addr_t *loadaddr)
                                     ^^^^^^^^^^^^^^^^^^
   Use hwaddr instead. I guess you need rebase to the trunk which
replace target_phys_addr_t with hwaddr everywhere.

Regards,
chenwj
Yin Olivia-R63875 - Oct. 29, 2012, 5:12 a.m.
Hi Wei-Ren,

Thanks for the reminder. I'll update the patches and submit again.

Best Regards,
Olivia

> -----Original Message-----

> From: 陳韋任 (Wei-Ren Chen) [mailto:chenwj@iis.sinica.edu.tw]

> Sent: Friday, October 26, 2012 5:32 PM

> To: Yin Olivia-R63875

> Cc: qemu-ppc@nongnu.org; qemu-devel@nongnu.org

> Subject: Re: [Qemu-devel] [PATCH 2/5] use reset handlers to reload kernel

> and initrd

> 

> > -/* Load a U-Boot image.  */

> > -int load_uimage(const char *filename, target_phys_addr_t *ep,

> > -                target_phys_addr_t *loadaddr, int *is_linux)

> > +/* write uimage into memory */

> > +static int uimage_physical_loader(const char *filename, uint8_t **data,

> > +                                  target_phys_addr_t *loadaddr)

>                                      ^^^^^^^^^^^^^^^^^^

>    Use hwaddr instead. I guess you need rebase to the trunk which replace

> target_phys_addr_t with hwaddr everywhere.

> 

> Regards,

> chenwj

> 

> --

> Wei-Ren Chen (陳韋任)

> Computer Systems Lab, Institute of Information Science, Academia Sinica,

> Taiwan (R.O.C.)

> Tel:886-2-2788-3799 #1667

> Homepage: http://people.cs.nctu.edu.tw/~chenwj

Patch

diff --git a/hw/loader.c b/hw/loader.c
index 726c0e7..4a20ed2 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -151,7 +151,12 @@  int load_image_targphys(const char *filename,
         return -1;
     }
     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;
 }
@@ -472,15 +477,14 @@  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, target_phys_addr_t *ep,
-                target_phys_addr_t *loadaddr, int *is_linux)
+/* write uimage into memory */
+static int uimage_physical_loader(const char *filename, uint8_t **data,
+                                  target_phys_addr_t *loadaddr)
 {
     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);
@@ -513,18 +517,9 @@  int load_uimage(const char *filename, target_phys_addr_t *ep,
         goto out;
     }
 
-    /* TODO: Check CPU type.  */
-    if (is_linux) {
-        if (hdr->ih_os == IH_OS_LINUX)
-            *is_linux = 1;
-        else
-            *is_linux = 0;
-    }
-
-    *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 +529,11 @@  int load_uimage(const char *filename, target_phys_addr_t *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 +542,6 @@  int load_uimage(const char *filename, target_phys_addr_t *ep,
         hdr->ih_size = bytes;
     }
 
-    rom_add_blob_fixed(filename, data, hdr->ih_size, hdr->ih_load);
 
     if (loadaddr)
         *loadaddr = hdr->ih_load;
@@ -555,12 +549,38 @@  int load_uimage(const char *filename, target_phys_addr_t *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;
+    int size;
+
+    size = uimage_physical_loader(image->name, &data, &image->addr);
+    cpu_physical_memory_rw(image->addr, data, size, 1);
+    g_free(data);
+}
+
+/* Load a U-Boot image.  */
+int load_uimage(const char *filename, target_phys_addr_t *ep,
+                target_phys_addr_t *loadaddr, int *is_linux)
+{
+    int size;
+    ImageFile *image;
+    uint8_t *data = NULL;
+
+    size= uimage_physical_loader(filename, &data, loadaddr);
+    g_free(data);
+    image = g_malloc0(sizeof(*image));
+    image->name = g_strdup(filename);
+    image->addr = *loadaddr;
+    qemu_register_reset(uimage_reset, image);
+    return size;
+}
+
 /*
  * Functions for reboot-persistent memory regions.
  *  - used for vga bios and option roms.