Merge patch series "mkimage: fit: various fixes in fit_{import,extract}_data"

Quentin Schulz <foss+uboot@0leil.net> says:

I had to hunt down a difference between the FIT after running mkimage
once and after running it twice. The use-case is typically U-Boot
generating an unsigned FIT and then calling mkimage manually to sign it
outside any build system.

The issue can be reproduced with the following

make CROSS_COMPILE=aarch64-linux-gnu- BUILD_TAG= SOURCE_DATE_EPOCH=0 O=build/ringneck ringneck-px30_defconfig
make CROSS_COMPILE=aarch64-linux-gnu- BUILD_TAG= SOURCE_DATE_EPOCH=0 O=build/ringneck -j`nproc`
cd build/ringneck
cp ./simple-bin.fit.itb ./simple-bin.foo.fit
cp ./simple-bin.fit.itb ./simple-bin.foo2.fit
BUILD_TAG= SOURCE_DATE_EPOCH=0 ./tools/mkimage -E -t -B 200 -F ./simple-bin.foo.fit
BUILD_TAG= SOURCE_DATE_EPOCH=0 ./tools/mkimage -E -t -B 200 -F ./simple-bin.foo2.fit
BUILD_TAG= SOURCE_DATE_EPOCH=0 ./tools/mkimage -E -t -B 200 -F ./simple-bin.foo2.fit

then compare the output of

dtc -I dtb -O dts simple-bin.foo.fit
dtc -I dtb -O dts simple-bin.foo2.fit

data-size and data-offset properties are swapped.

While going through the code, I identified a few theoretical issues
possibly triggered by not checking the return code of fdt_setprop so
those are added. Not tested outside of building.

Link: https://lore.kernel.org/r/20250923-mkimage-2-runs-data-size-v1-0-ef3fa57e9645@cherry.de
This commit is contained in:
Tom Rini
2025-10-10 13:28:42 -06:00

View File

@@ -658,13 +658,25 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
}
if (params->external_offset > 0) {
/* An external offset positions the data absolutely. */
fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP,
params->external_offset + buf_ptr);
ret = fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP,
params->external_offset + buf_ptr);
} else {
fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP,
buf_ptr);
ret = fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP,
buf_ptr);
}
fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len);
if (ret) {
ret = -EINVAL;
goto err_munmap;
}
ret = fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len);
if (ret) {
ret = -EINVAL;
goto err_munmap;
}
buf_ptr += ALIGN(len, align_size);
}
@@ -793,14 +805,28 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
debug("Importing data size %x\n", len);
ret = fdt_setprop(fdt, node, FIT_DATA_PROP, data, len);
ret = fdt_delprop(fdt, node, ext_data_prop);
if (ret) {
debug("%s: Failed to write property: %s\n", __func__,
fdt_strerror(ret));
ret = -EINVAL;
goto err_munmap;
}
ret = fdt_delprop(fdt, node, ext_data_prop);
if (ret) {
debug("%s: Failed to erase property: %s\n", __func__,
fdt_strerror(ret));
ret = -EINVAL;
goto err_munmap;
}
ret = fdt_delprop(fdt, node, FIT_DATA_SIZE_PROP);
if (ret) {
debug("%s: Failed to erase %s property: %s\n", __func__,
FIT_DATA_SIZE_PROP, fdt_strerror(ret));
ret = -EINVAL;
goto err_munmap;
}
}
confs = fdt_path_offset(fdt, FIT_CONFS_PATH);