From 9177b7e84b0af3e6a10a6444d72ead82b72c001f Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Wed, 15 Jun 2016 10:29:55 +0200 Subject: tools: use crc checking code from romfs/tools 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 Signed-off-by: Alexey Kardashevskiy --- tools/Makefile | 6 +++++- tools/sloffs.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'tools') 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 #include +#include #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; -- cgit v1.1