From patchwork Mon Apr 27 00:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Roederer X-Patchwork-Id: 238567 List-Id: U-Boot discussion From: devel-sven at geroedel.de (Sven Roederer) Date: Mon, 27 Apr 2020 02:08:38 +0200 Subject: [PATCH 1/2] tools/mkimage: fix handling long filenames In-Reply-To: <20200427000839.26473-1-devel-sven@geroedel.de> References: <20200427000839.26473-1-devel-sven@geroedel.de> Message-ID: <20200427000839.26473-2-devel-sven@geroedel.de> The cmdline for calling the dtc was cut-off when using long filenames (e.g. 245 bytes) for output-file and datafile of "-f" parameter. For FIT-images cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN] is declared (hardcoded 512 bytes), and contains some static values, the path of a tmpfile and a datafile. tmpfile is max MKIMAGE_MAX_TMPFILE_LEN (256) and datafile might be also this size. Having two very long pathname results in a truncation os the executed shell command, as the truncated datafile path will not be found. Redefine MKIMAGE_MAX_DTC_CMDLINE_LEN to "2 * MKIMAGE_MAX_TMPFILE_LEN + 35 for the parameters. This likely applies to the "-d" parameter, too. Signed-off-by: Sven Roederer --- tools/mkimage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mkimage.h b/tools/mkimage.h index 0254af59fb..9de94dbe99 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -42,6 +42,7 @@ static inline ulong map_to_sysmem(void *ptr) #define MKIMAGE_TMPFILE_SUFFIX ".tmp" #define MKIMAGE_MAX_TMPFILE_LEN 256 #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500" -#define MKIMAGE_MAX_DTC_CMDLINE_LEN 512 +#define MKIMAGE_MAX_DTC_CMDLINE_LEN 2 * MKIMAGE_MAX_TMPFILE_LEN + 35 /* 35 bytes for quotes, spaces, "-o", len(MKIMAGE_DEFAULT_DTC_OPTIONS), len(MKIMAGE_TMPFILE_SUFFIX) */ #endif /* _MKIIMAGE_H_ */ From patchwork Mon Apr 27 00:08:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Roederer X-Patchwork-Id: 238566 List-Id: U-Boot discussion From: devel-sven at geroedel.de (Sven Roederer) Date: Mon, 27 Apr 2020 02:08:39 +0200 Subject: [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated In-Reply-To: <20200427000839.26473-1-devel-sven@geroedel.de> References: <20200427000839.26473-1-devel-sven@geroedel.de> Message-ID: <20200427000839.26473-3-devel-sven@geroedel.de> Signed-off-by: Sven Roederer --- tools/fit_image.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/fit_image.c b/tools/fit_image.c index 4aeabbcfe9..88ff093d05 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -17,6 +17,7 @@ #include "fit_common.h" #include "mkimage.h" #include +#include #include #include #include @@ -744,6 +745,9 @@ static int fit_handle_file(struct image_tool_params *params) snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile); } + 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"); + } if (*cmd && system(cmd) == -1) { fprintf (stderr, "%s: system(%s) failed: %s\n",