Amaury Pouly | 2e0c558 | 2013-10-22 00:48:33 +0200 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2013 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 "mkzenboot.h" |
| 27 | |
| 28 | static void usage(void) |
| 29 | { |
| 30 | printf("Usage: mkzenboot [options | file]...\n"); |
| 31 | printf("Options:\n"); |
| 32 | printf(" -?/--help Display this message\n"); |
| 33 | printf(" -i <file> Set input file\n"); |
| 34 | printf(" -o <file> Set output file\n"); |
| 35 | printf(" -b <file> Set boot file\n"); |
| 36 | printf(" -t <type> Set output type\n"); |
| 37 | printf(" -d/--debug Enable debug output\n"); |
| 38 | printf("Output types: dualboot, deferred_dualboot, singleboot, recovery\n"); |
| 39 | printf("By default a dualboot image is built\n"); |
| 40 | exit(1); |
| 41 | } |
| 42 | |
| 43 | int main(int argc, char *argv[]) |
| 44 | { |
| 45 | char *outfile = NULL; |
| 46 | char *bootfile = NULL; |
| 47 | char *infile = NULL; |
| 48 | struct zen_option_t opt; |
| 49 | memset(&opt, 0, sizeof(opt)); |
| 50 | |
| 51 | if(argc == 1) |
| 52 | usage(); |
| 53 | |
| 54 | while(1) |
| 55 | { |
| 56 | static struct option long_options[] = |
| 57 | { |
| 58 | {"help", no_argument, 0, '?'}, |
| 59 | {"debug", no_argument, 0, 'd'}, |
| 60 | {0, 0, 0, 0} |
| 61 | }; |
| 62 | |
| 63 | int c = getopt_long(argc, argv, "?di:o:b:t:", long_options, NULL); |
| 64 | if(c == -1) |
| 65 | break; |
| 66 | switch(c) |
| 67 | { |
| 68 | case 'd': |
| 69 | opt.debug = true; |
| 70 | break; |
| 71 | case '?': |
| 72 | usage(); |
| 73 | break; |
| 74 | case 'o': |
| 75 | outfile = optarg; |
| 76 | break; |
| 77 | case 'i': |
| 78 | infile = optarg; |
| 79 | break; |
| 80 | case 'b': |
| 81 | bootfile = optarg; |
| 82 | break; |
| 83 | case 't': |
| 84 | if(strcmp(optarg, "dualboot") == 0) opt.output = ZEN_DUALBOOT; |
| 85 | else if(strcmp(optarg, "mixedboot") == 0) opt.output = ZEN_MIXEDBOOT; |
| 86 | else if(strcmp(optarg, "singleboot") == 0) opt.output = ZEN_SINGLEBOOT; |
| 87 | else if(strcmp(optarg, "recovery") == 0) opt.output = ZEN_RECOVERY; |
| 88 | else |
| 89 | { |
| 90 | printf("Unknown output type '%s'\n", optarg); |
| 91 | return 1; |
| 92 | } |
| 93 | break; |
| 94 | default: |
| 95 | abort(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if(!outfile) |
| 100 | { |
| 101 | printf("You must specify an output file\n"); |
| 102 | return 1; |
| 103 | } |
| 104 | if(!bootfile) |
| 105 | { |
| 106 | printf("You must specify a boot file\n"); |
| 107 | return 1; |
| 108 | } |
| 109 | if(!infile) |
| 110 | { |
| 111 | printf("You must specify an input file\n"); |
| 112 | return 1; |
| 113 | } |
| 114 | if(optind != argc) |
| 115 | { |
| 116 | printf("Extra arguments on command line\n"); |
| 117 | return 1; |
| 118 | } |
| 119 | |
| 120 | enum zen_error_t err = mkzenboot(infile, bootfile, outfile, opt); |
| 121 | printf("Result: %d\n", err); |
| 122 | return 0; |
| 123 | } |