mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] ARM64: board-dt-2nd: adopt kernel image header
Date: Mon,  8 Mar 2021 20:32:14 +0100	[thread overview]
Message-ID: <20210308193214.32573-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210308193214.32573-1-a.fatoum@pengutronix.de>

The ARM64 generic DT image is meant to be interchangeable with a
kernel image to aid in debugging and testing. To achieve this, it
reuses an externally passed device tree in x0, just like Linux does.

The ARM barebox image format used however imposes some limitations:

  - Commands verifying the header before boot, like U-Boot's booti
    won't boot the barebox image

  - The barebox image is not fully relocatable. It has the implicit
    assumption that the barebox stack can grow into the memory space
    preceding the barebox image while the /memory node is parsed
    from the FDT.

Adopting the Linux ARM64 header solves both issues. booti won't be
able to tell us apart and we can specify an image load offset to
reserve a stack space that won't interfere with anything else.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/board-dt-2nd-aarch64.S | 31 +++++++++++++--
 arch/arm/cpu/board-dt-2nd.c         |  4 +-
 arch/arm/include/asm/image.h        | 59 +++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/include/asm/image.h

diff --git a/arch/arm/cpu/board-dt-2nd-aarch64.S b/arch/arm/cpu/board-dt-2nd-aarch64.S
index 0540a1690dbe..d32b4066cae2 100644
--- a/arch/arm/cpu/board-dt-2nd-aarch64.S
+++ b/arch/arm/cpu/board-dt-2nd-aarch64.S
@@ -1,11 +1,34 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 #include <linux/linkage.h>
 #include <asm/barebox-arm64.h>
+#include <asm/image.h>
 
-ENTRY_PROC(start_dt_2nd)
-	adr x1, stack
+#define IMAGE_FLAGS \
+	(ARM64_IMAGE_FLAG_PAGE_SIZE_4K << ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT) | \
+	(ARM64_IMAGE_FLAG_PHYS_BASE << ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT)
+
+.section .text_head_entry_start_dt_2nd
+ENTRY("start_dt_2nd")
+1:
+	adr x1, 1b		   /* code0 */
+	b 2f                       /* code1 */
+	.xword 0x80000             /* Image load offset */
+	.xword _barebox_image_size /* Effective Image size */
+	.xword IMAGE_FLAGS	   /* Kernel flags */
+	.xword 0                   /* reserved */
+	.xword 0                   /* reserved */
+	.xword 0                   /* reserved */
+	.ascii ARM64_IMAGE_MAGIC   /* magic number */
+	.int   0                   /* reserved (PE-COFF offset) */
+	.asciz "barebox"	   /* unused for now */
+2:
+	ldr x2, linkadr
+	subs x1, x1, x2		    /* get runtime image load offset */
 	mov sp, x1
+	/* Stack now grows into the 0x80000 image load offset specified
+	 * above. This is more than enough until FDT /memory is decoded.
+	 */
 	b dt_2nd_aarch64
-.word 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-stack:
+linkadr:
+.xword start_dt_2nd
 ENTRY_PROC_END(start_dt_2nd)
diff --git a/arch/arm/cpu/board-dt-2nd.c b/arch/arm/cpu/board-dt-2nd.c
index bb131807859c..6f6f53591844 100644
--- a/arch/arm/cpu/board-dt-2nd.c
+++ b/arch/arm/cpu/board-dt-2nd.c
@@ -29,9 +29,7 @@ void dt_2nd_aarch64(void *fdt);
 
 void dt_2nd_aarch64(void *fdt)
 {
-	unsigned long image_start = (unsigned long)_text + global_variable_offset();
-
-	arm_setup_stack(image_start);
+	/* entry point already set up stack */
 
 	relocate_to_current_adr();
 	setup_c();
diff --git a/arch/arm/include/asm/image.h b/arch/arm/include/asm/image.h
new file mode 100644
index 000000000000..c2b13213c720
--- /dev/null
+++ b/arch/arm/include/asm/image.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_IMAGE_H
+#define __ASM_IMAGE_H
+
+#define ARM64_IMAGE_MAGIC	"ARM\x64"
+
+#define ARM64_IMAGE_FLAG_BE_SHIFT		0
+#define ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT	(ARM64_IMAGE_FLAG_BE_SHIFT + 1)
+#define ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT \
+					(ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT + 2)
+#define ARM64_IMAGE_FLAG_BE_MASK		0x1
+#define ARM64_IMAGE_FLAG_PAGE_SIZE_MASK		0x3
+#define ARM64_IMAGE_FLAG_PHYS_BASE_MASK		0x1
+
+#define ARM64_IMAGE_FLAG_LE			0
+#define ARM64_IMAGE_FLAG_BE			1
+#define ARM64_IMAGE_FLAG_PAGE_SIZE_4K		1
+#define ARM64_IMAGE_FLAG_PAGE_SIZE_16K		2
+#define ARM64_IMAGE_FLAG_PAGE_SIZE_64K		3
+#define ARM64_IMAGE_FLAG_PHYS_BASE		1
+
+#ifndef __ASSEMBLY__
+
+#define arm64_image_flag_field(flags, field) \
+				(((flags) >> field##_SHIFT) & field##_MASK)
+
+/*
+ * struct arm64_image_header - arm64 kernel image header
+ * See Documentation/arm64/booting.rst for details
+ *
+ * @code0:		Executable code, or
+ *   @mz_header		  alternatively used for part of MZ header
+ * @code1:		Executable code
+ * @text_offset:	Image load offset
+ * @image_size:		Effective Image size
+ * @flags:		kernel flags
+ * @reserved:		reserved
+ * @magic:		Magic number
+ * @reserved5:		reserved, or
+ *   @pe_header:	  alternatively used for PE COFF offset
+ */
+
+struct arm64_image_header {
+	__le32 code0;
+	__le32 code1;
+	__le64 text_offset;
+	__le64 image_size;
+	__le64 flags;
+	__le64 res2;
+	__le64 res3;
+	__le64 res4;
+	__le32 magic;
+	__le32 res5;
+};
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __ASM_IMAGE_H */
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-03-08 19:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-08 19:32 [PATCH 1/4] ARM64: qemu-virt64: remove dead CPU identification code Ahmad Fatoum
2021-03-08 19:32 ` [PATCH 2/4] ARM64: qemu-virt64: migrate to generic DT image Ahmad Fatoum
2021-03-09 22:39   ` [PATCH] doc: qemu-virt64: fix reST literal block syntax Roland Hieber
2021-03-08 19:32 ` [PATCH 3/4] ARM64: qemu-virt64: enable Virt IO and other useful options Ahmad Fatoum
2021-03-08 19:32 ` Ahmad Fatoum [this message]
2021-03-11  9:53 ` [PATCH 1/4] ARM64: qemu-virt64: remove dead CPU identification code Sascha Hauer

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=20210308193214.32573-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@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