Hi Beleswar,
On 1/28/26 09:18, Beleswar Padhi wrote:
From: Marek Vasut <[email protected]>
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")
To fix this, check the image type when extracting FIT image data and
set the alignment size to 8 bytes (if not already) only for flat_dt
images. This ensures correct alignment for device tree blobs as per the
DT spec, while also allowing different alignment sizes for other image
types within the FIT.
Reported-by: Anshul Dalal <[email protected]>
Closes: https://lore.kernel.org/u-boot/[email protected]
Fixes: 0535e46d55d7 ("scripts/dtc: Update to upstream version
v1.7.2-35-g52f07dcca47c")
Signed-off-by: Marek Vasut <[email protected]>
Signed-off-by: Beleswar Padhi <[email protected]>
---
Testing Done:
1. Boot tested on all TI K3 platforms.
v4: Changelog:
1. Align only the DTBs to 8-bytes, other images in a FIT can have their
independent alignment. [Marek]
Link to v3:
https://lore.kernel.org/all/[email protected]/
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/fit_image.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
Can you please update doc/mkimage.1 as well? There should be a note about
this under -E.
diff --git a/tools/fit_image.c b/tools/fit_image.c
index e865f65a400..f842c845771 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -682,9 +682,17 @@ 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;
+ /* Fallback to 8-byte alignment for DTBs if unaligned */
+ type = fdt_getprop(fdt, node, FIT_TYPE_PROP, &len);
+ if (type &&
+ len == sizeof("flat_dt") &&
+ !memcmp(type, "flat_dt", len) &&
+ align_size & 0x7)
+ align_size = 8;
+
Doesn't this increase the alignment for all images following the devicetree?
And actually, doesn't this happen too late? By the time we check whether the
node is a devicetree, buf_ptr has already been updated. This check will only
affect the alignment of the *next* image in the FIT.
--Sean
data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
if (!data)
continue;