From 60df52326f1a60138defffea7133e0fd3728cc61 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 3 Jan 2024 14:06:33 +0100 Subject: [PATCH] Look for matching prog_modes in `locate_part_by_signature()` (#1605) --- src/avrpart.c | 20 ++++++++++---------- src/libavrdude.h | 2 ++ src/main.c | 7 ++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/avrpart.c b/src/avrpart.c index 90bf932e..54e25af8 100644 --- a/src/avrpart.c +++ b/src/avrpart.c @@ -1031,21 +1031,21 @@ AVRPART *locate_part_by_avr910_devcode(const LISTID parts, int devcode) { return NULL; } -AVRPART *locate_part_by_signature(const LISTID parts, unsigned char *sig, int sigsize) { - if(parts && sigsize == 3) - for(LNODEID ln1=lfirst(parts); ln1; ln1=lnext(ln1)) { - AVRPART *p = ldata(ln1); - int i; - for(i=0; i<3; i++) - if(p->signature[i] != sig[i]) - break; - if(i == 3) +AVRPART *locate_part_by_signature_pm(const LISTID parts, unsigned char *sig, int sigsize, int prog_modes) { + if(parts && sigsize == 3) { + for(LNODEID ln=lfirst(parts); ln; ln=lnext(ln)) { + AVRPART *p = ldata(ln); + if(memcmp(p->signature, sig, 3) == 0 && p->prog_modes & prog_modes) return p; } - + } return NULL; } +AVRPART *locate_part_by_signature(const LISTID parts, unsigned char *sig, int sigsize) { + return locate_part_by_signature_pm(parts, sig, sigsize, PM_ALL); +} + /* * Iterate over the list of avrparts given as "avrparts", and * call the callback function cb for each entry found. cb is being diff --git a/src/libavrdude.h b/src/libavrdude.h index bd23fa0c..a240f6f2 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -207,6 +207,7 @@ typedef struct opcode { #define PM_XMEGAJTAG 1024 // JTAG, some XMEGA parts #define PM_AVR32JTAG 2048 // JTAG for 32-bit AVRs #define PM_aWire 4096 // For 32-bit AVRs +#define PM_ALL 0x1fff // All programming interfaces #define HV_UPDI_VARIANT_0 0 /* Shared UPDI/GPIO/RESET pin, HV on UPDI pin (tinyAVR0/1/2)*/ #define HV_UPDI_VARIANT_1 1 /* Dedicated UPDI pin, no HV (megaAVR0/AVR-Dx) */ @@ -548,6 +549,7 @@ void avr_free_part(AVRPART * d); AVRPART * locate_part(const LISTID parts, const char *partdesc); AVRPART * locate_part_by_avr910_devcode(const LISTID parts, int devcode); AVRPART * locate_part_by_signature(const LISTID parts, unsigned char *sig, int sigsize); +AVRPART * locate_part_by_signature_pm(const LISTID parts, unsigned char *sig, int sigsize, int prog_modes); const char *avr_prog_modes_str(int pm); void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose); int avr_variants_display(FILE *f, const AVRPART *p, const char *prefix); diff --git a/src/main.c b/src/main.c index 6011c244..9256e197 100644 --- a/src/main.c +++ b/src/main.c @@ -1617,9 +1617,10 @@ skipopen: sig->buf[2] == p->signature[2]; if (quell_progress < 2) { - AVRPART * part; - if((part = locate_part_by_signature(part_list, sig->buf, sig->size))) - msg_info(" (probably %s)", signature_matches ? p->id : part->id); + AVRPART *part; + if((part = locate_part_by_signature_pm(part_list, sig->buf, sig->size, pgm->prog_modes)) || + (part = locate_part_by_signature(part_list, sig->buf, sig->size))) + msg_info(" (probably %s)", signature_matches? p->id: part->id); } if (ff || zz) { if (++attempt < 3) {