diff options
Diffstat (limited to 'tools/scramble.c')
-rw-r--r-- | tools/scramble.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/tools/scramble.c b/tools/scramble.c index 8534d41832..ad128835c5 100644 --- a/tools/scramble.c +++ b/tools/scramble.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "gigabeat.h" | 25 | #include "gigabeat.h" |
26 | #include "gigabeats.h" | 26 | #include "gigabeats.h" |
27 | #include "mi4.h" | 27 | #include "mi4.h" |
28 | #include "telechips.h" | ||
28 | 29 | ||
29 | int iaudio_encode(char *iname, char *oname, char *idstring); | 30 | int iaudio_encode(char *iname, char *oname, char *idstring); |
30 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); | 31 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); |
@@ -102,6 +103,7 @@ void usage(void) | |||
102 | "\t -model=XXXX where XXXX is the model id string\n" | 103 | "\t -model=XXXX where XXXX is the model id string\n" |
103 | "\t -type=XXXX where XXXX is a string indicating the \n" | 104 | "\t -type=XXXX where XXXX is a string indicating the \n" |
104 | "\t type of binary, eg. RBOS, RBBL\n" | 105 | "\t type of binary, eg. RBOS, RBBL\n" |
106 | "\t-tcc=X Telechips generic firmware format (X values: sum, crc)\n" | ||
105 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" | 107 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" |
106 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n" | 108 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n" |
107 | "\t ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2,\n" | 109 | "\t ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2,\n" |
@@ -127,7 +129,7 @@ int main (int argc, char** argv) | |||
127 | unsigned long modelnum; | 129 | unsigned long modelnum; |
128 | char modelname[5]; | 130 | char modelname[5]; |
129 | int model_id; | 131 | int model_id; |
130 | enum { none, scramble, xor, add } method = scramble; | 132 | enum { none, scramble, xor, tcc_sum, tcc_crc, add } method = scramble; |
131 | 133 | ||
132 | model_id = ARCHOS_PLAYER; | 134 | model_id = ARCHOS_PLAYER; |
133 | 135 | ||
@@ -186,6 +188,20 @@ int main (int argc, char** argv) | |||
186 | return -1; | 188 | return -1; |
187 | } | 189 | } |
188 | } | 190 | } |
191 | else if(!strncmp(argv[1], "-tcc=", 4)) { | ||
192 | headerlen = 0; | ||
193 | iname = argv[2]; | ||
194 | oname = argv[3]; | ||
195 | |||
196 | if(!strcmp(&argv[1][5], "sum")) | ||
197 | method = tcc_sum; | ||
198 | else if(!strcmp(&argv[1][5], "crc")) | ||
199 | method = tcc_crc; | ||
200 | else { | ||
201 | fprintf(stderr, "unsupported TCC method: %s\n", &argv[1][5]); | ||
202 | return 2; | ||
203 | } | ||
204 | } | ||
189 | else if(!strncmp(argv[1], "-add=", 5)) { | 205 | else if(!strncmp(argv[1], "-add=", 5)) { |
190 | iname = argv[2]; | 206 | iname = argv[2]; |
191 | oname = argv[3]; | 207 | oname = argv[3]; |
@@ -409,7 +425,7 @@ int main (int argc, char** argv) | |||
409 | break; | 425 | break; |
410 | } | 426 | } |
411 | 427 | ||
412 | if(method != add) { | 428 | if((method == none) || (method == scramble) || (method == xor)) { |
413 | /* calculate checksum */ | 429 | /* calculate checksum */ |
414 | for (i=0;i<length;i++) | 430 | for (i=0;i<length;i++) |
415 | crc += inbuf[i]; | 431 | crc += inbuf[i]; |
@@ -426,6 +442,17 @@ int main (int argc, char** argv) | |||
426 | headerlen = 8; | 442 | headerlen = 8; |
427 | } | 443 | } |
428 | break; | 444 | break; |
445 | |||
446 | case tcc_sum: | ||
447 | memcpy(outbuf, inbuf, length); /* the input buffer to output*/ | ||
448 | telechips_encode_sum(outbuf, length); | ||
449 | break; | ||
450 | |||
451 | case tcc_crc: | ||
452 | memcpy(outbuf, inbuf, length); /* the input buffer to output*/ | ||
453 | telechips_encode_crc(outbuf, length); | ||
454 | break; | ||
455 | |||
429 | case scramble: | 456 | case scramble: |
430 | if (headerlen == 6) { | 457 | if (headerlen == 6) { |
431 | int2be(length, header); | 458 | int2be(length, header); |
@@ -488,9 +515,11 @@ int main (int argc, char** argv) | |||
488 | perror(oname); | 515 | perror(oname); |
489 | return -1; | 516 | return -1; |
490 | } | 517 | } |
491 | if ( !fwrite(header,headerlen,1,file) ) { | 518 | if (headerlen > 0) { |
492 | perror(oname); | 519 | if ( !fwrite(header,headerlen,1,file) ) { |
493 | return -1; | 520 | perror(oname); |
521 | return -1; | ||
522 | } | ||
494 | } | 523 | } |
495 | if ( !fwrite(outbuf,length,1,file) ) { | 524 | if ( !fwrite(outbuf,length,1,file) ) { |
496 | perror(oname); | 525 | perror(oname); |