diff -U 3 avrdude-5.8/arduino.c avrdude-5.8-arduino/arduino.c
--- avrdude-5.8/arduino.c	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/arduino.c	2009-08-16 00:13:21.000000000 +0200
@@ -82,13 +82,32 @@
   return 3;
 }
 
+static int arduino_open(PROGRAMMER * pgm, char * port)
+{
+  strcpy(pgm->port, port);
+  serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd, SEROPEN_FL_SETDTR | SEROPEN_FL_PULSERTS);
+
+  /*
+   * drain any extraneous input
+   */
+  stk500_drain(pgm, 0);
+
+  if (stk500_getsync(pgm) < 0)
+    return -1;
+
+  return 0;
+}
+
+
 void arduino_initpgm(PROGRAMMER * pgm)
 {
 	/* This is mostly a STK500; just the signature is read
-     differently than on real STK500v1 */
+     differently than on real STK500v1 
+     and the DTR signal is set when opening the serial port
+     for the Auto-Reset feature */
   stk500_initpgm(pgm);
 
   strcpy(pgm->type, "Arduino");
   pgm->read_sig_bytes = arduino_read_sig_bytes;
-
+  pgm->open = arduino_open;
 }
diff -U 3 avrdude-5.8/avr910.c avrdude-5.8-arduino/avr910.c
--- avrdude-5.8/avr910.c	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/avr910.c	2009-08-16 00:13:21.000000000 +0200
@@ -383,7 +383,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, pgm->baudrate, &pgm->fd);
+  serial_open(port, pgm->baudrate, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
diff -U 3 avrdude-5.8/butterfly.c avrdude-5.8-arduino/butterfly.c
--- avrdude-5.8/butterfly.c	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/butterfly.c	2009-08-16 00:13:21.000000000 +0200
@@ -356,7 +356,7 @@
   if(pgm->baudrate == 0) {
     pgm->baudrate = 19200;
   }
-  serial_open(port, pgm->baudrate, &pgm->fd);
+  serial_open(port, pgm->baudrate, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
Common subdirectories: avrdude-5.8/doc and avrdude-5.8-arduino/doc
diff -U 3 avrdude-5.8/jtagmkI.c avrdude-5.8-arduino/jtagmkI.c
--- avrdude-5.8/jtagmkI.c	2009-07-11 00:39:37.000000000 +0200
+++ avrdude-5.8-arduino/jtagmkI.c	2009-08-16 00:13:21.000000000 +0200
@@ -673,7 +673,7 @@
       fprintf(stderr,
               "%s: jtagmkI_open(): trying to sync at baud rate %ld:\n",
               progname, baudtab[i].baud);
-    serial_open(port, baudtab[i].baud, &pgm->fd);
+    serial_open(port, baudtab[i].baud, &pgm->fd, 0);
 
     /*
      * drain any extraneous input
diff -U 3 avrdude-5.8/jtagmkII.c avrdude-5.8-arduino/jtagmkII.c
--- avrdude-5.8/jtagmkII.c	2009-07-11 00:39:37.000000000 +0200
+++ avrdude-5.8-arduino/jtagmkII.c	2009-08-16 00:13:21.000000000 +0200
@@ -1318,7 +1318,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -1363,7 +1363,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -1408,7 +1408,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -1453,7 +1453,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
diff -U 3 avrdude-5.8/ser_avrdoper.c avrdude-5.8-arduino/ser_avrdoper.c
--- avrdude-5.8/ser_avrdoper.c	2009-07-11 00:48:48.000000000 +0200
+++ avrdude-5.8-arduino/ser_avrdoper.c	2009-08-16 00:13:21.000000000 +0200
@@ -504,7 +504,7 @@
 
 /* ------------------------------------------------------------------------- */
 
-static void avrdoper_open(char *port, long baud, union filedescriptor *fdp)
+static void avrdoper_open(char *port, long baud, union filedescriptor *fdp, unsigned int openflags)
 {
     int rval;
     char *vname = "obdev.at";
diff -U 3 avrdude-5.8/ser_posix.c avrdude-5.8-arduino/ser_posix.c
--- avrdude-5.8/ser_posix.c	2009-07-02 12:31:14.000000000 +0200
+++ avrdude-5.8-arduino/ser_posix.c	2009-08-16 00:14:18.000000000 +0200
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
@@ -210,7 +211,109 @@
   fdp->ifd = fd;
 }
 
-static void ser_open(char * port, long baud, union filedescriptor *fdp)
+
+static int ser_set_dtr(union filedescriptor *fdp)
+{
+  unsigned int	ctl;
+  int           r;
+
+  r = ioctl(fdp->ifd, TIOCMGET, &ctl);
+  if (r < 0) {
+    perror("ioctl(\"TIOCMGET\")");
+    return -1;
+  }
+  else {
+    /* make sure the RESET capacitor is unloaded by a cleared DTR */
+    /* clear DTR */
+    ctl &= ~(TIOCM_DTR);
+    r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+    if (r < 0) {
+      perror("ioctl(\"TIOCMSET\")");
+      return -1;
+    }
+    else {
+      usleep(50*1000);
+
+      /* set DTR */
+      ctl |= TIOCM_DTR;
+      r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+      if (r < 0) {
+        perror("ioctl(\"TIOCMSET\")");
+        return -1;
+      }
+      else {
+        usleep(50*1000);
+      }
+    }
+  }
+
+  return 0;
+}
+
+
+static int ser_reset_dtr_rts(union filedescriptor *fdp)
+{
+  unsigned int	ctl;
+  int           r;
+
+  r = ioctl(fdp->ifd, TIOCMGET, &ctl);
+  if (r < 0) {
+    perror("ioctl(\"TIOCMGET\")");
+    return -1;
+  }
+  else {
+    /* clear DTR and RTS */
+    ctl &= ~(TIOCM_DTR | TIOCM_RTS);
+    r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+    if (r < 0) {
+      perror("ioctl(\"TIOCMSET\")");
+      return -1;
+    }
+  }
+
+  return 0;
+}
+
+
+static int ser_pulse_rts(union filedescriptor *fdp)
+{
+  unsigned int	ctl;
+  int           r;
+
+  r = ioctl(fdp->ifd, TIOCMGET, &ctl);
+  if (r < 0) {
+    perror("ioctl(\"TIOCMGET\")");
+    return -1;
+  }
+  else {
+    /* clear RTS */
+    ctl &= ~(TIOCM_RTS);
+    r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+    if (r < 0) {
+      perror("ioctl(\"TIOCMSET\")");
+      return -1;
+    }
+    else {
+      usleep(50*1000);
+
+      /* set RTS */
+      ctl |= TIOCM_RTS;
+      r = ioctl(fdp->ifd, TIOCMSET, &ctl);
+      if (r < 0) {
+        perror("ioctl(\"TIOCMSET\")");
+        return -1;
+      }
+      else {
+        usleep(50*1000);
+      }
+    }
+  }
+
+  return 0;
+}
+
+
+static void ser_open(char * port, long baud, union filedescriptor *fdp, unsigned int openflags)
 {
   int rc;
   int fd;
@@ -246,6 +349,16 @@
             progname, port, strerror(-rc));
     exit(1);
   }
+
+  if(openflags & SEROPEN_FL_SETDTR)
+  {
+    ser_set_dtr(fdp);
+  }
+
+  if(openflags & SEROPEN_FL_PULSERTS)
+  {
+    ser_pulse_rts(fdp);
+  }
 }
 
 
