From patchwork Mon Jul 14 16:17:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33611 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C42B20CAD for ; Mon, 14 Jul 2014 16:20:04 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id m20sf3168408qcx.7 for ; Mon, 14 Jul 2014 09:20:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=4FkqLtJCz11eK9FMYvcyJSLhTORRQYYNIbp/Oc3nM1Y=; b=EC5ju28scOqu/k44PACDniEdFHtPiGkj9Hjz166P3qNdv7/+JEKRDtUXSgp6bKDcK/ 2yejGWwB7QQ23Ax5HWh8EBDnz5EsgBq2LHW68RAQNsi6y2Kk1da6MXdjt/67FIHBeJJl iV8NJv7JZRDXbvekU6WMiFQAIei6hgn7SE9PHI+aGvGU7wRPNAK8pja0zTqwn5sFw2Sv 06P3ajTnaqOcMmNhNFv3mOIL2p7i2T2qWMMHLhHeDlb6S2pUP9LzpdTAthCiehOnOw3+ M2Orcvz25OyDf647Vq6/UvOl6+jlhfd2SQdfiZYC+BTpHbfywzUgdQnaeb/y4x2hlx/n 1RXQ== X-Gm-Message-State: ALoCoQljZf0HmGCTdiVATTmwFEWbC6PfzLtLrNkriH/tUPB4G7nc3ZZt9nEHle6t5M5ekoiTbukh X-Received: by 10.236.62.165 with SMTP id y25mr7290413yhc.26.1405354804254; Mon, 14 Jul 2014 09:20:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.22.198 with SMTP id 64ls1074856qgn.8.gmail; Mon, 14 Jul 2014 09:20:04 -0700 (PDT) X-Received: by 10.58.40.75 with SMTP id v11mr343693vek.77.1405354804177; Mon, 14 Jul 2014 09:20:04 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id h4si5510217vdi.70.2014.07.14.09.20.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 09:20:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id id10so7559665vcb.24 for ; Mon, 14 Jul 2014 09:20:04 -0700 (PDT) X-Received: by 10.58.207.84 with SMTP id lu20mr16639362vec.9.1405354804094; Mon, 14 Jul 2014 09:20:04 -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.221.37.5 with SMTP id tc5csp147212vcb; Mon, 14 Jul 2014 09:20:03 -0700 (PDT) X-Received: by 10.68.178.37 with SMTP id cv5mr4063185pbc.115.1405354802328; Mon, 14 Jul 2014 09:20:02 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ko7si4747656pdb.476.2014.07.14.09.20.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jul 2014 09:20:02 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X6ixo-0004se-M5; Mon, 14 Jul 2014 16:18:52 +0000 Received: from mail-wg0-f41.google.com ([74.125.82.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X6ixf-0004jG-S5 for linux-arm-kernel@lists.infradead.org; Mon, 14 Jul 2014 16:18:44 +0000 Received: by mail-wg0-f41.google.com with SMTP id z12so4400172wgg.24 for ; Mon, 14 Jul 2014 09:18:20 -0700 (PDT) X-Received: by 10.180.208.35 with SMTP id mb3mr25972533wic.48.1405354700686; Mon, 14 Jul 2014 09:18:20 -0700 (PDT) Received: from ards-macbook-pro.local ([109.227.8.83]) by mx.google.com with ESMTPSA id ut2sm19022807wjc.49.2014.07.14.09.18.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 09:18:19 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, geoff@infradead.org, mark.rutland@arm.com Subject: [PATCH 1/2] arm64: add C struct definition for Image header Date: Mon, 14 Jul 2014 18:17:50 +0200 Message-Id: <1405354671-14031-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405354671-14031-1-git-send-email-ard.biesheuvel@linaro.org> References: <1405354671-14031-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140714_091844_077541_A8572C3C X-CRM114-Status: GOOD ( 16.25 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.41 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.41 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , catalin.marinas@arm.com, leif.lindholm@linaro.org, roy.franz@linaro.org, msalter@redhat.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 In order to be able to interpret the Image header from C code, we need a struct definition that reflects the specification for Image headers as laid out in Documentation/arm64/booting.txt. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/image_hdr.h | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 arch/arm64/include/asm/image_hdr.h diff --git a/arch/arm64/include/asm/image_hdr.h b/arch/arm64/include/asm/image_hdr.h new file mode 100644 index 000000000000..9dc74b672124 --- /dev/null +++ b/arch/arm64/include/asm/image_hdr.h @@ -0,0 +1,75 @@ +/* + * image_hdr.h - C struct definition of the arm64 Image header format + * + * Copyright (C) 2014 Linaro Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __ASM_IMAGE_HDR_H +#define __ASM_IMAGE_HDR_H + +#ifdef __KERNEL__ +#include +#else +#include +#endif + +/** + * struct arm64_image_hdr - arm64 kernel Image binary header format + * @code0: entry point, first instruction to jump to when booting + * the Image + * @code1: second instruction of entry point + * @text_offset: mandatory offset (little endian) beyond a 2 megabyte + * aligned boundary that needs to be taken into account + * when deciding where to load the image + * @image_size: total size (little endian) of the memory area (counted + * from the offset where the image was loaded) that may be + * used by the booting kernel before memory reservations + * can be honoured + * @flags: little endian bit field + * Bit 0: Kernel endianness. 1 if BE, 0 if LE. + * Bits 1-63: Reserved. + * @res2: reserved, must be 0 + * @res3: reserved, must be 0 + * @res4: reserved, must be 0 + * @magic: Magic number (little endian): "ARM\x64" + * @res5: reserved (used for PE COFF offset) + * + * This definition reflects the definition in Documentation/arm64/booting.txt in + * the Linux source tree. + */ +struct arm64_image_hdr { + uint32_t code0; + uint32_t code1; + uint64_t text_offset; + uint64_t image_size; + uint64_t flags; + uint64_t res2; + uint64_t res3; + uint64_t res4; + uint32_t magic; + uint32_t res5; +}; + +static const union { + uint8_t le_val[4]; + uint32_t cpu_val; +} arm64_image_hdr_magic = { + .le_val = "ARM\x64" +}; + +/** + * int arm64_image_hdr_check() - check whether hdr points to an arm64 Image + * @hdr: pointer to an arm64 Image + * + * Return: 1 if check is successful, 0 otherwise + */ +static inline int arm64_image_hdr_check(struct arm64_image_hdr const *hdr) +{ + return hdr->magic == arm64_image_hdr_magic.cpu_val; +} + +#endif