summaryrefslogtreecommitdiff
path: root/tools/iaudio.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/iaudio.c')
-rw-r--r--tools/iaudio.c108
1 files changed, 0 insertions, 108 deletions
diff --git a/tools/iaudio.c b/tools/iaudio.c
deleted file mode 100644
index 41d718f69b..0000000000
--- a/tools/iaudio.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Christian Gmeiner
11 *
12 * This particular source code file is licensed under the X11 license. See the
13 * bottom of the COPYING file for details on this license.
14 *
15 ****************************************************************************/
16
17/* This little application updates the checksum of a modifized iAudio x5
18 firmware bin.
19 And this is how it works:
20
21 The byte at offset 0x102b contains the 8-bit sum of all the bytes starting with the one at 0x1030.
22*/
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28#define CHECKSUM_BIT 0x102b
29#define CHECKSUM_START 0x1030
30
31void usage(void) {
32
33 printf("usage: iaudio <input file> <output file>\n");
34 printf("\n\nThis tool updates the checksum of an iaudio fw bin\n");
35 exit(1);
36}
37
38int main (int argc, char* argv[]) {
39
40 char byte = '\0';
41 char checksum = '\0';
42 unsigned long length, i;
43 unsigned char* inbuf;
44 char* iname = argv[1];
45 char* oname = argv[2];
46 FILE* pFile;
47
48 if (argc < 2) {
49 usage();
50 }
51
52 /* open file */
53 pFile = fopen(iname, "rb");
54 if (!pFile) {
55 perror(oname);
56 return -1;
57 }
58
59 /* print old checksum */
60 fseek (pFile, CHECKSUM_BIT, SEEK_SET);
61 byte = fgetc(pFile);
62 printf("Old checksum: 0x%02x\n", byte & 0xff);
63
64 /* get file size*/
65 fseek(pFile,0,SEEK_END);
66 length = ftell(pFile);
67 fseek(pFile,0,SEEK_SET);
68
69 /* try to allocate memory */
70 inbuf = malloc(length);
71 if (!inbuf) {
72 printf("out of memory!\n");
73 return -1;
74 }
75
76 /* read file */
77 i = fread(inbuf, 1, length, pFile);
78 if (!i) {
79 perror(iname);
80 return -1;
81 }
82 fclose(pFile);
83
84 /* calculate new checksum */
85 for (i = CHECKSUM_START; i < length; i++) {
86 checksum += inbuf[i];
87 }
88 printf("New checksum: 0x%02x\n", checksum & 0xff);
89
90 /* save new checksum */
91 inbuf[CHECKSUM_BIT] = (unsigned char) checksum;
92
93 /* save inbuf */
94 pFile = fopen(oname,"wb");
95 if (!pFile) {
96 perror(oname);
97 return -1;
98 }
99
100 i = fwrite(inbuf, 1, length, pFile);
101 if (!i) {
102 perror(oname);
103 return -1;
104 }
105 fclose(pFile);
106
107 return 0;
108}