Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
jtag3.c File Reference
#include "ac_cfg.h"
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "crc16.h"
#include "jtag3.h"
#include "jtag3_private.h"
#include "usbdevs.h"
+ Include dependency graph for jtag3.c:

Go to the source code of this file.

Classes

struct  pdata
 

Macros

#define PDATA(pgm)   ((struct pdata *)(pgm->cookie))
 
#define PGM_FL_IS_DW   (0x0001)
 
#define PGM_FL_IS_PDI   (0x0002)
 
#define PGM_FL_IS_JTAG   (0x0004)
 
#define PGM_FL_IS_EDBG   (0x0008)
 

Functions

static int jtag3_open (PROGRAMMER *pgm, char *port)
 
static int jtag3_edbg_prepare (PROGRAMMER *pgm)
 
static int jtag3_edbg_signoff (PROGRAMMER *pgm)
 
static int jtag3_edbg_send (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static int jtag3_edbg_recv_frame (PROGRAMMER *pgm, unsigned char **msg)
 
static int jtag3_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static int jtag3_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static int jtag3_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static int jtag3_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static int jtag3_set_sck_period (PROGRAMMER *pgm, double v)
 
static void jtag3_print_parms1 (PROGRAMMER *pgm, const char *p)
 
static int jtag3_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static unsigned char jtag3_memtype (PROGRAMMER *pgm, AVRPART *p, unsigned long addr)
 
static unsigned int jtag3_memaddr (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr)
 
void jtag3_setup (PROGRAMMER *pgm)
 
void jtag3_teardown (PROGRAMMER *pgm)
 
static unsigned long b4_to_u32 (unsigned char *b)
 
static void u32_to_b4 (unsigned char *b, unsigned long l)
 
static unsigned short b2_to_u16 (unsigned char *b)
 
static void u16_to_b2 (unsigned char *b, unsigned short l)
 
static void jtag3_print_data (unsigned char *b, size_t s)
 
static void jtag3_prmsg (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static void jtag3_prevent (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
int jtag3_send (PROGRAMMER *pgm, unsigned char *data, size_t len)
 
static int jtag3_drain (PROGRAMMER *pgm, int display)
 
static int jtag3_recv_frame (PROGRAMMER *pgm, unsigned char **msg)
 
int jtag3_recv (PROGRAMMER *pgm, unsigned char **msg)
 
int jtag3_command (PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, unsigned char **resp, const char *descr)
 
int jtag3_getsync (PROGRAMMER *pgm, int mode)
 
static int jtag3_chip_erase_dw (PROGRAMMER *pgm, AVRPART *p)
 
static int jtag3_program_enable_dummy (PROGRAMMER *pgm, AVRPART *p)
 
static int jtag3_program_enable (PROGRAMMER *pgm)
 
static int jtag3_program_disable (PROGRAMMER *pgm)
 
static int jtag3_set_sck_xmega_pdi (PROGRAMMER *pgm, unsigned char *clk)
 
static int jtag3_set_sck_xmega_jtag (PROGRAMMER *pgm, unsigned char *clk)
 
static int jtag3_set_sck_mega_jtag (PROGRAMMER *pgm, unsigned char *clk)
 
static void jtag3_disable (PROGRAMMER *pgm)
 
static void jtag3_enable (PROGRAMMER *pgm)
 
static int jtag3_parseextparms (PROGRAMMER *pgm, LISTID extparms)
 
int jtag3_open_common (PROGRAMMER *pgm, char *port)
 
static int jtag3_open_dw (PROGRAMMER *pgm, char *port)
 
static int jtag3_open_pdi (PROGRAMMER *pgm, char *port)
 
void jtag3_close (PROGRAMMER *pgm)
 
static int jtag3_page_erase (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
 
static int jtag3_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
int jtag3_getparm (PROGRAMMER *pgm, unsigned char scope, unsigned char section, unsigned char parm, unsigned char *value, unsigned char length)
 
int jtag3_setparm (PROGRAMMER *pgm, unsigned char scope, unsigned char section, unsigned char parm, unsigned char *value, unsigned char length)
 
static void jtag3_display (PROGRAMMER *pgm, const char *p)
 
static void jtag3_print_parms (PROGRAMMER *pgm)
 
void jtag3_initpgm (PROGRAMMER *pgm)
 
void jtag3_dw_initpgm (PROGRAMMER *pgm)
 
void jtag3_pdi_initpgm (PROGRAMMER *pgm)
 

Variables

const char jtag3_desc [] = "Atmel JTAGICE3"
 
const char jtag3_dw_desc [] = "Atmel JTAGICE3 in debugWire mode"
 
const char jtag3_pdi_desc [] = "Atmel JTAGICE3 in PDI mode"
 

Macro Definition Documentation

◆ PDATA

#define PDATA (   pgm)    ((struct pdata *)(pgm->cookie))

◆ PGM_FL_IS_DW

#define PGM_FL_IS_DW   (0x0001)

◆ PGM_FL_IS_EDBG

#define PGM_FL_IS_EDBG   (0x0008)

◆ PGM_FL_IS_JTAG

#define PGM_FL_IS_JTAG   (0x0004)

◆ PGM_FL_IS_PDI

#define PGM_FL_IS_PDI   (0x0002)

Function Documentation

◆ b2_to_u16()

static unsigned short b2_to_u16 ( unsigned char *  b)
static
148{
149 unsigned short l;
150 l = b[0];
151 l += (unsigned)b[1] << 8;
152
153 return l;
154}

Referenced by jtag3_print_parms1().

+ Here is the caller graph for this function:

◆ b4_to_u32()

static unsigned long b4_to_u32 ( unsigned char *  b)
static
127{
128 unsigned long l;
129 l = b[0];
130 l += (unsigned)b[1] << 8;
131 l += (unsigned)b[2] << 16;
132 l += (unsigned)b[3] << 24;
133
134 return l;
135}

Referenced by jtag3_prevent().

+ Here is the caller graph for this function:

◆ jtag3_chip_erase()

static int jtag3_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
881{
882 unsigned char buf[8], *resp;
883
884 buf[0] = SCOPE_AVR;
885 buf[1] = CMD3_ERASE_MEMORY;
886 buf[2] = 0;
887 buf[3] = XMEGA_ERASE_CHIP;
888 buf[4] = buf[5] = buf[6] = buf[7] = 0; /* page address */
889
890 if (jtag3_command(pgm, buf, 8, &resp, "chip erase") < 0)
891 return -1;
892
893 free(resp);
894 return 0;
895}
void free(void *)
int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, unsigned char **resp, const char *descr)
Definition jtag3.c:816
#define CMD3_ERASE_MEMORY
Definition jtag3_private.h:124
#define XMEGA_ERASE_CHIP
Definition jtag3_private.h:207
#define SCOPE_AVR
Definition jtag3_private.h:98
static PROGRAMMER * pgm
Definition main.c:192

References CMD3_ERASE_MEMORY, free(), jtag3_command(), pgm, SCOPE_AVR, and XMEGA_ERASE_CHIP.

Referenced by jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_chip_erase_dw()

static int jtag3_chip_erase_dw ( PROGRAMMER pgm,
AVRPART p 
)
static
901{
902
903 avrdude_message(MSG_INFO, "%s: Chip erase not supported in debugWire mode\n",
904 progname);
905
906 return 0;
907}
#define MSG_INFO
Definition avrdude.h:51
char * progname
Definition main.c:61
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93

References avrdude_message(), MSG_INFO, and progname.

Referenced by jtag3_dw_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_close()

void jtag3_close ( PROGRAMMER pgm)
1448{
1449 unsigned char buf[4], *resp;
1450
1451 avrdude_message(MSG_NOTICE2, "%s: jtag3_close()\n", progname);
1452
1453 buf[0] = SCOPE_AVR;
1454 buf[1] = CMD3_SIGN_OFF;
1455 buf[2] = buf[3] = 0;
1456
1457 if (jtag3_command(pgm, buf, 3, &resp, "AVR sign-off") >= 0)
1458 free(resp);
1459
1460 buf[0] = SCOPE_GENERAL;
1461 buf[1] = CMD3_SIGN_OFF;
1462
1463 if (jtag3_command(pgm, buf, 4, &resp, "sign-off") >= 0)
1464 free(resp);
1465
1466 if (pgm->flag & PGM_FL_IS_EDBG)
1468
1469 serial_close(&pgm->fd);
1470 pgm->fd.ifd = -1;
1471}
#define MSG_NOTICE2
Definition avrdude.h:53
static int jtag3_edbg_signoff(PROGRAMMER *pgm)
Definition jtag3.c:575
#define PGM_FL_IS_EDBG
Definition jtag3.c:86
#define SCOPE_GENERAL
Definition jtag3_private.h:96
#define CMD3_SIGN_OFF
Definition jtag3_private.h:111
#define serial_close
Definition libavrdude.h:576
int ifd
Definition libavrdude.h:522
char flag
Definition libavrdude.h:690
union filedescriptor fd
Definition libavrdude.h:637

References avrdude_message(), CMD3_SIGN_OFF, programmer_t::fd, programmer_t::flag, free(), filedescriptor::ifd, jtag3_command(), jtag3_edbg_signoff(), MSG_NOTICE2, pgm, PGM_FL_IS_EDBG, progname, SCOPE_AVR, SCOPE_GENERAL, and serial_close.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_command()

int jtag3_command ( PROGRAMMER pgm,
unsigned char *  cmd,
unsigned int  cmdlen,
unsigned char **  resp,
const char *  descr 
)
818{
819 int status;
820 unsigned char c;
821
822 avrdude_message(MSG_NOTICE2, "%s: Sending %s command: ",
823 progname, descr);
824 jtag3_send(pgm, cmd, cmdlen);
825
826 status = jtag3_recv(pgm, resp);
827 if (status <= 0) {
828 if (verbose >= 2)
829 putc('\n', stderr);
830 avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n",
831 progname, descr, status);
832 return -1;
833 } else if (verbose >= 3) {
834 putc('\n', stderr);
835 jtag3_prmsg(pgm, *resp, status);
836 } else {
837 avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status);
838 }
839
840 c = (*resp)[1];
841 if ((c & RSP3_STATUS_MASK) != RSP3_OK) {
842 avrdude_message(MSG_INFO, "%s: bad response to %s command: 0x%02x\n",
843 progname, descr, c);
844 free(*resp);
845 resp = 0;
846 return -1;
847 }
848
849 return status;
850}
int verbose
Definition main.c:198
int jtag3_send(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition jtag3.c:401
int jtag3_recv(PROGRAMMER *pgm, unsigned char **msg)
Definition jtag3.c:774
static void jtag3_prmsg(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition jtag3.c:181
#define RSP3_OK
Definition jtag3_private.h:130
#define RSP3_STATUS_MASK
Definition jtag3_private.h:136
struct command cmd[]
Definition term.c:94

References avrdude_message(), cmd, free(), jtag3_prmsg(), jtag3_recv(), jtag3_send(), MSG_INFO, MSG_NOTICE2, pgm, progname, RSP3_OK, RSP3_STATUS_MASK, and verbose.

Referenced by jtag3_chip_erase(), jtag3_close(), jtag3_display(), jtag3_getparm(), jtag3_getsync(), jtag3_initialize(), jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_program_disable(), jtag3_program_enable(), jtag3_read_byte(), jtag3_setparm(), and jtag3_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_disable()

static void jtag3_disable ( PROGRAMMER pgm)
static
1253{
1254
1255 free(PDATA(pgm)->flash_pagecache);
1256 PDATA(pgm)->flash_pagecache = NULL;
1257 free(PDATA(pgm)->eeprom_pagecache);
1258 PDATA(pgm)->eeprom_pagecache = NULL;
1259
1260 /*
1261 * jtag3_program_disable() doesn't do anything if the
1262 * device is currently not in programming mode, so just
1263 * call it unconditionally here.
1264 */
1266}
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
static int jtag3_program_disable(PROGRAMMER *pgm)
Definition jtag3.c:935
#define PDATA(pgm)
Definition jtag3.c:77

References free(), jtag3_program_disable(), PDATA, pgm, and void().

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_display()

static void jtag3_display ( PROGRAMMER pgm,
const char *  p 
)
static
2074{
2075 unsigned char parms[5];
2076 unsigned char cmd[4], *resp, c;
2077 int status;
2078
2079 /*
2080 * Ask for:
2081 * PARM3_HW_VER (1 byte)
2082 * PARM3_FW_MAJOR (1 byte)
2083 * PARM3_FW_MINOR (1 byte)
2084 * PARM3_FW_RELEASE (2 bytes)
2085 */
2086 if (jtag3_getparm(pgm, SCOPE_GENERAL, 0, PARM3_HW_VER, parms, 5) < 0)
2087 return;
2088
2089 cmd[0] = SCOPE_INFO;
2090 cmd[1] = CMD3_GET_INFO;
2091 cmd[2] = 0;
2092 cmd[3] = CMD3_INFO_SERIAL;
2093
2094 if ((status = jtag3_command(pgm, cmd, 4, &resp, "get info (serial number)")) < 0)
2095 return;
2096
2097 c = resp[1];
2098 if (c != RSP3_INFO) {
2099 avrdude_message(MSG_INFO, "%s: jtag3_display(): response is not RSP3_INFO\n",
2100 progname);
2101 free(resp);
2102 return;
2103 }
2104 memmove(resp, resp + 3, status - 3);
2105 resp[status - 3] = 0;
2106
2107 avrdude_message(MSG_INFO, "%sICE hardware version: %d\n", p, parms[0]);
2108 avrdude_message(MSG_INFO, "%sICE firmware version: %d.%02d (rel. %d)\n", p,
2109 parms[1], parms[2],
2110 (parms[3] | (parms[4] << 8)));
2111 avrdude_message(MSG_INFO, "%sSerial number : %s\n", p, resp);
2112 free(resp);
2113
2115}
static void jtag3_print_parms1(PROGRAMMER *pgm, const char *p)
Definition jtag3.c:2118
int jtag3_getparm(PROGRAMMER *pgm, unsigned char scope, unsigned char section, unsigned char parm, unsigned char *value, unsigned char length)
Definition jtag3.c:1993
#define CMD3_GET_INFO
Definition jtag3_private.h:101
#define PARM3_HW_VER
Definition jtag3_private.h:174
#define SCOPE_INFO
Definition jtag3_private.h:95
#define RSP3_INFO
Definition jtag3_private.h:131
#define CMD3_INFO_SERIAL
Definition jtag3_private.h:105

References avrdude_message(), cmd, CMD3_GET_INFO, CMD3_INFO_SERIAL, free(), jtag3_command(), jtag3_getparm(), jtag3_print_parms1(), MSG_INFO, PARM3_HW_VER, pgm, progname, RSP3_INFO, SCOPE_GENERAL, and SCOPE_INFO.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_drain()

static int jtag3_drain ( PROGRAMMER pgm,
int  display 
)
static
628{
629 return serial_drain(&pgm->fd, display);
630}
#define serial_drain
Definition libavrdude.h:579

References programmer_t::fd, pgm, and serial_drain.

Referenced by jtag3_open_common().

+ Here is the caller graph for this function:

◆ jtag3_dw_initpgm()

void jtag3_dw_initpgm ( PROGRAMMER pgm)
2224{
2225 strcpy(pgm->type, "JTAGICE3_DW");
2226
2227 /*
2228 * mandatory functions
2229 */
2240
2241 /*
2242 * optional functions
2243 */
2249 pgm->page_size = 256;
2251}
static void jtag3_display(PROGRAMMER *pgm, const char *p)
Definition jtag3.c:2073
static void jtag3_enable(PROGRAMMER *pgm)
Definition jtag3.c:1268
static int jtag3_open_dw(PROGRAMMER *pgm, char *port)
Definition jtag3.c:1420
static int jtag3_program_enable_dummy(PROGRAMMER *pgm, AVRPART *p)
Definition jtag3.c:909
static void jtag3_print_parms(PROGRAMMER *pgm)
Definition jtag3.c:2149
void jtag3_close(PROGRAMMER *pgm)
Definition jtag3.c:1447
static int jtag3_chip_erase_dw(PROGRAMMER *pgm, AVRPART *p)
Definition jtag3.c:900
static int jtag3_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition jtag3.c:1622
#define PGM_FL_IS_DW
Definition jtag3.c:83
static int jtag3_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition jtag3.c:1700
void jtag3_setup(PROGRAMMER *pgm)
Definition jtag3.c:109
static int jtag3_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition jtag3.c:1518
void jtag3_teardown(PROGRAMMER *pgm)
Definition jtag3.c:119
static int jtag3_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition jtag3.c:1855
static void jtag3_disable(PROGRAMMER *pgm)
Definition jtag3.c:1252
static int jtag3_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition jtag3.c:975
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
void(* print_parms)(struct programmer_t *pgm)
Definition libavrdude.h:673
char type[PGM_TYPELEN]
Definition libavrdude.h:619
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646
int page_size
Definition libavrdude.h:638

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::flag, programmer_t::initialize, jtag3_chip_erase_dw(), jtag3_close(), jtag3_disable(), jtag3_display(), jtag3_enable(), jtag3_initialize(), jtag3_open_dw(), jtag3_paged_load(), jtag3_paged_write(), jtag3_print_parms(), jtag3_program_enable_dummy(), jtag3_read_byte(), jtag3_setup(), jtag3_teardown(), jtag3_write_byte(), programmer_t::open, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, PGM_FL_IS_DW, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::setup, programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ jtag3_edbg_prepare()

static int jtag3_edbg_prepare ( PROGRAMMER pgm)
static
518{
519 unsigned char buf[USBDEV_MAX_XFER_3];
520 unsigned char status[USBDEV_MAX_XFER_3];
521 int rv;
522
523 avrdude_message(MSG_DEBUG, "\n%s: jtag3_edbg_prepare()\n",
524 progname);
525
526 if (verbose >= 4)
527 memset(buf, 0, USBDEV_MAX_XFER_3);
528
529 buf[0] = CMSISDAP_CMD_CONNECT;
530 buf[1] = CMSISDAP_CONN_SWD;
531 if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
532 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
533 progname);
534 return -1;
535 }
536 rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
537 if (rv != pgm->fd.usb.max_xfer) {
538 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
539 progname, rv);
540 return -1;
541 }
542 if (status[0] != CMSISDAP_CMD_CONNECT ||
543 status[1] == 0)
544 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
545 progname, status[0], status[1]);
546 avrdude_message(MSG_NOTICE2, "%s: jtag3_edbg_prepare(): connection status 0x%02x\n",
547 progname, status[1]);
548
549 buf[0] = CMSISDAP_CMD_LED;
550 buf[1] = CMSISDAP_LED_CONNECT;
551 buf[2] = 1;
552 if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
553 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): failed to send command to serial port\n",
554 progname);
555 return -1;
556 }
557 rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
558 if (rv != pgm->fd.usb.max_xfer) {
559 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): failed to read from serial port (%d)\n",
560 progname, rv);
561 return -1;
562 }
563 if (status[0] != CMSISDAP_CMD_LED ||
564 status[1] != 0)
565 avrdude_message(MSG_INFO, "%s: jtag3_edbg_prepare(): unexpected response 0x%02x, 0x%02x\n",
566 progname, status[0], status[1]);
567
568 return 0;
569}
#define MSG_DEBUG
Definition avrdude.h:54
#define CMSISDAP_CMD_CONNECT
Definition jtag3_private.h:237
#define CMSISDAP_CMD_LED
Definition jtag3_private.h:233
#define CMSISDAP_CONN_SWD
Definition jtag3_private.h:239
#define CMSISDAP_LED_CONNECT
Definition jtag3_private.h:234
struct filedescriptor::@12 usb
#define serial_send
Definition libavrdude.h:577
#define serial_recv
Definition libavrdude.h:578
#define USBDEV_MAX_XFER_3
Definition usbdevs.h:72

