From: Marek Vasut <marek.vasut@mailbox.org>
To: Simon Glass <sjg@chromium.org>,
Marek Vasut <marek.vasut+renesas@mailbox.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
Quentin Schulz <quentin.schulz@cherry.de>,
Tom Rini <trini@konsulko.com>,
Wolfgang Wallner <wolfgang.wallner@br-automation.com>
Subject: Re: [PATCH] boot: Assure FDT is always at 8-byte aligned address
Date: Thu, 13 Nov 2025 22:56:22 +0100 [thread overview]
Message-ID: <81115588-50c7-4ecc-975e-13994101955f@mailbox.org> (raw)
In-Reply-To: <CAFLszTg0ByjUGgX4MSbU=i0oG7fuidM4J0J128ER6Aq+r6HW9A@mail.gmail.com>
On 11/13/25 8:33 PM, Simon Glass wrote:
Hello Simon,
>> 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>
>> ---
>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> Cc: Quentin Schulz <quentin.schulz@cherry.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
>> Cc: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
>> Cc: u-boot@lists.denx.de
>> ---
>> boot/image-fit.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/boot/image-fit.c b/boot/image-fit.c
>> index 2f2d3e9304d..cccaa48f683 100644
>> --- a/boot/image-fit.c
>> +++ b/boot/image-fit.c
>> @@ -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);
>> --
>> 2.51.0
>>
>
> We really can't do a memory allocation in fit_image_load() !
We already do, notice the malloc() when "decompressing image" part.
> The problem should be fixed higher up, in its callers, etc. For one
> thing, the caller knows whether it is a DT or not, so putting this
> logic here is messy. See boot_get_fdt_fit()
This is triggered by a fitImage with DT embedded in that fitImage as
non-external-data. That DT is at 4-byte aligned address, so how can the
caller deal with it ? The caller gets a fitImage, which itself is at
8-byte aligned address, but the DT in it is not at 8-byte aligned
address, so that DT has to be relocated somehow and that happens here.
next prev parent reply other threads:[~2025-11-13 21:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 11:54 [PATCH] boot: Assure FDT is always at 8-byte aligned address Marek Vasut
2025-11-13 19:33 ` Simon Glass
2025-11-13 21:56 ` Marek Vasut [this message]
2025-11-13 22:46 ` Simon Glass
2025-11-15 17:19 ` Marek Vasut
2025-11-17 17:04 ` Simon Glass
2025-11-17 17:10 ` Marek Vasut
2025-11-18 3:47 ` Simon Glass
2025-11-19 21:29 ` Marek Vasut
2025-11-20 2:07 ` Simon Glass
2025-11-28 17:41 ` Tom Rini
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=81115588-50c7-4ecc-975e-13994101955f@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=quentin.schulz@cherry.de \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=wolfgang.wallner@br-automation.com \
--cc=xypron.glpk@gmx.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