mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Grzeschik <m.grzeschik@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] commands: crc: support setting environment variables
Date: Thu, 29 Jan 2015 16:43:48 +0100	[thread overview]
Message-ID: <1422546228-22674-1-git-send-email-m.grzeschik@pengutronix.de> (raw)

From: Jan Luebbe <jlu@pengutronix.de>

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 commands/crc.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/commands/crc.c b/commands/crc.c
index 9b6a3e2..58b750e 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -46,9 +46,10 @@ static int do_crc(int argc, char *argv[])
 #ifdef CONFIG_CMD_CRC_CMP
 	char *vfilename = NULL;
 #endif
+	char *crcvarname = NULL, *sizevarname = NULL;
 	int opt, err = 0, filegiven = 0, verify = 0;
 
-	while((opt = getopt(argc, argv, "f:F:v:V:")) > 0) {
+	while((opt = getopt(argc, argv, "f:F:v:V:r:s:")) > 0) {
 		switch(opt) {
 		case 'f':
 			filename = optarg;
@@ -60,6 +61,12 @@ static int do_crc(int argc, char *argv[])
 			vfilename = optarg;
 			break;
 #endif
+		case 'r':
+			crcvarname = optarg;
+			break;
+		case 's':
+			sizevarname = optarg;
+			break;
 		case 'v':
 			verify = 1;
 			vcrc = simple_strtoul(optarg, NULL, 0);
@@ -89,6 +96,18 @@ static int do_crc(int argc, char *argv[])
 	printf("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
 			filename, (ulong)start, (ulong)start + total - 1, crc);
 
+	if (crcvarname) {
+		char *crcstr = asprintf("0x%lx", crc);
+		setenv(crcvarname, crcstr);
+		kfree(crcstr);
+	}
+
+	if (sizevarname) {
+		char *sizestr = asprintf("0x%lx", total);
+		setenv(sizevarname, sizestr);
+		kfree(sizestr);
+	}
+
 #ifdef CONFIG_CMD_CRC_CMP
 	if (vfilename) {
 		size = total;
@@ -118,6 +137,8 @@ BAREBOX_CMD_HELP_OPT ("-F FILE", "Use file to compare.")
 #endif
 BAREBOX_CMD_HELP_OPT ("-v CRC",  "Verify")
 BAREBOX_CMD_HELP_OPT ("-V FILE", "Verify with CRC read from FILE")
+BAREBOX_CMD_HELP_OPT  ("-r <var>",  "Set <var> to the checksum result\n")
+BAREBOX_CMD_HELP_OPT  ("-s <var>",  "Set <var> to the data size\n")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(crc32)
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2015-01-29 15:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-29 15:43 Michael Grzeschik [this message]
2015-01-30  7:56 ` Sascha Hauer

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=1422546228-22674-1-git-send-email-m.grzeschik@pengutronix.de \
    --to=m.grzeschik@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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