From 9afb392045180c8513634b5230d2187347bdc065 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Fri, 26 Aug 2011 20:50:32 +0000 Subject: [PATCH] Submitted by Juergen Weigert: patch #7056: adding support for mikrokopter bootloader to butterfly * butterfly.c: Add some specific logic to handle the mikrokopter.de butterfly bootloader. * butterfly.h: Add one related function declaration. * config_gram.y: Add butterfly_mk keyword. * lexer.l: (Ditto.) * avrdude.conf.in: Add entry for butterfly_mk. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@991 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/ChangeLog | 11 ++++++ avrdude/NEWS | 1 + avrdude/avrdude.conf.in | 13 +++++++ avrdude/butterfly.c | 82 ++++++++++++++++++++++++++++++++--------- avrdude/butterfly.h | 1 + avrdude/config_gram.y | 7 ++++ avrdude/lexer.l | 1 + 7 files changed, 98 insertions(+), 18 deletions(-) diff --git a/avrdude/ChangeLog b/avrdude/ChangeLog index a834c4f2..fd457e2b 100644 --- a/avrdude/ChangeLog +++ b/avrdude/ChangeLog @@ -1,3 +1,14 @@ +2011-08-26 Joerg Wunsch + + Submitted by Juergen Weigert: + patch #7056: adding support for mikrokopter bootloader to butterfly + * butterfly.c: Add some specific logic to handle the + mikrokopter.de butterfly bootloader. + * butterfly.h: Add one related function declaration. + * config_gram.y: Add butterfly_mk keyword. + * lexer.l: (Ditto.) + * avrdude.conf.in: Add entry for butterfly_mk. + 2011-08-26 Joerg Wunsch Submitted by Stefan Tomanek: diff --git a/avrdude/NEWS b/avrdude/NEWS index b9f69c5b..c83a41d5 100644 --- a/avrdude/NEWS +++ b/avrdude/NEWS @@ -17,6 +17,7 @@ Current: and parallel ones) - FT2232 (and relatives) based programmers (MPSSE bitbang mode) - Wiring environment (http://wiring.org.co/) + - butterfly-style bootloader of the Mikrokopter.de device * Bugfixes diff --git a/avrdude/avrdude.conf.in b/avrdude/avrdude.conf.in index 8b6e6317..39e21568 100644 --- a/avrdude/avrdude.conf.in +++ b/avrdude/avrdude.conf.in @@ -551,6 +551,19 @@ programmer desc = "Atmel AppNote AVR911 AVROSP"; type = butterfly; ; + +# suggested in http://forum.mikrokopter.de/topic-post48317.html +programmer + id = "mkbutterfly"; + desc = "Mikrokopter.de Butterfly"; + type = butterfly_mk; +; + +programmer + id = "butterfly_mk"; + desc = "Mikrokopter.de Butterfly"; + type = butterfly_mk; +; programmer id = "jtagmkI"; diff --git a/avrdude/butterfly.c b/avrdude/butterfly.c index 1a2ddf40..bb7c35c9 100644 --- a/avrdude/butterfly.c +++ b/avrdude/butterfly.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "avrdude.h" #include "avr.h" @@ -205,6 +206,7 @@ static void butterfly_powerdown(PROGRAMMER * pgm) return; } +#define IS_BUTTERFLY_MK 0x0001 /* * initialize the AVR device and prepare it to accept commands @@ -223,26 +225,61 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p) * for plain avr109 bootloaders but does not harm there either. */ fprintf(stderr, "Connecting to programmer: "); - do { - putc('.', stderr); - butterfly_send(pgm, "\033", 1); - butterfly_drain(pgm, 0); - butterfly_send(pgm, "S", 1); - butterfly_recv(pgm, &c, 1); - if (c != '?') { - putc('\n', stderr); - /* - * Got a useful response, continue getting the programmer - * identifier. Programmer returns exactly 7 chars _without_ - * the null. - */ - id[0] = c; - butterfly_recv(pgm, &id[1], sizeof(id)-2); - id[sizeof(id)-1] = '\0'; + if (pgm->flag & IS_BUTTERFLY_MK) + { + char mk_reset_cmd[6] = {"#aR@S\r"}; + unsigned char mk_timeout = 0; + + putc('.', stderr); + butterfly_send(pgm, mk_reset_cmd, sizeof(mk_reset_cmd)); + usleep(20000); + + do + { + c = 27; + butterfly_send(pgm, &c, 1); + usleep(20000); + c = 0xaa; + usleep(80000); + butterfly_send(pgm, &c, 1); + if (mk_timeout % 10 == 0) putc('.', stderr); + } while (mk_timeout++ < 10); + + butterfly_recv(pgm, &c, 1); + if ( c != 'M' && c != '?') + { + fprintf(stderr, "\nConnection FAILED."); + exit(1); + } + else + { + id[0] = 'M'; id[1] = 'K'; id[2] = '2'; id[3] = 0; + } + } + else + { + do { + putc('.', stderr); + butterfly_send(pgm, "\033", 1); + butterfly_drain(pgm, 0); + butterfly_send(pgm, "S", 1); + butterfly_recv(pgm, &c, 1); + if (c != '?') { + putc('\n', stderr); + /* + * Got a useful response, continue getting the programmer + * identifier. Programmer returns exactly 7 chars _without_ + * the null. + */ + id[0] = c; + butterfly_recv(pgm, &id[1], sizeof(id)-2); + id[sizeof(id)-1] = '\0'; + } + } while (c == '?'); } - } while (c == '?'); /* Get the HW and SW versions to see if the programmer is present. */ + butterfly_drain(pgm, 0); butterfly_send(pgm, "V", 1); butterfly_recv(pgm, sw, sizeof(sw)); @@ -327,6 +364,7 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p) progname, (unsigned)buf[1]); butterfly_enter_prog_mode(pgm); + butterfly_drain(pgm, 0); return 0; } @@ -665,7 +703,7 @@ static int butterfly_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m) void butterfly_initpgm(PROGRAMMER * pgm) { - strcpy(pgm->type, "avr910"); + strcpy(pgm->type, "butterfly"); /* * mandatory functions @@ -698,4 +736,12 @@ void butterfly_initpgm(PROGRAMMER * pgm) pgm->setup = butterfly_setup; pgm->teardown = butterfly_teardown; + pgm->flag = 0; +} + +void butterfly_mk_initpgm(PROGRAMMER * pgm) +{ + butterfly_initpgm(pgm); + strcpy(pgm->type, "butterfly_mk"); + pgm->flag = IS_BUTTERFLY_MK; } diff --git a/avrdude/butterfly.h b/avrdude/butterfly.h index 51abdc0a..aa4c58c7 100644 --- a/avrdude/butterfly.h +++ b/avrdude/butterfly.h @@ -27,6 +27,7 @@ extern "C" { #endif void butterfly_initpgm (PROGRAMMER * pgm); +void butterfly_mk_initpgm (PROGRAMMER * pgm); #ifdef __cplusplus } diff --git a/avrdude/config_gram.y b/avrdude/config_gram.y index 1de7d650..3e10cd46 100644 --- a/avrdude/config_gram.y +++ b/avrdude/config_gram.y @@ -161,6 +161,7 @@ static int parse_cmdbits(OPCODE * op); %token K_USBVENDOR %token K_USBVID %token K_BUTTERFLY +%token K_BUTTERFLY_MK %token K_TYPE %token K_VCC %token K_VFYLED @@ -508,6 +509,12 @@ prog_parm : } } | + K_TYPE TKN_EQUAL K_BUTTERFLY_MK { + { + butterfly_mk_initpgm(current_prog); + } + } | + K_TYPE TKN_EQUAL K_JTAG_MKI { { jtagmkI_initpgm(current_prog); diff --git a/avrdude/lexer.l b/avrdude/lexer.l index cc3a40f3..6f1698f8 100644 --- a/avrdude/lexer.l +++ b/avrdude/lexer.l @@ -130,6 +130,7 @@ bs2 { yylval=NULL; return K_BS2; } buff { yylval=NULL; return K_BUFF; } buspirate { yylval=NULL; return K_BUSPIRATE; } butterfly { yylval=NULL; return K_BUTTERFLY; } +butterfly_mk { yylval=NULL; return K_BUTTERFLY_MK; } chip_erase_delay { yylval=NULL; return K_CHIP_ERASE_DELAY; } desc { yylval=NULL; return K_DESC; } default_parallel { yylval=NULL; return K_DEFAULT_PARALLEL; }