From patchwork Wed Jul 27 06:19:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 653111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rzlRj2H5qz9t2d for ; Wed, 27 Jul 2016 16:28:17 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rzlRj1Vy1zDrJm for ; Wed, 27 Jul 2016 16:28:17 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from ozlabs.ru (ozlabs.ru [83.169.36.222]) by lists.ozlabs.org (Postfix) with ESMTP id 3rzlRb1qYMzDrFC for ; Wed, 27 Jul 2016 16:28:11 +1000 (AEST) Received: from vpl2.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 4EF9F12064B; Wed, 27 Jul 2016 08:19:36 +0200 (CEST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Wed, 27 Jul 2016 16:19:15 +1000 Message-Id: <1469600360-19292-3-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 In-Reply-To: <1469600360-19292-1-git-send-email-aik@ozlabs.ru> References: <1469600360-19292-1-git-send-email-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof 2/7] romfs: factored out crc code, to make it usable from other locations X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Adrian Reber MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Adrian Reber This moves the CRC code to its own files without dependencies on board specific parts of SLOF. That why it can also be used from other parts of the code. (cherry picked from commit e0c2a1d61a66309fd6f0cec7efadd7e988bd03ab) Cherry picked from https://lisas.de/~adrian/slof/slof.git/ Signed-off-by: Adrian Reber Signed-off-by: Alexey Kardashevskiy --- romfs/tools/Makefile | 2 +- romfs/tools/crclib.c | 260 ++++++++++++++++++++++++++++++++++++++++++++++ romfs/tools/crclib.h | 23 +++++ romfs/tools/create_crc.c | 263 +---------------------------------------------- 4 files changed, 285 insertions(+), 263 deletions(-) create mode 100644 romfs/tools/crclib.c create mode 100644 romfs/tools/crclib.h diff --git a/romfs/tools/Makefile b/romfs/tools/Makefile index f86803d..f2a746f 100644 --- a/romfs/tools/Makefile +++ b/romfs/tools/Makefile @@ -22,7 +22,7 @@ include $(TOPCMNDIR)/make.rules CPPFLAGS = -I$(INCLCMNDIR) -I$(INCLBRDDIR) -I. CFLAGS += $(FLAG) -SRCS = build_ffs.c cfg_parse.c create_flash.c create_crc.c +SRCS = build_ffs.c cfg_parse.c create_flash.c create_crc.c crclib.c OBJS = $(SRCS:%.c=%.o) all: build_romfs diff --git a/romfs/tools/crclib.c b/romfs/tools/crclib.c new file mode 100644 index 0000000..b8a66e3 --- /dev/null +++ b/romfs/tools/crclib.c @@ -0,0 +1,260 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +#include +#include +#include + +uint64_t ui64Generator1; + +/** + * calculate standart ethernet 32 bit CRC + * generator polynome is 0x104C11DB7 + * this algorithm can be used for encoding and decoding + */ +static unsigned int +calCRCEthernet32(unsigned char *TextPtr, unsigned long int TextLength, + unsigned int AccumCRC) +{ + const unsigned int CrcTableHigh[16] = { + 0x00000000, 0x4C11DB70, 0x9823B6E0, 0xD4326D90, + 0x34867077, 0x7897AB07, 0xACA5C697, 0xE0B41DE7, + 0x690CE0EE, 0x251D3B9E, 0xF12F560E, 0xBD3E8D7E, + 0x5D8A9099, 0x119B4BE9, 0xC5A92679, 0x89B8FD09 + }; + const unsigned CrcTableLow[16] = { + 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, + 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, + 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, + 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD + }; + + unsigned char *Buffer = TextPtr; + unsigned long int Residual = TextLength; + + + while (Residual > 0) { + unsigned int Temp = ((AccumCRC >> 24) ^ *Buffer) & 0x000000ff; + AccumCRC <<= 8; + AccumCRC ^= CrcTableHigh[Temp / 16]; + AccumCRC ^= CrcTableLow[Temp % 16]; + ++Buffer; + --Residual; + } + return AccumCRC; +} + +/** + * create CRC Parameter: CRC Polynome, Shiftregister Mask and length + * + * ui64Generator[0] = 0; + * ui64Generator[1] = 0x42F0E1EB; + * ui64Generator[1] = (ui64Generator[1] << 32) + 0xA9EA3693; + * iRegisterLength = 63; + * ui64RegisterMask = 0xffffffff; + * ui64RegisterMask = ((ui64RegisterMask) << 32) + 0xffffffff; + * + * ucl=0x00000000ffffffff = Mask for 32 bit LSFR to cut down number of bits + * in the variable to get the same length as LFSR + * + * il = length of LSFR = degree of generator polynom reduce il by one to calculate the degree + * of the highest register in LSFR + * + * Examples: + * CRC-16 for Tap: x16 + x15 + x2 + 1 + * generator = 0x8005, il = 16, ucl = 0x000000000000FFFF + * + * CRC-16 for Floppy: x16 + x12 + x5 +1 + * generator = 0x1021, il = 16, ucl = 0x000000000000FFFF + * + * CRC-32 for Ethernet: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 + * generator = 0x04C11DB7, il = 32, ucl = 0x00000000FFFFFFFF + * + * CRC-64 SP-TrEMBL x64 + x4 + x3 + x + 1 (maximal-length LFSR) + * generator = 0x1B, il = 64, ucl = 0xFFFFFFFFFFFFFFFF + * + * CRC-64 improved + * x64 + x63 + x61 + x59 + x58 + x56 + x55 + x52 + x49 + x48 + x47 + x46+ x44 + + * x41 + x37 + x36 + x34 + x32 + x31 + x28 + x26 + x23 + x22 + x19 + x16 + x13 + + * x12 + x10 + x9 + x6 + x4 + x3 + 1 + * (see http://www.cs.ud.ac.uk/staff/D.Jones/crcbote.pdf) + * generator = 0xAD93D23594C9362D, il = 64, ucl = 0xFFFFFFFFFFFFFFFF + * + * CRC-64 DLT1 spec + * x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + + * x35 + x33 + x32 + x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + + * x10 + x9 + x7 + x4 + x + 1 + * (see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-182.pdf -> page63) + * generator = 0x42F0E1EBA9EA3693 + * + * CRC-64 from internet G(x)= 1006003C000F0D50B + */ +int +createCRCParameter(uint64_t *ui64RegisterMask, unsigned int *uiRegisterLength) +{ + enum Generators { Tape_16, Floppy_16, Ethernet_32, SPTrEMBL_64, + SPTrEMBL_improved_64, DLT1_64 }; + enum Generators Generator; + + Generator = CRC_METHODE; + switch (Generator) { + case Tape_16: { + *ui64RegisterMask = 0x0000ffff; + ui64Generator1 = 0x00008005; + *uiRegisterLength = 16; + break; + } + case Floppy_16: { + *ui64RegisterMask = 0x0000ffff; + ui64Generator1 = 0x00001021; + *uiRegisterLength = 16; + break; + } + case Ethernet_32: { + *ui64RegisterMask = 0xffffffff; + ui64Generator1 = 0x04C11DB7; + *uiRegisterLength = 32; + break; + } + case SPTrEMBL_64: { + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0x0000001B; + *uiRegisterLength = 64; + break; + } + case SPTrEMBL_improved_64: { + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0xAD93D235; + ui64Generator1 = (ui64Generator1 << 32) + 0x94C9362D; + *uiRegisterLength = 64; + break; + } + case DLT1_64: { + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0x42F0E1EB; + ui64Generator1 = (ui64Generator1 << 32) + 0xA9EA3693; + *uiRegisterLength = 64; + break; + } + } + (*uiRegisterLength)--; + + return 0; +} + +/** + * Check CRC by using Linear Feadback Shift Register (LFSR) + */ +static uint64_t +calCRCbyte(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + uint64_t ui64Mask, ui64Generator0; + uint8_t ui8Buffer; + unsigned int uiRegisterLength; + int iShift; + + createCRCParameter(&ui64Mask, &uiRegisterLength); + + ui8Buffer = (*cPtr); + while (ui32NoWords > 0) { + for (iShift = 7; iShift >= 0; iShift--) { + + ui64Generator0 = (AccumCRC >> uiRegisterLength); + AccumCRC <<= 1; + ui64Generator0 &= 0x01; + ui64Generator0 = (0 - ui64Generator0); + AccumCRC ^= (ui64Generator1 & ui64Generator0); + } + AccumCRC ^= ui8Buffer; + AccumCRC &= ui64Mask; + ui32NoWords -= 1; + cPtr += 1; + ui8Buffer = (*cPtr); + } + return AccumCRC; +} + +/** + * Check CRC by using Linear Feadback Shift Register (LFSR) + */ +uint64_t +calCRCword(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + uint64_t ui64Mask, ui64Generator0; + uint16_t ui16Buffer; + unsigned int uiRegisterLength; + int iShift; + + createCRCParameter(&ui64Mask, &uiRegisterLength); + + if ((ui32NoWords % 2) != 0) { + /* if Data string does not end at word boundery add one byte */ + ui32NoWords++; + cPtr[ui32NoWords] = 0; + } + ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); + while (ui32NoWords > 0) { + for (iShift = 15; iShift >= 0; iShift--) { + ui64Generator0 = (AccumCRC >> uiRegisterLength); + AccumCRC <<= 1; + ui64Generator0 &= 0x01; + ui64Generator0 = (0 - ui64Generator0); + AccumCRC ^= (ui64Generator1 & ui64Generator0); + } + AccumCRC ^= ui16Buffer; + AccumCRC &= ui64Mask; + ui32NoWords -= 2; + cPtr += 2; + ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); + } + return AccumCRC; +} + +uint64_t +checkCRC(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + enum Generators { Ethernet_32 }; + enum Generators Generator; + uint64_t ui64Buffer = AccumCRC; + + Generator = CRC_METHODE; + + switch (Generator) { + case Ethernet_32: { + /* (ui32NoWords - 4),no need of 4 bytes 0x as + * with shift-register method */ + AccumCRC = + calCRCEthernet32(cPtr, (ui32NoWords - 4), AccumCRC); + break; + } + default: { + AccumCRC = calCRCword(cPtr, ui32NoWords, AccumCRC); + break; + } + } + + if (calCRCbyte(cPtr, ui32NoWords, ui64Buffer) != AccumCRC) { + printf("\n --- big Endian - small Endian problem --- \n"); + AccumCRC--; + } + + return (AccumCRC); +} diff --git a/romfs/tools/crclib.h b/romfs/tools/crclib.h new file mode 100644 index 0000000..4ee21d0 --- /dev/null +++ b/romfs/tools/crclib.h @@ -0,0 +1,23 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +#ifndef CRCLIB_H +#define CRCLIB_H +#include + +extern uint64_t ui64Generator1; + +int createCRCParameter(uint64_t *, unsigned int *); +uint64_t calCRCword(unsigned char *, uint32_t, uint64_t); +uint64_t checkCRC(unsigned char *, uint32_t, uint64_t); + +#endif /* CRCLIB_H */ diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c index 51f137d..5a76b9c 100644 --- a/romfs/tools/create_crc.c +++ b/romfs/tools/create_crc.c @@ -14,29 +14,13 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include #include #include #include "createcrc.h" - -int createHeaderImage(int); -unsigned int calCRCEthernet32(unsigned char *TextPtr, - unsigned long int TextLength, - unsigned int AccumCRC); -int createCRCParameter(uint64_t * ui64RegisterMask, - unsigned int *iRegisterLength); -uint64_t calCRCbyte(unsigned char *TextPtr, uint32_t Residual, - uint64_t AccumCRC); -uint64_t calCRCword(unsigned char *TextPtr, uint32_t Residual, - uint64_t AccumCRC); -uint64_t checkCRC(unsigned char *TextPtr, uint32_t Residual, uint64_t AccumCRC); +#include "crclib.h" /* file length in bytes */ static uint64_t ui64globalFileSize = 0; @@ -46,7 +30,6 @@ static unsigned char pucFileStream[4400000]; static uint64_t ui64globalHeaderSize = 0; /* flag to filter detect the header in buildDataStream() */ static int iglobalHeaderFlag = 1; -static uint64_t ui64Generator1; /** * Build the file image and store it as Data Stream of bytes @@ -179,250 +162,6 @@ createHeaderImage(int notime) } /** - * calculate standart ethernet 32 bit CRC - * generator polynome is 0x104C11DB7 - * this algorithm can be used for encoding and decoding - */ -unsigned int -calCRCEthernet32(unsigned char *TextPtr, unsigned long int TextLength, - unsigned int AccumCRC) -{ - const unsigned int CrcTableHigh[16] = { - 0x00000000, 0x4C11DB70, 0x9823B6E0, 0xD4326D90, - 0x34867077, 0x7897AB07, 0xACA5C697, 0xE0B41DE7, - 0x690CE0EE, 0x251D3B9E, 0xF12F560E, 0xBD3E8D7E, - 0x5D8A9099, 0x119B4BE9, 0xC5A92679, 0x89B8FD09 - }; - const unsigned CrcTableLow[16] = { - 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, - 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, - 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, - 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD - }; - - unsigned char *Buffer = TextPtr; - unsigned long int Residual = TextLength; - - - while (Residual > 0) { - unsigned int Temp = ((AccumCRC >> 24) ^ *Buffer) & 0x000000ff; - AccumCRC <<= 8; - AccumCRC ^= CrcTableHigh[Temp / 16]; - AccumCRC ^= CrcTableLow[Temp % 16]; - ++Buffer; - --Residual; - } - return AccumCRC; -} - -/** - * create CRC Parameter: CRC Polynome, Shiftregister Mask and length - * - * ui64Generator[0] = 0; - * ui64Generator[1] = 0x42F0E1EB; - * ui64Generator[1] = (ui64Generator[1] << 32) + 0xA9EA3693; - * iRegisterLength = 63; - * ui64RegisterMask = 0xffffffff; - * ui64RegisterMask = ((ui64RegisterMask) << 32) + 0xffffffff; - * - * ucl=0x00000000ffffffff = Mask for 32 bit LSFR to cut down number of bits - * in the variable to get the same length as LFSR - * - * il = length of LSFR = degree of generator polynom reduce il by one to calculate the degree - * of the highest register in LSFR - * - * Examples: - * CRC-16 for Tap: x16 + x15 + x2 + 1 - * generator = 0x8005, il = 16, ucl = 0x000000000000FFFF - * - * CRC-16 for Floppy: x16 + x12 + x5 +1 - * generator = 0x1021, il = 16, ucl = 0x000000000000FFFF - * - * CRC-32 for Ethernet: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 - * generator = 0x04C11DB7, il = 32, ucl = 0x00000000FFFFFFFF - * - * CRC-64 SP-TrEMBL x64 + x4 + x3 + x + 1 (maximal-length LFSR) - * generator = 0x1B, il = 64, ucl = 0xFFFFFFFFFFFFFFFF - * - * CRC-64 improved - * x64 + x63 + x61 + x59 + x58 + x56 + x55 + x52 + x49 + x48 + x47 + x46+ x44 + - * x41 + x37 + x36 + x34 + x32 + x31 + x28 + x26 + x23 + x22 + x19 + x16 + x13 + - * x12 + x10 + x9 + x6 + x4 + x3 + 1 - * (see http://www.cs.ud.ac.uk/staff/D.Jones/crcbote.pdf) - * generator = 0xAD93D23594C9362D, il = 64, ucl = 0xFFFFFFFFFFFFFFFF - * - * CRC-64 DLT1 spec - * x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + - * x35 + x33 + x32 + x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + - * x10 + x9 + x7 + x4 + x + 1 - * (see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-182.pdf -> page63) - * generator = 0x42F0E1EBA9EA3693 - * - * CRC-64 from internet G(x)= 1006003C000F0D50B - */ -int -createCRCParameter(uint64_t * ui64RegisterMask, unsigned int *uiRegisterLength) -{ - enum Generators { Tape_16, Floppy_16, Ethernet_32, SPTrEMBL_64, - SPTrEMBL_improved_64, DLT1_64 - }; - enum Generators Generator; - - Generator = CRC_METHODE; - switch (Generator) { - case Tape_16:{ - *ui64RegisterMask = 0x0000ffff; - ui64Generator1 = 0x00008005; - *uiRegisterLength = 16; - break; - } - case Floppy_16:{ - *ui64RegisterMask = 0x0000ffff; - ui64Generator1 = 0x00001021; - *uiRegisterLength = 16; - break; - } - case Ethernet_32:{ - *ui64RegisterMask = 0xffffffff; - ui64Generator1 = 0x04C11DB7; - *uiRegisterLength = 32; - break; - } - case SPTrEMBL_64:{ - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = - ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0x0000001B; - *uiRegisterLength = 64; - break; - } - case SPTrEMBL_improved_64:{ - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = - ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0xAD93D235; - ui64Generator1 = (ui64Generator1 << 32) + 0x94C9362D; - *uiRegisterLength = 64; - break; - } - case DLT1_64:{ - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = - ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0x42F0E1EB; - ui64Generator1 = (ui64Generator1 << 32) + 0xA9EA3693; - *uiRegisterLength = 64; - break; - } - } - (*uiRegisterLength)--; - - return 0; -} - -/** - * Check CRC by using Linear Feadback Shift Register (LFSR) - */ -uint64_t -calCRCbyte(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) -{ - - uint64_t ui64Mask, ui64Generator0; - uint8_t ui8Buffer; - unsigned int uiRegisterLength; - int iShift; - - createCRCParameter(&ui64Mask, &uiRegisterLength); - - ui8Buffer = (*cPtr); - while (ui32NoWords > 0) { - for (iShift = 7; iShift >= 0; iShift--) { - - ui64Generator0 = (AccumCRC >> uiRegisterLength); - AccumCRC <<= 1; - ui64Generator0 &= 0x01; - ui64Generator0 = (0 - ui64Generator0); - AccumCRC ^= (ui64Generator1 & ui64Generator0); - } - AccumCRC ^= ui8Buffer; - AccumCRC &= ui64Mask; - ui32NoWords -= 1; - cPtr += 1; - ui8Buffer = (*cPtr); - } - return AccumCRC; -} - -/** - * Check CRC by using Linear Feadback Shift Register (LFSR) - */ -uint64_t -calCRCword(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) -{ - - uint64_t ui64Mask, ui64Generator0; - uint16_t ui16Buffer; - unsigned int uiRegisterLength; - int iShift; - - createCRCParameter(&ui64Mask, &uiRegisterLength); - - if ((ui32NoWords % 2) != 0) { - /* if Data string does not end at word boundery add one byte */ - ui32NoWords++; - cPtr[ui32NoWords] = 0; - } - ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); - while (ui32NoWords > 0) { - for (iShift = 15; iShift >= 0; iShift--) { - ui64Generator0 = (AccumCRC >> uiRegisterLength); - AccumCRC <<= 1; - ui64Generator0 &= 0x01; - ui64Generator0 = (0 - ui64Generator0); - AccumCRC ^= (ui64Generator1 & ui64Generator0); - } - AccumCRC ^= ui16Buffer; - AccumCRC &= ui64Mask; - ui32NoWords -= 2; - cPtr += 2; - ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); - } - return AccumCRC; -} - -uint64_t -checkCRC(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) -{ - - enum Generators { Ethernet_32 }; - enum Generators Generator; - uint64_t ui64Buffer = AccumCRC; - - Generator = CRC_METHODE; - - switch (Generator) { - case Ethernet_32:{ - /* (ui32NoWords - 4),no need of 4 bytes 0x as - * with shift-register method */ - AccumCRC = - calCRCEthernet32(cPtr, (ui32NoWords - 4), AccumCRC); - break; - } - default:{ - AccumCRC = calCRCword(cPtr, ui32NoWords, AccumCRC); - break; - } - } - - if (calCRCbyte(cPtr, ui32NoWords, ui64Buffer) != AccumCRC) { - printf("\n --- big Endian - small Endian problem --- \n"); - AccumCRC--; - } - - return (AccumCRC); -} - -/** * insert header and file CRC into data stream * do CRC check on header and file * write data stream to disk