2 * Copyright © 2013 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 #include "ao-verbose.h"
26 static const struct option options[] = {
27 { .name = "verbose", .has_arg = 1, .val = 'v' },
28 { .name = "output", .has_arg = 1, .val = 'o' },
32 static void usage(char *program)
34 fprintf(stderr, "usage: %s [--verbose=<level>] [--output=<output.ihx>] <input.elf>\n", program);
39 ends_with(char *whole, char *suffix)
41 int whole_len = strlen(whole);
42 int suffix_len = strlen(suffix);
44 if (suffix_len > whole_len)
46 return strcmp(whole + whole_len - suffix_len, suffix) == 0;
50 main (int argc, char **argv)
54 struct ao_hex_image *image;
55 struct ao_sym *file_symbols;
60 while ((c = getopt_long(argc, argv, "v:o:", options, NULL)) != -1) {
66 ao_verbose = (int) strtol(optarg, NULL, 0);
78 if (ends_with (input, ".ihx"))
79 image = ao_hex_load(input, &file_symbols, &num_file_symbols);
81 image = ao_load_elf(input, &file_symbols, &num_file_symbols);
89 file = fopen(output, "w");
96 if (!ao_hex_save(file, image, file_symbols, num_file_symbols)) {
97 fprintf(stderr, "%s: failed to write hex file\n", output ? output : "<stdout>");