From patchwork Tue Nov 27 07:07:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivia Yin X-Patchwork-Id: 202110 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 6A9772C008F for ; Tue, 27 Nov 2012 18:56:58 +1100 (EST) Received: from localhost ([::1]:58590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdG2K-0007Xd-MT for incoming@patchwork.ozlabs.org; Tue, 27 Nov 2012 02:56:56 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdG1T-0005K4-Kx for qemu-devel@nongnu.org; Tue, 27 Nov 2012 02:56:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TdG1Q-0004Cr-R4 for qemu-devel@nongnu.org; Tue, 27 Nov 2012 02:56:03 -0500 Received: from co9ehsobe001.messaging.microsoft.com ([207.46.163.24]:39893 helo=co9outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdG1E-00049h-6M; Tue, 27 Nov 2012 02:55:48 -0500 Received: from mail183-co9-R.bigfish.com (10.236.132.248) by CO9EHSOBE009.bigfish.com (10.236.130.72) with Microsoft SMTP Server id 14.1.225.23; Tue, 27 Nov 2012 07:55:44 +0000 Received: from mail183-co9 (localhost [127.0.0.1]) by mail183-co9-R.bigfish.com (Postfix) with ESMTP id 989CDDC011B; Tue, 27 Nov 2012 07:55:44 +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 mail183-co9 (localhost.localdomain [127.0.0.1]) by mail183-co9 (MessageSwitch) id 1354002941328286_19230; Tue, 27 Nov 2012 07:55:41 +0000 (UTC) Received: from CO9EHSMHS001.bigfish.com (unknown [10.236.132.226]) by mail183-co9.bigfish.com (Postfix) with ESMTP id 4E2698C0048; Tue, 27 Nov 2012 07:55:41 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS001.bigfish.com (10.236.130.11) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 27 Nov 2012 07:55:41 +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; Tue, 27 Nov 2012 07:55:39 +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 qAR7tJaw009818; Tue, 27 Nov 2012 00:55:36 -0700 From: Olivia Yin To: , Date: Tue, 27 Nov 2012 15:07:38 +0800 Message-ID: <1354000059-805-4-git-send-email-hong-hua.yin@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1354000059-805-3-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> <1354000059-805-3-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 v6 3/4] use elf_reset to reload elf image 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 --- elf.h | 10 ++++++++++ hw/elf_ops.h | 44 +++++++++++++++++++++++++++++++++++++++----- hw/loader.c | 11 +++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/elf.h b/elf.h index a21ea53..335f1af 100644 --- a/elf.h +++ b/elf.h @@ -1078,6 +1078,16 @@ typedef struct elf64_hdr { Elf64_Half e_shstrndx; } Elf64_Ehdr; +typedef struct ImageElf ImageElf; +struct ImageElf { + char *name; + uint64_t (*fn)(void *, uint64_t); + void *opaque; + int swab; + int machine; + int lsb; +}; + /* These constants define the permissions on sections in the program header, p_flags. */ #define PF_R 0x4 diff --git a/hw/elf_ops.h b/hw/elf_ops.h index 531a425..3ff8ffd 100644 --- a/hw/elf_ops.h +++ b/hw/elf_ops.h @@ -187,12 +187,12 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, return -1; } -static int glue(load_elf, SZ)(const char *name, int fd, +static int glue(elf_phy_loader, SZ)(const char *name, int fd, uint64_t (*translate_fn)(void *, uint64_t), void *translate_opaque, int must_swab, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, - int elf_machine, int clear_lsb) + int elf_machine, int clear_lsb, int reset) { struct elfhdr ehdr; struct elf_phdr *phdr = NULL, *ph; @@ -202,6 +202,9 @@ static int glue(load_elf, SZ)(const char *name, int fd, uint8_t *data = NULL; char label[128]; + if (reset) { + fd = open(name, O_RDONLY | O_BINARY); + } if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) goto fail; if (must_swab) { @@ -232,7 +235,9 @@ static int glue(load_elf, SZ)(const char *name, int fd, if (pentry) *pentry = (uint64_t)(elf_sword)ehdr.e_entry; - glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb); + if (!reset) { + glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb); + } size = ehdr.e_phnum * sizeof(phdr[0]); lseek(fd, ehdr.e_phoff, SEEK_SET); @@ -280,8 +285,12 @@ static int glue(load_elf, SZ)(const char *name, int fd, *pentry = ehdr.e_entry - ph->p_vaddr + ph->p_paddr; } - snprintf(label, sizeof(label), "phdr #%d: %s", i, name); - rom_add_blob_fixed(label, data, mem_size, addr); + if (!reset) { + snprintf(label, sizeof(label), "phdr #%d: %s", i, name); + rom_add_blob_fixed(label, data, mem_size, addr); + } else { + cpu_physical_memory_write(addr, data, mem_size); + } total_size += mem_size; if (addr < low) @@ -304,3 +313,28 @@ static int glue(load_elf, SZ)(const char *name, int fd, g_free(phdr); return -1; } + +static void glue(elf_reset, SZ)(void *opaque) +{ + ImageElf *elf = opaque; + int fd; + + fd = open(elf->name, O_RDONLY | O_BINARY); + glue(elf_phy_loader, SZ)(elf->name, fd, elf->fn, elf->opaque, elf->swab, + NULL, NULL, NULL, elf->machine, elf->lsb, 1); +} + +static int glue(load_elf, SZ)(const char *name, int fd, + uint64_t (*translate_fn)(void *, uint64_t), + void *translate_opaque, + int must_swab, uint64_t *pentry, + uint64_t *lowaddr, uint64_t *highaddr, + int elf_machine, int clear_lsb) +{ + int ret; + + ret = glue(elf_phy_loader, SZ)(name, fd, (*translate_fn), translate_opaque, + must_swab, pentry, lowaddr, highaddr, + elf_machine, clear_lsb, 0); + return ret; +} diff --git a/hw/loader.c b/hw/loader.c index 0d93c3b..d075ed3 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -357,13 +357,24 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), goto fail; } + ImageElf *elf; + elf = g_malloc0(sizeof(*elf)); + elf->name = g_strdup(filename); + elf->fn = translate_fn; + elf->opaque = translate_opaque; + elf->swab = must_swab; + elf->machine = elf_machine; + elf->lsb = clear_lsb; + lseek(fd, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb); + qemu_register_reset(elf_reset64, elf); } else { ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb); + qemu_register_reset(elf_reset32, elf); } close(fd);