diff --git a/ChangeLog b/ChangeLog index 8d8056d1..2795935d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-08-31 Joerg Wunsch + + The major part of this change has been contributed by + . + Implements patch #4635: Add support for terminal/console + servers for serial programmers + * ser_posix.c: Add net_open(), and divert to it for net:host:port. + * ser_win32.c: Recognize net:host:port, and bail out. + * avrdude.1: Document the net:host:port connection option. + * doc/avrdude.texi: (Ditto.) + 2006-08-31 Joerg Wunsch Fix for bug #16627: Butterfly programmer does not reset after @@ -22,7 +33,7 @@ * serbb_win32.c: New pin numbering. The generic and Posix-related parts of these changes have been contributed by Hanns-Konrad Unger - + 2006-08-30 Joerg Wunsch Contributed by the anonymous developer of patch #5096: diff --git a/avrdude.1 b/avrdude.1 index 3e86ed4a..b0520b63 100644 --- a/avrdude.1 +++ b/avrdude.1 @@ -370,7 +370,7 @@ For the JTAG ICE mkII, if has been configured with libusb support, .Ar port can alternatively be specified as -.Ar usb Ns Op \&: Ns Ar serialno . +.Pa usb Ns Op \&: Ns Ar serialno . This will cause .Nm to search a JTAG ICE mkII on USB. @@ -384,6 +384,25 @@ from the serial number need to be given. .Pp As the AVRISP mkII device can only be talked to over USB, the very same method of specifying the port is required there. +.Pp +For programmers that attach to a serial port using some kind of +higher level protocol (as opposed to bit-bang style programmers), +.Ar port +can be specified as +.Pa net Ns \&: Ns Ar host Ns \&: Ns Ar port . +In this case, instead of trying to open a local device, a TCP +network connection to (TCP) +.Ar port +on +.Ar host +is established. +The remote endpoint is assumed to be a terminal or console server +that connects the network stream to a local serial port where the +actual programmer has been attached to. +The port is assumed to be properly configured, for example using a +transparent 8-bit data connection without parity at 115200 Baud +for a STK500. +.Em This feature is currently not implemented for Win32 systems. .It Fl q Disable (or quell) output of the progress bar while reading or writing to the device. Specify it a second time for even quieter operation. diff --git a/doc/avrdude.texi b/doc/avrdude.texi index 1babea75..fa1b30fe 100644 --- a/doc/avrdude.texi +++ b/doc/avrdude.texi @@ -28,7 +28,9 @@ This file documents the avrdude program. For avrdude version @value{VERSION}, @value{UPDATED}. -Copyright @copyright{} 2003, 2005, 2006 Brian Dean +Copyright @copyright{} 2003, 2005 Brian Dean + +Copyright @copyright{} 2006 J@"org Wunsch Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -64,6 +66,8 @@ Send comments on AVRDUDE to @w{@email{avrdude-dev@@nongnu.org}}. Use @uref{http://savannah.nongnu.org/bugs/?group=avrdude} to report bugs. Copyright @copyright{} 2003,2005 Brian S. Dean + +Copyright @copyright{} 2006 J@"org Wunsch @sp 2 Permission is granted to make and distribute verbatim copies of @@ -100,6 +104,8 @@ Send comments on AVRDUDE to @w{@email{avrdude-dev@@nongnu.org}}. Use @uref{http://savannah.nongnu.org/bugs/?group=avrdude} to report bugs. Copyright @copyright{} 2003,2005 Brian S. Dean + +Copyright @copyright{} 2006 J@"org Wunsch @end ifinfo @menu @@ -615,7 +621,7 @@ parallel or serial port, use this option to specify the alternate port name. For the JTAG ICE mkII, if AVRDUDE has been built with libusb support, @var{port} may alternatively be specified as -@var{usb}[:@var{serialno}]. In that case, the JTAG ICE mkII will be +@code{usb}[:@var{serialno}]. In that case, the JTAG ICE mkII will be looked up on USB. If @var{serialno} is also specified, it will be matched against the serial number read from any JTAG ICE mkII found on USB. The match is done after stripping any existing colons from the @@ -627,6 +633,22 @@ attached to USB, see @ref{Example Command Line Invocations}. As the AVRISP mkII device can only be talked to over USB, the very same method of specifying the port is required there. +For programmers that attach to a serial port using some kind of +higher level protocol (as opposed to bit-bang style programmers), +@var{port} can be specified as @code{net}:@var{host}:@var{port}. +In this case, instead of trying to open a local device, a TCP +network connection to (TCP) @var{port} on @var{host} +is established. +The remote endpoint is assumed to be a terminal or console server +that connects the network stream to a local serial port where the +actual programmer has been attached to. +The port is assumed to be properly configured, for example using a +transparent 8-bit data connection without parity at 115200 Baud +for a STK500. + +@emph{This feature is currently not implemented for Win32 systems.} + + @item -q Disable (or quell) output of the progress bar while reading or writing to the device. Specify it a second time for even quieter operation. diff --git a/ser_posix.c b/ser_posix.c index 141fe782..9feffd06 100644 --- a/ser_posix.c +++ b/ser_posix.c @@ -1,6 +1,7 @@ /* * avrdude - A Downloader/Uploader for AVR device programmers - * Copyright (C) 2003-2004, 2006 Theodore A. Roth + * Copyright (C) 2003-2004 Theodore A. Roth + * Copyright (C) 2006 Joerg Wunsch * * 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 @@ -33,6 +34,9 @@ #include #include #include +#include +#include +#include #include #include @@ -137,12 +141,90 @@ static int ser_setspeed(int fd, long baud) return 0; } +/* + * Given a port description of the form :, 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.) + */ +static int +net_open(const char *port) +{ + char *hstr, *pstr, *end; + unsigned int pnum; + int fd; + struct sockaddr_in sockaddr; + struct hostent *hp; + + if ((hstr = strdup(port)) == NULL) { + fprintf(stderr, "%s: net_open(): Out of memory!\n", + progname); + exit(1); + } + + if (((pstr = strchr(hstr, ':')) == NULL) || (pstr == hstr)) { + fprintf(stderr, "%s: net_open(): Mangled host:port string \"%s\"\n", + progname, hstr); + free(hstr); + exit(1); + } + + /* + * Terminate the host section of the description. + */ + *pstr++ = '\0'; + + pnum = strtoul(pstr, &end, 10); + + if ((*pstr == '\0') || (*end != '\0') || (pnum == 0) || (pnum > 65535)) { + fprintf(stderr, "%s: net_open(): Bad port number \"%s\"\n", + progname, pstr); + free(hstr); + exit(1); + } + + if ((hp = gethostbyname(hstr)) == NULL) { + fprintf(stderr, "%s: net_open(): unknown host \"%s\"\n", + progname, hstr); + free(hstr); + exit(1); + } + + free(hstr); + + if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { + fprintf(stderr, "%s: net_open(): Cannot open socket: %s\n", + progname, strerror(errno)); + exit(1); + } + + memset(&sockaddr, 0, sizeof(struct sockaddr_in)); + sockaddr.sin_family = AF_INET; + sockaddr.sin_port = htons(pnum); + memcpy(&(sockaddr.sin_addr.s_addr), hp->h_addr, sizeof(struct in_addr)); + + if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) { + fprintf(stderr, "%s: net_open(): Connect failed: %s\n", + progname, strerror(errno)); + exit(1); + } + + return fd; +} static int ser_open(char * port, long baud) { int rc; int fd; + /* + * If the port is of the form "net::", then + * handle it as a TCP connection to a terminal server. + */ + if (strncmp(port, "net:", strlen("net:")) == 0) { + return net_open(port + strlen("net:")); + } + /* * open the serial port */ diff --git a/ser_win32.c b/ser_win32.c index 8ccecc62..41d7ca3d 100644 --- a/ser_win32.c +++ b/ser_win32.c @@ -1,6 +1,7 @@ /* * avrdude - A Downloader/Uploader for AVR device programmers * Copyright (C) 2003, 2004 Martin J. Thomas + * Copyright (C) 2006 Joerg Wunsch * * 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 @@ -110,6 +111,20 @@ static int ser_open(char * port, long baud) LPVOID lpMsgBuf; HANDLE hComPort=INVALID_HANDLE_VALUE; + /* + * If the port is of the form "net::", then + * handle it as a TCP connection to a terminal server. + * + * This is curently not implemented for Win32. + */ + if (strncmp(port, "net:", strlen("net:")) == 0) { + fprintf(stderr, + "%s: ser_open(): network connects are currently not" + "implemented for Win32 environments\n", + progname); + exit(1); + } + /* if (hComPort!=INVALID_HANDLE_VALUE) fprintf(stderr, "%s: ser_open(): \"%s\" is already open\n", progname, port);