@@ -264,6 +377,9 @@
     saved_original_termios = 0;
   }
 
+  /* clear DTR and RTS on close */
+  ser_reset_dtr_rts(fd);
+
   close(fd->ifd);
 }
 
diff -U 3 avrdude-5.8/ser_win32.c avrdude-5.8-arduino/ser_win32.c
--- avrdude-5.8/ser_win32.c	2009-07-02 12:23:57.000000000 +0200
+++ avrdude-5.8-arduino/ser_win32.c	2009-08-16 00:14:31.000000000 +0200
@@ -57,6 +57,11 @@
   { 0,      0 }                 /* Terminator. */
 };
 
+static DCB g_original_dcb;
+static int g_saved_original_dcb;
+
+static void ser_close(union filedescriptor *fd);
+
 static DWORD serial_baud_lookup(long baud)
 {
   struct baud_mapping *map = baud_lookup_table;
@@ -89,6 +94,27 @@
 	DCB dcb;
 	HANDLE hComPort = (HANDLE)fd->pfd;
 
+	/*
+	 * read and save original dcb
+	 */
+	ZeroMemory (&dcb, sizeof(DCB));
+	dcb.DCBlength = sizeof(DCB);
+	if(!GetCommState(hComPort, &dcb)) {
+		fprintf(stderr, "%s: ser_setspeed(): GetCommState() failed",
+			progname);
+		/* ignore the error; initial state will not be restored on close */
+	}
+	else
+	{
+		/*
+		 * copy DCB for ser_close if we haven't already
+		 */
+		if (! g_saved_original_dcb) {
+			g_saved_original_dcb = 1;
+			g_original_dcb = dcb;
+		}
+	}
+
 	ZeroMemory (&dcb, sizeof(DCB));
 	dcb.DCBlength = sizeof(DCB);
 	dcb.BaudRate = serial_baud_lookup (baud);
@@ -106,7 +132,7 @@
 }
 
 
