2003-03-13 03:52:19 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2006-08-31 20:52:47 +00:00
|
|
|
* Copyright (C) 2003-2004 Theodore A. Roth <troth@openavr.org>
|
|
|
|
* Copyright (C) 2006 Joerg Wunsch <j@uriah.heep.sax.de>
|
2003-03-13 03:52:19 +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-03-13 03:52:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Posix serial interface for avrdude.
|
|
|
|
*/
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#if !defined(WIN32)
|
2004-06-24 11:05:07 +00:00
|
|
|
|
2018-01-17 07:39:29 +00:00
|
|
|
#include "ac_cfg.h"
|
2004-06-24 11:05:07 +00:00
|
|
|
|
2003-08-25 15:55:48 +00:00
|
|
|
#include <ctype.h>
|
2022-03-07 22:20:50 +00:00
|
|
|
#include <stdbool.h>
|
2003-03-13 03:52:19 +00:00
|
|
|
#include <stdio.h>
|
2003-08-25 15:55:48 +00:00
|
|
|
#include <stdlib.h>
|
2003-03-13 03:52:19 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2009-10-10 01:41:40 +00:00
|
|
|
#include <sys/ioctl.h>
|
2003-03-13 04:44:46 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2006-08-31 20:52:47 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
2003-03-13 03:52:19 +00:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-03-07 22:20:50 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# include <IOKit/serial/ioss.h>
|
|
|
|
#endif
|
|
|
|
|
2007-01-24 21:07:54 +00:00
|
|
|
#include "avrdude.h"
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "libavrdude.h"
|
2005-06-19 21:38:03 +00:00
|
|
|
|
Mega-commit to bring in both, the STK500v2 support from Erik
Walthinsen, as well as JTAG ICE mkII support (by me).
Erik's submission has been cleaned up a little bit, mostly to add his
name and the current year to the copyright of the new file, remove
trailing white space before importing the files, and fix the minor
syntax errors in his avrdude.conf.in additions (missing semicolons).
The JTAG ICE mkII support should be considered alpha to beta quality
at this point. Few things are still to be done, like defering the
hfuse (OCDEN) tweaks until they are really required. Also, for
reasons not yet known, the target MCU doesn't start to run after
signing off from the ICE, it needs a power-cycle first (at least on my
STK500).
Note that for the JTAG ICE, I did change a few things in the internal
API. Notably I made the serial receive timeout configurable by the
backends via an exported variable (done in both the Posix and the
Win32 implementation), and I made the serial_recv() function return a
-1 instead of bailing out with exit(1) upon encountering a receive
timeout (currently only done in the Posix implementation). Both
measures together allow me to receive a datastreem from the ICE at 115
kbps on a somewhat lossy PCI multi-UART card that occasionally drops a
character. The JTAG ICE mkII protocol has enough of safety layers to
allow recovering from these events, but the previous code wasn't
prepared for any kind of recovery. The Win32 change for this still
has to be done, and the traditional drivers need to be converted to
exit(1) upon encountering a timeout (as they're now getting a -1
returned they didn't see before in that case).
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@451 81a1dc3b-b13d-400b-aceb-764788c761c2
2005-05-10 19:17:12 +00:00
|
|
|
long serial_recv_timeout = 5000; /* ms */
|
|
|
|
|
2003-03-13 03:52:19 +00:00
|
|
|
struct baud_mapping {
|
2003-03-13 19:25:27 +00:00
|
|
|
long baud;
|
2003-03-13 03:52:19 +00:00
|
|
|
speed_t speed;
|
|
|
|
};
|
|
|
|
|
2015-12-09 22:45:57 +00:00
|
|
|
/* There are a lot more baud rates we could handle, but what's the point? */
|
2003-03-13 03:52:19 +00:00
|
|
|
|
|
|
|
static struct baud_mapping baud_lookup_table [] = {
|
2021-12-08 10:09:52 +00:00
|
|
|
{ 300, B300 },
|
|
|
|
{ 600, B600 },
|
2003-03-13 03:52:19 +00:00
|
|
|
{ 1200, B1200 },
|
|
|
|
{ 2400, B2400 },
|
|
|
|
{ 4800, B4800 },
|
|
|
|
{ 9600, B9600 },
|
|
|
|
{ 19200, B19200 },
|
|
|
|
{ 38400, B38400 },
|
2011-12-30 16:38:58 +00:00
|
|
|
#ifdef B57600
|
2003-03-13 03:52:19 +00:00
|
|
|
{ 57600, B57600 },
|
2011-12-30 16:38:58 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
2003-03-13 03:52:19 +00:00
|
|
|
{ 115200, B115200 },
|
2011-12-30 16:38:58 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B230400
|
2003-03-13 03:52:19 +00:00
|
|
|
{ 230400, B230400 },
|
2022-06-07 09:50:03 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B250000
|
|
|
|
{ 250000, B250000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
|
|
|
{ 460800, B460800 },
|
|
|
|
#endif
|
|
|
|
#ifdef B500000
|
|
|
|
{ 500000, B500000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B576000
|
|
|
|
{ 576000, B576000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B921600
|
|
|
|
{ 921600, B921600 },
|
|
|
|
#endif
|
|
|
|
#ifdef B1000000
|
|
|
|
{ 1000000, B1000000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B1152000
|
|
|
|
{ 1152000, B1152000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B1500000
|
|
|
|
{ 1500000, B1500000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B2000000
|
|
|
|
{ 2000000, B2000000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B2500000
|
|
|
|
{ 2500000, B2500000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B3000000
|
|
|
|
{ 3000000, B3000000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B3500000
|
|
|
|
{ 3500000, B3500000 },
|
|
|
|
#endif
|
|
|
|
#ifdef B4000000
|
|
|
|
{ 4000000, B4000000 },
|
2011-12-30 16:38:58 +00:00
|
|
|
#endif
|
2003-03-13 03:52:19 +00:00
|
|
|
{ 0, 0 } /* Terminator. */
|
|
|
|
};
|
|
|
|
|
2015-12-09 22:45:57 +00:00
|
|
|
static struct termios original_termios;
|
|
|
|
static int saved_original_termios;
|
2006-08-28 21:17:01 +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 speed_t serial_baud_lookup(long baud, bool *nonstandard) {
|
2003-03-13 03:52:19 +00:00
|
|
|
struct baud_mapping *map = baud_lookup_table;
|
|
|
|
|
2022-03-07 22:20:50 +00:00
|
|
|
*nonstandard = false;
|
|
|
|
|
2003-03-13 03:52:19 +00:00
|
|
|
while (map->baud) {
|
|
|
|
if (map->baud == baud)
|
|
|
|
return map->speed;
|
|
|
|
map++;
|
|
|
|
}
|
|
|
|
|
2010-01-08 10:39:18 +00:00
|
|
|
/*
|
|
|
|
* If a non-standard BAUD rate is used, issue
|
|
|
|
* a warning (if we are verbose) and return the raw rate
|
|
|
|
*/
|
2022-03-07 22:25:36 +00:00
|
|
|
avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld\n",
|
2010-01-08 10:39:18 +00:00
|
|
|
progname, baud);
|
|
|
|
|
2022-03-07 22:20:50 +00:00
|
|
|
*nonstandard = true;
|
|
|
|
|
2010-01-08 10:39:18 +00:00
|
|
|
return baud;
|
2003-03-13 03:52:19 +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 ser_setparams(const union filedescriptor *fd, long baud, unsigned long cflags) {
|
2003-03-13 03:52:19 +00:00
|
|
|
int rc;
|
|
|
|
struct termios termios;
|
2022-03-07 22:20:50 +00:00
|
|
|
bool nonstandard;
|
|
|
|
speed_t speed = serial_baud_lookup (baud, &nonstandard);
|
2003-03-13 03:52:19 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
if (!isatty(fd->ifd))
|
2006-08-28 21:17:01 +00:00
|
|
|
return -ENOTTY;
|
2003-03-13 03:52:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize terminal modes
|
|
|
|
*/
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = tcgetattr(fd->ifd, &termios);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc < 0) {
|
2021-12-08 10:09:52 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcgetattr() failed",
|
2006-08-28 21:17:01 +00:00
|
|
|
progname);
|
2003-03-13 03:52:19 +00:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2006-08-28 21:17:01 +00:00
|
|
|
/*
|
|
|
|
* copy termios for ser_close if we haven't already
|
|
|
|
*/
|
|
|
|
if (! saved_original_termios++) {
|
|
|
|
original_termios = termios;
|
|
|
|
}
|
|
|
|
|
2022-02-19 17:00:58 +00:00
|
|
|
if (cflags & SERIAL_CREAD) {
|
|
|
|
termios.c_cflag |= CREAD;
|
|
|
|
}
|
|
|
|
if (cflags & SERIAL_CLOCAL) {
|
|
|
|
termios.c_cflag |= CLOCAL;
|
|
|
|
}
|
|
|
|
termios.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN);
|
|
|
|
#ifdef ECHOCTL
|
|
|
|
termios.c_lflag &= ~ECHOCTL;
|
|
|
|
#endif /* ECHOCTL */
|
|
|
|
#ifdef ECHOKE
|
|
|
|
termios.c_lflag &= ~ECHOKE;
|
|
|
|
#endif /* ECHOKE */
|
|
|
|
termios.c_oflag &= ~(OPOST | ONLCR | OCRNL);
|
|
|
|
termios.c_iflag &= ~(INLCR | IGNCR | ICRNL | IGNBRK);
|
|
|
|
#ifdef IUCLC
|
|
|
|
termios.c_iflag &= ~IUCLC;
|
|
|
|
#endif /* IUCLC */
|
|
|
|
#ifdef PARMRK
|
|
|
|
termios.c_iflag &= ~PARMRK;
|
|
|
|
#endif /* PARMRK */
|
2015-12-09 22:45:57 +00:00
|
|
|
|
2022-03-07 22:20:50 +00:00
|
|
|
// MacOS doesn't handle nonstandard baudrate values in
|
|
|
|
// normal tcsetattr(), sigh.
|
|
|
|
#ifdef __APPLE__
|
|
|
|
if (!nonstandard) {
|
|
|
|
#endif
|
|
|
|
cfsetospeed(&termios, speed);
|
|
|
|
cfsetispeed(&termios, speed);
|
|
|
|
#ifdef __APPLE__
|
|
|
|
}
|
|
|
|
#endif
|
2015-12-09 22:45:57 +00:00
|
|
|
|
2022-02-19 17:00:58 +00:00
|
|
|
termios.c_cflag &= ~CSIZE;
|
|
|
|
if (cflags & SERIAL_CS8) {
|
|
|
|
termios.c_cflag |= CS8;
|
|
|
|
}
|
|
|
|
if (cflags & SERIAL_CS7) {
|
|
|
|
termios.c_cflag |= CS7;
|
|
|
|
}
|
|
|
|
if (cflags & SERIAL_CS6) {
|
|
|
|
termios.c_cflag |= CS6;
|
|
|
|
}
|
|
|
|
if (cflags & SERIAL_CS5) {
|
|
|
|
termios.c_cflag |= CS5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cflags & SERIAL_CSTOPB) {
|
|
|
|
termios.c_cflag |= CSTOPB;
|
|
|
|
} else {
|
|
|
|
termios.c_cflag &= ~CSTOPB;
|
|
|
|
}
|
|
|
|
|
|
|
|
termios.c_iflag &= ~(INPCK | ISTRIP);
|
|
|
|
|
|
|
|
if (cflags & (SERIAL_PARENB | SERIAL_PARODD)) {
|
|
|
|
termios.c_cflag |= PARENB;
|
|
|
|
} else {
|
|
|
|
termios.c_cflag &= ~PARENB;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cflags & SERIAL_PARODD) {
|
|
|
|
termios.c_cflag |= PARODD;
|
|
|
|
} else {
|
|
|
|
termios.c_cflag &= ~PARODD;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IXANY
|
|
|
|
termios.c_iflag &= ~IXANY;
|
|
|
|
#endif /* IXANY */
|
|
|
|
termios.c_iflag &= ~(IXON | IXOFF);
|
|
|
|
|
|
|
|
#ifdef CRTSCTS
|
|
|
|
termios.c_iflag &= ~CRTSCTS;
|
|
|
|
#endif /* CRTSCTS */
|
|
|
|
|
|
|
|
#ifdef CNEW_RTSCTS
|
|
|
|
termios.c_iflag &= ~CNEW_RTSCTS;
|
|
|
|
#endif /* CRTSCTS */
|
|
|
|
|
|
|
|
|
2009-07-02 10:31:13 +00:00
|
|
|
rc = tcsetattr(fd->ifd, TCSANOW, &termios);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc < 0) {
|
2021-12-08 10:09:52 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcsetattr() failed\n",
|
2006-08-28 21:17:01 +00:00
|
|
|
progname);
|
2003-03-13 03:52:19 +00:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2022-03-07 22:20:50 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// handle nonstandard speed values the MacOS way
|
|
|
|
if (nonstandard) {
|
|
|
|
if (ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) {
|
|
|
|
avrdude_message(MSG_INFO, "%s: ser_setparams(): ioctrl(IOSSIOSPEED) failed\n",
|
|
|
|
progname);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
2022-02-19 17:00:58 +00:00
|
|
|
tcflush(fd->ifd, TCIFLUSH);
|
|
|
|
|
2003-03-13 03:52:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-31 20:52:47 +00:00
|
|
|
/*
|
|
|
|
* Given a port description of the form <host>:<port>, open a TCP
|
|
|
|
* connection to the specified destination, which is assumed to be a
|
|
|
|
* terminal/console server with serial parameters configured
|
|
|
|
* appropriately (e. g. 115200-8-N-1 for a STK500.)
|
|
|
|
*/
|
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 net_open(const char *port, union filedescriptor *fdp) {
|
2018-01-17 07:39:29 +00:00
|
|
|
char *hp, *hstr, *pstr;
|
|
|
|
int s, fd, ret = -1;
|
|
|
|
struct addrinfo hints;
|
|
|
|
struct addrinfo *result, *rp;
|
2006-08-31 20:52:47 +00:00
|
|
|
|
2018-01-17 07:39:29 +00:00
|
|
|
if ((hstr = hp = strdup(port)) == NULL) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: net_open(): Out of memory!\n",
|
2006-08-31 20:52:47 +00:00
|
|
|
progname);
|
2010-10-22 14:44:53 +00:00
|
|
|
return -1;
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 07:39:29 +00:00
|
|
|
/*
|
|
|
|
* As numeric IPv6 addresses use colons as separators, we need to
|
|
|
|
* look for the last colon here, which separates the port number or
|
|
|
|
* service name from the host or IP address.
|
|
|
|
*/
|
|
|
|
if (((pstr = strrchr(hstr, ':')) == NULL) || (pstr == hstr)) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: net_open(): Mangled host:port string \"%s\"\n",
|
2006-08-31 20:52:47 +00:00
|
|
|
progname, hstr);
|
2018-01-17 07:39:29 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove brackets from the host part, if present.
|
|
|
|
*/
|
|
|
|
if (*hstr == '[' && *(pstr-1) == ']') {
|
|
|
|
hstr++;
|
|
|
|
*(pstr-1) = '\0';
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Terminate the host section of the description.
|
|
|
|
*/
|
|
|
|
*pstr++ = '\0';
|
|
|
|
|
2018-01-17 07:39:29 +00:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
s = getaddrinfo(hstr, pstr, &hints, &result);
|
|
|
|
|
|
|
|
if (s != 0) {
|
|
|
|
avrdude_message(MSG_INFO,
|
|
|
|
"%s: net_open(): Cannot resolve "
|
|
|
|
"host=\"%s\", port=\"%s\": %s\n",
|
|
|
|
progname, hstr, pstr, gai_strerror(s));
|
|
|
|
goto error;
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
2018-01-17 07:39:29 +00:00
|
|
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
|
|
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
|
|
if (fd == -1) {
|
|
|
|
/* This one failed, loop over */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1) {
|
|
|
|
/* Success, we are connected */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
close(fd);
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
2018-01-17 07:39:29 +00:00
|
|
|
if (rp == NULL) {
|
|
|
|
avrdude_message(MSG_INFO, "%s: net_open(): Cannot connect: %s\n",
|
2006-08-31 20:52:47 +00:00
|
|
|
progname, strerror(errno));
|
|
|
|
}
|
2018-01-17 07:39:29 +00:00
|
|
|
else {
|
|
|
|
fdp->ifd = fd;
|
|
|
|
ret = 0;
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
2018-01-17 07:39:29 +00:00
|
|
|
freeaddrinfo(result);
|
|
|
|
|
|
|
|
error:
|
|
|
|
free(hp);
|
|
|
|
return ret;
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
2003-03-13 03:52:19 +00:00
|
|
|
|
2009-10-10 01:41:40 +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 ser_set_dtr_rts(const union filedescriptor *fdp, int is_on) {
|
2009-10-10 01:41:40 +00:00
|
|
|
unsigned int ctl;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = ioctl(fdp->ifd, TIOCMGET, &ctl);
|
|
|
|
if (r < 0) {
|
|
|
|
perror("ioctl(\"TIOCMGET\")");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_on) {
|
|
|
|
/* Set DTR and RTS */
|
|
|
|
ctl |= (TIOCM_DTR | TIOCM_RTS);
|
|
|
|
}
|
2010-03-07 21:27:22 +00:00
|
|
|
else {
|
|
|
|
/* Clear DTR and RTS */
|
|
|
|
ctl &= ~(TIOCM_DTR | TIOCM_RTS);
|
|
|
|
}
|
2009-10-10 01:41:40 +00:00
|
|
|
|
|
|
|
r = ioctl(fdp->ifd, TIOCMSET, &ctl);
|
|
|
|
if (r < 0) {
|
|
|
|
perror("ioctl(\"TIOCMSET\")");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static int ser_open(const char *port, union pinfo pinfo, union filedescriptor *fdp) {
|
2003-03-13 03:52:19 +00:00
|
|
|
int rc;
|
|
|
|
int fd;
|
|
|
|
|
2006-08-31 20:52:47 +00:00
|
|
|
/*
|
|
|
|
* If the port is of the form "net:<host>:<port>", then
|
|
|
|
* handle it as a TCP connection to a terminal server.
|
|
|
|
*/
|
|
|
|
if (strncmp(port, "net:", strlen("net:")) == 0) {
|
2010-10-22 14:44:53 +00:00
|
|
|
return net_open(port + strlen("net:"), fdp);
|
2006-08-31 20:52:47 +00:00
|
|
|
}
|
|
|
|
|
2003-03-13 03:52:19 +00:00
|
|
|
/*
|
|
|
|
* open the serial port
|
|
|
|
*/
|
2006-08-28 21:17:01 +00:00
|
|
|
fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (fd < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_open(): can't open device \"%s\": %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, port, strerror(errno));
|
2010-10-22 14:29:56 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
|
2006-12-11 16:02:45 +00:00
|
|
|
fdp->ifd = fd;
|
|
|
|
|
2003-03-13 03:52:19 +00:00
|
|
|
/*
|
|
|
|
* set serial line attributes
|
|
|
|
*/
|
2021-12-08 10:09:52 +00:00
|
|
|
rc = ser_setparams(fdp, pinfo.serialinfo.baud, pinfo.serialinfo.cflags);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_open(): can't set attributes for device \"%s\": %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, port, strerror(-rc));
|
2010-10-22 14:29:56 +00:00
|
|
|
close(fd);
|
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
2010-10-22 14:29:56 +00:00
|
|
|
return 0;
|
2003-03-13 03:52:19 +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 ser_close(union filedescriptor *fd) {
|
2006-08-28 21:17:01 +00:00
|
|
|
/*
|
|
|
|
* restore original termios settings from ser_open
|
|
|
|
*/
|
|
|
|
if (saved_original_termios) {
|
2006-12-11 12:47:35 +00:00
|
|
|
int rc = tcsetattr(fd->ifd, TCSANOW | TCSADRAIN, &original_termios);
|
2006-08-28 21:17:01 +00:00
|
|
|
if (rc) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_close(): can't reset attributes for device: %s\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname, strerror(errno));
|
2006-08-28 21:17:01 +00:00
|
|
|
}
|
|
|
|
saved_original_termios = 0;
|
|
|
|
}
|
2003-03-13 03:52:19 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
close(fd->ifd);
|
2003-03-13 03:52:19 +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 ser_send(const union filedescriptor *fd, const unsigned char * buf, size_t buflen) {
|
2003-03-13 03:52:19 +00:00
|
|
|
int rc;
|
2014-07-16 20:02:01 +00:00
|
|
|
const unsigned char * p = buf;
|
2003-03-24 01:57:31 +00:00
|
|
|
size_t len = buflen;
|
|
|
|
|
|
|
|
if (!len)
|
2003-03-13 03:52:19 +00:00
|
|
|
return 0;
|
|
|
|
|
2003-03-24 01:57:31 +00:00
|
|
|
if (verbose > 3)
|
|
|
|
{
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "%s: Send: ", progname);
|
2003-03-24 01:57:31 +00:00
|
|
|
|
|
|
|
while (buflen) {
|
2003-03-24 07:09:16 +00:00
|
|
|
unsigned char c = *buf;
|
2003-03-24 01:57:31 +00:00
|
|
|
if (isprint(c)) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "%c ", c);
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, ". ");
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "[%02x] ", c);
|
2003-03-24 01:57:31 +00:00
|
|
|
|
|
|
|
buf++;
|
|
|
|
buflen--;
|
|
|
|
}
|
|
|
|
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "\n");
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (len) {
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = write(fd->ifd, p, (len > 1024) ? 1024 : len);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_send(): write error: %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, strerror(errno));
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
2005-05-11 17:00:11 +00:00
|
|
|
p += rc;
|
|
|
|
len -= rc;
|
2003-03-13 03:52:19 +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 ser_recv(const union filedescriptor *fd, unsigned char * buf, size_t buflen) {
|
2005-05-11 17:00:11 +00:00
|
|
|
struct timeval timeout, to2;
|
2003-03-13 03:52:19 +00:00
|
|
|
fd_set rfds;
|
|
|
|
int nfds;
|
|
|
|
int rc;
|
2005-08-30 01:30:05 +00:00
|
|
|
unsigned char * p = buf;
|
2003-03-24 01:57:31 +00:00
|
|
|
size_t len = 0;
|
|
|
|
|
Mega-commit to bring in both, the STK500v2 support from Erik
Walthinsen, as well as JTAG ICE mkII support (by me).
Erik's submission has been cleaned up a little bit, mostly to add his
name and the current year to the copyright of the new file, remove
trailing white space before importing the files, and fix the minor
syntax errors in his avrdude.conf.in additions (missing semicolons).
The JTAG ICE mkII support should be considered alpha to beta quality
at this point. Few things are still to be done, like defering the
hfuse (OCDEN) tweaks until they are really required. Also, for
reasons not yet known, the target MCU doesn't start to run after
signing off from the ICE, it needs a power-cycle first (at least on my
STK500).
Note that for the JTAG ICE, I did change a few things in the internal
API. Notably I made the serial receive timeout configurable by the
backends via an exported variable (done in both the Posix and the
Win32 implementation), and I made the serial_recv() function return a
-1 instead of bailing out with exit(1) upon encountering a receive
timeout (currently only done in the Posix implementation). Both
measures together allow me to receive a datastreem from the ICE at 115
kbps on a somewhat lossy PCI multi-UART card that occasionally drops a
character. The JTAG ICE mkII protocol has enough of safety layers to
allow recovering from these events, but the previous code wasn't
prepared for any kind of recovery. The Win32 change for this still
has to be done, and the traditional drivers need to be converted to
exit(1) upon encountering a timeout (as they're now getting a -1
returned they didn't see before in that case).
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@451 81a1dc3b-b13d-400b-aceb-764788c761c2
2005-05-10 19:17:12 +00:00
|
|
|
timeout.tv_sec = serial_recv_timeout / 1000L;
|
|
|
|
timeout.tv_usec = (serial_recv_timeout % 1000L) * 1000;
|
2005-05-11 17:00:11 +00:00
|
|
|
to2 = timeout;
|
2003-03-13 03:52:19 +00:00
|
|
|
|
2003-03-24 01:57:31 +00:00
|
|
|
while (len < buflen) {
|
2005-05-11 17:00:11 +00:00
|
|
|
reselect:
|
2003-03-13 03:52:19 +00:00
|
|
|
FD_ZERO(&rfds);
|
2006-12-11 12:47:35 +00:00
|
|
|
FD_SET(fd->ifd, &rfds);
|
2003-03-13 03:52:19 +00:00
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (nfds == 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_NOTICE2, "%s: ser_recv(): programmer is not responding\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
Mega-commit to bring in both, the STK500v2 support from Erik
Walthinsen, as well as JTAG ICE mkII support (by me).
Erik's submission has been cleaned up a little bit, mostly to add his
name and the current year to the copyright of the new file, remove
trailing white space before importing the files, and fix the minor
syntax errors in his avrdude.conf.in additions (missing semicolons).
The JTAG ICE mkII support should be considered alpha to beta quality
at this point. Few things are still to be done, like defering the
hfuse (OCDEN) tweaks until they are really required. Also, for
reasons not yet known, the target MCU doesn't start to run after
signing off from the ICE, it needs a power-cycle first (at least on my
STK500).
Note that for the JTAG ICE, I did change a few things in the internal
API. Notably I made the serial receive timeout configurable by the
backends via an exported variable (done in both the Posix and the
Win32 implementation), and I made the serial_recv() function return a
-1 instead of bailing out with exit(1) upon encountering a receive
timeout (currently only done in the Posix implementation). Both
measures together allow me to receive a datastreem from the ICE at 115
kbps on a somewhat lossy PCI multi-UART card that occasionally drops a
character. The JTAG ICE mkII protocol has enough of safety layers to
allow recovering from these events, but the previous code wasn't
prepared for any kind of recovery. The Win32 change for this still
has to be done, and the traditional drivers need to be converted to
exit(1) upon encountering a timeout (as they're now getting a -1
returned they didn't see before in that case).
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@451 81a1dc3b-b13d-400b-aceb-764788c761c2
2005-05-10 19:17:12 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
else if (nfds == -1) {
|
2005-05-11 17:00:11 +00:00
|
|
|
if (errno == EINTR || errno == EAGAIN) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_recv(): programmer is not responding,reselecting\n",
|
2014-05-18 08:41:46 +00:00
|
|
|
progname);
|
2003-03-13 03:52:19 +00:00
|
|
|
goto reselect;
|
|
|
|
}
|
|
|
|
else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_recv(): select(): %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, strerror(errno));
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = read(fd->ifd, p, (buflen - len > 1024) ? 1024 : buflen - len);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_recv(): read error: %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, strerror(errno));
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
2005-05-11 17:00:11 +00:00
|
|
|
p += rc;
|
|
|
|
len += rc;
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
if (verbose > 3)
|
|
|
|
{
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "%s: Recv: ", progname);
|
2003-03-24 01:57:31 +00:00
|
|
|
|
|
|
|
while (len) {
|
2003-03-24 07:09:16 +00:00
|
|
|
unsigned char c = *p;
|
2003-03-24 01:57:31 +00:00
|
|
|
if (isprint(c)) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "%c ", c);
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, ". ");
|
2003-03-24 01:57:31 +00:00
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "[%02x] ", c);
|
2003-03-24 01:57:31 +00:00
|
|
|
|
|
|
|
p++;
|
|
|
|
len--;
|
|
|
|
}
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_TRACE, "\n");
|
2003-03-13 03:52:19 +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 ser_drain(const union filedescriptor *fd, int display) {
|
2003-03-13 03:52:19 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
fd_set rfds;
|
|
|
|
int nfds;
|
|
|
|
int rc;
|
|
|
|
unsigned char buf;
|
|
|
|
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 250000;
|
|
|
|
|
|
|
|
if (display) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "drain>");
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
FD_ZERO(&rfds);
|
2006-12-11 12:47:35 +00:00
|
|
|
FD_SET(fd->ifd, &rfds);
|
2003-03-13 03:52:19 +00:00
|
|
|
|
|
|
|
reselect:
|
2006-12-11 12:47:35 +00:00
|
|
|
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (nfds == 0) {
|
|
|
|
if (display) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "<drain\n");
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (nfds == -1) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
goto reselect;
|
|
|
|
}
|
|
|
|
else {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_drain(): select(): %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, strerror(errno));
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-11 12:47:35 +00:00
|
|
|
rc = read(fd->ifd, &buf, 1);
|
2003-03-13 03:52:19 +00:00
|
|
|
if (rc < 0) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n",
|
2003-03-13 03:52:19 +00:00
|
|
|
progname, strerror(errno));
|
2014-05-16 15:52:25 +00:00
|
|
|
return -1;
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
if (display) {
|
2014-06-13 20:07:40 +00:00
|
|
|
avrdude_message(MSG_INFO, "%02x ", buf);
|
2003-03-13 03:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-24 11:05:07 +00:00
|
|
|
|
2005-06-19 21:38:03 +00:00
|
|
|
struct serial_device serial_serdev =
|
|
|
|
{
|
|
|
|
.open = ser_open,
|
2021-12-08 10:09:52 +00:00
|
|
|
.setparams = ser_setparams,
|
2005-06-19 21:38:03 +00:00
|
|
|
.close = ser_close,
|
|
|
|
.send = ser_send,
|
|
|
|
.recv = ser_recv,
|
|
|
|
.drain = ser_drain,
|
2009-10-10 01:41:40 +00:00
|
|
|
.set_dtr_rts = ser_set_dtr_rts,
|
2006-10-27 08:45:47 +00:00
|
|
|
.flags = SERDEV_FL_CANSETSPEED,
|
2005-06-19 21:38:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct serial_device *serdev = &serial_serdev;
|
|
|
|
|
2022-01-07 12:15:55 +00:00
|
|
|
#endif /* WIN32 */
|
2022-03-07 22:20:50 +00:00
|
|
|
|