diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-11-04 21:56:40 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-11-04 21:56:40 +0000 |
commit | 20f3e646d8d5f41f009493ee8b193dd75436afbc (patch) | |
tree | 147c0fb8a7f957b49bcc3e79f640776686617a06 | |
parent | e9c900d09de17eb4367a607b723b77e7228d3cee (diff) | |
download | rockbox-20f3e646d8d5f41f009493ee8b193dd75436afbc.tar.gz rockbox-20f3e646d8d5f41f009493ee8b193dd75436afbc.zip |
Clean up mktccboot building. No functional changes.
- Adjust the Makefile similar to the changes done in r23520.
- Split out the standalone part into a separate source file.
- Put telechips.o inside the archive instead of building it separately for rbutil. It is part of mktccboot.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23522 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | rbutil/mktccboot/Makefile | 35 | ||||
-rw-r--r-- | rbutil/mktccboot/main.c | 133 | ||||
-rw-r--r-- | rbutil/mktccboot/mktccboot.c | 101 | ||||
-rw-r--r-- | rbutil/mktccboot/mktccboot.h | 5 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.pro | 2 |
5 files changed, 160 insertions, 116 deletions
diff --git a/rbutil/mktccboot/Makefile b/rbutil/mktccboot/Makefile index cd8a539648..f51c462766 100644 --- a/rbutil/mktccboot/Makefile +++ b/rbutil/mktccboot/Makefile | |||
@@ -45,25 +45,35 @@ OUT = $(TARGET_DIR)build$(RBARCH) | |||
45 | 45 | ||
46 | all: $(OUTPUT) | 46 | all: $(OUTPUT) |
47 | 47 | ||
48 | $(OUT)/telechips.o: $(TOOLSDIR)/telechips.[ch] | 48 | # inputs |
49 | LIBSOURCES := mktccboot.c $(TOOLSDIR)/telechips.o | ||
50 | SOURCES := $(LIBSOURCES) main.c | ||
51 | OBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(notdir $(SOURCES)))) | ||
52 | LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(notdir $(LIBSOURCES)))) | ||
53 | EXTRADEPS := | ||
54 | |||
55 | # rule for sources from tools dir | ||
56 | $(OUT)/%.o: $(TOOLSDIR)/%.c $(OUT) | ||
49 | @echo CC $< | 57 | @echo CC $< |
50 | $(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/telechips.o $(TOOLSDIR)/telechips.c | 58 | $(SILENT)$(CC) $(CFLAGS) -c -o $@ $< |
51 | 59 | ||
52 | $(OUT)/mktccboot.o: mktccboot.[ch] $(OUT)/telechips.o | 60 | $(OUT)/%.o: %.c $(OUT) |
53 | @echo CC $< | 61 | @echo CC $< |
54 | $(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/mktccboot.o -W -Wall mktccboot.c -DVERSION=\"$(APPVERSION)\" | 62 | $(SILENT)$(CC) $(CFLAGS) -c -o $@ $< |
55 | |||
56 | $(OUTPUT): $(OUT) $(OUT)/mktccboot.o | ||
57 | @echo LD $@ | ||
58 | $(SILENT)$(CC) $(CFLAGS) -o $(OUTPUT) $(OUT)/mktccboot.o $(OUT)/telechips.o | ||
59 | 63 | ||
64 | # building the library archive | ||
60 | $(OUT)/libmktccboot.o: $(OUT)/mktccboot.o | 65 | $(OUT)/libmktccboot.o: $(OUT)/mktccboot.o |
61 | @echo CC $< | 66 | @echo CC $< |
62 | $(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(OUT)/libmktccboot.o -W -Wall mktccboot.c | 67 | $(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(OUT)/libmktccboot.o -W -Wall mktccboot.c |
63 | 68 | ||
64 | libmktccboot$(RBARCH).a: $(OUT) $(OUT)/libmktccboot.o | 69 | libmktccboot$(RBARCH).a: $(LIBOBJS) |
65 | @echo AR $@ | 70 | @echo AR $@ |
66 | $(SILENT)$(AR) ruc $(TARGET_DIR)libmktccboot$(RBARCH).a $(OUT)/libmktccboot.o | 71 | $(SILENT)$(AR) ruc $(TARGET_DIR)$@ $^ |
72 | |||
73 | # building the standalone executable | ||
74 | $(OUTPUT): $(OBJS) $(EXTRADEPS) | ||
75 | @echo LD $@ | ||
76 | $(SILENT)$(CC) $(CFLAGS) -o$(OUTPUT) $(OBJS) $(EXTRADEPS) | ||
67 | 77 | ||
68 | # some trickery to build ppc and i386 from a single call | 78 | # some trickery to build ppc and i386 from a single call |
69 | ifeq ($(RBARCH),) | 79 | ifeq ($(RBARCH),) |
@@ -80,9 +90,8 @@ libmktccboot-universal: libmktccbooti386.a libmktccbootppc.a | |||
80 | lipo -create $(TARGET_DIR)libmktccbootppc.a $(TARGET_DIR)libmktccbooti386.a -output $(TARGET_DIR)libmktccboot.a | 90 | lipo -create $(TARGET_DIR)libmktccbootppc.a $(TARGET_DIR)libmktccbooti386.a -output $(TARGET_DIR)libmktccboot.a |
81 | 91 | ||
82 | clean: | 92 | clean: |
83 | rm -f $(OUTPUT) libmktccboot.o $(TARGET_DIR)libmktccboot*.a mktccboot.dmg | 93 | rm -f $(OUTPUT) $(TARGET_DIR)libmktccboot*.a mktccboot.dmg |
84 | rm -f $(TOOLSDIR)/telechips.o | 94 | rm -rf $(OUT) |
85 | rm -rf build* mktccboot-* | ||
86 | 95 | ||
87 | mktccboot-i386: | 96 | mktccboot-i386: |
88 | $(MAKE) RBARCH=i386 | 97 | $(MAKE) RBARCH=i386 |
diff --git a/rbutil/mktccboot/main.c b/rbutil/mktccboot/main.c new file mode 100644 index 0000000000..4dd5d0c6c4 --- /dev/null +++ b/rbutil/mktccboot/main.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Dave Chapman | ||
11 | * | ||
12 | * Based on mkboot, Copyright (C) 2005 by Linus Nielsen Feltzing | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <unistd.h> | ||
27 | #include <sys/types.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <fcntl.h> | ||
30 | #include <inttypes.h> | ||
31 | #include "mktccboot.h" | ||
32 | #include "telechips.h" | ||
33 | |||
34 | static void usage(void) | ||
35 | { | ||
36 | printf("Usage: mktccboot <firmware file> <boot file> <output file>\n"); | ||
37 | |||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | int main(int argc, char *argv[]) | ||
42 | { | ||
43 | char *infile, *bootfile, *outfile; | ||
44 | int fdout = -1; | ||
45 | int n, of_size, boot_size, patched_size; | ||
46 | unsigned char *of_buf; | ||
47 | unsigned char *boot_buf = NULL; | ||
48 | unsigned char* image = NULL; | ||
49 | int ret = 0; | ||
50 | |||
51 | if(argc < 3) { | ||
52 | usage(); | ||
53 | } | ||
54 | |||
55 | infile = argv[1]; | ||
56 | bootfile = argv[2]; | ||
57 | outfile = argv[3]; | ||
58 | |||
59 | /* Read OF and boot files */ | ||
60 | of_buf = file_read(infile, &of_size); | ||
61 | if (!of_buf) | ||
62 | { | ||
63 | ret = 1; | ||
64 | goto error_exit; | ||
65 | } | ||
66 | |||
67 | /* Validate input file */ | ||
68 | if (test_firmware_tcc(of_buf, of_size)) | ||
69 | { | ||
70 | printf("[ERR] Unknown OF file used, aborting\n"); | ||
71 | ret = 2; | ||
72 | goto error_exit; | ||
73 | } | ||
74 | |||
75 | boot_buf = file_read(bootfile, &boot_size); | ||
76 | if (!boot_buf) | ||
77 | { | ||
78 | ret = 3; | ||
79 | goto error_exit; | ||
80 | } | ||
81 | |||
82 | /* Allocate buffer for patched firmware */ | ||
83 | image = malloc(of_size + boot_size); | ||
84 | if (image == NULL) | ||
85 | { | ||
86 | printf("[ERR] Could not allocate memory, aborting\n"); | ||
87 | ret = 4; | ||
88 | goto error_exit; | ||
89 | } | ||
90 | |||
91 | /* Create the patched firmware */ | ||
92 | image = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size, | ||
93 | &patched_size); | ||
94 | if (!image) | ||
95 | { | ||
96 | printf("[ERR] Error creating patched firmware, aborting\n"); | ||
97 | ret = 5; | ||
98 | goto error_exit; | ||
99 | } | ||
100 | |||
101 | fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); | ||
102 | if (fdout < 0) | ||
103 | { | ||
104 | perror(outfile); | ||
105 | ret = 6; | ||
106 | goto error_exit; | ||
107 | } | ||
108 | |||
109 | n = write(fdout, image, patched_size); | ||
110 | if (n != patched_size) | ||
111 | { | ||
112 | printf("[ERR] Could not write output file %s\n",outfile); | ||
113 | ret = 7; | ||
114 | goto error_exit; | ||
115 | } | ||
116 | |||
117 | error_exit: | ||
118 | |||
119 | if (fdout >= 0) | ||
120 | close(fdout); | ||
121 | |||
122 | if (of_buf) | ||
123 | free(of_buf); | ||
124 | |||
125 | if (boot_buf) | ||
126 | free(boot_buf); | ||
127 | |||
128 | if (image) | ||
129 | free(image); | ||
130 | |||
131 | return ret; | ||
132 | } | ||
133 | |||
diff --git a/rbutil/mktccboot/mktccboot.c b/rbutil/mktccboot/mktccboot.c index 7103f23895..4f2c3258db 100644 --- a/rbutil/mktccboot/mktccboot.c +++ b/rbutil/mktccboot/mktccboot.c | |||
@@ -75,13 +75,6 @@ static uint32_t get_uint32le(unsigned char* p) | |||
75 | return (p[3] << 24) | (p[2] << 16) | (p[1]<<8) | p[0]; | 75 | return (p[3] << 24) | (p[2] << 16) | (p[1]<<8) | p[0]; |
76 | } | 76 | } |
77 | 77 | ||
78 | void usage(void) | ||
79 | { | ||
80 | printf("Usage: mktccboot <firmware file> <boot file> <output file>\n"); | ||
81 | |||
82 | exit(1); | ||
83 | } | ||
84 | |||
85 | static off_t filesize(int fd) { | 78 | static off_t filesize(int fd) { |
86 | struct stat buf; | 79 | struct stat buf; |
87 | 80 | ||
@@ -181,97 +174,3 @@ int test_firmware_tcc(unsigned char* buf, int length) | |||
181 | return telechips_test_crc(buf, length); | 174 | return telechips_test_crc(buf, length); |
182 | } | 175 | } |
183 | 176 | ||
184 | #ifndef LIB | ||
185 | int main(int argc, char *argv[]) | ||
186 | { | ||
187 | char *infile, *bootfile, *outfile; | ||
188 | int fdout = -1; | ||
189 | int n, of_size, boot_size, patched_size; | ||
190 | unsigned char *of_buf; | ||
191 | unsigned char *boot_buf = NULL; | ||
192 | unsigned char* image = NULL; | ||
193 | int ret = 0; | ||
194 | |||
195 | if(argc < 3) { | ||
196 | usage(); | ||
197 | } | ||
198 | |||
199 | infile = argv[1]; | ||
200 | bootfile = argv[2]; | ||
201 | outfile = argv[3]; | ||
202 | |||
203 | /* Read OF and boot files */ | ||
204 | of_buf = file_read(infile, &of_size); | ||
205 | if (!of_buf) | ||
206 | { | ||
207 | ret = 1; | ||
208 | goto error_exit; | ||
209 | } | ||
210 | |||
211 | /* Validate input file */ | ||
212 | if (test_firmware_tcc(of_buf, of_size)) | ||
213 | { | ||
214 | printf("[ERR] Unknown OF file used, aborting\n"); | ||
215 | ret = 2; | ||
216 | goto error_exit; | ||
217 | } | ||
218 | |||
219 | boot_buf = file_read(bootfile, &boot_size); | ||
220 | if (!boot_buf) | ||
221 | { | ||
222 | ret = 3; | ||
223 | goto error_exit; | ||
224 | } | ||
225 | |||
226 | /* Allocate buffer for patched firmware */ | ||
227 | image = malloc(of_size + boot_size); | ||
228 | if (image == NULL) | ||
229 | { | ||
230 | printf("[ERR] Could not allocate memory, aborting\n"); | ||
231 | ret = 4; | ||
232 | goto error_exit; | ||
233 | } | ||
234 | |||
235 | /* Create the patched firmware */ | ||
236 | image = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size, | ||
237 | &patched_size); | ||
238 | if (!image) | ||
239 | { | ||
240 | printf("[ERR] Error creating patched firmware, aborting\n"); | ||
241 | ret = 5; | ||
242 | goto error_exit; | ||
243 | } | ||
244 | |||
245 | fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); | ||
246 | if (fdout < 0) | ||
247 | { | ||
248 | perror(outfile); | ||
249 | ret = 6; | ||
250 | goto error_exit; | ||
251 | } | ||
252 | |||
253 | n = write(fdout, image, patched_size); | ||
254 | if (n != patched_size) | ||
255 | { | ||
256 | printf("[ERR] Could not write output file %s\n",outfile); | ||
257 | ret = 7; | ||
258 | goto error_exit; | ||
259 | } | ||
260 | |||
261 | error_exit: | ||
262 | |||
263 | if (fdout >= 0) | ||
264 | close(fdout); | ||
265 | |||
266 | if (of_buf) | ||
267 | free(of_buf); | ||
268 | |||
269 | if (boot_buf) | ||
270 | free(boot_buf); | ||
271 | |||
272 | if (image) | ||
273 | free(image); | ||
274 | |||
275 | return ret; | ||
276 | } | ||
277 | #endif | ||
diff --git a/rbutil/mktccboot/mktccboot.h b/rbutil/mktccboot/mktccboot.h index 2df2c54506..17179c11e7 100644 --- a/rbutil/mktccboot/mktccboot.h +++ b/rbutil/mktccboot/mktccboot.h | |||
@@ -25,6 +25,11 @@ | |||
25 | #ifndef _MKTCCBOOT_H_ | 25 | #ifndef _MKTCCBOOT_H_ |
26 | #define _MKTCCBOOT_H_ | 26 | #define _MKTCCBOOT_H_ |
27 | 27 | ||
28 | /* win32 compatibility */ | ||
29 | #ifndef O_BINARY | ||
30 | #define O_BINARY 0 | ||
31 | |||
32 | #endif | ||
28 | #ifdef __cplusplus | 33 | #ifdef __cplusplus |
29 | extern "C" { | 34 | extern "C" { |
30 | #endif | 35 | #endif |
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index b04667028b..90949fcc43 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro | |||
@@ -115,7 +115,6 @@ SOURCES += rbutilqt.cpp \ | |||
115 | base/bootloaderinstalltcc.cpp \ | 115 | base/bootloaderinstalltcc.cpp \ |
116 | ../../tools/mkboot.c \ | 116 | ../../tools/mkboot.c \ |
117 | ../../tools/iriver.c \ | 117 | ../../tools/iriver.c \ |
118 | ../../tools/telechips.c \ | ||
119 | 118 | ||
120 | HEADERS += rbutilqt.h \ | 119 | HEADERS += rbutilqt.h \ |
121 | install.h \ | 120 | install.h \ |
@@ -177,7 +176,6 @@ HEADERS += rbutilqt.h \ | |||
177 | base/bootloaderinstalltcc.h \ | 176 | base/bootloaderinstalltcc.h \ |
178 | ../../tools/mkboot.h \ | 177 | ../../tools/mkboot.h \ |
179 | ../../tools/iriver.h \ | 178 | ../../tools/iriver.h \ |
180 | ../../tools/telechips.h \ | ||
181 | 179 | ||
182 | # Needed by QT on Win | 180 | # Needed by QT on Win |
183 | INCLUDEPATH = $$_PRO_FILE_PWD_ $$_PRO_FILE_PWD_/irivertools $$_PRO_FILE_PWD_/zip $$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base | 181 | INCLUDEPATH = $$_PRO_FILE_PWD_ $$_PRO_FILE_PWD_/irivertools $$_PRO_FILE_PWD_/zip $$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base |