From 7f78bac54dceb658b8637ec58d4baa4eb5da7aa4 Mon Sep 17 00:00:00 2001 From: Eric Weddington Date: Mon, 13 Oct 2003 21:32:53 +0000 Subject: [PATCH] * stk500.c (stk500_paged_write): Limit blocks written to no bigger than memory device size. (stk500_paged_write): Send whole block at once. (stk500_paged_load): Limit blocks read to no bigger than memory device size. [Contributed by Bill Somerville , this fixes bug #5713.] git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@376 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 11 ++++++++++- stk500.c | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e989eaff..694a5a52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ +2003-10-13 Bill Somerville + + * stk500.c (stk500_paged_write): Limit blocks written to no bigger + than memory device size. + (stk500_paged_write): Send whole block at once. + (stk500_paged_load): Limit blocks read to no bigger than memory + device size. + [This fixes bug #5713.] + 2003-10-13 Eric B. Weddington - + *avrdude.conf.in: Fix for unterminated character error. 2003-10-13 Eric B. Weddington diff --git a/stk500.c b/stk500.c index 533e96ac..3ff99c43 100644 --- a/stk500.c +++ b/stk500.c @@ -687,7 +687,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int memtype; unsigned int addr; int a_div; - int i; + int block_size; int tries; unsigned int n; int flash; @@ -738,9 +738,16 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, for (addr = 0; addr < n; addr += page_size) { report_progress (addr, n_bytes, NULL); + if (addr + page_size > n_bytes) { + block_size = n_bytes % page_size; + } + else { + block_size = page_size; + } + /* Only skip on empty page if programming flash. */ if (flash) { - if (stk500_is_page_empty(addr, page_size, m->buf)) { + if (stk500_is_page_empty(addr, block_size, m->buf)) { continue; } } @@ -749,14 +756,13 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, tries++; stk500_loadaddr(pgm, addr/a_div); buf[0] = Cmnd_STK_PROG_PAGE; - buf[1] = (page_size >> 8) & 0xff; - buf[2] = page_size & 0xff; + buf[1] = (block_size >> 8) & 0xff; + buf[2] = block_size & 0xff; buf[3] = memtype; stk500_send(pgm, buf, 4); - for (i=0; ibuf[addr + i]; - stk500_send(pgm, buf, 1); - } + + stk500_send(pgm, &m->buf[addr], block_size); + buf[0] = Sync_CRC_EOP; stk500_send(pgm, buf, 1); @@ -788,7 +794,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, } } - return n; + return n_bytes; } static int stk500_is_page_empty(unsigned int address, int page_size, @@ -815,6 +821,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int a_div; int tries; unsigned int n; + int block_size; if (strcmp(m->desc, "flash") == 0) { memtype = 'F'; @@ -846,13 +853,21 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, for (addr = 0; addr < n; addr += page_size) { report_progress (addr, n_bytes, NULL); + + if (addr + page_size > n_bytes) { + block_size = n_bytes % page_size; + } + else { + block_size = page_size; + } + tries = 0; retry: tries++; stk500_loadaddr(pgm, addr/a_div); buf[0] = Cmnd_STK_READ_PAGE; - buf[1] = (page_size >> 8) & 0xff; - buf[2] = page_size & 0xff; + buf[1] = (block_size >> 8) & 0xff; + buf[2] = block_size & 0xff; buf[3] = memtype; buf[4] = Sync_CRC_EOP; stk500_send(pgm, buf, 5); @@ -875,7 +890,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return -4; } - stk500_recv(pgm, &m->buf[addr], page_size); + stk500_recv(pgm, &m->buf[addr], block_size); stk500_recv(pgm, buf, 1); if (buf[0] != Resp_STK_OK) { @@ -887,7 +902,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, } } - return n; + return n_bytes; }