[SLOF] [PATCH slof 4/7] tools: use crc checking code from romfs/tools

Alexey Kardashevskiy aik at ozlabs.ru
Wed Jul 27 16:19:17 AEST 2016


From: Adrian Reber <adrian at lisas.de>

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 at lisas.de>
Signed-off-by: Alexey Kardashevskiy <aik at ozlabs.ru>
---
 tools/Makefile |  6 +++++-
 tools/sloffs.c | 18 ++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

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 4b9ba5e..4ec5d56 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
 
@@ -139,11 +140,24 @@ sloffs_dump(const void *data)
 	printf(" (0x%lx) bytes\n", be64_to_cpu(header->flashlen));
 	printf("  Revision    : %s\n", header->platform_revision);
 	crc = be64_to_cpu(header->ui64CRC);
-	printf("  Header CRC  : 0x%016lx\n", crc);
+	printf("  Header CRC  : 0x%016lx 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%016lx\n", crc);
+	printf("  Image CRC   : 0x%016lx 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;
-- 
2.5.0.rc3



More information about the SLOF mailing list