[PATCH 1/1 V2] command: crc: add -V option to check the crc store in a file

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Thu Sep 19 08:47:24 EDT 2013


the format is %08x

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
v2:

	improve help description

Best Regards,
J.
 commands/crc.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/commands/crc.c b/commands/crc.c
index a0071b0..ee8dacf 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)
-- 
1.8.4.rc1




More information about the barebox mailing list