public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv5] new tool mkenvimage: generates an env image from an arbitrary config file
Date: Thu, 1 Sep 2011 13:47:00 -0400	[thread overview]
Message-ID: <201109011347.01447.vapier@gentoo.org> (raw)
In-Reply-To: <1314892629-2002-1-git-send-email-david.wagner@free-electrons.com>

On Thursday, September 01, 2011 11:57:09 David Wagner wrote:
> +	txt_filename = argv[optind];
> +	if (strcmp(txt_filename, "-") == 0) {
> +		txt_fd = STDIN_FILENO;
> +	} else {
> +		txt_fd = open(txt_filename, O_RDONLY);
> +		if (txt_fd == -1) {
> +			fprintf(stderr, "Can't open \"%s\": %s\n",
> +					txt_filename, strerror(errno));
> +			return EXIT_FAILURE;
> +		}
> +	}
> +	/* ... and check it */
> +	ret = fstat(txt_fd, &txt_file_stat);
> +	if (ret == -1) {
> +		fprintf(stderr, "Can't stat() on \"%s\": "
> +				"%s\n", txt_filename, strerror(errno));
> +		return EXIT_FAILURE;
> +	}
> +	/*
> +	 * The right test to do is "=>" (not ">") because of the additionnal
> +	 * ending \0. See below.
> +	 */
> +	if (txt_file_stat.st_size >= envsize) {
> +		fprintf(stderr, "The input file is larger than the "
> +				"envrionnment partition size\n");
> +		return EXIT_FAILURE;
> +	}
> +
> +	/* Read the raw input file and transform it */
> +	filebuf = malloc(sizeof(*envptr) * txt_file_stat.st_size);
> +	ret = read(txt_fd, filebuf, sizeof(*envptr) * txt_file_stat.st_size);
> +	if (ret != txt_file_stat.st_size) {
> +		fprintf(stderr, "Can't read the whole input file\n");
> +		return EXIT_FAILURE;
> +	}

i think the stdin logic here is broken.  when you fstat() stdin, you get back 
st_size == 0, and so you end up doing a read() on stdin of 0 bytes, and it 
writes out an empty image.

simple test:
echo foo=var | ./mkenvimage -s 0x1000 -o foo -
hexdump -C foo
<see that the env is empty>

running it through strace shows the bum read(0, "", 0) ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110901/5e00bdeb/attachment.pgp 

  reply	other threads:[~2011-09-01 17:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-05 14:49 [U-Boot] [PATCH] new tool mkenvimage: generates an env image from an arbitrary config file David Wagner
2011-08-05 15:23 ` Thomas Petazzoni
2011-08-05 16:23 ` [U-Boot] [PATCHv2] " David Wagner
2011-08-06 11:18   ` Mike Frysinger
2011-08-08  8:16     ` David Wagner
2011-08-08  8:46       ` Albert ARIBAUD
2011-08-08  8:56         ` David Wagner
2011-08-08 18:53       ` Mike Frysinger
2011-08-09 10:31 ` [U-Boot] [PATCH] " David Wagner
2011-08-22  1:09   ` Mike Frysinger
2011-08-24 22:12   ` Wolfgang Denk
2011-08-29 12:06 ` [U-Boot] [PATCHv4] " David Wagner
2011-08-30 19:12   ` Mike Frysinger
2011-08-30 19:34   ` Wolfgang Denk
2011-09-01 15:57 ` [U-Boot] [PATCHv5] " David Wagner
2011-09-01 17:47   ` Mike Frysinger [this message]
2011-09-02  8:47 ` [U-Boot] [PATCH] " David Wagner
2011-09-02  8:48   ` David Wagner
2011-09-02  8:48 ` [U-Boot] [PATCHv6] " David Wagner
2011-09-02 14:35   ` Mike Frysinger
2011-09-26 12:10   ` Thomas Petazzoni
2011-09-26 13:26 ` [U-Boot] [PATCHv7] " David Wagner
2011-09-30  7:31 ` [U-Boot] [PATCHv8] " David Wagner
2011-10-06 21:17   ` Wolfgang Denk
2011-10-13 18:45 ` [U-Boot] [PATCHv9] " David Wagner
2011-10-14  8:21   ` Detlev Zundel
2011-10-14 17:16 ` [U-Boot] [PATCHv10] " David Wagner
2011-10-19  8:22   ` Thomas Petazzoni
2011-10-23 20:44   ` Wolfgang Denk
2011-10-31  0:49     ` Mike Frysinger
2011-11-22  8:48   ` Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201109011347.01447.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox