Mega-commit to bring in memory tagging.

Each memory image byte is now tagged as it's being read from a file.
Only bytes read from a file will be written or verified (modulo page
granularity requirements).



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1007 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch
2011-09-14 21:49:42 +00:00
parent 92952f3693
commit 95a42e16d5
18 changed files with 489 additions and 469 deletions

View File

@@ -267,8 +267,6 @@ static int stk500v2_getparm2(PROGRAMMER * pgm, unsigned char parm, unsigned int
static int stk500v2_setparm2(PROGRAMMER * pgm, unsigned char parm, unsigned int value);
static int stk500v2_setparm_real(PROGRAMMER * pgm, unsigned char parm, unsigned char value);
static void stk500v2_print_parms1(PROGRAMMER * pgm, const char * p);
static int stk500v2_is_page_empty(unsigned int address, int page_size,
const unsigned char *buf);
static unsigned int stk500v2_mode_for_pagesize(unsigned int pagesize);
@@ -1716,17 +1714,20 @@ static int stk500hvsp_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
unsigned int addr, block_size, last_addr, hiaddr, addrshift, use_ext_addr;
unsigned int block_size, last_addr, hiaddr, addrshift, use_ext_addr;
unsigned int maxaddr = addr + n_bytes;
unsigned char commandbuf[10];
unsigned char buf[266];
unsigned char cmds[4];
int result;
OPCODE * rop, * wop;
DEBUG("STK500V2: stk500v2_paged_write(..,%s,%d,%d)\n",m->desc,page_size,n_bytes);
DEBUG("STK500V2: stk500v2_paged_write(..,%s,%u,%u,%u)\n",
m->desc, page_size, addr, n_bytes);
if (page_size == 0) page_size = 256;
hiaddr = UINT_MAX;
@@ -1809,22 +1810,14 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
last_addr=UINT_MAX; /* impossible address */
for (addr=0; addr < n_bytes; addr += page_size) {
report_progress(addr,n_bytes,NULL);
if ((n_bytes-addr) < page_size)
block_size = n_bytes - addr;
for (; addr < maxaddr; addr += page_size) {
if ((maxaddr - addr) < page_size)
block_size = maxaddr - addr;
else
block_size = page_size;
DEBUG("block_size at addr %d is %d\n",addr,block_size);
if(commandbuf[0] == CMD_PROGRAM_FLASH_ISP){
if (stk500v2_is_page_empty(addr, block_size, m->buf)) {
continue;
}
}
memcpy(buf,commandbuf,sizeof(commandbuf));
buf[1] = block_size >> 8;
@@ -1854,14 +1847,17 @@ static int stk500v2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
* Write pages of flash/EEPROM, generic HV mode
*/
static int stk500hv_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes,
enum hvmode mode)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes,
enum hvmode mode)
{
unsigned int addr, block_size, last_addr, hiaddr, addrshift, use_ext_addr;
unsigned int block_size, last_addr, hiaddr, addrshift, use_ext_addr;
unsigned int maxaddr = addr + n_bytes;
unsigned char commandbuf[5], buf[266];
int result;
DEBUG("STK500V2: stk500hv_paged_write(..,%s,%d,%d)\n",m->desc,page_size,n_bytes);
DEBUG("STK500V2: stk500hv_paged_write(..,%s,%u,%u)\n",
m->desc, page_size, addr, n_bytes);
hiaddr = UINT_MAX;
addrshift = 0;
@@ -1906,22 +1902,14 @@ static int stk500hv_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
last_addr = UINT_MAX; /* impossible address */
for (addr = 0; addr < n_bytes; addr += page_size) {
report_progress(addr,n_bytes,NULL);
if ((n_bytes-addr) < page_size)
block_size = n_bytes - addr;
for (; addr < maxaddr; addr += page_size) {
if ((maxaddr - addr) < page_size)
block_size = maxaddr - addr;
else
block_size = page_size;
DEBUG("block_size at addr %d is %d\n",addr,block_size);
if (addrshift == 1) {
if (stk500v2_is_page_empty(addr, block_size, m->buf)) {
continue;
}
}
memcpy(buf, commandbuf, sizeof(commandbuf));
buf[1] = page_size >> 8;
@@ -1953,46 +1941,36 @@ static int stk500hv_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
* Write pages of flash/EEPROM, PP mode
*/
static int stk500pp_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
return stk500hv_paged_write(pgm, p, m, page_size, n_bytes, PPMODE);
return stk500hv_paged_write(pgm, p, m, page_size, addr, n_bytes, PPMODE);
}
/*
* Write pages of flash/EEPROM, HVSP mode
*/
static int stk500hvsp_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
return stk500hv_paged_write(pgm, p, m, page_size, n_bytes, HVSPMODE);
}
static int stk500v2_is_page_empty(unsigned int address, int page_size,
const unsigned char *buf)
{
int i;
for(i = 0; i < page_size; i++) {
if(buf[address + i] != 0xFF) {
/* Page is not empty. */
return(0);
}
}
/* Page is empty. */
return(1);
return stk500hv_paged_write(pgm, p, m, page_size, addr, n_bytes, HVSPMODE);
}
static int stk500v2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
unsigned int addr, block_size, hiaddr, addrshift, use_ext_addr;
unsigned int block_size, hiaddr, addrshift, use_ext_addr;
unsigned int maxaddr = addr + n_bytes;
unsigned char commandbuf[4];
unsigned char buf[275]; // max buffer size for stk500v2 at this point
unsigned char cmds[4];
int result;
OPCODE * rop;
DEBUG("STK500V2: stk500v2_paged_load(..,%s,%d,%d)\n",m->desc,page_size,n_bytes);
DEBUG("STK500V2: stk500v2_paged_load(..,%s,%u,%u,%u)\n",
m->desc, page_size, addr, n_bytes);
page_size = m->readsize;
@@ -2030,11 +2008,9 @@ static int stk500v2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
avr_set_bits(rop, cmds);
commandbuf[3] = cmds[0];
for (addr=0; addr < n_bytes; addr += page_size) {
report_progress(addr, n_bytes,NULL);
if ((n_bytes-addr) < page_size)
block_size = n_bytes - addr;
for (; addr < maxaddr; addr += page_size) {
if ((maxaddr - addr) < page_size)
block_size = maxaddr - addr;
else
block_size = page_size;
DEBUG("block_size at addr %d is %d\n",addr,block_size);
@@ -2077,14 +2053,17 @@ static int stk500v2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
* Read pages of flash/EEPROM, generic HV mode
*/
static int stk500hv_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes,
enum hvmode mode)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes,
enum hvmode mode)
{
unsigned int addr, block_size, hiaddr, addrshift, use_ext_addr;
unsigned int block_size, hiaddr, addrshift, use_ext_addr;
unsigned int maxaddr = addr + n_bytes;
unsigned char commandbuf[3], buf[266];
int result;
DEBUG("STK500V2: stk500hv_paged_load(..,%s,%d,%d)\n",m->desc,page_size,n_bytes);
DEBUG("STK500V2: stk500hv_paged_load(..,%s,%u,%u,%u)\n",
m->desc, page_size, addr, n_bytes);
page_size = m->readsize;
@@ -2110,11 +2089,9 @@ static int stk500hv_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
commandbuf[0] = mode == PPMODE? CMD_READ_EEPROM_PP: CMD_READ_EEPROM_HVSP;
}
for (addr = 0; addr < n_bytes; addr += page_size) {
report_progress(addr, n_bytes, NULL);
if ((n_bytes-addr) < page_size)
block_size = n_bytes - addr;
for (; addr < maxaddr; addr += page_size) {
if ((maxaddr - addr) < page_size)
block_size = maxaddr - addr;
else
block_size = page_size;
DEBUG("block_size at addr %d is %d\n",addr,block_size);
@@ -2156,18 +2133,20 @@ static int stk500hv_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
* Read pages of flash/EEPROM, PP mode
*/
static int stk500pp_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
return stk500hv_paged_load(pgm, p, m, page_size, n_bytes, PPMODE);
return stk500hv_paged_load(pgm, p, m, page_size, addr, n_bytes, PPMODE);
}
/*
* Read pages of flash/EEPROM, HVSP mode
*/
static int stk500hvsp_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
return stk500hv_paged_load(pgm, p, m, page_size, n_bytes, HVSPMODE);
return stk500hv_paged_load(pgm, p, m, page_size, addr, n_bytes, HVSPMODE);
}
@@ -3305,10 +3284,10 @@ static int stk600_xprog_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
static int stk600_xprog_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
unsigned char *b;
unsigned int addr;
unsigned int offset;
unsigned char memtype;
int n_bytes_orig = n_bytes;
@@ -3358,7 +3337,6 @@ static int stk600_xprog_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
offset = 0;
while (n_bytes != 0) {
report_progress(offset, n_bytes_orig, NULL);
b[0] = XPRG_CMD_READ_MEM;
b[1] = memtype;
b[2] = addr >> 24;
@@ -3387,10 +3365,10 @@ static int stk600_xprog_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
static int stk600_xprog_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
int page_size, int n_bytes)
unsigned int page_size,
unsigned int addr, unsigned int n_bytes)
{
unsigned char *b;
unsigned int addr;
unsigned int offset;
unsigned char memtype;
int n_bytes_orig = n_bytes;
@@ -3435,7 +3413,7 @@ static int stk600_xprog_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
progname, mem->desc);
return -1;
}
addr = mem->offset;
addr += mem->offset;
if ((b = malloc(page_size + 9)) == NULL) {
fprintf(stderr,
@@ -3449,8 +3427,6 @@ static int stk600_xprog_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
offset = 0;
while (n_bytes != 0) {
report_progress(offset, n_bytes_orig, NULL);
if (page_size > 256) {
/*
* AVR079 is not quite clear. While it suggests that