Fix a number of logic errors in the previous commits
RSP3_FAIL_CRC_FAILURE is 0x43 rather than 0x47. jtag3_errcode() must only be applied to a reason code, not to any general status code.
This commit is contained in:
parent
8953967fc3
commit
f22b81c00e
30
src/jtag3.c
30
src/jtag3.c
|
@ -313,12 +313,10 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jtag3_errcode(int status)
|
static int jtag3_errcode(int reason)
|
||||||
{
|
{
|
||||||
if (status >= LIBAVRDUDE_SUCCESS)
|
if (reason == RSP3_FAIL_OCD_LOCKED ||
|
||||||
return status;
|
reason == RSP3_FAIL_CRC_FAILURE)
|
||||||
if (status == RSP3_FAIL_OCD_LOCKED ||
|
|
||||||
status == RSP3_FAIL_CRC_FAILURE)
|
|
||||||
return LIBAVRDUDE_SOFTFAIL;
|
return LIBAVRDUDE_SOFTFAIL;
|
||||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -868,9 +866,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
|
||||||
avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status);
|
avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status);
|
||||||
}
|
}
|
||||||
|
|
||||||
c = (*resp)[1];
|
c = (*resp)[1] & RSP3_STATUS_MASK;
|
||||||
if ((c & RSP3_STATUS_MASK) != RSP3_OK) {
|
if (c != RSP3_OK) {
|
||||||
if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED)) {
|
if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED ||
|
||||||
|
(*resp)[3] == RSP3_FAIL_CRC_FAILURE)) {
|
||||||
avrdude_message(MSG_INFO,
|
avrdude_message(MSG_INFO,
|
||||||
"%s: Device is locked! Chip erase required to unlock.\n",
|
"%s: Device is locked! Chip erase required to unlock.\n",
|
||||||
progname);
|
progname);
|
||||||
|
@ -881,11 +880,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
|
||||||
status = (*resp)[3];
|
status = (*resp)[3];
|
||||||
free(*resp);
|
free(*resp);
|
||||||
resp = 0;
|
resp = 0;
|
||||||
|
|
||||||
return jtag3_errcode(status);
|
return jtag3_errcode(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LIBAVRDUDE_SUCCESS;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1001,7 +999,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm)
|
||||||
return LIBAVRDUDE_SUCCESS;
|
return LIBAVRDUDE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jtag3_program_disable(PROGRAMMER * pgm)
|
static int jtag3_program_disable(PROGRAMMER * pgm)
|
||||||
|
@ -1932,7 +1930,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
|
||||||
|
|
||||||
if (!(pgm->flag & PGM_FL_IS_DW))
|
if (!(pgm->flag & PGM_FL_IS_DW))
|
||||||
if ((status = jtag3_program_enable(pgm)) < 0)
|
if ((status = jtag3_program_enable(pgm)) < 0)
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
|
|
||||||
cmd[0] = SCOPE_AVR;
|
cmd[0] = SCOPE_AVR;
|
||||||
cmd[1] = CMD3_READ_MEMORY;
|
cmd[1] = CMD3_READ_MEMORY;
|
||||||
|
@ -2018,7 +2016,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
|
||||||
|
|
||||||
if (addr == 0) {
|
if (addr == 0) {
|
||||||
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
|
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
|
|
||||||
signature_cache[0] = resp[4];
|
signature_cache[0] = resp[4];
|
||||||
signature_cache[1] = resp[5];
|
signature_cache[1] = resp[5];
|
||||||
|
@ -2068,7 +2066,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
|
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0)
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
|
|
||||||
if (resp[1] != RSP3_DATA ||
|
if (resp[1] != RSP3_DATA ||
|
||||||
status < (pagesize? pagesize: 1) + 4) {
|
status < (pagesize? pagesize: 1) + 4) {
|
||||||
|
@ -2196,7 +2194,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
|
||||||
cmd[13] = data;
|
cmd[13] = data;
|
||||||
|
|
||||||
if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0)
|
if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0)
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
|
|
||||||
free(resp);
|
free(resp);
|
||||||
|
|
||||||
|
@ -2327,7 +2325,7 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib)
|
||||||
u32_to_b4(cmd + 8, AVR_SIBLEN);
|
u32_to_b4(cmd + 8, AVR_SIBLEN);
|
||||||
|
|
||||||
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0)
|
if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0)
|
||||||
return jtag3_errcode(status);
|
return status;
|
||||||
|
|
||||||
memcpy(sib, resp+3, AVR_SIBLEN);
|
memcpy(sib, resp+3, AVR_SIBLEN);
|
||||||
sib[AVR_SIBLEN] = 0; // Zero terminate string
|
sib[AVR_SIBLEN] = 0; // Zero terminate string
|
||||||
|
|
|
@ -144,8 +144,8 @@
|
||||||
# define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */
|
# define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */
|
||||||
# define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */
|
# define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */
|
||||||
# define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */
|
# define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */
|
||||||
|
# define RSP3_FAIL_CRC_FAILURE 0x43 /* CRC failure in device */
|
||||||
# define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */
|
# define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */
|
||||||
# define RSP3_FAIL_CRC_FAILURE 0x47 /* CRC failure in device */
|
|
||||||
# define RSP3_FAIL_NOT_UNDERSTOOD 0x91
|
# define RSP3_FAIL_NOT_UNDERSTOOD 0x91
|
||||||
|
|
||||||
/* ICE events */
|
/* ICE events */
|
||||||
|
|
Loading…
Reference in New Issue