Skip to contentSkip to conversation

mkimage: Default to 8-byte alignment for DTBs added via -b argument

PATCH In review Beleswar Padhi 5 participants 24 messages Jan 22 – Jan 27

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mkimage: Default to 8-byte alignment for DTBs added via -b argument

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

---
Testing Done:
1. Boot tested on all TI K3 platforms.

v3: Changelog:
1. Default to 8-byte alignment for DTBs in mkimage instead of passing -B 0x8 in build command [Marek]
2. Remove previous R/Bs.

Link to v2:
https://lore.kernel.org/all/[email protected]/

v2: Changelog:
1. Carry R/B, Reported-by, Closes and Fixes tag.

Link to v1:
https://lore.kernel.org/all/[email protected]/

 tools/mkimage.c | 2 ++
 1 file changed, 2 insertions(+)
tools/mkimage.c +2 -0
index 3c43962807d..9ccda2e18e2 100644
@@ -240,6 +240,8 @@ static void process_args(int argc, char **argv)
 					params.cmdname, optarg);
 				exit(EXIT_FAILURE);
 			}
+			/* Default to 8-byte alignment for DTBs as per spec */
+			params.bl_len = 0x8;
 			break;
 		case 'B':
 			params.bl_len = strtoull(optarg, &ptr, 16);
Signature · 1 line
2.34.1
Tested-by on v3 1/1
#1 lore raw
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Signature · 1 line
Tom
#2 lore raw
Quoted 17 lines · Tom Rini
Quoted 15 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Quoted 6 lines
Quoted 4 lines
Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

#3 lore raw
Quoted 23 lines · Marek Vasut
Quoted 22 lines · Tom Rini
Quoted 19 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 4 lines
Quoted 1 line

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else. We would get the same result when using mkimage -f auto -b ...dtb... -B 0x8 I think we should be fine with this limitation for the usecases when generating fitImage with mixed images. Unless you have some idea?

Thanks,
Beleswar

