public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Edgar E. Iglesias <edgar.iglesias@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 2/4] arm64: Trap PIE builds early if load address is not 4K aligned
Date: Wed,  9 Sep 2020 19:07:25 +0200	[thread overview]
Message-ID: <20200909170727.658573-3-edgar.iglesias@gmail.com> (raw)
In-Reply-To: <20200909170727.658573-1-edgar.iglesias@gmail.com>

From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

PIE requires a 4K aligned load address. If this is not met, trap
the startup sequence in a WFI loop rather than running into obscure
failures.

Tested-by: Michal Simek <michal.simek@xilinx.com>
Suggested-by: Andr? Przywara <andre.przywara@arm.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 arch/arm/cpu/armv8/start.S | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 002698b501..85baebc5f7 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -59,6 +59,23 @@ reset:
 save_boot_params_ret:
 
 #if CONFIG_POSITION_INDEPENDENT
+	/* Verify that we're 4K aligned.  */
+	adr	x0, _start
+	ands	x0, x0, #0xfff
+	b.eq	1f
+0:
+	/*
+	 * FATAL, can't continue.
+	 * U-Boot needs to be loaded at a 4K aligned address.
+	 *
+	 * We use ADRP and ADD to load some symbol addresses during startup.
+	 * The ADD uses an absolute (non pc-relative) lo12 relocation
+	 * thus requiring 4K alignment.
+	 */
+	wfi
+	b	0b
+1:
+
 	/*
 	 * Fix .rela.dyn relocations. This allows U-Boot to be loaded to and
 	 * executed at a different address than it was linked at.
-- 
2.25.1

  parent reply	other threads:[~2020-09-09 17:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 17:07 [PATCH v3 0/4] arm64: Large PIE fixes Edgar E. Iglesias
2020-09-09 17:07 ` [PATCH v3 1/4] arm64: Mention 4K aligned load addresses in the PIE Kconfig help Edgar E. Iglesias
2020-09-09 17:07 ` Edgar E. Iglesias [this message]
2020-09-09 17:07 ` [PATCH v3 3/4] arm64: Add support for larger PIE U-Boot Edgar E. Iglesias
2020-09-10 11:37   ` Michal Simek
2020-09-09 17:07 ` [PATCH v3 4/4] arm64: Trap non-PIE builds early if starting from wrong address Edgar E. Iglesias
2020-09-10 12:38   ` Michal Simek
2020-09-10 13:06     ` André Przywara
2020-09-10 13:38       ` Michal Simek
2020-09-10 13:50         ` Tom Rini
2020-09-10 15:02           ` Michal Simek
2020-09-11  8:21             ` Edgar E. Iglesias
2020-09-09 19:16 ` [PATCH v3 0/4] arm64: Large PIE fixes Stephen Warren
2020-09-14  9:55 ` Michal Simek

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=20200909170727.658573-3-edgar.iglesias@gmail.com \
    --to=edgar.iglesias@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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