Fix makefile conditions
[maemo-rb.git] / rbutil / mkimxboot / main.c
blob95fc226db1797c4d71ce56029a79f1eb07aa5ef0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <getopt.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "mkimxboot.h"
28 static void usage(void)
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);
42 int main(int argc, char *argv[])
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;
50 if(argc == 1)
51 usage();
53 while(1)
55 static struct option long_options[] =
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}
66 int c = getopt_long(argc, argv, "?di:o:b:t:", long_options, NULL);
67 if(c == -1)
68 break;
69 switch(c)
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':
85 bootfile = optarg;
86 break;
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
97 printf("Invalid boot type '%s'\n", optarg);
98 return 1;
100 break;
101 default:
102 abort();
106 if(!infile)
108 printf("You must specify an input file\n");
109 return 1;
111 if(!outfile)
113 printf("You must specify an output file\n");
114 return 1;
116 if(!bootfile)
118 printf("You must specify an boot file\n");
119 return 1;
121 if(optind != argc)
123 printf("Extra arguments on command line\n");
124 return 1;
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;