#4 lore raw
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params *params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +7 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
        for (node = fdt_first_subnode(fdt, images);
             node >= 0;
             node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                int len;
 
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                if (!data)
                        continue;

"

Quoted 4 lines

We
would get the same result when using mkimage -f auto -b ...dtb... -B 0x8 I think we should be fine with this limitation for the usecases when generating fitImage with mixed images. Unless you have some idea?

What about the above ?

#5 lore raw

Hi Marek,

Quoted 69 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params 
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +7 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct 
 image_tool_params *params, const char *fname)
         for (node = fdt_first_subnode(fdt, images);
              node >= 0;
              node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                 int len;
 
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                 data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                 if (!data)
                         continue;
Quoted 2 lines

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

Regards,
Anshul

Quoted 5 lines
Quoted 4 lines

We
would get the same result when using mkimage -f auto -b ...dtb... -B 0x8 I think we should be fine with this limitation for the usecases when generating fitImage with mixed images. Unless you have some idea?

What about the above ?

#6 lore raw
Quoted 63 lines · Anshul Dalal

Hi Marek,

Quoted 60 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
          for (node = fdt_first_subnode(fdt, images);
               node >= 0;
               node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                  int len;
 
Quoted 14 lines
Quoted 11 lines
tools/fit_image.c +6 -0
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                  data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                  if (!data)
                          continue;

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

#7 lore raw
Quoted 78 lines · Marek Vasut
Quoted 63 lines · Anshul Dalal

Hi Marek,

Quoted 60 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
          for (node = fdt_first_subnode(fdt, images);
               node >= 0;
               node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                  int len;
 
Quoted 14 lines
Quoted 11 lines
tools/fit_image.c +6 -0
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                  data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                  if (!data)
                          continue;

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

Quoted 3 lines

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

Probably fine to keep going as-is. If there's security challenges here this isn't the first one I bet.

Signature · 1 line
Tom
#8 lore raw
Quoted 28 lines · Tom Rini
Quoted 28 lines
Quoted 28 lines
Quoted 23 lines

"

tools/fit_image.c +7 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
           for (node = fdt_first_subnode(fdt, images);
                node >= 0;
                node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                   int len;
 
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                   data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                   if (!data)
                           continue;
Quoted 2 lines

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

Quoted 6 lines
Quoted 3 lines

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

Probably fine to keep going as-is. If there's security challenges here this isn't the first one I bet.

This is unacceptable.

Adding strncmp() is trivial.

#9 lore raw
In reply to Marek Vasut
Quoted 78 lines · Marek Vasut
Quoted 63 lines · Anshul Dalal

Hi Marek,

Quoted 60 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
          for (node = fdt_first_subnode(fdt, images);
               node >= 0;
               node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                  int len;
 
Quoted 14 lines
Quoted 11 lines
tools/fit_image.c +6 -0
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                  data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                  if (!data)
                          continue;

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

Quoted 3 lines

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

strcmp is fine when one of the strings is a constant

If type is shorter than "flat_dt" then there is no risk of overflow.

If type is longer than "flat_dt" then strcmp will return early when it hits the nul-terminator of "flat_dt".

strncmp is unnecessarily verbose and creates an opportunity for misuse if the wrong length is supplied. Whereas strcmp with a constant is impossible to get wrong.

--Sean

[Embedded World 2026, SECO SpA]<https://www.messe-ticket.de/Nuernberg_SHOP/embeddedworld2026/Landing?code=ew26561753&returnUrl=%2FNuernberg_SHOP%2Fembeddedworld2026%2FProfile>

#10 lore raw
Quoted 79 lines · Sean Anderson
Quoted 78 lines · Marek Vasut
Quoted 77 lines · Anshul Dalal

Hi Marek,

Quoted 69 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +7 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
           for (node = fdt_first_subnode(fdt, images);
                node >= 0;
                node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                   int len;
 
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                   data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                   if (!data)
                           continue;
Quoted 2 lines

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

Quoted 7 lines
Quoted 3 lines

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

strcmp is fine when one of the strings is a constant

If type is shorter than "flat_dt" then there is no risk of overflow.

What exact data would you be comparing here , the constant and something read from possibly past the user supplied "type" buffer ?

Some validation of "len" has to be done before it is fed into strcmp() here.

#11 lore raw
Quoted 84 lines · Marek Vasut
Quoted 83 lines · Sean Anderson
Quoted 81 lines · Marek Vasut
Quoted 63 lines · Anshul Dalal

Hi Marek,

Quoted 60 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
           for (node = fdt_first_subnode(fdt, images);
                node >= 0;
                node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                   int len;
 
Quoted 14 lines
Quoted 11 lines
tools/fit_image.c +6 -0
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                   data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                   if (!data)
                           continue;

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

Quoted 7 lines
Quoted 3 lines

strcmp is fine when one of the strings is a constant

If type is shorter than "flat_dt" then there is no risk of overflow.

What exact data would you be comparing here , the constant and something read from possibly past the user supplied "type" buffer ?

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

--Sean

[Embedded World 2026, SECO SpA]<https://www.messe-ticket.de/Nuernberg_SHOP/embeddedworld2026/Landing?code=ew26561753&returnUrl=%2FNuernberg_SHOP%2Fembeddedworld2026%2FProfile>

#12 lore raw
Quoted 96 lines · Sean Anderson
Quoted 84 lines · Marek Vasut
Quoted 83 lines · Sean Anderson
Quoted 81 lines · Marek Vasut
Quoted 63 lines · Anshul Dalal

Hi Marek,

Quoted 60 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params
*params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct
 image_tool_params *params, const char *fname)
           for (node = fdt_first_subnode(fdt, images);
                node >= 0;
                node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                   int len;
 
Quoted 14 lines
Quoted 11 lines
tools/fit_image.c +6 -0
+               if (align_size < 8) {
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                   data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                   if (!data)
                           continue;

"

I just ran a quick test with this diff and it seems to fix the issue for us. If it's okay can we take the change as is.

I think the strcmp needs to be some strncmp and check the 'len' too.

Let's see what others think.

Quoted 7 lines
Quoted 3 lines

strcmp is fine when one of the strings is a constant

If type is shorter than "flat_dt" then there is no risk of overflow.

What exact data would you be comparing here , the constant and something read from possibly past the user supplied "type" buffer ?

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

Quoted 6 lines

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

And gets back to my original point. Either we're fine here, because libfdt is doing enough input validation (type and len come from fdt_getprop(...)) and if that passes enough validation to happen but also allow malicious input this is not the most interesting place to wreck havoc. Or we're fine, actually. Which is what I was saying on IRC.

Signature · 1 line
Tom
#13 lore raw
Quoted 4 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

Which is wrong, and trivial to fix -- check the "len" that is already provided to you by fdt_getprop() and make sure it is exactly length of FIT_TYPE_PROP before doing the strcmp() . Then you should be safe.

Quoted 2 lines
Quoted 2 lines

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

This I did not consider. So maybe what needs to be done is compare the length and then memcmp() instead of strcmp().

Quoted 3 lines
Quoted 3 lines

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

fdt_string_eq_() seems like the best fit, yes , nice.

Quoted 5 lines

And gets back to my original point. Either we're fine here, because libfdt is doing enough input validation (type and len come from fdt_getprop(...)) and if that passes enough validation to happen but also allow malicious input this is not the most interesting place to wreck havoc. Or we're fine, actually. Which is what I was saying on IRC.

We are not fine, fdt_getprop() returns pointer to the string in DT and its length decoded from the DT, it doesn't validate any of it. But what Sean found, fdt_string_eq_(), seems like the right fit/fix here.

#14 lore raw
Quoted 14 lines · Marek Vasut
Quoted 4 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

Which is wrong, and trivial to fix -- check the "len" that is already provided to you by fdt_getprop() and make sure it is exactly length of FIT_TYPE_PROP before doing the strcmp() . Then you should be safe.

Quoted 2 lines
Quoted 2 lines

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

Quoted 8 lines

This I did not consider. So maybe what needs to be done is compare the length and then memcmp() instead of strcmp().

Quoted 3 lines
Quoted 3 lines

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

fdt_string_eq_() seems like the best fit, yes , nice.

Bad news, fdt_string_eq_() is an internal call in libfdt. Good news, fdt_getprop() makes use of it via its eventual call chain. Which I think gets back to what I said earlier, libfdt is doing the input sanitization for us, or so many other places are more useful to exploit?

Signature · 1 line
Tom
#15 lore raw
Quoted 22 lines · Tom Rini
Quoted 21 lines · Marek Vasut
Quoted 4 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

Which is wrong, and trivial to fix -- check the "len" that is already provided to you by fdt_getprop() and make sure it is exactly length of FIT_TYPE_PROP before doing the strcmp() . Then you should be safe.

Quoted 2 lines
Quoted 2 lines

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

This I did not consider. So maybe what needs to be done is compare the length and then memcmp() instead of strcmp().

Quoted 3 lines
Quoted 3 lines

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

Quoted 7 lines
Quoted 1 line

fdt_string_eq_() seems like the best fit, yes , nice.

Bad news, fdt_string_eq_() is an internal call in libfdt. Good news, fdt_getprop() makes use of it via its eventual call chain. Which I think gets back to what I said earlier, libfdt is doing the input sanitization for us, or so many other places are more useful to exploit?

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

--Sean

[Embedded World 2026, SECO SpA]<https://www.messe-ticket.de/Nuernberg_SHOP/embeddedworld2026/Landing?code=ew26561753&returnUrl=%2FNuernberg_SHOP%2Fembeddedworld2026%2FProfile>

#16 lore raw
Quoted 34 lines · Sean Anderson
Quoted 22 lines · Tom Rini
Quoted 21 lines · Marek Vasut
Quoted 4 lines · Tom Rini
Quoted 4 lines
Quoted 1 line

Some validation of "len" has to be done before it is fed into strcmp() here.

Well if you are concerned about lacking a nul-terminator then we will read at most 8 bytes beyond the string.

Which is wrong, and trivial to fix -- check the "len" that is already provided to you by fdt_getprop() and make sure it is exactly length of FIT_TYPE_PROP before doing the strcmp() . Then you should be safe.

Quoted 2 lines
Quoted 2 lines

The other thing that can go wrong is if we get something like "flat_dt\0extra data" we will match.

This I did not consider. So maybe what needs to be done is compare the length and then memcmp() instead of strcmp().

Quoted 3 lines
Quoted 3 lines

Surprisingly the closest we have to this construct is fdt_string_eq_. I suppose this is because most strings in U-Boot are guaranteed to be nul-terminated.

Quoted 7 lines
Quoted 1 line

fdt_string_eq_() seems like the best fit, yes , nice.

Bad news, fdt_string_eq_() is an internal call in libfdt. Good news, fdt_getprop() makes use of it via its eventual call chain. Which I think gets back to what I said earlier, libfdt is doing the input sanitization for us, or so many other places are more useful to exploit?

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

Quoted 8 lines

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

Signature · 1 line
Tom
#17 lore raw
Quoted 21 lines · Tom Rini
Quoted 11 lines

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Quoted 3 lines

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

So back to my and Sean suggestion:

fdt_string_eq_() does effectively memcmp():

return p && (slen == len) && (memcmp(p, s, len) == 0);

So do this and be done with it ?

type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
if (type && len == strlen(FIT_TYPE_PROP) && !memcmp(type, "flat_dt", len))
align_size = 8;

#18 lore raw
Quoted 28 lines · Marek Vasut
Quoted 21 lines · Tom Rini
Quoted 11 lines

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Quoted 3 lines

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

So back to my and Sean suggestion:

Quoted 8 lines

fdt_string_eq_() does effectively memcmp():

return p && (slen == len) && (memcmp(p, s, len) == 0);

So do this and be done with it ?

type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
if (type && len == strlen(FIT_TYPE_PROP) && !memcmp(type, "flat_dt", len))

this is wrong it needs to be

type && len == sizeof("flat_dt") && !memcmp(type, "flat_dt", len)

and it's exactly the sort of error I was complaining about earlier :)

--Sean

Quoted 1 line
  align_size = 8;

[Embedded World 2026, SECO SpA]<https://www.messe-ticket.de/Nuernberg_SHOP/embeddedworld2026/Landing?code=ew26561753&returnUrl=%2FNuernberg_SHOP%2Fembeddedworld2026%2FProfile>

#19 lore raw
Quoted 33 lines · Sean Anderson
Quoted 32 lines · Marek Vasut
Quoted 21 lines · Tom Rini
Quoted 11 lines

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Quoted 3 lines

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

So back to my and Sean suggestion:

fdt_string_eq_() does effectively memcmp():

return p && (slen == len) && (memcmp(p, s, len) == 0);

Quoted 8 lines
Quoted 4 lines

So do this and be done with it ?

type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
if (type && len == strlen(FIT_TYPE_PROP) && !memcmp(type, "flat_dt", len))

this is wrong it needs to be

type && len == sizeof("flat_dt") && !memcmp(type, "flat_dt", len)

... because ... ?

Quoted 1 line

and it's exactly the sort of error I was complaining about earlier :)

#20 lore raw
Quoted 36 lines · Marek Vasut
Quoted 35 lines · Sean Anderson
Quoted 34 lines · Marek Vasut
Quoted 21 lines · Tom Rini
Quoted 11 lines

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Quoted 3 lines

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

So back to my and Sean suggestion:

fdt_string_eq_() does effectively memcmp():

return p && (slen == len) && (memcmp(p, s, len) == 0);

So do this and be done with it ?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
if (type && len == strlen(FIT_TYPE_PROP) && !memcmp(type, "flat_dt", len))

this is wrong it needs to be

type && len == sizeof("flat_dt") && !memcmp(type, "flat_dt", len)

... because ... ?

Because the check you wrote is equivalent to

if (type && sizeof("flat_dt") == strlen("type") && ...)

which will always fail.

--Sean

[Embedded World 2026, SECO SpA]<https://www.messe-ticket.de/Nuernberg_SHOP/embeddedworld2026/Landing?code=ew26561753&returnUrl=%2FNuernberg_SHOP%2Fembeddedworld2026%2FProfile>

#21 lore raw
Quoted 44 lines · Sean Anderson
Quoted 43 lines · Marek Vasut
Quoted 41 lines · Sean Anderson
Quoted 28 lines · Marek Vasut
Quoted 21 lines · Tom Rini
Quoted 11 lines

No, the check in fdt_getprop is only for the name, not the value (which could be arbitrary binary data including many nul bytes).

I think the assumption in most of U-Boot is that the provided FDT is trusted (or at least not maliciously ill-formed). functions like image_get_checksum_algo read up to 6 bytes beyond full_name if full_name == "". It's possible to read off the end of the DTB if this is the very last string in the strings block and there is no trailing padding. If we're really concerned about this (e.g. to avoid false-positives with ASAN), then we should just add (say) 16 bytes to the end of every DTB when we malloc it.

Yes, we rely on the sanity checking in libfdt, which I think the kernel also does.

And no, I'm not sure if we care enough about all of these corner cases, but if we do then I'm not sure this right here and now is where to start. It should start with upstream libfdt to see whatever cases aren't handled, and then what cases fall on the callers to deal with wrt security implications.

Quoted 3 lines

Because I really, really, really, do not want to block fixing booting on some large number of boards because now we're going to depend first on a security audit here.

So back to my and Sean suggestion:

Quoted 8 lines

fdt_string_eq_() does effectively memcmp():

return p && (slen == len) && (memcmp(p, s, len) == 0);

So do this and be done with it ?

type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
if (type && len == strlen(FIT_TYPE_PROP) && !memcmp(type, "flat_dt", len))

this is wrong it needs to be

type && len == sizeof("flat_dt") && !memcmp(type, "flat_dt", len)

Quoted 7 lines
Quoted 1 line

... because ... ?

Because the check you wrote is equivalent to

if (type && sizeof("flat_dt") == strlen("type") && ...)

which will always fail.

Oh, that ... you're right.

#22 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 36 lines · Marek Vasut
Quoted 26 lines · Beleswar Prasad Padhi
Quoted 24 lines · Marek Vasut
Quoted 23 lines · Tom Rini
Quoted 11 lines · Beleswar Padhi

When CONFIG_SPL_MULTI_DTB_FIT is enabled, multiple device trees are packed inside the multidtb.fit FIT image. While the individual DTBs and the FIT image start address are 8-byte aligned, the DTBs embedded within the FIT image are not guaranteed to maintain 8-byte alignment.

This misalignment causes -FDT_ERR_ALIGNMENT failure in setup_multi_dtb_fit() when locating the next available DTB within the FIT blob and setting gd->fdt_blob, because of the recent libfdt hardening since commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")

Quoted 8 lines

The mkimage tool already supports enforcing this alignment via the -B option, but users would have to specify it explicitly. This change makes 8-byte alignment the default when using -b.

Fixes 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")
Quoted 8 lines
Quoted 3 lines

Doesn't this enable 8-byte alignment for everything in case a DT is specified on mkimage command line ? That doesn't seem right ?

If I do mkimage -f auto -b ...dtb ... , then I only want the DTB to be 8-byte aligned, all the other blobs can be 4 byte aligned just fine .

All the mkimage flags are parsed at once and populated in the params data structure in one shot in the code. There is no separation of code specifically for generating a FIT for a DTB vs for anything else.

Quoted 8 lines

That does not seem to be true ?

$ git grep -p '\<bl_len\>' tools/
tools/fit_image.c=static int fit_extract_data(struct image_tool_params *params, const char *fname)
tools/fit_image.c:      align_size = params->bl_len ? params->bl_len : 4;
...

So something like that may work ?

Yup, you're right. I was fixated to correct the alignment at the bl_len layer, so didn't look further how it was getting propagated.

Quoted 7 lines

"

tools/fit_image.c +0 -0
index 0306333141e..0c606ba4cc3 100644

tools/fit_image.c static int fit_extract_data(struct image_tool_params *params, const char *fname) · line 648

Quoted 8 lines
tools/fit_image.c +2 -1
@@ -642,9 +642,15 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
         for (node = fdt_first_subnode(fdt, images);
              node >= 0;
              node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                 int len;
 
+               if (align_size < 8) {

Do we need this check?
Although unlikely, but should we account for mkimage invocations with -B > 0x8 and not a multiple of 8?

Quoted 10 lines
tools/fit_image.c +5 -0
+                       type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+                       if (type && !strcmp(type, "flat_dt"))
+                               align_size = 8;
+               }
+
                 data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
                 if (!data)
                         continue;

"

Quoted 5 lines
Quoted 4 lines

We
would get the same result when using mkimage -f auto -b ...dtb... -B 0x8 I think we should be fine with this limitation for the usecases when generating fitImage with mixed images. Unless you have some idea?

What about the above ?

Thanks,
Beleswar

#23 lore raw

On 1/27/26 8:46 AM, Beleswar Prasad Padhi wrote:

[...]

Quoted 13 lines
Quoted 13 lines

"

tools/fit_image.c +1 -1
index 0306333141e..0c606ba4cc3 100644
@@ -642,9 +642,15 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
         for (node = fdt_first_subnode(fdt, images);
              node >= 0;
              node = fdt_next_subnode(fdt, node)) {
-               const char *data;
+               const char *data, *type;
                 int len;
 
Quoted 6 lines

tools/fit_image.c static int fit_extract_data(struct image_tool_params *params, const char *fname) · line 648

Quoted 1 line
tools/fit_image.c +1 -0
+               if (align_size < 8) {

Do we need this check?
Although unlikely, but should we account for mkimage invocations with -B > 0x8 and not a multiple of 8?

Yes, you should, that's a good point.