From patchwork Wed Nov 14 13:28:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivia Yin X-Patchwork-Id: 198924 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 A66AD2C00A9 for ; Thu, 15 Nov 2012 01:44:58 +1100 (EST) Received: from localhost ([::1]:40483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYeD1-0004ti-UC for incoming@patchwork.ozlabs.org; Wed, 14 Nov 2012 09:44:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYeCs-0004sG-9r for qemu-devel@nongnu.org; Wed, 14 Nov 2012 09:44:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYeCp-0002o0-7b for qemu-devel@nongnu.org; Wed, 14 Nov 2012 09:44:46 -0500 Received: from co9ehsobe001.messaging.microsoft.com ([207.46.163.24]:56230 helo=co9outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYeCi-0002mc-QH; Wed, 14 Nov 2012 09:44:37 -0500 Received: from mail72-co9-R.bigfish.com (10.236.132.235) by CO9EHSOBE031.bigfish.com (10.236.130.94) with Microsoft SMTP Server id 14.1.225.23; Wed, 14 Nov 2012 14:14:23 +0000 Received: from mail72-co9 (localhost [127.0.0.1]) by mail72-co9-R.bigfish.com (Postfix) with ESMTP id EBAE51403F2; Wed, 14 Nov 2012 14:14:22 +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: 1 X-BigFish: VS1(z551bizzz1de0h1202h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h1155h) Received: from mail72-co9 (localhost.localdomain [127.0.0.1]) by mail72-co9 (MessageSwitch) id 135290246189696_20144; Wed, 14 Nov 2012 14:14:21 +0000 (UTC) Received: from CO9EHSMHS019.bigfish.com (unknown [10.236.132.227]) by mail72-co9.bigfish.com (Postfix) with ESMTP id 14139420057; Wed, 14 Nov 2012 14:14:21 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS019.bigfish.com (10.236.130.29) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 14 Nov 2012 14:14:19 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.318.3; Wed, 14 Nov 2012 14:14:18 +0000 Received: from localhost.localdomain (rock.ap.freescale.net [10.193.20.106]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id qAEEE6XF022652; Wed, 14 Nov 2012 07:14:17 -0700 From: Olivia Yin To: , Date: Wed, 14 Nov 2012 21:28:51 +0800 Message-ID: <1352899732-1197-3-git-send-email-hong-hua.yin@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1352899732-1197-2-git-send-email-hong-hua.yin@freescale.com> References: <1352899732-1197-1-git-send-email-hong-hua.yin@freescale.com> <1352899732-1197-2-git-send-email-hong-hua.yin@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.46.163.24 Cc: Olivia Yin Subject: [Qemu-devel] [RFC PATCH v4 2/3] use uimage_reset to reload uimage 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 Signed-off-by: Olivia Yin --- hw/loader.c | 64 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 46 insertions(+), 18 deletions(-) diff --git a/hw/loader.c b/hw/loader.c index a8a0a09..1a909d0 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -55,6 +55,8 @@ #include static int roms_loaded; +static int kernel_loaded; +static int *is_linux; /* return the size or -1 if error */ int get_image_size(const char *filename) @@ -472,15 +474,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, hwaddr *ep, - hwaddr *loadaddr, int *is_linux) +/* write uimage into memory */ +static int uimage_physical_loader(const char *filename, uint8_t **data, + hwaddr *loadaddr, int *is_linux) { 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); @@ -521,10 +522,9 @@ int load_uimage(const char *filename, hwaddr *ep, *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 +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,9 @@ 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 (!kernel_loaded) { + rom_add_blob_fixed(filename, *data, hdr->ih_size, hdr->ih_load); + } if (loadaddr) *loadaddr = hdr->ih_load; @@ -555,12 +557,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; + int size; + + size = uimage_physical_loader(image->name, &data, &image->addr, is_linux); + cpu_physical_memory_write(image->addr, data, size); + 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, &data, loadaddr, is_linux); + if (size > 0) { + kernel_loaded = 1; + 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. @@ -708,11 +739,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; } }