]>
Commit | Line | Data |
---|---|---|
6fc57dcd | 1 | #include <stdio.h> |
7215c018 | 2 | #include <stdint.h> |
6fc57dcd | 3 | |
972ac24b MG |
4 | #define POLY 0x04c11db7 |
5 | ||
7215c018 MG |
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; | |
972ac24b | 10 | |
c8b1eccb MG |
11 | while (r6_pos < r14_len) { |
12 | r3_data = (*(r6_pos+r10_buf)) << 24; | |
13 | r11_crc = r11_crc ^ r3_data; | |
972ac24b | 14 | |
c8b1eccb | 15 | r5_bit = 8; |
972ac24b MG |
16 | |
17 | do { | |
c8b1eccb | 18 | r3_data = r11_crc & 0x80000000; |
972ac24b | 19 | |
c8b1eccb MG |
20 | if (r3_data != 0) { |
21 | r3_data = r11_crc << 1; | |
22 | r11_crc = r3_data ^ POLY; | |
972ac24b | 23 | } else { |
c8b1eccb | 24 | r11_crc = r11_crc << 1; |
972ac24b | 25 | } |
c8b1eccb MG |
26 | r5_bit--; |
27 | } while (r5_bit); | |
972ac24b | 28 | |
c8b1eccb | 29 | r6_pos++; |
972ac24b MG |
30 | } |
31 | ||
c8b1eccb | 32 | return r11_crc; |
972ac24b | 33 | } |
6fc57dcd | 34 | |
7215c018 MG |
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; | |
6fc57dcd | 38 | |
7215c018 | 39 | r4_len = *(uint32_t*)(r0_buf + 0x20); |
6fc57dcd | 40 | |
7215c018 | 41 | if (*((uint32_t*)(r0_buf + 0x24)) != r2_magic) |
85feabf9 | 42 | return 2; /* MAGIC does not match */ |
6fc57dcd | 43 | |
85feabf9 MG |
44 | if (r1_buflen < r4_len) |
45 | return 3; /* image to small */ | |
6fc57dcd | 46 | |
a4019508 | 47 | *crc_out = ~rsb_crc(~0x0, r0_buf, r4_len); |
6fc57dcd | 48 | |
7215c018 | 49 | file_crc = *((uint32_t*)(r0_buf + r4_len)); |
6fc57dcd | 50 | |
a4019508 | 51 | if (file_crc != *crc_out) |
01004d01 | 52 | return 4; |
6fc57dcd | 53 | |
01004d01 | 54 | return 0; |
6fc57dcd | 55 | } |