From patchwork Fri Jul 28 13:07:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yongbok Kim X-Patchwork-Id: 9868749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5790B6035E for ; Fri, 28 Jul 2017 13:11:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 470A0288DE for ; Fri, 28 Jul 2017 13:11:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BE51288E6; Fri, 28 Jul 2017 13:11:58 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 88964288DE for ; Fri, 28 Jul 2017 13:11:57 +0000 (UTC) Received: from localhost ([::1]:48338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db53c-0007Ix-H7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Jul 2017 09:11:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db4zk-000466-JE for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:07:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db4zg-0008RU-Np for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:07:56 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:58476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db4zg-0008Qy-FV for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:07:52 -0400 Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id 40AC1711E54E2; Fri, 28 Jul 2017 14:07:47 +0100 (IST) Received: from hhmipssw204.hh.imgtec.org (10.100.21.121) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 28 Jul 2017 14:07:50 +0100 From: Yongbok Kim To: Date: Fri, 28 Jul 2017 14:07:44 +0100 Message-ID: <1501247265-22367-2-git-send-email-yongbok.kim@imgtec.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501247265-22367-1-git-send-email-yongbok.kim@imgtec.com> References: <1501247265-22367-1-git-send-email-yongbok.kim@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.100.21.121] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.59.15.196 Subject: [Qemu-devel] [PULL 1/2] hw/mips: load_elf_strerror to report kernel loading failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Aurelien Jarno Emulated MIPS boards bail out with a simple "could not load kernel" when a kernel could not be load, without specifying the underlying reason. Fix that by calling load_elf_strerror. At the same time use error_report to report the error instead of fprintf. Signed-off-by: Aurelien Jarno Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Yongbok Kim --- hw/mips/mips_fulong2e.c | 15 +++++++++------ hw/mips/mips_malta.c | 14 ++++++++------ hw/mips/mips_mipssim.c | 5 +++-- hw/mips/mips_r4k.c | 6 ++++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 3f3cb32..3532399 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -110,16 +110,19 @@ static int64_t load_kernel (CPUMIPSState *env) { int64_t kernel_entry, kernel_low, kernel_high; int index = 0; - long initrd_size; + long kernel_size, initrd_size; ram_addr_t initrd_offset; uint32_t *prom_buf; long prom_size; - if (load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, NULL, - (uint64_t *)&kernel_entry, (uint64_t *)&kernel_low, - (uint64_t *)&kernel_high, 0, EM_MIPS, 1, 0) < 0) { - fprintf(stderr, "qemu: could not load kernel '%s'\n", - loaderparams.kernel_filename); + kernel_size = load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, + NULL, (uint64_t *)&kernel_entry, + (uint64_t *)&kernel_low, (uint64_t *)&kernel_high, + 0, EM_MIPS, 1, 0); + if (kernel_size < 0) { + error_report("qemu: could not load kernel '%s': %s", + loaderparams.kernel_filename, + load_elf_strerror(kernel_size)); exit(1); } diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 3487d16..8ecd544 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -794,7 +794,7 @@ static void GCC_FMT_ATTR(3, 4) prom_set(uint32_t* prom_buf, int index, static int64_t load_kernel (void) { int64_t kernel_entry, kernel_high; - long initrd_size; + long kernel_size, initrd_size; ram_addr_t initrd_offset; int big_endian; uint32_t *prom_buf; @@ -808,11 +808,13 @@ static int64_t load_kernel (void) big_endian = 0; #endif - if (load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, NULL, - (uint64_t *)&kernel_entry, NULL, (uint64_t *)&kernel_high, - big_endian, EM_MIPS, 1, 0) < 0) { - fprintf(stderr, "qemu: could not load kernel '%s'\n", - loaderparams.kernel_filename); + kernel_size = load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, + NULL, (uint64_t *)&kernel_entry, NULL, + (uint64_t *)&kernel_high, big_endian, EM_MIPS, 1, 0); + if (kernel_size < 0) { + error_report("qemu: could not load kernel '%s': %s", + loaderparams.kernel_filename, + load_elf_strerror(kernel_size)); exit(1); } diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c index 6990b1b..07fc4c2 100644 --- a/hw/mips/mips_mipssim.c +++ b/hw/mips/mips_mipssim.c @@ -78,8 +78,9 @@ static int64_t load_kernel(void) if ((entry & ~0x7fffffffULL) == 0x80000000) entry = (int32_t)entry; } else { - fprintf(stderr, "qemu: could not load kernel '%s'\n", - loaderparams.kernel_filename); + error_report("qemu: could not load kernel '%s': %s", + loaderparams.kernel_filename, + load_elf_strerror(kernel_size)); exit(1); } diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c index 690874b..2f5ced7 100644 --- a/hw/mips/mips_r4k.c +++ b/hw/mips/mips_r4k.c @@ -31,6 +31,7 @@ #include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" +#include "qemu/error-report.h" #define MAX_IDE_BUS 2 @@ -96,8 +97,9 @@ static int64_t load_kernel(void) if ((entry & ~0x7fffffffULL) == 0x80000000) entry = (int32_t)entry; } else { - fprintf(stderr, "qemu: could not load kernel '%s'\n", - loaderparams.kernel_filename); + error_report("qemu: could not load kernel '%s': %s", + loaderparams.kernel_filename, + load_elf_strerror(kernel_size)); exit(1); }