diff mbox

[08/13] tools: use crc checking code from romfs/tools

Message ID 1465979400-2964-9-git-send-email-adrian@lisas.de
State Accepted
Headers show

Commit Message

Adrian Reber June 15, 2016, 8:29 a.m. UTC
Added CRC check of the header and complete image
when dumping the header.

(cherry picked from commit 645bc2cbd550829d43b460663b998b9d4685a2d2)

Cherry picked from https://lisas.de/~adrian/slof/slof.git/

Signed-off-by: Adrian Reber <adrian@lisas.de>
---
 tools/Makefile |  6 +++++-
 tools/sloffs.c | 18 ++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/tools/Makefile b/tools/Makefile
index a035960..6da2e17 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -13,16 +13,20 @@ 
 include ../make.rules
 
 TARGETS = gen_reloc_table sloffs
+HOSTCFLAGS += -I../romfs/tools
 
 all: $(TARGETS)
 
+crclib.o: ../romfs/tools/crclib.c
+		$(HOSTCC) -W $(HOSTCFLAGS) -c $^ -o $@
+
 %.o: %.c
 		$(HOSTCC) -W $(HOSTCFLAGS) -c $^
 
 gen_reloc_table: gen_reloc_table.o
 		$(HOSTCC) $(HOSTCFLAGS) -o $@ $^
 
-sloffs: sloffs.o
+sloffs: sloffs.o crclib.o
 		$(HOSTCC) $(HOSTCFLAGS) -o $@ $^
 
 clean_here:
diff --git a/tools/sloffs.c b/tools/sloffs.c
index eca06d8..bd8ebd2 100644
--- a/tools/sloffs.c
+++ b/tools/sloffs.c
@@ -23,6 +23,7 @@ 
 #include <getopt.h>
 
 #include <calculatecrc.h>
+#include <crclib.h>
 
 #define VERSION 1
 
@@ -136,11 +137,24 @@  sloffs_dump(const void *data)
 	printf(" (0x%llx) bytes\n", be64_to_cpu(header->flashlen));
 	printf("  Revision    : %s\n", header->platform_revision);
 	crc = be64_to_cpu(header->ui64CRC);
-	printf("  Header CRC  : 0x%016llx\n", crc);
+	printf("  Header CRC  : 0x%016llx CRC check: ", crc);
+	crc = calCRCword((unsigned char *)data, be64_to_cpu(sloffs->len), 0);
+	if (!crc)
+		printf("[OK]");
+	else
+		printf("[FAILED]");
+	printf("\n");
+
 	crc = be64_to_cpu(header->flashlen);
 	crc = *(uint64_t *)(unsigned char *)(data + crc - 8);
 	crc = be64_to_cpu(crc);
-	printf("  Image CRC   : 0x%016llx\n", crc);
+	printf("  Image CRC   : 0x%016llx CRC check: ", crc);
+	crc = calCRCword((unsigned char *)data, be64_to_cpu(header->flashlen), 0);
+	if (!crc)
+		printf("[OK]");
+	else
+		printf("[FAILED]");
+	printf("\n");
 
 	/* count number of files */
 	sloffs = (struct sloffs *)data;