Index: jtagmkII.c
===================================================================
--- jtagmkII.c	(révision 1018)
+++ jtagmkII.c	(copie de travail)
@@ -166,6 +166,9 @@
                                  unsigned int page_size,
                                  unsigned int addr, unsigned int n_bytes);
 
+static int jtagmkII_dragon_open32(PROGRAMMER * pgm, char * port);
+
+
 void jtagmkII_setup(PROGRAMMER * pgm)
 {
   if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
@@ -1676,7 +1679,81 @@
   return 0;
 }
 
+static int jtagmkII_dragon_open32(PROGRAMMER * pgm, char * port)
+{
+  int status;
+  unsigned char buf[6], *resp;
+  long baud;
 
+  if (verbose >= 2)
+    fprintf(stderr, "%s: jtagmkII_dragon_open()\n", progname);
+
+  /*
+   * The JTAG ICE mkII always starts with a baud rate of 19200 Bd upon
+   * attaching.  If the config file or command-line parameters specify
+   * a higher baud rate, we switch to it later on, after establishing
+   * the connection with the ICE.
+   */
+  baud = 19200;
+
+  /*
+   * If the port name starts with "usb", divert the serial routines
+   * to the USB ones.  The serial_open() function for USB overrides
+   * the meaning of the "baud" parameter to be the USB device ID to
+   * search for.
+   */
+  if (strncmp(port, "usb", 3) == 0) {
+#if defined(HAVE_LIBUSB)
+    serdev = &usb_serdev;
+    baud = USB_DEVICE_AVRDRAGON;
+#else
+    fprintf(stderr, "avrdude was compiled without usb support.\n");
+    return -1;
+#endif
+  }
+
+  strcpy(pgm->port, port);
+  if (serial_open(port, baud, &pgm->fd)==-1) {
+    return -1;
+  }
+
+  /*
+   * drain any extraneous input
+   */
+  jtagmkII_drain(pgm, 0);
+
+  if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0)
+    return -1;
+
+  // AVR32 "special"
+  buf[0] = CMND_SET_PARAMETER;
+  buf[1] = 0x2D;
+  buf[2] = 0x03;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  buf[1] = 0x03;
+  buf[2] = 0x02;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  buf[1] = 0x03;
+  buf[2] = 0x04;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  return 0;
+}
+
 void jtagmkII_close(PROGRAMMER * pgm)
 {
   int status;
@@ -3734,6 +3811,38 @@
   pgm->flag           = PGM_FL_IS_DW;
 }
 
+void jtagmkII_dragon_avr32_initpgm(PROGRAMMER * pgm)
+{
+  strcpy(pgm->type, "DRAGON_AVR32");
+
+  /*
+   * mandatory functions
+   */
+  pgm->initialize     = jtagmkII_initialize32;
+  pgm->display        = jtagmkII_display;
+  pgm->enable         = jtagmkII_enable;
+  pgm->disable        = jtagmkII_disable;
+  pgm->program_enable = jtagmkII_program_enable_dummy;
+  pgm->chip_erase     = jtagmkII_chip_erase32;
+  pgm->open           = jtagmkII_dragon_open32;
+  pgm->close          = jtagmkII_close32;
+  pgm->read_byte      = jtagmkII_read_byte;
+  pgm->write_byte     = jtagmkII_write_byte;
+
+  /*
+   * optional functions
+   */
+  pgm->paged_write    = jtagmkII_paged_write32;
+  pgm->paged_load     = jtagmkII_paged_load32;
+  pgm->print_parms    = jtagmkII_print_parms;
+  pgm->set_sck_period = jtagmkII_set_sck_period;
+  pgm->parseextparams = jtagmkII_parseextparms;
+  pgm->setup          = jtagmkII_setup;
+  pgm->teardown       = jtagmkII_teardown;
+  pgm->page_size      = 256;
+  pgm->flag           = PGM_FL_IS_JTAG;
+}
+
 void jtagmkII_avr32_initpgm(PROGRAMMER * pgm)
 {
   strcpy(pgm->type, "JTAGMKII_AVR32");
Index: jtagmkII.h
===================================================================
--- jtagmkII.h	(révision 1018)
+++ jtagmkII.h	(copie de travail)
@@ -40,6 +40,7 @@
 void jtagmkII_dragon_initpgm (PROGRAMMER * pgm);
 void jtagmkII_dragon_dw_initpgm (PROGRAMMER * pgm);
 void jtagmkII_dragon_pdi_initpgm (PROGRAMMER * pgm);
+void jtagmkII_dragon_avr32_initpgm(PROGRAMMER * pgm);
 
 /*
  * These functions are referenced from stk500v2.c for JTAG ICE mkII
Index: config_gram.y
===================================================================
--- config_gram.y	(révision 1018)
+++ config_gram.y	(copie de travail)
@@ -103,6 +103,7 @@
 %token K_DRAGON_JTAG
 %token K_DRAGON_PDI
 %token K_DRAGON_PP
+%token K_DRAGON_AVR32
 %token K_STK500_DEVCODE
 %token K_AVR910_DEVCODE
 %token K_EEPROM
@@ -532,6 +533,11 @@
       jtagmkII_avr32_initpgm(current_prog);
     }
   } |
+  K_TYPE TKN_EQUAL K_DRAGON_AVR32 {
+    {
+      jtagmkII_dragon_avr32_initpgm(current_prog);
+    }
+  } |
 
   K_TYPE TKN_EQUAL K_JTAG_MKII_DW {
     {
Index: ChangeLog
===================================================================
--- ChangeLog	(révision 1018)
+++ ChangeLog	(copie de travail)
@@ -1,3 +1,9 @@
+2011-11-06  Julien Aube  <julien.aube@openwide.fr>
+
+	* jtakmkII.c: Added a new programmer type "dragon_avr32", to 
+	let an AVR dragon program AVR32 parts.
+	* avrdude.conf: 32UC3A1256 part to config file.
+
 2011-10-19  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* configure.ac: Replace "cvs" in version number by "svn".
Index: lexer.l
===================================================================
--- lexer.l	(révision 1018)
+++ lexer.l	(copie de travail)
@@ -144,6 +144,7 @@
 dragon_jtag      { yylval=NULL; return K_DRAGON_JTAG; }
 dragon_pdi       { yylval=NULL; return K_DRAGON_PDI; }
 dragon_pp        { yylval=NULL; return K_DRAGON_PP; }
+dragon_avr32     { yylval=NULL; return K_DRAGON_AVR32; }
 eecr             { yylval=NULL; return K_EECR; }
 eeprom           { yylval=NULL; return K_EEPROM; }
 enablepageprogramming { yylval=NULL; return K_ENABLEPAGEPROGRAMMING; }
