From patchwork Wed Jun 6 20:55:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Collins X-Patchwork-Id: 163425 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 CFED9B6FA4 for ; Thu, 7 Jun 2012 06:55:42 +1000 (EST) Received: from localhost ([::1]:55404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScNGW-0006HN-84 for incoming@patchwork.ozlabs.org; Wed, 06 Jun 2012 16:55:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScNGO-0006H8-M1 for qemu-devel@nongnu.org; Wed, 06 Jun 2012 16:55:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ScNGM-0001uw-Jn for qemu-devel@nongnu.org; Wed, 06 Jun 2012 16:55:32 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:39098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScNGM-0001uf-7g for qemu-devel@nongnu.org; Wed, 06 Jun 2012 16:55:30 -0400 Received: by pbbro12 with SMTP id ro12so58714pbb.4 for ; Wed, 06 Jun 2012 13:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:content-type:subject:date:message-id:cc:to:mime-version :x-mailer; bh=mKAFVclGRSSTgL7JHlAqEFOFM0I8J7GeBcVnHEVrfRw=; b=pQYIrFMlRCg5HYHsTQghZPpljdF/PcVaA4mfZW3X7yJosb32akZiJ161HI6irsy2Pt Dy4KMyZHTtchPl/yVjggP3uRyY2NEULx6a5VduZXaE3tzPHKN6Yz6Xtw6JOHBxTpv0VF eVnVXFG6EIWauH1dzC9hUeWWi7ikJzdw6FzDjuoVLi+MrY/TyPKiwGsqBzUYtaLr9OGY lOgk31WK01sGH8K55usFEa09RdbrNRfmhDOTAwjjGyXDfcOzWpk2j0mTu54SvvIxgG8x qVNqg3P8CPpCyBdkOATv/Cu43If37yRYfnAM0E3wUKFprOxdGDBP2gl1F5KAwWht2Fmz kV1Q== Received: by 10.68.203.40 with SMTP id kn8mr219189pbc.162.1339016127180; Wed, 06 Jun 2012 13:55:27 -0700 (PDT) Received: from [192.168.0.5] (ip68-13-200-36.hr.hr.cox.net. [68.13.200.36]) by mx.google.com with ESMTPS id ol1sm1523404pbb.25.2012.06.06.13.55.25 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Jun 2012 13:55:26 -0700 (PDT) From: Ben Collins Date: Wed, 6 Jun 2012 16:55:22 -0400 Message-Id: <7E42318E-5EFE-4F7A-93E5-DB3427574153@ubuntu.com> To: qemu-devel Mime-Version: 1.0 (Apple Message framework v1278) X-Mailer: Apple Mail (2.1278) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Scott Wood Subject: [Qemu-devel] [PATCH] Allow loading U-Boot initrd images 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 The hooks were already there for the kernel, so enabled it for initrd's too. The caveat is that we don't decompress initrd's, since the kernel can do this itself (and actually gets confused if it encounters an uncompressed image). This is based on a patch by Scott Wood that was for another purpose, but it helped with the fixed load addresses. Signed-off-by: Ben Collins Cc: Scott Wood --- hw/loader.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/hw/loader.c b/hw/loader.c index 7d64113..7c2635d 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -105,8 +105,13 @@ ssize_t read_targphys(const char *name, int load_image_targphys(const char *filename, target_phys_addr_t addr, uint64_t max_sz) { + target_phys_addr_t ep; int size; + size = load_uimage(filename, &ep, &addr, NULL); + if (size > 0) + return size; + size = get_image_size(filename); if (size > max_sz) { return -1; @@ -435,12 +440,13 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, /* Load a U-Boot image. */ int load_uimage(const char *filename, target_phys_addr_t *ep, - target_phys_addr_t *loadaddr, int *is_linux) + target_phys_addr_t *loadaddr_ptr, int *is_linux) { int fd; int size; uboot_image_header_t h; uboot_image_header_t *hdr = &h; + target_phys_addr_t loadaddr; uint8_t *data = NULL; int ret = -1; @@ -458,8 +464,9 @@ int load_uimage(const char *filename, target_phys_addr_t *ep, goto out; /* TODO: Implement other image types. */ - if (hdr->ih_type != IH_TYPE_KERNEL) { - fprintf(stderr, "Can only load u-boot image type \"kernel\"\n"); + if (hdr->ih_type != IH_TYPE_KERNEL && + hdr->ih_type != IH_TYPE_RAMDISK) { + fprintf(stderr, "Can only load u-boot image type \"kernel\" or \"ramdisk\"\n"); goto out; } @@ -482,7 +489,18 @@ int load_uimage(const char *filename, target_phys_addr_t *ep, *is_linux = 0; } - *ep = hdr->ih_ep; + loadaddr = hdr->ih_load; + + if (loadaddr_ptr) { + if (hdr->ih_type == IH_TYPE_RAMDISK) { + loadaddr = *loadaddr_ptr; + } else { + *loadaddr_ptr = loadaddr; + } + } + + *ep = loadaddr + hdr->ih_ep - hdr->ih_load; + data = g_malloc(hdr->ih_size); if (read(fd, data, hdr->ih_size) != hdr->ih_size) { @@ -490,7 +508,8 @@ int load_uimage(const char *filename, target_phys_addr_t *ep, goto out; } - if (hdr->ih_comp == IH_COMP_GZIP) { + /* We don't decompress initrd's */ + if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_comp == IH_COMP_GZIP) { uint8_t *compressed_data; size_t max_bytes; ssize_t bytes; @@ -508,10 +527,7 @@ 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; + rom_add_blob_fixed(filename, data, hdr->ih_size, loadaddr); ret = hdr->ih_size;