Cleaned up whitespace in jtag3.c so it at least is consistent within the file.

This commit is contained in:
Jan Egil Ruud 2022-11-22 13:05:14 +01:00
parent 10ccf0f515
commit 32a6ca39e4
2 changed files with 257 additions and 298 deletions

View File

@ -239,8 +239,7 @@ static void jtag3_prmsg(const PROGRAMMER *pgm, unsigned char *data, size_t len)
{ {
char reason[50]; char reason[50];
sprintf(reason, "0x%02x", data[3]); sprintf(reason, "0x%02x", data[3]);
switch (data[3]) switch (data[3]) {
{
case RSP3_FAIL_NO_ANSWER: case RSP3_FAIL_NO_ANSWER:
strcpy(reason, "target does not answer"); strcpy(reason, "target does not answer");
break; break;
@ -275,8 +274,7 @@ static void jtag3_prmsg(const PROGRAMMER *pgm, unsigned char *data, size_t len)
} }
msg_info(", reason: %s\n", reason); msg_info(", reason: %s\n", reason);
} }
else else {
{
msg_info(", unspecified reason\n"); msg_info(", unspecified reason\n");
} }
break; break;
@ -298,12 +296,10 @@ static void jtag3_prmsg(const PROGRAMMER *pgm, unsigned char *data, size_t len)
break; break;
case RSP3_PC: case RSP3_PC:
if (len < 7) if (len < 7) {
{
msg_info("PC reply too short\n"); msg_info("PC reply too short\n");
} }
else else {
{
unsigned long pc = (data[6] << 24) | (data[5] << 16) unsigned long pc = (data[6] << 24) | (data[5] << 16)
| (data[4] << 8) | data[3]; | (data[4] << 8) | data[3];
msg_info("PC 0x%0lx\n", pc); msg_info("PC 0x%0lx\n", pc);
@ -411,8 +407,6 @@ static void jtag3_prevent(const PROGRAMMER *pgm, unsigned char *data, size_t len
msg_info("\n"); msg_info("\n");
} }
int jtag3_send(const PROGRAMMER *pgm, unsigned char *data, size_t len) { int jtag3_send(const PROGRAMMER *pgm, unsigned char *data, size_t len) {
unsigned char *buf; unsigned char *buf;
@ -422,8 +416,7 @@ int jtag3_send(const PROGRAMMER *pgm, unsigned char *data, size_t len) {
msg_debug("\n"); msg_debug("\n");
pmsg_debug("jtag3_send(): sending %lu bytes\n", (unsigned long) len); pmsg_debug("jtag3_send(): sending %lu bytes\n", (unsigned long) len);
if ((buf = malloc(len + 4)) == NULL) if ((buf = malloc(len + 4)) == NULL) {
{
pmsg_error("out of memory"); pmsg_error("out of memory");
return -1; return -1;
} }
@ -449,8 +442,7 @@ static int jtag3_edbg_send(const PROGRAMMER *pgm, unsigned char *data, size_t le
unsigned char status[USBDEV_MAX_XFER_3]; unsigned char status[USBDEV_MAX_XFER_3];
int rv; int rv;
if (verbose >= 4) if (verbose >= 4) {
{
memset(buf, 0, USBDEV_MAX_XFER_3); memset(buf, 0, USBDEV_MAX_XFER_3);
memset(status, 0, USBDEV_MAX_XFER_3); memset(status, 0, USBDEV_MAX_XFER_3);
} }
@ -461,13 +453,11 @@ static int jtag3_edbg_send(const PROGRAMMER *pgm, unsigned char *data, size_t le
/* 4 bytes overhead for CMD, fragment #, and length info */ /* 4 bytes overhead for CMD, fragment #, and length info */
int max_xfer = pgm->fd.usb.max_xfer; int max_xfer = pgm->fd.usb.max_xfer;
int nfragments = (len + max_xfer - 1) / max_xfer; int nfragments = (len + max_xfer - 1) / max_xfer;
if (nfragments > 1) if (nfragments > 1) {
{
pmsg_debug("jtag3_edbg_send(): fragmenting into %d packets\n", nfragments); pmsg_debug("jtag3_edbg_send(): fragmenting into %d packets\n", nfragments);
} }
int frag; int frag;
for (frag = 0; frag < nfragments; frag++) for (frag = 0; frag < nfragments; frag++) {
{
int this_len; int this_len;
/* All fragments have the (CMSIS-DAP layer) CMD, the fragment /* All fragments have the (CMSIS-DAP layer) CMD, the fragment
@ -475,8 +465,7 @@ static int jtag3_edbg_send(const PROGRAMMER *pgm, unsigned char *data, size_t le
buf[0] = EDBG_VENDOR_AVR_CMD; buf[0] = EDBG_VENDOR_AVR_CMD;
buf[1] = ((frag + 1) << 4) | nfragments; buf[1] = ((frag + 1) << 4) | nfragments;
if (frag == 0) if (frag == 0) {
{
/* Only first fragment has TOKEN and seq#, thus four bytes /* Only first fragment has TOKEN and seq#, thus four bytes
* less payload than subsequent fragments. */ * less payload than subsequent fragments. */
this_len = len < max_xfer - 8? len: max_xfer - 8; this_len = len < max_xfer - 8? len: max_xfer - 8;
@ -487,8 +476,7 @@ static int jtag3_edbg_send(const PROGRAMMER *pgm, unsigned char *data, size_t le
u16_to_b2(buf + 6, PDATA(pgm)->command_sequence); u16_to_b2(buf + 6, PDATA(pgm)->command_sequence);
memcpy(buf + 8, data, this_len); memcpy(buf + 8, data, this_len);
} }
else else {
{
this_len = len < max_xfer - 4? len: max_xfer - 4; this_len = len < max_xfer - 4? len: max_xfer - 4;
buf[2] = (this_len) >> 8; buf[2] = (this_len) >> 8;
buf[3] = (this_len) & 0xff; buf[3] = (this_len) & 0xff;
@ -507,8 +495,7 @@ static int jtag3_edbg_send(const PROGRAMMER *pgm, unsigned char *data, size_t le
return -1; return -1;
} }
if (status[0] != EDBG_VENDOR_AVR_CMD || if (status[0] != EDBG_VENDOR_AVR_CMD ||
(frag == nfragments - 1 && status[1] != 0x01)) (frag == nfragments - 1 && status[1] != 0x01)) {
{
/* what to do in this case? */ /* what to do in this case? */
pmsg_notice("jtag3_edbg_send(): unexpected response 0x%02x, 0x%02x\n", status[0], status[1]); pmsg_notice("jtag3_edbg_send(): unexpected response 0x%02x, 0x%02x\n", status[0], status[1]);
} }
@ -803,8 +790,7 @@ int jtag3_recv(const PROGRAMMER *pgm, unsigned char **msg) {
} }
int jtag3_command(const PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, int jtag3_command(const PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen,
unsigned char **resp, const char *descr) unsigned char **resp, const char *descr) {
{
int status; int status;
unsigned char c; unsigned char c;
@ -825,8 +811,8 @@ int jtag3_command(const PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen
c = (*resp)[1] & RSP3_STATUS_MASK; c = (*resp)[1] & RSP3_STATUS_MASK;
if (c != RSP3_OK) { if (c != RSP3_OK) {
if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED || if ((c == RSP3_FAILED) &&
(*resp)[3] == RSP3_FAIL_CRC_FAILURE)) { ((*resp)[3] == RSP3_FAIL_OCD_LOCKED || (*resp)[3] == RSP3_FAIL_CRC_FAILURE)) {
pmsg_error("device is locked; chip erase required to unlock\n"); pmsg_error("device is locked; chip erase required to unlock\n");
} else { } else {
pmsg_notice("bad response to %s command: 0x%02x\n", descr, c); pmsg_notice("bad response to %s command: 0x%02x\n", descr, c);
@ -919,9 +905,7 @@ static int jtag3_unlock_erase_key(const PROGRAMMER *pgm, const AVRPART *p) {
* There is no chip erase functionality in debugWire mode. * There is no chip erase functionality in debugWire mode.
*/ */
static int jtag3_chip_erase_dw(const PROGRAMMER *pgm, const AVRPART *p) { static int jtag3_chip_erase_dw(const PROGRAMMER *pgm, const AVRPART *p) {
pmsg_error("chip erase not supported in debugWire mode\n"); pmsg_error("chip erase not supported in debugWire mode\n");
return 0; return 0;
} }
@ -1068,8 +1052,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
else else
PDATA(pgm)->set_sck = jtag3_set_sck_mega_jtag; PDATA(pgm)->set_sck = jtag3_set_sck_mega_jtag;
} }
if (pgm->bitclock != 0.0 && PDATA(pgm)->set_sck != NULL) if (pgm->bitclock != 0.0 && PDATA(pgm)->set_sck != NULL) {
{
unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */ unsigned int clock = 1E-3 / pgm->bitclock; /* kHz */
pmsg_notice2("jtag3_initialize(): " pmsg_notice2("jtag3_initialize(): "
"trying to set JTAG clock to %u kHz\n", clock); "trying to set JTAG clock to %u kHz\n", clock);
@ -1079,8 +1062,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
return -1; return -1;
} }
jtag3_print_parms1(pgm, progbuf, stderr); jtag3_print_parms1(pgm, progbuf, stderr);
if (conn == PARM3_CONN_JTAG) if (conn == PARM3_CONN_JTAG) {
{
pmsg_notice2("jtag3_initialize(): " pmsg_notice2("jtag3_initialize(): "
"trying to set JTAG daisy-chain info to %d,%d,%d,%d\n", "trying to set JTAG daisy-chain info to %d,%d,%d,%d\n",
PDATA(pgm)->jtagchain[0], PDATA(pgm)->jtagchain[1], PDATA(pgm)->jtagchain[0], PDATA(pgm)->jtagchain[1],
@ -1090,8 +1072,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
} }
/* set device descriptor data */ /* set device descriptor data */
if ((p->prog_modes & PM_PDI)) if ((p->prog_modes & PM_PDI)) {
{
struct xmega_device_desc xd; struct xmega_device_desc xd;
LNODEID ln; LNODEID ln;
AVRMEM * m; AVRMEM * m;
@ -1135,8 +1116,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&xd, sizeof xd) < 0) if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&xd, sizeof xd) < 0)
return -1; return -1;
} }
else if ((p->prog_modes & PM_UPDI)) else if ((p->prog_modes & PM_UPDI)) {
{
struct updi_device_desc xd; struct updi_device_desc xd;
LNODEID ln; LNODEID ln;
AVRMEM *m; AVRMEM *m;
@ -1145,11 +1125,9 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
u16_to_b2(xd.ocd_base_addr, p->ocd_base); u16_to_b2(xd.ocd_base_addr, p->ocd_base);
xd.hvupdi_variant = p->hvupdi_variant; xd.hvupdi_variant = p->hvupdi_variant;
for (ln = lfirst(p->mem); ln; ln = lnext(ln)) for (ln = lfirst(p->mem); ln; ln = lnext(ln)) {
{
m = ldata(ln); m = ldata(ln);
if (strcmp(m->desc, "flash") == 0) if (strcmp(m->desc, "flash") == 0) {
{
u16_to_b2(xd.prog_base, m->offset&0xFFFF); u16_to_b2(xd.prog_base, m->offset&0xFFFF);
xd.prog_base_msb = m->offset>>16; xd.prog_base_msb = m->offset>>16;
@ -1167,8 +1145,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
else else
xd.address_mode = UPDI_ADDRESS_MODE_16BIT; xd.address_mode = UPDI_ADDRESS_MODE_16BIT;
} }
else if (strcmp(m->desc, "eeprom") == 0) else if (strcmp(m->desc, "eeprom") == 0) {
{
PDATA(pgm)->eeprom_pagesize = m->page_size; PDATA(pgm)->eeprom_pagesize = m->page_size;
xd.eeprom_page_size = m->page_size; xd.eeprom_page_size = m->page_size;
@ -1176,24 +1153,20 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
u16_to_b2(xd.eeprom_base, m->offset); u16_to_b2(xd.eeprom_base, m->offset);
} }
else if (strcmp(m->desc, "usersig") == 0 || else if (strcmp(m->desc, "usersig") == 0 ||
strcmp(m->desc, "userrow") == 0) strcmp(m->desc, "userrow") == 0) {
{
u16_to_b2(xd.user_sig_bytes, m->size); u16_to_b2(xd.user_sig_bytes, m->size);
u16_to_b2(xd.user_sig_base, m->offset); u16_to_b2(xd.user_sig_base, m->offset);
} }
else if (strcmp(m->desc, "signature") == 0) else if (strcmp(m->desc, "signature") == 0) {
{
u16_to_b2(xd.signature_base, m->offset); u16_to_b2(xd.signature_base, m->offset);
xd.device_id[0] = p->signature[1]; xd.device_id[0] = p->signature[1];
xd.device_id[1] = p->signature[2]; xd.device_id[1] = p->signature[2];
} }
else if (strcmp(m->desc, "fuses") == 0) else if (strcmp(m->desc, "fuses") == 0) {
{
xd.fuses_bytes = m->size; xd.fuses_bytes = m->size;
u16_to_b2(xd.fuses_base, m->offset); u16_to_b2(xd.fuses_base, m->offset);
} }
else if (strcmp(m->desc, "lock") == 0) else if (strcmp(m->desc, "lock") == 0) {
{
u16_to_b2(xd.lockbits_base, m->offset); u16_to_b2(xd.lockbits_base, m->offset);
} }
} }
@ -1251,8 +1224,7 @@ static int jtag3_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&xd, sizeof xd) < 0) if (jtag3_setparm(pgm, SCOPE_AVR, 2, PARM3_DEVICEDESC, (unsigned char *)&xd, sizeof xd) < 0)
return -1; return -1;
} }
else else {
{
struct mega_device_desc md; struct mega_device_desc md;
LNODEID ln; LNODEID ln;
AVRMEM * m; AVRMEM * m;
@ -1413,8 +1385,7 @@ static int jtag3_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
if (matches(extended_param, "jtagchain=")) { if (matches(extended_param, "jtagchain=")) {
unsigned int ub, ua, bb, ba; unsigned int ub, ua, bb, ba;
if (sscanf(extended_param, "jtagchain=%u,%u,%u,%u", &ub, &ua, &bb, &ba) if (sscanf(extended_param, "jtagchain=%u,%u,%u,%u", &ub, &ua, &bb, &ba) != 4) {
!= 4) {
pmsg_error("invalid JTAG chain '%s'\n", extended_param); pmsg_error("invalid JTAG chain '%s'\n", extended_param);
rv = -1; rv = -1;
continue; continue;
@ -1542,8 +1513,7 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port) {
return -1; return -1;
} }
if (pgm->fd.usb.eep == 0) if (pgm->fd.usb.eep == 0) {
{
/* The event EP has been deleted by usb_open(), so we are /* The event EP has been deleted by usb_open(), so we are
running on a CMSIS-DAP device, using EDBG protocol */ running on a CMSIS-DAP device, using EDBG protocol */
pgm->flag |= PGM_FL_IS_EDBG; pgm->flag |= PGM_FL_IS_EDBG;
@ -1614,8 +1584,7 @@ static int jtag3_open_updi(PROGRAMMER *pgm, const char *port) {
return 0; return 0;
} }
void jtag3_close(PROGRAMMER * pgm) void jtag3_close(PROGRAMMER * pgm) {
{
unsigned char buf[4], *resp; unsigned char buf[4], *resp;
pmsg_notice2("jtag3_close()\n"); pmsg_notice2("jtag3_close()\n");
@ -1645,8 +1614,7 @@ void jtag3_close(PROGRAMMER * pgm)
} }
static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned int addr) unsigned int addr) {
{
unsigned char cmd[8], *resp; unsigned char cmd[8], *resp;
pmsg_notice2("jtag3_page_erase(.., %s, 0x%x)\n", m->desc, addr); pmsg_notice2("jtag3_page_erase(.., %s, 0x%x)\n", m->desc, addr);
@ -1693,8 +1661,7 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
static int jtag3_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, static int jtag3_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes) {
{
unsigned int block_size; unsigned int block_size;
unsigned int maxaddr = addr + n_bytes; unsigned int maxaddr = addr + n_bytes;
unsigned char *cmd; unsigned char *cmd;
@ -1712,7 +1679,8 @@ static int jtag3_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0) if (!(pgm->flag & PGM_FL_IS_DW) && jtag3_program_enable(pgm) < 0)
return -1; return -1;
if (page_size == 0) page_size = 256; if (page_size == 0)
page_size = 256;
if ((cmd = malloc(page_size + 13)) == NULL) { if ((cmd = malloc(page_size + 13)) == NULL) {
pmsg_error("out of memory\n"); pmsg_error("out of memory\n");
@ -1800,8 +1768,7 @@ static int jtag3_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const AVRM
static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned int page_size, unsigned int page_size,
unsigned int addr, unsigned int n_bytes) unsigned int addr, unsigned int n_bytes) {
{
unsigned int block_size; unsigned int block_size;
unsigned int maxaddr = addr + n_bytes; unsigned int maxaddr = addr + n_bytes;
unsigned char cmd[12]; unsigned char cmd[12];
@ -1883,8 +1850,7 @@ static int jtag3_paged_load(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
} }
static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char * value) unsigned long addr, unsigned char * value) {
{
unsigned char cmd[12]; unsigned char cmd[12];
unsigned char *resp, *cache_ptr = NULL; unsigned char *resp, *cache_ptr = NULL;
int status, unsupp = 0; int status, unsupp = 0;
@ -2054,8 +2020,7 @@ static int jtag3_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
} }
static int jtag3_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int jtag3_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char data) unsigned long addr, unsigned char data) {
{
unsigned char cmd[14]; unsigned char cmd[14];
unsigned char *resp; unsigned char *resp;
unsigned char *cache_ptr = 0; unsigned char *cache_ptr = 0;
@ -2197,8 +2162,7 @@ static int jtag3_set_sck_period(const PROGRAMMER *pgm, double v) {
*/ */
int jtag3_getparm(const PROGRAMMER *pgm, unsigned char scope, int jtag3_getparm(const PROGRAMMER *pgm, unsigned char scope,
unsigned char section, unsigned char parm, unsigned char section, unsigned char parm,
unsigned char *value, unsigned char length) unsigned char *value, unsigned char length) {
{
int status; int status;
unsigned char buf[6], *resp, c; unsigned char buf[6], *resp, c;
char descr[60]; char descr[60];
@ -2237,8 +2201,7 @@ int jtag3_getparm(const PROGRAMMER *pgm, unsigned char scope,
*/ */
int jtag3_setparm(const PROGRAMMER *pgm, unsigned char scope, int jtag3_setparm(const PROGRAMMER *pgm, unsigned char scope,
unsigned char section, unsigned char parm, unsigned char section, unsigned char parm,
unsigned char *value, unsigned char length) unsigned char *value, unsigned char length) {
{
int status; int status;
unsigned char *buf, *resp; unsigned char *buf, *resp;
char descr[60]; char descr[60];
@ -2248,8 +2211,7 @@ int jtag3_setparm(const PROGRAMMER *pgm, unsigned char scope,
sprintf(descr, "set parameter (scope 0x%02x, section %d, parm %d)", sprintf(descr, "set parameter (scope 0x%02x, section %d, parm %d)",
scope, section, parm); scope, section, parm);
if ((buf = malloc(6 + length)) == NULL) if ((buf = malloc(6 + length)) == NULL) {
{
pmsg_error("out of memory\n"); pmsg_error("out of memory\n");
return -1; return -1;
} }
@ -2349,8 +2311,7 @@ static void jtag3_display(const PROGRAMMER *pgm, const char *p) {
resp[status - 3] = 0; resp[status - 3] = 0;
msg_info("%sICE HW version : %d\n", p, parms[0]); msg_info("%sICE HW version : %d\n", p, parms[0]);
msg_info("%sICE FW version : %d.%02d (rel. %d)\n", p, msg_info("%sICE FW version : %d.%02d (rel. %d)\n", p, parms[1], parms[2],
parms[1], parms[2],
(parms[3] | (parms[4] << 8))); (parms[3] | (parms[4] << 8)));
msg_info("%sSerial number : %s", p, resp); msg_info("%sSerial number : %s", p, resp);
free(resp); free(resp);
@ -2622,8 +2583,7 @@ static void jtag3_disable_tpi(const PROGRAMMER *pgm) {
} }
static int jtag3_read_byte_tpi(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, static int jtag3_read_byte_tpi(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char * value) unsigned long addr, unsigned char * value) {
{
int result, pollidx; int result, pollidx;
unsigned char buf[8]; unsigned char buf[8];
unsigned long paddr = 0UL, *paddr_ptr = NULL; unsigned long paddr = 0UL, *paddr_ptr = NULL;
@ -2634,7 +2594,6 @@ static int jtag3_read_byte_tpi(const PROGRAMMER *pgm, const AVRPART *p, const AV
pmsg_notice2("jtag3_read_byte_tpi(.., %s, 0x%lx, ...)\n", mem->desc, addr); pmsg_notice2("jtag3_read_byte_tpi(.., %s, 0x%lx, ...)\n", mem->desc, addr);
buf[0] = XPRG_CMD_READ_MEM; buf[0] = XPRG_CMD_READ_MEM;
if (strcmp(mem->desc, "lfuse") == 0 || if (strcmp(mem->desc, "lfuse") == 0 ||