FreeCalypso > hg > freecalypso-sw
comparison stashaway/mkcrc32tab.c @ 33:8fbd52a639a5
CRC-32 table, will be used for flash dump integrity checks
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 04 May 2013 08:33:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
32:9a77b3395747 | 33:8fbd52a639a5 |
---|---|
1 /* | |
2 * This program generates the CRC-32 table for the LSB-first direction. | |
3 * Derived from the MSB-first version written years earlier by the | |
4 * same author (Michael Spacefalcon) for SDSL/ATM AAL5. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 | |
10 u_long table[256]; | |
11 | |
12 main(argc, argv) | |
13 char **argv; | |
14 { | |
15 build_table(); | |
16 emit_table(); | |
17 exit(0); | |
18 } | |
19 | |
20 u_long | |
21 crc_byte(crc, inb) | |
22 u_long crc; | |
23 int inb; | |
24 { | |
25 register int bit; | |
26 | |
27 crc ^= inb & 0xFF; | |
28 for (bit = 0; bit < 8; bit++) { | |
29 if (crc & 1) | |
30 crc = (crc >> 1) ^ 0xEDB88320; | |
31 else | |
32 crc >>= 1; | |
33 } | |
34 return(crc); | |
35 } | |
36 | |
37 build_table() | |
38 { | |
39 int i; | |
40 | |
41 for (i = 0; i < 256; i++) | |
42 table[i] = crc_byte(0, i); | |
43 } | |
44 | |
45 emit_table() | |
46 { | |
47 int i, j, idx; | |
48 | |
49 printf("unsigned long crc32_table[256] = {\n"); | |
50 for (i = 0, idx = 0; i < 64; i++) { | |
51 putchar('\t'); | |
52 for (j = 0; j < 4; j++, idx++) | |
53 printf("0x%08X,%c", table[idx], j==3 ? '\n' : ' '); | |
54 } | |
55 printf("};\n"); | |
56 } |