Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.c
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.c	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.c	(working copy)
@@ -44,6 +44,8 @@
 
 extern int do_cycles;
 
+int verbose;     /* verbose output */
+FILE * DebFile;
 
 int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, 
                           unsigned long addr, unsigned char * value)
@@ -738,7 +740,9 @@
 	WriteAdres = NextAdres;
   }
   
+  fprintf(stderr,"polling of last byte");
   avr_read_byte(pgm, p, m, LastAdres, &data); /*enshure\flush write last page write*/
+  fprintf(stderr," done\n");
   
   return rc;
 }
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.h
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.h	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/avr.h	(working copy)
@@ -26,9 +26,8 @@
 
 #include "avrpart.h"
 #include "pgm.h"
+#include "globals.h"
 
-
-
 extern struct avrpart parts[];
 
 
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/butterfly.c
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/butterfly.c	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/butterfly.c	(working copy)
@@ -480,18 +480,38 @@
   if (wordbytes <= 0) 
   	{return wordbytes;}
 
+#ifdef DEBMSG
+  if (verbose >= ProgrammerDebLevel) {
+  	fprintf(DebFile,"\n%s:butterfly_read_byte_flash(): read byte from %s:%X", progname, m->desc, part_addr);
+  }
+#endif
+
   if (cached && (caddr == part_addr)) {
     *value = cvalue[addr - word_addr];
+
+#ifdef DEBMSG
+	  if (verbose >= ProgrammerDebLevel) {
+	  	fprintf(DebFile,"butterfly_read_byte_flash(): was cached\n");
+	  }
+#endif
+
   }
   else {
     char cmd[4] = "g\000\002F";
 
     butterfly_set_addr(pgm, part_addr);
+    
     cmd[2] = (char) wordbytes;
     butterfly_send(pgm, cmd, sizeof(cmd));
-    butterfly_recv(pgm, cvalue, sizeof(cvalue));
+    butterfly_recv(pgm, cvalue, wordbytes);
     cached = 1;
     *value = cvalue[addr - word_addr];
+
+#ifdef DEBMSG
+	  if (verbose >= ProgrammerDebLevel) {
+	  	fprintf(DebFile,"butterfly_read_byte_flash(): done\n");
+	  }
+#endif
   }
 
   return 0;
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ChangeLog
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ChangeLog	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ChangeLog	(working copy)
@@ -1,3 +1,22 @@
+2006-02-09 AlexRayne <alexrainpe196@newmail.ru>
+	* avr.c:
+	* avr.h:
+	* butterfly.c:
+	* config.c:
+	* config.h:
+	* main.c:
+	* ser_win32.c:
+	* serial.h:
+	* makefile.in:
+	* globals.h:
+	
+	* fixed bug of previous my patch - butterfly_read_byte_flash tryes to read wrong amount of data
+	* introduced contecanating option avrdude_CFLAGS with user deined in make command str.
+	* introduced global definition DEBMSG - wich should turn on ability of verbose debug messaging
+	* introduced option -d - wich define file name to write debuf Info. for this defined another file
+	 DebFile - wich is by default = stderr. new headers file inserted - globals.h
+	* revised code to monitor data flow in ser_win32.c
+	
 2006-02-08 AlexRayne <alexrainpe196@newmail.ru>
 	
 	* avr.c:
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.c
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.c	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.c	(working copy)
@@ -283,4 +283,3 @@
 
   return s;
 }
-
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.h
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.h	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/config.h	(working copy)
@@ -58,7 +58,6 @@
 extern int			FastWrite;
 extern int			FastVerify;
 
-
 #if !defined(HAS_YYSTYPE)
 #define YYSTYPE struct token_t *
 #endif
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/main.c
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/main.c	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/main.c	(working copy)
@@ -75,7 +75,6 @@
 /* Get VERSION from ac_cfg.h */
 char * version      = VERSION;
 
-int    verbose;     /* verbose output */
 int    quell_progress; /* un-verebose output */
 char * progname;
 char   progbuf[PATH_MAX]; /* temporary buffer of spaces the same
@@ -113,9 +112,9 @@
  "                             Multiple -U options are allowed, each request\n"
  "                             is performed in the order specified.\n"
  "  -n                         Do not write anything to the device.\n"
- "  -f <w+|->                  Write only noempty pages 2 Flash or EEPROM "
- "                             if errased before"
- "     <v+|->                  Only verify noempty pages of Flash"
+ "  -f <w+|->                  Write only noempty pages 2 Flash or EEPROM\n"
+ "                             if errased before\n"
+ "     <v+|->                  Only verify noempty pages of Flash\n"
  "  -V                         Do not verify.\n"
  "  -u                         Disable safemode, default when running from a script.\n"
  "  -s                         Silent safemode operation, will not ask you if\n"
@@ -126,6 +125,7 @@
  "  -Y <number>                Initialize erase cycle # in EEPROM.\n"
  "  -v                         Verbose output. -v -v for more.\n"
  "  -q                         Quell progress output. -q -q for less.\n"
+ "  -d <debug messages filename> write debug messages in specified file" 
  "  -?                         Display this usage.\n"
  "\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n"
           ,progname);
@@ -799,6 +799,7 @@
   bitclock      = 0.0;
   safemode      = 1;       /* Safemode on by default */
   silentsafe    = 0;       /* Ask by default */
+  DebFile 		= stderr;
   
   if (isatty(STDIN_FILENO) == 0)
       safemode  = 0;       /* Turn off safemode if this isn't a terminal */
@@ -847,7 +848,7 @@
   /*
    * process command line arguments
    */
