Restructure "write mode" code

This commit is contained in:
MCUdude 2022-03-03 19:37:42 +01:00 committed by Joerg Wunsch
parent 4e05a8fa41
commit dca5fc92bf
1 changed files with 9 additions and 17 deletions

View File

@ -365,9 +365,16 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
return -1;
}
// Figure out how many bytes there is to write to memory
uint8_t * buf = malloc(mem->size);
if (buf == NULL) {
avrdude_message(MSG_INFO, "%s (write): out of memory\n", progname);
return -1;
}
// Find the first argument to write to flash and how many arguments to parse and write
if (strcmp(argv[argc - 1], "...") == 0) {
write_mode = WRITE_MODE_FILL;
start_offset = 4;
len = strtoul(argv[3], &end_ptr, 0);
if (*end_ptr || (end_ptr == argv[3])) {
avrdude_message(MSG_INFO, "%s (write ...): can't parse address \"%s\"\n",
@ -376,23 +383,8 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
}
} else {
write_mode = WRITE_MODE_STANDARD;
}
uint8_t * buf = malloc(mem->size);
if (buf == NULL) {
avrdude_message(MSG_INFO, "%s (write): out of memory\n", progname);
return -1;
}
if (write_mode == WRITE_MODE_STANDARD) {
start_offset = 3; // Argument number where data to write starts
start_offset = 3;
len = argc - start_offset;
} else if (write_mode == WRITE_MODE_FILL)
start_offset = 4;
else {
avrdude_message(MSG_INFO, "%s (write): invalid write mode %d\n",
progname, write_mode);
return -1;
}
// Structure related to data that is being written to memory