2003-11-30 15:16:48 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2004-12-22 01:52:45 +00:00
|
|
|
* Copyright (C) 2003-2004 Theodore A. Roth <troth@openavr.org>
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
* Copyright (C) 2005, 2007 Joerg Wunsch <j@uriah.heep.sax.de>
|
2003-11-30 15:16:48 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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/>.
|
2003-11-30 15:16:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* avrdude interface for the serial programming mode of the Atmel butterfly
|
|
|
|
* evaluation board. This board features a bootloader which uses a protocol
|
|
|
|
* very similar, but not identical, to the one described in application note
|
|
|
|
* avr910.
|
2005-07-28 16:06:35 +00:00
|
|
|
*
|
|
|
|
* Actually, the butterfly uses a predecessor of the avr910 protocol
|
|
|
|
* which is described in application notes avr109 (generic AVR
|
|
|
|
* bootloader) and avr911 (opensource programmer). This file now
|
|
|
|
* fully handles the features present in avr109. It should probably
|
|
|
|
* be renamed to avr109, but we rather stick with the old name inside
|
|
|
|
* the file. We'll provide aliases for "avr109" and "avr911" in
|
|
|
|
* avrdude.conf so users could call it by these name as well.
|
2003-11-30 15:16:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
2011-08-26 20:50:32 +00:00
|
|
|
#include <unistd.h>
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2003-11-30 15:16:48 +00:00
|
|
|
#include "butterfly.h"
|
|
|
|
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
/*
|
|
|
|
* Private data for this programmer.
|
|
|
|
*/
|
|
|
|
struct pdata
|
|
|
|
{
|
|
|
|
char has_auto_incr_addr;
|
|
|
|
unsigned int buffersize;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
|
|
|
|
|
|
|
|
static void butterfly_setup(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: butterfly_setup(): Out of memory allocating private data\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memset(pgm->cookie, 0, sizeof(struct pdata));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void butterfly_teardown(PROGRAMMER * pgm)
|
|
|
|
{
|
|
|
|
free(pgm->cookie);
|
|
|
|
}
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_send(const PROGRAMMER *pgm, char *buf, size_t len) {
|
2006-12-11 12:47:35 +00:00
|
|
|
return serial_send(&pgm->fd, (unsigned char *)buf, len);
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_recv(const PROGRAMMER *pgm, char *buf, size_t len) {
|
2005-05-11 17:09:22 +00:00
|
|
|
int rv;
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rv = serial_recv(&pgm->fd, (unsigned char *)buf, len);
|
2005-05-11 17:09:22 +00:00
|
|
|
if (rv < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: butterfly_recv(): programmer is not responding\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2005-05-11 17:09:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_drain(const PROGRAMMER *pgm, int display) {
|
2006-12-11 12:47:35 +00:00
|
|
|
return serial_drain(&pgm->fd, display);
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_vfy_cmd_sent(const PROGRAMMER *pgm, char *errmsg) {
|
2003-11-30 15:16:48 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
|
|
|
if (c != '\r') {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: error: programmer did not respond to command: %s\n",
|
2003-11-30 15:16:48 +00:00
|
|
|
progname, errmsg);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-11-30 15:16:48 +00:00
|
|
|
}
|
2014-05-16 15:52:25 +00:00
|
|
|
return 0;
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_rdy_led(const PROGRAMMER *pgm, int value) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
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
|
|
|
static int butterfly_err_led(const PROGRAMMER *pgm, int value) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
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
|
|
|
static int butterfly_pgm_led(const PROGRAMMER *pgm, int value) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
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
|
|
|
static int butterfly_vfy_led(const PROGRAMMER *pgm, int value) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-30 15:16:48 +00:00
|
|
|
/*
|
|
|
|
* issue the 'chip erase' command to the butterfly board
|
|
|
|
*/
|
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 butterfly_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
2003-11-30 15:16:48 +00:00
|
|
|
butterfly_send(pgm, "e", 1);
|
2014-05-16 15:52:25 +00:00
|
|
|
if (butterfly_vfy_cmd_sent(pgm, "chip erase") < 0)
|
|
|
|
return -1;
|
2003-11-30 15:16:48 +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
|
|
|
static void butterfly_enter_prog_mode(const PROGRAMMER *pgm) {
|
2003-11-30 15:16:48 +00:00
|
|
|
butterfly_send(pgm, "P", 1);
|
|
|
|
butterfly_vfy_cmd_sent(pgm, "enter prog mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 void butterfly_leave_prog_mode(const PROGRAMMER *pgm) {
|
2003-11-30 15:16:48 +00:00
|
|
|
butterfly_send(pgm, "L", 1);
|
|
|
|
butterfly_vfy_cmd_sent(pgm, "leave prog mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* issue the 'program enable' command to the AVR device
|
|
|
|
*/
|
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 butterfly_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2003-11-30 15:16:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-24 11:05:07 +00:00
|
|
|
/*
|
|
|
|
* apply power to the AVR processor
|
|
|
|
*/
|
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 void butterfly_powerup(const PROGRAMMER *pgm) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove power from the AVR processor
|
|
|
|
*/
|
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 void butterfly_powerdown(const PROGRAMMER *pgm) {
|
2004-06-24 11:05:07 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:50:32 +00:00
|
|
|
#define IS_BUTTERFLY_MK 0x0001
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the AVR device and prepare it to accept commands
|
|
|
|
*/
|
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 butterfly_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2003-11-30 15:16:48 +00:00
|
|
|
char id[8];
|
|
|
|
char sw[2];
|
|
|
|
char hw[2];
|
|
|
|
char buf[10];
|
|
|
|
char type;
|
2007-01-11 20:20:25 +00:00
|
|
|
char c, devtype_1st;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2005-07-28 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* Send some ESC to activate butterfly bootloader. This is not needed
|
|
|
|
* for plain avr109 bootloaders but does not harm there either.
|
|
|
|
*/
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Connecting to programmer: ");
|
2011-08-26 20:50:32 +00:00
|
|
|
if (pgm->flag & IS_BUTTERFLY_MK)
|
|
|
|
{
|
|
|
|
char mk_reset_cmd[6] = {"#aR@S\r"};
|
|
|
|
unsigned char mk_timeout = 0;
|
|
|
|
|
|
|
|
putc('.', stderr);
|
|
|
|
butterfly_send(pgm, mk_reset_cmd, sizeof(mk_reset_cmd));
|
|
|
|
usleep(20000);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = 27;
|
|
|
|
butterfly_send(pgm, &c, 1);
|
|
|
|
usleep(20000);
|
|
|
|
c = 0xaa;
|
|
|
|
usleep(80000);
|
|
|
|
butterfly_send(pgm, &c, 1);
|
|
|
|
if (mk_timeout % 10 == 0) putc('.', stderr);
|
|
|
|
} while (mk_timeout++ < 10);
|
|
|
|
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
2014-05-18 08:41:46 +00:00
|
|
|
if ( c != 'M' && c != '?')
|
|
|
|
{
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "\nConnection FAILED.");
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2011-08-26 20:50:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id[0] = 'M'; id[1] = 'K'; id[2] = '2'; id[3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
putc('.', stderr);
|
|
|
|
butterfly_send(pgm, "\033", 1);
|
|
|
|
butterfly_drain(pgm, 0);
|
|
|
|
butterfly_send(pgm, "S", 1);
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
|
|
|
if (c != '?') {
|
|
|
|
putc('\n', stderr);
|
|
|
|
/*
|
|
|
|
* Got a useful response, continue getting the programmer
|
|
|
|
* identifier. Programmer returns exactly 7 chars _without_
|
|
|
|
* the null.
|
|
|
|
*/
|
|
|
|
id[0] = c;
|
|
|
|
butterfly_recv(pgm, &id[1], sizeof(id)-2);
|
|
|
|
id[sizeof(id)-1] = '\0';
|
|
|
|
}
|
|
|
|
} while (c == '?');
|
2005-09-16 14:54:55 +00:00
|
|
|
}
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/* Get the HW and SW versions to see if the programmer is present. */
|
2011-08-26 20:50:32 +00:00
|
|
|
butterfly_drain(pgm, 0);
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
butterfly_send(pgm, "V", 1);
|
|
|
|
butterfly_recv(pgm, sw, sizeof(sw));
|
|
|
|
|
|
|
|
butterfly_send(pgm, "v", 1);
|
|
|
|
butterfly_recv(pgm, hw, 1); /* first, read only _one_ byte */
|
|
|
|
if (hw[0]!='?') {
|
|
|
|
butterfly_recv(pgm, &hw[1], 1);/* now, read second byte */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get the programmer type (serial or parallel). Expect serial. */
|
|
|
|
|
|
|
|
butterfly_send(pgm, "p", 1);
|
|
|
|
butterfly_recv(pgm, &type, 1);
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Found programmer: Id = \"%s\"; type = %c\n", id, type);
|
|
|
|
avrdude_message(MSG_INFO, " Software Version = %c.%c; ", sw[0], sw[1]);
|
2003-11-30 15:16:48 +00:00
|
|
|
if (hw[0]=='?') {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "No Hardware Version given.\n");
|
2003-11-30 15:16:48 +00:00
|
|
|
} else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Hardware Version = %c.%c\n", hw[0], hw[1]);
|
2003-11-30 15:16:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* See if programmer supports autoincrement of address. */
|
|
|
|
|
|
|
|
butterfly_send(pgm, "a", 1);
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
butterfly_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1);
|
|
|
|
if (PDATA(pgm)->has_auto_incr_addr == 'Y')
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Programmer supports auto addr increment.\n");
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/* Check support for buffered memory access, abort if not available */
|
|
|
|
|
|
|
|
butterfly_send(pgm, "b", 1);
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
|
|
|
if (c != 'Y') {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: error: buffered memory access not supported. Maybe it isn't\n"\
|
2014-05-18 08:41:46 +00:00
|
|
|
"a butterfly/AVR109 but a AVR910 device?\n", progname);
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-11-30 15:16:48 +00:00
|
|
|
};
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8;
|
2003-11-30 15:16:48 +00:00
|
|
|
butterfly_recv(pgm, &c, 1);
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c;
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "Programmer supports buffered memory access with buffersize=%i bytes.\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
PDATA(pgm)->buffersize);
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/* Get list of devices that the programmer supports. */
|
|
|
|
|
|
|
|
butterfly_send(pgm, "t", 1);
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "\nProgrammer supports the following devices:\n");
|
2007-01-11 20:20:25 +00:00
|
|
|
devtype_1st = 0;
|
2003-11-30 15:16:48 +00:00
|
|
|
while (1) {
|
|
|
|
butterfly_recv(pgm, &c, 1);
|
2007-01-11 20:20:25 +00:00
|
|
|
if (devtype_1st == 0)
|
|
|
|
devtype_1st = c;
|
|
|
|
|
2003-11-30 15:16:48 +00:00
|
|
|
if (c == 0)
|
|
|
|
break;
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, " Device code: 0x%02x\n", (unsigned int)(unsigned char)c);
|
2003-11-30 15:16:48 +00:00
|
|
|
};
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "\n");
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2007-01-11 20:20:25 +00:00
|
|
|
/* Tell the programmer which part we selected.
|
|
|
|
According to the AVR109 code, this is ignored by the bootloader. As
|
|
|
|
some early versions might not properly ignore it, rather pick up the
|
|
|
|
first device type as reported above than anything out of avrdude.conf,
|
|
|
|
so to avoid a potential conflict. There appears to be no general
|
|
|
|
agreement on AVR910 device IDs beyond the ones from the original
|
|
|
|
appnote 910. */
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
buf[0] = 'T';
|
2007-01-11 20:20:25 +00:00
|
|
|
buf[1] = devtype_1st;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
butterfly_send(pgm, buf, 2);
|
2014-05-16 15:52:25 +00:00
|
|
|
if (butterfly_vfy_cmd_sent(pgm, "select device") < 0)
|
|
|
|
return -1;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2008-06-07 21:03:41 +00:00
|
|
|
if (verbose)
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: devcode selected: 0x%02x\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, (unsigned)buf[1]);
|
2008-06-07 21:03:41 +00:00
|
|
|
|
2006-09-01 10:03:12 +00:00
|
|
|
butterfly_enter_prog_mode(pgm);
|
2011-08-26 20:50:32 +00:00
|
|
|
butterfly_drain(pgm, 0);
|
2005-09-16 14:54:55 +00:00
|
|
|
|
2006-09-01 10:03:12 +00:00
|
|
|
return 0;
|
2003-11-30 15:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-24 11:05:07 +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
|
|
|
static void butterfly_disable(const PROGRAMMER *pgm) {
|
2005-07-28 16:06:35 +00:00
|
|
|
butterfly_leave_prog_mode(pgm);
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 void butterfly_enable(PROGRAMMER *pgm, const AVRPART *p) {
|
2003-11-30 15:16:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 butterfly_open(PROGRAMMER *pgm, const char *port) {
|
2014-02-21 13:44:11 +00:00
|
|
|
union pinfo pinfo;
|
2003-11-30 15:16:48 +00:00
|
|
|
strcpy(pgm->port, port);
|
2005-07-28 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* If baudrate was not specified use 19200 Baud
|
|
|
|
*/
|
|
|
|
if(pgm->baudrate == 0) {
|
|
|
|
pgm->baudrate = 19200;
|
|
|
|
}
|
2021-12-08 10:09:52 +00:00
|
|
|
pinfo.serialinfo.baud = pgm->baudrate;
|
|
|
|
pinfo.serialinfo.cflags = SERIAL_8N1;
|
2014-02-21 13:44:11 +00:00
|
|
|
if (serial_open(port, pinfo, &pgm->fd)==-1) {
|
2010-10-22 14:29:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* drain any extraneous input
|
|
|
|
*/
|
|
|
|
butterfly_drain (pgm, 0);
|
2004-01-28 20:01:44 +00:00
|
|
|
|
|
|
|
return 0;
|
2003-11-30 15:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void butterfly_close(PROGRAMMER * pgm)
|
|
|
|
{
|
2006-08-31 11:02:25 +00:00
|
|
|
/* "exit programmer" */
|
2004-06-24 11:05:07 +00:00
|
|
|
butterfly_send(pgm, "E", 1);
|
2006-08-31 11:02:25 +00:00
|
|
|
butterfly_vfy_cmd_sent(pgm, "exit bootloader");
|
2004-06-24 11:05:07 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
serial_close(&pgm->fd);
|
|
|
|
pgm->fd.ifd = -1;
|
2003-11-30 15:16:48 +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
|
|
|
static void butterfly_display(const PROGRAMMER *pgm, const char *p) {
|
2003-11-30 15:16:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 void butterfly_set_addr(const PROGRAMMER *pgm, unsigned long addr) {
|
2022-09-24 18:42:42 +00:00
|
|
|
if( addr < 0x10000 ) {
|
|
|
|
char cmd[3];
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2022-09-24 18:42:42 +00:00
|
|
|
cmd[0] = 'A';
|
|
|
|
cmd[1] = (addr >> 8) & 0xff;
|
|
|
|
cmd[2] = addr & 0xff;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2022-09-24 18:42:42 +00:00
|
|
|
butterfly_send(pgm, cmd, sizeof(cmd));
|
|
|
|
butterfly_vfy_cmd_sent(pgm, "set addr");
|
|
|
|
} else {
|
|
|
|
char cmd[4];
|
|
|
|
|
|
|
|
cmd[0] = 'H';
|
|
|
|
cmd[1] = (addr >> 16) & 0xff;
|
|
|
|
cmd[2] = (addr >> 8) & 0xff;
|
|
|
|
cmd[3] = addr & 0xff;
|
|
|
|
|
|
|
|
butterfly_send(pgm, cmd, sizeof(cmd));
|
|
|
|
butterfly_vfy_cmd_sent(pgm, "set extaddr");
|
|
|
|
}
|
2003-11-30 15:16:48 +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
|
|
|
static void butterfly_set_extaddr(const PROGRAMMER *pgm, unsigned long addr) {
|
2007-01-30 15:47:53 +00:00
|
|
|
char cmd[4];
|
|
|
|
|
|
|
|
cmd[0] = 'H';
|
|
|
|
cmd[1] = (addr >> 16) & 0xff;
|
|
|
|
cmd[2] = (addr >> 8) & 0xff;
|
|
|
|
cmd[3] = addr & 0xff;
|
|
|
|
|
|
|
|
butterfly_send(pgm, cmd, sizeof(cmd));
|
|
|
|
butterfly_vfy_cmd_sent(pgm, "set extaddr");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2003-11-30 15:16:48 +00:00
|
|
|
unsigned long addr, unsigned char value)
|
|
|
|
{
|
2005-08-30 01:30:05 +00:00
|
|
|
char cmd[6];
|
2003-11-30 15:16:48 +00:00
|
|
|
int size;
|
2007-01-30 15:47:53 +00:00
|
|
|
int use_ext_addr = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2005-07-28 16:06:35 +00:00
|
|
|
if ((strcmp(m->desc, "flash") == 0) || (strcmp(m->desc, "eeprom") == 0))
|
|
|
|
{
|
|
|
|
cmd[0] = 'B';
|
|
|
|
cmd[1] = 0;
|
2010-01-22 16:40:17 +00:00
|
|
|
if ((cmd[3] = toupper((int)(m->desc[0]))) == 'E') { /* write to eeprom */
|
2005-07-28 16:06:35 +00:00
|
|
|
cmd[2] = 1;
|
|
|
|
cmd[4] = value;
|
|
|
|
size = 5;
|
|
|
|
} else { /* write to flash */
|
|
|
|
/* @@@ not yet implemented */
|
|
|
|
cmd[2] = 2;
|
|
|
|
size = 6;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-30 15:47:53 +00:00
|
|
|
if (use_ext_addr) {
|
|
|
|
butterfly_set_extaddr(pgm, addr);
|
|
|
|
} else {
|
|
|
|
butterfly_set_addr(pgm, addr);
|
|
|
|
}
|
2005-07-28 16:06:35 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(m->desc, "lock") == 0)
|
|
|
|
{
|
|
|
|
cmd[0] = 'l';
|
|
|
|
cmd[1] = value;
|
|
|
|
size = 2;
|
|
|
|
}
|
|
|
|
else
|
2003-11-30 15:16:48 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
butterfly_send(pgm, cmd, size);
|
2014-05-16 15:52:25 +00:00
|
|
|
if (butterfly_vfy_cmd_sent(pgm, "write byte") < 0)
|
|
|
|
return -1;
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_read_byte_flash(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2003-11-30 15:16:48 +00:00
|
|
|
unsigned long addr, unsigned char * value)
|
|
|
|
{
|
|
|
|
static int cached = 0;
|
|
|
|
static unsigned char cvalue;
|
|
|
|
static unsigned long caddr;
|
2007-01-30 15:47:53 +00:00
|
|
|
int use_ext_addr = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
if (cached && ((caddr + 1) == addr)) {
|
|
|
|
*value = cvalue;
|
|
|
|
cached = 0;
|
|
|
|
}
|
|
|
|
else {
|
2005-08-30 01:30:05 +00:00
|
|
|
char buf[2];
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2007-01-30 15:47:53 +00:00
|
|
|
if (use_ext_addr) {
|
|
|
|
butterfly_set_extaddr(pgm, addr >> 1);
|
|
|
|
} else {
|
|
|
|
butterfly_set_addr(pgm, addr >> 1);
|
|
|
|
}
|
2022-10-02 20:36:43 +00:00
|
|
|
// Defaults to flash read ('F')
|
|
|
|
char msg[4] = {'g', 0x00, 0x02, 'F'};
|
|
|
|
if (strcmp(m->desc, "prodsig") == 0)
|
|
|
|
msg[3] = 'P';
|
|
|
|
else if (strcmp(m->desc, "usersig") == 0)
|
|
|
|
msg[3] = 'U';
|
|
|
|
butterfly_send(pgm, msg, 4);
|
2003-11-30 15:16:48 +00:00
|
|
|
/* Read back the program mem word (MSB first) */
|
|
|
|
butterfly_recv(pgm, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if ((addr & 0x01) == 0) {
|
2013-09-13 06:54:53 +00:00
|
|
|
*value = buf[0];
|
2003-11-30 15:16:48 +00:00
|
|
|
cached = 1;
|
2013-09-13 06:54:53 +00:00
|
|
|
cvalue = buf[1];
|
2003-11-30 15:16:48 +00:00
|
|
|
caddr = addr;
|
|
|
|
}
|
|
|
|
else {
|
2013-09-13 06:54:53 +00:00
|
|
|
*value = buf[1];
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_read_byte_eeprom(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2003-11-30 15:16:48 +00:00
|
|
|
unsigned long addr, unsigned char * value)
|
|
|
|
{
|
|
|
|
butterfly_set_addr(pgm, addr);
|
|
|
|
butterfly_send(pgm, "g\000\001E", 4);
|
2005-08-30 01:30:05 +00:00
|
|
|
butterfly_recv(pgm, (char *)value, 1);
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned int addr) {
|
2013-09-13 19:37:54 +00:00
|
|
|
if (strcmp(m->desc, "flash") == 0)
|
|
|
|
return -1; /* not supported */
|
|
|
|
if (strcmp(m->desc, "eeprom") == 0)
|
|
|
|
return 0; /* nothing to do */
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: butterfly_page_erase() called on memory type \"%s\"\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, m->desc);
|
2013-09-13 19:37:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2003-11-30 15:16:48 +00:00
|
|
|
unsigned long addr, unsigned char * value)
|
|
|
|
{
|
2005-08-30 01:30:05 +00:00
|
|
|
char cmd;
|
2005-07-28 16:06:35 +00:00
|
|
|
|
2022-10-02 20:36:43 +00:00
|
|
|
if (strcmp(m->desc, "flash") == 0 ||
|
|
|
|
strcmp(m->desc, "prodsig") == 0 ||
|
|
|
|
strcmp(m->desc, "usersig") == 0) {
|
2003-11-30 15:16:48 +00:00
|
|
|
return butterfly_read_byte_flash(pgm, p, m, addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(m->desc, "eeprom") == 0) {
|
|
|
|
return butterfly_read_byte_eeprom(pgm, p, m, addr, value);
|
|
|
|
}
|
|
|
|
|
2005-07-28 16:06:35 +00:00
|
|
|
if (strcmp(m->desc, "lfuse") == 0) {
|
|
|
|
cmd = 'F';
|
|
|
|
}
|
|
|
|
else if (strcmp(m->desc, "hfuse") == 0) {
|
|
|
|
cmd = 'N';
|
|
|
|
}
|
|
|
|
else if (strcmp(m->desc, "efuse") == 0) {
|
|
|
|
cmd = 'Q';
|
|
|
|
}
|
|
|
|
else if (strcmp(m->desc, "lock") == 0) {
|
|
|
|
cmd = 'r';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
butterfly_send(pgm, &cmd, 1);
|
2005-08-30 01:30:05 +00:00
|
|
|
butterfly_recv(pgm, (char *)value, 1);
|
2005-07-28 16:06:35 +00:00
|
|
|
|
|
|
|
return *value == '?'? -1: 0;
|
2003-11-30 15:16:48 +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
|
|
|
static int butterfly_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes)
|
2003-11-30 15:16:48 +00:00
|
|
|
{
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int max_addr = addr + n_bytes;
|
2005-08-30 01:30:05 +00:00
|
|
|
char *cmd;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
unsigned int blocksize = PDATA(pgm)->buffersize;
|
2007-01-30 15:47:53 +00:00
|
|
|
int use_ext_addr = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL;
|
2013-09-03 21:24:16 +00:00
|
|
|
unsigned int wr_size = 2;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2022-10-02 20:36:43 +00:00
|
|
|
if (strcmp(m->desc, "flash") &&
|
|
|
|
strcmp(m->desc, "eeprom") &&
|
|
|
|
strcmp(m->desc, "usersig"))
|
2003-11-30 15:16:48 +00:00
|
|
|
return -2;
|
|
|
|
|
|
|
|
if (m->desc[0] == 'e')
|
2013-09-03 21:24:16 +00:00
|
|
|
wr_size = blocksize = 1; /* Write to eeprom single bytes only */
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2007-01-30 15:47:53 +00:00
|
|
|
if (use_ext_addr) {
|
2013-09-03 21:24:16 +00:00
|
|
|
butterfly_set_extaddr(pgm, addr / wr_size);
|
2007-01-30 15:47:53 +00:00
|
|
|
} else {
|
2013-09-03 21:24:16 +00:00
|
|
|
butterfly_set_addr(pgm, addr / wr_size);
|
2007-01-30 15:47:53 +00:00
|
|
|
}
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
usleep(1000000);
|
|
|
|
butterfly_send(pgm, "y", 1);
|
2014-05-16 15:52:25 +00:00
|
|
|
if (butterfly_vfy_cmd_sent(pgm, "clear LED") < 0)
|
|
|
|
return -1;
|
2003-11-30 15:16:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
cmd = malloc(4+blocksize);
|
|
|
|
if (!cmd) return -1;
|
|
|
|
cmd[0] = 'B';
|
2010-01-22 16:40:17 +00:00
|
|
|
cmd[3] = toupper((int)(m->desc[0]));
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
while (addr < max_addr) {
|
|
|
|
if ((max_addr - addr) < blocksize) {
|
|
|
|
blocksize = max_addr - addr;
|
|
|
|
};
|
|
|
|
memcpy(&cmd[4], &m->buf[addr], blocksize);
|
|
|
|
cmd[1] = (blocksize >> 8) & 0xff;
|
|
|
|
cmd[2] = blocksize & 0xff;
|
|
|
|
|
|
|
|
butterfly_send(pgm, cmd, 4+blocksize);
|
2014-05-16 15:52:25 +00:00
|
|
|
if (butterfly_vfy_cmd_sent(pgm, "write block") < 0)
|
|
|
|
return -1;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
addr += blocksize;
|
|
|
|
} /* while */
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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 butterfly_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int page_size,
|
|
|
|
unsigned int addr, unsigned int n_bytes)
|
2003-11-30 15:16:48 +00:00
|
|
|
{
|
2011-09-14 21:49:42 +00:00
|
|
|
unsigned int max_addr = addr + n_bytes;
|
2013-09-03 21:24:16 +00:00
|
|
|
int rd_size = 2;
|
|
|
|
int blocksize = PDATA(pgm)->buffersize;
|
2007-01-30 15:47:53 +00:00
|
|
|
int use_ext_addr = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2022-10-02 20:36:43 +00:00
|
|
|
/* check parameter syntax: only "flash", "eeprom" or "usersig" is allowed */
|
|
|
|
if (strcmp(m->desc, "flash") &&
|
|
|
|
strcmp(m->desc, "eeprom") &&
|
|
|
|
strcmp(m->desc, "usersig"))
|
2003-11-30 15:16:48 +00:00
|
|
|
return -2;
|
|
|
|
|
2013-09-03 21:24:16 +00:00
|
|
|
if (m->desc[0] == 'e')
|
|
|
|
rd_size = blocksize = 1; /* Read from eeprom single bytes only */
|
|
|
|
|
2003-11-30 15:16:48 +00:00
|
|
|
{ /* use buffered mode */
|
2005-08-30 01:30:05 +00:00
|
|
|
char cmd[4];
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
cmd[0] = 'g';
|
2010-01-22 16:40:17 +00:00
|
|
|
cmd[3] = toupper((int)(m->desc[0]));
|
2003-11-30 15:16:48 +00:00
|
|
|
|
2007-01-30 15:47:53 +00:00
|
|
|
if (use_ext_addr) {
|
2013-09-03 21:24:16 +00:00
|
|
|
butterfly_set_extaddr(pgm, addr / rd_size);
|
2007-01-30 15:47:53 +00:00
|
|
|
} else {
|
2013-09-03 21:24:16 +00:00
|
|
|
butterfly_set_addr(pgm, addr / rd_size);
|
2007-01-30 15:47:53 +00:00
|
|
|
}
|
2003-11-30 15:16:48 +00:00
|
|
|
while (addr < max_addr) {
|
|
|
|
if ((max_addr - addr) < blocksize) {
|
|
|
|
blocksize = max_addr - addr;
|
|
|
|
};
|
|
|
|
cmd[1] = (blocksize >> 8) & 0xff;
|
|
|
|
cmd[2] = blocksize & 0xff;
|
|
|
|
|
|
|
|
butterfly_send(pgm, cmd, 4);
|
2005-08-30 01:30:05 +00:00
|
|
|
butterfly_recv(pgm, (char *)&m->buf[addr], blocksize);
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
addr += blocksize;
|
|
|
|
} /* while */
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr * rd_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Signature byte reads are always 3 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
|
|
|
static int butterfly_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m) {
|
2005-07-28 16:06:35 +00:00
|
|
|
unsigned char tmp;
|
|
|
|
|
2003-11-30 15:16:48 +00:00
|
|
|
if (m->size < 3) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read", progname);
|
2003-11-30 15:16:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
butterfly_send(pgm, "s", 1);
|
2005-08-30 01:30:05 +00:00
|
|
|
butterfly_recv(pgm, (char *)m->buf, 3);
|
2005-07-28 16:06:35 +00:00
|
|
|
/* Returned signature has wrong order. */
|
|
|
|
tmp = m->buf[2];
|
|
|
|
m->buf[2] = m->buf[0];
|
|
|
|
m->buf[0] = tmp;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:03:43 +00:00
|
|
|
const char butterfly_desc[] = "Atmel Butterfly evaluation board; Atmel AppNotes AVR109, AVR911";
|
2003-11-30 15:16:48 +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
|
|
|
void butterfly_initpgm(PROGRAMMER *pgm) {
|
2011-08-26 20:50:32 +00:00
|
|
|
strcpy(pgm->type, "butterfly");
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mandatory functions
|
|
|
|
*/
|
2004-06-24 11:05:07 +00:00
|
|
|
pgm->rdy_led = butterfly_rdy_led;
|
|
|
|
pgm->err_led = butterfly_err_led;
|
|
|
|
pgm->pgm_led = butterfly_pgm_led;
|
|
|
|
pgm->vfy_led = butterfly_vfy_led;
|
2003-11-30 15:16:48 +00:00
|
|
|
pgm->initialize = butterfly_initialize;
|
|
|
|
pgm->display = butterfly_display;
|
|
|
|
pgm->enable = butterfly_enable;
|
|
|
|
pgm->disable = butterfly_disable;
|
2004-06-24 11:05:07 +00:00
|
|
|
pgm->powerup = butterfly_powerup;
|
|
|
|
pgm->powerdown = butterfly_powerdown;
|
2003-11-30 15:16:48 +00:00
|
|
|
pgm->program_enable = butterfly_program_enable;
|
|
|
|
pgm->chip_erase = butterfly_chip_erase;
|
|
|
|
pgm->open = butterfly_open;
|
|
|
|
pgm->close = butterfly_close;
|
2006-11-20 15:04:09 +00:00
|
|
|
pgm->read_byte = butterfly_read_byte;
|
|
|
|
pgm->write_byte = butterfly_write_byte;
|
2003-11-30 15:16:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* optional functions
|
|
|
|
*/
|
|
|
|
|
2013-09-13 19:37:54 +00:00
|
|
|
pgm->page_erase = butterfly_page_erase;
|
2003-11-30 15:16:48 +00:00
|
|
|
pgm->paged_write = butterfly_paged_write;
|
|
|
|
pgm->paged_load = butterfly_paged_load;
|
|
|
|
|
|
|
|
pgm->read_sig_bytes = butterfly_read_sig_bytes;
|
main.c, pgm.c, pgm.h: Add setup and teardown hooks to the programmer
definition. If present, call the setup hook immediately after finding
the respective programmer object, and schedule the teardown hook to be
called upon exit. This allows the programmer implementation to
dynamically allocate private programmer data.
avr910.c, butterfly.c, jtagmkI.c, jtagmkII.c, stk500v2.c, usbasp.c,
usbtiny.c: Convert static programmer data into dynamically allocated
data.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@764 81a1dc3b-b13d-400b-aceb-764788c761c2
2007-11-07 20:36:12 +00:00
|
|
|
|
|
|
|
pgm->setup = butterfly_setup;
|
|
|
|
pgm->teardown = butterfly_teardown;
|
2011-08-26 20:50:32 +00:00
|
|
|
pgm->flag = 0;
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:03:43 +00:00
|
|
|
const char butterfly_mk_desc[] = "Mikrokopter.de Butterfly";
|
|
|
|
|
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
|
|
|
void butterfly_mk_initpgm(PROGRAMMER *pgm) {
|
2011-08-26 20:50:32 +00:00
|
|
|
butterfly_initpgm(pgm);
|
|
|
|
strcpy(pgm->type, "butterfly_mk");
|
|
|
|
pgm->flag = IS_BUTTERFLY_MK;
|
2003-11-30 15:16:48 +00:00
|
|
|
}
|