From patchwork Fri Jun 28 17:32:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11023085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F1AE1920 for ; Fri, 28 Jun 2019 18:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC1528B30 for ; Fri, 28 Jun 2019 18:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E91C28B2B; Fri, 28 Jun 2019 18:06:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D17A28B2B for ; Fri, 28 Jun 2019 18:06:32 +0000 (UTC) Received: from localhost ([::1]:35114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgvGZ-0001FU-DY for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Jun 2019 14:06:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55191) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgulK-0000co-CW for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgulI-00012L-02 for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:34:14 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:32984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hgulH-000112-Pb for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:34:11 -0400 Received: by mail-pf1-f195.google.com with SMTP id x15so3339110pfq.0 for ; Fri, 28 Jun 2019 10:34:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=Ll0IfljzezEKYOWEmbGf9wV1tOe7NCSXkPQeobGClJk=; b=XWfC6Lwxqdz8Q5aaiUpmtEVr8b8vxoUQoTE6rBkjgYcqlzBryaB8F2OtKbZlqjx8ls n7AuSPHOWL9wi7BTL3Jh1/DWdp3JgJR3y1r4BCjZAWuco3fgjNOcZSYMt9oysz8H8mRv RFGr13GZmJ2cGSg6GiGzrik5vw7uzCeypZMVxDIWLZEiNp8QBMeZ6jCNIV6hHQhT1Zs1 VOPnt4mSvt6tg2s7s7kqNams0BBbhRjSMt1R58K43BT3saDmus/uB++VgbJ0mPghxLjI IV1xviQ0bYLN+3K3bJdneYKdzgFfJ1NLos/kes3rCZipGqkXFSfihm9HiPDBf1Qo4e6q NG9g== X-Gm-Message-State: APjAAAWrKZxjpRJyfUPGEnTPyVJvq+66WOAFoy8QKpk3ubJHENfhsjPr x5FOL2UgcUXpr9bRXCPED+uQ89opoTMYoij8 X-Google-Smtp-Source: APXvYqze22H5KcEhFfCajKSVrhJiw1mfdoinFOIu7mWm/myddmt14oH1wqDEva/AHHx/VANH0uopxA== X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr14592101pjs.73.1561743250039; Fri, 28 Jun 2019 10:34:10 -0700 (PDT) Received: from localhost (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id 64sm4146984pfe.128.2019.06.28.10.34.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 10:34:09 -0700 (PDT) Date: Fri, 28 Jun 2019 10:32:25 -0700 Message-Id: <20190628173227.31925-33-palmer@sifive.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190628173227.31925-1-palmer@sifive.com> References: <20190628173227.31925-1-palmer@sifive.com> MIME-Version: 1.0 From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.195 Subject: [Qemu-devel] [PULL 32/34] hw/riscv: Extend the kernel loading support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , Bin Meng , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Palmer Dabbelt Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alistair Francis Extend the RISC-V kernel loader to support Image and uImage files. A Linux kernel can now be booted with: qemu-system-riscv64 -machine virt -bios fw_jump.bin -kernel Image Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Signed-off-by: Palmer Dabbelt --- hw/riscv/boot.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 883df49a0c65..ff023f42d01d 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -56,12 +56,22 @@ target_ulong riscv_load_kernel(const char *kernel_filename) uint64_t kernel_entry, kernel_high; if (load_elf(kernel_filename, NULL, NULL, NULL, - &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) < 0) { - error_report("could not load kernel '%s'", kernel_filename); - exit(1); + &kernel_entry, NULL, &kernel_high, 0, EM_RISCV, 1, 0) > 0) { + return kernel_entry; } - return kernel_entry; + if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL, + NULL, NULL, NULL) > 0) { + return kernel_entry; + } + + if (load_image_targphys_as(kernel_filename, KERNEL_BOOT_ADDRESS, + ram_size, NULL) > 0) { + return KERNEL_BOOT_ADDRESS; + } + + error_report("could not load kernel '%s'", kernel_filename); + exit(1); } hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,