blob: 95fc226db1797c4d71ce56029a79f1eb07aa5ef0 [file] [log] [blame]
Amaury Pouly303c4862011-11-06 19:44:03 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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 <getopt.h>
23#include <stdlib.h>
24#include <stdio.h>
Dominik Riebeling2d2fa5c2011-12-04 13:54:07 +000025#include <string.h>
Amaury Pouly303c4862011-11-06 19:44:03 +000026#include "mkimxboot.h"
27
28static void usage(void)
29{
30 printf("Usage: elftosb [options | file]...\n");
31 printf("Options:\n");
32 printf(" -?/--help\tDisplay this message\n");
33 printf(" -o <file>\tSet output file\n");
34 printf(" -i <file>\tSet input file\n");
35 printf(" -b <file>\tSet boot file\n");
36 printf(" -d/--debug\tEnable debug output\n");
37 printf(" -t <type>\tSet type (dualboot, singleboot, recovery)\n");
38 printf("By default a dualboot image is built\n");
39 exit(1);
40}
41
42int main(int argc, char *argv[])
43{
44 char *infile = NULL;
45 char *outfile = NULL;
46 char *bootfile = NULL;
47 enum imx_output_type_t type = IMX_DUALBOOT;
48 bool debug = false;
49
50 if(argc == 1)
51 usage();
Dominik Riebeling2d2fa5c2011-12-04 13:54:07 +000052
Amaury Pouly303c4862011-11-06 19:44:03 +000053 while(1)
54 {
55 static struct option long_options[] =
56 {
57 {"help", no_argument, 0, '?'},
58 {"in-file", no_argument, 0, 'i'},
59 {"out-file", required_argument, 0, 'o'},
60 {"boot-file", required_argument, 0, 'b'},
61 {"debug", no_argument, 0, 'd'},
62 {"type", required_argument, 0, 't'},
63 {0, 0, 0, 0}
64 };
65
66 int c = getopt_long(argc, argv, "?di:o:b:t:", long_options, NULL);
67 if(c == -1)
68 break;
69 switch(c)
70 {
71 case 'd':
72 debug = true;
73 break;
74 case '?':
75 usage();
76 break;
77 case 'o':
78 outfile = optarg;
79 break;
80 case 'i':
81 infile = optarg;
82 break;
83 case 'b':
84 {
85 bootfile = optarg;
86 break;
87 }
88 case 't':
89 if(strcmp(optarg, "dualboot") == 0)
90 type = IMX_DUALBOOT;
91 else if(strcmp(optarg, "singleboot") == 0)
92 type = IMX_SINGLEBOOT;
93 else if(strcmp(optarg, "recovery") == 0)
94 type = IMX_RECOVERY;
95 else
96 {
97 printf("Invalid boot type '%s'\n", optarg);
98 return 1;
99 }
100 break;
101 default:
102 abort();
103 }
104 }
105
106 if(!infile)
107 {
108 printf("You must specify an input file\n");
109 return 1;
110 }
111 if(!outfile)
112 {
113 printf("You must specify an output file\n");
114 return 1;
115 }
116 if(!bootfile)
117 {
118 printf("You must specify an boot file\n");
119 return 1;
120 }
121 if(optind != argc)
122 {
123 printf("Extra arguments on command line\n");
124 return 1;
125 }
126
127 struct imx_option_t opt;
128 opt.debug = debug;
129 opt.output = type;
130 enum imx_error_t err = mkimxboot(infile, bootfile, outfile, opt);
131 printf("Result: %d\n", err);
132 return 0;
133}