summaryrefslogtreecommitdiff
path: root/utils/mknwzboot/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/mknwzboot/main.c')
-rw-r--r--utils/mknwzboot/main.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/utils/mknwzboot/main.c b/utils/mknwzboot/main.c
new file mode 100644
index 0000000000..491a18043b
--- /dev/null
+++ b/utils/mknwzboot/main.c
@@ -0,0 +1,126 @@
1/***************************************************************************
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>
25#include <string.h>
26#include "mknwzboot.h"
27
28static void usage(void)
29{
30 printf("Usage: mknwzboot [options | file]...\n");
31 printf("Options:\n");
32 printf(" -h/--help Display this message\n");
33 printf(" -o <file> Set output file\n");
34 printf(" -b <file> Set boot file\n");
35 printf(" -d/--debug Enable debug output\n");
36 printf(" -x Dump device informations\n");
37 printf(" -u Create uninstall update\n");
38 printf(" -m <model> Specify model\n");
39 exit(1);
40}
41
42int main(int argc, char *argv[])
43{
44 char *outfile = NULL;
45 char *bootfile = NULL;
46 bool debug = false;
47 bool install = true;
48 const char *model = NULL;
49
50 if(argc == 1)
51 usage();
52
53 while(1)
54 {
55 static struct option long_options[] =
56 {
57 {"help", no_argument, 0, 'h'},
58 {"out-file", required_argument, 0, 'o'},
59 {"boot-file", required_argument, 0, 'b'},
60 {"debug", no_argument, 0, 'd'},
61 {"dev-info", no_argument, 0, 'x'},
62 {"uninstall", no_argument, 0, 'u'},
63 {"model", required_argument, 0, 'm'},
64 {0, 0, 0, 0}
65 };
66
67 int c = getopt_long(argc, argv, "ho:b:dxum:", long_options, NULL);
68 if(c == -1)
69 break;
70 switch(c)
71 {
72 case 'd':
73 debug = true;
74 break;
75 case 'h':
76 usage();
77 break;
78 case 'o':
79 outfile = optarg;
80 break;
81 case 'b':
82 bootfile = optarg;
83 break;
84 case 'x':
85 dump_nwz_dev_info("");
86 return 0;
87 case 'u':
88 install = false;
89 break;
90 case 'm':
91 model = optarg;
92 break;
93 default:
94 abort();
95 }
96 }
97
98 if(!outfile)
99 {
100 printf("You must specify an output file\n");
101 return 1;
102 }
103 if(install && !bootfile)
104 {
105 printf("You must specify a boot file for installation\n");
106 return 1;
107 }
108 if(!install && !model)
109 {
110 printf("You must provide a model for uninstallation\n");
111 return 1;
112 }
113 if(optind != argc)
114 {
115 printf("Extra arguments on command line\n");
116 return 1;
117 }
118
119 int err;
120 if(install)
121 err = mknwzboot(bootfile, outfile, debug);
122 else
123 err = mknwzboot_uninst(model, outfile, debug);
124 printf("Result: %d\n", err);
125 return err;
126}