summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2025-10-10 13:28:42 -0600
committerTom Rini <[email protected]>2025-10-10 13:28:42 -0600
commitcd01a8164d06fb1f31fddadd78bf17be8d6fa006 (patch)
tree7bc8d265be241c823e2641916f9bbb191bd93298
parent8c42f534d7e1956192ef8457fae884469f60ff13 (diff)
parentb3ab77345e3d1e7f40f1991e5072daf0f2d972dc (diff)
Merge patch series "mkimage: fit: various fixes in fit_{import,extract}_data"
Quentin Schulz <[email protected]> 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/[email protected]
-rw-r--r--tools/fit_image.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 10849733816..0306333141e 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -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);