Merge branch 'partdesc' of github.com:stefanrueger/avrdude into partdesc

This commit is contained in:
Stefan Rueger 2022-07-07 18:34:26 +01:00
commit 215ea1af5c
9 changed files with 85 additions and 21 deletions

6
NEWS
View File

@ -18,6 +18,7 @@ Changes since version 7.0:
- Fix micronucleus bootloader to check for unresponsive USB - Fix micronucleus bootloader to check for unresponsive USB
devices #945 devices #945
- Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972 - Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972
- [bug #43898] atmega644p remains stopped after JTAG transaction #366
* Pull requests: * Pull requests:
@ -26,6 +27,11 @@ Changes since version 7.0:
- CMake Enhancements #962 - CMake Enhancements #962
- Reduce programmer desc string length in avrdude.conf - Reduce programmer desc string length in avrdude.conf
to < 80 characters #1000 to < 80 characters #1000
- Dragon JTAG fix #979
- 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
- Treat x bits in .conf SPI commands as 0 #943
* 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

@ -82,11 +82,11 @@ int avr_set_bits(OPCODE * op, unsigned char * cmd)
unsigned char mask; unsigned char mask;
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
if (op->bit[i].type == AVR_CMDBIT_VALUE) { if (op->bit[i].type == AVR_CMDBIT_VALUE || op->bit[i].type == AVR_CMDBIT_IGNORE) {
j = 3 - i / 8; j = 3 - i / 8;
bit = i % 8; bit = i % 8;
mask = 1 << bit; mask = 1 << bit;
if (op->bit[i].value) if (op->bit[i].value && op->bit[i].type == AVR_CMDBIT_VALUE)
cmd[j] = cmd[j] | mask; cmd[j] = cmd[j] | mask;
else else
cmd[j] = cmd[j] & ~mask; cmd[j] = cmd[j] & ~mask;

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;
@ -834,7 +842,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
} }
} }
int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen,
unsigned char **resp, const char *descr) unsigned char **resp, const char *descr)
{ {
int status; int status;
@ -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

@ -1840,8 +1840,8 @@ void jtagmkII_close(PROGRAMMER * pgm)
avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close()\n", progname); avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close()\n", progname);
if (pgm->flag & PGM_FL_IS_PDI) { if (pgm->flag & (PGM_FL_IS_PDI | PGM_FL_IS_JTAG)) {
/* When in PDI mode, restart target. */ /* When in PDI or JTAG mode, restart target. */
buf[0] = CMND_GO; buf[0] = CMND_GO;
avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close(): Sending GO command: ", avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close(): Sending GO command: ",
progname); progname);

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

@ -1122,9 +1122,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

View File

@ -76,6 +76,45 @@ static struct baud_mapping baud_lookup_table [] = {
#endif #endif
#ifdef B230400 #ifdef B230400
{ 230400, B230400 }, { 230400, B230400 },
#endif
#ifdef B250000
{ 250000, B250000 },
#endif
#ifdef B460800
{ 460800, B460800 },
#endif
#ifdef B500000
{ 500000, B500000 },
#endif
#ifdef B576000
{ 576000, B576000 },
#endif
#ifdef B921600
{ 921600, B921600 },
#endif
#ifdef B1000000
{ 1000000, B1000000 },
#endif
#ifdef B1152000
{ 1152000, B1152000 },
#endif
#ifdef B1500000
{ 1500000, B1500000 },
#endif
#ifdef B2000000
{ 2000000, B2000000 },
#endif
#ifdef B2500000
{ 2500000, B2500000 },
#endif
#ifdef B3000000
{ 3000000, B3000000 },
#endif
#ifdef B3500000
{ 3500000, B3500000 },
#endif
#ifdef B4000000
{ 4000000, B4000000 },
#endif #endif
{ 0, 0 } /* Terminator. */ { 0, 0 } /* Terminator. */
}; };