]> cvs.zerfleddert.de Git - rsbs2/blob - src/rsb-crc.c
firmware: update for 64bit platforms
[rsbs2] / src / rsb-crc.c
1 #include <stdio.h>
2 #include <stdint.h>
3
4 #define POLY 0x04c11db7
5
6 uint32_t rsb_crc(uint32_t r11_crc, uint8_t *r10_buf, uint32_t r14_len) {
7 uint32_t r6_pos = 0;
8 uint32_t r3_data;
9 int32_t r5_bit;
10
11 while (r6_pos < r14_len) {
12 r3_data = (*(r6_pos+r10_buf)) << 24;
13 r11_crc = r11_crc ^ r3_data;
14
15 r5_bit = 8;
16
17 do {
18 r3_data = r11_crc & 0x80000000;
19
20 if (r3_data != 0) {
21 r3_data = r11_crc << 1;
22 r11_crc = r3_data ^ POLY;
23 } else {
24 r11_crc = r11_crc << 1;
25 }
26 r5_bit--;
27 } while (r5_bit);
28
29 r6_pos++;
30 }
31
32 return r11_crc;
33 }
34
35 uint32_t rsb_crc2(uint8_t *r0_buf, uint32_t r1_buflen, uint32_t r2_magic, uint32_t *crc_out) {
36 uint32_t r4_len;
37 uint32_t file_crc;
38
39 r4_len = *(uint32_t*)(r0_buf + 0x20);
40
41 if (*((uint32_t*)(r0_buf + 0x24)) != r2_magic)
42 return 2; /* MAGIC does not match */
43
44 if (r1_buflen < r4_len)
45 return 3; /* image to small */
46
47 *crc_out = ~rsb_crc(~0x0, r0_buf, r4_len);
48
49 file_crc = *((uint32_t*)(r0_buf + r4_len));
50
51 if (file_crc != *crc_out)
52 return 4;
53
54 return 0;
55 }
Impressum, Datenschutz