-  while ((ch = getopt(argc,argv,"?b:B:c:C:DeE:Fnp:P:qstU:uvVyY:f:")) != -1) {
+  while ((ch = getopt(argc,argv,"?b:B:c:C:DeE:Fnp:P:qstU:uvVyY:f:d:")) != -1) {
 
     switch (ch) {
       case 'b': /* override default programmer baud rate */
@@ -986,6 +987,15 @@
         }
         do_cycles = 1;
         break;
+      case 'd': /* debug messages file*/
+      	
+		  DebFile = fopen(optarg, "w");
+		  if (DebFile == NULL) {
+		    fprintf(stderr, "can't open debug file \"%s\": %s\n",
+		            optarg, strerror(errno));
+		    DebFile = stderr;
+		  }
+		  break;
 
       case '?': /* help */
         usage();
@@ -1613,6 +1623,7 @@
   if (quell_progress < 2) {
     fprintf(stderr, "\n%s done.  Thank you.\n\n", progname);
   }
-
+	
+  if (DebFile != stderr) {fclose(DebFile);}
   return exitrc;
 }
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/Makefile.in
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/Makefile.in	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/Makefile.in	(working copy)
@@ -255,7 +255,7 @@
 DIST_SUBDIRS = @DIST_SUBDIRS_AC@
 AM_YFLAGS = -d
 avrdude_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\"
-avrdude_CFLAGS = @ENABLE_WARNINGS@  
+override avrdude_CFLAGS += @ENABLE_WARNINGS@  
 avrdude_SOURCES = \
 	config_gram.y \
 	lexer.l \
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ser_win32.c
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ser_win32.c	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/ser_win32.c	(working copy)
@@ -31,7 +31,6 @@
 #include "serial.h"
 
 extern char *progname;
-extern int verbose;
 
 long serial_recv_timeout = 5000; /* ms */
 
@@ -174,10 +173,9 @@
 }
 
 
-static int ser_send(int fd, char * buf, size_t buflen)
+static int ser_send(int fd, unsigned char * buf, size_t buflen)
 {
 	size_t len = buflen;
-	unsigned char c='\0';
 	DWORD written;
 
 	HANDLE hComPort=(HANDLE)fd;
@@ -191,25 +189,22 @@
 	if (!len)
   return 0;
 
-	if (verbose > 3)
-	{
-		fprintf(stderr, "%s: Send: ", progname);
-
-		while (buflen) {
-			c = *buf;
-			if (isprint(c)) {
-				fprintf(stderr, "%c ", c);
-			}
-			else {
-				fprintf(stderr, ". ");
-			}
-			fprintf(stderr, "[%02x] ", c);
-			buf++;
-			buflen--;
+	  if (verbose >= CmdFlowDebLevel) {
+	  	int idx;
+	  	int inlineidx;
+	  	int line;
+	  	
+	  	fprintf(DebFile,"%s: send %i bytes:", progname, len);
+	  	idx = 0;
+	  	for (line = 0 ; line < (len / 8)+1 ; line ++ ) {
+			fprintf(DebFile,"\n");
+		  	for (inlineidx = 0; (idx < len) && (inlineidx < 8); inlineidx++ , idx++) {
+		  		fprintf(DebFile,"%02x ", buf[idx]);
+		  	}
 		}
-      fprintf(stderr, "\n");
-	}
-	
+		fprintf(DebFile,"\n");
+	  }
+
 	serial_w32SetTimeOut(hComPort,500);
 
 	if (!WriteFile (hComPort, buf, buflen, &written, NULL)) {
@@ -228,11 +223,8 @@
 }
 
 
-static int ser_recv(int fd, char * buf, size_t buflen)
+static int ser_recv(int fd, unsigned char * buf, size_t buflen)
 {
-	unsigned char c;
-	char * p = buf;
-	size_t len = 0;
 	DWORD read;
 
 	HANDLE hComPort=(HANDLE)fd;
@@ -263,27 +255,22 @@
 		exit(1);
 	}
 
-	p = buf;
-
-	if (verbose > 3)
-	{
-		fprintf(stderr, "%s: Recv: ", progname);
-
-		while (len) {
-			c = *p;
-			if (isprint(c)) {
-				fprintf(stderr, "%c ", c);
-			}
-			else {
-				fprintf(stderr, ". ");
-			}
-			fprintf(stderr, "[%02x] ", c);
-
-			p++;
-			len--;
+	if (verbose >= CmdFlowDebLevel) {
+	  	int idx;
+	  	int inlineidx;
+	  	int line;
+	  	
+	  	idx = 0;
+	  	fprintf(DebFile,"%s: recv %i bytes:", progname, buflen);
+	  	for (line = 0 ; line < (buflen / 8)+1 ; line ++ ) {
+			fprintf(DebFile,"\n");
+		  	for (inlineidx = 0; (idx < buflen) && (inlineidx < 8); idx++ , inlineidx++) {
+		  		fprintf(DebFile,"%02x ", buf[idx]);
+		  	}
 		}
-		fprintf(stderr, "\n");
+		fprintf(DebFile,"\n");
 	}
+
   return 0;
 }
 
Index: G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/serial.h
===================================================================
--- G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/serial.h	(revision 6)
+++ G:/DOC/Components/Atmel/AVR_ISP/avrdude/src/serial.h	(working copy)
@@ -30,6 +30,8 @@
 #ifndef __serial_h__
 #define __serial_h__
 
+#include "globals.h"
+
 extern long serial_recv_timeout;
 
 struct serial_device
