mb/dell: Add Latitude E5520 (Sandy Bridge)
[coreboot.git] / util / cbfstool / rmodtool.c
blobc4256e86c82ad6ed0d652533cab4dfe0235a2b50
1 /* CLI utility for creating rmodules */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <getopt.h>
9 #include "common.h"
10 #include "rmodule.h"
12 static const char *optstring = "i:o:vh?";
13 static struct option long_options[] = {
14 {"inelf", required_argument, 0, 'i' },
15 {"outelf", required_argument, 0, 'o' },
16 {"verbose", no_argument, 0, 'v' },
17 {"help", no_argument, 0, 'h' },
18 {NULL, 0, 0, 0 }
21 static void usage(char *name)
23 printf(
24 "rmodtool: utility for creating rmodules\n\n"
25 "USAGE: %s [-h] [-v] <-i|--inelf name> <-o|--outelf name>\n",
26 name
30 int main(int argc, char *argv[])
32 int c;
33 struct buffer elfin;
34 struct buffer elfout;
35 const char *input_file = NULL;
36 const char *output_file = NULL;
38 if (argc < 3) {
39 usage(argv[0]);
40 return 1;
43 while (1) {
44 int optindex = 0;
46 c = getopt_long(argc, argv, optstring, long_options, &optindex);
48 if (c == -1)
49 break;
51 switch (c) {
52 case 'i':
53 input_file = optarg;
54 break;
55 case 'h':
56 usage(argv[0]);
57 return 1;
58 case 'o':
59 output_file = optarg;
60 break;
61 case 'v':
62 verbose++;
63 break;
64 default:
65 break;
69 if (input_file == NULL || output_file == NULL) {
70 usage(argv[0]);
71 return 1;
74 if (buffer_from_file(&elfin, input_file)) {
75 ERROR("Couldn't read in file '%s'.\n", input_file);
76 return 1;
79 if (rmodule_create(&elfin, &elfout)) {
80 ERROR("Unable to create rmodule from '%s'.\n", input_file);
81 return 1;
84 if (buffer_write_file(&elfout, output_file)) {
85 ERROR("Unable to write rmodule elf '%s'.\n", output_file);
86 return 1;
89 return 0;