X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Fao-elftohex%2Fao-elftohex.c;h=f3ab0c38ca4a1fdeff140e14a553979b1aeecff6;hb=HEAD;hp=db8f86f1569640fffebdbf04018054d670a5bacd;hpb=14204e3d147ad99cc249ad8de254809180fe5c38;p=fw%2Faltos diff --git a/ao-tools/ao-elftohex/ao-elftohex.c b/ao-tools/ao-elftohex/ao-elftohex.c index db8f86f1..a31f9656 100644 --- a/ao-tools/ao-elftohex/ao-elftohex.c +++ b/ao-tools/ao-elftohex/ao-elftohex.c @@ -3,7 +3,8 @@ * * 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. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,6 +19,7 @@ #include #include #include +#include #include "ao-hex.h" #include "ao-elf.h" #include "ao-verbose.h" @@ -25,6 +27,7 @@ static const struct option options[] = { { .name = "verbose", .has_arg = 1, .val = 'v' }, { .name = "output", .has_arg = 1, .val = 'o' }, + { .name = "nosym", .has_arg = 0, .val = 'n' }, { 0, 0, 0, 0}, }; @@ -50,13 +53,15 @@ main (int argc, char **argv) { char *input = NULL; char *output = NULL; - struct ao_hex_image *image; - struct ao_sym *file_symbols; + struct ao_hex_image *full_image = NULL; + struct ao_sym *file_symbols = NULL; int num_file_symbols; FILE *file; int c; + int i; + int nosym = 0; - while ((c = getopt_long(argc, argv, "v:o:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "nv:o:", options, NULL)) != -1) { switch (c) { case 'o': output = optarg; @@ -64,23 +69,50 @@ main (int argc, char **argv) case 'v': ao_verbose = (int) strtol(optarg, NULL, 0); break; + case 'n': + nosym = 1; + break; default: usage(argv[0]); break; } } - input = argv[optind]; - if (input == NULL) + if (optind >= argc) usage(argv[0]); - if (ends_with (input, ".ihx")) - image = ao_hex_load(input, &file_symbols, &num_file_symbols); - else - image = ao_load_elf(input, &file_symbols, &num_file_symbols); + for (i = optind; i < argc; i++) { + struct ao_hex_image *image; - if (!image) - usage(argv[0]); + input = argv[i]; + + free(file_symbols); + num_file_symbols = 0; + if (ends_with (input, ".ihx")) + image = ao_hex_load(input, &file_symbols, &num_file_symbols); + else + image = ao_load_elf(input, &file_symbols, &num_file_symbols); + + if (!image) { + fprintf(stderr, "Failed to load %s\n", input); + usage(argv[0]); + } + + if (nosym) { + free(file_symbols); + file_symbols = NULL; + num_file_symbols = 0; + } + + if (full_image) { + full_image = ao_hex_image_cat(full_image, image); + if (!full_image) { + fprintf(stderr, "Can't merge image %s\n", input); + usage(argv[0]); + } + } else + full_image = image; + } if (!output) file = stdout; @@ -92,7 +124,7 @@ main (int argc, char **argv) } } - if (!ao_hex_save(file, image, file_symbols, num_file_symbols)) { + if (!ao_hex_save(file, full_image, file_symbols, num_file_symbols)) { fprintf(stderr, "%s: failed to write hex file\n", output ? output : ""); if (output) unlink(output);