diff options
author | Aaron Durbin <adurbin@chromium.org> | 2014-03-07 15:11:53 -0600 |
---|---|---|
committer | Aaron Durbin <adurbin@google.com> | 2014-03-20 21:34:39 +0100 |
commit | 4fde5a66b4a2b4117a45519ab0f63a9fd6bff835 (patch) | |
tree | fc69dd7a4833805f274d8a5ea89ac34065e3921d /util/cbfstool/rmodtool.c | |
parent | 36be8135d74964fa2eb03af44079d845c199486b (diff) |
util: add rmodtool for parsing ELF files to rmodules
The current implementation of creating rmodules relies
on invoking the linker in a certain manner with the
relocations overlaid on the BSS section. It's not really
surprising that the linker doesn't always behave the way
one wants depending on the linker used and the architecture.
Instead, introduce rmodtool which takes an ELF file as an
input, parses it, and creates a new ELF file in the format
the rmodule loader expects.
Change-Id: I31ac2d327d450ef841c3a7d9740b787278382bef
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/5378
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'util/cbfstool/rmodtool.c')
-rw-r--r-- | util/cbfstool/rmodtool.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/util/cbfstool/rmodtool.c b/util/cbfstool/rmodtool.c new file mode 100644 index 0000000000..1455cd9a3b --- /dev/null +++ b/util/cbfstool/rmodtool.c @@ -0,0 +1,106 @@ +/* + * cbfstool, CLI utility for creating rmodules + * + * Copyright (C) 2014 Google, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <getopt.h> +#include "common.h" +#include "rmodule.h" + +static const char *optstring = "i:o:vh?"; +static struct option long_options[] = { + {"inelf", required_argument, 0, 'i' }, + {"outelf", required_argument, 0, 'o' }, + {"verbose", no_argument, 0, 'v' }, + {"help", no_argument, 0, 'h' }, + {NULL, 0, 0, 0 } +}; + +static void usage(char *name) +{ + printf( + "rmodtool: utility for creating rmodules\n\n" + "USAGE: %s [-h] [-v] <-i|--inelf name> <-o|--outelf name>\n", + name + ); +} + +int main(int argc, char *argv[]) +{ + int c; + struct buffer elfin; + struct buffer elfout; + const char *input_file = NULL; + const char *output_file = NULL; + + if (argc < 3) { + usage(argv[0]); + return 1; + } + + while (1) { + int optindex = 0; + + c = getopt_long(argc, argv, optstring, long_options, &optindex); + + if (c == -1) + break; + + switch (c) { + case 'i': + input_file = optarg; + break; + case 'h': + usage(argv[0]); + return 1; + case 'o': + output_file = optarg; + break; + case 'v': + verbose++; + break; + default: + break; + } + } + + if (input_file == NULL || output_file == NULL) { + usage(argv[0]); + return 1; + } + + if (buffer_from_file(&elfin, input_file)) { + ERROR("Couldn't read in file '%s'.\n", input_file); + return 1; + } + + if (rmodule_create(&elfin, &elfout)) { + ERROR("Unable to create rmodule from '%s'.\n", input_file); + return 1; + } + + if (buffer_write_file(&elfout, output_file)) { + ERROR("Unable to write rmodule elf '%s'.\n", output_file); + return 1; + } + + return 0; +} |