References avrdude_message(), CMSISDAP_CMD_CONNECT, CMSISDAP_CMD_LED, CMSISDAP_CONN_SWD, CMSISDAP_LED_CONNECT, programmer_t::fd, MSG_DEBUG, MSG_INFO, MSG_NOTICE2, pgm, progname, serial_recv, serial_send, filedescriptor::usb, USBDEV_MAX_XFER_3, and verbose.

Referenced by jtag3_getsync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_edbg_recv_frame()

static int jtag3_edbg_recv_frame ( PROGRAMMER pgm,
unsigned char **  msg 
)
static
673 {
674 int rv, len = 0;
675 unsigned char *buf = NULL;
676 unsigned char *request;
677
678 avrdude_message(MSG_TRACE, "%s: jtag3_edbg_recv():\n", progname);
679
680 if ((buf = malloc(USBDEV_MAX_XFER_3)) == NULL) {
681 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): out of memory\n",
682 progname);
683 return -1;
684 }
685 if ((request = malloc(pgm->fd.usb.max_xfer)) == NULL) {
686 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): out of memory\n",
687 progname);
688 free(buf);
689 return -1;
690 }
691
692 *msg = buf;
693
694 int nfrags = 0;
695 int thisfrag = 0;
696
697 do {
698 request[0] = EDBG_VENDOR_AVR_RSP;
699
700 if (serial_send(&pgm->fd, request, pgm->fd.usb.max_xfer) != 0) {
701 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): error sending CMSIS-DAP vendor command\n",
702 progname);
703 free(request);
704 free(*msg);
705 return -1;
706 }
707
708 rv = serial_recv(&pgm->fd, buf, pgm->fd.usb.max_xfer);
709
710 if (rv < 0) {
711 /* timeout in receive */
712 avrdude_message(MSG_NOTICE2, "%s: jtag3_edbg_recv(): Timeout receiving packet\n",
713 progname);
714 free(*msg);
715 free(request);
716 return -1;
717 }
718
719 if (buf[0] != EDBG_VENDOR_AVR_RSP) {
720 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Unexpected response 0x%02x\n",
721 progname, buf[0]);
722 free(*msg);
723 free(request);
724 return -1;
725 }
726
727 /* calculate fragment information */
728 if (thisfrag == 0) {
729 /* first fragment */
730 nfrags = buf[1] & 0x0F;
731 thisfrag = 1;
732 } else {
733 if (nfrags != (buf[1] & 0x0F)) {
735 "%s: jtag3_edbg_recv(): "
736 "Inconsistent # of fragments; had %d, now %d\n",
737 progname, nfrags, (buf[1] & 0x0F));
738 free(*msg);
739 free(request);
740 return -1;
741 }
742 }
743 if (thisfrag != ((buf[1] >> 4) & 0x0F)) {
745 "%s: jtag3_edbg_recv(): "
746 "Inconsistent fragment number; expect %d, got %d\n",
747 progname, thisfrag, ((buf[1] >> 4) & 0x0F));
748 free(*msg);
749 free(request);
750 return -1;
751 }
752
753 int thislen = (buf[2] << 8) | buf[3];
754 if (thislen > rv + 4) {
755 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Unexpected length value (%d > %d)\n",
756 progname, thislen, rv + 4);
757 thislen = rv + 4;
758 }
759 if (len + thislen > USBDEV_MAX_XFER_3) {
760 avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Length exceeds max size (%d > %d)\n",
761 progname, len + thislen, USBDEV_MAX_XFER_3);
762 thislen = USBDEV_MAX_XFER_3 - len;
763 }
764 memmove(buf, buf + 4, thislen);
765 thisfrag++;
766 len += thislen;
767 buf += thislen;
768 } while (thisfrag <= nfrags);
769
770 free(request);
771 return len;
772}
#define MSG_TRACE
Definition avrdude.h:55
void * malloc(YYSIZE_T)
#define EDBG_VENDOR_AVR_RSP
Definition jtag3_private.h:218

References avrdude_message(), EDBG_VENDOR_AVR_RSP, programmer_t::fd, free(), malloc(), MSG_INFO, MSG_NOTICE2, MSG_TRACE, pgm, progname, serial_recv, serial_send, filedescriptor::usb, and USBDEV_MAX_XFER_3.

Referenced by jtag3_recv_frame().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_edbg_send()

static int jtag3_edbg_send ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
435{
436 unsigned char buf[USBDEV_MAX_XFER_3];
437 unsigned char status[USBDEV_MAX_XFER_3];
438 int rv;
439
440 if (verbose >= 4)
441 {
442 memset(buf, 0, USBDEV_MAX_XFER_3);
443 memset(status, 0, USBDEV_MAX_XFER_3);
444 }
445
446 avrdude_message(MSG_DEBUG, "\n%s: jtag3_edbg_send(): sending %lu bytes\n",
447 progname, (unsigned long)len);
448
449 /* 4 bytes overhead for CMD, fragment #, and length info */
450 int max_xfer = pgm->fd.usb.max_xfer;
451 int nfragments = (len + max_xfer - 1) / max_xfer;
452 if (nfragments > 1)
453 {
454 avrdude_message(MSG_DEBUG, "%s: jtag3_edbg_send(): fragmenting into %d packets\n",
455 progname, nfragments);
456 }
457 int frag;
458 for (frag = 0; frag < nfragments; frag++)
459 {
460 int this_len;
461
462 /* All fragments have the (CMSIS-DAP layer) CMD, the fragment
463 * identifier, and the length field. */
464 buf[0] = EDBG_VENDOR_AVR_CMD;
465 buf[1] = ((frag + 1) << 4) | nfragments;
466
467 if (frag == 0)
468 {
469 /* Only first fragment has TOKEN and seq#, thus four bytes
470 * less payload than subsequent fragments. */
471 this_len = len < max_xfer - 8? len: max_xfer - 8;
472 buf[2] = (this_len + 4) >> 8;
473 buf[3] = (this_len + 4) & 0xff;
474 buf[4] = TOKEN;
475 buf[5] = 0; /* dummy */
476 u16_to_b2(buf + 6, PDATA(pgm)->command_sequence);
477 memcpy(buf + 8, data, this_len);
478 }
479 else
480 {
481 this_len = len < max_xfer - 4? len: max_xfer - 4;
482 buf[2] = (this_len) >> 8;
483 buf[3] = (this_len) & 0xff;
484 memcpy(buf + 4, data, this_len);
485 }
486
487 if (serial_send(&pgm->fd, buf, max_xfer) != 0) {
488 avrdude_message(MSG_INFO, "%s: jtag3_edbg_send(): failed to send command to serial port\n",
489 progname);
490 return -1;
491 }
492 rv = serial_recv(&pgm->fd, status, max_xfer);
493
494 if (rv < 0) {
495 /* timeout in receive */
496 avrdude_message(MSG_NOTICE2, "%s: jtag3_edbg_send(): Timeout receiving packet\n",
497 progname);
498 return -1;
499 }
500 if (status[0] != EDBG_VENDOR_AVR_CMD ||
501 (frag == nfragments - 1 && status[1] != 0x01))
502 {
503 /* what to do in this case? */
504 avrdude_message(MSG_INFO, "%s: jtag3_edbg_send(): Unexpected response 0x%02x, 0x%02x\n",
505 progname, status[0], status[1]);
506 }
507 data += this_len;
508 len -= this_len;
509 }
510
511 return 0;
512}
static void u16_to_b2(unsigned char *b, unsigned short l)
Definition jtag3.c:157
#define TOKEN
Definition jtag3_private.h:91
#define EDBG_VENDOR_AVR_CMD
Definition jtag3_private.h:217
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References avrdude_message(), EDBG_VENDOR_AVR_CMD, programmer_t::fd, MSG_DEBUG, MSG_INFO, MSG_NOTICE2, PDATA, pgm, progname, serial_recv, serial_send, TOKEN, u16_to_b2(), filedescriptor::usb, USBDEV_MAX_XFER_3, and verbose.

Referenced by jtag3_send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_edbg_signoff()

