From dca5fc92bf70b4ffd4dbccaa1229a8a28ea66c78 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Thu, 3 Mar 2022 19:37:42 +0100 Subject: [PATCH] Restructure "write mode" code --- src/term.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/term.c b/src/term.c index fc1b1069..d98f0207 100644 --- a/src/term.c +++ b/src/term.c @@ -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