From: bsekisser Date: Sat, 18 Apr 2015 12:11:22 +0000 (-0400) Subject: flash: be sure to use current page for writing X-Git-Tag: v1.3~49^2 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=77e3f7846e0ff3c1e1f61f20bcda39a29c671b10;p=sx%2Fsimavr.git flash: be sure to use current page for writing bound z to ~(page size - 1), otherwise write may start at anywhere in page to write and fail. also corrected log line to previous state as was missleading/inacurate. modified: simavr/sim/avr_flash.c --- diff --git a/simavr/sim/avr_flash.c b/simavr/sim/avr_flash.c index fc37b15..cc1fd96 100644 --- a/simavr/sim/avr_flash.c +++ b/simavr/sim/avr_flash.c @@ -76,13 +76,13 @@ static int avr_flash_ioctl(struct avr_io_t * port, uint32_t ctl, void * io_param for (int i = 0; i < p->spm_pagesize; i++) avr->flash[z++] = 0xff; } else if (avr_regbit_get(avr, p->pgwrt)) { - z &= ~1; + z &= ~(p->spm_pagesize - 1); + AVR_LOG(avr, LOG_TRACE, "FLASH: Writing page %04x (%d)\n", (z / p->spm_pagesize), p->spm_pagesize); for (int i = 0; i < p->spm_pagesize / 2; i++) { avr->flash[z++] = p->tmppage[i]; avr->flash[z++] = p->tmppage[i] >> 8; } avr_flash_clear_temppage(p); - AVR_LOG(avr, LOG_TRACE, "FLASH: Writing page %08x (%d)\n", z, p->spm_pagesize); } else if (avr_regbit_get(avr, p->blbset)) { AVR_LOG(avr, LOG_TRACE, "FLASH: Setting lock bits (ignored)\n"); } else if (p->flags & AVR_SELFPROG_HAVE_RWW && avr_regbit_get(avr, p->rwwsre)) {