Remove address from GPLv2 headers
[coreboot.git] / util / cbfstool / rmodtool.c
blob188d74998b297d6f34a52649c368d75da800626a
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <getopt.h>
25 #include "common.h"
26 #include "rmodule.h"
28 static const char *optstring = "i:o:vh?";
29 static struct option long_options[] = {
30 {"inelf", required_argument, 0, 'i' },
31 {"outelf", required_argument, 0, 'o' },
32 {"verbose", no_argument, 0, 'v' },
33 {"help", no_argument, 0, 'h' },
34 {NULL, 0, 0, 0 }
37 static void usage(char *name)
39 printf(
40 "rmodtool: utility for creating rmodules\n\n"
41 "USAGE: %s [-h] [-v] <-i|--inelf name> <-o|--outelf name>\n",
42 name
46 int main(int argc, char *argv[])
48 int c;
49 struct buffer elfin;
50 struct buffer elfout;
51 const char *input_file = NULL;
52 const char *output_file = NULL;
54 if (argc < 3) {
55 usage(argv[0]);
56 return 1;
59 while (1) {
60 int optindex = 0;
62 c = getopt_long(argc, argv, optstring, long_options, &optindex);
64 if (c == -1)
65 break;
67 switch (c) {
68 case 'i':
69 input_file = optarg;
70 break;
71 case 'h':
72 usage(argv[0]);
73 return 1;
74 case 'o':
75 output_file = optarg;
76 break;
77 case 'v':
78 verbose++;
79 break;
80 default:
81 break;
85 if (input_file == NULL || output_file == NULL) {
86 usage(argv[0]);
87 return 1;
90 if (buffer_from_file(&elfin, input_file)) {
91 ERROR("Couldn't read in file '%s'.\n", input_file);
92 return 1;
95 if (rmodule_create(&elfin, &elfout)) {
96 ERROR("Unable to create rmodule from '%s'.\n", input_file);
97 return 1;
100 if (buffer_write_file(&elfout, output_file)) {
101 ERROR("Unable to write rmodule elf '%s'.\n", output_file);
102 return 1;
105 return 0;