diff -crB avrdude-5.10/jtagmkII.c avrdude-5.10-jl/jtagmkII.c
*** avrdude-5.10/jtagmkII.c	2010-01-19 05:39:11.000000000 -0500
--- avrdude-5.10-jl/jtagmkII.c	2011-05-21 16:40:06.000000000 -0400
***************
*** 1746,1751 ****
--- 1746,1752 ----
    unsigned char par[4];
    int status, tries;
    long otimeout = serial_recv_timeout;
+ 	int actual_mem_size = 0;
  
    if (verbose >= 2)
      fprintf(stderr, "%s: jtagmkII_paged_write(.., %s, %d, %d)\n",
***************
*** 1770,1792 ****
    }
  
    cmd[0] = CMND_WRITE_MEMORY;
!   cmd[1] = ( p->flags & AVRPART_HAS_PDI ) ? MTYPE_FLASH : MTYPE_FLASH_PAGE;
    if (strcmp(m->desc, "flash") == 0) {
      PDATA(pgm)->flash_pageaddr = (unsigned long)-1L;
      page_size = PDATA(pgm)->flash_pagesize;
    } else if (strcmp(m->desc, "eeprom") == 0) {
!     if (pgm->flag & PGM_FL_IS_DW) {
        /*
         * jtagmkII_paged_write() to EEPROM attempted while in
         * DW mode.  Use jtagmkII_write_byte() instead.
         */
        for (addr = 0; addr < n_bytes; addr++) {
! 	status = jtagmkII_write_byte(pgm, p, m, addr, m->buf[addr]);
! 	report_progress(addr, n_bytes, NULL);
! 	if (status < 0) {
! 	  free(cmd);
! 	  return -1;
! 	}
        }
        free(cmd);
        return n_bytes;
--- 1771,1811 ----
    }
  
    cmd[0] = CMND_WRITE_MEMORY;
!   if ( p->flags & AVRPART_HAS_PDI )
!   {
!     if ( strcmp(m->desc, "boot") == 0 )
!       cmd[1] = MTYPE_BOOTFLASH;
!     else
!     {
!       cmd[1] = MTYPE_FLASH;
!       if (strcmp(m->desc, "flash") == 0 )
!       {
!         actual_mem_size = avr_locate_mem(p, "application")->size;
!       }
!     }
!   } else
!     cmd[1] = MTYPE_FLASH_PAGE;
! 	
    if (strcmp(m->desc, "flash") == 0) {
      PDATA(pgm)->flash_pageaddr = (unsigned long)-1L;
      page_size = PDATA(pgm)->flash_pagesize;
+   } else if ( ( strcmp(m->desc, "prodsig") == 0 ) ) {
+ 		cmd[1] = MTYPE_PRODSIG;
+   } else if ( ( strcmp(m->desc, "usersig") == 0 ) ) {
+     cmd[1] = MTYPE_USERSIG;
    } else if (strcmp(m->desc, "eeprom") == 0) {
! 		if (pgm->flag & PGM_FL_IS_DW) {
        /*
         * jtagmkII_paged_write() to EEPROM attempted while in
         * DW mode.  Use jtagmkII_write_byte() instead.
         */
        for (addr = 0; addr < n_bytes; addr++) {
! 	      status = jtagmkII_write_byte(pgm, p, m, addr, m->buf[addr]);
! 	      report_progress(addr, n_bytes, NULL);
! 	      if (status < 0) {
! 	        free(cmd);
! 	        return -1;
! 	      }
        }
        free(cmd);
        return n_bytes;
***************
*** 1811,1816 ****
--- 1830,1842 ----
      u32_to_b4(cmd + 2, page_size);
      u32_to_b4(cmd + 6, addr+m->offset );
  
+     if ( actual_mem_size > 0 && addr >= actual_mem_size ) {
+       if ( p->flags & AVRPART_HAS_PDI ) {
+         if ( strcmp(m->desc, "flash") == 0 )
+           cmd[1] = MTYPE_BOOTFLASH;
+       }
+     }
+ 		
      /*
       * The JTAG ICE will refuse to write anything but a full page, at
       * least for the flash ROM.  If a partial page has been requested,
***************
*** 1821,1833 ****
      memset(cmd + 10, 0xff, page_size);
      memcpy(cmd + 10, m->buf + addr, block_size);
  
      tries = 0;
  
      retry:
!     if (verbose >= 2)
!       fprintf(stderr, "%s: jtagmkII_paged_write(): "
! 	      "Sending write memory command: ",
! 	      progname);
      jtagmkII_send(pgm, cmd, page_size + 10);
  
      status = jtagmkII_recv(pgm, &resp);
--- 1847,1867 ----
      memset(cmd + 10, 0xff, page_size);
      memcpy(cmd + 10, m->buf + addr, block_size);
  
+ 		if((pgm->flag & PGM_FL_IS_JTAG)&&(cmd[1] == MTYPE_BOOTFLASH)) {
+ 			if (verbose >= 2)
+ 				fprintf(stderr, "\nOhh yes it is JTAG and a boot write!\n");
+ 			cmd[8] = 0;
+ 		}
+ 		
      tries = 0;
  
      retry:
!     if (verbose >= 2) {
! 			cmd[8] = 0;
!       fprintf(stderr, "--->> jtagmkII_paged_write(): "
! 	      "Sending write memory command: %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x -> ",
! 	      cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], cmd[8], cmd[9] );
! 		}
      jtagmkII_send(pgm, cmd, page_size + 10);
  
      status = jtagmkII_recv(pgm, &resp);
diff -crB avrdude-5.10/jtagmkII_private.h avrdude-5.10-jl/jtagmkII_private.h
*** avrdude-5.10/jtagmkII_private.h	2010-01-19 05:39:11.000000000 -0500
--- avrdude-5.10-jl/jtagmkII_private.h	2011-05-21 13:21:09.000000000 -0400
***************
*** 180,188 ****
  #define MTYPE_SIGN_JTAG 0xB4	/* signature in programming mode */
  #define MTYPE_OSCCAL_BYTE 0xB5	/* osccal cells in programming mode */
  #define MTYPE_CAN 0xB6		/* CAN mailbox */
! #define MTYPE_FLASH 0xc0	/* xmega flash - undocumented in AVR067 */
! #define MTYPE_USERSIG 0xc5	/* xmega user signature - undocumented in AVR067 */
! #define MTYPE_PRODSIG 0xc6	/* xmega production signature - undocumented in AVR067 */
  
  /* (some) ICE parameters, for CMND_{GET,SET}_PARAMETER */
  #define PAR_HW_VERSION 0x01
--- 180,189 ----
  #define MTYPE_SIGN_JTAG 0xB4	/* signature in programming mode */
  #define MTYPE_OSCCAL_BYTE 0xB5	/* osccal cells in programming mode */
  #define MTYPE_CAN 0xB6		/* CAN mailbox */
! #define MTYPE_FLASH 0xc0	/* xmega flash */
! #define MTYPE_BOOTFLASH 0xc1	/* xmega boot flash */
! #define MTYPE_USERSIG 0xc5	/* xmega user signature */
! #define MTYPE_PRODSIG 0xc6	/* xmega production signature */
  
  /* (some) ICE parameters, for CMND_{GET,SET}_PARAMETER */
  #define PAR_HW_VERSION 0x01
