From patchwork Fri Jan 18 09:16:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivia Yin X-Patchwork-Id: 213560 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 8FB342C0079 for ; Fri, 18 Jan 2013 21:39:25 +1100 (EST) Received: from localhost ([::1]:55091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw8yV-0001oZ-Rw for incoming@patchwork.ozlabs.org; Fri, 18 Jan 2013 05:15:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw8y3-00010i-CS for qemu-devel@nongnu.org; Fri, 18 Jan 2013 05:14:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tw8y1-0004dk-W9 for qemu-devel@nongnu.org; Fri, 18 Jan 2013 05:14:35 -0500 Received: from co9ehsobe004.messaging.microsoft.com ([207.46.163.27]:43278 helo=co9outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw8xy-0004cf-Hd; Fri, 18 Jan 2013 05:14:30 -0500 Received: from mail213-co9-R.bigfish.com (10.236.132.251) by CO9EHSOBE031.bigfish.com (10.236.130.94) with Microsoft SMTP Server id 14.1.225.23; Fri, 18 Jan 2013 10:14:29 +0000 Received: from mail213-co9 (localhost [127.0.0.1]) by mail213-co9-R.bigfish.com (Postfix) with ESMTP id 20ADFA0086; Fri, 18 Jan 2013 10:14:29 +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: 0 X-BigFish: VS0(zzzz1ee6h1de0h1202h1e76h1d1ah1d2ahzz84d07h8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h1354h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h1155h) Received: from mail213-co9 (localhost.localdomain [127.0.0.1]) by mail213-co9 (MessageSwitch) id 1358504067498704_21466; Fri, 18 Jan 2013 10:14:27 +0000 (UTC) Received: from CO9EHSMHS011.bigfish.com (unknown [10.236.132.227]) by mail213-co9.bigfish.com (Postfix) with ESMTP id 6DCC72E0054; Fri, 18 Jan 2013 10:14:27 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS011.bigfish.com (10.236.130.21) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 18 Jan 2013 10:14:27 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.2.318.3; Fri, 18 Jan 2013 10:14:26 +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 r0IAEDjB019990; Fri, 18 Jan 2013 03:14:24 -0700 From: Olivia Yin To: , Date: Fri, 18 Jan 2013 17:16:37 +0800 Message-ID: <1358500598-19518-4-git-send-email-hong-hua.yin@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1358500598-19518-3-git-send-email-hong-hua.yin@freescale.com> References: <1358500598-19518-1-git-send-email-hong-hua.yin@freescale.com> <1358500598-19518-2-git-send-email-hong-hua.yin@freescale.com> <1358500598-19518-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.27 Cc: Olivia Yin Subject: [Qemu-devel] [PATCH v9 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 --- hw/elf_ops.h | 45 ++++++++++++++++++++++++++++++++++++++++----- hw/loader.c | 11 +++++++++++ hw/loader.h | 9 +++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/hw/elf_ops.h b/hw/elf_ops.h index 531a425..25ee02a 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,29 @@ static int glue(load_elf, SZ)(const char *name, int fd, g_free(phdr); return -1; } + +static void glue(elf_reset, SZ)(void *opaque) +{ + FlatImageFile *elf = opaque; + int fd; + + fd = open(elf->image.name, O_RDONLY | O_BINARY); + glue(elf_phy_loader, SZ)(elf->image.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 89ce853..5849e32 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -343,13 +343,24 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t), goto fail; } + FlatImageFile *elf; + elf = g_malloc0(sizeof(*elf)); + elf->image.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); diff --git a/hw/loader.h b/hw/loader.h index b22d77b..69fac87 100644 --- a/hw/loader.h +++ b/hw/loader.h @@ -13,6 +13,15 @@ typedef struct UImageFile { int *is_linux; } UImageFile; +typedef struct FlatImageFile { + ImageFile image; + uint64_t (*fn)(void *, uint64_t); + void *opaque; + int swab; + int machine; + int lsb; +} FlatImageFile; + /* loader.c */ int get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */