2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2003-02-08 04:17:25 +00:00
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2004-12-22 01:52:45 +00:00
|
|
|
* Copyright (C) 2000-2004 Brian S. Dean <bsd@bsdhome.com>
|
2011-08-24 07:40:48 +00:00
|
|
|
* Copyright (C) 2011 Darell Tan <darell.tan@gmail.com>
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2001-01-19 02:46:50 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2012-11-20 14:03:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2003-02-14 20:34:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2001-10-13 03:12:52 +00:00
|
|
|
#include <string.h>
|
2003-11-19 18:11:59 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
#include "tpi.h"
|
2007-01-24 22:43:46 +00:00
|
|
|
|
|
|
|
FP_UpdateProgress update_progress;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2002-01-12 01:26:09 +00:00
|
|
|
#define DEBUG 0
|
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
/* TPI: returns 1 if NVM controller busy, 0 if free */
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_tpi_poll_nvmbsy(const PROGRAMMER *pgm) {
|
2011-08-23 21:03:36 +00:00
|
|
|
unsigned char cmd;
|
|
|
|
unsigned char res;
|
|
|
|
|
|
|
|
cmd = TPI_CMD_SIN | TPI_SIO_ADDR(TPI_IOREG_NVMCSR);
|
2013-09-03 11:05:13 +00:00
|
|
|
(void)pgm->cmd_tpi(pgm, &cmd, 1, &res, 1);
|
2013-05-02 11:07:30 +00:00
|
|
|
return (res & TPI_IOREG_NVMCSR_NVMBSY);
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 12:43:47 +00:00
|
|
|
/* TPI chip erase sequence */
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-06 12:43:47 +00:00
|
|
|
int err;
|
|
|
|
AVRMEM *mem;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2013-05-06 12:43:47 +00:00
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
|
|
|
|
/* Set Pointer Register */
|
|
|
|
mem = avr_locate_mem(p, "flash");
|
|
|
|
if (mem == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n",
|
2013-05-06 12:43:47 +00:00
|
|
|
p->desc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char cmd[] = {
|
|
|
|
/* write pointer register high byte */
|
|
|
|
(TPI_CMD_SSTPR | 0),
|
|
|
|
((mem->offset & 0xFF) | 1),
|
|
|
|
/* and low byte */
|
|
|
|
(TPI_CMD_SSTPR | 1),
|
|
|
|
((mem->offset >> 8) & 0xFF),
|
|
|
|
/* write CHIP_ERASE command to NVMCMD register */
|
|
|
|
(TPI_CMD_SOUT | TPI_SIO_ADDR(TPI_IOREG_NVMCMD)),
|
|
|
|
TPI_NVMCMD_CHIP_ERASE,
|
|
|
|
/* write dummy value to start erase */
|
|
|
|
TPI_CMD_SST,
|
|
|
|
0xFF
|
|
|
|
};
|
|
|
|
|
2020-03-11 09:41:15 +00:00
|
|
|
while (avr_tpi_poll_nvmbsy(pgm))
|
|
|
|
;
|
2013-05-06 12:43:47 +00:00
|
|
|
|
2020-03-11 09:41:15 +00:00
|
|
|
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
|
|
|
if(err)
|
|
|
|
return err;
|
2013-05-06 12:43:47 +00:00
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
|
2013-05-06 12:43:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 12:49:26 +00:00
|
|
|
/* TPI program enable sequence */
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned char guard_time) {
|
2013-05-06 12:49:26 +00:00
|
|
|
int err, retry;
|
|
|
|
unsigned char cmd[2];
|
|
|
|
unsigned char response;
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if(p->prog_modes & PM_TPI) {
|
2013-05-06 12:49:26 +00:00
|
|
|
/* set guard time */
|
|
|
|
cmd[0] = (TPI_CMD_SSTCS | TPI_REG_TPIPCR);
|
|
|
|
cmd[1] = guard_time;
|
|
|
|
|
|
|
|
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
|
|
|
if(err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* read TPI ident reg */
|
|
|
|
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
|
|
|
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
|
|
|
if (err || response != TPI_IDENT_CODE) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "TPIIR not correct\n");
|
2013-05-06 12:49:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send SKEY command + SKEY */
|
|
|
|
err = pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
|
|
|
|
if(err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* check if device is ready */
|
|
|
|
for(retry = 0; retry < 10; retry++)
|
|
|
|
{
|
|
|
|
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPISR);
|
|
|
|
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
|
|
|
if(err || !(response & TPI_REG_TPISR_NVMEN))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Error enabling TPI external programming mode:");
|
|
|
|
avrdude_message(MSG_INFO, "Target does not reply\n");
|
2013-05-06 12:49:26 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
} else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s called for a part that has no TPI\n", __func__);
|
2013-05-06 12:49:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
/* TPI: setup NVMCMD register and pointer register (PR) for read/write/erase */
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int avr_tpi_setup_rw(const PROGRAMMER *pgm, const AVRMEM *mem,
|
2011-08-23 21:03:36 +00:00
|
|
|
unsigned long addr, unsigned char nvmcmd)
|
|
|
|
{
|
|
|
|
unsigned char cmd[4];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* set NVMCMD register */
|
|
|
|
cmd[0] = TPI_CMD_SOUT | TPI_SIO_ADDR(TPI_IOREG_NVMCMD);
|
|
|
|
cmd[1] = nvmcmd;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* set Pointer Register (PR) */
|
|
|
|
cmd[0] = TPI_CMD_SSTPR | 0;
|
|
|
|
cmd[1] = (mem->offset + addr) & 0xFF;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
cmd[0] = TPI_CMD_SSTPR | 1;
|
|
|
|
cmd[1] = ((mem->offset + addr) >> 8) & 0xFF;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_read_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
2003-03-23 23:22:50 +00:00
|
|
|
unsigned long addr, unsigned char * value)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
2001-11-21 02:46:55 +00:00
|
|
|
unsigned char data;
|
2011-08-23 21:03:36 +00:00
|
|
|
int r;
|
2006-05-23 22:27:43 +00:00
|
|
|
OPCODE * readop, * lext;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2006-11-20 15:04:09 +00:00
|
|
|
if (pgm->cmd == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_read_byte_default() but does not\n"
|
2014-05-18 08:41:46 +00:00
|
|
|
"provide a cmd() method.\n",
|
|
|
|
progname, pgm->type);
|
2006-11-20 15:04:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
pgm->err_led(pgm, OFF);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
if (pgm->cmd_tpi == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
|
2011-08-23 21:03:36 +00:00
|
|
|
progname, pgm->type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
/* setup for read */
|
|
|
|
avr_tpi_setup_rw(pgm, mem, addr, TPI_NVMCMD_NO_OPERATION);
|
|
|
|
|
|
|
|
/* load byte */
|
|
|
|
cmd[0] = TPI_CMD_SLD;
|
|
|
|
r = pgm->cmd_tpi(pgm, cmd, 1, value, 1);
|
|
|
|
if (r == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-11-21 18:54:11 +00:00
|
|
|
/*
|
|
|
|
* figure out what opcode to use
|
|
|
|
*/
|
2001-11-21 02:46:55 +00:00
|
|
|
if (mem->op[AVR_OP_READ_LO]) {
|
|
|
|
if (addr & 0x00000001)
|
|
|
|
readop = mem->op[AVR_OP_READ_HI];
|
|
|
|
else
|
|
|
|
readop = mem->op[AVR_OP_READ_LO];
|
|
|
|
addr = addr / 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readop = mem->op[AVR_OP_READ];
|
|
|
|
}
|
2001-01-22 01:59:47 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
if (readop == NULL) {
|
2002-01-12 01:26:09 +00:00
|
|
|
#if DEBUG
|
2022-07-04 23:57:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_read_byte_default(): operation not supported on memory type \"%s\"\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
mem->desc);
|
2002-01-12 01:26:09 +00:00
|
|
|
#endif
|
2001-11-21 02:46:55 +00:00
|
|
|
return -1;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
2006-05-23 22:27:43 +00:00
|
|
|
/*
|
|
|
|
* If this device has a "load extended address" command, issue it.
|
|
|
|
*/
|
|
|
|
lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
|
|
|
|
if (lext != NULL) {
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
|
|
|
|
avr_set_bits(lext, cmd);
|
|
|
|
avr_set_addr(lext, cmd, addr);
|
2013-06-20 20:11:49 +00:00
|
|
|
r = pgm->cmd(pgm, cmd, res);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2006-05-23 22:27:43 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
avr_set_bits(readop, cmd);
|
|
|
|
avr_set_addr(readop, cmd, addr);
|
2013-06-20 20:11:49 +00:00
|
|
|
r = pgm->cmd(pgm, cmd, res);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2001-11-21 02:46:55 +00:00
|
|
|
data = 0;
|
|
|
|
avr_get_output(readop, res, &data);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
*value = data;
|
|
|
|
|
|
|
|
return 0;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-22 02:33:17 +00:00
|
|
|
/*
|
|
|
|
* Return the number of "interesting" bytes in a memory buffer,
|
|
|
|
* "interesting" being defined as up to the last non-0xff data
|
|
|
|
* value. This is useful for determining where to stop when dealing
|
|
|
|
* with "flash" memory, since writing 0xff to flash is typically a
|
|
|
|
* no-op. Always return an even number since flash is word addressed.
|
2022-04-15 19:48:46 +00:00
|
|
|
* Only apply this optimisation on flash-type memory.
|
2003-05-22 02:33:17 +00:00
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_mem_hiaddr(const AVRMEM * mem)
|
2003-05-22 02:33:17 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
2022-04-15 19:46:40 +00:00
|
|
|
static int disableffopt;
|
|
|
|
|
|
|
|
/* calling once with NULL disables any future trailing-0xff optimisation */
|
|
|
|
if(!mem) {
|
|
|
|
disableffopt = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(disableffopt)
|
|
|
|
return mem->size;
|
2003-05-22 02:33:17 +00:00
|
|
|
|
2022-04-15 19:48:46 +00:00
|
|
|
/* if the memory is not a flash-type memory do not remove trailing 0xff */
|
2022-08-15 13:57:04 +00:00
|
|
|
if(!avr_mem_is_flash_type(mem))
|
2022-04-15 19:48:46 +00:00
|
|
|
return mem->size;
|
|
|
|
|
2003-05-22 02:33:17 +00:00
|
|
|
/* return the highest non-0xff address regardless of how much
|
|
|
|
memory was read */
|
|
|
|
for (i=mem->size-1; i>0; i--) {
|
|
|
|
if (mem->buf[i] != 0xff) {
|
|
|
|
n = i+1;
|
|
|
|
if (n & 0x01)
|
|
|
|
return n+1;
|
|
|
|
else
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2001-01-20 16:34:28 +00:00
|
|
|
* Read the entirety of the specified memory type into the
|
2011-09-14 21:49:42 +00:00
|
|
|
* corresponding buffer of the avrpart pointed to by 'p'.
|
|
|
|
* If v is non-NULL, verify against v's memory area, only
|
|
|
|
* those cells that are tagged TAG_ALLOCATED are verified.
|
2001-01-20 16:34:28 +00:00
|
|
|
*
|
2001-11-21 18:54:11 +00:00
|
|
|
* Return the number of bytes read, or < 0 if an error occurs.
|
2001-11-21 02:46:55 +00:00
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_read(const PROGRAMMER *pgm, const AVRPART *p, const char *memtype,
|
2012-05-04 10:02:30 +00:00
|
|
|
AVRPART * v)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned long i, lastaddr;
|
2011-08-23 21:03:36 +00:00
|
|
|
unsigned char cmd[4];
|
2011-09-14 21:49:42 +00:00
|
|
|
AVRMEM * mem, * vmem = NULL;
|
2001-11-21 02:46:55 +00:00
|
|
|
int rc;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
mem = avr_locate_mem(p, memtype);
|
2011-09-14 21:49:42 +00:00
|
|
|
if (v != NULL)
|
|
|
|
vmem = avr_locate_mem(v, memtype);
|
2001-11-21 02:46:55 +00:00
|
|
|
if (mem == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype, p->desc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-05-22 02:33:17 +00:00
|
|
|
/*
|
|
|
|
* start with all 0xff
|
|
|
|
*/
|
2011-09-14 21:49:42 +00:00
|
|
|
memset(mem->buf, 0xff, mem->size);
|
2003-05-22 02:33:17 +00:00
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
/* supports "paged load" thru post-increment */
|
2022-08-30 15:33:42 +00:00
|
|
|
if ((p->prog_modes & PM_TPI) && mem->page_size > 1 &&
|
2021-12-26 15:57:23 +00:00
|
|
|
mem->size % mem->page_size == 0 && pgm->cmd_tpi != NULL) {
|
2011-08-23 21:03:36 +00:00
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
/* setup for read (NOOP) */
|
|
|
|
avr_tpi_setup_rw(pgm, mem, 0, TPI_NVMCMD_NO_OPERATION);
|
|
|
|
|
|
|
|
/* load bytes */
|
2011-09-14 21:49:42 +00:00
|
|
|
for (lastaddr = i = 0; i < mem->size; i++) {
|
|
|
|
if (vmem == NULL ||
|
|
|
|
(vmem->tags[i] & TAG_ALLOCATED) != 0)
|
|
|
|
{
|
|
|
|
if (lastaddr != i) {
|
|
|
|
/* need to setup new address */
|
|
|
|
avr_tpi_setup_rw(pgm, mem, i, TPI_NVMCMD_NO_OPERATION);
|
|
|
|
lastaddr = i;
|
|
|
|
}
|
|
|
|
cmd[0] = TPI_CMD_SLD_PI;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 1, mem->buf + i, 1);
|
|
|
|
lastaddr++;
|
|
|
|
if (rc == -1) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
|
2011-09-14 21:49:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
2011-09-14 21:49:42 +00:00
|
|
|
report_progress(i, mem->size, NULL);
|
2011-08-23 21:03:36 +00:00
|
|
|
}
|
|
|
|
return avr_mem_hiaddr(mem);
|
|
|
|
}
|
|
|
|
|
2021-12-26 15:57:23 +00:00
|
|
|
if (pgm->paged_load != NULL && mem->page_size > 1 &&
|
|
|
|
mem->size % mem->page_size == 0) {
|
2010-01-12 15:42:40 +00:00
|
|
|
/*
|
2011-09-14 21:49:42 +00:00
|
|
|
* the programmer supports a paged mode read
|
2010-01-12 15:42:40 +00:00
|
|
|
*/
|
2011-09-14 21:49:42 +00:00
|
|
|
int need_read, failure;
|
|
|
|
unsigned int pageaddr;
|
2013-09-13 09:42:47 +00:00
|
|
|
unsigned int npages, nread;
|
2011-09-14 21:49:42 +00:00
|
|
|
|
2013-09-13 09:42:47 +00:00
|
|
|
/* quickly scan number of pages to be written to first */
|
|
|
|
for (pageaddr = 0, npages = 0;
|
|
|
|
pageaddr < mem->size;
|
|
|
|
pageaddr += mem->page_size) {
|
|
|
|
/* check whether this page must be read */
|
|
|
|
for (i = pageaddr;
|
|
|
|
i < pageaddr + mem->page_size;
|
|
|
|
i++)
|
2013-09-13 12:48:13 +00:00
|
|
|
if (vmem == NULL /* no verify, read everything */ ||
|
|
|
|
(mem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
|
|
|
|
read pages that
|
|
|
|
are needed in
|
|
|
|
input file */) {
|
2013-09-13 09:42:47 +00:00
|
|
|
npages++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pageaddr = 0, failure = 0, nread = 0;
|
2011-09-14 21:49:42 +00:00
|
|
|
!failure && pageaddr < mem->size;
|
|
|
|
pageaddr += mem->page_size) {
|
|
|
|
/* check whether this page must be read */
|
|
|
|
for (i = pageaddr, need_read = 0;
|
|
|
|
i < pageaddr + mem->page_size;
|
|
|
|
i++)
|
|
|
|
if (vmem == NULL /* no verify, read everything */ ||
|
|
|
|
(vmem->tags[i] & TAG_ALLOCATED) != 0 /* verify, do only
|
|
|
|
read pages that
|
|
|
|
are needed in
|
|
|
|
input file */) {
|
|
|
|
need_read = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (need_read) {
|
2012-01-19 20:06:52 +00:00
|
|
|
rc = pgm->paged_load(pgm, p, mem, mem->page_size,
|
2011-09-14 21:49:42 +00:00
|
|
|
pageaddr, mem->page_size);
|
2012-01-19 20:06:52 +00:00
|
|
|
if (rc < 0)
|
2011-09-14 21:49:42 +00:00
|
|
|
/* paged load failed, fall back to byte-at-a-time read below */
|
|
|
|
failure = 1;
|
2014-06-13 20:07:40 +00:00
|
|
|
} else {
|
|
|
|
avrdude_message(MSG_DEBUG, "%s: avr_read(): skipping page %u: no interesting data\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, pageaddr / mem->page_size);
|
2011-09-14 21:49:42 +00:00
|
|
|
}
|
2013-09-13 09:42:47 +00:00
|
|
|
nread++;
|
|
|
|
report_progress(nread, npages, NULL);
|
2011-09-14 21:49:42 +00:00
|
|
|
}
|
2022-04-15 19:48:46 +00:00
|
|
|
if (!failure)
|
|
|
|
return avr_mem_hiaddr(mem);
|
2011-09-14 21:49:42 +00:00
|
|
|
/* else: fall back to byte-at-a-time write, for historical reasons */
|
2002-12-01 06:35:18 +00:00
|
|
|
}
|
|
|
|
|
2003-03-17 06:20:02 +00:00
|
|
|
if (strcmp(mem->desc, "signature") == 0) {
|
|
|
|
if (pgm->read_sig_bytes) {
|
|
|
|
return pgm->read_sig_bytes(pgm, p, mem);
|
|
|
|
}
|
|
|
|
}
|
2002-12-01 06:35:18 +00:00
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
for (i=0; i < mem->size; i++) {
|
|
|
|
if (vmem == NULL ||
|
|
|
|
(vmem->tags[i] & TAG_ALLOCATED) != 0)
|
|
|
|
{
|
|
|
|
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
|
2022-06-15 21:32:22 +00:00
|
|
|
if (rc != LIBAVRDUDE_SUCCESS) {
|
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9507: Fix UPDI chip erase
* lexer.l (family_id): New keyword.
* config_gram.y: (Ditto)
* doc/avrdude.texi: Document new keyword
* avrdude.conf.in: Add family_id for avr8x devices
* avr.c: Pass error code up.
* jtag3.c: Pass error code from memory read up; implement
jtag3_read_sib()
* libavrdude.h: Add new items.
* main.c: Implement different chip erase handling required
for UPDI devices.
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9506: Script to create device configuration stub from Atmel ATDF files
* avrdude.conf.in (ATtiny202, ATtiny204, ATtiny402, ATtiny404)
(ATtiny406, ATtiny804, ATtiny806, ATtiny807, ATtiny1604)
(ATtiny1606, ATtiny1607, ATtiny212, ATtiny214, ATtiny412)
(ATTiny414, ATtiny416, ATtiny417, ATtiny814, ATtiny816)
(ATtiny1614, ATtiny1616, ATtiny3214, ATtiny3216, ATtiny3217)
(ATmega3208, ATmega3209, ATmega4808, ATmega4809): New devices
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1405 81a1dc3b-b13d-400b-aceb-764788c761c2
2018-01-09 23:29:31 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
|
2022-06-15 21:32:22 +00:00
|
|
|
if (rc == LIBAVRDUDE_GENERAL_FAILURE) {
|
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9507: Fix UPDI chip erase
* lexer.l (family_id): New keyword.
* config_gram.y: (Ditto)
* doc/avrdude.texi: Document new keyword
* avrdude.conf.in: Add family_id for avr8x devices
* avr.c: Pass error code up.
* jtag3.c: Pass error code from memory read up; implement
jtag3_read_sib()
* libavrdude.h: Add new items.
* main.c: Implement different chip erase handling required
for UPDI devices.
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9506: Script to create device configuration stub from Atmel ATDF files
* avrdude.conf.in (ATtiny202, ATtiny204, ATtiny402, ATtiny404)
(ATtiny406, ATtiny804, ATtiny806, ATtiny807, ATtiny1604)
(ATtiny1606, ATtiny1607, ATtiny212, ATtiny214, ATtiny412)
(ATTiny414, ATtiny416, ATtiny417, ATtiny814, ATtiny816)
(ATtiny1614, ATtiny1616, ATtiny3214, ATtiny3216, ATtiny3217)
(ATmega3208, ATmega3209, ATmega4808, ATmega4809): New devices
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1405 81a1dc3b-b13d-400b-aceb-764788c761c2
2018-01-09 23:29:31 +00:00
|
|
|
avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
memtype);
|
2022-06-15 21:32:22 +00:00
|
|
|
return LIBAVRDUDE_NOTSUPPORTED;
|
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9507: Fix UPDI chip erase
* lexer.l (family_id): New keyword.
* config_gram.y: (Ditto)
* doc/avrdude.texi: Document new keyword
* avrdude.conf.in: Add family_id for avr8x devices
* avr.c: Pass error code up.
* jtag3.c: Pass error code from memory read up; implement
jtag3_read_sib()
* libavrdude.h: Add new items.
* main.c: Implement different chip erase handling required
for UPDI devices.
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9506: Script to create device configuration stub from Atmel ATDF files
* avrdude.conf.in (ATtiny202, ATtiny204, ATtiny402, ATtiny404)
(ATtiny406, ATtiny804, ATtiny806, ATtiny807, ATtiny1604)
(ATtiny1606, ATtiny1607, ATtiny212, ATtiny214, ATtiny412)
(ATTiny414, ATtiny416, ATtiny417, ATtiny814, ATtiny816)
(ATtiny1614, ATtiny1616, ATtiny3214, ATtiny3216, ATtiny3217)
(ATmega3208, ATmega3209, ATmega4808, ATmega4809): New devices
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1405 81a1dc3b-b13d-400b-aceb-764788c761c2
2018-01-09 23:29:31 +00:00
|
|
|
}
|
|
|
|
avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n",
|
|
|
|
memtype);
|
2022-06-15 21:32:22 +00:00
|
|
|
return LIBAVRDUDE_SOFTFAIL;
|
2011-09-14 21:49:42 +00:00
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
2011-09-14 21:49:42 +00:00
|
|
|
report_progress(i, mem->size, NULL);
|
2002-08-01 01:00:03 +00:00
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2022-04-15 19:48:46 +00:00
|
|
|
return avr_mem_hiaddr(mem);
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-14 02:53:21 +00:00
|
|
|
/*
|
2001-11-21 18:54:11 +00:00
|
|
|
* write a page data at the specified address
|
2001-10-14 02:53:21 +00:00
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_write_page(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
2001-11-21 02:46:55 +00:00
|
|
|
unsigned long addr)
|
2001-10-14 02:53:21 +00:00
|
|
|
{
|
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
2006-05-23 22:27:43 +00:00
|
|
|
OPCODE * wp, * lext;
|
2001-11-21 02:46:55 +00:00
|
|
|
|
2006-11-20 15:04:09 +00:00
|
|
|
if (pgm->cmd == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_page() but does not\n"
|
2014-05-18 08:41:46 +00:00
|
|
|
"provide a cmd() method.\n",
|
|
|
|
progname, pgm->type);
|
2006-11-20 15:04:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
wp = mem->op[AVR_OP_WRITEPAGE];
|
|
|
|
if (wp == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_write_page(): memory \"%s\" not configured for page writes\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
mem->desc);
|
2001-11-21 02:46:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-11-21 18:54:11 +00:00
|
|
|
/*
|
|
|
|
* if this memory is word-addressable, adjust the address
|
|
|
|
* accordingly
|
|
|
|
*/
|
2002-12-01 15:05:56 +00:00
|
|
|
if ((mem->op[AVR_OP_LOADPAGE_LO]) || (mem->op[AVR_OP_READ_LO]))
|
2001-11-21 02:46:55 +00:00
|
|
|
addr = addr / 2;
|
2001-10-14 02:53:21 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
pgm->err_led(pgm, OFF);
|
2001-10-14 02:53:21 +00:00
|
|
|
|
2006-05-23 22:27:43 +00:00
|
|
|
/*
|
|
|
|
* If this device has a "load extended address" command, issue it.
|
|
|
|
*/
|
|
|
|
lext = mem->op[AVR_OP_LOAD_EXT_ADDR];
|
|
|
|
if (lext != NULL) {
|
|
|
|
memset(cmd, 0, sizeof(cmd));
|
|
|
|
|
|
|
|
avr_set_bits(lext, cmd);
|
|
|
|
avr_set_addr(lext, cmd, addr);
|
|
|
|
pgm->cmd(pgm, cmd, res);
|
|
|
|
}
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-10-14 02:53:21 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
avr_set_bits(wp, cmd);
|
|
|
|
avr_set_addr(wp, cmd, addr);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->cmd(pgm, cmd, res);
|
2001-10-14 02:53:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* since we don't know what voltage the target AVR is powered by, be
|
2003-11-30 16:42:10 +00:00
|
|
|
* conservative and delay the max amount the spec says to wait
|
2001-10-14 02:53:21 +00:00
|
|
|
*/
|
2001-11-21 02:46:55 +00:00
|
|
|
usleep(mem->max_write_delay);
|
2001-10-14 02:53:21 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2001-10-14 02:53:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
2001-10-14 23:17:26 +00:00
|
|
|
unsigned long addr, unsigned char data)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
2001-01-22 01:59:47 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
unsigned char res[4];
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char r;
|
|
|
|
int ready;
|
|
|
|
int tries;
|
2003-11-19 18:11:59 +00:00
|
|
|
unsigned long start_time;
|
|
|
|
unsigned long prog_time;
|
2001-01-19 02:46:50 +00:00
|
|
|
unsigned char b;
|
2001-01-22 01:59:47 +00:00
|
|
|
unsigned short caddr;
|
2001-11-21 02:46:55 +00:00
|
|
|
OPCODE * writeop;
|
|
|
|
int rc;
|
2002-01-12 01:26:09 +00:00
|
|
|
int readok=0;
|
2003-11-19 18:11:59 +00:00
|
|
|
struct timeval tv;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2006-11-20 15:04:09 +00:00
|
|
|
if (pgm->cmd == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: Error: %s programmer uses avr_write_byte_default() but does not\n"
|
2014-05-18 08:41:46 +00:00
|
|
|
"provide a cmd() method.\n",
|
|
|
|
progname, pgm->type);
|
2006-11-20 15:04:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (p->prog_modes & PM_TPI) {
|
2011-08-23 21:03:36 +00:00
|
|
|
if (pgm->cmd_tpi == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
|
2011-08-23 21:03:36 +00:00
|
|
|
progname, pgm->type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(mem->desc, "flash") == 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Writing a byte to flash is not supported for %s\n", p->desc);
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
} else if ((mem->offset + addr) & 1) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Writing a byte to an odd location is not supported for %s\n", p->desc);
|
2011-08-23 21:03:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
/* must erase fuse first */
|
|
|
|
if (strcmp(mem->desc, "fuse") == 0) {
|
|
|
|
/* setup for SECTION_ERASE (high byte) */
|
|
|
|
avr_tpi_setup_rw(pgm, mem, addr | 1, TPI_NVMCMD_SECTION_ERASE);
|
|
|
|
|
|
|
|
/* write dummy byte */
|
|
|
|
cmd[0] = TPI_CMD_SST;
|
|
|
|
cmd[1] = 0xFF;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup for WORD_WRITE */
|
|
|
|
avr_tpi_setup_rw(pgm, mem, addr, TPI_NVMCMD_WORD_WRITE);
|
|
|
|
|
|
|
|
cmd[0] = TPI_CMD_SST_PI;
|
|
|
|
cmd[1] = data;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
/* dummy high byte to start WORD_WRITE */
|
|
|
|
cmd[0] = TPI_CMD_SST_PI;
|
|
|
|
cmd[1] = data;
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if (!mem->paged && (p->flags & AVRPART_IS_AT90S1200) == 0) {
|
2001-10-14 02:53:21 +00:00
|
|
|
/*
|
|
|
|
* check to see if the write is necessary by reading the existing
|
|
|
|
* value and only write if we are changing the value; we can't
|
2001-10-16 23:32:30 +00:00
|
|
|
* use this optimization for paged addressing.
|
2011-08-29 09:25:04 +00:00
|
|
|
*
|
|
|
|
* For mysterious reasons, on the AT90S1200, this read operation
|
|
|
|
* sometimes causes the high byte of the same word to be
|
|
|
|
* programmed to the value of the low byte that has just been
|
|
|
|
* programmed before. Avoid that optimization on this device.
|
2001-10-14 02:53:21 +00:00
|
|
|
*/
|
2006-11-20 15:04:09 +00:00
|
|
|
rc = pgm->read_byte(pgm, p, mem, addr, &b);
|
2002-01-12 01:26:09 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
if (rc != -1) {
|
2002-02-14 02:48:07 +00:00
|
|
|
return -2;
|
2002-01-12 01:26:09 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* the read operation is not support on this memory type
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readok = 1;
|
|
|
|
if (b == data) {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-10-14 02:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* determine which memory opcode to use
|
|
|
|
*/
|
|
|
|
if (mem->op[AVR_OP_WRITE_LO]) {
|
|
|
|
if (addr & 0x01)
|
|
|
|
writeop = mem->op[AVR_OP_WRITE_HI];
|
|
|
|
else
|
|
|
|
writeop = mem->op[AVR_OP_WRITE_LO];
|
|
|
|
caddr = addr / 2;
|
|
|
|
}
|
2006-08-22 22:05:19 +00:00
|
|
|
else if (mem->paged && mem->op[AVR_OP_LOADPAGE_LO]) {
|
2001-11-21 02:46:55 +00:00
|
|
|
if (addr & 0x01)
|
|
|
|
writeop = mem->op[AVR_OP_LOADPAGE_HI];
|
|
|
|
else
|
|
|
|
writeop = mem->op[AVR_OP_LOADPAGE_LO];
|
|
|
|
caddr = addr / 2;
|
|
|
|
}
|
2001-10-14 02:53:21 +00:00
|
|
|
else {
|
2001-11-21 02:46:55 +00:00
|
|
|
writeop = mem->op[AVR_OP_WRITE];
|
|
|
|
caddr = addr;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
if (writeop == NULL) {
|
2002-01-12 01:26:09 +00:00
|
|
|
#if DEBUG
|
2022-07-05 00:00:45 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_write_byte_default(): write not supported for memory type \"%s\"\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
mem->desc);
|
2002-01-12 01:26:09 +00:00
|
|
|
#endif
|
2001-11-21 02:46:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2001-01-22 01:59:47 +00:00
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, ON);
|
|
|
|
pgm->err_led(pgm, OFF);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
avr_set_bits(writeop, cmd);
|
|
|
|
avr_set_addr(writeop, cmd, caddr);
|
|
|
|
avr_set_input(writeop, cmd, data);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->cmd(pgm, cmd, res);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
if (mem->paged) {
|
2001-10-14 02:53:21 +00:00
|
|
|
/*
|
2002-07-27 20:55:01 +00:00
|
|
|
* in paged addressing, single bytes to be written to the memory
|
2001-10-14 02:53:21 +00:00
|
|
|
* page complete immediately, we only need to delay when we commit
|
2001-10-16 23:32:30 +00:00
|
|
|
* the whole page via the avr_write_page() routine.
|
2001-10-14 02:53:21 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2001-10-14 02:53:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-12 01:26:09 +00:00
|
|
|
if (readok == 0) {
|
|
|
|
/*
|
|
|
|
* read operation not supported for this memory type, just wait
|
|
|
|
* the max programming time and then return
|
|
|
|
*/
|
|
|
|
usleep(mem->max_write_delay); /* maximum write delay */
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2002-01-12 01:26:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
tries = 0;
|
|
|
|
ready = 0;
|
|
|
|
while (!ready) {
|
2002-02-14 02:48:07 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
if ((data == mem->readback[0]) ||
|
|
|
|
(data == mem->readback[1])) {
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
|
|
|
* use an extra long delay when we happen to be writing values
|
|
|
|
* used for polled data read-back. In this case, polling
|
|
|
|
* doesn't work, and we need to delay the worst case write time
|
|
|
|
* specified for the chip.
|
|
|
|
*/
|
2001-11-21 02:46:55 +00:00
|
|
|
usleep(mem->max_write_delay);
|
2006-11-20 15:04:09 +00:00
|
|
|
rc = pgm->read_byte(pgm, p, mem, addr, &r);
|
2001-11-21 02:46:55 +00:00
|
|
|
if (rc != 0) {
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
pgm->err_led(pgm, OFF);
|
2002-02-14 02:48:07 +00:00
|
|
|
return -5;
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
2003-11-19 18:11:59 +00:00
|
|
|
else {
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Do polling, but timeout after max_write_delay.
|
|
|
|
*/
|
2006-11-20 15:04:09 +00:00
|
|
|
rc = pgm->read_byte(pgm, p, mem, addr, &r);
|
2003-11-19 18:11:59 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
pgm->err_led(pgm, ON);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
prog_time = (tv.tv_sec * 1000000) + tv.tv_usec;
|
|
|
|
} while ((r != data) &&
|
|
|
|
((prog_time-start_time) < mem->max_write_delay));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we either have a valid readback or the
|
|
|
|
* max_write_delay is expired.
|
|
|
|
*/
|
2002-01-12 01:26:09 +00:00
|
|
|
|
2001-10-14 02:53:21 +00:00
|
|
|
if (r == data) {
|
2001-01-19 02:46:50 +00:00
|
|
|
ready = 1;
|
|
|
|
}
|
2002-02-14 02:48:07 +00:00
|
|
|
else if (mem->pwroff_after_write) {
|
|
|
|
/*
|
|
|
|
* The device has been flagged as power-off after write to this
|
|
|
|
* memory type. The reason we don't just blindly follow the
|
|
|
|
* flag is that the power-off advice may only apply to some
|
|
|
|
* memory bits but not all. We only actually power-off the
|
|
|
|
* device if the data read back does not match what we wrote.
|
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: this device must be powered off and back on to continue\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
2002-02-14 02:48:07 +00:00
|
|
|
if (pgm->pinno[PPI_AVR_VCC]) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: attempting to do this now ...\n", progname);
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->powerdown(pgm);
|
2002-02-14 02:48:07 +00:00
|
|
|
usleep(250000);
|
2002-11-30 14:09:12 +00:00
|
|
|
rc = pgm->initialize(pgm, p);
|
2002-02-14 02:48:07 +00:00
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: initialization failed, rc=%d\n", progname, rc);
|
|
|
|
avrdude_message(MSG_INFO, "%s: can't re-initialize device after programming the "
|
2014-05-18 08:41:46 +00:00
|
|
|
"%s bits\n", progname, mem->desc);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: you must manually power-down the device and restart\n"
|
2014-05-18 08:41:46 +00:00
|
|
|
"%s: %s to continue.\n",
|
|
|
|
progname, progname, progname);
|
2002-02-14 02:48:07 +00:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: device was successfully re-initialized\n",
|
2002-02-14 02:48:07 +00:00
|
|
|
progname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
tries++;
|
2001-10-14 02:53:21 +00:00
|
|
|
if (!ready && tries > 5) {
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2002-02-14 02:48:07 +00:00
|
|
|
* we wrote the data, but after waiting for what should have
|
|
|
|
* been plenty of time, the memory cell still doesn't match what
|
|
|
|
* we wrote. Indicate a write error.
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
|
|
|
pgm->err_led(pgm, ON);
|
2002-01-12 01:26:09 +00:00
|
|
|
|
2002-02-14 02:48:07 +00:00
|
|
|
return -6;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->pgm_led(pgm, OFF);
|
2001-01-19 02:46:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-23 23:22:50 +00:00
|
|
|
/*
|
|
|
|
* write a byte of data at the specified address
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
|
2003-03-23 23:22:50 +00:00
|
|
|
unsigned long addr, unsigned char data)
|
|
|
|
{
|
2006-11-20 15:04:09 +00:00
|
|
|
return pgm->write_byte(pgm, p, mem, addr, data);
|
2003-03-23 23:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
/*
|
2001-11-21 18:54:11 +00:00
|
|
|
* Write the whole memory region of the specified memory from the
|
|
|
|
* corresponding buffer of the avrpart pointed to by 'p'. Write up to
|
|
|
|
* 'size' bytes from the buffer. Data is only written if the new data
|
|
|
|
* value is different from the existing data value. Data beyond
|
|
|
|
* 'size' bytes is not affected.
|
2001-01-20 16:34:28 +00:00
|
|
|
*
|
|
|
|
* Return the number of bytes written, or -1 if an error occurs.
|
2001-01-19 02:46:50 +00:00
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_write(const PROGRAMMER *pgm, const AVRPART *p, const char *memtype,
|
|
|
|
int size, int auto_erase)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
2001-01-22 01:59:47 +00:00
|
|
|
int rc;
|
2011-09-14 21:49:42 +00:00
|
|
|
int newpage, page_tainted, flush_page, do_write;
|
2001-01-22 01:59:47 +00:00
|
|
|
int wsize;
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int i, lastaddr;
|
2001-01-22 01:59:47 +00:00
|
|
|
unsigned char data;
|
2001-02-08 01:05:05 +00:00
|
|
|
int werror;
|
2011-08-23 21:03:36 +00:00
|
|
|
unsigned char cmd[4];
|
2001-11-21 02:46:55 +00:00
|
|
|
AVRMEM * m;
|
|
|
|
|
|
|
|
m = avr_locate_mem(p, memtype);
|
|
|
|
if (m == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "No \"%s\" memory for part %s\n",
|
2001-11-21 02:46:55 +00:00
|
|
|
memtype, p->desc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->err_led(pgm, OFF);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2002-08-01 01:00:03 +00:00
|
|
|
werror = 0;
|
2001-02-08 01:05:05 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
wsize = m->size;
|
2001-01-22 01:59:47 +00:00
|
|
|
if (size < wsize) {
|
|
|
|
wsize = size;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
2001-01-22 01:59:47 +00:00
|
|
|
else if (size > wsize) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: %d bytes requested, but memory region is only %d"
|
2014-05-18 08:41:46 +00:00
|
|
|
"bytes\n"
|
|
|
|
"%sOnly %d bytes will actually be written\n",
|
|
|
|
progname, size, wsize,
|
|
|
|
progbuf, wsize);
|
2001-01-20 16:34:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2022-08-30 15:33:42 +00:00
|
|
|
if ((p->prog_modes & PM_TPI) && m->page_size > 1 && pgm->cmd_tpi) {
|
2022-01-11 21:00:22 +00:00
|
|
|
if (wsize == 1) {
|
|
|
|
/* fuse (configuration) memory: only single byte to write */
|
|
|
|
return avr_write_byte(pgm, p, m, 0, m->buf[0]) == 0? 1: -1;
|
|
|
|
}
|
|
|
|
|
2011-08-23 21:03:36 +00:00
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
|
|
|
|
/* setup for WORD_WRITE */
|
|
|
|
avr_tpi_setup_rw(pgm, m, 0, TPI_NVMCMD_WORD_WRITE);
|
|
|
|
|
|
|
|
/* make sure it's aligned to a word boundary */
|
|
|
|
if (wsize & 0x1) {
|
|
|
|
wsize++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write words, low byte first */
|
2011-09-14 21:49:42 +00:00
|
|
|
for (lastaddr = i = 0; i < wsize; i += 2) {
|
|
|
|
if ((m->tags[i] & TAG_ALLOCATED) != 0 ||
|
|
|
|
(m->tags[i + 1] & TAG_ALLOCATED) != 0) {
|
|
|
|
|
|
|
|
if (lastaddr != i) {
|
|
|
|
/* need to setup new address */
|
|
|
|
avr_tpi_setup_rw(pgm, m, i, TPI_NVMCMD_WORD_WRITE);
|
|
|
|
lastaddr = i;
|
|
|
|
}
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
cmd[0] = TPI_CMD_SST_PI;
|
|
|
|
cmd[1] = m->buf[i];
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
2011-08-23 21:03:36 +00:00
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
cmd[1] = m->buf[i + 1];
|
|
|
|
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
|
|
|
|
|
|
|
|
lastaddr += 2;
|
|
|
|
|
|
|
|
while (avr_tpi_poll_nvmbsy(pgm));
|
|
|
|
}
|
2011-08-23 21:03:36 +00:00
|
|
|
report_progress(i, wsize, NULL);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:26:05 +00:00
|
|
|
if (pgm->paged_write != NULL && m->page_size > 1) {
|
2010-01-12 15:42:40 +00:00
|
|
|
/*
|
2011-09-14 21:49:42 +00:00
|
|
|
* the programmer supports a paged mode write
|
2010-01-12 15:42:40 +00:00
|
|
|
*/
|
2011-09-14 21:49:42 +00:00
|
|
|
int need_write, failure;
|
|
|
|
unsigned int pageaddr;
|
2013-09-13 09:42:47 +00:00
|
|
|
unsigned int npages, nwritten;
|
|
|
|
|
|
|
|
/* quickly scan number of pages to be written to first */
|
|
|
|
for (pageaddr = 0, npages = 0;
|
|
|
|
pageaddr < wsize;
|
|
|
|
pageaddr += m->page_size) {
|
|
|
|
/* check whether this page must be written to */
|
|
|
|
for (i = pageaddr;
|
|
|
|
i < pageaddr + m->page_size;
|
|
|
|
i++)
|
|
|
|
if ((m->tags[i] & TAG_ALLOCATED) != 0) {
|
|
|
|
npages++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-14 21:49:42 +00:00
|
|
|
|
2013-09-13 09:42:47 +00:00
|
|
|
for (pageaddr = 0, failure = 0, nwritten = 0;
|
2011-09-14 21:49:42 +00:00
|
|
|
!failure && pageaddr < wsize;
|
|
|
|
pageaddr += m->page_size) {
|
|
|
|
/* check whether this page must be written to */
|
|
|
|
for (i = pageaddr, need_write = 0;
|
|
|
|
i < pageaddr + m->page_size;
|
|
|
|
i++)
|
|
|
|
if ((m->tags[i] & TAG_ALLOCATED) != 0) {
|
|
|
|
need_write = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (need_write) {
|
2012-05-04 10:02:30 +00:00
|
|
|
rc = 0;
|
|
|
|
if (auto_erase)
|
|
|
|
rc = pgm->page_erase(pgm, p, m, pageaddr);
|
|
|
|
if (rc >= 0)
|
2012-01-19 20:06:52 +00:00
|
|
|
rc = pgm->paged_write(pgm, p, m, m->page_size, pageaddr, m->page_size);
|
|
|
|
if (rc < 0)
|
2011-09-14 21:49:42 +00:00
|
|
|
/* paged write failed, fall back to byte-at-a-time write below */
|
|
|
|
failure = 1;
|
2014-06-13 20:07:40 +00:00
|
|
|
} else {
|
|
|
|
avrdude_message(MSG_DEBUG, "%s: avr_write(): skipping page %u: no interesting data\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, pageaddr / m->page_size);
|
2011-09-14 21:49:42 +00:00
|
|
|
}
|
2013-09-13 09:42:47 +00:00
|
|
|
nwritten++;
|
|
|
|
report_progress(nwritten, npages, NULL);
|
2011-09-14 21:49:42 +00:00
|
|
|
}
|
|
|
|
if (!failure)
|
|
|
|
return wsize;
|
|
|
|
/* else: fall back to byte-at-a-time write, for historical reasons */
|
2003-03-05 04:30:20 +00:00
|
|
|
}
|
|
|
|
|
2003-03-24 07:09:16 +00:00
|
|
|
if (pgm->write_setup) {
|
|
|
|
pgm->write_setup(pgm, p, m);
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
newpage = 1;
|
|
|
|
page_tainted = 0;
|
|
|
|
flush_page = 0;
|
|
|
|
|
2001-01-22 01:59:47 +00:00
|
|
|
for (i=0; i<wsize; i++) {
|
2001-11-21 02:46:55 +00:00
|
|
|
data = m->buf[i];
|
2003-07-29 22:08:21 +00:00
|
|
|
report_progress(i, wsize, NULL);
|
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
/*
|
|
|
|
* Find out whether the write action must be invoked for this
|
|
|
|
* byte.
|
|
|
|
*
|
|
|
|
* For non-paged memory, this only happens if TAG_ALLOCATED is
|
|
|
|
* set for the byte.
|
|
|
|
*
|
|
|
|
* For paged memory, TAG_ALLOCATED also invokes the write
|
|
|
|
* operation, which is actually a page buffer fill only. This
|
|
|
|
* "taints" the page, and upon encountering the last byte of each
|
|
|
|
* tainted page, the write operation must also be invoked in order
|
|
|
|
* to actually write the page buffer to memory.
|
|
|
|
*/
|
|
|
|
do_write = (m->tags[i] & TAG_ALLOCATED) != 0;
|
|
|
|
if (m->paged) {
|
|
|
|
if (newpage) {
|
|
|
|
page_tainted = do_write;
|
|
|
|
} else {
|
|
|
|
page_tainted |= do_write;
|
|
|
|
}
|
|
|
|
if (i % m->page_size == m->page_size - 1 ||
|
|
|
|
i == wsize - 1) {
|
|
|
|
/* last byte this page */
|
|
|
|
flush_page = page_tainted;
|
|
|
|
newpage = 1;
|
|
|
|
} else {
|
|
|
|
flush_page = newpage = 0;
|
|
|
|
}
|
2001-02-08 01:05:05 +00:00
|
|
|
}
|
2001-10-14 02:53:21 +00:00
|
|
|
|
2011-09-14 21:49:42 +00:00
|
|
|
if (!do_write && !flush_page) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_write) {
|
|
|
|
rc = avr_write_byte(pgm, p, m, i, data);
|
|
|
|
if (rc) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, " ***failed; ");
|
|
|
|
avrdude_message(MSG_INFO, "\n");
|
2011-09-14 21:49:42 +00:00
|
|
|
pgm->err_led(pgm, ON);
|
|
|
|
werror = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check to see if it is time to flush the page with a page
|
|
|
|
* write
|
|
|
|
*/
|
|
|
|
if (flush_page) {
|
|
|
|
rc = avr_write_page(pgm, p, m, i);
|
|
|
|
if (rc) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, " *** page %d (addresses 0x%04x - 0x%04x) failed "
|
2014-05-18 08:41:46 +00:00
|
|
|
"to write\n",
|
|
|
|
i % m->page_size,
|
|
|
|
i - m->page_size + 1, i);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "\n");
|
2011-09-14 21:49:42 +00:00
|
|
|
pgm->err_led(pgm, ON);
|
2001-10-14 02:53:21 +00:00
|
|
|
werror = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-08 01:05:05 +00:00
|
|
|
if (werror) {
|
2014-05-18 08:41:46 +00:00
|
|
|
/*
|
2001-02-08 01:05:05 +00:00
|
|
|
* make sure the error led stay on if there was a previous write
|
2003-11-30 16:42:10 +00:00
|
|
|
* error, otherwise it gets cleared in avr_write_byte()
|
2001-02-08 01:05:05 +00:00
|
|
|
*/
|
2002-11-30 14:09:12 +00:00
|
|
|
pgm->err_led(pgm, ON);
|
2001-01-22 01:59:47 +00:00
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
2005-09-21 00:20:32 +00:00
|
|
|
|
2001-01-22 01:59:47 +00:00
|
|
|
return i;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read the AVR device's signature bytes
|
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_signature(const PROGRAMMER *pgm, const AVRPART *p) {
|
2001-11-21 02:46:55 +00:00
|
|
|
int rc;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2003-07-29 22:08:21 +00:00
|
|
|
report_progress (0,1,"Reading");
|
2012-05-04 10:02:30 +00:00
|
|
|
rc = avr_read(pgm, p, "signature", 0);
|
2022-06-15 21:32:22 +00:00
|
|
|
if (rc < LIBAVRDUDE_SUCCESS) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, p->desc, rc);
|
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9507: Fix UPDI chip erase
* lexer.l (family_id): New keyword.
* config_gram.y: (Ditto)
* doc/avrdude.texi: Document new keyword
* avrdude.conf.in: Add family_id for avr8x devices
* avr.c: Pass error code up.
* jtag3.c: Pass error code from memory read up; implement
jtag3_read_sib()
* libavrdude.h: Add new items.
* main.c: Implement different chip erase handling required
for UPDI devices.
Submitted by Jan Egil Ruud <janegil.ruud@microchip.com>
patch #9506: Script to create device configuration stub from Atmel ATDF files
* avrdude.conf.in (ATtiny202, ATtiny204, ATtiny402, ATtiny404)
(ATtiny406, ATtiny804, ATtiny806, ATtiny807, ATtiny1604)
(ATtiny1606, ATtiny1607, ATtiny212, ATtiny214, ATtiny412)
(ATTiny414, ATtiny416, ATtiny417, ATtiny814, ATtiny816)
(ATtiny1614, ATtiny1616, ATtiny3214, ATtiny3216, ATtiny3217)
(ATmega3208, ATmega3209, ATmega4808, ATmega4809): New devices
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1405 81a1dc3b-b13d-400b-aceb-764788c761c2
2018-01-09 23:29:31 +00:00
|
|
|
return rc;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
2003-07-29 22:08:21 +00:00
|
|
|
report_progress (1,1,NULL);
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2022-06-15 21:32:22 +00:00
|
|
|
return LIBAVRDUDE_SUCCESS;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 22:02:29 +00:00
|
|
|
static uint8_t get_fuse_bitmask(AVRMEM * m) {
|
|
|
|
uint8_t bitmask_r = 0;
|
|
|
|
uint8_t bitmask_w = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!m || m->size > 1) {
|
|
|
|
// not a fuse, compare bytes directly
|
|
|
|
return 0xFF;
|
|
|
|
}
|
|
|
|
|
2022-01-11 21:00:22 +00:00
|
|
|
if (m->op[AVR_OP_WRITE] == NULL ||
|
|
|
|
m->op[AVR_OP_READ] == NULL)
|
|
|
|
// no memory operations provided by configuration, compare directly
|
|
|
|
return 0xFF;
|
|
|
|
|
2021-11-12 22:02:29 +00:00
|
|
|
// For fuses, only compare bytes that are actually written *and* read.
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (m->op[AVR_OP_WRITE]->bit[i].type == AVR_CMDBIT_INPUT)
|
|
|
|
bitmask_w |= (1 << m->op[AVR_OP_WRITE]->bit[i].bitno);
|
|
|
|
if (m->op[AVR_OP_READ]->bit[i].type == AVR_CMDBIT_OUTPUT)
|
|
|
|
bitmask_r |= (1 << m->op[AVR_OP_READ]->bit[i].bitno);
|
|
|
|
}
|
|
|
|
return bitmask_r & bitmask_w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int compare_memory_masked(AVRMEM * m, uint8_t b1, uint8_t b2) {
|
|
|
|
uint8_t bitmask = get_fuse_bitmask(m);
|
|
|
|
return (b1 & bitmask) != (b2 & bitmask);
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
/*
|
2001-01-26 17:22:40 +00:00
|
|
|
* Verify the memory buffer of p with that of v. The byte range of v,
|
|
|
|
* may be a subset of p. The byte range of p should cover the whole
|
|
|
|
* chip's memory size.
|
|
|
|
*
|
2003-11-30 16:42:10 +00:00
|
|
|
* Return the number of bytes verified, or -1 if they don't match.
|
2001-01-20 16:34:28 +00:00
|
|
|
*/
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_verify(const AVRPART * p, const AVRPART * v, const char * memtype, int size)
|
2001-01-19 02:46:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char * buf1, * buf2;
|
2001-01-20 16:34:28 +00:00
|
|
|
int vsize;
|
2001-11-21 02:46:55 +00:00
|
|
|
AVRMEM * a, * b;
|
|
|
|
|
|
|
|
a = avr_locate_mem(p, memtype);
|
|
|
|
if (a == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
memtype, p->desc);
|
2001-11-21 02:46:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
b = avr_locate_mem(v, memtype);
|
|
|
|
if (b == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "avr_verify(): memory type \"%s\" not defined for part %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
memtype, v->desc);
|
2001-11-21 02:46:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
buf1 = a->buf;
|
|
|
|
buf2 = b->buf;
|
|
|
|
vsize = a->size;
|
2001-01-19 02:46:50 +00:00
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
if (vsize < size) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: requested verification for %d bytes\n"
|
2014-05-18 08:41:46 +00:00
|
|
|
"%s%s memory region only contains %d bytes\n"
|
|
|
|
"%sOnly %d bytes will be verified.\n",
|
|
|
|
progname, size,
|
|
|
|
progbuf, memtype, vsize,
|
|
|
|
progbuf, vsize);
|
2001-01-20 16:34:28 +00:00
|
|
|
size = vsize;
|
|
|
|
}
|
|
|
|
|
2001-01-19 02:46:50 +00:00
|
|
|
for (i=0; i<size; i++) {
|
2011-09-14 21:49:42 +00:00
|
|
|
if ((b->tags[i] & TAG_ALLOCATED) != 0 &&
|
|
|
|
buf1[i] != buf2[i]) {
|
2021-11-12 22:02:29 +00:00
|
|
|
uint8_t bitmask = get_fuse_bitmask(a);
|
|
|
|
if((buf1[i] & bitmask) != (buf2[i] & bitmask)) {
|
|
|
|
// Mismatch is not just in unused bits
|
|
|
|
avrdude_message(MSG_INFO, "%s: verification error, first mismatch at byte 0x%04x\n"
|
|
|
|
"%s0x%02x != 0x%02x\n",
|
|
|
|
progname, i,
|
|
|
|
progbuf, buf1[i], buf2[i]);
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
// Mismatch is only in unused bits
|
|
|
|
if ((buf1[i] | bitmask) != 0xff) {
|
|
|
|
// Programmer returned unused bits as 0, must be the part/programmer
|
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: ignoring mismatch in unused bits of \"%s\"\n"
|
|
|
|
"%s(0x%02x != 0x%02x). To prevent this warning fix the part\n"
|
|
|
|
"%sor programmer definition in the config file.\n",
|
|
|
|
progname, memtype, progbuf, buf1[i], buf2[i], progbuf);
|
|
|
|
} else {
|
|
|
|
// Programmer returned unused bits as 1, must be the user
|
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: ignoring mismatch in unused bits of \"%s\"\n"
|
|
|
|
"%s(0x%02x != 0x%02x). To prevent this warning set unused bits\n"
|
|
|
|
"%sto 1 when writing (double check with your datasheet first).\n",
|
|
|
|
progname, memtype, progbuf, buf1[i], buf2[i], progbuf);
|
|
|
|
}
|
|
|
|
}
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-20 16:34:28 +00:00
|
|
|
return size;
|
2001-01-19 02:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_get_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int *cycles) {
|
2002-08-01 01:00:03 +00:00
|
|
|
AVRMEM * a;
|
2004-01-03 18:04:54 +00:00
|
|
|
unsigned int cycle_count = 0;
|
|
|
|
unsigned char v1;
|
2002-08-01 01:00:03 +00:00
|
|
|
int rc;
|
2004-01-03 18:04:54 +00:00
|
|
|
int i;
|
2002-08-01 01:00:03 +00:00
|
|
|
|
|
|
|
a = avr_locate_mem(p, "eeprom");
|
|
|
|
if (a == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
for (i=4; i>0; i--) {
|
2006-11-20 15:04:09 +00:00
|
|
|
rc = pgm->read_byte(pgm, p, a, a->size-i, &v1);
|
2002-08-01 01:00:03 +00:00
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: can't read memory for cycle count, rc=%d\n",
|
2002-08-01 01:00:03 +00:00
|
|
|
progname, rc);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-03 18:04:54 +00:00
|
|
|
cycle_count = (cycle_count << 8) | v1;
|
2002-10-11 19:36:56 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
/*
|
|
|
|
* If the EEPROM is erased, the cycle count reads 0xffffffff.
|
|
|
|
* In this case we return a cycle_count of zero.
|
|
|
|
* So, the calling function don't have to care about whether or not
|
|
|
|
* the cycle count was initialized.
|
|
|
|
*/
|
|
|
|
if (cycle_count == 0xffffffff) {
|
|
|
|
cycle_count = 0;
|
2002-11-01 14:40:23 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
*cycles = (int) cycle_count;
|
2002-11-06 02:19:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-08-01 01:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_put_cycle_count(const PROGRAMMER *pgm, const AVRPART *p, int cycles) {
|
2002-08-01 01:00:03 +00:00
|
|
|
AVRMEM * a;
|
2004-01-03 18:04:54 +00:00
|
|
|
unsigned char v1;
|
2002-08-01 01:00:03 +00:00
|
|
|
int rc;
|
2004-01-03 18:04:54 +00:00
|
|
|
int i;
|
2002-08-01 01:00:03 +00:00
|
|
|
|
|
|
|
a = avr_locate_mem(p, "eeprom");
|
|
|
|
if (a == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
for (i=1; i<=4; i++) {
|
|
|
|
v1 = cycles & 0xff;
|
|
|
|
cycles = cycles >> 8;
|
2002-08-01 01:00:03 +00:00
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
rc = avr_write_byte(pgm, p, a, a->size-i, v1);
|
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: WARNING: can't write memory for cycle count, rc=%d\n",
|
2004-01-03 18:04:54 +00:00
|
|
|
progname, rc);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-11 19:36:56 +00:00
|
|
|
}
|
2004-01-03 18:04:54 +00:00
|
|
|
|
|
|
|
return 0;
|
2022-08-02 22:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Typical order in which memories show in avrdude.conf, runtime adds unknown ones (if any)
|
|
|
|
const char *avr_mem_order[100] = {
|
|
|
|
"eeprom", "flash", "application", "apptable",
|
|
|
|
"boot", "lfuse", "hfuse", "efuse",
|
|
|
|
"fuse", "fuse0", "wdtcfg", "fuse1",
|
|
|
|
"bodcfg", "fuse2", "osccfg", "fuse3",
|
|
|
|
"fuse4", "tcd0cfg", "fuse5", "syscfg0",
|
|
|
|
"fuse6", "syscfg1", "fuse7", "append",
|
|
|
|
"codesize", "fuse8", "fuse9", "bootend",
|
|
|
|
"bootsize", "fuses", "lock", "lockbits",
|
|
|
|
"tempsense", "signature", "prodsig", "sernum",
|
|
|
|
"calibration", "osccal16", "osccal20", "osc16err",
|
|
|
|
"osc20err", "usersig", "userrow", "data",
|
|
|
|
};
|
|
|
|
|
|
|
|
void avr_add_mem_order(const char *str) {
|
|
|
|
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) {
|
|
|
|
if(avr_mem_order[i] && !strcmp(avr_mem_order[i], str))
|
|
|
|
return;
|
|
|
|
if(!avr_mem_order[i]) {
|
2022-08-09 20:20:44 +00:00
|
|
|
avr_mem_order[i] = cfg_strdup("avr_mem_order()", str);
|
2022-08-02 22:53:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-11 19:36:56 +00:00
|
|
|
}
|
2022-08-02 22:53:00 +00:00
|
|
|
avrdude_message(MSG_INFO,
|
|
|
|
"%s: avr_mem_order[] under-dimensioned in avr.c; increase and recompile\n",
|
|
|
|
progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
2022-08-15 13:57:04 +00:00
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_mem_is_flash_type(const AVRMEM *mem) {
|
2022-08-15 13:57:04 +00:00
|
|
|
return
|
|
|
|
strcmp(mem->desc, "flash") == 0 ||
|
|
|
|
strcmp(mem->desc, "application") == 0 ||
|
|
|
|
strcmp(mem->desc, "apptable") == 0 ||
|
|
|
|
strcmp(mem->desc, "boot") == 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_mem_is_eeprom_type(const AVRMEM *mem) {
|
2022-08-15 13:57:04 +00:00
|
|
|
return strcmp(mem->desc, "eeprom") == 0;
|
|
|
|
}
|
2022-08-02 22:53:00 +00:00
|
|
|
|
2022-08-02 23:04:14 +00:00
|
|
|
int avr_mem_is_known(const char *str) {
|
2022-08-03 23:14:19 +00:00
|
|
|
if(str && *str)
|
|
|
|
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++)
|
|
|
|
if(avr_mem_order[i] && !strcmp(avr_mem_order[i], str))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int avr_mem_might_be_known(const char *str) {
|
|
|
|
if(str && *str)
|
|
|
|
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++)
|
|
|
|
if(avr_mem_order[i] && !strncmp(avr_mem_order[i], str, strlen(str)))
|
|
|
|
return 1;
|
2022-08-02 22:53:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-03 18:04:54 +00:00
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2004-01-03 18:04:54 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = pgm->chip_erase(pgm, p);
|
|
|
|
|
|
|
|
return rc;
|
2002-08-01 01:00:03 +00:00
|
|
|
}
|
2007-01-24 22:43:46 +00:00
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
int avr_unlock(const PROGRAMMER *pgm, const AVRPART *p) {
|
2018-01-16 21:17:04 +00:00
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
if (pgm->unlock)
|
|
|
|
rc = pgm->unlock(pgm, p);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-01-24 22:43:46 +00:00
|
|
|
/*
|
|
|
|
* Report the progress of a read or write operation from/to the
|
|
|
|
* device.
|
|
|
|
*
|
|
|
|
* The first call of report_progress() should look like this (for a write op):
|
|
|
|
*
|
|
|
|
* report_progress (0, 1, "Writing");
|
|
|
|
*
|
|
|
|
* Then hdr should be passed NULL on subsequent calls while the
|
|
|
|
* operation is progressing. Once the operation is complete, a final
|
|
|
|
* call should be made as such to ensure proper termination of the
|
|
|
|
* progress report:
|
|
|
|
*
|
|
|
|
* report_progress (1, 1, NULL);
|
|
|
|
*
|
|
|
|
* It would be nice if we could reduce the usage to one and only one
|
|
|
|
* call for each of start, during and end cases. As things stand now,
|
|
|
|
* that is not possible and makes maintenance a bit more work.
|
|
|
|
*/
|
|
|
|
void report_progress (int completed, int total, char *hdr)
|
|
|
|
{
|
|
|
|
static int last = 0;
|
|
|
|
static double start_time;
|
2014-11-14 10:22:52 +00:00
|
|
|
int percent = (total > 0) ? ((completed * 100) / total) : 100;
|
2007-01-24 22:43:46 +00:00
|
|
|
struct timeval tv;
|
|
|
|
double t;
|
|
|
|
|
|
|
|
if (update_progress == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
t = tv.tv_sec + ((double)tv.tv_usec)/1000000;
|
|
|
|
|
|
|
|
if (hdr) {
|
|
|
|
last = 0;
|
|
|
|
start_time = t;
|
|
|
|
update_progress (percent, t - start_time, hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (percent > 100)
|
|
|
|
percent = 100;
|
|
|
|
|
|
|
|
if (percent > last) {
|
|
|
|
last = percent;
|
|
|
|
update_progress (percent, t - start_time, hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (percent == 100)
|
|
|
|
last = 0; /* Get ready for next time. */
|
|
|
|
}
|