static int jtag3_edbg_signoff ( PROGRAMMER pgm)
static
576{
577 unsigned char buf[USBDEV_MAX_XFER_3];
578 unsigned char status[USBDEV_MAX_XFER_3];
579 int rv;
580
581 avrdude_message(MSG_DEBUG, "\n%s: jtag3_edbg_signoff()\n",
582 progname);
583
584 if (verbose >= 4)
585 memset(buf, 0, USBDEV_MAX_XFER_3);
586
587 buf[0] = CMSISDAP_CMD_LED;
588 buf[1] = CMSISDAP_LED_CONNECT;
589 buf[2] = 0;
590 if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
591 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
592 progname);
593 return -1;
594 }
595 rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
596 if (rv != pgm->fd.usb.max_xfer) {
597 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
598 progname, rv);
599 return -1;
600 }
601 if (status[0] != CMSISDAP_CMD_LED ||
602 status[1] != 0)
603 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
604 progname, status[0], status[1]);
605
607 if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
608 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
609 progname);
610 return -1;
611 }
612 rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
613 if (rv != pgm->fd.usb.max_xfer) {
614 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
615 progname, rv);
616 return -1;
617 }
618 if (status[0] != CMSISDAP_CMD_DISCONNECT ||
619 status[1] != 0)
620 avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
621 progname, status[0], status[1]);
622
623 return 0;
624}
#define CMSISDAP_CMD_DISCONNECT
Definition jtag3_private.h:242

References avrdude_message(), CMSISDAP_CMD_DISCONNECT, CMSISDAP_CMD_LED, CMSISDAP_LED_CONNECT, programmer_t::fd, MSG_DEBUG, MSG_INFO, pgm, progname, serial_recv, serial_send, filedescriptor::usb, USBDEV_MAX_XFER_3, and verbose.

Referenced by jtag3_close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_enable()

static void jtag3_enable ( PROGRAMMER pgm)
static
1269{
1270 return;
1271}

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the caller graph for this function:

◆ jtag3_getparm()

int jtag3_getparm ( PROGRAMMER pgm,
unsigned char  scope,
unsigned char  section,
unsigned char  parm,
unsigned char *  value,
unsigned char  length 
)
1996{
1997 int status;
1998 unsigned char buf[6], *resp, c;
1999 char descr[60];
2000
2001 avrdude_message(MSG_NOTICE2, "%s: jtag3_getparm()\n", progname);
2002
2003 buf[0] = scope;
2004 buf[1] = CMD3_GET_PARAMETER;
2005 buf[2] = 0;
2006 buf[3] = section;
2007 buf[4] = parm;
2008 buf[5] = length;
2009
2010 sprintf(descr, "get parameter (scope 0x%02x, section %d, parm %d)",
2011 scope, section, parm);
2012
2013 if ((status = jtag3_command(pgm, buf, 6, &resp, descr)) < 0)
2014 return -1;
2015
2016 c = resp[1];
2017 if (c != RSP3_DATA || status < 3) {
2018 avrdude_message(MSG_INFO, "%s: jtag3_getparm(): "
2019 "bad response to %s\n",
2020 progname, descr);
2021 free(resp);
2022 return -1;
2023 }
2024
2025 status -= 3;
2026 memcpy(value, resp + 3, (length < status? length: status));
2027 free(resp);
2028
2029 return 0;
2030}
#define RSP3_DATA
Definition jtag3_private.h:133
#define CMD3_GET_PARAMETER
Definition jtag3_private.h:109
double length(std::vector< SurfacePoint > &path)
Definition exact_geodesic.cpp:1682

References avrdude_message(), CMD3_GET_PARAMETER, free(), jtag3_command(), MSG_INFO, MSG_NOTICE2, pgm, progname, and RSP3_DATA.

Referenced by jtag3_display(), jtag3_initialize(), and jtag3_print_parms1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_getsync()

int jtag3_getsync ( PROGRAMMER pgm,
int  mode 
)
853 {
854
855 unsigned char buf[3], *resp;
856
857 avrdude_message(MSG_DEBUG, "%s: jtag3_getsync()\n", progname);
858
859 if (pgm->flag & PGM_FL_IS_EDBG) {
860 if (jtag3_edbg_prepare(pgm) < 0)
861 return -1;
862 }
863
864 /* Get the sign-on information. */
865 buf[0] = SCOPE_GENERAL;
866 buf[1] = CMD3_SIGN_ON;
867 buf[2] = 0;
868
869 if (jtag3_command(pgm, buf, 3, &resp, "sign-on") < 0)
870 return -1;
871
872 free(resp);
873
874 return 0;
875}
static int jtag3_edbg_prepare(PROGRAMMER *pgm)
Definition jtag3.c:517
#define CMD3_SIGN_ON
Definition jtag3_private.h:110

References avrdude_message(), CMD3_SIGN_ON, programmer_t::flag, free(), jtag3_command(), jtag3_edbg_prepare(), MSG_DEBUG, pgm, PGM_FL_IS_EDBG, progname, and SCOPE_GENERAL.

Referenced by jtag3_open(), jtag3_open_dw(), and jtag3_open_pdi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_initialize()

static int jtag3_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
976{
977 unsigned char conn = 0, parm[4];
978 const char *ifname;
979 unsigned char cmd[4], *resp;
980 int status;
981
982 /*
983 * At least, as of firmware 2.12, the JTAGICE3 doesn't handle
984 * splitting packets correctly. On a large transfer, the first
985 * split packets are correct, but remaining packets contain just
986 * garbage.
987 *
988 * We move the check here so in case future firmware versions fix
989 * this, the check below can be made dependended on the actual
990 * firmware level. Retrieving the firmware version can always be
991 * accomplished with USB 1.1 (64 byte max) packets.
992 *
993 * Allow to override the check by -F (so users could try on newer
994 * firmware), but warn loudly.
995 */
996 if (jtag3_getparm(pgm, SCOPE_GENERAL, 0, PARM3_FW_MAJOR, parm, 2) < 0)
997 return -1;
998 if (pgm->fd.usb.max_xfer < USBDEV_MAX_XFER_3 && (pgm->flag & PGM_FL_IS_EDBG) == 0) {
999 avrdude_message(MSG_INFO, "%s: the JTAGICE3's firmware %d.%d is broken on USB 1.1 connections, sorry\n",
1000 progname, parm[0], parm[1]);
1001 if (ovsigck) {
1002 avrdude_message(MSG_INFO, "%s: forced to continue by option -F; THIS PUTS THE DEVICE'S DATA INTEGRITY AT RISK!\n",
1003 progname);
1004 } else {
1005 return -1;
1006 }
1007 }
1008
1009 if (pgm->flag & PGM_FL_IS_DW) {
1010 ifname = "debugWire";
1011 if (p->flags & AVRPART_HAS_DW)
1012 conn = PARM3_CONN_DW;
1013 } else if (pgm->flag & PGM_FL_IS_PDI) {
1014 ifname = "PDI";
1015 if (p->flags & AVRPART_HAS_PDI)
1016 conn = PARM3_CONN_PDI;
1017 } else {
1018 ifname = "JTAG";
1019 if (p->flags & AVRPART_HAS_JTAG)
1020 conn = PARM3_CONN_JTAG;
1021 }
1022
1023 if (conn == 0) {
1024 avrdude_message(MSG_INFO, "%s: jtag3_initialize(): part %s has no %s interface\n",
1025 progname, p->desc, ifname);
1026 return -1;
1027 }
1028
1029 if (p->flags & AVRPART_HAS_PDI)
1030 parm[0] = PARM3_ARCH_XMEGA;
1031 else if (p->flags & AVRPART_HAS_DW)
1032 parm[0] = PARM3_ARCH_TINY;
1033 else
1034 parm[0] = PARM3_ARCH_MEGA;
1035 if (jtag3_setparm(pgm, SCOPE_AVR, 0, PARM3_ARCH, parm, 1) < 0)
1036 return -1;
1037
1038 parm[0] = PARM3_SESS_PROGRAMMING;
1039 if (jtag3_setparm(pgm, SCOPE_AVR, 0, PARM3_SESS_PURPOSE, parm, 1) < 0)
1040 return -1;
1041
1042 parm[0] = conn;
1043 if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CONNECTION, parm, 1) < 0)
1044 return -1;
1045
1046 if (conn == PARM3_CONN_PDI)
1047 PDATA(pgm)->set_sck = jtag3_set_sck_xmega_pdi;
1048 else if (conn == PARM3_CONN_JTAG) {
1049 if (p->flags & AVRPART_HAS_PDI)
1051 else
1052 PDATA(pgm)->set_sck = jtag3_set_sck_mega_jtag;
1053 }
1054 if (pgm->bitclock != 0.0 && PDATA(pgm)->set_sck != NULL)
1055 {
1056 unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */
1057 avrdude_message(MSG_NOTICE2, "%s: jtag3_initialize(): "
1058 "trying to set JTAG clock to %u kHz\n",
1059 progname, clock);
1060 parm[0] = clock & 0xff;
1061 parm[1] = (clock >> 8) & 0xff;
1062 if (PDATA(pgm)->set_sck(pgm, parm) < 0)
1063 return -1;
1064 }
1065
1066 if (conn == PARM3_CONN_JTAG)
1067 {
1068 avrdude_message(MSG_NOTICE2, "%s: jtag3_initialize(): "
1069 "trying to set JTAG daisy-chain info to %d,%d,%d,%d\n",
1070 progname,
1071 PDATA(pgm)->jtagchain[0], PDATA(pgm)->jtagchain[1],
1072 PDATA(pgm)->jtagchain[2], PDATA(pgm)->jtagchain[3]);
1073 if (jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_JTAGCHAIN, PDATA(pgm)->jtagchain, 4) < 0)
1074 return -1;
1075 }
1076
1077 /* set device descriptor data */
1078 if ((p->flags & AVRPART_HAS_PDI))
1079 {
1080 struct xmega_device_desc xd;
1081 LNODEID ln;
1082 AVRMEM * m;
1083
1084 u16_to_b2(xd.nvm_base_addr, p->nvm_base);
1085 u16_to_b2(xd.mcu_base_addr, p->mcu_base);
1086
1087 for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
1088 m = ldata(ln);
1089 if (strcmp(m->desc, "flash") == 0) {
1090 if (m->readsize != 0 && m->readsize < m->page_size)
1091 PDATA(pgm)->flash_pagesize = m->readsize;
1092 else
1093 PDATA(pgm)->flash_pagesize = m->page_size;
1094 u16_to_b2(xd.flash_page_size, m->page_size);
1095 } else if (strcmp(m->desc, "eeprom") == 0) {
1096 PDATA(pgm)->eeprom_pagesize = m->page_size;
1097 xd.eeprom_page_size = m->page_size;
1098 u16_to_b2(xd.eeprom_size, m->size);
1099 u32_to_b4(xd.nvm_eeprom_offset, m->offset);
1100 } else if (strcmp(m->desc, "application") == 0) {
1101 u32_to_b4(xd.app_size, m->size);
1102 u32_to_b4(xd.nvm_app_offset, m->offset);
1103 } else if (strcmp(m->desc, "boot") == 0) {
1104 u16_to_b2(xd.boot_size, m->size);
1105 u32_to_b4(xd.nvm_boot_offset, m->offset);
1106 } else if (strcmp(m->desc, "fuse1") == 0) {
1107 u32_to_b4(xd.nvm_fuse_offset, m->offset & ~7);
1108 } else if (strncmp(m->desc, "lock", 4) == 0) {
1109 u32_to_b4(xd.nvm_lock_offset, m->offset);
1110 } else if (strcmp(m->desc, "usersig") == 0) {
1111 u32_to_b4(xd.nvm_user_sig_offset, m->offset);
1112 } else if (strcmp(m->desc, "prodsig") == 0) {
1113 u32_to_b4(xd.nvm_prod_sig_offset, m->offset);
1114 } else if (strcmp(m->desc, "data") == 0) {
1115 u32_to_b4(xd.nvm_data_offset, m->offset);
1116 }
1117 }
1118
1119 if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&xd, sizeof xd) < 0)
1120 return -1;
1121 }
1122 else
1123 {
1124 struct mega_device_desc md;
1125 LNODEID ln;
1126 AVRMEM * m;
1127 unsigned int flashsize = 0;
1128
1129 memset(&md, 0, sizeof md);
1130
1131 for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
1132 m = ldata(ln);
1133 if (strcmp(m->desc, "flash") == 0) {
1134 if (m->readsize != 0 && m->readsize < m->page_size)
1135 PDATA(pgm)->flash_pagesize = m->readsize;
1136 else
1137 PDATA(pgm)->flash_pagesize = m->page_size;
1138 u16_to_b2(md.flash_page_size, m->page_size);
1139 u32_to_b4(md.flash_size, (flashsize = m->size));
1140 // do we need it? just a wild guess
1141 u32_to_b4(md.boot_address, (m->size - m->page_size * 4) / 2);
1142 } else if (strcmp(m->desc, "eeprom") == 0) {
1143 PDATA(pgm)->eeprom_pagesize = m->page_size;
1144 md.eeprom_page_size = m->page_size;
1145 u16_to_b2(md.eeprom_size, m->size);
1146 }
1147 }
1148
1149 //md.sram_offset[2] = p->sram; // do we need it?
1150 if (p->ocdrev == -1) {
1151 int ocdrev;
1152
1153 /* lacking a proper definition, guess the OCD revision */
1154 if (p->flags & AVRPART_HAS_DW)
1155 ocdrev = 1; /* exception: ATtiny13, 2313, 4313 */
1156 else if (flashsize > 128 * 1024)
1157 ocdrev = 4;
1158 else
1159 ocdrev = 3; /* many exceptions from that, actually */
1160 avrdude_message(MSG_INFO, "%s: part definition for %s lacks \"ocdrev\"; guessing %d\n",
1161 progname, p->desc, ocdrev);
1162 md.ocd_revision = ocdrev;
1163 } else {
1164 md.ocd_revision = p->ocdrev;
1165 }
1166 md.always_one = 1;
1167 md.allow_full_page_bitstream = (p->flags & AVRPART_ALLOWFULLPAGEBITSTREAM) != 0;
1168 md.idr_address = p->idr;
1169
1170 if (p->eecr == 0)
1171 p->eecr = 0x3f; /* matches most "modern" mega/tiny AVRs */
1172 md.eearh_address = p->eecr - 0x20 + 3;
1173 md.eearl_address = p->eecr - 0x20 + 2;
1174 md.eecr_address = p->eecr - 0x20;
1175 md.eedr_address = p->eecr - 0x20 + 1;
1176 md.spmcr_address = p->spmcr;
1177 //md.osccal_address = p->osccal; // do we need it at all?
1178
1179 if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&md, sizeof md) < 0)
1180 return -1;
1181 }
1182
1183 int use_ext_reset;
1184
1185 for (use_ext_reset = 0; use_ext_reset <= 1; use_ext_reset++) {
1186 cmd[0] = SCOPE_AVR;
1187 cmd[1] = CMD3_SIGN_ON;
1188 cmd[2] = 0;
1189 cmd[3] = use_ext_reset; /* external reset */
1190
1191 if ((status = jtag3_command(pgm, cmd, 4, &resp, "AVR sign-on")) >= 0)
1192 break;
1193
1194 avrdude_message(MSG_INFO, "%s: retrying with external reset applied\n",
1195 progname);
1196 }
1197
1198 if (use_ext_reset > 1) {
1199 avrdude_message(MSG_INFO, "%s: JTAGEN fuse disabled?\n", progname);
1200 return -1;
1201 }
1202
1203 /*
1204 * Depending on the target connection, there are two different
1205 * possible replies of the ICE. For a JTAG connection, the reply
1206 * format is RSP3_DATA, followed by 4 bytes of the JTAG ID read from
1207 * the device (followed by a trailing 0). For all other connections
1208 * (except ISP which is handled completely differently, but that
1209 * doesn't apply here anyway), the response is just RSP_OK.
1210 */
1211 if (resp[1] == RSP3_DATA && status >= 7)
1212 /* JTAG ID has been returned */
1213 avrdude_message(MSG_NOTICE, "%s: JTAG ID returned: 0x%02x 0x%02x 0x%02x 0x%02x\n",
1214 progname, resp[3], resp[4], resp[5], resp[6]);
1215
1216 free(resp);
1217
1218 PDATA(pgm)->boot_start = ULONG_MAX;
1219 if ((p->flags & AVRPART_HAS_PDI)) {
1220 /*
1221 * Find out where the border between application and boot area
1222 * is.
1223 */
1224 AVRMEM *bootmem = avr_locate_mem(p, "boot");
1225 AVRMEM *flashmem = avr_locate_mem(p, "flash");
1226 if (bootmem == NULL || flashmem == NULL) {
1227 avrdude_message(MSG_INFO, "%s: jtagmk3_initialize(): Cannot locate \"flash\" and \"boot\" memories in description\n",
1228 progname);
1229 } else {
1230 PDATA(pgm)->boot_start = bootmem->offset - flashmem->offset;
1231 }
1232 }
1233
1234 free(PDATA(pgm)->flash_pagecache);
1235 free(PDATA(pgm)->eeprom_pagecache);
1236 if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
1237 avrdude_message(MSG_INFO, "%s: jtag3_initialize(): Out of memory\n",
1238 progname);
1239 return -1;
1240 }
1241 if ((PDATA(pgm)->eeprom_pagecache = malloc(PDATA(pgm)->eeprom_pagesize)) == NULL) {
1242 avrdude_message(MSG_INFO, "%s: jtag3_initialize(): Out of memory\n",
1243 progname);
1244 free(PDATA(pgm)->flash_pagecache);
1245 return -1;
1246 }
1247 PDATA(pgm)->flash_pageaddr = PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1248
1249 return 0;
1250}
int ovsigck
Definition main.c:200
#define MSG_NOTICE
Definition avrdude.h:52
AVRMEM * avr_locate_mem(AVRPART *p, char *desc)
Definition avrpart.c:354
static int jtag3_set_sck_xmega_pdi(PROGRAMMER *pgm, unsigned char *clk)
Definition jtag3.c:956
static int jtag3_set_sck_xmega_jtag(PROGRAMMER *pgm, unsigned char *clk)
Definition jtag3.c:961
#define PGM_FL_IS_PDI
Definition jtag3.c:84
static int jtag3_set_sck_mega_jtag(PROGRAMMER *pgm, unsigned char *clk)
Definition jtag3.c:966
static void u32_to_b4(unsigned char *b, unsigned long l)
Definition jtag3.c:138
int jtag3_setparm(PROGRAMMER *pgm, unsigned char scope, unsigned char section, unsigned char parm, unsigned char *value, unsigned char length)
Definition jtag3.c:2035
#define PARM3_CONN_DW
Definition jtag3_private.h:193
#define PARM3_DEVICEDESC
Definition jtag3_private.h:179
#define PARM3_ARCH_XMEGA
Definition jtag3_private.h:184
#define PARM3_ARCH_MEGA
Definition jtag3_private.h:183
#define PARM3_CONN_JTAG
Definition jtag3_private.h:192
#define PARM3_ARCH_TINY
Definition jtag3_private.h:182
#define PARM3_ARCH
Definition jtag3_private.h:181
#define PARM3_CONN_PDI
Definition jtag3_private.h:194
#define PARM3_FW_MAJOR
Definition jtag3_private.h:175
#define PARM3_SESS_PURPOSE
Definition jtag3_private.h:186
#define PARM3_SESS_PROGRAMMING
Definition jtag3_private.h:187
#define PARM3_CONNECTION
Definition jtag3_private.h:190
#define PARM3_JTAGCHAIN
Definition jtag3_private.h:197
Definition jtag3_private.h:258
Definition jtag3_private.h:292
int ocdrev
Definition libavrdude.h:273
unsigned char idr
Definition libavrdude.h:267
#define AVRPART_ALLOWFULLPAGEBITSTREAM
Definition libavrdude.h:199
unsigned short eecr
Definition libavrdude.h:270
#define AVRPART_HAS_JTAG
Definition libavrdude.h:198
void * ldata(LNODEID)
Definition lists.c:720
int size
Definition libavrdude.h:286
unsigned int offset
Definition libavrdude.h:289
void * LNODEID
Definition libavrdude.h:64
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
LNODEID lnext(LNODEID)
Definition lists.c:704
#define AVRPART_HAS_PDI
Definition libavrdude.h:202
int page_size
Definition libavrdude.h:287
LNODEID lfirst(LISTID)
Definition lists.c:688
#define AVRPART_HAS_DW
Definition libavrdude.h:201
int readsize
Definition libavrdude.h:301
unsigned int nvm_base
Definition libavrdude.h:272
unsigned flags
Definition libavrdude.h:230
unsigned char spmcr
Definition libavrdude.h:269
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284
unsigned int mcu_base
Definition libavrdude.h:271
LISTID mem
Definition libavrdude.h:277
Definition libavrdude.h:283
@ E
Definition libslic3r.h:101
double bitclock
Definition libavrdude.h:635
wchar_t const wchar_t unsigned long
Definition windows.hpp:29

