From patchwork Tue Jul 8 12:50:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33202 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 24AF020969 for ; Tue, 8 Jul 2014 12:52:00 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf34934821oac.7 for ; Tue, 08 Jul 2014 05:51:59 -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=kKcNuamWno8iF5uFBvCiJtpSADKJpXp0pwOnQXXkFho=; b=gW0pCNLbht14RwWS1NaR04k32Qduc5SJclMjZtrZzf6GkfLycfZ/MvBkS7Mu1zH4ij J9O13Ay7UpEfhYV6rJxJEcDMhrPDxObvrTht22zjRya7P5B+IxabRjuLFXUGhXbkJdj2 Jz3ZcsOozWoJQs5VudrK+JtQz3FGlXtEFMRY2r2DwZdlwz6I37PsvyLGZ1eWvzjktGQc EXFOuTQJrJsol5zuTJ4bd4ic78lgFw9G85DqNmXLCvyJFMA0nkdod+BcEvgLuzy+OIkt HvISSNkEp9Tw1MdwVQCwBuJ9gO+3ePJqVQTLsBdA1/4w6Ggca60Ftt4evoVYdldMCOoh 1SlQ== X-Gm-Message-State: ALoCoQkCyvV1fO5NFz1+zR50YOzeAFUgV4J+r+mSyJxGgVmYyLZGkFDCHR6R1Mdhd6Sa6qgju4xf X-Received: by 10.50.41.3 with SMTP id b3mr2367653igl.0.1404823919625; Tue, 08 Jul 2014 05:51:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.201 with SMTP id k67ls2237453qge.22.gmail; Tue, 08 Jul 2014 05:51:59 -0700 (PDT) X-Received: by 10.58.210.97 with SMTP id mt1mr183668vec.42.1404823919508; Tue, 08 Jul 2014 05:51:59 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id vs2si20087186vcb.69.2014.07.08.05.51.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 05:51:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id sa20so5510039veb.24 for ; Tue, 08 Jul 2014 05:51:59 -0700 (PDT) X-Received: by 10.220.183.4 with SMTP id ce4mr158848vcb.54.1404823919435; Tue, 08 Jul 2014 05:51:59 -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 tc5csp767609vcb; Tue, 8 Jul 2014 05:51:59 -0700 (PDT) X-Received: by 10.68.190.231 with SMTP id gt7mr1756537pbc.148.1404823918635; Tue, 08 Jul 2014 05:51:58 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id po2si2608105pdb.71.2014.07.08.05.51.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jul 2014 05:51:58 -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 1X4UrC-000179-OO; Tue, 08 Jul 2014 12:50:50 +0000 Received: from mail-wi0-f172.google.com ([209.85.212.172]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X4Ur5-0000ql-Vu for linux-arm-kernel@lists.infradead.org; Tue, 08 Jul 2014 12:50:45 +0000 Received: by mail-wi0-f172.google.com with SMTP id hi2so924894wib.5 for ; Tue, 08 Jul 2014 05:50:20 -0700 (PDT) X-Received: by 10.180.126.9 with SMTP id mu9mr3554395wib.69.1404823820606; Tue, 08 Jul 2014 05:50:20 -0700 (PDT) Received: from ards-macbook-pro.local (225-131.dsl.iskon.hr. [89.164.225.131]) by mx.google.com with ESMTPSA id 10sm84508382wjx.26.2014.07.08.05.50.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 05:50:19 -0700 (PDT) From: Ard Biesheuvel To: will.deacon@arm.com, mark.rutland@arm.com Subject: [RFC PATCH 2/3] arm64: add C struct definition for Image header Date: Tue, 8 Jul 2014 14:50:02 +0200 Message-Id: <1404823803-7317-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404823803-7317-1-git-send-email-ard.biesheuvel@linaro.org> References: <1404823803-7317-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140708_055044_207073_D78B9F60 X-CRM114-Status: GOOD ( 13.93 ) 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 [209.85.212.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.172 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: roy.franz@linaro.org, Ard Biesheuvel , leif.lindholm@linaro.org, linux-arm-kernel@lists.infradead.org, msalter@redhat.com 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.128.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 | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 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..16d32600fb18 --- /dev/null +++ b/arch/arm64/include/asm/image_hdr.h @@ -0,0 +1,53 @@ +/* + * image_hdr.h - C struct definition of the 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 + +#include +#include +#include + +/* + * As defined in Documentation/arm64/booting.txt + */ +#define IMAGE_HDR_SIZE 64 + +struct image_hdr { + u32 code0; /* Executable code */ + u32 code1; /* Executable code */ + __le64 text_offset; /* Image load offset */ + u64 res0; /* Reserved, must be 0 */ + u64 res1; /* Reserved, must be 0 */ + u64 res2; /* Reserved, must be 0 */ + u64 res3; /* Reserved, must be 0 */ + u64 res4; /* Reserved, must be 0 */ + __le32 magic; /* Magic number, little endian, "ARM\x64" */ + __le32 pehdr_offset; /* PE header offset, only used by EFI */ +}; + +/* + * bool image_hdr_check() - checks the Image header for inconsistencies. + */ +static inline bool image_hdr_check(struct image_hdr const *hdr) +{ + BUILD_BUG_ON(sizeof(struct image_hdr) != IMAGE_HDR_SIZE); + + if (hdr->res0 | hdr->res1 | hdr->res2 | hdr->res3 | hdr->res4) + return false; + return hdr->magic == cpu_to_le32(0x644d5241); +} + +static inline u64 image_hdr_text_offset(struct image_hdr const *hdr) +{ + return le64_to_cpu(hdr->text_offset); +} + +#endif