summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-28 12:06:55 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-04-28 12:06:55 +0200
commit8a3824f36a65c777388831c47556f8141b22d463 (patch)
tree1c871ae7120035e3a5ccb9bd61220a7241e55ad0
parent308f099874d5d763de20a2b22cd28389719cfc30 (diff)
downloadrockbox-8a3824f36a65c777388831c47556f8141b22d463.tar.gz
rockbox-8a3824f36a65c777388831c47556f8141b22d463.zip
ipodpatcher: replace ipod2c with bin2c.
Change-Id: I3b339e05c9a5f4a8a60bd7581ec402b4784542e2
-rw-r--r--rbutil/ipodpatcher/Makefile15
-rw-r--r--rbutil/ipodpatcher/ipod2c.c142
2 files changed, 6 insertions, 151 deletions
diff --git a/rbutil/ipodpatcher/Makefile b/rbutil/ipodpatcher/Makefile
index bae805671e..afdcaa5039 100644
--- a/rbutil/ipodpatcher/Makefile
+++ b/rbutil/ipodpatcher/Makefile
@@ -45,14 +45,11 @@ include ../libtools.make
45$(OBJDIR)ipodpatcher-rc.o: ipodpatcher.rc ipodpatcher.manifest 45$(OBJDIR)ipodpatcher-rc.o: ipodpatcher.rc ipodpatcher.manifest
46 $(CROSS)$(WINDRES) -i ipodpatcher.rc -o ipodpatcher-rc.o 46 $(CROSS)$(WINDRES) -i ipodpatcher.rc -o ipodpatcher-rc.o
47 47
48ipod2c: ipod2c.c 48%.c: bootloader-%.ipod $(BIN2C)
49 $(NATIVECC) $(CFLAGS) -o ipod2c ipod2c.c 49 @echo BIN2C $<
50 $(SILENT)$(BIN2C) -i $< $*
50 51
51%.c: bootloader-%.ipod ipod2c 52%.c: bootloader-%.ipodx $(BIN2C)
52 @echo IPOD2C $< 53 @echo BIN2C $<
53 $(SILENT)./ipod2c $< $* 54 $(SILENT)$(BIN2C) -i $< $*
54
55%.c: bootloader-%.ipodx ipod2c
56 @echo IPOD2C $<
57 $(SILENT)./ipod2c $< $*
58 55
diff --git a/rbutil/ipodpatcher/ipod2c.c b/rbutil/ipodpatcher/ipod2c.c
deleted file mode 100644
index 77a3923196..0000000000
--- a/rbutil/ipodpatcher/ipod2c.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Dave Chapman
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdio.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27#include <fcntl.h>
28#include <stdlib.h>
29
30#ifndef O_BINARY
31#define O_BINARY 0
32#endif
33
34static off_t filesize(int fd)
35{
36 struct stat buf;
37
38 fstat(fd,&buf);
39 return buf.st_size;
40}
41
42static int write_cfile(unsigned char* buf, off_t len, char* cname)
43{
44 char filename[256];
45 FILE* fp;
46 int i;
47
48 snprintf(filename,256,"%s.c",cname);
49
50 fp = fopen(filename,"w+");
51 if (fp == NULL) {
52 fprintf(stderr,"Couldn't open %s\n",filename);
53 return -1;
54 }
55
56 fprintf(fp,"/* Generated by ipod2c */\n\n");
57 fprintf(fp,"unsigned char %s[] = {",cname);
58
59 for (i=0;i<len;i++) {
60 if ((i % 16) == 0) {
61 fprintf(fp,"\n ");
62 }
63 if (i == (len-1)) {
64 fprintf(fp,"0x%02x",buf[i]);
65 } else {
66 fprintf(fp,"0x%02x, ",buf[i]);
67 }
68 }
69 fprintf(fp,"\n};\n");
70
71 fclose(fp);
72 return 0;
73}
74
75static int write_hfile(unsigned char* buf, off_t len, char* cname)
76{
77 char filename[256];
78 FILE* fp;
79 (void)buf;
80
81 snprintf(filename,256,"%s.h",cname);
82 fp = fopen(filename,"w+");
83 if (fp == NULL) {
84 fprintf(stderr,"Couldn't open %s\n",filename);
85 return -1;
86 }
87
88 fprintf(fp,"/* Generated by ipod2c */\n\n");
89 fprintf(fp,"#define LEN_%s %d\n",cname,(int)len);
90 fprintf(fp,"extern unsigned char %s[];\n",cname);
91 fclose(fp);
92 return 0;
93}
94
95int main (int argc, char* argv[])
96{
97 char* infile;
98 char* cname;
99 int fd;
100 unsigned char* buf;
101 int len;
102 int n;
103
104 if (argc != 3) {
105 fprintf(stderr,"Usage: ipod2c file.ipod cname\n");
106 return 0;
107 }
108
109 infile=argv[1];
110 cname=argv[2];
111
112 fd = open(infile,O_RDONLY|O_BINARY);
113 if (fd < 0) {
114 fprintf(stderr,"Can not open %s\n",infile);
115 return 0;
116 }
117
118 len = filesize(fd) - 8;
119
120 n = lseek(fd,8,SEEK_SET);
121 if (n != 8) {
122 fprintf(stderr,"Seek failed\n");
123 return 0;
124 }
125
126 buf = malloc(len);
127 n = read(fd,buf,len);
128 if (n < len) {
129 fprintf(stderr,"Short read, aborting\n");
130 return 0;
131 }
132 close(fd);
133
134 if (write_cfile(buf,len,cname) < 0) {
135 return -1;
136 }
137 if (write_hfile(buf,len,cname) < 0) {
138 return -1;
139 }
140
141 return 0;
142}