References mega_device_desc::allow_full_page_bitstream, mega_device_desc::always_one, xmega_device_desc::app_size, avr_locate_mem(), avrdude_message(), AVRPART_ALLOWFULLPAGEBITSTREAM, AVRPART_HAS_DW, AVRPART_HAS_JTAG, AVRPART_HAS_PDI, programmer_t::bitclock, mega_device_desc::boot_address, xmega_device_desc::boot_size, cmd, CMD3_SIGN_ON, avrpart::desc, avrmem::desc, mega_device_desc::eearh_address, mega_device_desc::eearl_address, avrpart::eecr, mega_device_desc::eecr_address, mega_device_desc::eedr_address, mega_device_desc::eeprom_page_size, xmega_device_desc::eeprom_page_size, mega_device_desc::eeprom_size, xmega_device_desc::eeprom_size, programmer_t::fd, programmer_t::flag, avrpart::flags, mega_device_desc::flash_page_size, xmega_device_desc::flash_page_size, mega_device_desc::flash_size, free(), avrpart::idr, mega_device_desc::idr_address, jtag3_command(), jtag3_getparm(), jtag3_set_sck_mega_jtag(), jtag3_set_sck_xmega_jtag(), jtag3_set_sck_xmega_pdi(), jtag3_setparm(), ldata(), lfirst(), lnext(), long, malloc(), avrpart::mcu_base, xmega_device_desc::mcu_base_addr, avrpart::mem, MSG_INFO, MSG_NOTICE, MSG_NOTICE2, xmega_device_desc::nvm_app_offset, avrpart::nvm_base, xmega_device_desc::nvm_base_addr, xmega_device_desc::nvm_boot_offset, xmega_device_desc::nvm_data_offset, xmega_device_desc::nvm_eeprom_offset, xmega_device_desc::nvm_fuse_offset, xmega_device_desc::nvm_lock_offset, xmega_device_desc::nvm_prod_sig_offset, xmega_device_desc::nvm_user_sig_offset, mega_device_desc::ocd_revision, avrpart::ocdrev, avrmem::offset, ovsigck, avrmem::page_size, PARM3_ARCH, PARM3_ARCH_MEGA, PARM3_ARCH_TINY, PARM3_ARCH_XMEGA, PARM3_CONN_DW, PARM3_CONN_JTAG, PARM3_CONN_PDI, PARM3_CONNECTION, PARM3_DEVICEDESC, PARM3_FW_MAJOR, PARM3_JTAGCHAIN, PARM3_SESS_PROGRAMMING, PARM3_SESS_PURPOSE, PDATA, pgm, PGM_FL_IS_DW, PGM_FL_IS_EDBG, PGM_FL_IS_PDI, progname, avrmem::readsize, RSP3_DATA, SCOPE_AVR, SCOPE_GENERAL, avrmem::size, avrpart::spmcr, mega_device_desc::spmcr_address, u16_to_b2(), u32_to_b4(), filedescriptor::usb, and USBDEV_MAX_XFER_3.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_initpgm()

void jtag3_initpgm ( PROGRAMMER pgm)
2189{
2190 strcpy(pgm->type, "JTAGICE3");
2191
2192 /*
2193 * mandatory functions
2194 */
2201 pgm->open = jtag3_open;
2205
2206 /*
2207 * optional functions
2208 */
2217 pgm->page_size = 256;
2219}
#define PGM_FL_IS_JTAG
Definition jtag3.c:85
static int jtag3_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition jtag3.c:880
static int jtag3_parseextparms(PROGRAMMER *pgm, LISTID extparms)
Definition jtag3.c:1273
static int jtag3_set_sck_period(PROGRAMMER *pgm, double v)
Definition jtag3.c:1972
static int jtag3_open(PROGRAMMER *pgm, char *port)
Definition jtag3.c:1407
static int jtag3_page_erase(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int addr)
Definition jtag3.c:1473
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683
int(* page_erase)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int baseaddr)
Definition libavrdude.h:665
int(* set_sck_period)(struct programmer_t *pgm, double v)
Definition libavrdude.h:677

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::flag, programmer_t::initialize, jtag3_chip_erase(), jtag3_close(), jtag3_disable(), jtag3_display(), jtag3_enable(), jtag3_initialize(), jtag3_open(), jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_parseextparms(), jtag3_print_parms(), jtag3_program_enable_dummy(), jtag3_read_byte(), jtag3_set_sck_period(), jtag3_setup(), jtag3_teardown(), jtag3_write_byte(), programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, programmer_t::parseextparams, pgm, PGM_FL_IS_JTAG, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_sck_period, programmer_t::setup, programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ jtag3_memaddr()

static unsigned int jtag3_memaddr ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned long  addr 
)
static
2167{
2168 if ((p->flags & AVRPART_HAS_PDI) != 0) {
2169 if (addr >= PDATA(pgm)->boot_start)
2170 /*
2171 * all memories but "flash" are smaller than boot_start anyway, so
2172 * no need for an extra check we are operating on "flash"
2173 */
2174 return addr - PDATA(pgm)->boot_start;
2175 else
2176 /* normal flash, or anything else */
2177 return addr;
2178 }
2179 /*
2180 * Non-Xmega device.
2181 */
2182 return addr;
2183}

References AVRPART_HAS_PDI, avrpart::flags, PDATA, and pgm.

Referenced by jtag3_paged_load(), and jtag3_paged_write().

+ Here is the caller graph for this function:

◆ jtag3_memtype()

static unsigned char jtag3_memtype ( PROGRAMMER pgm,
AVRPART p,
unsigned long  addr 
)
static
2155{
2156 if ( p->flags & AVRPART_HAS_PDI ) {
2157 if (addr >= PDATA(pgm)->boot_start)
2158 return MTYPE_BOOT_FLASH;
2159 else
2160 return MTYPE_FLASH;
2161 } else {
2162 return MTYPE_FLASH_PAGE;
2163 }
2164}
#define MTYPE_BOOT_FLASH
Definition jtag3_private.h:164
#define MTYPE_FLASH_PAGE
Definition jtag3_private.h:157
#define MTYPE_FLASH
Definition jtag3_private.h:163

References AVRPART_HAS_PDI, avrpart::flags, MTYPE_BOOT_FLASH, MTYPE_FLASH, MTYPE_FLASH_PAGE, PDATA, and pgm.

Referenced by jtag3_page_erase(), jtag3_paged_load(), and jtag3_paged_write().

+ Here is the caller graph for this function:

◆ jtag3_open()

static int jtag3_open ( PROGRAMMER pgm,
char *  port 
)
static
1408{
1409 avrdude_message(MSG_NOTICE2, "%s: jtag3_open()\n", progname);
1410
1411 if (jtag3_open_common(pgm, port) < 0)
1412 return -1;
1413
1415 return -1;
1416
1417 return 0;
1418}
int jtag3_getsync(PROGRAMMER *pgm, int mode)
Definition jtag3.c:853
int jtag3_open_common(PROGRAMMER *pgm, char *port)
Definition jtag3.c:1311

References avrdude_message(), jtag3_getsync(), jtag3_open_common(), MSG_NOTICE2, PARM3_CONN_JTAG, pgm, and progname.

Referenced by jtag3_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_open_common()

