forked from len0rd/rockbox
Added the "--add=[model]" option for upcoming iRiver work. Rockbox for iRiver
will not be scrambled, only have a 8 bytes header for checksum and model name. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5650 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
adaae249ef
commit
bf355b70b9
1 changed files with 58 additions and 5 deletions
|
@ -49,6 +49,8 @@ void usage(void)
|
||||||
"\t-neo SSI Neo format\n"
|
"\t-neo SSI Neo format\n"
|
||||||
"\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n"
|
"\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n"
|
||||||
"\t-iriver iRiver format\n"
|
"\t-iriver iRiver format\n"
|
||||||
|
"\t-add=X Rockbox iRiver \"add-up\" checksum format\n"
|
||||||
|
"\t (X values: h100, h120, h140, h300)\n"
|
||||||
"\nNo option results in Archos standard player/recorder format.\n");
|
"\nNo option results in Archos standard player/recorder format.\n");
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -59,6 +61,7 @@ int main (int argc, char** argv)
|
||||||
unsigned long length,i,slen;
|
unsigned long length,i,slen;
|
||||||
unsigned char *inbuf,*outbuf;
|
unsigned char *inbuf,*outbuf;
|
||||||
unsigned short crc=0;
|
unsigned short crc=0;
|
||||||
|
unsigned long crc32=0; /* 32 bit checksum */
|
||||||
unsigned char header[24];
|
unsigned char header[24];
|
||||||
unsigned char *iname = argv[1];
|
unsigned char *iname = argv[1];
|
||||||
unsigned char *oname = argv[2];
|
unsigned char *oname = argv[2];
|
||||||
|
@ -66,7 +69,9 @@ int main (int argc, char** argv)
|
||||||
int headerlen = 6;
|
int headerlen = 6;
|
||||||
FILE* file;
|
FILE* file;
|
||||||
int version;
|
int version;
|
||||||
enum { none, scramble, xor } method = scramble;
|
unsigned long irivernum;
|
||||||
|
char irivermodel[5];
|
||||||
|
enum { none, scramble, xor, add } method = scramble;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
usage();
|
usage();
|
||||||
|
@ -119,6 +124,29 @@ int main (int argc, char** argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(!strncmp(argv[1], "-add=", 5)) {
|
||||||
|
iname = argv[2];
|
||||||
|
oname = argv[3];
|
||||||
|
method = add;
|
||||||
|
|
||||||
|
if(!strcmp(&argv[1][5], "h120"))
|
||||||
|
irivernum = 0;
|
||||||
|
else if(!strcmp(&argv[1][5], "h140"))
|
||||||
|
irivernum = 0; /* the same as the h120 */
|
||||||
|
else if(!strcmp(&argv[1][5], "h140"))
|
||||||
|
irivernum = 0; /* the same as the h120 */
|
||||||
|
else if(!strcmp(&argv[1][5], "h100"))
|
||||||
|
irivernum = 1;
|
||||||
|
else if(!strcmp(&argv[1][5], "h300"))
|
||||||
|
irivernum = 2;
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "unsupported model: %s\n", &argv[1][5]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
/* we store a 4-letter model name too, for humans */
|
||||||
|
strcpy(irivermodel, &argv[1][5]);
|
||||||
|
crc32 = irivernum; /* start checksum calcs with this */
|
||||||
|
}
|
||||||
|
|
||||||
else if(!strcmp(argv[1], "-iriver")) {
|
else if(!strcmp(argv[1], "-iriver")) {
|
||||||
/* iRiver code dealt with in the iriver.c code */
|
/* iRiver code dealt with in the iriver.c code */
|
||||||
|
@ -148,12 +176,19 @@ int main (int argc, char** argv)
|
||||||
inbuf = malloc(length);
|
inbuf = malloc(length);
|
||||||
if (method == xor)
|
if (method == xor)
|
||||||
outbuf = malloc(length*2);
|
outbuf = malloc(length*2);
|
||||||
|
else if(method == add)
|
||||||
|
outbuf = malloc(length + 8);
|
||||||
else
|
else
|
||||||
outbuf = malloc(length);
|
outbuf = malloc(length);
|
||||||
if ( !inbuf || !outbuf ) {
|
if ( !inbuf || !outbuf ) {
|
||||||
printf("out of memory!\n");
|
printf("out of memory!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if(length> 4) {
|
||||||
|
/* zero-fill the last 4 bytes to make sure there's no rubbish there
|
||||||
|
when we write the size-aligned file later */
|
||||||
|
memset(outbuf+length-4, 0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
/* read file */
|
/* read file */
|
||||||
i=fread(inbuf,1,length,file);
|
i=fread(inbuf,1,length,file);
|
||||||
|
@ -165,6 +200,13 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
|
case add:
|
||||||
|
for (i = 0; i < length/2; i++) {
|
||||||
|
unsigned short *inbuf16 = (unsigned short *)inbuf;
|
||||||
|
/* add 16 unsigned bits but keep a 32 bit sum */
|
||||||
|
crc32 += inbuf16[i];
|
||||||
|
}
|
||||||
|
break;
|
||||||
case scramble:
|
case scramble:
|
||||||
slen = length/4;
|
slen = length/4;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
|
@ -186,13 +228,24 @@ int main (int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate checksum */
|
if(method != add) {
|
||||||
for (i=0;i<length;i++)
|
/* calculate checksum */
|
||||||
crc += inbuf[i];
|
for (i=0;i<length;i++)
|
||||||
|
crc += inbuf[i];
|
||||||
|
}
|
||||||
|
|
||||||
memset(header, 0, sizeof header);
|
memset(header, 0, sizeof header);
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
|
case add:
|
||||||
|
{
|
||||||
|
unsigned long *headp = (unsigned long *)header;
|
||||||
|
headp[0] = crc32; /* checksum */
|
||||||
|
memcpy(&header[4], irivermodel, 4); /* 4 bytes model name */
|
||||||
|
memcpy(outbuf, inbuf, length); /* the input buffer to output*/
|
||||||
|
headerlen = 8;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case scramble:
|
case scramble:
|
||||||
if (headerlen == 6) {
|
if (headerlen == 6) {
|
||||||
int2be(length, header);
|
int2be(length, header);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue