]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm64: Trap PIE builds early if load address is not 4K aligned
authorEdgar E. Iglesias <edgar.iglesias@xilinx.com>
Wed, 9 Sep 2020 17:07:25 +0000 (19:07 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Tue, 22 Sep 2020 10:47:28 +0000 (12:47 +0200)
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>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
arch/arm/cpu/armv8/start.S

index 002698b501c3002026941bbc812bc0123043132b..85baebc5f78ea8438d125e3b5f45dba321f11a3c 100644 (file)
@@ -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.