From patchwork Wed Jul 26 23:56:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 9866039 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 0530060225 for ; Wed, 26 Jul 2017 23:57:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB3A728770 for ; Wed, 26 Jul 2017 23:57:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF235287A3; Wed, 26 Jul 2017 23:57:41 +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 7E48C28770 for ; Wed, 26 Jul 2017 23:57:41 +0000 (UTC) Received: from localhost ([::1]:40398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daWBQ-00078L-OP for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Jul 2017 19:57:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daWAR-00077B-Sv for qemu-devel@nongnu.org; Wed, 26 Jul 2017 19:56:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daWAO-0003dP-7p for qemu-devel@nongnu.org; Wed, 26 Jul 2017 19:56:39 -0400 Received: from hall.aurel32.net ([2001:bc8:30d7:100::1]:39976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1daWAO-0003Z9-12 for qemu-devel@nongnu.org; Wed, 26 Jul 2017 19:56:36 -0400 Received: from qbt56-1-78-231-237-216.fbx.proxad.net ([78.231.237.216] helo=ohm.local) by hall.aurel32.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1daWAF-0002wt-Fb; Thu, 27 Jul 2017 01:56:27 +0200 Received: from aurel32 by ohm.local with local (Exim 4.89) (envelope-from ) id 1daWA4-0003tY-TP; Thu, 27 Jul 2017 01:56:16 +0200 From: Aurelien Jarno To: qemu-devel@nongnu.org Date: Thu, 27 Jul 2017 01:56:13 +0200 Message-Id: <20170726235614.14687-2-aurelien@aurel32.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170726235614.14687-1-aurelien@aurel32.net> References: <20170726235614.14687-1-aurelien@aurel32.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:bc8:30d7:100::1 Subject: [Qemu-devel] [PATCH for 2.10 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: Yongbok Kim , Alexey Kardashevskiy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é --- 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 3f3cb32651..3532399a13 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 3487d16f61..8ecd544baa 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 6990b1b0dd..07fc4c2300 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 690874be2b..2f5ced7409 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); }