int jtag3_open_common ( PROGRAMMER pgm,
char *  port 
)
1312{
1313 union pinfo pinfo;
1314 LNODEID usbpid;
1315 int rv = -1;
1316
1317#if !defined(HAVE_LIBUSB) && !defined(HAVE_LIBHIDAPI)
1318 avrdude_message(MSG_INFO, "avrdude was compiled without USB or HIDAPI support.\n");
1319 return -1;
1320#endif
1321
1322 if (strncmp(port, "usb", 3) != 0) {
1323 avrdude_message(MSG_INFO, "%s: jtag3_open_common(): JTAGICE3/EDBG port names must start with \"usb\"\n",
1324 progname);
1325 return -1;
1326 }
1327
1328 if (pgm->usbvid)
1329 pinfo.usbinfo.vid = pgm->usbvid;
1330 else
1332
1333 /* If the config entry did not specify a USB PID, insert the default one. */
1334 if (lfirst(pgm->usbpid) == NULL)
1336
1337#if defined(HAVE_LIBHIDAPI)
1338 /*
1339 * Try HIDAPI first. LibUSB is more generic, but might then cause
1340 * troubles for HID-class devices in some OSes (like Windows).
1341 */
1343 for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) {
1345 pinfo.usbinfo.pid = *(int *)(ldata(usbpid));
1346 pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_3;
1349 pgm->fd.usb.eep = 0;
1350
1351 strcpy(pgm->port, port);
1352 rv = serial_open(port, pinfo, &pgm->fd);
1353 }
1354 if (rv < 0) {
1355#endif /* HAVE_LIBHIDAPI */
1356#if defined(HAVE_LIBUSB)
1358 for (usbpid = lfirst(pgm->usbpid); rv < 0 && usbpid != NULL; usbpid = lnext(usbpid)) {
1360 pinfo.usbinfo.pid = *(int *)(ldata(usbpid));
1361 pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_3;
1365
1366 strcpy(pgm->port, port);
1367 rv = serial_open(port, pinfo, &pgm->fd);
1368 }
1369#endif /* HAVE_LIBUSB */
1370#if defined(HAVE_LIBHIDAPI)
1371 }
1372#endif
1373 if (rv < 0) {
1374 avrdude_message(MSG_INFO, "%s: jtag3_open_common(): Did not find any device matching VID 0x%04x and PID list: ",
1375 progname, (unsigned)pinfo.usbinfo.vid);
1376 int notfirst = 0;
1377 for (usbpid = lfirst(pgm->usbpid); usbpid != NULL; usbpid = lnext(usbpid)) {
1378 if (notfirst)
1380 avrdude_message(MSG_INFO, "0x%04x", (unsigned int)(*(int *)(ldata(usbpid))));
1381 notfirst = 1;
1382 }
1383 fputc('\n', stderr);
1384
1385 return -1;
1386 }
1387
1388 if (pgm->fd.usb.eep == 0)
1389 {
1390 /* The event EP has been deleted by usb_open(), so we are
1391 running on a CMSIS-DAP device, using EDBG protocol */
1393 avrdude_message(MSG_NOTICE, "%s: Found CMSIS-DAP compliant device, using EDBG protocol\n",
1394 progname);
1395 }
1396
1397 /*
1398 * drain any extraneous input
1399 */
1400 jtag3_drain(pgm, 0);
1401
1402 return 0;
1403}
static int jtag3_drain(PROGRAMMER *pgm, int display)
Definition jtag3.c:627
int ladd(LISTID lid, void *p)
Definition lists.c:547
struct serial_device * serdev
Definition ser_posix.c:562
#define serial_open
Definition libavrdude.h:574
struct serial_device usb_serdev_frame
struct pinfo::@13 usbinfo
#define PINFO_FL_SILENT
Definition libavrdude.h:544
struct serial_device usbhid_serdev
Definition libavrdude.h:536
int usbvid
Definition libavrdude.h:631
char port[PGM_PORTLEN]
Definition libavrdude.h:620
LISTID usbpid
Definition libavrdude.h:632
#define USB_VENDOR_ATMEL
Definition usbdevs.h:28
#define USBDEV_BULK_EP_READ_3
Definition usbdevs.h:70
#define USB_DEVICE_JTAGICE3
Definition usbdevs.h:33
#define USBDEV_BULK_EP_WRITE_3
Definition usbdevs.h:69
#define USBDEV_EVT_EP_READ_3
Definition usbdevs.h:71

References avrdude_message(), programmer_t::fd, programmer_t::flag, jtag3_drain(), ladd(), ldata(), lfirst(), lnext(), MSG_INFO, MSG_NOTICE, pgm, PGM_FL_IS_EDBG, PINFO_FL_SILENT, programmer_t::port, progname, serdev, serial_open, filedescriptor::usb, USB_DEVICE_JTAGICE3, usb_serdev_frame, USB_VENDOR_ATMEL, USBDEV_BULK_EP_READ_3, USBDEV_BULK_EP_WRITE_3, USBDEV_EVT_EP_READ_3, USBDEV_MAX_XFER_3, usbhid_serdev, pinfo::usbinfo, programmer_t::usbpid, and programmer_t::usbvid.

Referenced by jtag3_open(), jtag3_open_dw(), and jtag3_open_pdi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_open_dw()

static int jtag3_open_dw ( PROGRAMMER pgm,
char *  port 
)
static
1421{
1422 avrdude_message(MSG_NOTICE2, "%s: jtag3_open_dw()\n", progname);
1423
1424 if (jtag3_open_common(pgm, port) < 0)
1425 return -1;
1426
1428 return -1;
1429
1430 return 0;
1431}

References avrdude_message(), jtag3_getsync(), jtag3_open_common(), MSG_NOTICE2, PARM3_CONN_DW, pgm, and progname.

Referenced by jtag3_dw_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_open_pdi()

static int jtag3_open_pdi ( PROGRAMMER pgm,
char *  port 
)
static
1434{
1435 avrdude_message(MSG_NOTICE2, "%s: jtag3_open_pdi()\n", progname);
1436
1437 if (jtag3_open_common(pgm, port) < 0)
1438 return -1;
1439
1441 return -1;
1442
1443 return 0;
1444}

References avrdude_message(), jtag3_getsync(), jtag3_open_common(), MSG_NOTICE2, PARM3_CONN_PDI, pgm, and progname.

Referenced by jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_page_erase()

static int jtag3_page_erase ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  addr 
)
static
1475{
1476 unsigned char cmd[8], *resp;
1477
1478 avrdude_message(MSG_NOTICE2, "%s: jtag3_page_erase(.., %s, 0x%x)\n",
1479 progname, m->desc, addr);
1480
1481 if (!(p->flags & AVRPART_HAS_PDI)) {
1482 avrdude_message(MSG_INFO, "%s: jtag3_page_erase: not an Xmega device\n",
1483 progname);
1484 return -1;
1485 }
1486
1487 if (jtag3_program_enable(pgm) < 0)
1488 return -1;
1489
1490 cmd[0] = SCOPE_AVR;
1492 cmd[2] = 0;
1493
1494 if (strcmp(m->desc, "flash") == 0) {
1495 if (jtag3_memtype(pgm, p, addr) == MTYPE_FLASH)
1497 else
1499 } else if (strcmp(m->desc, "eeprom") == 0) {
1501 } else if ( ( strcmp(m->desc, "usersig") == 0 ) ) {
1503 } else if ( ( strcmp(m->desc, "boot") == 0 ) ) {
1505 } else {
1507 }
1508
1509 u32_to_b4(cmd + 4, addr + m->offset);
1510
1511 if (jtag3_command(pgm, cmd, 8, &resp, "page erase") < 0)
1512 return -1;
1513
1514 free(resp);
1515 return 0;
1516}
static int jtag3_program_enable(PROGRAMMER *pgm)
Definition jtag3.c:914
static unsigned char jtag3_memtype(PROGRAMMER *pgm, AVRPART *p, unsigned long addr)
Definition jtag3.c:2154
#define XMEGA_ERASE_EEPROM_PAGE
Definition jtag3_private.h:213
#define XMEGA_ERASE_BOOT_PAGE
Definition jtag3_private.h:212
#define XMEGA_ERASE_APP_PAGE
Definition jtag3_private.h:211
#define XMEGA_ERASE_USERSIG
Definition jtag3_private.h:214

References avrdude_message(), AVRPART_HAS_PDI, cmd, CMD3_ERASE_MEMORY, avrmem::desc, avrpart::flags, free(), jtag3_command(), jtag3_memtype(), jtag3_program_enable(), MSG_INFO, MSG_NOTICE2, MTYPE_FLASH, avrmem::offset, pgm, progname, SCOPE_AVR, u32_to_b4(), XMEGA_ERASE_APP_PAGE, XMEGA_ERASE_BOOT_PAGE, XMEGA_ERASE_EEPROM_PAGE, and XMEGA_ERASE_USERSIG.

Referenced by jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_paged_load()

static int jtag3_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
1625{
1626 unsigned int block_size;
1627 unsigned int maxaddr = addr + n_bytes;
1628 unsigned char cmd[12];
1629 unsigned char *resp;
1630 int status, dynamic_memtype = 0;
1631 long otimeout = serial_recv_timeout;
1632
1633 avrdude_message(MSG_NOTICE2, "%s: jtag3_paged_load(.., %s, %d, %d)\n",
1634 progname, m->desc, page_size, n_bytes);
1635
1636 if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
1637 return -1;
1638
1639 page_size = m->readsize;
1640
1641 cmd[0] = SCOPE_AVR;
1642 cmd[1] = CMD3_READ_MEMORY;
1643 cmd[2] = 0;
1644
1645 if (strcmp(m->desc, "flash") == 0) {
1646 cmd[3] = jtag3_memtype(pgm, p, addr);
1647 if (p->flags & AVRPART_HAS_PDI)
1648 /* dynamically decide between flash/boot memtype */
1649 dynamic_memtype = 1;
1650 } else if (strcmp(m->desc, "eeprom") == 0) {
1652 if (pgm->flag & PGM_FL_IS_DW)
1653 return -1;
1654 } else if ( ( strcmp(m->desc, "prodsig") == 0 ) ) {
1655 cmd[3] = MTYPE_PRODSIG;
1656 } else if ( ( strcmp(m->desc, "usersig") == 0 ) ) {
1657 cmd[3] = MTYPE_USERSIG;
1658 } else if ( ( strcmp(m->desc, "boot") == 0 ) ) {
1659 cmd[3] = MTYPE_BOOT_FLASH;
1660 } else if ( p->flags & AVRPART_HAS_PDI ) {
1661 cmd[3] = MTYPE_FLASH;
1662 } else {
1663 cmd[3] = MTYPE_SPM;
1664 }
1665 serial_recv_timeout = 100;
1666 for (; addr < maxaddr; addr += page_size) {
1667 if ((maxaddr - addr) < page_size)
1668 block_size = maxaddr - addr;
1669 else
1670 block_size = page_size;
1671 avrdude_message(MSG_DEBUG, "%s: jtag3_paged_load(): "
1672 "block_size at addr %d is %d\n",
1673 progname, addr, block_size);
1674
1675 if (dynamic_memtype)
1676 cmd[3] = jtag3_memtype(pgm, p, addr);
1677
1678 u32_to_b4(cmd + 8, block_size);
1679 u32_to_b4(cmd + 4, jtag3_memaddr(pgm, p, m, addr));
1680
1681 if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
1682 return -1;
1683
1684 if (resp[1] != RSP3_DATA ||
1685 status < block_size + 4) {
1686 avrdude_message(MSG_INFO, "%s: wrong/short reply to read memory command\n",
1687 progname);
1688 serial_recv_timeout = otimeout;
1689 free(resp);
1690 return -1;
1691 }
1692 memcpy(m->buf + addr, resp + 3, status - 4);
1693 free(resp);
1694 }
1695 serial_recv_timeout = otimeout;
1696
1697 return n_bytes;
1698}
static unsigned int jtag3_memaddr(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr)
Definition jtag3.c:2166
#define MTYPE_USERSIG
Definition jtag3_private.h:166
#define MTYPE_PRODSIG
Definition jtag3_private.h:167
#define MTYPE_EEPROM_PAGE
Definition jtag3_private.h:158
#define MTYPE_SPM
Definition jtag3_private.h:156
#define CMD3_READ_MEMORY
Definition jtag3_private.h:125
#define MTYPE_EEPROM
Definition jtag3_private.h:155
long serial_recv_timeout
Definition ser_posix.c:47
unsigned char * buf
Definition libavrdude.h:304

References avrdude_message(), AVRPART_HAS_PDI, avrmem::buf, cmd, CMD3_READ_MEMORY, avrmem::desc, programmer_t::flag, avrpart::flags, free(), jtag3_command(), jtag3_memaddr(), jtag3_memtype(), jtag3_program_enable(), MSG_DEBUG, MSG_INFO, MSG_NOTICE2, MTYPE_BOOT_FLASH, MTYPE_EEPROM, MTYPE_EEPROM_PAGE, MTYPE_FLASH, MTYPE_PRODSIG, MTYPE_SPM, MTYPE_USERSIG, pgm, PGM_FL_IS_DW, progname, avrmem::readsize, RSP3_DATA, SCOPE_AVR, serial_recv_timeout, and u32_to_b4().

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_paged_write()

