summaryrefslogtreecommitdiff
path: root/rbutil/mktccboot/mktccboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/mktccboot/mktccboot.c')
-rw-r--r--rbutil/mktccboot/mktccboot.c101
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
78void usage(void)
79{
80 printf("Usage: mktccboot <firmware file> <boot file> <output file>\n");
81
82 exit(1);
83}
84
85static off_t filesize(int fd) { 78static 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
185int 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
261error_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