From patchwork Thu Dec 6 04:00:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivia Yin X-Patchwork-Id: 204128 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 DF20A2C0123 for ; Thu, 6 Dec 2012 15:50:41 +1100 (EST) Received: from localhost ([::1]:60610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgTPx-000374-LY for incoming@patchwork.ozlabs.org; Wed, 05 Dec 2012 23:50:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgTPj-000341-Vc for qemu-devel@nongnu.org; Wed, 05 Dec 2012 23:50:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgTPh-00022s-8e for qemu-devel@nongnu.org; Wed, 05 Dec 2012 23:50:23 -0500 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182]:20158 helo=ch1outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgTPe-000228-RF; Wed, 05 Dec 2012 23:50:18 -0500 Received: from mail128-ch1-R.bigfish.com (10.43.68.235) by CH1EHSOBE017.bigfish.com (10.43.70.67) with Microsoft SMTP Server id 14.1.225.23; Thu, 6 Dec 2012 04:50:17 +0000 Received: from mail128-ch1 (localhost [127.0.0.1]) by mail128-ch1-R.bigfish.com (Postfix) with ESMTP id 83455200095; Thu, 6 Dec 2012 04:50:17 +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(z551bizzz1de0h1202h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h162dh1631h1155h) Received: from mail128-ch1 (localhost.localdomain [127.0.0.1]) by mail128-ch1 (MessageSwitch) id 1354769416224057_15550; Thu, 6 Dec 2012 04:50:16 +0000 (UTC) Received: from CH1EHSMHS013.bigfish.com (snatpool3.int.messaging.microsoft.com [10.43.68.229]) by mail128-ch1.bigfish.com (Postfix) with ESMTP id 34D204006E; Thu, 6 Dec 2012 04:50:16 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS013.bigfish.com (10.43.70.13) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 6 Dec 2012 04:50:16 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.318.3; Thu, 6 Dec 2012 04:50:15 +0000 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 qB64o8Qv019044; Wed, 5 Dec 2012 21:50:13 -0700 From: Olivia Yin To: , Date: Thu, 6 Dec 2012 12:00:41 +0800 Message-ID: <1354766444-1103-2-git-send-email-hong-hua.yin@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1354766444-1103-1-git-send-email-hong-hua.yin@freescale.com> References: <1354766444-1103-1-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: 216.32.181.182 Cc: Olivia Yin Subject: [Qemu-devel] [RFC PATCH v8 1/4] use image_file_reset to reload initrd 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 | 24 ++++++++++++++++++++++++ hw/loader.h | 6 ++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/hw/loader.c b/hw/loader.c index ba01ca6..f62aa7c 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -86,6 +86,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_write(image->addr, (uint8_t *)content, size); + g_free(content); + } +} + /* read()-like version */ ssize_t read_targphys(const char *name, int fd, hwaddr dst_addr, size_t nbytes) @@ -113,6 +131,12 @@ int load_image_targphys(const char *filename, } 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; } diff --git a/hw/loader.h b/hw/loader.h index 26480ad..9e76ebd 100644 --- a/hw/loader.h +++ b/hw/loader.h @@ -1,6 +1,12 @@ #ifndef LOADER_H #define LOADER_H +typedef struct ImageFile ImageFile; +struct ImageFile { + char *name; + hwaddr addr; +}; + /* loader.c */ int get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */