annotate stashaway/mkcrc32tab.c @ 616:4d40f9a99445

gsm-fw/L1/stand: plan to use L1IF forwarder entity
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 30 Aug 2014 22:52:35 +0000
parents 8fbd52a639a5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program generates the CRC-32 table for the LSB-first direction.
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * Derived from the MSB-first version written years earlier by the
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * same author (Michael Spacefalcon) for SDSL/ATM AAL5.
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/types.h>
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 u_long table[256];
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 main(argc, argv)
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 char **argv;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 build_table();
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 emit_table();
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 exit(0);
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 }
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 u_long
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 crc_byte(crc, inb)
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 u_long crc;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 int inb;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 register int bit;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 crc ^= inb & 0xFF;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 for (bit = 0; bit < 8; bit++) {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 if (crc & 1)
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 crc = (crc >> 1) ^ 0xEDB88320;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 else
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 crc >>= 1;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 }
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 return(crc);
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 build_table()
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 int i;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 for (i = 0; i < 256; i++)
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 table[i] = crc_byte(0, i);
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 emit_table()
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 int i, j, idx;
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 printf("unsigned long crc32_table[256] = {\n");
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 for (i = 0, idx = 0; i < 64; i++) {
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 putchar('\t');
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 for (j = 0; j < 4; j++, idx++)
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 printf("0x%08X,%c", table[idx], j==3 ? '\n' : ' ');
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 }
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 printf("};\n");
8fbd52a639a5 CRC-32 table, will be used for flash dump integrity checks
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }