Add print_warn() macro and the --use-vma option
This commit is contained in:
15
src/main.c
15
src/main.c
@@ -38,13 +38,15 @@ const char *argp_program_bug_address = "<mario [dot] huettel [at] linux [dot] co
|
||||
#define ARG_KEY_LIST (4)
|
||||
#define ARG_KEY_EXPORT (5)
|
||||
#define ARG_KEY_IMPORT (6)
|
||||
#define ARG_KEY_XSD (7)
|
||||
#define ARG_KEY_USE_VMA (7)
|
||||
#define ARG_KEY_XSD (8)
|
||||
|
||||
struct command_line_options {
|
||||
bool little_endian;
|
||||
bool dry_run;
|
||||
bool verbose;
|
||||
bool print_xsd;
|
||||
bool use_vma;
|
||||
enum granularity granularity;
|
||||
enum crc_format format;
|
||||
struct crc_settings crc;
|
||||
@@ -99,6 +101,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||
case ARG_KEY_XSD:
|
||||
args->print_xsd = true;
|
||||
break;
|
||||
case ARG_KEY_USE_VMA:
|
||||
args->use_vma = true;
|
||||
break;
|
||||
case 'p':
|
||||
/* Polyniomial */
|
||||
args->crc.polynomial = strtoull(arg, &endptr, 0);
|
||||
@@ -189,6 +194,7 @@ static int parse_cmdline_options(int *argc, char ***argv, struct command_line_op
|
||||
{"export", ARG_KEY_EXPORT, "XML", 0, "Export CRCs to XML file", 3},
|
||||
{"import", ARG_KEY_IMPORT, "XML", 0, "Do not caclulate CRCs but import them from file", 3},
|
||||
{"xsd", ARG_KEY_XSD, 0, 0, "Print XSD to stdout", 0},
|
||||
{"use-vma", ARG_KEY_USE_VMA, 0, 0, "Use the VMA instead of the LMA for struct output", 2},
|
||||
/* Sentinel */
|
||||
{NULL, 0, 0, 0, NULL, 0}
|
||||
};
|
||||
@@ -214,6 +220,7 @@ static void prepare_default_opts(struct command_line_options *opts)
|
||||
opts->granularity = GRANULARITY_BYTE;
|
||||
opts->dry_run = false;
|
||||
opts->crc.xor = 0UL;
|
||||
opts->use_vma = false;
|
||||
opts->crc.polynomial = 0x104C11DB7UL;
|
||||
opts->crc.start_value = 0xFFFFFFFFUL;
|
||||
opts->crc.rev = false;
|
||||
@@ -308,7 +315,7 @@ static int check_all_sections_present(elfpatch_handle_t *ep, SlList *list)
|
||||
if (!ep)
|
||||
return -1001;
|
||||
if (!list) {
|
||||
print_err("No input sections specified.\n")
|
||||
print_err("No input sections specified.\n");
|
||||
return -1;
|
||||
}
|
||||
for (iter = list; iter; iter = sl_list_next(iter)) {
|
||||
@@ -426,6 +433,10 @@ int main(int argc, char **argv)
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (cmd_opts.use_vma && cmd_opts.format != FORMAT_STRUCT) {
|
||||
print_warn("--use-vma option only has an effect when exporting as struct output.");
|
||||
}
|
||||
|
||||
if (!cmd_opts.output_section && cmd_opts.export_xml == NULL) {
|
||||
print_err("No output section / XML export specified. Will continue but not create any output\n");
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ int xml_write_crcs_to_file(const char *path, const uint32_t *crcs, SlList *secti
|
||||
|
||||
writer = xmlNewTextWriterFilename(path, 0);
|
||||
if (!writer) {
|
||||
print_err("Cannot create XML file %s\n", path)
|
||||
ret = -1;
|
||||
print_err("Cannot create XML file %s\n", path);
|
||||
ret = -1;
|
||||
goto ret_none;
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ struct xml_crc_import *xml_import_from_file(const char *path)
|
||||
/* Get all CRCs */
|
||||
xpath_obj = xmlXPathEvalExpression(BAD_CAST "/patchelfcrc/sections/crc", xpath_ctx);
|
||||
if (xmlXPathNodeSetIsEmpty(xpath_obj->nodesetval)) {
|
||||
print_err("Internal error during read\n")
|
||||
print_err("Internal error during read\n");
|
||||
xml_crc_import_free(ret);
|
||||
ret = NULL;
|
||||
goto ret_close_doc;
|
||||
|
Reference in New Issue
Block a user