From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdG1H-0004jB-JW for qemu-devel@nongnu.org; Tue, 27 Nov 2012 02:55:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TdG1B-00049k-HS for qemu-devel@nongnu.org; Tue, 27 Nov 2012 02:55:51 -0500 From: Olivia Yin Date: Tue, 27 Nov 2012 15:07:37 +0800 Message-ID: <1354000059-805-3-git-send-email-hong-hua.yin@freescale.com> In-Reply-To: <1354000059-805-2-git-send-email-hong-hua.yin@freescale.com> References: <1354000059-805-1-git-send-email-hong-hua.yin@freescale.com> <1354000059-805-2-git-send-email-hong-hua.yin@freescale.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [RFC PATCH v6 2/4] use uimage_reset to reload uimage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Olivia Yin Signed-off-by: Olivia Yin --- hw/loader.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------------ hw/loader.h | 6 ++++++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/hw/loader.c b/hw/loader.c index e45f56a..0d93c3b 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. diff --git a/hw/loader.h b/hw/loader.h index 9e76ebd..17654fa 100644 --- a/hw/loader.h +++ b/hw/loader.h @@ -5,6 +5,12 @@ typedef struct ImageFile ImageFile; struct ImageFile { char *name; hwaddr addr; + int reset; + /* rom file */ + char *dir; + /* uimage */ + hwaddr *ep; + int *is_linux; }; /* loader.c */ -- 1.7.1