diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2013-09-19 14:47:24 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-20 08:34:07 +0200 |
commit | 78182d5d4f8532ab1018c99a7271005d9bb1bad2 (patch) | |
tree | 1ca0966b0db98e5f1560a5e97ee9192abdaa3219 /commands | |
parent | d36178223b5f32821555dafbd8e065d326209cdc (diff) | |
download | barebox-78182d5d4f8532ab1018c99a7271005d9bb1bad2.tar.gz barebox-78182d5d4f8532ab1018c99a7271005d9bb1bad2.tar.xz |
command: crc: add -V option to check the crc store in a file
the format is %08x
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/crc.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/commands/crc.c b/commands/crc.c index a0071b0e8b..ee8dacff0b 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -82,6 +82,19 @@ out: return ret; } +static int crc_from_file(const char* file, ulong *crc) +{ + char * buf; + + buf= read_file(file, NULL); + + if (!buf) + return -ENOMEM; + + *crc = simple_strtoul(buf, NULL, 16); + return 0; +} + static int do_crc(int argc, char *argv[]) { loff_t start = 0, size = ~0; @@ -92,7 +105,7 @@ static int do_crc(int argc, char *argv[]) #endif int opt, err = 0, filegiven = 0, verify = 0; - while((opt = getopt(argc, argv, "f:F:v:")) > 0) { + while((opt = getopt(argc, argv, "f:F:v:V:")) > 0) { switch(opt) { case 'f': filename = optarg; @@ -108,6 +121,10 @@ static int do_crc(int argc, char *argv[]) verify = 1; vcrc = simple_strtoul(optarg, NULL, 0); break; + case 'V': + if (!crc_from_file(optarg, &vcrc)) + verify = 1; + break; default: return COMMAND_ERROR_USAGE; } @@ -153,6 +170,7 @@ BAREBOX_CMD_HELP_OPT ("-f <file>", "Use file instead of memory.\n") BAREBOX_CMD_HELP_OPT ("-F <file>", "Use file to compare.\n") #endif BAREBOX_CMD_HELP_OPT ("-v <crc>", "Verify\n") +BAREBOX_CMD_HELP_OPT ("-V <file>", "Verify with crc read from <file>\n") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(crc32) |