Merge pull request #996 from dl8dtl/jtag3_retcode
Replace internal knowledge in jtag3.c by a public API Supersedes #982
This commit is contained in:
commit
7ec51a5185
12
src/avr.c
12
src/avr.c
|
@ -439,16 +439,16 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
|
|||
(vmem->tags[i] & TAG_ALLOCATED) != 0)
|
||||
{
|
||||
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
|
||||
if (rc != 0) {
|
||||
if (rc != LIBAVRDUDE_SUCCESS) {
|
||||
avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i);
|
||||
if (rc == -1) {
|
||||
if (rc == LIBAVRDUDE_GENERAL_FAILURE) {
|
||||
avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n",
|
||||
memtype);
|
||||
return -2;
|
||||
return LIBAVRDUDE_NOTSUPPORTED;
|
||||
}
|
||||
avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n",
|
||||
memtype);
|
||||
return rc;
|
||||
return LIBAVRDUDE_SOFTFAIL;
|
||||
}
|
||||
}
|
||||
report_progress(i, mem->size, NULL);
|
||||
|
@ -1035,14 +1035,14 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p)
|
|||
|
||||
report_progress (0,1,"Reading");
|
||||
rc = avr_read(pgm, p, "signature", 0);
|
||||
if (rc < 0) {
|
||||
if (rc < LIBAVRDUDE_SUCCESS) {
|
||||
avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
|
||||
progname, p->desc, rc);
|
||||
return rc;
|
||||
}
|
||||
report_progress (1,1,NULL);
|
||||
|
||||
return 0;
|
||||
return LIBAVRDUDE_SUCCESS;
|
||||
}
|
||||
|
||||
static uint8_t get_fuse_bitmask(AVRMEM * m) {
|
||||
|
|
21
src/jtag3.c
21
src/jtag3.c
|
@ -313,6 +313,14 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
static int jtag3_errcode(int reason)
|
||||
{
|
||||
if (reason == RSP3_FAIL_OCD_LOCKED ||
|
||||
reason == RSP3_FAIL_CRC_FAILURE)
|
||||
return LIBAVRDUDE_SOFTFAIL;
|
||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
@ -850,7 +858,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
|
|||
putc('\n', stderr);
|
||||
avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n",
|
||||
progname, descr, status);
|
||||
return -1;
|
||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||
} else if (verbose >= 3) {
|
||||
putc('\n', stderr);
|
||||
jtag3_prmsg(pgm, *resp, status);
|
||||
|
@ -858,9 +866,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
|
|||
avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status);
|
||||
}
|
||||
|
||||
c = (*resp)[1];
|
||||
if ((c & RSP3_STATUS_MASK) != RSP3_OK) {
|
||||
if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED)) {
|
||||
c = (*resp)[1] & RSP3_STATUS_MASK;
|
||||
if (c != RSP3_OK) {
|
||||
if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED ||
|
||||
(*resp)[3] == RSP3_FAIL_CRC_FAILURE)) {
|
||||
avrdude_message(MSG_INFO,
|
||||
"%s: Device is locked! Chip erase required to unlock.\n",
|
||||
progname);
|
||||
|
@ -871,7 +880,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
|
|||
status = (*resp)[3];
|
||||
free(*resp);
|
||||
resp = 0;
|
||||
return -status;
|
||||
return jtag3_errcode(status);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -987,7 +996,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm)
|
|||
free(resp);
|
||||
PDATA(pgm)->prog_enabled = 1;
|
||||
|
||||
return 0;
|
||||
return LIBAVRDUDE_SUCCESS;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
@ -144,6 +144,7 @@
|
|||
# define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */
|
||||
# define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */
|
||||
# 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_NOT_UNDERSTOOD 0x91
|
||||
|
||||
|
|
|
@ -27,6 +27,16 @@
|
|||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t pinmask_t;
|
||||
/*
|
||||
* Values returned by library functions.
|
||||
* Some library functions also return a count, i.e. a positive
|
||||
* number greater than 0.
|
||||
*/
|
||||
#define LIBAVRDUDE_SUCCESS 0
|
||||
#define LIBAVRDUDE_GENERAL_FAILURE (-1)
|
||||
#define LIBAVRDUDE_NOTSUPPORTED (-2) // operation not supported
|
||||
#define LIBAVRDUDE_SOFTFAIL (-3) // returned by avr_signature() if caller
|
||||
// might proceed with chip erase
|
||||
|
||||
/* formerly lists.h */
|
||||
|
||||
|
|
|
@ -1116,9 +1116,8 @@ int main(int argc, char * argv [])
|
|||
usleep(waittime);
|
||||
if (init_ok) {
|
||||
rc = avr_signature(pgm, p);
|
||||
if (rc != 0) {
|
||||
// -68 == -(0x44) == -(RSP3_FAIL_OCD_LOCKED)
|
||||
if ((rc == -68) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) {
|
||||
if (rc != LIBAVRDUDE_SUCCESS) {
|
||||
if ((rc == LIBAVRDUDE_SOFTFAIL) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) {
|
||||
attempt++;
|
||||
if (pgm->read_sib) {
|
||||
// Read SIB and compare FamilyID
|
||||
|
|
Loading…
Reference in New Issue