1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2003 Jörg Hohensohn [IDC]Dragon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 /* Code copied from firmware_flash plugin. */
22 /* Tool function to calculate a CRC32 across some buffer */
23 /* third argument is either 0xFFFFFFFF to start or value from last piece */
24 unsigned crc_32(const void *src
, unsigned len
, unsigned crc32
)
26 const unsigned char *buf
= (const unsigned char *)src
;
28 /* CCITT standard polynomial 0x04C11DB7 */
29 static const unsigned crc32_lookup
[16] =
30 { /* lookup table for 4 bits at a time is affordable */
31 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
32 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
33 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
34 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD
42 byte
= *buf
++; /* get one byte of data */
44 /* upper nibble of our data */
45 t
= crc32
>> 28; /* extract the 4 most significant bits */
46 t
^= byte
>> 4; /* XOR in 4 bits of data into the extracted bits */
47 crc32
<<= 4; /* shift the CRC register left 4 bits */
48 crc32
^= crc32_lookup
[t
]; /* do the table lookup and XOR the result */
50 /* lower nibble of our data */
51 t
= crc32
>> 28; /* extract the 4 most significant bits */
52 t
^= byte
& 0x0F; /* XOR in 4 bits of data into the extracted bits */
53 crc32
<<= 4; /* shift the CRC register left 4 bits */
54 crc32
^= crc32_lookup
[t
]; /* do the table lookup and XOR the result */