[PATCHv2] boot/image-fit.c: Resort to using malloc for USE_HOSTCC
Tom Rini
trini at konsulko.com
Tue Dec 2 17:22:50 CET 2025
With the changes in commit 8fbcc0e0e839 ("boot: Assure FDT is always at
8-byte aligned address") to call memalign(...) we now always call
memalign(...) rather than malloc(...) when allocating a buffer that may
contain a device tree. However, memalign(...) is not portable among all
of the host OSes we support. Specifically on macOS it isn't seemingly
possible to get memalign exactly. To keep alignment we would need to
rework to use posix_memalign(...) for USE_HOSTCC and memalign(...) for
U-Boot itself. This would get rather tricky. However, given the limited
use case in question, it makes more sense to fall back to malloc(...)
for the USE_HOSTCC case.
Fixes: 8fbcc0e0e839 ("boot: Assure FDT is always at 8-byte aligned address")
Signed-off-by: Tom Rini <trini at konsulko.com>
---
Cc: Marek Vasut <marek.vasut+renesas at mailbox.org>
My biggest take-away from this is that I need to move up the plans I had
about asking if anyone even uses the host tools on Windows / macOS from
post-v2026.01 to instead be later today.
This change is a work-around at best. Ideally, we can drop Windows /
macOS host build support and revert this commit at that time.
Changes in v2:
- Rework things entirely, and elaborate on the commit message.
---
boot/image-fit.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/boot/image-fit.c b/boot/image-fit.c
index cccaa48f6839..3323ca1020d1 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -23,6 +23,7 @@
#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
@@ -35,7 +36,6 @@ 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,18 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
log_debug("decompressing image\n");
if (load == data) {
+ /*
+ * This could be a compressed device tree, and device
+ * trees require 8 byte alignment for use. However, in
+ * userspace we aren't using the tree, and getting at
+ * a portable memalign is extremely difficult. Continue
+ * to malloc in the host case.
+ */
+#ifdef USE_HOSTCC
+ loadbuf = malloc(max_decomp_len);
+#else
loadbuf = memalign(8, max_decomp_len);
+#endif
load = map_to_sysmem(loadbuf);
} else {
loadbuf = map_sysmem(load, max_decomp_len);
@@ -2291,11 +2302,13 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
return -ENOEXEC;
}
len = load_end - load;
+#ifndef USE_HOSTCC
} 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);
+#endif
} else if (load != data) {
log_debug("copying\n");
loadbuf = map_sysmem(load, len);
--
2.43.0
More information about the U-Boot
mailing list