tools: mkimage: copy the FIT in process instead of shelling out to cp
PATCH 1/1 tools: mkimage: copy the FIT in process instead of shelling out to cp
Rebuilding an existing FIT (-F) starts by making a working copy of it, and mkimage asks a shell to do that:
snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile);
so signing a FIT needs /bin/sh and cp on top of mkimage itself. That rules the tool out of the minimal images where firmware tends to be assembled; in one of them the failure reads
mkimage: system(cp "u-boot.itb" "u-boot.itb.tmp") failed:
No such file or directory
which names cp but means there is no shell to run it with: glibc's system() uses posix_spawn and returns -1 with ENOENT when /bin/sh is missing.
copyfile() does the same job in process, is declared in tools/fit_common.h and is already called further down this same function to restore the backup, so use it. Leaving cmd empty makes the existing "if (*cmd && ...)" guard skip system() altogether, the same way the auto-FIT path above already does.
No functional change intended: the temporary file ends up with the same contents.
--- tools/fit_image.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/fit_image.c +4 -2
@@ -1654,8 +1654,10 @@ static int fit_handle_file(struct image_tool_params *params) MKIMAGE_DTC, params->dtc, tmpfile, params->datafile);debug ("Trying to execute \"%s\"\n" , cmd); }else { -snprintf (cmd,sizeof (cmd),"cp \"%s\" \"%s\"" , - params->imagefile, tmpfile); +/* Copy the image in process: mkimage must not need a shell. */ +if (copyfile (params->imagefile, tmpfile) <0 ) + goto err_system; + *cmd ='\0' ; }if (strlen (cmd) >=MKIMAGE_MAX_DTC_CMDLINE_LEN -1 ) {fprintf (stderr,"WARNING: command-line for FIT creation might be truncated and will probably fail.\n" );
Signature · 1 line
2.56.0
Quoted 25 lines · Enrique Hernández Bello
tools: mkimage: copy the FIT in process instead of shelling out to cp
Rebuilding an existing FIT (-F) starts by making a working copy of it, and mkimage asks a shell to do that:
snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile);so signing a FIT needs
/bin/shand cp on top of mkimage itself. That rules the tool out of the minimal images where firmware tends to be assembled; in one of them the failure readsmkimage:
system(cp "u-boot.itb" "u-boot.itb.tmp")failed:
No such file or directorywhich names cp but means there is no shell to run it with: glibc's
system()usesposix_spawnand returns -1 with ENOENT when/bin/shis missing.
copyfile()does the same job in process, is declared intools/fit_common.hand is already called further down this same function to restore the backup, so use it. Leaving cmd empty makes the existing "if (*cmd && ...)" guard skipsystem()altogether, the same way the auto-FIT path above already does.
Quoted 7 lines
No functional change intended: the temporary file ends up with the same contents.
Signed-off-by Enrique Hernández Bello <[email protected]>tools/fit_image.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 11 lines · Enrique Hernández Bello
Rebuilding an existing FIT (-F) starts by making a working copy of it, and mkimage asks a shell to do that:
snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile);so signing a FIT needs
/bin/shand cp on top of mkimage itself. That rules the tool out of the minimal images where firmware tends to be assembled; in one of them the failure reads[...]
Applied to u-boot/main, thanks!
[1/1] tools: mkimage: copy the FIT in process instead of shelling out to cp
commit: 58eb0801bca518d6aa81a7b49b063aacc6e98bb2
Signature · 1 line
Tom