]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
arm: Update linker scripts to ensure appended device tree is aligned
authorTom Rini <trini@konsulko.com>
Thu, 15 Jan 2026 22:19:32 +0000 (16:19 -0600)
committerTom Rini <trini@konsulko.com>
Tue, 20 Jan 2026 18:06:41 +0000 (12:06 -0600)
With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version
v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our
device tree is not 8-byte aligned. In commit 85f586035d75 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains
that we must have ALIGN(x) statements inside of a section to ensure that
padding is included and not simply that the linker address counter is
incremented. To that end, this patch:
- Expands some linker sections to be more readable when adding a second
  statement to the section.
- Aligns the final section before _end (for U-Boot) or
  _image_binary_end or __bss_end (for xPL phases) by 8-bytes by adding
  '. = ALIGN(8);' to the final section before the symbol.
- Ensure that we do have alignment by adding an ASSERT so that when not
  aligned we fail to link (and explain why).
- Remove now-spurious  '. = ALIGN(x);' statements that were intended to
  provide the above alignments.

Tested-by: Michal Simek <michal.simek@amd.com> # Zynq
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
[trini: Also update arch/arm/cpu/armv8/u-boot.lds as Ilas requested]
Signed-off-by: Tom Rini <trini@konsulko.com>
17 files changed:
arch/arm/cpu/arm1136/u-boot-spl.lds
arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
arch/arm/cpu/armv8/u-boot-spl.lds
arch/arm/cpu/armv8/u-boot.lds
arch/arm/cpu/u-boot-spl.lds
arch/arm/cpu/u-boot.lds
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds
arch/arm/mach-at91/arm926ejs/u-boot-spl.lds
arch/arm/mach-at91/armv7/u-boot-spl.lds
arch/arm/mach-omap2/u-boot-spl.lds
arch/arm/mach-rockchip/u-boot-tpl-v8.lds
arch/arm/mach-zynq/u-boot-spl.lds
arch/arm/mach-zynq/u-boot.lds
board/davinci/da8xxevm/u-boot-spl-da850evm.lds
board/samsung/common/exynos-uboot-spl.lds

index b7af29183a97c0c012c2107c93dcf0032c535431..22a9302275ae0455794c013f3dce4f8abc9a1118 100644 (file)
@@ -30,8 +30,10 @@ SECTIONS
        .rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
 
        . = ALIGN(4);
-       .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
-       . = ALIGN(4);
+       .data : {
+               *(SORT_BY_ALIGNMENT(.data*))
+               . = ALIGN(8);
+       } >.sram
        __image_copy_end = .;
        _end = .;
 
@@ -44,3 +46,5 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
index 7c6309246f8b68fb46d77ab761e42b4940b9d93b..b4adae272ebaf63759f29c19f00f77754af70777 100644 (file)
@@ -45,7 +45,7 @@ SECTIONS
                . = ALIGN(4);
                __bss_start = .;
                *(.bss*)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        }
 
@@ -62,3 +62,6 @@ SECTIONS
        .gnu : { *(.gnu*) }
        .ARM.exidx : { *(.ARM.exidx*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index cf65e8c46281d57e3c5334b19914d0226f01c382..2225985c79c09b54cf36c0599b23ad01fc0e7150 100644 (file)
@@ -31,9 +31,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -47,3 +47,6 @@ SECTIONS
                __bss_end = .;
        } > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index fb7a789b28b87c3a70adb3e16ac73c4b830989ad..e69291d8be6dcb79647d238601c777b33d7cb90d 100644 (file)
@@ -40,9 +40,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -56,3 +56,6 @@ SECTIONS
                __bss_end = .;
        } > .sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index c4f83ec9cfc470f0cef0fff56e0c2e1a160fb4cc..d9963846c4f46fdfe78196efcf167e842013de91 100644 (file)
@@ -52,9 +52,9 @@ SECTIONS
        __u_boot_list : {
                . = ALIGN(8);
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } >.sram
 
-       . = ALIGN(8);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -89,5 +89,7 @@ SECTIONS
 #endif
 }
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
 ASSERT(ADDR(.bss) % 8 == 0, \
        ".bss must be 8-byte aligned");
index f4ce98c82c8df14f57c0cd56f8a39acfbcb2de37..231ab28b50cd2a19d9df539eb982847bbce31f5f 100644 (file)
@@ -146,6 +146,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rela*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
        _end = .;
