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 /rbutil/mktccboot/mktccboot.c | |
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
Diffstat (limited to 'rbutil/mktccboot/mktccboot.c')
-rw-r--r-- | rbutil/mktccboot/mktccboot.c | 101 |
1 files changed, 0 insertions, 101 deletions
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 | ||