A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

FS#10740 - rbutil: Test Cowon D2 OF file for CRC consistency before patching

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23470 a1c6a512-1295-4272-9138-f99709370657

+55 -6
+15 -1
rbutil/mktccboot/mktccboot.c
··· 175 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 184 #ifndef LIB 179 185 int main(int argc, char *argv[]) 180 186 { ··· 185 191 unsigned char *boot_buf = NULL; 186 192 unsigned char* image = NULL; 187 193 int ret = 0; 188 - 194 + 189 195 if(argc < 3) { 190 196 usage(); 191 197 } ··· 199 205 if (!of_buf) 200 206 { 201 207 ret = 1; 208 + goto error_exit; 209 + } 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; 202 216 goto error_exit; 203 217 } 204 218
+3
rbutil/mktccboot/mktccboot.h
··· 35 35 36 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 41 #ifdef __cplusplus 39 42 }; 40 43 #endif
+8
rbutil/rbutilqt/base/bootloaderinstalltcc.cpp
··· 81 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 92 /* Load bootloader file */ 85 93 boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size); 86 94 if (boot_buf == NULL)
+28 -4
tools/telechips.c
··· 31 31 #include <fcntl.h> 32 32 #include <stdint.h> 33 33 #include <stdlib.h> 34 + #include <string.h> 34 35 35 36 static uint32_t crctable[256]; 36 37 ··· 57 58 { 58 59 int i; 59 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 66 for (i=0; i<8; i++) 66 67 { 67 68 if (r & (1 << 31)) ··· 69 70 else 70 71 r<<=1; 71 72 } 72 - crctable[index] = bitreverse(r,32); 73 + crctable[idx] = bitreverse(r,32); 73 74 } 74 75 } 75 76 ··· 156 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 + }
+1 -1
tools/telechips.h
··· 24 24 25 25 void telechips_encode_sum(unsigned char* buf, int length); 26 26 void telechips_encode_crc(unsigned char* buf, int length); 27 - 27 + int telechips_test_crc(unsigned char* buf, int length); 28 28 #endif