From patchwork Fri Aug 17 09:08:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivia Yin X-Patchwork-Id: 178175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4DFC42C0099 for ; Fri, 17 Aug 2012 19:37:19 +1000 (EST) Received: from localhost ([::1]:41228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2IzU-0000u5-Jp for incoming@patchwork.ozlabs.org; Fri, 17 Aug 2012 05:37:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2IzM-0000tb-Ak for qemu-devel@nongnu.org; Fri, 17 Aug 2012 05:37:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T2IzL-00025Z-3A for qemu-devel@nongnu.org; Fri, 17 Aug 2012 05:37:08 -0400 Received: from ch1ehsobe001.messaging.microsoft.com ([216.32.181.181]:43075 helo=ch1outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2IzI-00025E-55; Fri, 17 Aug 2012 05:37:04 -0400 Received: from mail107-ch1-R.bigfish.com (10.43.68.252) by CH1EHSOBE017.bigfish.com (10.43.70.67) with Microsoft SMTP Server id 14.1.225.23; Fri, 17 Aug 2012 09:37:02 +0000 Received: from mail107-ch1 (localhost [127.0.0.1]) by mail107-ch1-R.bigfish.com (Postfix) with ESMTP id E68CB2A0518; Fri, 17 Aug 2012 09:37:02 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 11 X-BigFish: VS11(zz82c2szz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah) Received: from mail107-ch1 (localhost.localdomain [127.0.0.1]) by mail107-ch1 (MessageSwitch) id 1345196221787455_8121; Fri, 17 Aug 2012 09:37:01 +0000 (UTC) Received: from CH1EHSMHS017.bigfish.com (snatpool3.int.messaging.microsoft.com [10.43.68.228]) by mail107-ch1.bigfish.com (Postfix) with ESMTP id B44DE1A00AB; Fri, 17 Aug 2012 09:37:01 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS017.bigfish.com (10.43.70.17) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 17 Aug 2012 09:37:01 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.298.5; Fri, 17 Aug 2012 04:37:00 -0500 Received: from localhost.localdomain (rock.ap.freescale.net [10.193.20.106]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q7H9awMr008107; Fri, 17 Aug 2012 02:36:59 -0700 From: Olivia Yin To: , Date: Fri, 17 Aug 2012 17:08:29 +0800 Message-ID: <1345194509-29203-1-git-send-email-hong-hua.yin@freescale.com> X-Mailer: git-send-email 1.6.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-detected-operating-system: by eggs.gnu.org: Windows XP/2000 (RFC1323+, w+, tstamp-) X-Received-From: 216.32.181.181 Cc: Olivia Yin Subject: [Qemu-devel] [PATCH v2] register reset handler to write image into memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of add rom blobs, this patch just write them directly to memory. This patch registers reset handler uimage_reset() and image_file_reset() which load images into RAM during initial bootup and VM reset. v2: use g_file_get_content() to load load image file. Signed-off-by: Olivia Yin --- This patch is based on branch 'ppc-next' of Alex's upstream QEMU repo: http://repo.or.cz/r/qemu/agraf.git hw/loader.c | 88 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 66 insertions(+), 22 deletions(-) diff --git a/hw/loader.c b/hw/loader.c index 33acc2f..0be8bf7 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -56,6 +56,12 @@ static int roms_loaded; +typedef struct ImageFile ImageFile; +struct ImageFile { + char *name; + target_phys_addr_t addr; +}; + /* return the size or -1 if error */ int get_image_size(const char *filename) { @@ -86,6 +92,24 @@ 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; + + 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, target_phys_addr_t dst_addr, size_t nbytes) @@ -112,7 +136,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; } @@ -433,15 +462,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); @@ -474,18 +502,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; } @@ -495,11 +514,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"); @@ -508,7 +527,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; @@ -516,12 +534,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.