static int jtag3_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
1521{
1522 unsigned int block_size;
1523 unsigned int maxaddr = addr + n_bytes;
1524 unsigned char *cmd;
1525 unsigned char *resp;
1526 int status, dynamic_memtype = 0;
1527 long otimeout = serial_recv_timeout;
1528
1529 avrdude_message(MSG_NOTICE2, "%s: jtag3_paged_write(.., %s, %d, %d)\n",
1530 progname, m->desc, page_size, n_bytes);
1531
1532 if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
1533 return -1;
1534
1535 if (page_size == 0) page_size = 256;
1536
1537 if ((cmd = malloc(page_size + 13)) == NULL) {
1538 avrdude_message(MSG_INFO, "%s: jtag3_paged_write(): Out of memory\n",
1539 progname);
1540 return -1;
1541 }
1542
1543 cmd[0] = SCOPE_AVR;
1545 cmd[2] = 0;
1546 if (strcmp(m->desc, "flash") == 0) {
1547 PDATA(pgm)->flash_pageaddr = (unsigned long)-1L;
1548 cmd[3] = jtag3_memtype(pgm, p, addr);
1549 if (p->flags & AVRPART_HAS_PDI)
1550 /* dynamically decide between flash/boot memtype */
1551 dynamic_memtype = 1;
1552 } else if (strcmp(m->desc, "eeprom") == 0) {
1553 if (pgm->flag & PGM_FL_IS_DW) {
1554 /*
1555 * jtag3_paged_write() to EEPROM attempted while in
1556 * DW mode. Use jtag3_write_byte() instead.
1557 */
1558 for (; addr < maxaddr; addr++) {
1559 status = jtag3_write_byte(pgm, p, m, addr, m->buf[addr]);
1560 if (status < 0) {
1561 free(cmd);
1562 return -1;
1563 }
1564 }
1565 free(cmd);
1566 return n_bytes;
1567 }
1569 PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1570 } else if ( ( strcmp(m->desc, "usersig") == 0 ) ) {
1571 cmd[3] = MTYPE_USERSIG;
1572 } else if ( ( strcmp(m->desc, "boot") == 0 ) ) {
1573 cmd[3] = MTYPE_BOOT_FLASH;
1574 } else if ( p->flags & AVRPART_HAS_PDI ) {
1575 cmd[3] = MTYPE_FLASH;
1576 } else {
1577 cmd[3] = MTYPE_SPM;
1578 }
1579 serial_recv_timeout = 100;
1580 for (; addr < maxaddr; addr += page_size) {
1581 if ((maxaddr - addr) < page_size)
1582 block_size = maxaddr - addr;
1583 else
1584 block_size = page_size;
1585 avrdude_message(MSG_DEBUG, "%s: jtag3_paged_write(): "
1586 "block_size at addr %d is %d\n",
1587 progname, addr, block_size);
1588
1589 if (dynamic_memtype)
1590 cmd[3] = jtag3_memtype(pgm, p, addr);
1591
1592 u32_to_b4(cmd + 8, page_size);
1593 u32_to_b4(cmd + 4, jtag3_memaddr(pgm, p, m, addr));
1594 cmd[12] = 0;
1595
1596 /*
1597 * The JTAG ICE will refuse to write anything but a full page, at
1598 * least for the flash ROM. If a partial page has been requested,
1599 * set the remainder to 0xff. (Maybe we should rather read back
1600 * the existing contents instead before? Doesn't matter much, as
1601 * bits cannot be written to 1 anyway.)
1602 */
1603 memset(cmd + 13, 0xff, page_size);
1604 memcpy(cmd + 13, m->buf + addr, block_size);
1605
1606 if ((status = jtag3_command(pgm, cmd, page_size + 13,
1607 &resp, "write memory")) < 0) {
1608 free(cmd);
1609 serial_recv_timeout = otimeout;
1610 return -1;
1611 }
1612
1613 free(resp);
1614 }
1615
1616 free(cmd);
1617 serial_recv_timeout = otimeout;
1618
1619 return n_bytes;
1620}
#define CMD3_WRITE_MEMORY
Definition jtag3_private.h:126
#define MTYPE_EEPROM_XMEGA
Definition jtag3_private.h:165

References avrdude_message(), AVRPART_HAS_PDI, avrmem::buf, cmd, CMD3_WRITE_MEMORY, avrmem::desc, programmer_t::flag, avrpart::flags, free(), jtag3_command(), jtag3_memaddr(), jtag3_memtype(), jtag3_program_enable(), jtag3_write_byte(), long, malloc(), MSG_DEBUG, MSG_INFO, MSG_NOTICE2, MTYPE_BOOT_FLASH, MTYPE_EEPROM_PAGE, MTYPE_EEPROM_XMEGA, MTYPE_FLASH, MTYPE_SPM, MTYPE_USERSIG, PDATA, pgm, PGM_FL_IS_DW, progname, SCOPE_AVR, serial_recv_timeout, and u32_to_b4().

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), jtag3_pdi_initpgm(), and jtag3_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_parseextparms()

static int jtag3_parseextparms ( PROGRAMMER pgm,
LISTID  extparms 
)
static
1274{
1275 LNODEID ln;
1276 const char *extended_param;
1277 int rv = 0;
1278
1279 for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
1280 extended_param = ldata(ln);
1281
1282 if (strncmp(extended_param, "jtagchain=", strlen("jtagchain=")) == 0) {
1283 unsigned int ub, ua, bb, ba;
1284 if (sscanf(extended_param, "jtagchain=%u,%u,%u,%u", &ub, &ua, &bb, &ba)
1285 != 4) {
1286 avrdude_message(MSG_INFO, "%s: jtag3_parseextparms(): invalid JTAG chain '%s'\n",
1287 progname, extended_param);
1288 rv = -1;
1289 continue;
1290 }
1291 avrdude_message(MSG_NOTICE2, "%s: jtag3_parseextparms(): JTAG chain parsed as:\n"
1292 "%s %u units before, %u units after, %u bits before, %u bits after\n",
1293 progname,
1294 progbuf, ub, ua, bb, ba);
1295 PDATA(pgm)->jtagchain[0] = ub;
1296 PDATA(pgm)->jtagchain[1] = ua;
1297 PDATA(pgm)->jtagchain[2] = bb;
1298 PDATA(pgm)->jtagchain[3] = ba;
1299
1300 continue;
1301 }
1302
1303 avrdude_message(MSG_INFO, "%s: jtag3_parseextparms(): invalid extended parameter '%s'\n",
1304 progname, extended_param);
1305 rv = -1;
1306 }
1307
1308 return rv;
1309}
char progbuf[]
Definition main.c:62

References avrdude_message(), ldata(), lfirst(), lnext(), MSG_INFO, MSG_NOTICE2, PDATA, pgm, progbuf, and progname.

Referenced by jtag3_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_pdi_initpgm()

void jtag3_pdi_initpgm ( PROGRAMMER pgm)
2256{
2257 strcpy(pgm->type, "JTAGICE3_PDI");
2258
2259 /*
2260 * mandatory functions
2261 */
2272
2273 /*
2274 * optional functions
2275 */
2283 pgm->page_size = 256;
2285}
static int jtag3_open_pdi(PROGRAMMER *pgm, char *port)
Definition jtag3.c:1433

References programmer_t::chip_erase, programmer_t::close, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::flag, programmer_t::initialize, jtag3_chip_erase(), jtag3_close(), jtag3_disable(), jtag3_display(), jtag3_enable(), jtag3_initialize(), jtag3_open_pdi(), jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_print_parms(), jtag3_program_enable_dummy(), jtag3_read_byte(), jtag3_set_sck_period(), jtag3_setup(), jtag3_teardown(), jtag3_write_byte(), programmer_t::open, programmer_t::page_erase, programmer_t::page_size, programmer_t::paged_load, programmer_t::paged_write, pgm, PGM_FL_IS_PDI, programmer_t::print_parms, programmer_t::program_enable, programmer_t::read_byte, programmer_t::set_sck_period, programmer_t::setup, programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ jtag3_prevent()

static void jtag3_prevent ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
310{
311 int i;
312
313 if (verbose >= 4) {
314 avrdude_message(MSG_TRACE, "Raw event:\n");
315
316 for (i = 0; i < len; i++) {
317 avrdude_message(MSG_TRACE, "%02x ", data[i]);
318 if (i % 16 == 15)
319 putc('\n', stderr);
320 else
321 putc(' ', stderr);
322 }
323 if (i % 16 != 0)
324 putc('\n', stderr);
325 }
326
327 avrdude_message(MSG_INFO, "Event serial 0x%04x, ",
328 (data[3] << 8) | data[2]);
329
330 switch (data[4]) {
331 case SCOPE_INFO:
332 avrdude_message(MSG_INFO, "[info] ");
333 break;
334
335 case SCOPE_GENERAL:
336 avrdude_message(MSG_INFO, "[general] ");
337 break;
338
339 case SCOPE_AVR:
340 avrdude_message(MSG_INFO, "[AVR] ");
341 break;
342
343 default:
344 avrdude_message(MSG_INFO, "[scope 0x%02x] ", data[0]);
345 break;
346 }
347
348 switch (data[5]) {
349 case EVT3_BREAK:
350 avrdude_message(MSG_INFO, "BREAK");
351 if (len >= 11) {
352 avrdude_message(MSG_INFO, ", PC = 0x%lx, reason ", b4_to_u32(data + 6));
353 switch (data[10]) {
354 case 0x00:
355 avrdude_message(MSG_INFO, "unspecified");
356 break;
357 case 0x01:
358 avrdude_message(MSG_INFO, "program break");
359 break;
360 case 0x02:
361 avrdude_message(MSG_INFO, "data break PDSB");
362 break;
363 case 0x03:
364 avrdude_message(MSG_INFO, "data break PDMSB");
365 break;
366 default:
367 avrdude_message(MSG_INFO, "unknown: 0x%02x", data[10]);
368 }
369 /* There are two more bytes of data which always appear to be
370 * 0x01, 0x00. Purpose unknown. */
371 }
372 break;
373
374 case EVT3_SLEEP:
375 if (len >= 8 && data[7] == 0)
376 avrdude_message(MSG_INFO, "sleeping");
377 else if (len >= 8 && data[7] == 1)
378 avrdude_message(MSG_INFO, "wakeup");
379 else
380 avrdude_message(MSG_INFO, "unknown SLEEP event");
381 break;
382
383 case EVT3_POWER:
384 if (len >= 8 && data[7] == 0)
385 avrdude_message(MSG_INFO, "power-down");
386 else if (len >= 8 && data[7] == 1)
387 avrdude_message(MSG_INFO, "power-up");
388 else
389 avrdude_message(MSG_INFO, "unknown POWER event");
390 break;
391
392 default:
393 avrdude_message(MSG_INFO, "UNKNOWN 0x%02x", data[5]);
394 break;
395 }
396 putc('\n', stderr);
397}
static unsigned long b4_to_u32(unsigned char *b)
Definition jtag3.c:126
#define EVT3_POWER
Definition jtag3_private.h:151
#define EVT3_BREAK
Definition jtag3_private.h:149
#define EVT3_SLEEP
Definition jtag3_private.h:150

References avrdude_message(), b4_to_u32(), EVT3_BREAK, EVT3_POWER, EVT3_SLEEP, MSG_INFO, MSG_TRACE, SCOPE_AVR, SCOPE_GENERAL, SCOPE_INFO, and verbose.

Referenced by jtag3_recv().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_print_data()

static void jtag3_print_data ( unsigned char *  b,
size_t  s 
)
static
164{
165 int i;
166
167 if (s < 2)
168 return;
169
170 for (i = 0; i < s; i++) {
171 avrdude_message(MSG_INFO, "0x%02x", b[i]);
172 if (i % 16 == 15)
173 putc('\n', stderr);
174 else
175 putc(' ', stderr);
176 }
177 if (i % 16 != 0)
178 putc('\n', stderr);
179}

References avrdude_message(), and MSG_INFO.

Referenced by jtag3_prmsg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_print_parms()

static void jtag3_print_parms ( PROGRAMMER pgm)
static
2150{
2152}

References jtag3_print_parms1(), and pgm.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_print_parms1()

static void jtag3_print_parms1 ( PROGRAMMER pgm,
const char *  p 
)
static
2119{
2120 unsigned char buf[2];
2121
2122 if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0)
2123 return;
2124
2125 avrdude_message(MSG_INFO, "%sVtarget : %.2f V\n", p,
2126 b2_to_u16(buf) / 1000.0);
2127
2128 if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, buf, 2) < 0)
2129 return;
2130 avrdude_message(MSG_INFO, "%sJTAG clock megaAVR/program: %u kHz\n", p,
2131 b2_to_u16(buf));
2132
2133 if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_DEBUG, buf, 2) < 0)
2134 return;
2135 avrdude_message(MSG_INFO, "%sJTAG clock megaAVR/debug: %u kHz\n", p,
2136 b2_to_u16(buf));
2137
2138 if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_JTAG, buf, 2) < 0)
2139 return;
2140 avrdude_message(MSG_INFO, "%sJTAG clock Xmega: %u kHz\n", p,
2141 b2_to_u16(buf));
2142
2143 if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, buf, 2) < 0)
2144 return;
2145 avrdude_message(MSG_INFO, "%sPDI clock Xmega : %u kHz\n", p,
2146 b2_to_u16(buf));
2147}
static unsigned short b2_to_u16(unsigned char *b)
Definition jtag3.c:147
#define PARM3_CLK_XMEGA_JTAG
Definition jtag3_private.h:201
#define PARM3_CLK_MEGA_PROG
Definition jtag3_private.h:199
#define PARM3_VTARGET
Definition jtag3_private.h:178
#define PARM3_CLK_XMEGA_PDI
Definition jtag3_private.h:202
#define PARM3_CLK_MEGA_DEBUG
Definition jtag3_private.h:200

References avrdude_message(), b2_to_u16(), jtag3_getparm(), MSG_INFO, PARM3_CLK_MEGA_DEBUG, PARM3_CLK_MEGA_PROG, PARM3_CLK_XMEGA_JTAG, PARM3_CLK_XMEGA_PDI, PARM3_VTARGET, pgm, SCOPE_AVR, and SCOPE_GENERAL.

Referenced by jtag3_display(), and jtag3_print_parms().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_prmsg()

