diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 4 | ||||
-rw-r--r-- | tools/mkneofile.c | 112 |
2 files changed, 115 insertions, 1 deletions
diff --git a/tools/Makefile b/tools/Makefile index 5fec4b1dbe..ea54b1b6f3 100644 --- a/tools/Makefile +++ b/tools/Makefile | |||
@@ -8,7 +8,7 @@ | |||
8 | # | 8 | # |
9 | CFLAGS := -O -ansi | 9 | CFLAGS := -O -ansi |
10 | 10 | ||
11 | TARGETS := scramble descramble sh2d bmp2rb convbdf generate_rocklatin | 11 | TARGETS := scramble descramble sh2d bmp2rb convbdf generate_rocklatin mkneofile |
12 | 12 | ||
13 | all: $(TARGETS) | 13 | all: $(TARGETS) |
14 | 14 | ||
@@ -16,6 +16,8 @@ scramble: scramble.c | |||
16 | 16 | ||
17 | descramble: descramble.c | 17 | descramble: descramble.c |
18 | 18 | ||
19 | mkneofile: mkneofile.c | ||
20 | |||
19 | sh2d: sh2d.c | 21 | sh2d: sh2d.c |
20 | 22 | ||
21 | bmp2rb: bmp2rb.c | 23 | bmp2rb: bmp2rb.c |
diff --git a/tools/mkneofile.c b/tools/mkneofile.c new file mode 100644 index 0000000000..93e0d45043 --- /dev/null +++ b/tools/mkneofile.c | |||
@@ -0,0 +1,112 @@ | |||
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 | |||
25 | int 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 | } | ||