]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
boot: Assure FDT is always at 8-byte aligned address
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Thu, 13 Nov 2025 11:54:51 +0000 (12:54 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 28 Nov 2025 16:20:17 +0000 (10:20 -0600)
The fitImage may contain FDT at 4-byte aligned address, because alignment
of DT tags is 4 bytes. However, libfdt and also Linux expects DT to be at
8-byte aligned address. Make sure that the DTs embedded in fitImages are
always used from 8-byte aligned addresses. In case the DT is decompressed,
make sure the target buffer is 8-byte aligned. In case the DT is only
loaded, make sure the target buffer is 8-byte aligned too.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
boot/image-fit.c

index 2f2d3e9304d571bdd56500070c4be673c5fd6312..cccaa48f6839415686ec557e31a3a60ac7780127 100644 (file)
@@ -23,7 +23,6 @@
 #include <log.h>
 #include <mapmem.h>
 #include <asm/io.h>
-#include <malloc.h>
 #include <memalign.h>
 #include <asm/global_data.h>
 #ifdef CONFIG_DM_HASH
@@ -36,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #include <bootm.h>
 #include <image.h>
 #include <bootstage.h>
+#include <malloc.h>
 #include <upl.h>
 #include <u-boot/crc.h>
 
@@ -2279,7 +2279,7 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
 
                log_debug("decompressing image\n");
                if (load == data) {
-                       loadbuf = malloc(max_decomp_len);
+                       loadbuf = memalign(8, max_decomp_len);
                        load = map_to_sysmem(loadbuf);
                } else {
                        loadbuf = map_sysmem(load, max_decomp_len);
@@ -2291,6 +2291,11 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
                        return -ENOEXEC;
                }
                len = load_end - load;
+       } else if (load_op != FIT_LOAD_IGNORED && image_type == IH_TYPE_FLATDT &&
+                  ((uintptr_t)buf & 7)) {
+               loadbuf = memalign(8, len);
+               load = map_to_sysmem(loadbuf);
+               memcpy(loadbuf, buf, len);
        } else if (load != data) {
                log_debug("copying\n");
                loadbuf = map_sysmem(load, len);