From patchwork Fri Mar 21 18:44:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 26866 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1962420143 for ; Fri, 21 Mar 2014 18:44:49 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id w5sf5627749qac.0 for ; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=GOK2rNZpqq+3d/Yr9x6QiedJ9XjBA5tZDcp4aDgJmN4=; b=dyF8sIcd6LMrxEhL3m40kQtd8EHpGsss1S7AvpFjIbj8iNKcjF/6FMYUvfYVGVRR97 Iw/asb239VLG9KLuifjcTViLFgRFgPj0s07gAkkaYbKWV7ZsTdQrH2+Ceom9yTUIoghK i11EvtmTD5krec+yen52xHxdOwlDM2kvNCkdw7pI+xavhiyV48AKNIALQRLJEqfgt6yC zr05V7KGHXiEC9jvaxrul19ZrbeBwyE2z3tf+A+ikQpTiCVWyyk8VWgpyL8Ziay8PYQc vgcbkc1IkEMqF3PVo5EGkO9aB38oeiVGP8UiKa5efM3/uh2RCQhWaR9+Rigj6PwJ0grN ss9A== X-Gm-Message-State: ALoCoQn8Cv9TemynWaZgbz1XdyILH6e2nIjunPGuTXQtZaDDNcZU/3mlEKzk1xphoHQrH3iXkya3 X-Received: by 10.58.7.134 with SMTP id j6mr11206312vea.29.1395427488734; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.136 with SMTP id 8ls793900qgh.43.gmail; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) X-Received: by 10.221.34.7 with SMTP id sq7mr6074834vcb.5.1395427488569; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id cb3si1356146vdc.23.2014.03.21.11.44.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Mar 2014 11:44:48 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so3075195veb.0 for ; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr17778642veb.21.1395427488440; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.78.9 with SMTP id i9csp51672vck; Fri, 21 Mar 2014 11:44:48 -0700 (PDT) X-Received: by 10.180.182.199 with SMTP id eg7mr4444437wic.13.1395427487416; Fri, 21 Mar 2014 11:44:47 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id cb8si2072521wib.78.2014.03.21.11.44.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 21 Mar 2014 11:44:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WR4Qm-0006eV-Ml; Fri, 21 Mar 2014 18:44:36 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Michael Matz , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Peter Crosthwaite Subject: [PATCH] target-arm: Load ELF images with the correct machine type for CPU Date: Fri, 21 Mar 2014 18:44:36 +0000 Message-Id: <1395427476-25546-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , When trying to load an ELF file specified via -kernel, we need to pass load_elf() the ELF machine type corresponding to the CPU we're booting with, not the one corresponding to the softmmu binary we happen to be running. (The two are different in the case of loading a 32-bit ARM ELF file into a 32 bit CPU being emulated by qemu-system aarch64.) This was causing us to incorrectly fail to load ELF images in this situation. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber Reviewed-by: Peter Crosthwaite --- This isn't really a big deal since we can just say "use the qemu-system-arm binary instead". However maybe we should put this into 2.0. Opinions? Incidentally I suspect hw/i386/multiboot.c has a similar problem where it calls load_elf() passing ELF_MACHINE. --- hw/arm/boot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index dc62918..3d1f4a2 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -448,6 +448,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) int initrd_size; int is_linux = 0; uint64_t elf_entry; + int elf_machine; hwaddr entry, kernel_load_offset; int big_endian; static const ARMInsnFixup *primary_loader; @@ -463,9 +464,11 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { primary_loader = bootloader_aarch64; kernel_load_offset = KERNEL64_LOAD_ADDR; + elf_machine = EM_AARCH64; } else { primary_loader = bootloader; kernel_load_offset = KERNEL_LOAD_ADDR; + elf_machine = EM_ARM; } info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb"); @@ -501,7 +504,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) /* Assume that raw images are linux kernels, and ELF images are not. */ kernel_size = load_elf(info->kernel_filename, NULL, NULL, &elf_entry, - NULL, NULL, big_endian, ELF_MACHINE, 1); + NULL, NULL, big_endian, elf_machine, 1); entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(info->kernel_filename, &entry, NULL,