-static void ser_open(char * port, long baud, union filedescriptor *fdp)
+static void ser_open(char * port, long baud, union filedescriptor *fdp, unsigned int openflags)
 {
 	LPVOID lpMsgBuf;
 	HANDLE hComPort=INVALID_HANDLE_VALUE;
@@ -174,15 +200,29 @@
         fdp->pfd = (void *)hComPort;
 	if (ser_setspeed(fdp, baud) != 0)
 	{
-		CloseHandle(hComPort);
+		ser_close(fdp);
 		fprintf(stderr, "%s: ser_open(): can't set com-state for \"%s\"\n",
 				progname, port);
 		exit(1);
 	}
 
+	if(openflags & SEROPEN_FL_SETDTR)
+	{
+		Sleep(50); /* make sure the RESET capacitor is unloaded by a cleared DTR */
+		EscapeCommFunction(hComPort, SETDTR);
+		Sleep(50);
+	}
+
+	if(openflags & SEROPEN_FL_PULSERTS)
+	{
+		Sleep(50);
+		EscapeCommFunction(hComPort, SETRTS);
+		Sleep(50);
+	}
+
 	if (!serial_w32SetTimeOut(hComPort,0))
 	{
-		CloseHandle(hComPort);
+		ser_close(fdp);
 		fprintf(stderr, "%s: ser_open(): can't set initial timeout for \"%s\"\n",
 				progname, port);
 		exit(1);
@@ -197,10 +237,35 @@
 static void ser_close(union filedescriptor *fd)
 {
 	HANDLE hComPort=(HANDLE)fd->pfd;
+
 	if (hComPort != INVALID_HANDLE_VALUE)
+	{
+		/* restore original settings */
+		if(g_saved_original_dcb) {
+			DCB dcb = g_original_dcb;
+
+			/* always reset DTR and RTS on close, important for Bluetooth devices */
+			dcb.fDtrControl = DTR_CONTROL_DISABLE;
+			dcb.fRtsControl = RTS_CONTROL_DISABLE;
+
+			if(!SetCommState(hComPort, &dcb)) {
+				fprintf(stderr, 
+					"%s: ser_close(): can't reset attributes for device\n",
+					progname);
+			}
+			g_saved_original_dcb = 0;
+		}
+		else {
+			/* fallback strategy when original values cannot be restored */
+			EscapeCommFunction(hComPort, CLRDTR);
+			EscapeCommFunction(hComPort, CLRRTS);
+		}
+
 		CloseHandle (hComPort);
+	}
 
 	hComPort = INVALID_HANDLE_VALUE;
+	fd->pfd = hComPort;
 }
 
 
diff -U 3 avrdude-5.8/serial.h avrdude-5.8-arduino/serial.h
--- avrdude-5.8/serial.h	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/serial.h	2009-08-16 00:13:21.000000000 +0200
@@ -44,7 +44,9 @@
 
 struct serial_device
 {
-  void (*open)(char * port, long baud, union filedescriptor *fd);
+  void (*open)(char * port, long baud, union filedescriptor *fd, unsigned int openflags);
+#define SEROPEN_FL_SETDTR    0x0001 /* set DTR when opening the serial port, needed for auto-reset of Arduino board */
+#define SEROPEN_FL_PULSERTS  0x0002 /* set RTS for a short time and clear it then when opening the serial port, needed for auto-reset of old Arduino board */
   int (*setspeed)(union filedescriptor *fd, long baud);
   void (*close)(union filedescriptor *fd);
 
diff -U 3 avrdude-5.8/stk500.c avrdude-5.8-arduino/stk500.c
--- avrdude-5.8/stk500.c	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/stk500.c	2009-08-16 00:13:21.000000000 +0200
@@ -73,13 +73,13 @@
 }
 
 
-static int stk500_drain(PROGRAMMER * pgm, int display)
+int stk500_drain(PROGRAMMER * pgm, int display)
 {
   return serial_drain(&pgm->fd, display);
 }
 
 
-static int stk500_getsync(PROGRAMMER * pgm)
+int stk500_getsync(PROGRAMMER * pgm)
 {
   unsigned char buf[32], resp[32];
 
@@ -657,7 +657,7 @@
 static int stk500_open(PROGRAMMER * pgm, char * port)
 {
   strcpy(pgm->port, port);
-  serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd);
+  serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
diff -U 3 avrdude-5.8/stk500.h avrdude-5.8-arduino/stk500.h
--- avrdude-5.8/stk500.h	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/stk500.h	2009-08-16 00:13:21.000000000 +0200
@@ -28,6 +28,10 @@
 
 void stk500_initpgm (PROGRAMMER * pgm);
 
+/* used by arduino.c to avoid duplicate code */
+int stk500_getsync(PROGRAMMER * pgm);
+int stk500_drain(PROGRAMMER * pgm, int display);
+
 #ifdef __cplusplus
 }
 #endif
diff -U 3 avrdude-5.8/stk500v2.c avrdude-5.8-arduino/stk500v2.c
--- avrdude-5.8/stk500v2.c	2009-07-11 00:39:37.000000000 +0200
+++ avrdude-5.8-arduino/stk500v2.c	2009-08-16 00:13:21.000000000 +0200
@@ -1268,7 +1268,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -1318,7 +1318,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -2765,7 +2765,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -2837,7 +2837,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
@@ -2909,7 +2909,7 @@
   }
 
   strcpy(pgm->port, port);
-  serial_open(port, baud, &pgm->fd);
+  serial_open(port, baud, &pgm->fd, 0);
 
   /*
    * drain any extraneous input
diff -U 3 avrdude-5.8/usb_libusb.c avrdude-5.8-arduino/usb_libusb.c
--- avrdude-5.8/usb_libusb.c	2009-03-06 21:09:11.000000000 +0100
+++ avrdude-5.8-arduino/usb_libusb.c	2009-08-16 00:13:21.000000000 +0200
@@ -56,7 +56,7 @@
  * The "baud" parameter is meaningless for USB devices, so we reuse it
  * to pass the desired USB device ID.
  */
-static void usbdev_open(char * port, long baud, union filedescriptor *fd)
+static void usbdev_open(char * port, long baud, union filedescriptor *fd, unsigned int openflags)
 {
   char string[256];
   char product[256];
Common subdirectories: avrdude-5.8/windows and avrdude-5.8-arduino/windows
