tree: drop last paragraph of GPL copyright header
[coreboot.git] / util / cbfstool / rmodtool.c
blobbbcc2aebb08db88a4c0a83d4e8a038a45e145650
1 /*
2 * cbfstool, CLI utility for creating rmodules
4 * Copyright (C) 2014 Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <getopt.h>
21 #include "common.h"
22 #include "rmodule.h"
24 static const char *optstring = "i:o:vh?";
25 static struct option long_options[] = {
26 {"inelf", required_argument, 0, 'i' },
27 {"outelf", required_argument, 0, 'o' },
28 {"verbose", no_argument, 0, 'v' },
29 {"help", no_argument, 0, 'h' },
30 {NULL, 0, 0, 0 }
33 static void usage(char *name)
35 printf(
36 "rmodtool: utility for creating rmodules\n\n"
37 "USAGE: %s [-h] [-v] <-i|--inelf name> <-o|--outelf name>\n",
38 name
42 int main(int argc, char *argv[])
44 int c;
45 struct buffer elfin;
46 struct buffer elfout;
47 const char *input_file = NULL;
48 const char *output_file = NULL;
50 if (argc < 3) {
51 usage(argv[0]);
52 return 1;
55 while (1) {
56 int optindex = 0;
58 c = getopt_long(argc, argv, optstring, long_options, &optindex);
60 if (c == -1)
61 break;
63 switch (c) {
64 case 'i':
65 input_file = optarg;
66 break;
67 case 'h':
68 usage(argv[0]);
69 return 1;
70 case 'o':
71 output_file = optarg;
72 break;
73 case 'v':
74 verbose++;
75 break;
76 default:
77 break;
81 if (input_file == NULL || output_file == NULL) {
82 usage(argv[0]);
83 return 1;
86 if (buffer_from_file(&elfin, input_file)) {
87 ERROR("Couldn't read in file '%s'.\n", input_file);
88 return 1;
91 if (rmodule_create(&elfin, &elfout)) {
92 ERROR("Unable to create rmodule from '%s'.\n", input_file);
93 return 1;
96 if (buffer_write_file(&elfout, output_file)) {
97 ERROR("Unable to write rmodule elf '%s'.\n", output_file);
98 return 1;
101 return 0;