@@ -175,3 +176,5 @@ SECTIONS
 #include "linux-kernel-image-header-vars.h"
 #endif
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
index 5aecb61ce902b8398525e21417df96a56d4d0746..d780a50607748309a6ac1b6cc2189bea2481545d 100644 (file)
@@ -51,9 +51,9 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
-       . = ALIGN(8);
        _image_binary_end = .;
        _end = .;
 
@@ -80,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
index 78aad093d3b207ebad65e4bca72d3f2eeb08bd84..8e2266a90fe2859c3df0ac7a8c341aab4f04b011 100644 (file)
@@ -164,6 +164,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
        _end = .;
@@ -192,3 +193,6 @@ SECTIONS
        /DISCARD/ : { *(.ARM.exidx*) }
        /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index 9502a7384b53b4e2260b63d41e70f0dfd0780a9e..c9664a6ce566657671e1a904bcc03611364db372 100644 (file)
@@ -59,6 +59,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        } > .nor
 
        _end = .;
@@ -79,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
index 09cf838cf96e6bafeea97506f4c18a9d692ca24e..1af4f7b6524ca260395a8df7944d38f74996377b 100644 (file)
@@ -29,9 +29,11 @@ SECTIONS
        .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
        . = ALIGN(4);
-       __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)))
+               . = ALIGN(8);
+       } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -51,6 +53,9 @@ ASSERT(__image_copy_end - __start <= (IMAGE_MAX_SIZE), \
        "SPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_SPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
        "SPL image BSS too big");
index 460a91d93ec47ec81e630b1b2cb6853f9dd43fbc..287764df48ff0d3396a3a2ee9056fe0b9bd3c68b 100644 (file)
@@ -36,9 +36,11 @@ SECTIONS
        .data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
 
        . = ALIGN(4);
-       __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)))
+               . = ALIGN(8);
+       } > .sram
 
-       . = ALIGN(4);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -52,3 +54,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index 3bb759d8a1c8d4e2a183f23556d58e7102568656..b61e657900a88a1fa885aae0d648cfce40d6d2c7 100644 (file)
@@ -51,3 +51,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index 958a1b70aefe95b18927743a0c327aa9aa91e905..2c0f5c3e5f326a45d9bb39003e0e9e558a1f185f 100644 (file)
@@ -42,9 +42,9 @@ SECTIONS
        __u_boot_list : {
                . = ALIGN(8);
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        }
 
-       . = ALIGN(8);
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -69,6 +69,9 @@ ASSERT(__image_copy_end - __image_copy_start < (CONFIG_TPL_MAX_SIZE), \
        "TPL image too big");
 #endif
 
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
 #if defined(CONFIG_TPL_BSS_MAX_SIZE)
 ASSERT(__bss_end - __bss_start < (CONFIG_TPL_BSS_MAX_SIZE), \
        "TPL image BSS too big");
index d96a57702886808d9d15c4be5228076929f6b6d4..17f0d7c9b72f0ad6d0e861220f3c1bb06968fd9e 100644 (file)
@@ -39,10 +39,9 @@ SECTIONS
        . = ALIGN(4);
        __u_boot_list : {
                KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
        } > .sram
 
-       . = ALIGN(4);
-
        _image_binary_end = .;
 
        _end = .;
@@ -62,3 +61,6 @@ SECTIONS
        /DISCARD/ : { *(.interp*) }
        /DISCARD/ : { *(.gnu*) }
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index f52523edf49055880e27a2bb233b810905b30718..2a8e3399e0bf35697c88b8584d91bed788a3a549 100644 (file)
@@ -66,6 +66,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        }
 
        _end = .;
@@ -98,3 +99,5 @@ SECTIONS
        /DISCARD/ : { *(.ARM.exidx*) }
        /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");
index 56d6f4f114b9c6ea427c74d8809b0b30891b8104..d1a82e118af1030123e1b9bac519acc8afee5db8 100644 (file)
@@ -43,6 +43,7 @@ SECTIONS
                __rel_dyn_start = .;
                *(.rel*)
                __rel_dyn_end = .;
+               . = ALIGN(8);
        } >.sram
 
        __image_copy_end = .;
@@ -58,3 +59,6 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
index 9d3b57e98dbb71875372fca578b6b9a6b348e152..62e150bcf33566c110d60c62a730f27d83256c84 100644 (file)
@@ -48,7 +48,10 @@ SECTIONS
                . = ALIGN(4);
                __bss_start = .;
                *(.bss*)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        } >.sram
 }
+
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");