From ae566048c39e9f7b80171a322135962953ff4f4a Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Mon, 16 Feb 2009 10:19:46 +0000
Subject: [PATCH] Submitted by Janos Sallai: patch #6542: paged_load fails on
 the MIB510 programming board * stk500.c: Add a workaround for the different
 signon sequence on MIB510 programmers.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@791 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog |  7 +++++++
 NEWS      |  2 +-
 stk500.c  | 14 +++++++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 369f4fc9..9c3bf0d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-02-16  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	Submitted by Janos Sallai:
+	patch #6542: paged_load fails on the MIB510 programming board
+	* stk500.c: Add a workaround for the different signon sequence on
+	MIB510 programmers.
+
 2009-02-05  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* avrdude.conf.in: Add the ATmega128RFA1.
diff --git a/NEWS b/NEWS
index c0718788..6fb7b298 100644
--- a/NEWS
+++ b/NEWS
@@ -20,7 +20,7 @@ Current:
     programmer, to allow overriding the device code sent to the
     programmer.
 
-  * Add support for the Crossbow MIB510 programmer (patch #6074).
+  * Add support for the Crossbow MIB510 programmer (patch #6074, #6542).
 
   * Add support to bootstrap with GNU autoconf 2.61, and automake 1.10,
     respectively.
diff --git a/stk500.c b/stk500.c
index 4481ce46..03ee5b83 100644
--- a/stk500.c
+++ b/stk500.c
@@ -971,7 +971,9 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
 
     if (stk500_recv(pgm, buf, 1) < 0)
       exit(1);
-    if (buf[0] != Resp_STK_OK) {
+
+    if(strcmp(ldata(lfirst(pgm->id)), "mib510") == 0) {
+      if (buf[0] != Resp_STK_INSYNC) {
       fprintf(stderr,
               "\n%s: stk500_paged_load(): (a) protocol error, "
               "expect=0x%02x, resp=0x%02x\n", 
@@ -979,6 +981,16 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
       return -5;
     }
   }
+    else {
+      if (buf[0] != Resp_STK_OK) {
+        fprintf(stderr,
+                "\n%s: stk500_paged_load(): (a) protocol error, "
+                "expect=0x%02x, resp=0x%02x\n",
+                progname, Resp_STK_OK, buf[0]);
+        return -5;
+      }
+    }
+  }
 
   return n_bytes;
 }