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:
parent
af8d44bf4b
commit
fe4bb95f85
2
Makefile
2
Makefile
|
@ -46,5 +46,5 @@ ${BINDIR}/${TARGET} : ${TARGET}
|
||||||
|
|
||||||
${MANDIR}/${MANUAL}.gz : ${MANUAL}
|
${MANDIR}/${MANUAL}.gz : ${MANUAL}
|
||||||
${INSTALL_MANUAL} ${MANUAL} ${MANDIR}
|
${INSTALL_MANUAL} ${MANUAL} ${MANDIR}
|
||||||
gzip ${MANDIR}/${MANUAL}
|
gzip -f ${MANDIR}/${MANUAL}
|
||||||
|
|
||||||
|
|
256
avr.c
256
avr.c
|
@ -47,26 +47,26 @@ extern char progbuf[];
|
||||||
/* Need to add information for 2323, 2343, and 4414 */
|
/* Need to add information for 2323, 2343, and 4414 */
|
||||||
|
|
||||||
struct avrpart parts[] = {
|
struct avrpart parts[] = {
|
||||||
{ "AT90S1200", "1200", 1024, 64, 0xff, { 0x00, 0xff },
|
{ "AT90S1200", "1200", { 64, 1024 }, 0xff, { 0x00, 0xff },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S2313", "2313", 2048, 128, 0x7f, { 0x80, 0x7f },
|
{ "AT90S2313", "2313", { 128, 2048 }, 0x7f, { 0x80, 0x7f },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S2333", "2333", 2048, 128, 0xff, { 0x00, 0xff },
|
{ "AT90S2333", "2333", { 128, 2048 }, 0xff, { 0x00, 0xff },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S4433", "4433", 4096, 256, 0xff, { 0x00, 0xff },
|
{ "AT90S4433", "4433", { 256, 4096 }, 0xff, { 0x00, 0xff },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S4434", "4434", 4096, 256, 0xff, { 0x00, 0xff },
|
{ "AT90S4434", "4434", { 256, 4096 }, 0xff, { 0x00, 0xff },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S8515", "8515", 8192, 512, 0x7f, { 0x80, 0x7f },
|
{ "AT90S8515", "8515", { 512, 8192 }, 0x7f, { 0x80, 0x7f },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
|
|
||||||
{ "AT90S8535", "8535", 8192, 512, 0xff, { 0x00, 0xff },
|
{ "AT90S8535", "8535", { 512, 8192 }, 0xff, { 0x00, 0xff },
|
||||||
9000, 20000, 20000, NULL, NULL },
|
9000, 20000, 20000, { NULL, NULL } },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define N_AVRPARTS (sizeof(parts)/sizeof(struct avrpart))
|
#define N_AVRPARTS (sizeof(parts)/sizeof(struct avrpart))
|
||||||
|
@ -169,27 +169,20 @@ int avr_cmd ( int fd, unsigned char cmd[4], unsigned char res[4] )
|
||||||
unsigned char avr_read_byte ( int fd, struct avrpart * p,
|
unsigned char avr_read_byte ( int fd, struct avrpart * p,
|
||||||
AVRMEM memtype, unsigned short addr )
|
AVRMEM memtype, unsigned short addr )
|
||||||
{
|
{
|
||||||
|
unsigned short offset;
|
||||||
unsigned char cmd[4];
|
unsigned char cmd[4];
|
||||||
unsigned char res[4];
|
unsigned char res[4];
|
||||||
|
/* order here is very important, AVR_EEPROM, AVR_FLASH, AVR_FLASH+1 */
|
||||||
|
static unsigned char cmdbyte[3] = { 0xa0, 0x20, 0x28 };
|
||||||
|
|
||||||
switch (memtype) {
|
offset = 0;
|
||||||
case AVR_FLASH_LO:
|
|
||||||
cmd[0] = 0x20;
|
if (memtype == AVR_FLASH) {
|
||||||
break;
|
offset = addr & 0x01;
|
||||||
case AVR_FLASH_HI:
|
addr = addr / 2;
|
||||||
cmd[0] = 0x28;
|
|
||||||
break;
|
|
||||||
case AVR_EEPROM:
|
|
||||||
cmd[0] = 0xa0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr,
|
|
||||||
"%s: avr_read_byte(); internal error: invalid memtype=%d\n",
|
|
||||||
progname, memtype);
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd[0] = cmdbyte[memtype + offset];
|
||||||
cmd[1] = addr >> 8; /* high order bits of address */
|
cmd[1] = addr >> 8; /* high order bits of address */
|
||||||
cmd[2] = addr & 0x0ff; /* low order bits of address */
|
cmd[2] = addr & 0x0ff; /* low order bits of address */
|
||||||
cmd[3] = 0; /* don't care */
|
cmd[3] = 0; /* don't care */
|
||||||
|
@ -208,60 +201,23 @@ unsigned char avr_read_byte ( int fd, struct avrpart * p,
|
||||||
*/
|
*/
|
||||||
int avr_read ( int fd, struct avrpart * p, AVRMEM memtype )
|
int avr_read ( int fd, struct avrpart * p, AVRMEM memtype )
|
||||||
{
|
{
|
||||||
unsigned char rbyte, memt;
|
unsigned char rbyte;
|
||||||
unsigned short n, start, end, i, bi;
|
unsigned short i;
|
||||||
unsigned char * buf;
|
unsigned char * buf;
|
||||||
int bufsize;
|
int size;
|
||||||
|
|
||||||
start = 0;
|
buf = p->mem[memtype];
|
||||||
|
size = p->memsize[memtype];
|
||||||
|
|
||||||
switch (memtype) {
|
for (i=0; i<size; i++) {
|
||||||
case AVR_FLASH :
|
rbyte = avr_read_byte(fd, p, memtype, i);
|
||||||
memt = AVR_FLASH_LO;
|
|
||||||
buf = p->flash;
|
|
||||||
n = p->flash_size/2;
|
|
||||||
bufsize = p->flash_size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AVR_EEPROM :
|
|
||||||
memt = memtype;
|
|
||||||
buf = p->eeprom;
|
|
||||||
n = p->eeprom_size;
|
|
||||||
bufsize = p->eeprom_size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: avr_read(); internal error: invalid memtype=%d\n",
|
|
||||||
progname, memtype);
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
end = start+n;
|
|
||||||
|
|
||||||
bi = 0;
|
|
||||||
|
|
||||||
for (i=start; i<end; i++) {
|
|
||||||
/* eeprom or low byte of flash */
|
|
||||||
rbyte = avr_read_byte(fd, p, memt, i);
|
|
||||||
fprintf ( stderr, " \r%4u 0x%02x", i, rbyte );
|
fprintf ( stderr, " \r%4u 0x%02x", i, rbyte );
|
||||||
if (bi < bufsize) {
|
buf[i] = rbyte;
|
||||||
buf[bi++] = rbyte;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memtype == AVR_FLASH) {
|
|
||||||
/* flash high byte */
|
|
||||||
rbyte = avr_read_byte(fd, p, AVR_FLASH_HI, i);
|
|
||||||
fprintf ( stderr, " 0x%02x", rbyte );
|
|
||||||
if (bi < bufsize) {
|
|
||||||
buf[bi++] = rbyte;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf ( stderr, "\n" );
|
fprintf ( stderr, "\n" );
|
||||||
|
|
||||||
return bi;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,11 +227,16 @@ int avr_read ( int fd, struct avrpart * p, AVRMEM memtype )
|
||||||
int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
|
int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
|
||||||
unsigned short addr, unsigned char data )
|
unsigned short addr, unsigned char data )
|
||||||
{
|
{
|
||||||
unsigned char cmd[4], res[4];
|
unsigned char cmd[4];
|
||||||
|
unsigned char res[4];
|
||||||
unsigned char r;
|
unsigned char r;
|
||||||
int ready;
|
int ready;
|
||||||
int tries;
|
int tries;
|
||||||
unsigned char b;
|
unsigned char b;
|
||||||
|
unsigned short offset;
|
||||||
|
unsigned short caddr;
|
||||||
|
/* order here is very important, AVR_EEPROM, AVR_FLASH, AVR_FLASH+1 */
|
||||||
|
static unsigned char cmdbyte[3] = { 0xc0, 0x40, 0x48 };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check to see if the write is necessary by reading the existing
|
* check to see if the write is necessary by reading the existing
|
||||||
|
@ -286,26 +247,17 @@ int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (memtype) {
|
offset = 0;
|
||||||
case AVR_FLASH_LO:
|
|
||||||
cmd[0] = 0x40;
|
caddr = addr;
|
||||||
break;
|
if (memtype == AVR_FLASH) {
|
||||||
case AVR_FLASH_HI:
|
offset = addr & 0x01;
|
||||||
cmd[0] = 0x48;
|
caddr = addr / 2;
|
||||||
break;
|
|
||||||
case AVR_EEPROM:
|
|
||||||
cmd[0] = 0xc0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr,
|
|
||||||
"%s: avr_write_byte(); internal error: invalid memtype=%d\n",
|
|
||||||
progname, memtype);
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd[1] = addr >> 8; /* high order bits of address */
|
cmd[0] = cmdbyte[memtype + offset];
|
||||||
cmd[2] = addr & 0x0ff; /* low order bits of address */
|
cmd[1] = caddr >> 8; /* high order bits of address */
|
||||||
|
cmd[2] = caddr & 0x0ff; /* low order bits of address */
|
||||||
cmd[3] = data; /* data */
|
cmd[3] = data; /* data */
|
||||||
|
|
||||||
avr_cmd(fd, cmd, res);
|
avr_cmd(fd, cmd, res);
|
||||||
|
@ -355,83 +307,39 @@ int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
|
||||||
*/
|
*/
|
||||||
int avr_write ( int fd, struct avrpart * p, AVRMEM memtype, int size )
|
int avr_write ( int fd, struct avrpart * p, AVRMEM memtype, int size )
|
||||||
{
|
{
|
||||||
unsigned char data, memt;
|
|
||||||
unsigned short start, end, i, bi;
|
|
||||||
int nl;
|
|
||||||
int rc;
|
int rc;
|
||||||
unsigned char * buf;
|
|
||||||
int bufsize;
|
|
||||||
int wsize;
|
int wsize;
|
||||||
|
unsigned char * buf;
|
||||||
|
unsigned short i;
|
||||||
|
unsigned char data;
|
||||||
|
|
||||||
start = 0;
|
buf = p->mem[memtype];
|
||||||
|
wsize = p->memsize[memtype];
|
||||||
switch (memtype) {
|
|
||||||
case AVR_FLASH :
|
|
||||||
buf = p->flash;
|
|
||||||
bufsize = p->flash_size;
|
|
||||||
wsize = bufsize;
|
|
||||||
if (size < wsize) {
|
if (size < wsize) {
|
||||||
bufsize = size;
|
wsize = size;
|
||||||
}
|
}
|
||||||
end = start+bufsize/2;
|
else if (size > wsize) {
|
||||||
memt = AVR_FLASH_LO;
|
|
||||||
break;
|
|
||||||
case AVR_EEPROM :
|
|
||||||
buf = p->eeprom;
|
|
||||||
bufsize = p->eeprom_size;
|
|
||||||
wsize = bufsize;
|
|
||||||
if (size < wsize) {
|
|
||||||
bufsize = size;
|
|
||||||
}
|
|
||||||
end = start+bufsize;
|
|
||||||
memt = memtype;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: avr_write(); internal error: invalid memtype=%d\n",
|
|
||||||
progname, memtype);
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* were we asked to write out more data than the device can hold? */
|
|
||||||
if (wsize < size) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: WARNING: %d bytes requested, but memory region is only %d bytes\n"
|
"%s: WARNING: %d bytes requested, but memory region is only %d bytes\n"
|
||||||
"%sOnly %d bytes will actually be written\n",
|
"%sOnly %d bytes will actually be written\n",
|
||||||
progname, size, bufsize,
|
progname, size, wsize,
|
||||||
progbuf, bufsize);
|
progbuf, wsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bi = 0;
|
for (i=0; i<wsize; i++) {
|
||||||
|
|
||||||
for (i=start; i<end; i++) {
|
|
||||||
/* eeprom or low byte of flash */
|
/* eeprom or low byte of flash */
|
||||||
data = buf[bi++];
|
data = buf[i];
|
||||||
nl = 0;
|
rc = avr_write_byte(fd, p, memtype, i, data );
|
||||||
rc = avr_write_byte(fd, p, memt, i, data );
|
|
||||||
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; ");
|
||||||
nl = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memtype == AVR_FLASH) {
|
|
||||||
/* high byte of flash */
|
|
||||||
data = buf[bi++];
|
|
||||||
rc = avr_write_byte(fd, p, AVR_FLASH_HI, i, data );
|
|
||||||
fprintf(stderr, " 0x%02x", data);
|
|
||||||
if (rc) {
|
|
||||||
fprintf(stderr, " ***failed; " );
|
|
||||||
nl = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nl)
|
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf ( stderr, "\n" );
|
fprintf ( stderr, "\n" );
|
||||||
|
|
||||||
return bi;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -570,18 +478,15 @@ char * avr_memtstr ( AVRMEM memtype )
|
||||||
|
|
||||||
int avr_initmem ( struct avrpart * p )
|
int avr_initmem ( struct avrpart * p )
|
||||||
{
|
{
|
||||||
p->flash = (unsigned char *) malloc(p->flash_size);
|
int i;
|
||||||
if (p->flash == NULL) {
|
|
||||||
fprintf(stderr, "%s: can't alloc buffer for flash size of %d bytes\n",
|
for (i=0; i<AVR_MAXMEMTYPES; i++) {
|
||||||
progname, p->flash_size);
|
p->mem[i] = (unsigned char *) malloc(p->memsize[i]);
|
||||||
|
if (p->mem[i] == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't alloc buffer for %s size of %d bytes\n",
|
||||||
|
progname, avr_memtstr(i), p->memsize[i]);
|
||||||
return -1;
|
return -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);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -598,24 +503,9 @@ int avr_verify(struct avrpart * p, struct avrpart * v, AVRMEM memtype, int size)
|
||||||
unsigned char * buf1, * buf2;
|
unsigned char * buf1, * buf2;
|
||||||
int vsize;
|
int vsize;
|
||||||
|
|
||||||
switch (memtype) {
|
buf1 = p->mem[memtype];
|
||||||
case AVR_FLASH:
|
buf2 = v->mem[memtype];
|
||||||
buf1 = p->flash;
|
vsize = p->memsize[memtype];
|
||||||
buf2 = v->flash;
|
|
||||||
vsize = p->flash_size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AVR_EEPROM:
|
|
||||||
buf1 = p->eeprom;
|
|
||||||
buf2 = v->eeprom;
|
|
||||||
vsize = p->eeprom_size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: invalid memory type = %d for data verification\n",
|
|
||||||
progname, memtype);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vsize < size) {
|
if (vsize < size) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -654,8 +544,8 @@ void avr_display ( FILE * f, struct avrpart * p, char * prefix )
|
||||||
"%sFlash Polled Readback = 0x%02x\n"
|
"%sFlash Polled Readback = 0x%02x\n"
|
||||||
"%sEEPROM Polled Readback = 0x%02x, 0x%02x\n",
|
"%sEEPROM Polled Readback = 0x%02x, 0x%02x\n",
|
||||||
prefix, p->partdesc,
|
prefix, p->partdesc,
|
||||||
prefix, p->flash_size,
|
prefix, p->memsize[AVR_FLASH],
|
||||||
prefix, p->eeprom_size,
|
prefix, p->memsize[AVR_EEPROM],
|
||||||
prefix, p->min_write_delay, p->max_write_delay,
|
prefix, p->min_write_delay, p->max_write_delay,
|
||||||
prefix, p->chip_erase_delay,
|
prefix, p->chip_erase_delay,
|
||||||
prefix, p->f_readback,
|
prefix, p->f_readback,
|
||||||
|
|
28
avr.h
28
avr.h
|
@ -45,27 +45,47 @@
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AVR memory designations
|
* AVR memory designations; the order of these is important, these are
|
||||||
|
* used as indexes into statically initialized data, don't change them
|
||||||
|
* around.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AVR_EEPROM,
|
AVR_EEPROM,
|
||||||
AVR_FLASH,
|
AVR_FLASH
|
||||||
AVR_FLASH_LO,
|
|
||||||
AVR_FLASH_HI
|
|
||||||
} AVRMEM;
|
} AVRMEM;
|
||||||
|
|
||||||
|
#define AVR_MAXMEMTYPES 2 /* just flash and eeprom */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
struct avrmem {
|
||||||
|
AVRMEM memtype;
|
||||||
|
int startaddr;
|
||||||
|
int size;
|
||||||
|
unsigned char buf;
|
||||||
|
struct avrmem * next;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct avrpart {
|
struct avrpart {
|
||||||
char * partdesc; /* long part name */
|
char * partdesc; /* long part name */
|
||||||
char * optiontag; /* short part name */
|
char * optiontag; /* short part name */
|
||||||
|
int memsize[AVR_MAXMEMTYPES]; /* sizes for eeprom,
|
||||||
|
flash, etc, indexed by
|
||||||
|
AVR_EEPROM or AVR_FLASH */
|
||||||
|
#if 0
|
||||||
int flash_size; /* size in bytes of flash */
|
int flash_size; /* size in bytes of flash */
|
||||||
int eeprom_size; /* size in bytes of eeprom */
|
int eeprom_size; /* size in bytes of eeprom */
|
||||||
|
#endif
|
||||||
unsigned char f_readback; /* flash write polled readback value */
|
unsigned char f_readback; /* flash write polled readback value */
|
||||||
unsigned char e_readback[2]; /* eeprom write polled readback values */
|
unsigned char e_readback[2]; /* eeprom write polled readback values */
|
||||||
int min_write_delay; /* microseconds */
|
int min_write_delay; /* microseconds */
|
||||||
int max_write_delay; /* microseconds */
|
int max_write_delay; /* microseconds */
|
||||||
int chip_erase_delay; /* microseconds */
|
int chip_erase_delay; /* microseconds */
|
||||||
|
unsigned char * mem[AVR_MAXMEMTYPES];
|
||||||
|
#if 0
|
||||||
unsigned char * flash;
|
unsigned char * flash;
|
||||||
unsigned char * eeprom;
|
unsigned char * eeprom;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct avrpart parts[];
|
extern struct avrpart parts[];
|
||||||
|
|
20
fileio.c
20
fileio.c
|
@ -433,24 +433,10 @@ int fileio ( int op, char * filename, FILEFMT format,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (memtype) {
|
/* point at the requested memory buffer */
|
||||||
case AVR_EEPROM:
|
buf = p->mem[memtype];
|
||||||
buf = p->eeprom;
|
|
||||||
if (fio.op == FIO_READ)
|
if (fio.op == FIO_READ)
|
||||||
size = p->eeprom_size;
|
size = p->memsize[memtype];
|
||||||
break;
|
|
||||||
|
|
||||||
case AVR_FLASH:
|
|
||||||
buf = p->flash;
|
|
||||||
if (fio.op == FIO_READ)
|
|
||||||
size = p->flash_size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: invalid memory type for %s: %d\n",
|
|
||||||
progname, fio.iodesc, memtype);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fio.op == FIO_READ) {
|
if (fio.op == FIO_READ) {
|
||||||
/* 0xff fill unspecified memory */
|
/* 0xff fill unspecified memory */
|
||||||
|
|
82
term.c
82
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[] )
|
int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
{
|
{
|
||||||
char * e;
|
char * e;
|
||||||
int i, j, l;
|
int i, l;
|
||||||
unsigned short daddr;
|
|
||||||
char * buf;
|
char * buf;
|
||||||
int maxsize;
|
int maxsize;
|
||||||
static AVRMEM memtype=AVR_FLASH;
|
static AVRMEM memtype=AVR_FLASH;
|
||||||
|
@ -241,12 +240,7 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (memtype) {
|
maxsize = p->memsize[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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addr > maxsize) {
|
if (addr > maxsize) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -265,29 +259,8 @@ int cmd_dump ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
j = 0;
|
for (i=0; i<len; i++)
|
||||||
daddr = addr;
|
buf[i] = avr_read_byte(fd, p, memtype, addr+i);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
hexdump_buf(stdout, addr, buf, len);
|
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[] )
|
int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
{
|
{
|
||||||
char * e;
|
char * e;
|
||||||
int i, j, l;
|
int i, l;
|
||||||
int len, maxsize;
|
int len, maxsize;
|
||||||
AVRMEM memtype;
|
AVRMEM memtype;
|
||||||
unsigned short addr, daddr;
|
unsigned short addr;
|
||||||
char * buf;
|
char * buf;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -317,11 +290,9 @@ int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
l = strlen(argv[1]);
|
l = strlen(argv[1]);
|
||||||
if (strncasecmp(argv[1],"flash",l)==0) {
|
if (strncasecmp(argv[1],"flash",l)==0) {
|
||||||
memtype = AVR_FLASH;
|
memtype = AVR_FLASH;
|
||||||
maxsize = p->flash_size;
|
|
||||||
}
|
}
|
||||||
else if (strncasecmp(argv[1],"eeprom",l)==0) {
|
else if (strncasecmp(argv[1],"eeprom",l)==0) {
|
||||||
memtype = AVR_EEPROM;
|
memtype = AVR_EEPROM;
|
||||||
maxsize = p->eeprom_size;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s (write): invalid memory type \"%s\"\n",
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxsize = p->memsize[memtype];
|
||||||
|
|
||||||
addr = strtoul(argv[2], &e, 0);
|
addr = strtoul(argv[2], &e, 0);
|
||||||
if (*e || (e == argv[2])) {
|
if (*e || (e == argv[2])) {
|
||||||
fprintf(stderr, "%s (write): can't parse address \"%s\"\n",
|
fprintf(stderr, "%s (write): can't parse address \"%s\"\n",
|
||||||
|
@ -369,45 +342,12 @@ int cmd_write ( int fd, struct avrpart * p, int argc, char * argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j = 0;
|
for (i=0; i<len; i++) {
|
||||||
daddr = addr;
|
rc = avr_write_byte(fd, p, memtype, addr+i, buf[i]);
|
||||||
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) {
|
if (rc) {
|
||||||
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
fprintf(stderr, "%s (write): error writing 0x%02x at 0x%04x\n",
|
||||||
progname, buf[j-1], daddr*2+1);
|
progname, buf[i], addr+i);
|
||||||
}
|
}
|
||||||
daddr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
free(buf);
|
||||||
|
|
Loading…
Reference in New Issue