In developing a stk500v2 XPROG bootloader for my product, I ran into a problem with avrdude switching into the USB-only unframed version of the protocol after SIGN_ON. It does so because of an assumption that every stk500v2-xprog device will be communicating over USB. In my case I'm running over a serial link (and soon running that over a mutliplexed protocol), and the assumption is no longer correct.

I did a quick hack to the stk500v2.c code in order to make both cases work. Basically it adds a struct var 'bareproto', which is used to decide whether to send the stk500 commands framed or unframed, rather than the specific programmer type. The flag itself is set when the actual comms port is selected, and currently is only set if it's USB.

Being a quick hack I don't expect this patch to go anywhere itself. However, something like it should be put in place, since non-USB XPROG implementations are likely to show up (especially since I'll be releasing mine at some point soon...).

Likely a better way to implement it would be an avrdude.conf flag that would specifically set it to "framed-mode". Along those lines it would be nice to have some way to define programmers by their SIGN_ON responses. Since SIGN_ON is always sent in full stk500 framed mode no matter what, having avrdude check through the .conf for a string match (rather than hard-coded) and then picking up the "framed-mode" flag before continuing would make it easy to define new programmer types for bootloaders, etc.

Due to my development schedule I'm unable to do anything further on this at this point, but if it's still an issue when I have a bit more time, I'll see if I can give it a go.

Patch is attached, and I'll be filing it in the bug tracker in a couple minutes.
Index: stk500v2.c
===================================================================
--- stk500v2.c	(revision 947)
+++ stk500v2.c	(working copy)
@@ -116,6 +116,7 @@
         PGMTYPE_STK600,
     }
         pgmtype;
+  unsigned char bareproto;
 
   AVRPART *lastpart;
 
@@ -455,8 +456,9 @@
   unsigned char buf[275 + 6];		// max MESSAGE_BODY of 275 bytes, 6 bytes overhead
   int i;
 
-  if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
-      PDATA(pgm)->pgmtype == PGMTYPE_STK600)
+//  if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
+//      PDATA(pgm)->pgmtype == PGMTYPE_STK600)
+  if (PDATA(pgm)->bareproto == 1)
     return stk500v2_send_mk2(pgm, data, len);
   else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII)
     return stk500v2_jtagmkII_send(pgm, data, len);
@@ -558,8 +560,9 @@
   struct timeval tv;
   double tstart, tnow;
 
-  if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
-      PDATA(pgm)->pgmtype == PGMTYPE_STK600)
+//  if (PDATA(pgm)->pgmtype == PGMTYPE_AVRISP_MKII ||
+//      PDATA(pgm)->pgmtype == PGMTYPE_STK600)
+  if (PDATA(pgm)->bareproto == 1)
     return stk500v2_recv_mk2(pgm, msg, maxsize);
   else if (PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE_MKII)
     return stk500v2_jtagmkII_recv(pgm, msg, maxsize);
@@ -1283,6 +1286,7 @@
     baud = pgm->baudrate;
 
   PDATA(pgm)->pgmtype = PGMTYPE_UNKNOWN;
+  PDATA(pgm)->bareproto = 0;
 
   if(strcasecmp(port, "avrdoper") == 0){
 #if defined(HAVE_LIBUSB) || (defined(WIN32NATIVE) && defined(HAVE_LIBHID))
@@ -1304,7 +1308,9 @@
 #if defined(HAVE_LIBUSB)
     serdev = &usb_serdev_frame;
     baud = USB_DEVICE_AVRISPMKII;
-    PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
+//    PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
+    fprintf(stderr,"setting bare protocol\n");
+    PDATA(pgm)->bareproto = 1;
     pgm->set_sck_period = stk500v2_set_sck_period_mk2;
 #else
     fprintf(stderr, "avrdude was compiled without usb support.\n");
_______________________________________________
avrdude-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avrdude-dev

Reply via email to