static void jtag3_prmsg ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
static
182{
183 int i;
184
185 if (verbose >= 4) {
186 avrdude_message(MSG_TRACE, "Raw message:\n");
187
188 for (i = 0; i < len; i++) {
189 avrdude_message(MSG_TRACE, "%02x ", data[i]);
190 if (i % 16 == 15)
191 putc('\n', stderr);
192 else
193 putc(' ', stderr);
194 }
195 if (i % 16 != 0)
196 putc('\n', stderr);
197 }
198
199 switch (data[0]) {
200 case SCOPE_INFO:
201 avrdude_message(MSG_INFO, "[info] ");
202 break;
203
204 case SCOPE_GENERAL:
205 avrdude_message(MSG_INFO, "[general] ");
206 break;
207
208 case SCOPE_AVR_ISP:
209 avrdude_message(MSG_INFO, "[AVRISP] ");
210 jtag3_print_data(data + 1, len - 1);
211 return;
212
213 case SCOPE_AVR:
214 avrdude_message(MSG_INFO, "[AVR] ");
215 break;
216
217 default:
218 avrdude_message(MSG_INFO, "[scope 0x%02x] ", data[0]);
219 break;
220 }
221
222 switch (data[1]) {
223 case RSP3_OK:
224 avrdude_message(MSG_INFO, "OK\n");
225 break;
226
227 case RSP3_FAILED:
228 avrdude_message(MSG_INFO, "FAILED");
229 if (len > 3)
230 {
231 char reason[50];
232 sprintf(reason, "0x%02x", data[3]);
233 switch (data[3])
234 {
236 strcpy(reason, "target does not answer");
237 break;
238
240 strcpy(reason, "no target power");
241 break;
242
244 strcpy(reason, "command not understood");
245 break;
246
248 strcpy(reason, "wrong (programming) mode");
249 break;
250
251 case RSP3_FAIL_PDI:
252 strcpy(reason, "PDI failure");
253 break;
254
256 strcpy(reason, "unsupported memory type");
257 break;
258
260 strcpy(reason, "wrong length in memory access");
261 break;
262
264 strcpy(reason, "debugWIRE communication failed");
265 break;
266 }
267 avrdude_message(MSG_INFO, ", reason: %s\n", reason);
268 }
269 else
270 {
271 avrdude_message(MSG_INFO, ", unspecified reason\n");
272 }
273 break;
274
275 case RSP3_DATA:
276 avrdude_message(MSG_INFO, "Data returned:\n");
277 jtag3_print_data(data + 2, len - 2);
278 break;
279
280 case RSP3_INFO:
281 avrdude_message(MSG_INFO, "Info returned:\n");
282 for (i = 2; i < len; i++) {
283 if (isprint(data[i]))
284 putc(data[i], stderr);
285 else
286 avrdude_message(MSG_INFO, "\\%03o", data[i]);
287 }
288 putc('\n', stderr);
289 break;
290
291 case RSP3_PC:
292 if (len < 7)
293 {
294 avrdude_message(MSG_INFO, "PC reply too short\n");
295 }
296 else
297 {
298 unsigned long pc = (data[6] << 24) | (data[5] << 16)
299 | (data[4] << 8) | data[3];
300 avrdude_message(MSG_INFO, "PC 0x%0lx\n", pc);
301 }
302 break;
303
304 default:
305 avrdude_message(MSG_INFO, "unknown message 0x%02x\n", data[1]);
306 }
307}
static void jtag3_print_data(unsigned char *b, size_t s)
Definition jtag3.c:163
#define RSP3_FAIL_UNSUPP_MEMORY
Definition jtag3_private.h:144
#define RSP3_FAIL_WRONG_LENGTH
Definition jtag3_private.h:145
#define RSP3_FAIL_DEBUGWIRE
Definition jtag3_private.h:139
#define RSP3_FAIL_WRONG_MODE
Definition jtag3_private.h:143
#define SCOPE_AVR_ISP
Definition jtag3_private.h:97
#define RSP3_FAIL_NO_TARGET_POWER
Definition jtag3_private.h:142
#define RSP3_PC
Definition jtag3_private.h:132
#define RSP3_FAILED
Definition jtag3_private.h:134
#define RSP3_FAIL_PDI
Definition jtag3_private.h:140
#define RSP3_FAIL_NO_ANSWER
Definition jtag3_private.h:141
#define RSP3_FAIL_NOT_UNDERSTOOD
Definition jtag3_private.h:146

References avrdude_message(), jtag3_print_data(), MSG_INFO, MSG_TRACE, RSP3_DATA, RSP3_FAIL_DEBUGWIRE, RSP3_FAIL_NO_ANSWER, RSP3_FAIL_NO_TARGET_POWER, RSP3_FAIL_NOT_UNDERSTOOD, RSP3_FAIL_PDI, RSP3_FAIL_UNSUPP_MEMORY, RSP3_FAIL_WRONG_LENGTH, RSP3_FAIL_WRONG_MODE, RSP3_FAILED, RSP3_INFO, RSP3_OK, RSP3_PC, SCOPE_AVR, SCOPE_AVR_ISP, SCOPE_GENERAL, SCOPE_INFO, and verbose.

Referenced by jtag3_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_program_disable()

static int jtag3_program_disable ( PROGRAMMER pgm)
static
936{
937 unsigned char buf[3], *resp;
938
939 if (!PDATA(pgm)->prog_enabled)
940 return 0;
941
942 buf[0] = SCOPE_AVR;
943 buf[1] = CMD3_LEAVE_PROGMODE;
944 buf[2] = 0;
945
946 if (jtag3_command(pgm, buf, 3, &resp, "leave progmode") < 0)
947 return -1;
948
949 free(resp);
950
951 PDATA(pgm)->prog_enabled = 0;
952
953 return 0;
954}
#define CMD3_LEAVE_PROGMODE
Definition jtag3_private.h:123

References CMD3_LEAVE_PROGMODE, free(), jtag3_command(), PDATA, pgm, and SCOPE_AVR.

Referenced by jtag3_disable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_program_enable()

static int jtag3_program_enable ( PROGRAMMER pgm)
static
915{
916 unsigned char buf[3], *resp;
917
918 if (PDATA(pgm)->prog_enabled)
919 return 0;
920
921 buf[0] = SCOPE_AVR;
922 buf[1] = CMD3_ENTER_PROGMODE;
923 buf[2] = 0;
924
925 if (jtag3_command(pgm, buf, 3, &resp, "enter progmode") >= 0) {
926 free(resp);
927 PDATA(pgm)->prog_enabled = 1;
928
929 return 0;
930 }
931
932 return -1;
933}
#define CMD3_ENTER_PROGMODE
Definition jtag3_private.h:122

References CMD3_ENTER_PROGMODE, free(), jtag3_command(), PDATA, pgm, and SCOPE_AVR.

Referenced by jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_read_byte(), and jtag3_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_program_enable_dummy()

static int jtag3_program_enable_dummy ( PROGRAMMER pgm,
AVRPART p 
)
static
910{
911 return 0;
912}

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the caller graph for this function:

◆ jtag3_read_byte()

static int jtag3_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
1702{
1703 unsigned char cmd[12];
1704 unsigned char *resp, *cache_ptr = NULL;
1705 int status, unsupp = 0;
1706 unsigned long paddr = 0UL, *paddr_ptr = NULL;
1707 unsigned int pagesize = 0;
1708
1709 avrdude_message(MSG_NOTICE2, "%s: jtag3_read_byte(.., %s, 0x%lx, ...)\n",
1710 progname, mem->desc, addr);
1711
1712 if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
1713 return -1;
1714
1715 cmd[0] = SCOPE_AVR;
1716 cmd[1] = CMD3_READ_MEMORY;
1717 cmd[2] = 0;
1718
1720 if (strcmp(mem->desc, "flash") == 0 ||
1721 strcmp(mem->desc, "application") == 0 ||
1722 strcmp(mem->desc, "apptable") == 0 ||
1723 strcmp(mem->desc, "boot") == 0) {
1724 addr += mem->offset & (512 * 1024 - 1); /* max 512 KiB flash */
1725 pagesize = PDATA(pgm)->flash_pagesize;
1726 paddr = addr & ~(pagesize - 1);
1727 paddr_ptr = &PDATA(pgm)->flash_pageaddr;
1728 cache_ptr = PDATA(pgm)->flash_pagecache;
1729 } else if (strcmp(mem->desc, "eeprom") == 0) {
1730 if ( (pgm->flag & PGM_FL_IS_DW) || ( p->flags & AVRPART_HAS_PDI ) ) {
1731 cmd[3] = MTYPE_EEPROM;
1732 } else {
1734 }
1735 pagesize = mem->page_size;
1736 paddr = addr & ~(pagesize - 1);
1737 paddr_ptr = &PDATA(pgm)->eeprom_pageaddr;
1738 cache_ptr = PDATA(pgm)->eeprom_pagecache;
1739 } else if (strcmp(mem->desc, "lfuse") == 0) {
1740 cmd[3] = MTYPE_FUSE_BITS;
1741 addr = 0;
1742 if (pgm->flag & PGM_FL_IS_DW)
1743 unsupp = 1;
1744 } else if (strcmp(mem->desc, "hfuse") == 0) {
1745 cmd[3] = MTYPE_FUSE_BITS;
1746 addr = 1;
1747 if (pgm->flag & PGM_FL_IS_DW)
1748 unsupp = 1;
1749 } else if (strcmp(mem->desc, "efuse") == 0) {
1750 cmd[3] = MTYPE_FUSE_BITS;
1751 addr = 2;
1752 if (pgm->flag & PGM_FL_IS_DW)
1753 unsupp = 1;
1754 } else if (strncmp(mem->desc, "lock", 4) == 0) {
1755 cmd[3] = MTYPE_LOCK_BITS;
1756 if (pgm->flag & PGM_FL_IS_DW)
1757 unsupp = 1;
1758 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
1759 cmd[3] = MTYPE_FUSE_BITS;
1760 addr = mem->offset & 7;
1761 } else if (strcmp(mem->desc, "usersig") == 0) {
1762 cmd[3] = MTYPE_USERSIG;
1763 } else if (strcmp(mem->desc, "prodsig") == 0) {
1764 cmd[3] = MTYPE_PRODSIG;
1765 } else if (strcmp(mem->desc, "calibration") == 0) {
1767 if (pgm->flag & PGM_FL_IS_DW)
1768 unsupp = 1;
1769 } else if (strcmp(mem->desc, "signature") == 0) {
1770 static unsigned char signature_cache[2];
1771
1772 cmd[3] = MTYPE_SIGN_JTAG;
1773
1774 /*
1775 * dW can read out the signature on JTAGICE3, but only allows
1776 * for a full three-byte read. We cache them in a local
1777 * variable to avoid multiple reads. This optimization does not
1778 * harm for other connection types either.
1779 */
1780 u32_to_b4(cmd + 8, 3);
1781 u32_to_b4(cmd + 4, 0);
1782
1783 if (addr == 0) {
1784 if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
1785 return -1;
1786
1787 signature_cache[0] = resp[4];
1788 signature_cache[1] = resp[5];
1789 *value = resp[3];
1790 free(resp);
1791 return 0;
1792 } else if (addr <= 2) {
1793 *value = signature_cache[addr - 1];
1794 return 0;
1795 } else {
1796 /* should not happen */
1797 avrdude_message(MSG_INFO, "address out of range for signature memory: %lu\n", addr);
1798 return -1;
1799 }
1800 }
1801
1802 /*
1803 * If the respective memory area is not supported under debugWire,
1804 * leave here.
1805 */
1806 if (unsupp) {
1807 *value = 42;
1808 return -1;
1809 }
1810
1811 /*
1812 * To improve the read speed, we used paged reads for flash and
1813 * EEPROM, and cache the results in a page cache.
1814 *
1815 * Page cache validation is based on "{flash,eeprom}_pageaddr"
1816 * (holding the base address of the most recent cache fill
1817 * operation). This variable is set to (unsigned long)-1L when the
1818 * cache needs to be invalidated.
1819 */
1820 if (pagesize && paddr == *paddr_ptr) {
1821 *value = cache_ptr[addr & (pagesize - 1)];
1822 return 0;
1823 }
1824
1825 if (pagesize) {
1826 u32_to_b4(cmd + 8, pagesize);
1827 u32_to_b4(cmd + 4, paddr);
1828 } else {
1829 u32_to_b4(cmd + 8, 1);
1830 u32_to_b4(cmd + 4, addr);
1831 }
1832
1833 if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
1834 return -1;
1835
1836 if (resp[1] != RSP3_DATA ||
1837 status < (pagesize? pagesize: 1) + 4) {
1838 avrdude_message(MSG_INFO, "%s: wrong/short reply to read memory command\n",
1839 progname);
1840 free(resp);
1841 return -1;
1842 }
1843
1844 if (pagesize) {
1845 *paddr_ptr = paddr;
1846 memcpy(cache_ptr, resp + 3, pagesize);
1847 *value = cache_ptr[addr & (pagesize - 1)];
1848 } else
1849 *value = resp[3];
1850
1851 free(resp);
1852 return 0;
1853}
#define MTYPE_LOCK_BITS
Definition jtag3_private.h:160
#define MTYPE_SIGN_JTAG
Definition jtag3_private.h:161
#define MTYPE_OSCCAL_BYTE
Definition jtag3_private.h:162
#define MTYPE_FUSE_BITS
Definition jtag3_private.h:159

References avrdude_message(), AVRPART_HAS_PDI, cmd, CMD3_READ_MEMORY, avrmem::desc, programmer_t::flag, avrpart::flags, free(), jtag3_command(), jtag3_program_enable(), MSG_INFO, MSG_NOTICE2, MTYPE_EEPROM, MTYPE_EEPROM_PAGE, MTYPE_FLASH, MTYPE_FLASH_PAGE, MTYPE_FUSE_BITS, MTYPE_LOCK_BITS, MTYPE_OSCCAL_BYTE, MTYPE_PRODSIG, MTYPE_SIGN_JTAG, MTYPE_USERSIG, avrmem::offset, avrmem::page_size, PDATA, pgm, PGM_FL_IS_DW, progname, RSP3_DATA, SCOPE_AVR, and u32_to_b4().

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), jtag3_pdi_initpgm(), and jtag3_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_recv()

