1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Dave Chapman
12 * Based on mkboot, Copyright (C) 2005 by Linus Nielsen Feltzing
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.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
27 #include <sys/types.h>
31 #include "mktccboot.h"
32 #include "telechips.h"
34 static void usage(void)
36 printf("Usage: mktccboot <firmware file> <boot file> <output file>\n");
41 int main(int argc
, char *argv
[])
43 char *infile
, *bootfile
, *outfile
;
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
;
59 /* Read OF and boot files */
60 of_buf
= file_read(infile
, &of_size
);
67 /* Validate input file */
68 if (test_firmware_tcc(of_buf
, of_size
))
70 printf("[ERR] Unknown OF file used, aborting\n");
75 boot_buf
= file_read(bootfile
, &boot_size
);
82 /* Allocate buffer for patched firmware */
83 image
= malloc(of_size
+ boot_size
);
86 printf("[ERR] Could not allocate memory, aborting\n");
91 /* Create the patched firmware */
92 image
= patch_firmware_tcc(of_buf
, of_size
, boot_buf
, boot_size
,
96 printf("[ERR] Error creating patched firmware, aborting\n");
101 fdout
= open(outfile
, O_WRONLY
|O_CREAT
|O_TRUNC
|O_BINARY
, 0644);
109 n
= write(fdout
, image
, patched_size
);
110 if (n
!= patched_size
)
112 printf("[ERR] Could not write output file %s\n",outfile
);