Restructure "write mode" code

This commit is contained in:
MCUdude 2022-03-03 19:37:42 +01:00
parent c7174d7678
commit d9c52249a9
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; 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) { if (strcmp(argv[argc - 1], "...") == 0) {
write_mode = WRITE_MODE_FILL; write_mode = WRITE_MODE_FILL;
start_offset = 4;
len = strtoul(argv[3], &end_ptr, 0); len = strtoul(argv[3], &end_ptr, 0);
if (*end_ptr || (end_ptr == argv[3])) { if (*end_ptr || (end_ptr == argv[3])) {
avrdude_message(MSG_INFO, "%s (write ...): can't parse address \"%s\"\n", 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 { } else {
write_mode = WRITE_MODE_STANDARD; write_mode = WRITE_MODE_STANDARD;
} start_offset = 3;
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
len = argc - start_offset; 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 // Structure related to data that is being written to memory