From 6cb270c952ddab3e8c4b6cc04fb95f9040e48157 Mon Sep 17 00:00:00 2001 From: bsd Date: Mon, 15 Jan 2001 04:18:39 +0000 Subject: [PATCH] Automatically verify on-chip data with what we just programmed. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@34 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrprog.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 123 insertions(+), 20 deletions(-) diff --git a/avrprog.c b/avrprog.c index aad8b43c..604dff12 100644 --- a/avrprog.c +++ b/avrprog.c @@ -1745,6 +1745,66 @@ int go_interactive ( int fd, struct avrpart * p ) +int avr_initmem ( struct avrpart * p ) +{ + p->flash = (unsigned char *) malloc(p->flash_size); + if (p->flash == NULL) { + fprintf(stderr, "%s: can't alloc buffer for flash size of %d bytes\n", + progname, p->flash_size); + exit(1); + } + + p->eeprom = (unsigned char *) malloc(p->eeprom_size); + if (p->eeprom == NULL) { + fprintf(stderr, "%s: can't alloc buffer for eeprom size of %d bytes\n", + progname, p->eeprom_size); + exit(1); + } + + return 0; +} + + +int verify_data(struct avrpart * p, struct avrpart * v, AVRMEM memtype) +{ + int i; + unsigned char * buf1, * buf2; + int size; + + switch (memtype) { + case AVR_FLASH: + buf1 = p->flash; + buf2 = v->flash; + size = p->flash_size; + break; + + case AVR_EEPROM: + buf1 = p->eeprom; + buf2 = v->eeprom; + size = p->eeprom_size; + break; + + default: + fprintf(stderr, "%s: invalid memory type = %d for data verification\n", + progname, memtype); + return -1; + } + + for (i=0; ie_readback[0], p->e_readback[1]); fprintf(stderr, "\n"); - p->flash = (unsigned char *) malloc(p->flash_size); - if (p->flash == NULL) { - fprintf(stderr, "%s: can't alloc buffer for flash size of %d bytes\n", - progname, p->flash_size); - exit(1); - } - - p->eeprom = (unsigned char *) malloc(p->eeprom_size); - if (p->eeprom == NULL) { - fprintf(stderr, "%s: can't alloc buffer for eeprom size of %d bytes\n", - progname, p->eeprom_size); - exit(1); - } - /* * open the parallel port */ @@ -2091,16 +2158,18 @@ int main ( int argc, char * argv [] ) /* * read out the specified device memory and write it to a file */ - fprintf ( stderr, "%s: reading %s memory:\n", - progname, memtypestr(memtype) ); + fprintf(stderr, "%s: reading %s memory:\n", + progname, memtypestr(memtype)); rc = avr_read ( fd, p, memtype ); if (rc) { - fprintf ( stderr, "%s: failed to read all of %s memory, rc=%d\n", - progname, memtypestr(memtype), rc ); + fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", + progname, memtypestr(memtype), rc); exitrc = 1; goto main_exit; } + fprintf(stderr, "%s: writing output file \"%s\"\n", + progname, outputf); rc = fileio(FIO_WRITE, outputf, filefmt, p, memtype); if (rc < 0) { fprintf(stderr, "%s: terminating\n", progname); @@ -2114,6 +2183,8 @@ int main ( int argc, char * argv [] ) * write the selected device memory using data from a file; first * read the data from the specified file */ + fprintf(stderr, "%s: reading input file \"%s\"\n", + progname, inputf); rc = fileio(FIO_READ, inputf, filefmt, p, memtype ); if (rc < 0) { fprintf(stderr, "%s: terminating\n", progname); @@ -2145,8 +2216,40 @@ int main ( int argc, char * argv [] ) exitrc = 1; goto main_exit; } + } + if (!doread && verify) { + /* + * verify that the in memory file (p->flash or p->eeprom) is the + * same as what is on the chip + */ + fprintf(stderr, "%s: verifying %s memory against %s:\n", + progname, memtypestr(memtype), inputf); + fprintf(stderr, "%s: reading on-chip %s data:\n", + progname, memtypestr(memtype)); + rc = avr_read ( fd, v, memtype ); + if (rc) { + fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", + progname, memtypestr(memtype), rc); + exitrc = 1; + goto main_exit; + } + + fprintf(stderr, "%s: verifying\n", progname); + rc = verify_data(p, v, memtype); + if (rc) { + fprintf(stderr, "%s: verification error; content mismatch\n", + progname); + exitrc = 1; + goto main_exit; + } + + fprintf(stderr, "%s: data verified\n", progname); + } + + + main_exit: /*