public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 0/2] mkimage: fix using long pathnames
@ 2020-04-27  0:08 Sven Roederer
  2020-04-27  0:08 ` [PATCH 1/2] tools/mkimage: fix handling long filenames Sven Roederer
  2020-04-27  0:08 ` [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated Sven Roederer
  0 siblings, 2 replies; 5+ messages in thread
From: Sven Roederer @ 2020-04-27  0:08 UTC (permalink / raw)
  To: u-boot

When running an buildbot with OpenWrt-CI I got the following error:

mkimage -f /var/lib/buildbot/slaves/slave/ipq40xx-generic/build/firmware/openwrt/
build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/tmp/
freifunk-berlin-dev-daily-1907-f66973b-ipq40xx-generic-asus_map-ac2200-initramfs-fit-uImage.itb.its
 /var/lib/buildbot/slaves/slave/ipq40xx-generic/build/firmware/openwrt/build_dir/
target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/tmp/
freifunk-berlin-dev-daily-1907-f66973b-ipq40xx-generic-asus_map-ac2200-initramfs-fit-uImage.itb.new
sh: 1: Syntax error: Unterminated quoted string

The syntax error is reported by the system()-call of fit_image.c as the cmd-
variable get truncated when using such long pathnames for teh output and the
FIT-file.
It's fixed by redefining the MKIMAGE_MAX_DTC_CMDLINE_LEN based on the size.
of MKIMAGE_MAX_TMPFILE_LEN. Also a Warning will be printed when detecting 
that the cmd-variable has reached its maximal size.

Sven Roederer (2):
  tools/mkimage: fix handling long filenames
  tools/fit-image: print a warning when cmd-line for dtc might be
    truncated

 tools/fit_image.c | 4 ++++
 tools/mkimage.h   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] tools/mkimage: fix handling long filenames
  2020-04-27  0:08 [PATCH 0/2] mkimage: fix using long pathnames Sven Roederer
@ 2020-04-27  0:08 ` Sven Roederer
  2020-05-01 21:56   ` Tom Rini
  2020-04-27  0:08 ` [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated Sven Roederer
  1 sibling, 1 reply; 5+ messages in thread
From: Sven Roederer @ 2020-04-27  0:08 UTC (permalink / raw)
  To: u-boot

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 <devel-sven@geroedel.de>
---
 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_ */
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated
  2020-04-27  0:08 [PATCH 0/2] mkimage: fix using long pathnames Sven Roederer
  2020-04-27  0:08 ` [PATCH 1/2] tools/mkimage: fix handling long filenames Sven Roederer
@ 2020-04-27  0:08 ` Sven Roederer
  2020-05-01 21:57   ` Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Sven Roederer @ 2020-04-27  0:08 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Sven Roederer <devel-sven@geroedel.de>
---
 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 <image.h>
+#include <string.h>
 #include <stdarg.h>
 #include <version.h>
 #include <u-boot/crc.h>
@@ -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",
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 1/2] tools/mkimage: fix handling long filenames
  2020-04-27  0:08 ` [PATCH 1/2] tools/mkimage: fix handling long filenames Sven Roederer
@ 2020-05-01 21:56   ` Tom Rini
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2020-05-01 21:56 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 27, 2020 at 02:08:38AM +0200, Sven Roederer wrote:

> 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 <devel-sven@geroedel.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/556e85bd/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated
  2020-04-27  0:08 ` [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated Sven Roederer
@ 2020-05-01 21:57   ` Tom Rini
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2020-05-01 21:57 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 27, 2020 at 02:08:39AM +0200, Sven Roederer wrote:

> Signed-off-by: Sven Roederer <devel-sven@geroedel.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/9658973a/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-01 21:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-27  0:08 [PATCH 0/2] mkimage: fix using long pathnames Sven Roederer
2020-04-27  0:08 ` [PATCH 1/2] tools/mkimage: fix handling long filenames Sven Roederer
2020-05-01 21:56   ` Tom Rini
2020-04-27  0:08 ` [PATCH 2/2] tools/fit-image: print a warning when cmd-line for dtc might be truncated Sven Roederer
2020-05-01 21:57   ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox