diff options
-rw-r--r-- | rbutil/mktccboot/mktccboot.c | 16 | ||||
-rw-r--r-- | rbutil/mktccboot/mktccboot.h | 3 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstalltcc.cpp | 8 | ||||
-rw-r--r-- | tools/telechips.c | 32 | ||||
-rw-r--r-- | tools/telechips.h | 2 |
5 files changed, 55 insertions, 6 deletions
diff --git a/rbutil/mktccboot/mktccboot.c b/rbutil/mktccboot/mktccboot.c index 432bc03213..7103f23895 100644 --- a/rbutil/mktccboot/mktccboot.c +++ b/rbutil/mktccboot/mktccboot.c | |||
@@ -175,6 +175,12 @@ error: | |||
175 | return NULL; | 175 | return NULL; |
176 | } | 176 | } |
177 | 177 | ||
178 | /* A CRC test in order to reject non OF file */ | ||
179 | int test_firmware_tcc(unsigned char* buf, int length) | ||
180 | { | ||
181 | return telechips_test_crc(buf, length); | ||
182 | } | ||
183 | |||
178 | #ifndef LIB | 184 | #ifndef LIB |
179 | int main(int argc, char *argv[]) | 185 | int main(int argc, char *argv[]) |
180 | { | 186 | { |
@@ -185,7 +191,7 @@ int main(int argc, char *argv[]) | |||
185 | unsigned char *boot_buf = NULL; | 191 | unsigned char *boot_buf = NULL; |
186 | unsigned char* image = NULL; | 192 | unsigned char* image = NULL; |
187 | int ret = 0; | 193 | int ret = 0; |
188 | 194 | ||
189 | if(argc < 3) { | 195 | if(argc < 3) { |
190 | usage(); | 196 | usage(); |
191 | } | 197 | } |
@@ -202,6 +208,14 @@ int main(int argc, char *argv[]) | |||
202 | goto error_exit; | 208 | goto error_exit; |
203 | } | 209 | } |
204 | 210 | ||
211 | /* Validate input file */ | ||
212 | if (test_firmware_tcc(of_buf, of_size)) | ||
213 | { | ||
214 | printf("[ERR] Unknown OF file used, aborting\n"); | ||
215 | ret = 2; | ||
216 | goto error_exit; | ||
217 | } | ||
218 | |||
205 | boot_buf = file_read(bootfile, &boot_size); | 219 | boot_buf = file_read(bootfile, &boot_size); |
206 | if (!boot_buf) | 220 | if (!boot_buf) |
207 | { | 221 | { |
diff --git a/rbutil/mktccboot/mktccboot.h b/rbutil/mktccboot/mktccboot.h index 6c6410c258..2df2c54506 100644 --- a/rbutil/mktccboot/mktccboot.h +++ b/rbutil/mktccboot/mktccboot.h | |||
@@ -35,6 +35,9 @@ unsigned char *patch_firmware_tcc(unsigned char *of_buf, int of_size, | |||
35 | 35 | ||
36 | unsigned char *file_read(char *filename, int *size); | 36 | unsigned char *file_read(char *filename, int *size); |
37 | 37 | ||
38 | /* Test TCC firmware file for consistency using CRC test */ | ||
39 | int test_firmware_tcc(unsigned char* buf, int length); | ||
40 | |||
38 | #ifdef __cplusplus | 41 | #ifdef __cplusplus |
39 | }; | 42 | }; |
40 | #endif | 43 | #endif |
diff --git a/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp b/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp index 1d0a9e606e..525421defe 100644 --- a/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstalltcc.cpp | |||
@@ -81,6 +81,14 @@ void BootloaderInstallTcc::installStage2(void) | |||
81 | goto exit; | 81 | goto exit; |
82 | } | 82 | } |
83 | 83 | ||
84 | /* A CRC test in order to reject non OF file */ | ||
85 | if (test_firmware_tcc(of_buf, of_size)) | ||
86 | { | ||
87 | emit logItem(errstr, LOGERROR); | ||
88 | emit logItem(tr("Unknown OF file used: %1").arg(m_offile), LOGERROR); | ||
89 | goto exit; | ||
90 | } | ||
91 | |||
84 | /* Load bootloader file */ | 92 | /* Load bootloader file */ |
85 | boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size); | 93 | boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size); |
86 | if (boot_buf == NULL) | 94 | if (boot_buf == NULL) |
diff --git a/tools/telechips.c b/tools/telechips.c index 8eefffcb98..acb15b8b14 100644 --- a/tools/telechips.c +++ b/tools/telechips.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <fcntl.h> | 31 | #include <fcntl.h> |
32 | #include <stdint.h> | 32 | #include <stdint.h> |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #include <string.h> | ||
34 | 35 | ||
35 | static uint32_t crctable[256]; | 36 | static uint32_t crctable[256]; |
36 | 37 | ||
@@ -57,11 +58,11 @@ static void gentable(uint32_t poly) | |||
57 | { | 58 | { |
58 | int i; | 59 | int i; |
59 | uint32_t r; | 60 | uint32_t r; |
60 | uint32_t index; | 61 | uint32_t idx; |
61 | 62 | ||
62 | for (index = 0; index < 256; index++) | 63 | for (idx = 0; idx < 256; idx++) |
63 | { | 64 | { |
64 | r = bitreverse(index,8) << 24; | 65 | r = bitreverse(idx,8) << 24; |
65 | for (i=0; i<8; i++) | 66 | for (i=0; i<8; i++) |
66 | { | 67 | { |
67 | if (r & (1 << 31)) | 68 | if (r & (1 << 31)) |
@@ -69,7 +70,7 @@ static void gentable(uint32_t poly) | |||
69 | else | 70 | else |
70 | r<<=1; | 71 | r<<=1; |
71 | } | 72 | } |
72 | crctable[index] = bitreverse(r,32); | 73 | crctable[idx] = bitreverse(r,32); |
73 | } | 74 | } |
74 | } | 75 | } |
75 | 76 | ||
@@ -156,3 +157,26 @@ void telechips_encode_crc(unsigned char* buf, int length) | |||
156 | put_uint32le(buf+0x10, crc1); | 157 | put_uint32le(buf+0x10, crc1); |
157 | } | 158 | } |
158 | } | 159 | } |
160 | |||
161 | int telechips_test_crc(unsigned char* buf, int length) | ||
162 | { | ||
163 | uint32_t crc1, crc2, test_crc1, test_crc2; | ||
164 | unsigned char *test_buf; | ||
165 | |||
166 | crc1 = get_uint32le(buf + 0x10); | ||
167 | crc2 = get_uint32le(buf + 0x18); | ||
168 | |||
169 | test_buf = malloc(length); | ||
170 | if (!test_buf) | ||
171 | return 1; | ||
172 | |||
173 | memcpy(test_buf, buf, length); | ||
174 | telechips_encode_crc(test_buf, length); | ||
175 | |||
176 | test_crc1 = get_uint32le(test_buf + 0x10); | ||
177 | test_crc2 = get_uint32le(test_buf + 0x18); | ||
178 | |||
179 | free(test_buf); | ||
180 | |||
181 | return (crc1 == test_crc1 && crc2 == test_crc2) ? 0 : 2; | ||
182 | } | ||
diff --git a/tools/telechips.h b/tools/telechips.h index 27e133b7a6..6550af70d0 100644 --- a/tools/telechips.h +++ b/tools/telechips.h | |||
@@ -24,5 +24,5 @@ | |||
24 | 24 | ||
25 | void telechips_encode_sum(unsigned char* buf, int length); | 25 | void telechips_encode_sum(unsigned char* buf, int length); |
26 | void telechips_encode_crc(unsigned char* buf, int length); | 26 | void telechips_encode_crc(unsigned char* buf, int length); |
27 | 27 | int telechips_test_crc(unsigned char* buf, int length); | |
28 | #endif | 28 | #endif |