diff options
| author | Dave Chapman <dave@dchapman.com> | 2007-09-30 12:49:43 +0000 |
|---|---|---|
| committer | Dave Chapman <dave@dchapman.com> | 2007-09-30 12:49:43 +0000 |
| commit | 41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f (patch) | |
| tree | a57742b5bb57f6b9d5cd5700601fcf9e22ebebf7 /tools/scramble.c | |
| parent | 0f5d9f9125e53ae62175469e78151ca4cb0be79a (diff) | |
| download | rockbox-41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f.zip rockbox-41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f.tar.gz rockbox-41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f.tar.bz2 rockbox-41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f.tar.xz | |
Add support for the generic Telechips firmware format checksums - use -tcc=sum if the header just contains a single checksum, or -tcc=crc if the header contains two 32-bit CRCs. Credit goes to Hein-Pieter van Braam for his work on identifying the (reverse) CRC32 algorithm used when calculating the two CRCs
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14917 a1c6a512-1295-4272-9138-f99709370657
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 8534d41..ad12883 100644 --- a/tools/scramble.c +++ b/tools/scramble.c @@ -25,6 +25,7 @@ #include "gigabeat.h" #include "gigabeats.h" #include "mi4.h" +#include "telechips.h" int iaudio_encode(char *iname, char *oname, char *idstring); int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); @@ -102,6 +103,7 @@ void usage(void) "\t -model=XXXX where XXXX is the model id string\n" "\t -type=XXXX where XXXX is a string indicating the \n" "\t type of binary, eg. RBOS, RBBL\n" + "\t-tcc=X Telechips generic firmware format (X values: sum, crc)\n" "\t-add=X Rockbox generic \"add-up\" checksum format\n" "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n" "\t ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2,\n" @@ -127,7 +129,7 @@ int main (int argc, char** argv) unsigned long modelnum; char modelname[5]; int model_id; - enum { none, scramble, xor, add } method = scramble; + enum { none, scramble, xor, tcc_sum, tcc_crc, add } method = scramble; model_id = ARCHOS_PLAYER; @@ -186,6 +188,20 @@ int main (int argc, char** argv) return -1; } } + else if(!strncmp(argv[1], "-tcc=", 4)) { + headerlen = 0; + iname = argv[2]; + oname = argv[3]; + + if(!strcmp(&argv[1][5], "sum")) + method = tcc_sum; + else if(!strcmp(&argv[1][5], "crc")) + method = tcc_crc; + else { + fprintf(stderr, "unsupported TCC method: %s\n", &argv[1][5]); + return 2; + } + } else if(!strncmp(argv[1], "-add=", 5)) { iname = argv[2]; oname = argv[3]; @@ -409,7 +425,7 @@ int main (int argc, char** argv) break; } - if(method != add) { + if((method == none) || (method == scramble) || (method == xor)) { /* calculate checksum */ for (i=0;i<length;i++) crc += inbuf[i]; @@ -426,6 +442,17 @@ int main (int argc, char** argv) headerlen = 8; } break; + + case tcc_sum: + memcpy(outbuf, inbuf, length); /* the input buffer to output*/ + telechips_encode_sum(outbuf, length); + break; + + case tcc_crc: + memcpy(outbuf, inbuf, length); /* the input buffer to output*/ + telechips_encode_crc(outbuf, length); + break; + case scramble: if (headerlen == 6) { int2be(length, header); @@ -488,9 +515,11 @@ int main (int argc, char** argv) perror(oname); return -1; } - if ( !fwrite(header,headerlen,1,file) ) { - perror(oname); - return -1; + if (headerlen > 0) { + if ( !fwrite(header,headerlen,1,file) ) { + perror(oname); + return -1; + } } if ( !fwrite(outbuf,length,1,file) ) { perror(oname); |