2022-06-28 19:14:29 +00:00
|
|
|
/*
|
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
|
|
|
* Copyright (C) 2022, Stefan Rueger <smr@theblueorange.space>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to program an Atmel AVR device through one of the supported
|
|
|
|
* programmers.
|
|
|
|
*
|
|
|
|
* For parallel port connected programmers, the pin definitions can be
|
|
|
|
* changed via a config file. See the config file for instructions on
|
|
|
|
* how to add a programmer definition.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <whereami.h>
|
|
|
|
#include <stdarg.h>
|
2022-08-07 16:52:17 +00:00
|
|
|
#include <stddef.h>
|
2022-06-28 19:14:29 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include "avrdude.h"
|
|
|
|
#include "libavrdude.h"
|
2022-08-11 23:28:54 +00:00
|
|
|
#include "config.h"
|
2022-06-28 19:14:29 +00:00
|
|
|
|
|
|
|
#include "developer_opts.h"
|
|
|
|
#include "developer_opts_private.h"
|
|
|
|
|
2022-08-24 11:55:00 +00:00
|
|
|
// Inject part parameters into a semi-automated rewrite of avrdude.conf
|
|
|
|
// - Add entries to the tables below; they get written on -p*/i
|
|
|
|
// - Use the output in a new avrdude.conf
|
|
|
|
// - Output again with -p* (no /i) and use that for final avrdude.conf
|
|
|
|
// - Remove entries from below tables
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *mcu, *var, *value;
|
|
|
|
} ptinj[] = {
|
|
|
|
// Add triples here, eg, {"ATmega328P", "mcuid", "999"},
|
2022-08-24 12:50:07 +00:00
|
|
|
{NULL, NULL, NULL},
|
2022-08-24 11:55:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *mcu, *mem, *var, *value;
|
|
|
|
} meminj[] = {
|
|
|
|
// Add quadruples here, eg, {"ATmega328P", "flash", "page_size", "128"},
|
2022-08-24 12:50:07 +00:00
|
|
|
{NULL, NULL, NULL, NULL},
|
2022-08-24 11:55:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Return 0 if op code would encode (essentially) the same SPI command
|
2022-08-23 15:57:09 +00:00
|
|
|
static int opcodecmp(const OPCODE *op1, const OPCODE *op2, int opnum) {
|
2022-07-07 17:32:19 +00:00
|
|
|
char *opstr1, *opstr2, *p;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
if(!op1 && !op2)
|
|
|
|
return 0;
|
|
|
|
if(!op1 || !op2)
|
|
|
|
return op1? -1: 1;
|
|
|
|
|
2022-07-19 22:44:58 +00:00
|
|
|
opstr1 = opcode2str(op1, opnum, 1);
|
|
|
|
opstr2 = opcode2str(op2, opnum, 1);
|
2022-07-07 17:32:19 +00:00
|
|
|
if(!opstr1 || !opstr2) {
|
|
|
|
dev_info("%s: out of memory\n", progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Don't care x and 0 are functionally equivalent
|
2022-07-07 17:32:19 +00:00
|
|
|
for(p=opstr1; *p; p++)
|
|
|
|
if(*p == 'x')
|
|
|
|
*p = '0';
|
|
|
|
for(p=opstr2; *p; p++)
|
|
|
|
if(*p == 'x')
|
|
|
|
*p = '0';
|
|
|
|
|
|
|
|
cmp = strcmp(opstr1, opstr2);
|
|
|
|
free(opstr1);
|
|
|
|
free(opstr2);
|
|
|
|
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void printopcode(const AVRPART *p, const char *d, const OPCODE *op, int opnum) {
|
2022-06-28 19:14:29 +00:00
|
|
|
unsigned char cmd[4];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(op) {
|
|
|
|
memset(cmd, 0, sizeof cmd);
|
|
|
|
avr_set_bits(op, cmd);
|
|
|
|
|
2022-07-21 17:47:48 +00:00
|
|
|
dev_info(".op\t%s\t%s\t%s\t0x%02x%02x%02x%02x\t", p->desc, d, opcodename(opnum), cmd[0], cmd[1], cmd[2], cmd[3]);
|
2022-06-28 19:14:29 +00:00
|
|
|
for(i=31; i >= 0; i--) {
|
|
|
|
dev_info("%c", cmdbitchar(op->bit[i]));
|
|
|
|
if(i%8 == 0)
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info("%c", i? '\t': '\n');
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void printallopcodes(const AVRPART *p, const char *d, OPCODE * const *opa) {
|
2022-06-28 19:14:29 +00:00
|
|
|
for(int i=0; i<AVR_OP_MAX; i++)
|
|
|
|
printopcode(p, d, opa[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
// Programming modes
|
|
|
|
static char *prog_modes(const AVRPART *p) {
|
2022-06-28 19:14:29 +00:00
|
|
|
static char type[1024];
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
*type = 0;
|
|
|
|
|
|
|
|
if(!(p->flags & AVRPART_HAS_TPI) // TPI devices don't have the SPM opcode
|
|
|
|
&& strcmp(p->id, "t4") // Nor have these early ones
|
|
|
|
&& strcmp(p->id, "t5")
|
|
|
|
&& strcmp(p->id, "t9")
|
|
|
|
&& strcmp(p->id, "t10")
|
|
|
|
&& strcmp(p->id, "t11")
|
|
|
|
&& strcmp(p->id, "t12")
|
|
|
|
&& strcmp(p->id, "t15")
|
|
|
|
&& strcmp(p->id, "t20")
|
|
|
|
&& strcmp(p->id, "t26")
|
|
|
|
&& strcmp(p->id, "t28")
|
|
|
|
&& strcmp(p->id, "t40"))
|
|
|
|
strcpy(type, "PM_SPM");
|
|
|
|
|
2022-06-28 19:14:29 +00:00
|
|
|
switch(p->flags & (AVRPART_HAS_PDI | AVRPART_AVR32 | AVRPART_HAS_TPI | AVRPART_HAS_UPDI)) {
|
2022-08-23 15:57:09 +00:00
|
|
|
case AVRPART_HAS_TPI: // AVR8L family
|
|
|
|
strcat(type, "|PM_TPI");
|
|
|
|
break;
|
|
|
|
case 0: // AVR8 family, "classic" parts
|
|
|
|
if(p->flags & AVRPART_SERIALOK) // ATmega406 has no ISP
|
|
|
|
strcat(type, "|PM_ISP");
|
|
|
|
break;
|
|
|
|
case AVRPART_HAS_PDI: // AVR8_XMEGA family
|
|
|
|
strcat(type, "|PM_PDI");
|
|
|
|
break;
|
|
|
|
case AVRPART_HAS_UPDI: // AVR8X family
|
|
|
|
strcat(type, "|PM_UPDI");
|
|
|
|
break;
|
|
|
|
case AVRPART_AVR32: // AVR32 family
|
|
|
|
strcat(type, "|PM_aWire");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcat(type, "|PM_UNKNOWN");
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
switch(p->ctl_stack_type) {
|
|
|
|
case CTL_STACK_PP:
|
|
|
|
strcat(type, "|PM_HVPP");
|
|
|
|
break;
|
|
|
|
case CTL_STACK_HVSP:
|
|
|
|
strcat(type, "|PM_HVSP");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-06-28 19:14:29 +00:00
|
|
|
|
|
|
|
if(p->flags & AVRPART_HAS_DW)
|
2022-08-23 15:57:09 +00:00
|
|
|
strcat(type, "|PM_debugWIRE");
|
2022-06-28 19:14:29 +00:00
|
|
|
|
|
|
|
if(p->flags & AVRPART_HAS_JTAG)
|
2022-08-23 15:57:09 +00:00
|
|
|
strcat(type, "|PM_JTAG");
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
return type + (*type == '|');
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Check whether address bits are where they should be in ISP commands
|
2022-08-23 15:57:09 +00:00
|
|
|
static void checkaddr(int memsize, int pagesize, int opnum, const OPCODE *op, const AVRPART *p, const AVRMEM *m) {
|
2022-06-28 19:14:29 +00:00
|
|
|
int i, lo, hi;
|
2022-07-21 17:47:48 +00:00
|
|
|
const char *opstr = opcodename(opnum);
|
2022-06-28 19:14:29 +00:00
|
|
|
|
|
|
|
lo = intlog2(pagesize);
|
|
|
|
hi = intlog2(memsize-1);
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Address bits should be between positions lo and hi (and fall in line), outside should be 0 or don't care
|
2022-06-28 19:14:29 +00:00
|
|
|
for(i=0; i<16; i++) { // ISP programming only deals with 16-bit addresses (words for flash, bytes for eeprom)
|
|
|
|
if(i < lo || i > hi) {
|
|
|
|
if(op->bit[i+8].type != AVR_CMDBIT_IGNORE && !(op->bit[i+8].type == AVR_CMDBIT_VALUE && op->bit[i+8].value == 0)) {
|
2022-07-07 17:32:19 +00:00
|
|
|
char *cbs = cmdbitstr(op->bit[i+8]);
|
2022-07-21 17:47:48 +00:00
|
|
|
dev_info(".cmderr\t%s\t%s-%s\tbit %d outside addressable space should be x or 0 but is %s\n", p->desc, m->desc, opstr, i+8, cbs? cbs: "NULL");
|
2022-07-07 17:32:19 +00:00
|
|
|
if(cbs)
|
|
|
|
free(cbs);
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(op->bit[i+8].type != AVR_CMDBIT_ADDRESS)
|
2022-07-21 17:47:48 +00:00
|
|
|
dev_info(".cmderr\t%s\t%s-%s\tbit %d is %c but should be a\n", p->desc, m->desc, opstr, i+8, cmdbitchar(op->bit[i+8]));
|
2022-06-28 19:14:29 +00:00
|
|
|
else if(op->bit[i+8].bitno != i)
|
2022-07-21 17:47:48 +00:00
|
|
|
dev_info(".cmderr\t%s\t%s-%s\tbit %d inconsistent: a%d specified as a%d\n", p->desc, m->desc, opstr, i+8, i, op->bit[i+8].bitno);
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-07 16:52:17 +00:00
|
|
|
for(i=0; i<32; i++) // Command bits 8..23 should not contain address bits
|
2022-06-28 19:14:29 +00:00
|
|
|
if((i<8 || i>23) && op->bit[i].type == AVR_CMDBIT_ADDRESS)
|
2022-07-21 17:47:48 +00:00
|
|
|
dev_info(".cmderr\t%s\t%s-%s\tbit %d contains a%d which it shouldn't\n", p->desc, m->desc, opstr, i, op->bit[i].bitno);
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide avr_set_addr_mem() to set addresses in SPI opcodes within boundaries
The function avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd,
unsigned long addr) is meant to replace avr_set_addr(OPCODE *op, unsigned
char *cmd, unsigned long addr) in future.
avr_set_addr_mem() has more information about the context of the task in that
it knows the memory size, memory page size, whether or not the memory is a
flash memory (which gets words addressees supplied) and, crucially, knows
which SPI operation it is meant to compute the address bits for.
avr_set_addr_mem() first computes the interval of bit numbers that must be
supplied for the SPI command to stand a chance to work. The function only
sets those address bits that are needed. Once all avr_set_addr() function
calls have been replaced by avr_set_addr_mem(), the SPI commands that need an
address can afford to declare in avrdude.conf all 16 address bits in the
middle two bytes of the SPI command. This over-declaration will be corrected
during runtime by avr_set_addr_mem(). One consequence of this is that parts
can inherit smaller or larger memories from parents without the need to use
different SPI codes in avrdude.conf. Another consequence is that
avr_set_addr_mem() can, and does, tell the caller whether vital address bits
were not declared in the SPI opcode. During parsing of avrdude.conf this
might be utilised to generate a corresponding warning. This will uncover
problematic SPI codes in avrdude.conf that in the past went undetected.
2022-07-21 20:42:07 +00:00
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
static char *dev_sprintf(const char *fmt, ...) {
|
|
|
|
int size = 0;
|
|
|
|
char *p = NULL;
|
|
|
|
va_list ap;
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Compute size
|
2022-07-07 17:32:19 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
size = vsnprintf(p, size, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if(size < 0)
|
2022-08-09 20:20:44 +00:00
|
|
|
return cfg_strdup("dev_sprintf()", "");
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
size++; // For terminating '\0'
|
|
|
|
p = cfg_malloc("dev_sprintf()", size);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
size = vsnprintf(p, size, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
if(size < 0)
|
|
|
|
*p = 0;
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dev_nprinted;
|
|
|
|
|
|
|
|
int dev_message(int msglvl, const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if(verbose >= msglvl) {
|
|
|
|
va_start(ap, fmt);
|
2022-08-09 08:23:26 +00:00
|
|
|
rc = vfprintf(stdout, fmt, ap);
|
2022-07-07 17:32:19 +00:00
|
|
|
va_end(ap);
|
|
|
|
if(rc > 0)
|
|
|
|
dev_nprinted += rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
// Any of the strings in the list contains subs as substring?
|
|
|
|
int dev_has_subsstr_comms(const LISTID comms, const char *subs) {
|
|
|
|
if(comms)
|
|
|
|
for(LNODEID ln=lfirst(comms); ln; ln=lnext(ln))
|
|
|
|
if(strstr((char *) ldata(ln), subs))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a chained list of strings
|
|
|
|
void dev_print_comment(const LISTID comms) {
|
|
|
|
if(comms)
|
|
|
|
for(LNODEID ln=lfirst(comms); ln; ln=lnext(ln))
|
|
|
|
dev_info("%s", (char *) ldata(ln));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional output of part, memory or programmer's comments field
|
|
|
|
static void dev_cout(const LISTID comms, const char *name, int rhs, int elself) {
|
|
|
|
COMMENT *cp;
|
|
|
|
|
|
|
|
if((cp = locate_comment(comms, name, rhs)))
|
|
|
|
dev_print_comment(cp->comms);
|
|
|
|
else if(elself)
|
|
|
|
dev_info("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print part->comments, mem->comments or pgm->comments (for debugging)
|
|
|
|
void dev_print_kw_comments(const LISTID comms) {
|
|
|
|
if(comms)
|
|
|
|
for(LNODEID ln=lfirst(comms); ln; ln=lnext(ln)) {
|
|
|
|
COMMENT *n = ldata(ln);
|
|
|
|
if(n && n->comms) {
|
|
|
|
dev_info(">>> %s %c\n", n->kw, n->rhs? '>': '<');
|
|
|
|
dev_print_comment(n->comms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ideally all assignment outputs run via this function
|
|
|
|
static int dev_part_strct_entry(bool tsv, // Print as spreadsheet?
|
|
|
|
const char *col0, const char *col1, const char *col2, // Descriptors of item
|
|
|
|
const char *name, char *cont, const LISTID comms) { // Name, contents and comments
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
const char *n = name? name: "name_error";
|
|
|
|
const char *c = cont? cont: "cont_error";
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
if(tsv) { // Tab separated values
|
2022-07-07 17:32:19 +00:00
|
|
|
if(col0) {
|
|
|
|
dev_info("%s\t", col0);
|
|
|
|
if(col1) {
|
|
|
|
dev_info("%s\t", col1);
|
|
|
|
if(col2) {
|
|
|
|
dev_info("%s\t", col2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dev_info("%s\t%s\n", n, c);
|
2022-08-07 16:52:17 +00:00
|
|
|
} else { // Grammar conform
|
2022-07-07 17:32:19 +00:00
|
|
|
int indent = col2 && strcmp(col2, "part");
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_cout(comms, n, 0, 0); // Print comments before the line
|
|
|
|
dev_info("%*s%-*s = %s;", indent? 8: 4, "", indent? 15: 19, n, c);
|
|
|
|
dev_cout(comms, n, 1, 1); // Print comments on rhs
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(cont)
|
|
|
|
free(cont);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static const char *dev_controlstack_name(const AVRPART *p) {
|
2022-07-07 17:32:19 +00:00
|
|
|
return
|
|
|
|
p->ctl_stack_type == CTL_STACK_PP? "pp_controlstack":
|
|
|
|
p->ctl_stack_type == CTL_STACK_HVSP? "hvsp_controlstack":
|
2022-07-19 15:16:55 +00:00
|
|
|
p->ctl_stack_type == CTL_STACK_NONE? "NULL":
|
2022-07-07 17:32:19 +00:00
|
|
|
"unknown_controlstack";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void dev_stack_out(bool tsv, const AVRPART *p, const char *name, const unsigned char *stack, int ns) {
|
2022-07-19 15:16:55 +00:00
|
|
|
if(!strcmp(name, "NULL")) {
|
2022-07-07 17:32:19 +00:00
|
|
|
name = "pp_controlstack";
|
|
|
|
ns = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tsv)
|
|
|
|
dev_info(".pt\t%s\t%s\t", p->desc, name);
|
2022-08-11 23:28:54 +00:00
|
|
|
else {
|
|
|
|
dev_cout(p->comments, name, 0, 0);
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info(" %-19s =%s", name, ns <=8? " ": "");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(ns <= 0)
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info(tsv? "NULL\n": "NULL;");
|
2022-06-28 19:14:29 +00:00
|
|
|
else
|
2022-07-07 17:32:19 +00:00
|
|
|
for(int i=0; i<ns; i++)
|
2022-08-24 00:10:51 +00:00
|
|
|
dev_info("%s0x%02x%s", !tsv && ns > 8 && i%8 == 0? "\n ": " ", stack[i], i+1<ns? ",": tsv? "\n": ";");
|
2022-08-11 23:28:54 +00:00
|
|
|
|
|
|
|
dev_cout(p->comments, name, 1, 1);
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int intcmp(int a, int b) {
|
|
|
|
return a-b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Deep copies for comparison and raw output
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
typedef struct {
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
char descbuf[32];
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRMEM base;
|
|
|
|
OPCODE ops[AVR_OP_MAX];
|
|
|
|
} AVRMEMdeep;
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
static int avrmem_deep_copy(AVRMEMdeep *d, const AVRMEM *m) {
|
2022-07-07 17:32:19 +00:00
|
|
|
d->base = *m;
|
|
|
|
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
// Note memory desc (name, really) is limited to 31 char here
|
|
|
|
memset(d->descbuf, 0, sizeof d->descbuf);
|
|
|
|
strncpy(d->descbuf, m->desc, sizeof d->descbuf-1);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Zap address values
|
2022-08-11 23:28:54 +00:00
|
|
|
d->base.comments = NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
d->base.buf = NULL;
|
|
|
|
d->base.tags = NULL;
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
d->base.desc = NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
for(int i=0; i<AVR_OP_MAX; i++)
|
|
|
|
d->base.op[i] = NULL;
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Copy over the SPI operations themselves
|
2022-07-07 17:32:19 +00:00
|
|
|
memset(d->ops, 0, sizeof d->ops);
|
2022-08-11 23:28:54 +00:00
|
|
|
for(size_t i=0; i<AVR_OP_MAX; i++)
|
2022-07-07 17:32:19 +00:00
|
|
|
if(m->op[i])
|
|
|
|
d->ops[i] = *m->op[i];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static int memorycmp(const AVRMEM *m1, const AVRMEM *m2) {
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRMEMdeep dm1, dm2;
|
|
|
|
|
|
|
|
if(!m1 && !m2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(!m1 || !m2)
|
|
|
|
return m1? -1: 1;
|
2022-08-11 23:28:54 +00:00
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
avrmem_deep_copy(&dm1, m1);
|
|
|
|
avrmem_deep_copy(&dm2, m2);
|
|
|
|
|
|
|
|
return memcmp(&dm1, &dm2, sizeof dm1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
char descbuf[64];
|
|
|
|
char idbuf[32];
|
|
|
|
char family_idbuf[16];
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRPART base;
|
|
|
|
OPCODE ops[AVR_OP_MAX];
|
|
|
|
AVRMEMdeep mems[40];
|
|
|
|
} AVRPARTdeep;
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
static int avrpart_deep_copy(AVRPARTdeep *d, const AVRPART *p) {
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRMEM *m;
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
size_t di;
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
memset(d, 0, sizeof *d);
|
|
|
|
|
|
|
|
d->base = *p;
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
d->base.comments = NULL;
|
2022-07-26 22:43:56 +00:00
|
|
|
d->base.parent_id = NULL;
|
2022-07-19 13:38:34 +00:00
|
|
|
d->base.config_file = NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
d->base.lineno = 0;
|
|
|
|
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
// Copy over desc, id, and family_id
|
|
|
|
memset(d->descbuf, 0, sizeof d->descbuf);
|
2022-08-12 13:58:21 +00:00
|
|
|
strncpy(d->descbuf, p->desc, sizeof d->descbuf-1);
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
memset(d->idbuf, 0, sizeof d->idbuf);
|
2022-08-12 13:58:21 +00:00
|
|
|
strncpy(d->idbuf, p->id, sizeof d->idbuf-1);
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
memset(d->family_idbuf, 0, sizeof d->family_idbuf);
|
2022-08-12 13:58:21 +00:00
|
|
|
strncpy(d->family_idbuf, p->family_id, sizeof d->family_idbuf-1);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Zap address values
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
d->base.desc = NULL;
|
|
|
|
d->base.id = NULL;
|
|
|
|
d->base.family_id = NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
d->base.mem = NULL;
|
|
|
|
d->base.mem_alias = NULL;
|
|
|
|
for(int i=0; i<AVR_OP_MAX; i++)
|
|
|
|
d->base.op[i] = NULL;
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
// Copy over all used SPI operations
|
2022-07-07 17:32:19 +00:00
|
|
|
memset(d->ops, 0, sizeof d->ops);
|
|
|
|
for(int i=0; i<AVR_OP_MAX; i++)
|
|
|
|
if(p->op[i])
|
|
|
|
d->ops[i] = *p->op[i];
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Fill in all memories we got in defined order
|
2022-07-07 17:32:19 +00:00
|
|
|
di = 0;
|
2022-08-02 22:53:00 +00:00
|
|
|
for(size_t mi=0; mi < sizeof avr_mem_order/sizeof *avr_mem_order && avr_mem_order[mi]; mi++) {
|
2022-08-10 21:25:19 +00:00
|
|
|
m = p->mem? avr_locate_mem_noalias(p, avr_mem_order[mi]): NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
if(m) {
|
|
|
|
if(di >= sizeof d->mems/sizeof *d->mems) {
|
|
|
|
avrdude_message(MSG_INFO, "%s: ran out of mems[] space, increase size in AVRMEMdeep of developer_opts.c and recompile\n", progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
avrmem_deep_copy(d->mems+di, m);
|
|
|
|
di++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
static char txtchar(unsigned char in) {
|
|
|
|
in &= 0x7f;
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
return in == 0? '.': in > ' ' && in < 0x7f? in: '_';
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
static void dev_raw_dump(const void *v, int nbytes, const char *name, const char *sub, int idx) {
|
|
|
|
const unsigned char *p = v;
|
2022-08-07 16:52:17 +00:00
|
|
|
int n = (nbytes + 31)/32;
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
for(int i=0; i<n; i++, p += 32, nbytes -= 32) {
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
dev_info("%s\t%s\t%02x.%03x0: ", name, sub, idx, 2*i);
|
2022-08-07 16:52:17 +00:00
|
|
|
for(int j=0; j<32; j++) {
|
|
|
|
if(j && j%8 == 0)
|
|
|
|
dev_info(" ");
|
|
|
|
if(j < nbytes)
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("%02x", p[j]);
|
2022-08-07 16:52:17 +00:00
|
|
|
else
|
|
|
|
dev_info(" ");
|
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info(" ");
|
2022-08-07 16:52:17 +00:00
|
|
|
for(int j=0; j<32 && j < nbytes; j++)
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("%c", txtchar(p[j]));
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
static int _is_all_zero(const void *p, size_t n) {
|
|
|
|
const char *q = (const char *) p;
|
|
|
|
return n <= 0 || (*q == 0 && memcmp(q, q+1, n-1) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *opsnm(const char *pre, int opnum) {
|
|
|
|
static char ret[128];
|
|
|
|
sprintf(ret, "%.31s.%.95s", pre, opcodename(opnum));
|
|
|
|
return ret;
|
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void dev_part_raw(const AVRPART *part) {
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRPARTdeep dp;
|
|
|
|
int di = avrpart_deep_copy(&dp, part);
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_raw_dump(&dp.base, sizeof dp.base, part->desc, "part", 0);
|
|
|
|
for(int i=0; i<AVR_OP_MAX; i++)
|
|
|
|
if(!_is_all_zero(dp.ops+i, sizeof*dp.ops))
|
|
|
|
dev_raw_dump(dp.ops+i, sizeof*dp.ops, part->desc, opsnm("part", i), 1);
|
|
|
|
|
|
|
|
for(int i=0; i<di; i++) {
|
|
|
|
char *nm = dp.mems[i].descbuf;
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_raw_dump(nm, sizeof dp.mems[i].descbuf, part->desc, nm, i+2);
|
|
|
|
dev_raw_dump(&dp.mems[i].base, sizeof dp.mems[i].base, part->desc, nm, i+2);
|
|
|
|
for(int j=0; j<AVR_OP_MAX; j++)
|
|
|
|
if(!_is_all_zero(dp.mems[i].ops+j, sizeof(OPCODE)))
|
|
|
|
dev_raw_dump(dp.mems[i].ops+j, sizeof(OPCODE), part->desc, opsnm(nm, j), i+2);
|
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-24 11:55:00 +00:00
|
|
|
static void dev_part_strct(const AVRPART *p, bool tsv, const AVRPART *base, bool injct) {
|
2022-08-09 20:20:44 +00:00
|
|
|
char *descstr = cfg_escape(p->desc);
|
2022-08-11 23:28:54 +00:00
|
|
|
COMMENT *cp;
|
|
|
|
|
2022-07-25 19:30:40 +00:00
|
|
|
if(!tsv) {
|
2022-08-11 23:28:54 +00:00
|
|
|
const char *del = "#------------------------------------------------------------";
|
|
|
|
cp = locate_comment(p->comments, "*", 0);
|
|
|
|
|
|
|
|
if(!cp || !dev_has_subsstr_comms(cp->comms, del)) {
|
|
|
|
dev_info("%s\n", del);
|
|
|
|
dev_info("# %.*s\n", strlen(descstr)-2, descstr+1); // Remove double quotes
|
|
|
|
dev_info("%s\n\n", del);
|
|
|
|
}
|
|
|
|
if(cp)
|
|
|
|
dev_print_comment(cp->comms);
|
|
|
|
|
2022-08-07 13:05:54 +00:00
|
|
|
if(p->parent_id && *p->parent_id)
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("part parent \"%s\"\n", p->parent_id);
|
2022-07-26 22:43:56 +00:00
|
|
|
else
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("part\n");
|
2022-07-25 19:30:40 +00:00
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
_if_partout_str(strcmp, descstr, desc);
|
|
|
|
_if_partout_str(strcmp, cfg_escape(p->id), id);
|
|
|
|
_if_partout_str(strcmp, cfg_escape(p->family_id), family_id);
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_partout(intcmp, "%d", hvupdi_variant);
|
|
|
|
_if_partout(intcmp, "0x%02x", stk500_devcode);
|
|
|
|
_if_partout(intcmp, "0x%02x", avr910_devcode);
|
|
|
|
_if_partout(intcmp, "%d", chip_erase_delay);
|
|
|
|
_if_partout(intcmp, "0x%02x", pagel);
|
|
|
|
_if_partout(intcmp, "0x%02x", bs2);
|
|
|
|
_if_n_partout_str(memcmp, sizeof p->signature, dev_sprintf("0x%02x 0x%02x 0x%02x", p->signature[0], p->signature[1], p->signature[2]), signature);
|
|
|
|
_if_partout(intcmp, "0x%04x", usbpid);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(!base || base->reset_disposition != p->reset_disposition)
|
2022-08-09 20:20:44 +00:00
|
|
|
_partout_str(cfg_strdup("dev_part_strct()",
|
|
|
|
p->reset_disposition == RESET_DEDICATED? "dedicated": p->reset_disposition == RESET_IO? "io": "unknown"),
|
|
|
|
reset);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
_if_partout_str(intcmp, cfg_strdup("dev_part_strct()",
|
|
|
|
p->retry_pulse == PIN_AVR_RESET? "reset": p->retry_pulse == PIN_AVR_SCK? "sck": "unknown"),
|
|
|
|
retry_pulse);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(!base || base->flags != p->flags) {
|
|
|
|
if(tsv) {
|
2022-07-19 13:38:34 +00:00
|
|
|
_partout("0x%04x", flags);
|
2022-07-07 17:32:19 +00:00
|
|
|
} else {
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_flagout(AVRPART_HAS_JTAG, has_jtag);
|
|
|
|
_if_flagout(AVRPART_HAS_DW, has_debugwire);
|
|
|
|
_if_flagout(AVRPART_HAS_PDI, has_pdi);
|
|
|
|
_if_flagout(AVRPART_HAS_UPDI, has_updi);
|
|
|
|
_if_flagout(AVRPART_HAS_TPI, has_tpi);
|
|
|
|
_if_flagout(AVRPART_IS_AT90S1200, is_at90s1200);
|
|
|
|
_if_flagout(AVRPART_AVR32, is_avr32);
|
|
|
|
_if_flagout(AVRPART_ALLOWFULLPAGEBITSTREAM, allowfullpagebitstream);
|
|
|
|
_if_flagout(AVRPART_ENABLEPAGEPROGRAMMING, enablepageprogramming);
|
|
|
|
_if_flagout(AVRPART_SERIALOK, serial);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(!base || (base->flags & (AVRPART_PARALLELOK | AVRPART_PSEUDOPARALLEL)) != (p->flags & (AVRPART_PARALLELOK | AVRPART_PSEUDOPARALLEL))) {
|
|
|
|
int par = p->flags & (AVRPART_PARALLELOK | AVRPART_PSEUDOPARALLEL);
|
2022-08-09 20:20:44 +00:00
|
|
|
_partout_str(cfg_strdup("dev_part_strct()",
|
|
|
|
par == 0? "no": par == AVRPART_PSEUDOPARALLEL? "unknown": AVRPART_PARALLELOK? "yes": "pseudo"),
|
|
|
|
parallel);
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_partout(intcmp, "%d", timeout);
|
|
|
|
_if_partout(intcmp, "%d", stabdelay);
|
|
|
|
_if_partout(intcmp, "%d", cmdexedelay);
|
|
|
|
_if_partout(intcmp, "%d", synchloops);
|
|
|
|
_if_partout(intcmp, "%d", bytedelay);
|
|
|
|
_if_partout(intcmp, "%d", pollindex);
|
|
|
|
_if_partout(intcmp, "0x%02x", pollvalue);
|
|
|
|
_if_partout(intcmp, "%d", predelay);
|
|
|
|
_if_partout(intcmp, "%d", postdelay);
|
|
|
|
_if_partout(intcmp, "%d", pollmethod);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(!base && p->ctl_stack_type != CTL_STACK_NONE)
|
|
|
|
dev_stack_out(tsv, p, dev_controlstack_name(p), p->controlstack, CTL_STACK_SIZE);
|
|
|
|
|
|
|
|
// @@@ may need to remove controlstack and set p->ctl_stack_type to CTL_STACK_NONE if base has controlstack?
|
|
|
|
if(base && (p->ctl_stack_type != base->ctl_stack_type || memcmp(base->controlstack, p->controlstack, sizeof base->controlstack)))
|
|
|
|
dev_stack_out(tsv, p, dev_controlstack_name(p), p->controlstack, CTL_STACK_SIZE);
|
|
|
|
|
|
|
|
if(!base || memcmp(base->flash_instr, p->flash_instr, sizeof base->flash_instr))
|
|
|
|
dev_stack_out(tsv, p, "flash_instr", p->flash_instr, FLASH_INSTR_SIZE);
|
|
|
|
|
|
|
|
if(!base || memcmp(base->eeprom_instr, p->eeprom_instr, sizeof base->eeprom_instr))
|
|
|
|
dev_stack_out(tsv, p, "eeprom_instr", p->eeprom_instr, EEPROM_INSTR_SIZE);
|
|
|
|
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_partout(intcmp, "%d", hventerstabdelay);
|
|
|
|
_if_partout(intcmp, "%d", progmodedelay);
|
|
|
|
_if_partout(intcmp, "%d", latchcycles);
|
|
|
|
_if_partout(intcmp, "%d", togglevtg);
|
|
|
|
_if_partout(intcmp, "%d", poweroffdelay);
|
|
|
|
_if_partout(intcmp, "%d", resetdelayms);
|
|
|
|
_if_partout(intcmp, "%d", resetdelayus);
|
|
|
|
_if_partout(intcmp, "%d", hvleavestabdelay);
|
|
|
|
_if_partout(intcmp, "%d", resetdelay);
|
|
|
|
_if_partout(intcmp, "%d", chiperasepulsewidth);
|
|
|
|
_if_partout(intcmp, "%d", chiperasepolltimeout);
|
|
|
|
_if_partout(intcmp, "%d", chiperasetime);
|
|
|
|
_if_partout(intcmp, "%d", programfusepulsewidth);
|
|
|
|
_if_partout(intcmp, "%d", programfusepolltimeout);
|
|
|
|
_if_partout(intcmp, "%d", programlockpulsewidth);
|
|
|
|
_if_partout(intcmp, "%d", programlockpolltimeout);
|
|
|
|
_if_partout(intcmp, "%d", synchcycles);
|
|
|
|
_if_partout(intcmp, "%d", hvspcmdexedelay);
|
|
|
|
|
|
|
|
_if_partout(intcmp, "0x%02x", idr);
|
|
|
|
_if_partout(intcmp, "0x%02x", rampz);
|
|
|
|
_if_partout(intcmp, "0x%02x", spmcr);
|
2022-08-09 12:19:40 +00:00
|
|
|
_if_partout(intcmp, "0x%02x", eecr);
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_partout(intcmp, "0x%04x", mcu_base);
|
|
|
|
_if_partout(intcmp, "0x%04x", nvm_base);
|
|
|
|
_if_partout(intcmp, "0x%04x", ocd_base);
|
|
|
|
_if_partout(intcmp, "%d", ocdrev);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
for(int i=0; i < AVR_OP_MAX; i++)
|
2022-07-19 22:44:58 +00:00
|
|
|
if(!base || opcodecmp(p->op[i], base->op[i], i))
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_part_strct_entry(tsv, ".ptop", p->desc, "part", opcodename(i), opcode2str(p->op[i], i, !tsv), p->comments);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-02 22:53:00 +00:00
|
|
|
for(size_t mi=0; mi < sizeof avr_mem_order/sizeof *avr_mem_order && avr_mem_order[mi]; mi++) {
|
2022-07-07 17:32:19 +00:00
|
|
|
AVRMEM *m, *bm;
|
|
|
|
|
2022-08-10 21:25:19 +00:00
|
|
|
m = p->mem? avr_locate_mem_noalias(p, avr_mem_order[mi]): NULL;
|
|
|
|
bm = base && base->mem? avr_locate_mem_noalias(base, avr_mem_order[mi]): NULL;
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
if(!m && bm && !tsv)
|
|
|
|
dev_info("\n memory \"%s\" = NULL;\n", bm->desc);
|
|
|
|
|
|
|
|
if(!m)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(base && !bm)
|
|
|
|
bm = avr_new_memtype();
|
|
|
|
|
|
|
|
if(!tsv) {
|
2022-08-07 16:52:17 +00:00
|
|
|
if(!memorycmp(bm, m)) // Same memory bit for bit, no need to instantiate
|
2022-07-07 17:32:19 +00:00
|
|
|
continue;
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_cout(m->comments, "*", 0, 1);
|
|
|
|
dev_info(" memory \"%s\"\n", m->desc);
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_memout_yn(paged);
|
|
|
|
_if_memout(intcmp, m->size > 8192? "0x%x": "%d", size);
|
|
|
|
_if_memout(intcmp, "%d", page_size);
|
2022-08-07 16:52:17 +00:00
|
|
|
_if_memout(intcmp, "%d", num_pages);
|
2022-07-19 13:38:34 +00:00
|
|
|
_if_memout(intcmp, "0x%x", offset);
|
|
|
|
_if_memout(intcmp, "%d", min_write_delay);
|
|
|
|
_if_memout(intcmp, "%d", max_write_delay);
|
|
|
|
_if_memout_yn(pwroff_after_write);
|
|
|
|
_if_n_memout_str(memcmp, 2, dev_sprintf("0x%02x 0x%02x", m->readback[0], m->readback[1]), readback);
|
|
|
|
_if_memout(intcmp, "%d", mode);
|
|
|
|
_if_memout(intcmp, "%d", delay);
|
|
|
|
_if_memout(intcmp, "%d", blocksize);
|
|
|
|
_if_memout(intcmp, "%d", readsize);
|
|
|
|
_if_memout(intcmp, "%d", pollindex);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
for(int i=0; i < AVR_OP_MAX; i++)
|
2022-07-19 22:44:58 +00:00
|
|
|
if(!bm || opcodecmp(bm->op[i], m->op[i], i))
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_part_strct_entry(tsv, ".ptmmop", p->desc, m->desc, opcodename(i), opcode2str(m->op[i], i, !tsv), m->comments);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-24 11:55:00 +00:00
|
|
|
if(injct)
|
|
|
|
for(size_t i=0; i<sizeof meminj/sizeof*meminj; i++)
|
2022-08-24 12:50:07 +00:00
|
|
|
if(meminj[i].mcu)
|
|
|
|
if(strcmp(meminj[i].mcu, p->desc) == 0 && strcmp(meminj[i].mem, m->desc) == 0)
|
|
|
|
dev_part_strct_entry(tsv, ".ptmm", p->desc, m->desc,
|
|
|
|
meminj[i].var, cfg_strdup("meminj", meminj[i].value), NULL);
|
2022-08-24 11:55:00 +00:00
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
if(!tsv) {
|
|
|
|
dev_cout(m->comments, ";", 0, 0);
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info(" ;\n");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
for(LNODEID lnm=lfirst(p->mem_alias); lnm; lnm=lnext(lnm)) {
|
|
|
|
AVRMEM_ALIAS *ma = ldata(lnm);
|
|
|
|
if(ma->aliased_mem && !strcmp(ma->aliased_mem->desc, m->desc)) {
|
|
|
|
if(tsv)
|
|
|
|
dev_info(".ptmm\t%s\t%s\talias\t%s\n", p->desc, ma->desc, m->desc);
|
|
|
|
else
|
|
|
|
dev_info("\n memory \"%s\"\n alias \"%s\";\n ;\n", ma->desc, m->desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:55:00 +00:00
|
|
|
if(injct)
|
|
|
|
for(size_t i=0; i<sizeof ptinj/sizeof*ptinj; i++)
|
2022-08-24 12:50:07 +00:00
|
|
|
if(ptinj[i].mcu)
|
|
|
|
if(strcmp(ptinj[i].mcu, p->desc) == 0)
|
|
|
|
dev_part_strct_entry(tsv, ".pt", p->desc, NULL,
|
|
|
|
ptinj[i].var, cfg_strdup("ptinj", ptinj[i].value), NULL);
|
2022-08-24 11:55:00 +00:00
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
if(!tsv) {
|
|
|
|
dev_cout(p->comments, ";", 0, 0);
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info(";\n");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dev_output_pgm_part(int dev_opt_c, char *programmer, int dev_opt_p, char *partdesc) {
|
|
|
|
if(dev_opt_c == 2 && dev_opt_p == 2) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
dev_print_comment(cfg_get_prologue());
|
|
|
|
|
|
|
|
dev_info("default_programmer = %s;\n", p = cfg_escape(default_programmer)); free(p);
|
|
|
|
dev_info("default_parallel = %s;\n", p = cfg_escape(default_parallel)); free(p);
|
|
|
|
dev_info("default_serial = %s;\n", p = cfg_escape(default_serial)); free(p);
|
|
|
|
dev_info("default_spi = %s;\n", p = cfg_escape(default_spi)); free(p);
|
|
|
|
|
|
|
|
dev_info("\n#\n# PROGRAMMER DEFINITIONS\n#\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dev_opt_c)
|
|
|
|
dev_output_pgm_defs(cfg_strdup("main()", programmer));
|
|
|
|
|
|
|
|
if(dev_opt_p == 2 && dev_opt_c)
|
|
|
|
dev_info("\n");
|
|
|
|
if(dev_opt_p == 2)
|
|
|
|
dev_info("#\n# PART DEFINITIONS\n#\n");
|
|
|
|
|
|
|
|
if(dev_opt_p)
|
|
|
|
dev_output_part_defs(cfg_strdup("main()", partdesc));
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-07 13:05:54 +00:00
|
|
|
// -p */[dASsrcow*t]
|
2022-06-28 19:14:29 +00:00
|
|
|
void dev_output_part_defs(char *partdesc) {
|
2022-08-24 11:55:00 +00:00
|
|
|
bool cmdok, waits, opspi, descs, astrc, strct, cmpst, injct, raw, all, tsv;
|
2022-07-07 17:32:19 +00:00
|
|
|
char *flags;
|
|
|
|
int nprinted;
|
|
|
|
AVRPART *nullpart = avr_new_part();
|
|
|
|
|
|
|
|
if((flags = strchr(partdesc, '/')))
|
|
|
|
*flags++ = 0;
|
|
|
|
|
2022-08-08 15:52:09 +00:00
|
|
|
if(!flags && !strcmp(partdesc, "*")) // Treat -p * as if it was -p */s
|
|
|
|
flags = "s";
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-24 11:55:00 +00:00
|
|
|
if(!*flags || !strchr("cdoASsrw*ti", *flags)) {
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info("%s: flags for developer option -p <wildcard>/<flags> not recognised\n", progname);
|
|
|
|
dev_info(
|
2022-07-24 22:38:51 +00:00
|
|
|
"Wildcard examples (these need protecting in the shell through quoting):\n"
|
2022-07-07 17:32:19 +00:00
|
|
|
" * all known parts\n"
|
|
|
|
" ATtiny10 just this part\n"
|
|
|
|
" *32[0-9] matches ATmega329, ATmega325 and ATmega328\n"
|
|
|
|
" *32? matches ATmega329, ATmega32A, ATmega325 and ATmega328\n"
|
|
|
|
"Flags (one or more of the characters below):\n"
|
|
|
|
" d description of core part features\n"
|
2022-08-07 07:53:24 +00:00
|
|
|
" A show entries of avrdude.conf parts with all values\n"
|
|
|
|
" S show entries of avrdude.conf parts with necessary values\n"
|
|
|
|
" s show short entries of avrdude.conf parts using parent\n"
|
2022-07-07 17:32:19 +00:00
|
|
|
" r show entries of avrdude.conf parts as raw dump\n"
|
2022-08-07 07:53:24 +00:00
|
|
|
" c check and report errors in address bits of SPI commands\n"
|
|
|
|
" o opcodes for SPI programming parts and memories\n"
|
2022-07-07 17:32:19 +00:00
|
|
|
" w wd_... constants for ISP parts\n"
|
2022-08-07 07:53:24 +00:00
|
|
|
" * all of the above except s and S\n"
|
2022-07-07 17:32:19 +00:00
|
|
|
" t use tab separated values as much as possible\n"
|
2022-08-24 11:55:00 +00:00
|
|
|
" i inject assignments from source code table\n"
|
2022-07-24 22:38:51 +00:00
|
|
|
"Examples:\n"
|
|
|
|
" $ avrdude -p ATmega328P/s\n"
|
|
|
|
" $ avrdude -p m328*/st | grep chip_erase_delay\n"
|
|
|
|
" avrdude -p*/r | sort\n"
|
|
|
|
"Notes:\n"
|
2022-08-08 15:52:09 +00:00
|
|
|
" -p * is the same as -p */s\n"
|
2022-07-24 22:38:51 +00:00
|
|
|
" This help message is printed using any unrecognised flag, eg, -p/h\n"
|
|
|
|
" Leaving no space after -p can be an OK substitute for quoting in shells\n"
|
2022-08-07 07:53:24 +00:00
|
|
|
" /s, /S and /A outputs are designed to be used as input in avrdude.conf\n"
|
2022-07-24 22:38:51 +00:00
|
|
|
" Sorted /r output should stay invariant when rearranging avrdude.conf\n"
|
|
|
|
" The /c, /o and /w flags are less generic and may be removed sometime\n"
|
|
|
|
" These options are just to help development, so not further documented\n"
|
2022-07-07 17:32:19 +00:00
|
|
|
);
|
2022-06-28 19:14:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
all = *flags == '*';
|
|
|
|
cmdok = all || !!strchr(flags, 'c');
|
|
|
|
descs = all || !!strchr(flags, 'd');
|
|
|
|
opspi = all || !!strchr(flags, 'o');
|
|
|
|
waits = all || !!strchr(flags, 'w');
|
2022-08-07 07:53:24 +00:00
|
|
|
astrc = all || !!strchr(flags, 'A');
|
2022-07-07 17:32:19 +00:00
|
|
|
raw = all || !!strchr(flags, 'r');
|
2022-08-07 07:53:24 +00:00
|
|
|
strct = !!strchr(flags, 'S');
|
2022-07-07 17:32:19 +00:00
|
|
|
cmpst = !!strchr(flags, 's');
|
|
|
|
tsv = !!strchr(flags, 't');
|
2022-08-24 11:55:00 +00:00
|
|
|
injct = !!strchr(flags, 'i');
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Go through all memories and add them to the memory order list
|
2022-06-28 19:14:29 +00:00
|
|
|
for(LNODEID ln1 = lfirst(part_list); ln1; ln1 = lnext(ln1)) {
|
|
|
|
AVRPART *p = ldata(ln1);
|
2022-07-07 17:32:19 +00:00
|
|
|
if(p->mem)
|
|
|
|
for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm))
|
2022-08-02 22:53:00 +00:00
|
|
|
avr_add_mem_order(((AVRMEM *) ldata(lnm))->desc);
|
2022-07-07 17:32:19 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Same for aliased memories (though probably not needed)
|
2022-07-07 17:32:19 +00:00
|
|
|
if(p->mem_alias)
|
|
|
|
for(LNODEID lnm=lfirst(p->mem_alias); lnm; lnm=lnext(lnm))
|
2022-08-02 22:53:00 +00:00
|
|
|
avr_add_mem_order(((AVRMEM_ALIAS *) ldata(lnm))->desc);
|
2022-07-07 17:32:19 +00:00
|
|
|
}
|
2022-06-28 19:14:29 +00:00
|
|
|
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
if((nprinted = dev_nprinted)) {
|
|
|
|
dev_info("\n");
|
|
|
|
nprinted = dev_nprinted;
|
|
|
|
}
|
2022-07-07 17:32:19 +00:00
|
|
|
for(LNODEID ln1 = lfirst(part_list); ln1; ln1 = lnext(ln1)) {
|
|
|
|
AVRPART *p = ldata(ln1);
|
|
|
|
int flashsize, flashoffset, flashpagesize, eepromsize , eepromoffset, eeprompagesize;
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
if(!descs || tsv)
|
|
|
|
if(dev_nprinted > nprinted) {
|
2022-06-28 19:14:29 +00:00
|
|
|
dev_info("\n");
|
2022-07-07 17:32:19 +00:00
|
|
|
nprinted = dev_nprinted;
|
2022-06-28 19:14:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 17:04:41 +00:00
|
|
|
if(!part_match(partdesc, p->desc) && !part_match(partdesc, p->id))
|
2022-07-07 17:32:19 +00:00
|
|
|
continue;
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-08-07 07:53:24 +00:00
|
|
|
if(astrc || strct || cmpst)
|
|
|
|
dev_part_strct(p, tsv,
|
|
|
|
astrc? NULL:
|
|
|
|
strct? nullpart:
|
2022-08-24 11:55:00 +00:00
|
|
|
p->parent_id && *p->parent_id? locate_part(part_list, p->parent_id): nullpart,
|
|
|
|
injct);
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-07-07 17:32:19 +00:00
|
|
|
if(raw)
|
|
|
|
dev_part_raw(p);
|
2022-06-28 19:14:29 +00:00
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Identify core flash and eeprom parameters
|
2022-06-28 19:14:29 +00:00
|
|
|
|
|
|
|
flashsize = flashoffset = flashpagesize = eepromsize = eepromoffset = eeprompagesize = 0;
|
|
|
|
if(p->mem) {
|
|
|
|
for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm)) {
|
|
|
|
AVRMEM *m = ldata(lnm);
|
2022-07-22 22:50:22 +00:00
|
|
|
if(!flashsize && 0==strcmp(m->desc, "flash")) {
|
2022-06-28 19:14:29 +00:00
|
|
|
flashsize = m->size;
|
|
|
|
flashpagesize = m->page_size;
|
|
|
|
flashoffset = m->offset;
|
|
|
|
}
|
2022-07-22 22:50:22 +00:00
|
|
|
if(!eepromsize && 0==strcmp(m->desc, "eeprom")) {
|
2022-06-28 19:14:29 +00:00
|
|
|
eepromsize = m->size;
|
|
|
|
eepromoffset = m->offset;
|
|
|
|
eeprompagesize = m->page_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// "Real" entries don't seem to have a space in their desc (a bit hackey)
|
2022-07-22 22:50:22 +00:00
|
|
|
if(flashsize && !strchr(p->desc, ' ')) {
|
2022-06-28 19:14:29 +00:00
|
|
|
int ok, nfuses;
|
|
|
|
AVRMEM *m;
|
|
|
|
OPCODE *oc;
|
|
|
|
|
|
|
|
ok = 2047;
|
|
|
|
nfuses = 0;
|
|
|
|
|
|
|
|
if(!p->op[AVR_OP_PGM_ENABLE])
|
|
|
|
ok &= ~DEV_SPI_EN_CE_SIG;
|
|
|
|
|
|
|
|
if(!p->op[AVR_OP_CHIP_ERASE])
|
|
|
|
ok &= ~DEV_SPI_EN_CE_SIG;
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "flash"))) {
|
|
|
|
if((oc = m->op[AVR_OP_LOAD_EXT_ADDR])) {
|
|
|
|
// @@@ to do: check whether address is put at lsb of third byte
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_LOAD_EXT_ADDR;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_READ_HI])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size>>1, 1, AVR_OP_READ_HI, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_READ_LO])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size>>1, 1, AVR_OP_READ_LO, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_WRITE_HI])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size>>1, 1, AVR_OP_WRITE_HI, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_WRITE_LO])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size>>1, 1, AVR_OP_WRITE_LO, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_LOADPAGE_HI])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->page_size>>1, 1, AVR_OP_LOADPAGE_HI, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM_PAGED;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_LOADPAGE_LO])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->page_size>>1, 1, AVR_OP_LOADPAGE_LO, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM_PAGED;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_WRITEPAGE])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size>>1, m->page_size>>1, AVR_OP_WRITEPAGE, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_PROGMEM_PAGED;
|
|
|
|
} else
|
|
|
|
ok &= ~(DEV_SPI_PROGMEM_PAGED | DEV_SPI_PROGMEM);
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "eeprom"))) {
|
|
|
|
if((oc = m->op[AVR_OP_READ])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size, 1, AVR_OP_READ, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_EEPROM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_WRITE])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size, 1, AVR_OP_WRITE, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_EEPROM;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_LOADPAGE_LO])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->page_size, 1, AVR_OP_LOADPAGE_LO, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_EEPROM_PAGED;
|
|
|
|
|
|
|
|
if((oc = m->op[AVR_OP_WRITEPAGE])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size, m->page_size, AVR_OP_WRITEPAGE, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_EEPROM_PAGED;
|
|
|
|
} else
|
|
|
|
ok &= ~(DEV_SPI_EEPROM_PAGED | DEV_SPI_EEPROM);
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "signature")) && (oc = m->op[AVR_OP_READ])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size, 1, AVR_OP_READ, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_EN_CE_SIG;
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "calibration")) && (oc = m->op[AVR_OP_READ])) {
|
|
|
|
if(cmdok)
|
|
|
|
checkaddr(m->size, 1, AVR_OP_READ, oc, p, m);
|
|
|
|
} else
|
|
|
|
ok &= ~DEV_SPI_CALIBRATION;
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Actually, some AT90S... parts cannot read, only write lock bits :-0
|
2022-06-28 19:14:29 +00:00
|
|
|
if( ! ((m = avr_locate_mem(p, "lock")) && m->op[AVR_OP_WRITE]))
|
|
|
|
ok &= ~DEV_SPI_LOCK;
|
|
|
|
|
|
|
|
if(((m = avr_locate_mem(p, "fuse")) || (m = avr_locate_mem(p, "lfuse"))) && m->op[AVR_OP_READ] && m->op[AVR_OP_WRITE])
|
|
|
|
nfuses++;
|
|
|
|
else
|
|
|
|
ok &= ~DEV_SPI_LFUSE;
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "hfuse")) && m->op[AVR_OP_READ] && m->op[AVR_OP_WRITE])
|
|
|
|
nfuses++;
|
|
|
|
else
|
|
|
|
ok &= ~DEV_SPI_HFUSE;
|
|
|
|
|
|
|
|
if((m = avr_locate_mem(p, "efuse")) && m->op[AVR_OP_READ] && m->op[AVR_OP_WRITE])
|
|
|
|
nfuses++;
|
|
|
|
else
|
|
|
|
ok &= ~DEV_SPI_EFUSE;
|
|
|
|
|
|
|
|
if(descs) {
|
|
|
|
int len = 16-strlen(p->desc);
|
2022-07-07 17:32:19 +00:00
|
|
|
dev_info("%s '%s' =>%*s [0x%02X, 0x%02X, 0x%02X, 0x%08x, 0x%05x, 0x%03x, 0x%06x, 0x%04x, 0x%03x, %d, 0x%03x, 0x%04x, '%s'], # %s %d\n",
|
|
|
|
tsv || all? ".desc": " ",
|
2022-06-28 19:14:29 +00:00
|
|
|
p->desc, len > 0? len: 0, "",
|
|
|
|
p->signature[0], p->signature[1], p->signature[2],
|
|
|
|
flashoffset, flashsize, flashpagesize,
|
|
|
|
eepromoffset, eepromsize, eeprompagesize,
|
|
|
|
nfuses,
|
|
|
|
ok,
|
|
|
|
p->flags,
|
2022-08-23 15:57:09 +00:00
|
|
|
prog_modes(p),
|
2022-06-28 19:14:29 +00:00
|
|
|
p->config_file, p->lineno
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opspi) {
|
|
|
|
printallopcodes(p, "part", p->op);
|
|
|
|
if(p->mem) {
|
|
|
|
for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm)) {
|
|
|
|
AVRMEM *m = ldata(lnm);
|
|
|
|
if(m)
|
|
|
|
printallopcodes(p, m->desc, m->op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-07 16:52:17 +00:00
|
|
|
// Print wait delays for AVR family parts
|
2022-06-28 19:14:29 +00:00
|
|
|
if(waits) {
|
|
|
|
if(!(p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI | AVRPART_HAS_TPI | AVRPART_AVR32)))
|
|
|
|
dev_info(".wd_chip_erase %.3f ms %s\n", p->chip_erase_delay/1000.0, p->desc);
|
|
|
|
if(p->mem) {
|
|
|
|
for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm)) {
|
|
|
|
AVRMEM *m = ldata(lnm);
|
2022-08-07 16:52:17 +00:00
|
|
|
// Write delays not needed for read-only calibration and signature memories
|
2022-06-28 19:14:29 +00:00
|
|
|
if(strcmp(m->desc, "calibration") && strcmp(m->desc, "signature")) {
|
|
|
|
if(!(p->flags & (AVRPART_HAS_PDI | AVRPART_HAS_UPDI | AVRPART_HAS_TPI | AVRPART_AVR32))) {
|
|
|
|
if(m->min_write_delay == m->max_write_delay)
|
|
|
|
dev_info(".wd_%s %.3f ms %s\n", m->desc, m->min_write_delay/1000.0, p->desc);
|
|
|
|
else {
|
|
|
|
dev_info(".wd_min_%s %.3f ms %s\n", m->desc, m->min_write_delay/1000.0, p->desc);
|
|
|
|
dev_info(".wd_max_%s %.3f ms %s\n", m->desc, m->max_write_delay/1000.0, p->desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-07 13:05:54 +00:00
|
|
|
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void dev_pgm_raw(const PROGRAMMER *pgm) {
|
2022-08-07 13:05:54 +00:00
|
|
|
PROGRAMMER dp;
|
2022-08-07 16:52:17 +00:00
|
|
|
int len, idx;
|
|
|
|
char *id = ldata(lfirst(pgm->id));
|
|
|
|
LNODEID ln;
|
2022-08-07 13:05:54 +00:00
|
|
|
|
|
|
|
memcpy(&dp, pgm, sizeof dp);
|
2022-08-07 16:52:17 +00:00
|
|
|
|
|
|
|
// Dump id, usbpid and hvupdi_support lists
|
|
|
|
for(idx=0, ln=lfirst(dp.id); ln; ln=lnext(ln))
|
|
|
|
dev_raw_dump(ldata(ln), strlen(ldata(ln))+1, id, "id", idx++);
|
|
|
|
for(idx=0, ln=lfirst(dp.usbpid); ln; ln=lnext(ln))
|
|
|
|
dev_raw_dump(ldata(ln), sizeof(int), id, "usbpid", idx++);
|
|
|
|
for(idx=0, ln=lfirst(dp.hvupdi_support); ln; ln=lnext(ln))
|
|
|
|
dev_raw_dump(ldata(ln), sizeof(int), id, "hvupdi_", idx++);
|
|
|
|
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
if(dp.desc)
|
|
|
|
dev_raw_dump(dp.desc, strlen(dp.desc)+1, id, "desc", 0);
|
2022-08-07 16:52:17 +00:00
|
|
|
// Dump cache_string values
|
|
|
|
if(dp.usbdev && *dp.usbdev)
|
|
|
|
dev_raw_dump(dp.usbdev, strlen(dp.usbdev)+1, id, "usbdev", 0);
|
|
|
|
if(dp.usbsn && *dp.usbsn)
|
|
|
|
dev_raw_dump(dp.usbsn, strlen(dp.usbsn)+1, id, "usbsn", 0);
|
|
|
|
if(dp.usbvendor && *dp.usbvendor)
|
|
|
|
dev_raw_dump(dp.usbvendor, strlen(dp.usbvendor)+1, id, "usbvend", 0);
|
|
|
|
if(dp.usbproduct && *dp.usbproduct)
|
|
|
|
dev_raw_dump(dp.usbproduct, strlen(dp.usbproduct)+1, id, "usbprod", 0);
|
|
|
|
|
|
|
|
// Zap all bytes beyond terminating nul of desc, type and port array
|
|
|
|
if((len = strlen(dp.type)+1) < sizeof dp.type)
|
|
|
|
memset(dp.type + len, 0, sizeof dp.type - len);
|
|
|
|
if((len = strlen(dp.port)+1) < sizeof dp.port)
|
|
|
|
memset(dp.port + len, 0, sizeof dp.port - len);
|
|
|
|
|
|
|
|
// Zap address values
|
Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.
config_gram.y now only needs to consider one type of string assignment.
This commit also
- Replaces the simple linear-search cache_string() function with faster
hashed cache_string(). Either way, the returned value is likely to be
shared, so should never be free()'d.
- Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()
- Adds const qualifier to some function args in avrpart.c and pgm.c
- Hardens some functions against being called with NULL pointers
- Ensures _new() and _dup() functions for parts, programmers and memory
return a suitable memory. Out of memory triggers exit in one of three
functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
rarely anything useful that AVRDUDE or, for that matter, any
application compiled against libavrdude can do once you run out of
memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 15:14:56 +00:00
|
|
|
dp.desc = NULL;
|
2022-08-07 16:52:17 +00:00
|
|
|
dp.id = NULL;
|
2022-08-11 23:28:54 +00:00
|
|
|
dp.comments = NULL;
|
2022-08-07 16:52:17 +00:00
|
|
|
dp.parent_id = NULL;
|
|
|
|
dp.initpgm = NULL;
|
2022-08-08 15:52:09 +00:00
|
|
|
dp.usbpid = NULL;
|
|
|
|
dp.usbdev = NULL;
|
|
|
|
dp.usbsn = NULL;
|
|
|
|
dp.usbvendor = NULL;
|
|
|
|
dp.usbproduct = NULL;
|
|
|
|
dp.hvupdi_support = NULL;
|
2022-08-07 16:52:17 +00:00
|
|
|
|
|
|
|
// Only dump contents of PROGRAMMER struct up to and excluding the fd component
|
|
|
|
dev_raw_dump((char *) &dp, offsetof(PROGRAMMER, fd), id, "pgm", 0);
|
2022-08-07 13:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-08 15:52:09 +00:00
|
|
|
static const char *connstr(conntype_t conntype) {
|
|
|
|
switch(conntype) {
|
|
|
|
case CONNTYPE_PARALLEL: return "parallel";
|
|
|
|
case CONNTYPE_SERIAL: return "serial";
|
|
|
|
case CONNTYPE_USB: return "usb";
|
|
|
|
case CONNTYPE_SPI: return "spi";
|
|
|
|
default: return "<unknown>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 15:57:09 +00:00
|
|
|
static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *base) {
|
2022-08-08 15:52:09 +00:00
|
|
|
char *id = ldata(lfirst(pgm->id));
|
|
|
|
LNODEID ln;
|
2022-08-11 23:28:54 +00:00
|
|
|
COMMENT *cp;
|
2022-08-08 15:52:09 +00:00
|
|
|
int firstid;
|
2022-08-07 13:05:54 +00:00
|
|
|
|
2022-08-08 15:52:09 +00:00
|
|
|
if(!tsv) {
|
2022-08-11 23:28:54 +00:00
|
|
|
const char *del = "#------------------------------------------------------------";
|
|
|
|
cp = locate_comment(pgm->comments, "*", 0);
|
|
|
|
|
|
|
|
if(!cp || !dev_has_subsstr_comms(cp->comms, del)) {
|
|
|
|
dev_info("%s\n# ", del);
|
|
|
|
for(firstid=1, ln=lfirst(pgm->id); ln; ln=lnext(ln)) {
|
|
|
|
if(!firstid)
|
|
|
|
dev_info("/");
|
|
|
|
firstid = 0;
|
|
|
|
dev_info("%s", ldata(ln));
|
|
|
|
}
|
|
|
|
dev_info("\n%s\n\n", del);
|
2022-08-07 13:05:54 +00:00
|
|
|
}
|
2022-08-11 23:28:54 +00:00
|
|
|
if(cp)
|
|
|
|
dev_print_comment(cp->comms);
|
|
|
|
|
2022-08-07 13:05:54 +00:00
|
|
|
if(pgm->parent_id && *pgm->parent_id)
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("programmer parent \"%s\"\n", pgm->parent_id);
|
2022-08-07 13:05:54 +00:00
|
|
|
else
|
2022-08-11 23:28:54 +00:00
|
|
|
dev_info("programmer\n");
|
2022-08-07 13:05:54 +00:00
|
|
|
}
|
|
|
|
|
2022-08-08 15:52:09 +00:00
|
|
|
if(tsv)
|
|
|
|
dev_info(".prog\t%s\tid\t", id);
|
2022-08-11 23:28:54 +00:00
|
|
|
else {
|
|
|
|
dev_cout(pgm->comments, "id", 0, 0);
|
2022-08-08 15:52:09 +00:00
|
|
|
dev_info(" %-19s = ", "id");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
for(firstid=1, ln=lfirst(pgm->id); ln; ln=lnext(ln)) {
|
|
|
|
if(!firstid)
|
|
|
|
dev_info(", ");
|
|
|
|
firstid = 0;
|
2022-08-09 20:20:44 +00:00
|
|
|
char *str = cfg_escape(ldata(ln));
|
|
|
|
dev_info("%s", str);
|
|
|
|
free(str);
|
2022-08-08 15:52:09 +00:00
|
|
|
}
|
2022-08-11 23:28:54 +00:00
|
|
|
if(tsv)
|
|
|
|
dev_info("\n");
|
|
|
|
else {
|
|
|
|
dev_info(";");
|
|
|
|
dev_cout(pgm->comments, "id", 1, 1);
|
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
_if_pgmout_str(strcmp, cfg_escape(pgm->desc), desc);
|
2022-08-24 09:57:25 +00:00
|
|
|
if(!base || base->initpgm != pgm->initpgm)
|
|
|
|
_pgmout_fmt("type", "\"%s\"", locate_programmer_type_id(pgm->initpgm));
|
2022-08-09 20:20:44 +00:00
|
|
|
if(!base || base->conntype != pgm->conntype)
|
|
|
|
_pgmout_fmt("connection_type", "%s", connstr(pgm->conntype));
|
2022-08-08 15:52:09 +00:00
|
|
|
_if_pgmout(intcmp, "%d", baudrate);
|
|
|
|
|
|
|
|
_if_pgmout(intcmp, "0x%04x", usbvid);
|
|
|
|
|
|
|
|
if(pgm->usbpid && lfirst(pgm->usbpid)) {
|
|
|
|
if(tsv)
|
|
|
|
dev_info(".prog\t%s\tusbpid\t", id);
|
2022-08-11 23:28:54 +00:00
|
|
|
else {
|
|
|
|
dev_cout(pgm->comments, "usbpid", 0, 0);
|
2022-08-08 15:52:09 +00:00
|
|
|
dev_info(" %-19s = ", "usbpid");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
for(firstid=1, ln=lfirst(pgm->usbpid); ln; ln=lnext(ln)) {
|
|
|
|
if(!firstid)
|
|
|
|
dev_info(", ");
|
|
|
|
firstid = 0;
|
|
|
|
dev_info("0x%04x", *(unsigned int *) ldata(ln));
|
|
|
|
}
|
2022-08-11 23:28:54 +00:00
|
|
|
if(tsv)
|
|
|
|
dev_info("\n");
|
|
|
|
else {
|
|
|
|
dev_info(";");
|
|
|
|
dev_cout(pgm->comments, "usbpid", 1, 1);
|
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 20:20:44 +00:00
|
|
|
_if_pgmout_str(strcmp, cfg_escape(pgm->usbdev), usbdev);
|
|
|
|
_if_pgmout_str(strcmp, cfg_escape(pgm->usbsn), usbsn);
|
|
|
|
_if_pgmout_str(strcmp, cfg_escape(pgm->usbvendor), usbvendor);
|
|
|
|
_if_pgmout_str(strcmp, cfg_escape(pgm->usbproduct), usbproduct);
|
2022-08-08 15:52:09 +00:00
|
|
|
|
|
|
|
for(int i=0; i<N_PINS; i++) {
|
|
|
|
char *str = pins_to_strdup(pgm->pin+i);
|
2022-08-24 09:57:25 +00:00
|
|
|
char *bstr = base? pins_to_strdup(base->pin+i): NULL;
|
|
|
|
if(!base || strcmp(bstr, str))
|
2022-08-08 15:52:09 +00:00
|
|
|
_pgmout_fmt(avr_pin_lcname(i), "%s", str);
|
2022-08-24 09:57:25 +00:00
|
|
|
|
|
|
|
free(str);
|
|
|
|
if(bstr)
|
|
|
|
free(bstr);
|
2022-08-08 15:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(pgm->hvupdi_support && lfirst(pgm->hvupdi_support)) {
|
|
|
|
if(tsv)
|
|
|
|
dev_info(".prog\t%s\thvupdu_support\t", id);
|
2022-08-11 23:28:54 +00:00
|
|
|
else {
|
|
|
|
dev_cout(pgm->comments, "hvupdi_support", 0, 0);
|
2022-08-08 15:52:09 +00:00
|
|
|
dev_info(" %-19s = ", "hvupdi_support");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
for(firstid=1, ln=lfirst(pgm->hvupdi_support); ln; ln=lnext(ln)) {
|
|
|
|
if(!firstid)
|
|
|
|
dev_info(", ");
|
|
|
|
firstid = 0;
|
|
|
|
dev_info("%d", *(unsigned int *) ldata(ln));
|
|
|
|
}
|
2022-08-11 23:28:54 +00:00
|
|
|
if(tsv)
|
|
|
|
dev_info("\n");
|
|
|
|
else {
|
|
|
|
dev_info(";");
|
|
|
|
dev_cout(pgm->comments, "hvupdi_support", 1, 1);
|
|
|
|
}
|
2022-08-08 15:52:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 23:28:54 +00:00
|
|
|
if(!tsv) {
|
|
|
|
dev_cout(pgm->comments, ";", 0, 0);
|
2022-08-07 13:05:54 +00:00
|
|
|
dev_info(";\n");
|
2022-08-11 23:28:54 +00:00
|
|
|
}
|
2022-08-07 13:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -c */[ASsrt]
|
|
|
|
void dev_output_pgm_defs(char *pgmid) {
|
|
|
|
bool astrc, strct, cmpst, raw, tsv;
|
|
|
|
char *flags;
|
|
|
|
int nprinted;
|
|
|
|
PROGRAMMER *nullpgm = pgm_new();
|
|
|
|
|
|
|
|
if((flags = strchr(pgmid, '/')))
|
|
|
|
*flags++ = 0;
|
|
|
|
|
2022-08-08 16:03:06 +00:00
|
|
|
if(!flags && !strcmp(pgmid, "*")) // Treat -c * as if it was -c */s
|
|
|
|
flags = "s";
|
2022-08-07 13:05:54 +00:00
|
|
|
|
|
|
|
if(!*flags || !strchr("ASsrt", *flags)) {
|
|
|
|
dev_info("%s: flags for developer option -c <wildcard>/<flags> not recognised\n", progname);
|
|
|
|
dev_info(
|
|
|
|
"Wildcard examples (these need protecting in the shell through quoting):\n"
|
|
|
|
" * all known programmers\n"
|
|
|
|
" avrftdi just this programmer\n"
|
|
|
|
" jtag*pdi matches jtag2pdi, jtag3pdi, jtag3updi and jtag2updi\n"
|
|
|
|
" jtag?pdi matches jtag2pdi and jtag3pdi\n"
|
|
|
|
"Flags (one or more of the characters below):\n"
|
|
|
|
" A show entries of avrdude.conf programmers with all values\n"
|
|
|
|
" S show entries of avrdude.conf programmers with necessary values\n"
|
|
|
|
" s show short entries of avrdude.conf programmers using parent\n"
|
|
|
|
" r show entries of avrdude.conf programmers as raw dump\n"
|
|
|
|
" t use tab separated values as much as possible\n"
|
|
|
|
"Examples:\n"
|
|
|
|
" $ avrdude -c usbasp/s\n"
|
|
|
|
" $ avrdude -c */st | grep baudrate\n"
|
|
|
|
" $ avrdude -c */r | sort\n"
|
|
|
|
"Notes:\n"
|
2022-08-08 16:03:06 +00:00
|
|
|
" -c * is the same as -c */s\n"
|
2022-08-07 13:05:54 +00:00
|
|
|
" This help message is printed using any unrecognised flag, eg, -c/h\n"
|
|
|
|
" Leaving no space after -c can be an OK substitute for quoting in shells\n"
|
|
|
|
" /s, /S and /A outputs are designed to be used as input in avrdude.conf\n"
|
|
|
|
" Sorted /r output should stay invariant when rearranging avrdude.conf\n"
|
|
|
|
" These options are just to help development, so not further documented\n"
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
astrc = !!strchr(flags, 'A');
|
|
|
|
strct = !!strchr(flags, 'S');
|
|
|
|
cmpst = !!strchr(flags, 's');
|
|
|
|
raw = !!strchr(flags, 'r');
|
|
|
|
tsv = !!strchr(flags, 't');
|
|
|
|
|
|
|
|
nprinted = dev_nprinted;
|
|
|
|
|
|
|
|
LNODEID ln1, ln2;
|
|
|
|
for(ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) {
|
|
|
|
PROGRAMMER *pgm = ldata(ln1);
|
|
|
|
int matched = 0;
|
|
|
|
for(ln2=lfirst(pgm->id); ln2; ln2=lnext(ln2)) {
|
|
|
|
if(part_match(pgmid, ldata(ln2))) {
|
|
|
|
matched = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!matched)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(dev_nprinted > nprinted) {
|
|
|
|
dev_info("\n");
|
|
|
|
nprinted = dev_nprinted;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(astrc || strct || cmpst)
|
|
|
|
dev_pgm_strct(pgm, tsv,
|
|
|
|
astrc? NULL:
|
|
|
|
strct? nullpgm:
|
|
|
|
pgm->parent_id && *pgm->parent_id? locate_programmer(programmers, pgm->parent_id): nullpgm);
|
|
|
|
|
|
|
|
if(raw)
|
|
|
|
dev_pgm_raw(pgm);
|
|
|
|
}
|
|
|
|
}
|