summaryrefslogtreecommitdiff
path: root/tools/mkneofile.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-12-12 13:32:27 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-12-12 13:32:27 +0000
commitda6d7e9b44bce4007ba0d1c8e0d44e5a900ac75e (patch)
tree9423f28720a2dd8bbc2ef5a58354e966df9b881f /tools/mkneofile.c
parentc78b30dac867d956a48df96ac4eb73e2372f0fbc (diff)
downloadrockbox-da6d7e9b44bce4007ba0d1c8e0d44e5a900ac75e.tar.gz
rockbox-da6d7e9b44bce4007ba0d1c8e0d44e5a900ac75e.zip
Added the 'mkneofile' tool that is used instead of scramble when making the
Neo firmware image. The Open Neo project used to call this tool 'add_header'. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4136 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/mkneofile.c')
-rw-r--r--tools/mkneofile.c112
1 files changed, 112 insertions, 0 deletions
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
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}