From patchwork Wed May 14 19:30:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 30192 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CC8882055D for ; Wed, 14 May 2014 19:31:42 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wo20sf114405obc.3 for ; Wed, 14 May 2014 12:31:41 -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:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=it1cqJGevc2s9kvdJUDWLwWOgdsc3U5imYXwx80EOqQ=; b=cqRS2btUrHo1i4vhRux+LEVtP4iLjpVb9U4pRvbHZoCB5xYFxo2bA7Xyj+zbfM/BRc idTRCiJkDfujh7lmTsdjscPKX4lpl/a6BtGY/2bFhYAGi8SP78X7nlcWlhSy7ImXBHji dbz2qMAd10DYlPsiwsrZXVbhQmgcuIIwvnSqFCZvYZGYXiPDIv40YKFmdKwpRbp4w+AD 5PZmiPY+NuC6HViEHwcjTvFjEOPFlkwTleXtcyqqyX3V+PM4kQpO2QIi2ATSRknD53wZ K/ZOnkmeIl4i5YWVEPQ8SE3Q8VYDFAJNgCkJkkNAhkvJDimDEq7PIdvGIXaloFdNgqzd K+xw== X-Gm-Message-State: ALoCoQnM+2NkO1vq2Lf8iLvP2udMTHpsRZw1Ab0AR2Pmkan8+DqxSohhnvZlqpA4RF2djKsR/mxm X-Received: by 10.42.83.17 with SMTP id f17mr232635icl.17.1400095901324; Wed, 14 May 2014 12:31:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.201 with SMTP id e67ls2587315qgf.94.gmail; Wed, 14 May 2014 12:31:41 -0700 (PDT) X-Received: by 10.220.160.67 with SMTP id m3mr1099434vcx.56.1400095901202; Wed, 14 May 2014 12:31:41 -0700 (PDT) Received: from mail-ve0-x230.google.com (mail-ve0-x230.google.com [2607:f8b0:400c:c01::230]) by mx.google.com with ESMTPS id rl1si488170vcb.182.2014.05.14.12.31.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 12:31:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::230 as permitted sender) client-ip=2607:f8b0:400c:c01::230; Received: by mail-ve0-f176.google.com with SMTP id jz11so27699veb.21 for ; Wed, 14 May 2014 12:31:41 -0700 (PDT) X-Received: by 10.52.136.98 with SMTP id pz2mr67062vdb.70.1400095901121; Wed, 14 May 2014 12:31:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp265928vcb; Wed, 14 May 2014 12:31:40 -0700 (PDT) X-Received: by 10.224.40.76 with SMTP id j12mr6636832qae.90.1400095900677; Wed, 14 May 2014 12:31:40 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a7si1340918qat.138.2014.05.14.12.31.40 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 14 May 2014 12:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:53948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wketw-0000Ca-7e for patch@linaro.org; Wed, 14 May 2014 15:31:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WketD-0008Ga-0s for qemu-devel@nongnu.org; Wed, 14 May 2014 15:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wket7-00018R-He for qemu-devel@nongnu.org; Wed, 14 May 2014 15:30:54 -0400 Received: from mail-oa0-x232.google.com ([2607:f8b0:4003:c02::232]:49728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wket7-00018M-CP for qemu-devel@nongnu.org; Wed, 14 May 2014 15:30:49 -0400 Received: by mail-oa0-f50.google.com with SMTP id i7so27783oag.9 for ; Wed, 14 May 2014 12:30:48 -0700 (PDT) X-Received: by 10.60.231.134 with SMTP id tg6mr4305888oec.84.1400095848541; Wed, 14 May 2014 12:30:48 -0700 (PDT) Received: from localhost.localdomain (72-48-77-163.dyn.grandenetworks.net. [72.48.77.163]) by mx.google.com with ESMTPSA id ld8sm4827107obb.9.2014.05.14.12.30.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 May 2014 12:30:48 -0700 (PDT) From: Rob Herring To: Peter Maydell , qemu-devel@nongnu.org Date: Wed, 14 May 2014 14:30:37 -0500 Message-Id: <1400095837-26128-1-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::232 Cc: Rob Herring Subject: [Qemu-devel] [PATCH] hw/arm/boot: get AArch64 kernel Image load offset from Image file 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Original-Sender: robherring2@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::230 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=fail header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Rob Herring The AArch64 kermel Image format defines the load offset in its header. Retrieve the offset from the file instead of hardcoding it to 0x80000. Use of the hardcoded value will break when text_offset randomization is added to the kernel. Signed-off-by: Rob Herring --- hw/arm/boot.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 3d1f4a2..4adce9e 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -24,7 +24,14 @@ */ #define KERNEL_ARGS_ADDR 0x100 #define KERNEL_LOAD_ADDR 0x00010000 -#define KERNEL64_LOAD_ADDR 0x00080000 + +typedef struct { + uint32_t code[2]; + uint64_t text_offset; + uint64_t res[5]; + uint32_t magic; + uint32_t res5; +} aarch64_image_header_t; typedef enum { FIXUP_NONE = 0, /* do nothing */ @@ -441,6 +448,26 @@ static void do_cpu_reset(void *opaque) } } +static hwaddr aarch64_get_image_offset(const char *filename) +{ + int fd, size; + aarch64_image_header_t hdr; + + fd = open(filename, O_RDONLY | O_BINARY); + if (fd < 0) { + return 0; + } + + size = read(fd, &hdr, sizeof(hdr)); + close(fd); + + if (size < sizeof(aarch64_image_header_t) || + le32_to_cpu(hdr.magic) != 0x644d5241) { + return 0; + } + return le32_to_cpu(hdr.text_offset); +} + void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) { CPUState *cs = CPU(cpu); @@ -463,7 +490,7 @@ 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; + kernel_load_offset = aarch64_get_image_offset(info->kernel_filename); elf_machine = EM_AARCH64; } else { primary_loader = bootloader; @@ -505,6 +532,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); + entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(info->kernel_filename, &entry, NULL,