Use a smarter programming algorithm - read the existing data byte

first and only write the new one if it is different.

Add -n option which is a test mode in which the chip is not actually
updated.  This option does not affect writes in interactive mode.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@31 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2001-01-14 21:32:36 +00:00
parent d59f002dbf
commit 556c4e3ee1
1 changed files with 33 additions and 20 deletions

View File

@ -528,6 +528,16 @@ int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
unsigned char r; unsigned char r;
int ready; int ready;
int tries; int tries;
unsigned char b;
/*
* check to see if the write is necessary by reading the existing
* value and only write if we are changing the value
*/
b = avr_read_byte(fd, p, memtype, addr);
if (b == data) {
return 0;
}
switch (memtype) { switch (memtype) {
case AVR_FLASH_LO: case AVR_FLASH_LO:
@ -631,10 +641,7 @@ int avr_write ( int fd, struct avrpart * p, AVRMEM memtype )
/* eeprom or low byte of flash */ /* eeprom or low byte of flash */
data = buf[bi++]; data = buf[bi++];
nl = 0; nl = 0;
if (data != 0xff)
rc = avr_write_byte(fd, p, memt, i, data ); rc = avr_write_byte(fd, p, memt, i, data );
else
rc = 0;
fprintf(stderr, " \r%4u 0x%02x", i, data); fprintf(stderr, " \r%4u 0x%02x", i, data);
if (rc) { if (rc) {
fprintf(stderr, " ***failed; "); fprintf(stderr, " ***failed; ");
@ -644,10 +651,7 @@ int avr_write ( int fd, struct avrpart * p, AVRMEM memtype )
if (memtype == AVR_FLASH) { if (memtype == AVR_FLASH) {
/* high byte of flash */ /* high byte of flash */
data = buf[bi++]; data = buf[bi++];
if (data != 0xff)
rc = avr_write_byte(fd, p, AVR_FLASH_HI, i, data ); rc = avr_write_byte(fd, p, AVR_FLASH_HI, i, data );
else
rc = 0;
fprintf(stderr, " 0x%02x", data); fprintf(stderr, " 0x%02x", data);
if (rc) { if (rc) {
fprintf(stderr, " ***failed; " ); fprintf(stderr, " ***failed; " );
@ -974,10 +978,10 @@ int ihex2b ( char * infile, FILE * inf,
cksum = -cksum & 0xff; cksum = -cksum & 0xff;
if (cksum != b) { if (cksum != b) {
fprintf(stderr, fprintf(stderr,
"%s: cksum error for line %d of \"%s\": computed=%02x " "%s: WARNING: cksum error for line %d of \"%s\": computed=%02x "
"found=%02x\n", "found=%02x\n",
progname, lineno, infile, cksum, b); progname, lineno, infile, cksum, b);
return -1; /* return -1; */
} }
if (rectype == 1) { if (rectype == 1) {
@ -1763,6 +1767,7 @@ int main ( int argc, char * argv [] )
char * parallel; /* parallel port device */ char * parallel; /* parallel port device */
int interactive; /* 1=enter interactive command mode, 0=don't */ int interactive; /* 1=enter interactive command mode, 0=don't */
FILEFMT filefmt; /* FMT_AUTO, FMT_IHEX, FMT_SREC, FMT_RBIN */ FILEFMT filefmt; /* FMT_AUTO, FMT_IHEX, FMT_SREC, FMT_RBIN */
int nowrite; /* don't actually write anything to the chip */
readorwrite = 0; readorwrite = 0;
parallel = DEFAULT_PARALLEL; parallel = DEFAULT_PARALLEL;
@ -1775,6 +1780,7 @@ int main ( int argc, char * argv [] )
ovsigck = 0; ovsigck = 0;
interactive = 0; interactive = 0;
filefmt = FMT_AUTO; filefmt = FMT_AUTO;
nowrite = 0;
progname = rindex(argv[0],'/'); progname = rindex(argv[0],'/');
if (progname) if (progname)
@ -1822,7 +1828,7 @@ int main ( int argc, char * argv [] )
/* /*
* process command line arguments * process command line arguments
*/ */
while ((ch = getopt(argc,argv,"?cef:Fi:m:o:p:P:")) != -1) { while ((ch = getopt(argc,argv,"?cef:Fi:m:no:p:P:")) != -1) {
switch (ch) { switch (ch) {
case 'm': /* select memory type to operate on */ case 'm': /* select memory type to operate on */
@ -1846,6 +1852,10 @@ int main ( int argc, char * argv [] )
ovsigck = 1; ovsigck = 1;
break; break;
case 'n':
nowrite = 1;
break;
case 'o': /* specify output file */ case 'o': /* specify output file */
if (inputf || interactive) { if (inputf || interactive) {
fprintf(stderr,"%s: -i, -o, and -c are incompatible\n\n", progname); fprintf(stderr,"%s: -i, -o, and -c are incompatible\n\n", progname);
@ -2110,15 +2120,18 @@ int main ( int argc, char * argv [] )
*/ */
fprintf(stderr, "%s: writing %s:\n", fprintf(stderr, "%s: writing %s:\n",
progname, memtypestr(memtype)); progname, memtypestr(memtype));
#if 0
if (!nowrite) {
rc = avr_write ( fd, p, memtype ); rc = avr_write ( fd, p, memtype );
#else }
else {
/* /*
* test mode, don't actually write to the chip, output the buffer * test mode, don't actually write to the chip, output the buffer
* to stdout in intel hex instead * to stdout in intel hex instead
*/ */
rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, memtype); rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, memtype);
#endif }
if (rc) { if (rc) {
fprintf ( stderr, "%s: failed to write flash memory, rc=%d\n", fprintf ( stderr, "%s: failed to write flash memory, rc=%d\n",
progname, rc ); progname, rc );