1
0
Fork 0
forked from len0rd/rockbox

removed the neo-specific scramble-tool and made it an option to scramble

instead, and made the makefile use this


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4140 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2003-12-12 14:07:28 +00:00
parent d0f5910534
commit 0115af21d9
3 changed files with 62 additions and 147 deletions

View file

@ -31,6 +31,9 @@ AFLAGS += -small -relax
# Check if this is a kind of Recorder # Check if this is a kind of Recorder
ANYREC = $(findstring RECORDER, $(TARGET)) ANYREC = $(findstring RECORDER, $(TARGET))
# scramble tool
TOOL = scramble
ifndef MEM ifndef MEM
# if MEM is not set, assume 2MB # if MEM is not set, assume 2MB
MEM=2 MEM=2
@ -56,19 +59,17 @@ ifeq ($(ANYREC), RECORDER)
SRC += $(wildcard recorder/*.c) SRC += $(wildcard recorder/*.c)
CFLAGS += -Irecorder CFLAGS += -Irecorder
OUTNAME = ajbrec.ajz OUTNAME = ajbrec.ajz
TOOL = scramble
else else
ifeq ($(TARGET), -DARCHOS_PLAYER) ifeq ($(TARGET), -DARCHOS_PLAYER)
SRC += $(wildcard player/*.c) SRC += $(wildcard player/*.c)
CFLAGS += -Iplayer CFLAGS += -Iplayer
OUTNAME = archos.mod OUTNAME = archos.mod
TOOL = scramble
else else
# some kind of Neo # some kind of Neo
SRC += $(wildcard neo/*.c) SRC += $(wildcard neo/*.c)
CFLAGS += -Ineo CFLAGS += -Ineo
OUTNAME = Rockbox.bin OUTNAME = Rockbox.bin
TOOL = mkneofile TOOL_OPT = -neo
endif endif
endif endif

View file

@ -1,112 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2003 by Open Neo
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define MY_FIRMWARE_TYPE "Rockbox"
#define MY_HEADER_VERSION 1
int main (int argc, char** argv)
{
unsigned long length,i,slen;
unsigned char *inbuf;
unsigned short checksum=0;
unsigned char *iname = argv[1];
unsigned char *oname = argv[2];
unsigned char header[17];
FILE* file;
if (argc < 3) {
printf("usage: %s <input file> <output file>\n",argv[0]);
return -1;
}
/* open file */
file = fopen(iname,"rb");
if (!file) {
perror(iname);
return -1;
}
fseek(file,0,SEEK_END);
length = ftell(file);
length = (length + 3) & ~3; /* Round up to nearest 4 byte boundary */
if (length >= 0x32000) {
printf("error: max firmware size is 200KB!\n");
fclose(file);
return -1;
}
fseek(file,0,SEEK_SET);
inbuf = malloc(length);
if ( !inbuf ) {
printf("out of memory!\n");
return -1;
}
/* read file */
i=fread(inbuf,1,length,file);
if ( !i ) {
perror(iname);
return -1;
}
fclose(file);
/* calculate checksum */
for (i=0;i<length;i++)
checksum+=inbuf[i];
/* make header */
memset(header, 0, sizeof(header));
strncpy(header,MY_FIRMWARE_TYPE,9);
header[9]='\0'; /*shouldn't have to, but to be SURE */
header[10]=MY_HEADER_VERSION&0xFF;
header[11]=(checksum>>8)&0xFF;
header[12]=checksum&0xFF;
header[13]=(sizeof(header)>>24)&0xFF;
header[14]=(sizeof(header)>>16)&0xFF;
header[15]=(sizeof(header)>>8)&0xFF;
header[16]=sizeof(header)&0xFF;
/* write file */
file = fopen(oname,"wb");
if ( !file ) {
perror(oname);
return -1;
}
if ( !fwrite(header,sizeof(header),1,file) ) {
perror(oname);
return -1;
}
if ( !fwrite(inbuf,length,1,file) ) {
perror(oname);
return -1;
}
fclose(file);
free(inbuf);
printf("\r\nHeader Info:\r\n\t"
"Header Type:\t\t%s\r\n\t"
"Header Version:\t\t%d\r\n\t"
"Header Checksum:\t0x%x\r\n\t"
"Data Start:\t\t0x%x\r\n\r\n",
header,header[10],checksum,sizeof(header));
return 0;
}

