Merge branch 'avrdudes:main' into issue942

This commit is contained in:
Stefan Rueger 2022-06-28 22:38:47 +01:00 committed by GitHub
commit a21f3d20af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 17 deletions

2
NEWS
View File

@ -29,6 +29,8 @@ Changes since version 7.0:
to < 80 characters #1000 to < 80 characters #1000
- Dragon JTAG fix #979 - Dragon JTAG fix #979
- adding support for all Linux baud rates v.2 #993 - adding support for all Linux baud rates v.2 #993
- Replace internal knowledge in jtag3.c by a public API #996
- JTAG3 UPDI EEPROM fix #1013
* Internals: * Internals:

View File

@ -439,16 +439,16 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype,
(vmem->tags[i] & TAG_ALLOCATED) != 0) (vmem->tags[i] & TAG_ALLOCATED) != 0)
{ {
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i); 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); 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", avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n",
memtype); memtype);
return -2; return LIBAVRDUDE_NOTSUPPORTED;
} }
avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n", avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n",
memtype); memtype);
return rc; return LIBAVRDUDE_SOFTFAIL;
} }
} }
report_progress(i, mem->size, NULL); report_progress(i, mem->size, NULL);
@ -1035,14 +1035,14 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p)
report_progress (0,1,"Reading"); report_progress (0,1,"Reading");
rc = avr_read(pgm, p, "signature", 0); 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", avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n",
progname, p->desc, rc); progname, p->desc, rc);
return rc; return rc;
} }
report_progress (1,1,NULL); report_progress (1,1,NULL);
return 0; return LIBAVRDUDE_SUCCESS;
} }
static uint8_t get_fuse_bitmask(AVRMEM * m) { static uint8_t get_fuse_bitmask(AVRMEM * m) {

View File

@ -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) static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len)
{ {
int i; int i;
@ -850,7 +858,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
putc('\n', stderr); putc('\n', stderr);
avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n", avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n",
progname, descr, status); progname, descr, status);
return -1; return LIBAVRDUDE_GENERAL_FAILURE;
} else if (verbose >= 3) { } else if (verbose >= 3) {
putc('\n', stderr); putc('\n', stderr);
jtag3_prmsg(pgm, *resp, status); 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); 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);
@ -871,7 +880,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
status = (*resp)[3]; status = (*resp)[3];
free(*resp); free(*resp);
resp = 0; resp = 0;
return -status; return jtag3_errcode(status);
} }
return status; return status;
@ -987,7 +996,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm)
free(resp); free(resp);
PDATA(pgm)->prog_enabled = 1; PDATA(pgm)->prog_enabled = 1;
return 0; return LIBAVRDUDE_SUCCESS;
} }
return status; return status;
@ -1761,7 +1770,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
free(cmd); free(cmd);
return n_bytes; return n_bytes;
} }
cmd[3] = ( p->flags & AVRPART_HAS_PDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE; cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE;
PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L; PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L;
} else if (strcmp(m->desc, "usersig") == 0 || } else if (strcmp(m->desc, "usersig") == 0 ||
strcmp(m->desc, "userrow") == 0) { strcmp(m->desc, "userrow") == 0) {

View File

@ -144,6 +144,7 @@
# 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_NOT_UNDERSTOOD 0x91 # define RSP3_FAIL_NOT_UNDERSTOOD 0x91

View File

@ -27,6 +27,16 @@
#include <stdint.h> #include <stdint.h>
typedef uint32_t pinmask_t; 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 */ /* formerly lists.h */

View File

@ -1116,9 +1116,8 @@ int main(int argc, char * argv [])
usleep(waittime); usleep(waittime);
if (init_ok) { if (init_ok) {
rc = avr_signature(pgm, p); rc = avr_signature(pgm, p);
if (rc != 0) { if (rc != LIBAVRDUDE_SUCCESS) {
// -68 == -(0x44) == -(RSP3_FAIL_OCD_LOCKED) if ((rc == LIBAVRDUDE_SOFTFAIL) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) {
if ((rc == -68) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) {
attempt++; attempt++;
if (pgm->read_sib) { if (pgm->read_sib) {
// Read SIB and compare FamilyID // Read SIB and compare FamilyID