Compare commits
3 Commits
5067527394
...
dc85955859
Author | SHA1 | Date | |
---|---|---|---|
dc85955859 | |||
5ec8d8d90b | |||
e33c48618b |
40
src/main.c
40
src/main.c
@ -108,11 +108,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
|||||||
/* Polyniomial */
|
/* Polyniomial */
|
||||||
args->crc.polynomial = strtoull(arg, &endptr, 0);
|
args->crc.polynomial = strtoull(arg, &endptr, 0);
|
||||||
if (endptr == arg) {
|
if (endptr == arg) {
|
||||||
if ((looked_up_crc = lookup_named_crc(arg))) {
|
looked_up_crc = lookup_named_crc(arg);
|
||||||
|
if (looked_up_crc)
|
||||||
memcpy(&args->crc, &looked_up_crc->settings, sizeof(struct crc_settings));
|
memcpy(&args->crc, &looked_up_crc->settings, sizeof(struct crc_settings));
|
||||||
} else {
|
else
|
||||||
argp_error(state, "Error parsing polynomial: %s\n", arg);
|
argp_error(state, "Error parsing polynomial: %s\n", arg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
@ -261,28 +261,22 @@ static void print_verbose_start_info(const struct command_line_options *cmd_opts
|
|||||||
print_debug("CRC length: %d\n", crc_len_from_poly(cmd_opts->crc.polynomial));
|
print_debug("CRC length: %d\n", crc_len_from_poly(cmd_opts->crc.polynomial));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_opts->elf_path) {
|
if (cmd_opts->elf_path)
|
||||||
print_debug("ELF file: %s\n", cmd_opts->elf_path);
|
print_debug("ELF file: %s\n", cmd_opts->elf_path);
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_opts->output_section) {
|
if (cmd_opts->output_section)
|
||||||
print_debug("Output section: %s\n", cmd_opts->output_section);
|
print_debug("Output section: %s\n", cmd_opts->output_section);
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_opts->export_xml) {
|
if (cmd_opts->export_xml)
|
||||||
print_debug("Export CRCs to '%s'\n", cmd_opts->export_xml);
|
print_debug("Export CRCs to '%s'\n", cmd_opts->export_xml);
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_opts->import_xml) {
|
if (cmd_opts->import_xml)
|
||||||
print_debug("Import CRCs from '%s'\n", cmd_opts->import_xml);
|
print_debug("Import CRCs from '%s'\n", cmd_opts->import_xml);
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_opts->section_list) {
|
if (cmd_opts->section_list) {
|
||||||
for (list_iter = cmd_opts->section_list, i = 1; list_iter; list_iter = sl_list_next(list_iter), i++) {
|
for (list_iter = cmd_opts->section_list, i = 1; list_iter; list_iter = sl_list_next(list_iter), i++)
|
||||||
print_debug("Input section [%d]: \"%s\"\n", i, (const char *)list_iter->data);
|
print_debug("Input section [%d]: \"%s\"\n", i, (const char *)list_iter->data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_cmd_args(struct command_line_options *opts)
|
static void free_cmd_args(struct command_line_options *opts)
|
||||||
@ -322,6 +316,7 @@ static int check_all_sections_present(elfpatch_handle_t *ep, SlList *list)
|
|||||||
sec_name = (const char *)iter->data;
|
sec_name = (const char *)iter->data;
|
||||||
if (!sec_name)
|
if (!sec_name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (elf_patch_check_for_section(ep, sec_name)) {
|
if (elf_patch_check_for_section(ep, sec_name)) {
|
||||||
print_err("Cannot find section '%s'\n", sec_name);
|
print_err("Cannot find section '%s'\n", sec_name);
|
||||||
ret = -2;
|
ret = -2;
|
||||||
@ -340,7 +335,8 @@ static int check_all_sections_present(elfpatch_handle_t *ep, SlList *list)
|
|||||||
* @param opts Command line options. Used for CRC generation
|
* @param opts Command line options. Used for CRC generation
|
||||||
* @return CRC data
|
* @return CRC data
|
||||||
*/
|
*/
|
||||||
static struct crc_import_data *compute_crcs(elfpatch_handle_t *ep, SlList *list, const struct command_line_options *opts)
|
static struct crc_import_data *compute_crcs(elfpatch_handle_t *ep, SlList *list,
|
||||||
|
const struct command_line_options *opts)
|
||||||
{
|
{
|
||||||
SlList *iter;
|
SlList *iter;
|
||||||
const char *sec_name;
|
const char *sec_name;
|
||||||
@ -423,6 +419,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
prepare_default_opts(&cmd_opts);
|
prepare_default_opts(&cmd_opts);
|
||||||
parse_cmdline_options(&argc, &argv, &cmd_opts);
|
parse_cmdline_options(&argc, &argv, &cmd_opts);
|
||||||
|
|
||||||
if (cmd_opts.print_xsd) {
|
if (cmd_opts.print_xsd) {
|
||||||
xml_print_xsd();
|
xml_print_xsd();
|
||||||
goto free_cmds;
|
goto free_cmds;
|
||||||
@ -430,6 +427,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (cmd_opts.verbose || cmd_opts.dry_run)
|
if (cmd_opts.verbose || cmd_opts.dry_run)
|
||||||
reporting_enable_verbose();
|
reporting_enable_verbose();
|
||||||
|
|
||||||
print_verbose_start_info(&cmd_opts);
|
print_verbose_start_info(&cmd_opts);
|
||||||
|
|
||||||
if (cmd_opts.list) {
|
if (cmd_opts.list) {
|
||||||
@ -448,13 +446,11 @@ int main(int argc, char **argv)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_opts.use_vma && cmd_opts.format != FORMAT_STRUCT) {
|
if (cmd_opts.use_vma && cmd_opts.format != FORMAT_STRUCT)
|
||||||
print_warn("--use-vma option only has an effect when exporting as struct output.\n");
|
print_warn("--use-vma option only has an effect when exporting as struct output.\n");
|
||||||
}
|
|
||||||
|
|
||||||
if (!cmd_opts.output_section && cmd_opts.export_xml == NULL) {
|
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");
|
print_err("No output section / XML export specified. Will continue but not create any output\n");
|
||||||
}
|
|
||||||
|
|
||||||
/* Do error printing if using a reversed polynomial. It is not implemented yet! */
|
/* Do error printing if using a reversed polynomial. It is not implemented yet! */
|
||||||
if (cmd_opts.crc.rev) {
|
if (cmd_opts.crc.rev) {
|
||||||
@ -481,13 +477,11 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Compute CRCs over sections */
|
/* Compute CRCs over sections */
|
||||||
crc_data = compute_crcs(ep, cmd_opts.section_list, &cmd_opts);
|
crc_data = compute_crcs(ep, cmd_opts.section_list, &cmd_opts);
|
||||||
if (!crc_data) {
|
if (!crc_data)
|
||||||
goto ret_close_elf;
|
goto ret_close_elf;
|
||||||
}
|
|
||||||
|
|
||||||
if (reporting_get_verbosity()) {
|
if (reporting_get_verbosity())
|
||||||
print_crcs(crc_data);
|
print_crcs(crc_data);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
crc_data = xml_import_from_file(cmd_opts.import_xml);
|
crc_data = xml_import_from_file(cmd_opts.import_xml);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
.xor = outxor, \
|
.xor = outxor, \
|
||||||
.start_value = init, \
|
.start_value = init, \
|
||||||
.rev = reverse \
|
.rev = reverse \
|
||||||
}}
|
} }
|
||||||
|
|
||||||
const struct named_crc predefined_crc_table[] = {
|
const struct named_crc predefined_crc_table[] = {
|
||||||
NAMED_CRC("crc-8", 0x107, false, 0x00, 0x00),
|
NAMED_CRC("crc-8", 0x107, false, 0x00, 0x00),
|
||||||
@ -70,7 +70,7 @@ const struct named_crc predefined_crc_table[] = {
|
|||||||
NAMED_CRC("jamcrc", 0x104C11DB7, true, 0xFFFFFFFF, 0x00000000),
|
NAMED_CRC("jamcrc", 0x104C11DB7, true, 0xFFFFFFFF, 0x00000000),
|
||||||
NAMED_CRC("xfer", 0x1000000AF, false, 0x00000000, 0x00000000),
|
NAMED_CRC("xfer", 0x1000000AF, false, 0x00000000, 0x00000000),
|
||||||
/* SENTINEL */
|
/* SENTINEL */
|
||||||
{.name = NULL, .settings = {0, 0, 0, false}},
|
{ .name = NULL, .settings = {0, 0, 0, false} },
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct named_crc *reverse_lookup_named_crc(const struct crc_settings *settings)
|
const struct named_crc *reverse_lookup_named_crc(const struct crc_settings *settings)
|
||||||
|
20
src/xml.c
20
src/xml.c
@ -30,9 +30,8 @@ int xml_write_crcs_to_file(const char *path, const struct crc_import_data *crc_d
|
|||||||
const struct crc_entry *entry;
|
const struct crc_entry *entry;
|
||||||
size_t index;
|
size_t index;
|
||||||
|
|
||||||
if (!path || !crc_data) {
|
if (!path || !crc_data)
|
||||||
return -1000;
|
return -1000;
|
||||||
}
|
|
||||||
|
|
||||||
writer = xmlNewTextWriterFilename(path, 0);
|
writer = xmlNewTextWriterFilename(path, 0);
|
||||||
if (!writer) {
|
if (!writer) {
|
||||||
@ -67,7 +66,9 @@ int xml_write_crcs_to_file(const char *path, const struct crc_import_data *crc_d
|
|||||||
xmlTextWriterStartElement(writer, BAD_CAST "sections");
|
xmlTextWriterStartElement(writer, BAD_CAST "sections");
|
||||||
|
|
||||||
/* Output all section CRCs */
|
/* Output all section CRCs */
|
||||||
for (entry_iter = crc_data->crc_entries, index = 0u; entry_iter; entry_iter = sl_list_next(entry_iter), index++) {
|
for (entry_iter = crc_data->crc_entries, index = 0u;
|
||||||
|
entry_iter;
|
||||||
|
entry_iter = sl_list_next(entry_iter), index++) {
|
||||||
entry = (const struct crc_entry *)entry_iter->data;
|
entry = (const struct crc_entry *)entry_iter->data;
|
||||||
xmlTextWriterStartElement(writer, BAD_CAST "crc");
|
xmlTextWriterStartElement(writer, BAD_CAST "crc");
|
||||||
xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", entry->name);
|
xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", entry->name);
|
||||||
@ -222,7 +223,8 @@ static int convert_number_string_to_uint(const char *data, uint64_t *output)
|
|||||||
* @return 0 if successful
|
* @return 0 if successful
|
||||||
* @return negative in case of an error
|
* @return negative in case of an error
|
||||||
*/
|
*/
|
||||||
static int get_uint64_from_xpath_content(const char *xpath, xmlXPathContextPtr xpath_ctx, uint64_t *output, bool required)
|
static int get_uint64_from_xpath_content(const char *xpath, xmlXPathContextPtr xpath_ctx,
|
||||||
|
uint64_t *output, bool required)
|
||||||
{
|
{
|
||||||
const char *data;
|
const char *data;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -245,7 +247,8 @@ static int get_uint64_from_xpath_content(const char *xpath, xmlXPathContextPtr x
|
|||||||
* @return 0 if successful
|
* @return 0 if successful
|
||||||
* @return negative in case of an error
|
* @return negative in case of an error
|
||||||
*/
|
*/
|
||||||
static int get_uint32_from_xpath_content(const char *xpath, xmlXPathContextPtr xpath_ctx, uint32_t *output, bool required)
|
static int get_uint32_from_xpath_content(const char *xpath, xmlXPathContextPtr xpath_ctx,
|
||||||
|
uint32_t *output, bool required)
|
||||||
{
|
{
|
||||||
const char *data;
|
const char *data;
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
@ -359,10 +362,10 @@ struct crc_import_data *xml_import_from_file(const char *path)
|
|||||||
print_err("Error reading XML file: %s\n", path);
|
print_err("Error reading XML file: %s\n", path);
|
||||||
goto ret_none;
|
goto ret_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
root_node = xmlDocGetRootElement(doc);
|
root_node = xmlDocGetRootElement(doc);
|
||||||
if (!root_node) {
|
if (!root_node)
|
||||||
goto ret_close_doc;
|
goto ret_close_doc;
|
||||||
}
|
|
||||||
|
|
||||||
/* Validate the document */
|
/* Validate the document */
|
||||||
if (!validate_xml_doc(doc)) {
|
if (!validate_xml_doc(doc)) {
|
||||||
@ -372,9 +375,8 @@ struct crc_import_data *xml_import_from_file(const char *path)
|
|||||||
|
|
||||||
/* Get xpath context */
|
/* Get xpath context */
|
||||||
xpath_ctx = xmlXPathNewContext(doc);
|
xpath_ctx = xmlXPathNewContext(doc);
|
||||||
if (!xpath_ctx) {
|
if (!xpath_ctx)
|
||||||
goto ret_close_doc;
|
goto ret_close_doc;
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the version number and print error in case of incompatibility. Continue either way */
|
/* Get the version number and print error in case of incompatibility. Continue either way */
|
||||||
cptr = (char *)xmlGetProp(root_node, BAD_CAST "version");
|
cptr = (char *)xmlGetProp(root_node, BAD_CAST "version");
|
||||||
|
Loading…
Reference in New Issue
Block a user