View file

@ -31,9 +31,10 @@ int main (int argc, char** argv)
int headerlen = 6; int headerlen = 6;
FILE* file; FILE* file;
int version; int version;
int scramble=1;
if (argc < 3) { if (argc < 3) {
printf("usage: %s [-fm] [-v2] <input file> <output file>\n",argv[0]); printf("usage: %s [-fm] [-v2] [-neo]<input file> <output file>\n",argv[0]);
return -1; return -1;
} }
@ -44,13 +45,21 @@ int main (int argc, char** argv)
version = 4; version = 4;
} }
if(!strcmp(argv[1], "-v2")) { else if(!strcmp(argv[1], "-v2")) {
headerlen = 24; headerlen = 24;
iname = argv[2]; iname = argv[2];
oname = argv[3]; oname = argv[3];
version = 2; version = 2;
} }
else if(!strcmp(argv[1], "-neo")) {
headerlen = 17;
iname = argv[2];
oname = argv[3];
scramble = 0;
}
/* open file */ /* open file */
file = fopen(iname,"rb"); file = fopen(iname,"rb");
if (!file) { if (!file) {
@ -83,46 +92,63 @@ int main (int argc, char** argv)
} }
fclose(file); fclose(file);
/* scramble */ if(scramble) {
slen = length/4; /* scramble */
for (i = 0; i < length; i++) { slen = length/4;
unsigned long addr = (i >> 2) + ((i % 4) * slen); for (i = 0; i < length; i++) {
unsigned char data = inbuf[i]; unsigned long addr = (i >> 2) + ((i % 4) * slen);
data = ~((data << 1) | ((data >> 7) & 1)); /* poor man's ROL */ unsigned char data = inbuf[i];
outbuf[addr] = data; data = ~((data << 1) | ((data >> 7) & 1)); /* poor man's ROL */
outbuf[addr] = data;
}
} }
/* calculate checksum */ /* calculate checksum */
for (i=0;i<length;i++) for (i=0;i<length;i++)
crc += inbuf[i]; crc += inbuf[i];
/* make header */
memset(header, 0, sizeof header); memset(header, 0, sizeof header);
if (headerlen == 6) { if(scramble) {
header[0] = (length >> 24) & 0xff; if (headerlen == 6) {
header[1] = (length >> 16) & 0xff; header[0] = (length >> 24) & 0xff;
header[2] = (length >> 8) & 0xff; header[1] = (length >> 16) & 0xff;
header[3] = length & 0xff; header[2] = (length >> 8) & 0xff;
header[4] = (crc >> 8) & 0xff; header[3] = length & 0xff;
header[5] = crc & 0xff; header[4] = (crc >> 8) & 0xff;
header[5] = crc & 0xff;
}
else {
header[0] =
header[1] =
header[2] =
header[3] = 0xff; /* ??? */
header[6] = (crc >> 8) & 0xff;
header[7] = crc & 0xff;
header[11] = version;
header[15] = headerlen; /* really? */
header[20] = (length >> 24) & 0xff;
header[21] = (length >> 16) & 0xff;
header[22] = (length >> 8) & 0xff;
header[23] = length & 0xff;
}
} }
else { else {
header[0] = #define MY_FIRMWARE_TYPE "Rockbox"
header[1] = #define MY_HEADER_VERSION 1
header[2] =
header[3] = 0xff; /* ??? */
header[6] = (crc >> 8) & 0xff; strncpy(header,MY_FIRMWARE_TYPE,9);
header[7] = crc & 0xff; header[9]='\0'; /*shouldn't have to, but to be SURE */
header[10]=MY_HEADER_VERSION&0xFF;
header[11] = version; header[11]=(crc>>8)&0xFF;
header[12]=crc&0xFF;
header[15] = headerlen; /* really? */ header[13]=(sizeof(header)>>24)&0xFF;
header[14]=(sizeof(header)>>16)&0xFF;
header[20] = (length >> 24) & 0xff; header[15]=(sizeof(header)>>8)&0xFF;
header[21] = (length >> 16) & 0xff; header[16]=sizeof(header)&0xFF;
header[22] = (length >> 8) & 0xff;
header[23] = length & 0xff;
} }
/* write file */ /* write file */