summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-12-12 14:07:28 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-12-12 14:07:28 +0000
commit0115af21d9badaab2fdb7e2404bea69a0504e4b0 (patch)
treed776d31422a5c978f9c9db5f046781c2c902f0f3
parentd0f59105348bfb2d29596ff65b41a3aaeea86432 (diff)
downloadrockbox-0115af21d9badaab2fdb7e2404bea69a0504e4b0.tar.gz
rockbox-0115af21d9badaab2fdb7e2404bea69a0504e4b0.zip
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
-rw-r--r--apps/Makefile7
-rw-r--r--tools/mkneofile.c112
-rw-r--r--tools/scramble.c88
3 files changed, 61 insertions, 146 deletions
diff --git a/apps/Makefile b/apps/Makefile
index bb7625b1c2..2fc9d97adb 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -31,6 +31,9 @@ AFLAGS += -small -relax
31# Check if this is a kind of Recorder 31# Check if this is a kind of Recorder
32ANYREC = $(findstring RECORDER, $(TARGET)) 32ANYREC = $(findstring RECORDER, $(TARGET))
33 33
34# scramble tool
35TOOL = scramble
36
34ifndef MEM 37ifndef MEM
35 # if MEM is not set, assume 2MB 38 # if MEM is not set, assume 2MB
36 MEM=2 39 MEM=2
@@ -56,19 +59,17 @@ ifeq ($(ANYREC), RECORDER)
56 SRC += $(wildcard recorder/*.c) 59 SRC += $(wildcard recorder/*.c)
57 CFLAGS += -Irecorder 60 CFLAGS += -Irecorder
58 OUTNAME = ajbrec.ajz 61 OUTNAME = ajbrec.ajz
59 TOOL = scramble
60else 62else
61ifeq ($(TARGET), -DARCHOS_PLAYER) 63ifeq ($(TARGET), -DARCHOS_PLAYER)
62 SRC += $(wildcard player/*.c) 64 SRC += $(wildcard player/*.c)
63 CFLAGS += -Iplayer 65 CFLAGS += -Iplayer
64 OUTNAME = archos.mod 66 OUTNAME = archos.mod
65 TOOL = scramble
66else 67else
67# some kind of Neo 68# some kind of Neo
68 SRC += $(wildcard neo/*.c) 69 SRC += $(wildcard neo/*.c)
69 CFLAGS += -Ineo 70 CFLAGS += -Ineo
70 OUTNAME = Rockbox.bin 71 OUTNAME = Rockbox.bin
71 TOOL = mkneofile 72 TOOL_OPT = -neo
72endif 73endif
73endif 74endif
74 75
diff --git a/tools/mkneofile.c b/tools/mkneofile.c
deleted file mode 100644
index 93e0d45043..0000000000
--- a/tools/mkneofile.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 by Open Neo
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <stdlib.h>
21
22#define MY_FIRMWARE_TYPE "Rockbox"
23#define MY_HEADER_VERSION 1
24
25int main (int argc, char** argv)
26{
27 unsigned long length,i,slen;
28 unsigned char *inbuf;
29 unsigned short checksum=0;
30 unsigned char *iname = argv[1];
31 unsigned char *oname = argv[2];
32 unsigned char header[17];
33 FILE* file;
34
35 if (argc < 3) {
36 printf("usage: %s <input file> <output file>\n",argv[0]);
37 return -1;
38 }
39
40 /* open file */
41 file = fopen(iname,"rb");
42 if (!file) {
43 perror(iname);
44 return -1;
45 }
46 fseek(file,0,SEEK_END);
47 length = ftell(file);
48 length = (length + 3) & ~3; /* Round up to nearest 4 byte boundary */
49
50 if (length >= 0x32000) {
51 printf("error: max firmware size is 200KB!\n");
52 fclose(file);
53 return -1;
54 }
55
56 fseek(file,0,SEEK_SET);
57 inbuf = malloc(length);
58 if ( !inbuf ) {
59 printf("out of memory!\n");
60 return -1;
61 }
62
63 /* read file */
64 i=fread(inbuf,1,length,file);
65 if ( !i ) {
66 perror(iname);
67 return -1;
68 }
69 fclose(file);
70
71 /* calculate checksum */
72 for (i=0;i<length;i++)
73 checksum+=inbuf[i];
74
75 /* make header */
76 memset(header, 0, sizeof(header));
77 strncpy(header,MY_FIRMWARE_TYPE,9);
78 header[9]='\0'; /*shouldn't have to, but to be SURE */
79 header[10]=MY_HEADER_VERSION&0xFF;
80 header[11]=(checksum>>8)&0xFF;
81 header[12]=checksum&0xFF;
82 header[13]=(sizeof(header)>>24)&0xFF;
83 header[14]=(sizeof(header)>>16)&0xFF;
84 header[15]=(sizeof(header)>>8)&0xFF;
85 header[16]=sizeof(header)&0xFF;
86
87 /* write file */
88 file = fopen(oname,"wb");
89 if ( !file ) {
90 perror(oname);
91 return -1;
92 }
93 if ( !fwrite(header,sizeof(header),1,file) ) {
94 perror(oname);
95 return -1;
96 }
97 if ( !fwrite(inbuf,length,1,file) ) {
98 perror(oname);
99 return -1;
100 }
101 fclose(file);
102
103 free(inbuf);
104
105 printf("\r\nHeader Info:\r\n\t"
106 "Header Type:\t\t%s\r\n\t"
107 "Header Version:\t\t%d\r\n\t"
108 "Header Checksum:\t0x%x\r\n\t"
109 "Data Start:\t\t0x%x\r\n\r\n",
110 header,header[10],checksum,sizeof(header));
111 return 0;
112}
diff --git a/tools/scramble.c b/tools/scramble.c
index 95709c0618..0021bcacaa 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -31,9 +31,10 @@ int main (int argc, char** argv)
31 int headerlen = 6; 31 int headerlen = 6;
32 FILE* file; 32 FILE* file;
33 int version; 33 int version;
34 int scramble=1;
34 35
35 if (argc < 3) { 36 if (argc < 3) {
36 printf("usage: %s [-fm] [-v2] <input file> <output file>\n",argv[0]); 37 printf("usage: %s [-fm] [-v2] [-neo]<input file> <output file>\n",argv[0]);
37 return -1; 38 return -1;
38 } 39 }
39 40
@@ -44,12 +45,20 @@ int main (int argc, char** argv)
44 version = 4; 45 version = 4;
45 } 46 }
46 47
47 if(!strcmp(argv[1], "-v2")) { 48 else if(!strcmp(argv[1], "-v2")) {
48 headerlen = 24; 49 headerlen = 24;
49 iname = argv[2]; 50 iname = argv[2];
50 oname = argv[3]; 51 oname = argv[3];
51 version = 2; 52 version = 2;
52 } 53 }
54
55 else if(!strcmp(argv[1], "-neo")) {
56 headerlen = 17;
57 iname = argv[2];
58 oname = argv[3];
59 scramble = 0;
60 }
61
53 62
54 /* open file */ 63 /* open file */
55 file = fopen(iname,"rb"); 64 file = fopen(iname,"rb");
@@ -83,46 +92,63 @@ int main (int argc, char** argv)
83 } 92 }
84 fclose(file); 93 fclose(file);
85 94
86 /* scramble */ 95 if(scramble) {
87 slen = length/4; 96 /* scramble */
88 for (i = 0; i < length; i++) { 97 slen = length/4;
89 unsigned long addr = (i >> 2) + ((i % 4) * slen); 98 for (i = 0; i < length; i++) {
90 unsigned char data = inbuf[i]; 99 unsigned long addr = (i >> 2) + ((i % 4) * slen);
91 data = ~((data << 1) | ((data >> 7) & 1)); /* poor man's ROL */ 100 unsigned char data = inbuf[i];
92 outbuf[addr] = data; 101 data = ~((data << 1) | ((data >> 7) & 1)); /* poor man's ROL */
102 outbuf[addr] = data;
103 }
93 } 104 }
94 105
95 /* calculate checksum */ 106 /* calculate checksum */
96 for (i=0;i<length;i++) 107 for (i=0;i<length;i++)
97 crc += inbuf[i]; 108 crc += inbuf[i];
98 109
99 /* make header */
100 memset(header, 0, sizeof header); 110 memset(header, 0, sizeof header);
101 if (headerlen == 6) { 111 if(scramble) {
102 header[0] = (length >> 24) & 0xff; 112 if (headerlen == 6) {
103 header[1] = (length >> 16) & 0xff; 113 header[0] = (length >> 24) & 0xff;
104 header[2] = (length >> 8) & 0xff; 114 header[1] = (length >> 16) & 0xff;
105 header[3] = length & 0xff; 115 header[2] = (length >> 8) & 0xff;
106 header[4] = (crc >> 8) & 0xff; 116 header[3] = length & 0xff;
107 header[5] = crc & 0xff; 117 header[4] = (crc >> 8) & 0xff;
108 } 118 header[5] = crc & 0xff;
109 else { 119 }
110 header[0] = 120 else {
111 header[1] = 121 header[0] =
112 header[2] = 122 header[1] =
113 header[3] = 0xff; /* ??? */ 123 header[2] =
124 header[3] = 0xff; /* ??? */
114 125
115 header[6] = (crc >> 8) & 0xff; 126 header[6] = (crc >> 8) & 0xff;
116 header[7] = crc & 0xff; 127 header[7] = crc & 0xff;
128
129 header[11] = version;
117 130
118 header[11] = version; 131 header[15] = headerlen; /* really? */
119 132
120 header[15] = headerlen; /* really? */ 133 header[20] = (length >> 24) & 0xff;
134 header[21] = (length >> 16) & 0xff;
135 header[22] = (length >> 8) & 0xff;
136 header[23] = length & 0xff;
137 }
138 }
139 else {
140#define MY_FIRMWARE_TYPE "Rockbox"
141#define MY_HEADER_VERSION 1
121 142
122 header[20] = (length >> 24) & 0xff; 143 strncpy(header,MY_FIRMWARE_TYPE,9);
123 header[21] = (length >> 16) & 0xff; 144 header[9]='\0'; /*shouldn't have to, but to be SURE */
124 header[22] = (length >> 8) & 0xff; 145 header[10]=MY_HEADER_VERSION&0xFF;
125 header[23] = length & 0xff; 146 header[11]=(crc>>8)&0xFF;
147 header[12]=crc&0xFF;
148 header[13]=(sizeof(header)>>24)&0xFF;
149 header[14]=(sizeof(header)>>16)&0xFF;
150 header[15]=(sizeof(header)>>8)&0xFF;
151 header[16]=sizeof(header)&0xFF;
126 } 152 }
127 153
128 /* write file */ 154 /* write file */