mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-09-28 23:15:27 +00:00
Makefile : use gzip -f for man page installation so that we don't get
prompted. avr.c avr.h fileio.c term.c : Change the avrpart data structure so that the typedef AVRMEM is used as an index into an array for the sizes of the memory types and also for pointers to buffers that represent the chip data for that memory type. This removes a lot of conditional code of the form: switch (memtype) { case AVR_FLASH : ... } Also, re-code avr_read_byte() and avr_write_byte() to properly handle the flash memory type without having to tell them whether they should program the high byte or the low byte - figure that out from the address itself. For flash memory type, these routines now take the actual byte address instead of the word address. This _greatly_ simplifies many otherwise simple operations, such a reading or writing a range of memory, by not having to worry about whether the address starts on an odd byte or an even byte. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@45 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
86
term.c
86
term.c
@@ -196,8 +196,7 @@ int hexdump_buf ( FILE * f, int startaddr, char * buf, int len )
|
||||
int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
{
|
||||
char * e;
|
||||
int i, j, l;
|
||||
unsigned short daddr;
|
||||
int i, l;
|
||||
char * buf;
|
||||
int maxsize;
|
||||
static AVRMEM memtype=AVR_FLASH;
|
||||
@@ -241,12 +240,7 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
switch (memtype) {
|
||||
case AVR_FLASH : maxsize = p->flash_size; break;
|
||||
case AVR_EEPROM : maxsize = p->eeprom_size; break;
|
||||
default : return -1; /* this can't happen, but is silences gcc
|
||||
warnings */
|
||||
}
|
||||
maxsize = p->memsize[memtype];
|
||||
|
||||
if (addr > maxsize) {
|
||||
fprintf(stderr,
|
||||
@@ -265,29 +259,8 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
return -1;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
daddr = addr;
|
||||
if (memtype == AVR_FLASH) {
|
||||
daddr = addr / 2;
|
||||
if (addr & 0x01) {
|
||||
buf[j++] = avr_read_byte( fd, p, AVR_FLASH_HI, daddr);
|
||||
daddr++;
|
||||
}
|
||||
}
|
||||
|
||||
i = daddr;
|
||||
while (j < len) {
|
||||
if (memtype == AVR_FLASH) {
|
||||
buf[j++] = avr_read_byte( fd, p, AVR_FLASH_LO, i);
|
||||
if (j < len) {
|
||||
buf[j++] = avr_read_byte( fd, p, AVR_FLASH_HI, i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
buf[j++] = avr_read_byte( fd, p, AVR_EEPROM, i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
for (i=0; i<len; i++)
|
||||
buf[i] = avr_read_byte(fd, p, memtype, addr+i);
|
||||
|
||||
hexdump_buf(stdout, addr, buf, len);
|
||||
|
||||
@@ -301,10 +274,10 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
{
|
||||
char * e;
|
||||
int i, j, l;
|
||||
int i, l;
|
||||
int len, maxsize;
|
||||
AVRMEM memtype;
|
||||
unsigned short addr, daddr;
|
||||
unsigned short addr;
|
||||
char * buf;
|
||||
int rc;
|
||||
|
||||
@@ -317,11 +290,9 @@ int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
l = strlen(argv[1]);
|
||||
if (strncasecmp(argv[1],"flash",l)==0) {
|
||||
memtype = AVR_FLASH;
|
||||
maxsize = p->flash_size;
|
||||
}
|
||||
else if (strncasecmp(argv[1],"eeprom",l)==0) {
|
||||
memtype = AVR_EEPROM;
|
||||
maxsize = p->eeprom_size;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s (write): invalid memory type \"%s\"\n",
|
||||
@@ -329,6 +300,8 @@ int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
return -1;
|
||||
}
|
||||
|
||||
maxsize = p->memsize[memtype];
|
||||
|
||||
addr = strtoul(argv[2], &e, 0);
|
||||
if (*e || (e == argv[2])) {
|
||||
fprintf(stderr, "%s (write): can't parse address \"%s\"\n",
|
||||
@@ -369,47 +342,14 @@ int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
j = 0;
|
||||
daddr = addr;
|
||||
if (memtype == AVR_FLASH) {
|
||||
daddr = addr / 2;
|
||||
if (addr & 0x01) {
|
||||
/* handle odd numbered memory locations in the flash area */
|
||||
rc = avr_write_byte(fd, p, AVR_FLASH_HI, daddr, buf[j++]);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||
progname, buf[j-1], daddr*2+1);
|
||||
}
|
||||
daddr++;
|
||||
for (i=0; i<len; i++) {
|
||||
rc = avr_write_byte(fd, p, memtype, addr+i, buf[i]);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||
progname, buf[i], addr+i);
|
||||
}
|
||||
}
|
||||
|
||||
i = daddr;
|
||||
while (j < len) {
|
||||
if (memtype == AVR_FLASH) {
|
||||
rc = avr_write_byte( fd, p, AVR_FLASH_LO, i, buf[j++]);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||
progname, buf[j-1], i*2);
|
||||
}
|
||||
if (j < len) {
|
||||
rc = avr_write_byte( fd, p, AVR_FLASH_HI, i, buf[j++]);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||
progname, buf[j-1], i*2+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
rc = avr_write_byte( fd, p, AVR_EEPROM, i, buf[j++]);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||
progname, buf[j-1], i);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
|
Reference in New Issue
Block a user