int jtag3_recv ( PROGRAMMER pgm,
unsigned char **  msg 
)
774 {
775 unsigned short r_seqno;
776 int rv;
777
778 for (;;) {
779 if ((rv = jtag3_recv_frame(pgm, msg)) <= 0)
780 return rv;
781
782 if ((rv & USB_RECV_FLAG_EVENT) != 0) {
783 if (verbose >= 3)
785
786 free(*msg);
787 continue;
788 }
789
791 r_seqno = ((*msg)[2] << 8) | (*msg)[1];
792 avrdude_message(MSG_DEBUG, "%s: jtag3_recv(): "
793 "Got message seqno %d (command_sequence == %d)\n",
794 progname, r_seqno, PDATA(pgm)->command_sequence);
795 if (r_seqno == PDATA(pgm)->command_sequence) {
796 if (++(PDATA(pgm)->command_sequence) == 0xffff)
797 PDATA(pgm)->command_sequence = 0;
798 /*
799 * We move the payload to the beginning of the buffer, to make
800 * the job easier for the caller. We have to return the
801 * original pointer though, as the caller must free() it.
802 */
803 rv -= 3;
804 memmove(*msg, *msg + 3, rv);
805
806 return rv;
807 }
808 avrdude_message(MSG_NOTICE2, "%s: jtag3_recv(): "
809 "got wrong sequence number, %u != %u\n",
810 progname, r_seqno, PDATA(pgm)->command_sequence);
811
812 free(*msg);
813 }
814}
static int jtag3_recv_frame(PROGRAMMER *pgm, unsigned char **msg)
Definition jtag3.c:641
static void jtag3_prevent(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition jtag3.c:309
#define USB_RECV_FLAG_EVENT
Definition usbdevs.h:81
#define USB_RECV_LENGTH_MASK
Definition usbdevs.h:80

References avrdude_message(), free(), jtag3_prevent(), jtag3_recv_frame(), MSG_DEBUG, MSG_NOTICE2, PDATA, pgm, progname, USB_RECV_FLAG_EVENT, USB_RECV_LENGTH_MASK, and verbose.

Referenced by jtag3_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_recv_frame()

static int jtag3_recv_frame ( PROGRAMMER pgm,
unsigned char **  msg 
)
static
641 {
642 int rv;
643 unsigned char *buf = NULL;
644
645 if (pgm->flag & PGM_FL_IS_EDBG)
646 return jtag3_edbg_recv_frame(pgm, msg);
647
648 avrdude_message(MSG_TRACE, "%s: jtag3_recv():\n", progname);
649
650 if ((buf = malloc(pgm->fd.usb.max_xfer)) == NULL) {
651 avrdude_message(MSG_INFO, "%s: jtag3_recv(): out of memory\n",
652 progname);
653 return -1;
654 }
655 if (verbose >= 4)
656 memset(buf, 0, pgm->fd.usb.max_xfer);
657
658 rv = serial_recv(&pgm->fd, buf, pgm->fd.usb.max_xfer);
659
660 if (rv < 0) {
661 /* timeout in receive */
662 avrdude_message(MSG_NOTICE2, "%s: jtag3_recv(): Timeout receiving packet\n",
663 progname);
664 free(buf);
665 return -1;
666 }
667
668 *msg = buf;
669
670 return rv;
671}
static int jtag3_edbg_recv_frame(PROGRAMMER *pgm, unsigned char **msg)
Definition jtag3.c:673

References avrdude_message(), programmer_t::fd, programmer_t::flag, free(), jtag3_edbg_recv_frame(), malloc(), MSG_INFO, MSG_NOTICE2, MSG_TRACE, pgm, PGM_FL_IS_EDBG, progname, serial_recv, filedescriptor::usb, and verbose.

Referenced by jtag3_recv().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_send()

int jtag3_send ( PROGRAMMER pgm,
unsigned char *  data,
size_t  len 
)
402{
403 unsigned char *buf;
404
405 if (pgm->flag & PGM_FL_IS_EDBG)
406 return jtag3_edbg_send(pgm, data, len);
407
408 avrdude_message(MSG_DEBUG, "\n%s: jtag3_send(): sending %lu bytes\n",
409 progname, (unsigned long)len);
410
411 if ((buf = malloc(len + 4)) == NULL)
412 {
413 avrdude_message(MSG_INFO, "%s: jtag3_send(): out of memory",
414 progname);
415 return -1;
416 }
417
418 buf[0] = TOKEN;
419 buf[1] = 0; /* dummy */
420 u16_to_b2(buf + 2, PDATA(pgm)->command_sequence);
421 memcpy(buf + 4, data, len);
422
423 if (serial_send(&pgm->fd, buf, len + 4) != 0) {
424 avrdude_message(MSG_INFO, "%s: jtag3_send(): failed to send command to serial port\n",
425 progname);
426 return -1;
427 }
428
429 free(buf);
430
431 return 0;
432}
static int jtag3_edbg_send(PROGRAMMER *pgm, unsigned char *data, size_t len)
Definition jtag3.c:434

References avrdude_message(), programmer_t::fd, programmer_t::flag, free(), jtag3_edbg_send(), malloc(), MSG_DEBUG, MSG_INFO, PDATA, pgm, PGM_FL_IS_EDBG, progname, serial_send, TOKEN, and u16_to_b2().

Referenced by jtag3_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_set_sck_mega_jtag()

static int jtag3_set_sck_mega_jtag ( PROGRAMMER pgm,
unsigned char *  clk 
)
static
967{
968 return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, clk, 2);
969}

References jtag3_setparm(), PARM3_CLK_MEGA_PROG, pgm, and SCOPE_AVR.

Referenced by jtag3_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_set_sck_period()

static int jtag3_set_sck_period ( PROGRAMMER pgm,
double  v 
)
static
1973{
1974 unsigned char parm[2];
1975 unsigned int clock = 1E-3 / v; /* kHz */
1976
1977 parm[0] = clock & 0xff;
1978 parm[1] = (clock >> 8) & 0xff;
1979
1980 if (PDATA(pgm)->set_sck == NULL) {
1981 avrdude_message(MSG_INFO, "%s: No backend to set the SCK period for\n",
1982 progname);
1983 return -1;
1984 }
1985
1986 return (PDATA(pgm)->set_sck(pgm, parm) < 0)? -1: 0;
1987}

References avrdude_message(), MSG_INFO, PDATA, pgm, and progname.

Referenced by jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_set_sck_xmega_jtag()

static int jtag3_set_sck_xmega_jtag ( PROGRAMMER pgm,
unsigned char *  clk 
)
static
962{
963 return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_JTAG, clk, 2);
964}

References jtag3_setparm(), PARM3_CLK_XMEGA_JTAG, pgm, and SCOPE_AVR.

Referenced by jtag3_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_set_sck_xmega_pdi()

static int jtag3_set_sck_xmega_pdi ( PROGRAMMER pgm,
unsigned char *  clk 
)
static
957{
958 return jtag3_setparm(pgm, SCOPE_AVR, 1, PARM3_CLK_XMEGA_PDI, clk, 2);
959}

References jtag3_setparm(), PARM3_CLK_XMEGA_PDI, pgm, and SCOPE_AVR.

Referenced by jtag3_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_setparm()

int jtag3_setparm ( PROGRAMMER pgm,
unsigned char  scope,
unsigned char  section,
unsigned char  parm,
unsigned char *  value,
unsigned char  length 
)
2038{
2039 int status;
2040 unsigned char *buf, *resp;
2041 char descr[60];
2042
2043 avrdude_message(MSG_NOTICE2, "%s: jtag3_setparm()\n", progname);
2044
2045 sprintf(descr, "set parameter (scope 0x%02x, section %d, parm %d)",
2046 scope, section, parm);
2047
2048 if ((buf = malloc(6 + length)) == NULL)
2049 {
2050 avrdude_message(MSG_INFO, "%s: jtag3_setparm(): Out of memory\n",
2051 progname);
2052 return -1;
2053 }
2054
2055 buf[0] = scope;
2056 buf[1] = CMD3_SET_PARAMETER;
2057 buf[2] = 0;
2058 buf[3] = section;
2059 buf[4] = parm;
2060 buf[5] = length;
2061 memcpy(buf + 6, value, length);
2062
2063 status = jtag3_command(pgm, buf, length + 6, &resp, descr);
2064
2065 free(buf);
2066 if (status > 0)
2067 free(resp);
2068
2069 return status;
2070}
#define CMD3_SET_PARAMETER
Definition jtag3_private.h:108

References avrdude_message(), CMD3_SET_PARAMETER, free(), jtag3_command(), malloc(), MSG_INFO, MSG_NOTICE2, pgm, and progname.

Referenced by jtag3_initialize(), jtag3_set_sck_mega_jtag(), jtag3_set_sck_xmega_jtag(), and jtag3_set_sck_xmega_pdi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_setup()

void jtag3_setup ( PROGRAMMER pgm)
110{
111 if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
112 avrdude_message(MSG_INFO, "%s: jtag3_setup(): Out of memory allocating private data\n",
113 progname);
114 exit(1);
115 }
116 memset(pgm->cookie, 0, sizeof(struct pdata));
117}
Definition avr910.c:50
void * cookie
Definition libavrdude.h:689

References avrdude_message(), programmer_t::cookie, malloc(), MSG_INFO, pgm, and progname.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_teardown()

void jtag3_teardown ( PROGRAMMER pgm)
120{
121 free(pgm->cookie);
122}

References programmer_t::cookie, free(), and pgm.

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jtag3_write_byte()

static int jtag3_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
1857{
1858 unsigned char cmd[14];
1859 unsigned char *resp;
1860 unsigned char *cache_ptr = 0;
1861 int status, unsupp = 0;
1862 unsigned int pagesize = 0;
1863
1864 avrdude_message(MSG_NOTICE2, "%s: jtag3_write_byte(.., %s, 0x%lx, ...)\n",
1865 progname, mem->desc, addr);
1866
1867 cmd[0] = SCOPE_AVR;
1869 cmd[2] = 0;
1870 cmd[3] = ( p->flags & AVRPART_HAS_PDI ) ? MTYPE_FLASH : MTYPE_SPM;
1871 if (strcmp(mem->desc, "flash") == 0) {
1872 cache_ptr = PDATA(pgm)->flash_pagecache;
1873 pagesize = PDATA(pgm)->flash_pagesize;
1874 PDATA(pgm)->flash_pageaddr = (unsigned long)-1L;
1875 if (pgm->flag & PGM_FL_IS_DW)
1876 unsupp = 1;
1877 } else if (strcmp(mem->desc, "eeprom") == 0) {
1878 if (pgm->flag & PGM_FL_IS_DW) {
1879 cmd[3] = MTYPE_EEPROM;
1880 } else {
1881 cache_ptr = PDATA(pgm)->eeprom_pagecache;
1882 pagesize = PDATA(pgm)->eeprom_pagesize;
1883 }
1884 PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
1885 } else if (strcmp(mem->desc, "lfuse") == 0) {
1886 cmd[3] = MTYPE_FUSE_BITS;
1887 addr = 0;
1888 if (pgm->flag & PGM_FL_IS_DW)
1889 unsupp = 1;
1890 } else if (strcmp(mem->desc, "hfuse") == 0) {
1891 cmd[3] = MTYPE_FUSE_BITS;
1892 addr = 1;
1893 if (pgm->flag & PGM_FL_IS_DW)
1894 unsupp = 1;
1895 } else if (strcmp(mem->desc, "efuse") == 0) {
1896 cmd[3] = MTYPE_FUSE_BITS;
1897 addr = 2;
1898 if (pgm->flag & PGM_FL_IS_DW)
1899 unsupp = 1;
1900 } else if (strncmp(mem->desc, "fuse", strlen("fuse")) == 0) {
1901 cmd[3] = MTYPE_FUSE_BITS;
1902 addr = mem->offset & 7;
1903 } else if (strcmp(mem->desc, "usersig") == 0) {
1904 cmd[3] = MTYPE_USERSIG;
1905 } else if (strcmp(mem->desc, "prodsig") == 0) {
1906 cmd[3] = MTYPE_PRODSIG;
1907 } else if (strncmp(mem->desc, "lock", 4) == 0) {
1908 cmd[3] = MTYPE_LOCK_BITS;
1909 if (pgm->flag & PGM_FL_IS_DW)
1910 unsupp = 1;
1911 } else if (strcmp(mem->desc, "calibration") == 0) {
1913 if (pgm->flag & PGM_FL_IS_DW)
1914 unsupp = 1;
1915 } else if (strcmp(mem->desc, "signature") == 0) {
1916 cmd[3] = MTYPE_SIGN_JTAG;
1917 if (pgm->flag & PGM_FL_IS_DW)
1918 unsupp = 1;
1919 }
1920
1921 if (unsupp)
1922 return -1;
1923
1924 if (pagesize != 0) {
1925 /* flash or EEPROM write: use paged algorithm */
1926 unsigned char dummy;
1927 int i;
1928
1929 /* step #1: ensure the page cache is up to date */
1930 if (jtag3_read_byte(pgm, p, mem, addr, &dummy) < 0)
1931 return -1;
1932 /* step #2: update our value in page cache, and copy
1933 * cache to mem->buf */
1934 cache_ptr[addr & (pagesize - 1)] = data;
1935 addr &= ~(pagesize - 1); /* page base address */
1936 memcpy(mem->buf + addr, cache_ptr, pagesize);
1937 /* step #3: write back */
1938 i = jtag3_paged_write(pgm, p, mem, pagesize, addr, pagesize);
1939 if (i < 0)
1940 return -1;
1941 else
1942 return 0;
1943 }
1944
1945 /* non-paged writes go here */
1946 if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
1947 return -1;
1948
1949 u32_to_b4(cmd + 8, 1);
1950 u32_to_b4(cmd + 4, addr);
1951 cmd[12] = 0;
1952 cmd[13] = data;
1953
1954 if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0)
1955 return -1;
1956
1957 free(resp);
1958
1959 return 0;
1960}

References avrdude_message(), AVRPART_HAS_PDI, avrmem::buf, cmd, CMD3_WRITE_MEMORY, avrmem::desc, programmer_t::flag, avrpart::flags, free(), jtag3_command(), jtag3_paged_write(), jtag3_program_enable(), jtag3_read_byte(), long, MSG_NOTICE2, MTYPE_EEPROM, MTYPE_FLASH, MTYPE_FUSE_BITS, MTYPE_LOCK_BITS, MTYPE_OSCCAL_BYTE, MTYPE_PRODSIG, MTYPE_SIGN_JTAG, MTYPE_SPM, MTYPE_USERSIG, avrmem::offset, PDATA, pgm, PGM_FL_IS_DW, progname, SCOPE_AVR, and u32_to_b4().

Referenced by jtag3_dw_initpgm(), jtag3_initpgm(), jtag3_paged_write(), and jtag3_pdi_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u16_to_b2()

static void u16_to_b2 ( unsigned char *  b,
unsigned short  l 
)
static
158{
159 b[0] = l & 0xff;
160 b[1] = (l >> 8) & 0xff;
161}

Referenced by jtag3_edbg_send(), jtag3_initialize(), and jtag3_send().

+ Here is the caller graph for this function:

◆ u32_to_b4()

static void u32_to_b4 ( unsigned char *  b,
unsigned long  l 
)
static
139{
140 b[0] = l & 0xff;
141 b[1] = (l >> 8) & 0xff;
142 b[2] = (l >> 16) & 0xff;
143 b[3] = (l >> 24) & 0xff;
144}

Referenced by jtag3_initialize(), jtag3_page_erase(), jtag3_paged_load(), jtag3_paged_write(), jtag3_read_byte(), and jtag3_write_byte().

+ Here is the caller graph for this function:

Variable Documentation

◆ jtag3_desc

const char jtag3_desc[] = "Atmel JTAGICE3"

◆ jtag3_dw_desc

const char jtag3_dw_desc[] = "Atmel JTAGICE3 in debugWire mode"

◆ jtag3_pdi_desc

const char jtag3_pdi_desc[] = "Atmel JTAGICE3 in PDI mode"