linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] arm64: add C struct definition for Image header
Date: Mon, 14 Jul 2014 18:17:50 +0200	[thread overview]
Message-ID: <1405354671-14031-2-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1405354671-14031-1-git-send-email-ard.biesheuvel@linaro.org>

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 <ard.biesheuvel@linaro.org>
---
 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 <linux/types.h>
+#else
+#include <stdint.h>
+#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
-- 
1.8.3.2

  reply	other threads:[~2014-07-14 16:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-14 16:17 [PATCH 0/2] arm64: use Image header fields in EFI stub Ard Biesheuvel
2014-07-14 16:17 ` Ard Biesheuvel [this message]
2014-07-14 16:58   ` [PATCH 1/2] arm64: add C struct definition for Image header Mark Rutland
2014-07-14 17:21     ` Ard Biesheuvel
2014-07-14 16:17 ` [PATCH 2/2] arm64/efi: efistub: get text offset and image size from the " Ard Biesheuvel
2014-07-14 16:54   ` Mark Rutland
2014-07-14 17:35     ` Ard Biesheuvel
2014-07-14 18:29       ` Mark Rutland
2014-07-15  9:02         ` Ard Biesheuvel
2014-07-15  9:47           ` Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405354671-14031-2-git-send-email-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).