Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update part cmd #1568

Merged
merged 44 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c3ff7fd
First attempt on re-formatting the memory table
MCUdude Nov 11, 2023
c3885d9
Remove px and buf
MCUdude Nov 11, 2023
c593c88
Formatting, add progmodes, remove "non-useful" avr_display() info
MCUdude Nov 11, 2023
5f0a96c
Don't print non-default baud warning when using -v
MCUdude Nov 11, 2023
f804699
No need to specify strlen here
MCUdude Nov 11, 2023
2ce0f6e
Formatting
MCUdude Nov 12, 2023
fc280fa
Make sure there is a minimun character length
MCUdude Nov 12, 2023
a104611
Add variants table
MCUdude Nov 12, 2023
2138362
Merge branch 'avrdudes:main' into parts-cmd
MCUdude Nov 13, 2023
b68371f
Replace '|' with ',' and remove "PM_" prefix
MCUdude Nov 13, 2023
3baed33
Print a "cleaner" table
MCUdude Nov 13, 2023
306c775
Imprive table generation logic
MCUdude Nov 13, 2023
f6380af
Remove unused and commented-out code
MCUdude Nov 13, 2023
3dfa0cf
Add comments
MCUdude Nov 13, 2023
4991f27
Remove pipes from tables
MCUdude Nov 16, 2023
ff189b8
Make "Size" left oriented
MCUdude Nov 16, 2023
2670f20
remove spaces and dashes
MCUdude Nov 16, 2023
a1e0ada
Rename char array
MCUdude Nov 16, 2023
33528a6
Add avr_variants_display to libavrdude
MCUdude Nov 16, 2023
f97a43c
Add variants command to terminal
MCUdude Nov 16, 2023
e1fedb2
Don't print variants table when executing the terminal 'part' command
MCUdude Nov 16, 2023
c7a463f
Tweak 'variants' command descrition
MCUdude Nov 16, 2023
e30bdb8
Print 'SPM' at the end
MCUdude Nov 16, 2023
b9d6e19
Remove whitespace that ruined table formatting
MCUdude Nov 17, 2023
0a1fde0
Don't depend on static variables in avr_mem_display
MCUdude Nov 17, 2023
3feccec
remove variants command
MCUdude Nov 18, 2023
8375551
Formatting
MCUdude Nov 18, 2023
fd311c6
Formatting
MCUdude Nov 18, 2023
a2ddb99
Print variants table when verbosity lever is greater than 0
MCUdude Nov 18, 2023
c691940
Increase verbosity level
MCUdude Nov 18, 2023
293568d
Allign colons and strings across the board
MCUdude Nov 19, 2023
7066c42
show memory table only with , and variants table only with
MCUdude Nov 19, 2023
b28ba21
add part -m -v to docs
MCUdude Nov 19, 2023
9d6a651
remove prefix check
MCUdude Nov 20, 2023
77940c1
tweak docs
MCUdude Nov 20, 2023
c3ff775
Remove unnecessary offset checks
MCUdude Nov 20, 2023
e38184b
Harden string length calculation routine
MCUdude Nov 20, 2023
a932ca7
Fix memory leak
MCUdude Nov 20, 2023
611af7c
Remove unnecessary whitespaces
MCUdude Nov 21, 2023
cc999c3
Reorganise column width computation for memory table
stefanrueger Nov 22, 2023
bcc4307
Check sscanf result and simplify variants
stefanrueger Nov 22, 2023
3a159c5
Pad intervals after closing square bracket not before
stefanrueger Nov 22, 2023
2b60183
Merge branch 'main' into parts-cmd
stefanrueger Nov 22, 2023
400f8e5
Resolve merge conflicts
stefanrueger Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,12 @@ on a non-zero verbosity level the line numbers are printed, too.
.It Ar sig
Display the device signature bytes.
.It Ar part
Display the current part settings and parameters. Includes chip
specific information including all memories supported by the
device, read/write timing, etc.
Display the current part information. Includes chip specific information
MCUdude marked this conversation as resolved.
Show resolved Hide resolved
including supported programming modes, memory and variants tables. Use
.Ar -m
to only print the memory table, and
.Ar -v
to only print the variants table.
.It Ar verbose Op Ar level
Change (when
.Ar level
Expand Down
2 changes: 1 addition & 1 deletion src/avrftdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ static int avrftdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {

static void avrftdi_display(const PROGRAMMER *pgm, const char *p)
{
msg_info("%sPin assignment : 0..7 = DBUS0..7, 8..15 = CBUS0..7\n", p);
msg_info("%sPin assignment : 0..7 = DBUS0..7, 8..15 = CBUS0..7\n", p);
if (pgm->flag & PGM_FL_IS_JTAG) {
pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS & ~SHOW_AVR_PINS);
} else {
Expand Down
326 changes: 186 additions & 140 deletions src/avrpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,39 +290,6 @@ int avr_get_output_index(const OPCODE *op) {
}


static char * avr_op_str(int op)
{
switch (op) {
case AVR_OP_READ : return "READ"; break;
case AVR_OP_WRITE : return "WRITE"; break;
case AVR_OP_READ_LO : return "READ_LO"; break;
case AVR_OP_READ_HI : return "READ_HI"; break;
case AVR_OP_WRITE_LO : return "WRITE_LO"; break;
case AVR_OP_WRITE_HI : return "WRITE_HI"; break;
case AVR_OP_LOADPAGE_LO : return "LOADPAGE_LO"; break;
case AVR_OP_LOADPAGE_HI : return "LOADPAGE_HI"; break;
case AVR_OP_LOAD_EXT_ADDR : return "LOAD_EXT_ADDR"; break;
case AVR_OP_WRITEPAGE : return "WRITEPAGE"; break;
case AVR_OP_CHIP_ERASE : return "CHIP_ERASE"; break;
case AVR_OP_PGM_ENABLE : return "PGM_ENABLE"; break;
default : return "<unknown opcode>"; break;
}
}


static char * bittype(int type)
{
switch (type) {
case AVR_CMDBIT_IGNORE : return "IGNORE"; break;
case AVR_CMDBIT_VALUE : return "VALUE"; break;
case AVR_CMDBIT_ADDRESS : return "ADDRESS"; break;
case AVR_CMDBIT_INPUT : return "INPUT"; break;
case AVR_CMDBIT_OUTPUT : return "OUTPUT"; break;
default : return "<unknown bit type>"; break;
}
}


/***
*** Elementary functions dealing with AVRMEM structures
***/
Expand Down Expand Up @@ -529,68 +496,165 @@ AVRMEM_ALIAS *avr_find_memalias(const AVRPART *p, const AVRMEM *m_orig) {
return NULL;
}

void avr_mem_display(const char *prefix, FILE *f, const AVRMEM *m,
const AVRPART *p, int verbose) {
static unsigned int prev_mem_offset;
static int prev_mem_size;
int i, j;
char * optr;
void avr_mem_display(FILE *f, const AVRPART *p, const char *prefix) {
unsigned int prev_mem_offset = 0;
int prev_mem_size = 0;
const char *table_colum[] = {"Memory", "Size", "Pg size", "Offset"};
const char *table_padding = "-------------------------------";
int m_char_max[4] = {0};

if (m == NULL || verbose > 2) {
fprintf(f,
"%s Block Poll Page Polled\n"
"%sMemory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack\n"
"%s----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------\n",
prefix, prefix, prefix);
for (LNODEID ln=lfirst(p->mem); ln; ln=lnext(ln)) {
AVRMEM *m = ldata(ln);
int m_size[] = {0, m->size, m->page_size, m->offset};
const int m_base[] = {0, 10, 10, 16};

// Mem desc charcter length
AVRMEM_ALIAS *a = avr_find_memalias(p, m);
const char *m_desc_a = a? a->desc: "";
int cnt = strlen(m->desc) + strlen(a? "/": "") + strlen(m_desc_a);
if(m_char_max[0] < cnt)
m_char_max[0] = cnt;
if(m_char_max[0] < (int)strlen(table_colum[0]))
m_char_max[0] = strlen(table_colum[0]);
// Mem size/pgsize/offset character length
for(int i = 1; i < 4; i++) {
cnt = 0;
do {
m_size[i] /= m_base[i];
++cnt;
} while (m_size[i] != 0);
if(m_char_max[i] < cnt)
m_char_max[i] = cnt;
if(m_char_max[i] < (int)strlen(table_colum[i]))
m_char_max[i] = strlen(table_colum[i]);
}
}
m_char_max[3] += strlen("0x");

// Print memory table header
if(p->prog_modes & (PM_PDI | PM_UPDI)) {
fprintf(f,
"\n%s%-*s %*s %-*s %*s\n"
"%s%*.*s--%*.*s--%*.*s--%*.*s\n",
prefix,
m_char_max[0], table_colum[0],
m_char_max[1], table_colum[1],
m_char_max[2], table_colum[2],
m_char_max[3], table_colum[3],
prefix,
m_char_max[0], m_char_max[0], table_padding,
m_char_max[1], m_char_max[1], table_padding,
m_char_max[2], m_char_max[2], table_padding,
m_char_max[3], m_char_max[3], table_padding);
} else {
fprintf(f,
"\n%s%-*s %*s %-*s\n"
"%s%*.*s--%*.*s--%*.*s\n",
prefix,
m_char_max[0], table_colum[0],
m_char_max[1], table_colum[1],
m_char_max[2], table_colum[2],
prefix,
m_char_max[0], m_char_max[0], table_padding,
m_char_max[1], m_char_max[1], table_padding,
m_char_max[2], m_char_max[2], table_padding);
}

if (m != NULL) {
for (LNODEID ln=lfirst(p->mem); ln; ln=lnext(ln)) {
AVRMEM *m = ldata(ln);
// Only print memory section if the previous section printed isn't identical
if(prev_mem_offset != m->offset || prev_mem_size != m->size || str_eq(p->family_id, "")) {
prev_mem_offset = m->offset;
prev_mem_size = m->size;
AVRMEM_ALIAS *ap = avr_find_memalias(p, m);
/* Show alias if the current and the next memory section has the same offset
and size, we're not out of band and a family_id is present */
const char *mem_desc_alias = ap? ap->desc: "";
fprintf(f,
"%s%-11s %-8s %4d %5d %5d %4d %-6s %6d %4d %6d %5d %5d 0x%02x 0x%02x\n",
prefix,
m->desc,
mem_desc_alias,
m->mode, m->delay, m->blocksize, m->pollindex,
m->paged ? "yes" : "no",
m->size,
m->page_size,
m->num_pages,
m->min_write_delay,
m->max_write_delay,
m->readback[0],
m->readback[1]);

MCUdude marked this conversation as resolved.
Show resolved Hide resolved
// Workaround to get the 0x prefix where it should be
MCUdude marked this conversation as resolved.
Show resolved Hide resolved
int m_offset = m->offset;
int m_offset_cnt = 0;
int m_offset_digits = 0;
do {
m_offset /= 16;
++m_offset_cnt;
} while (m_offset != 0);
if(m_offset_digits < m_offset_cnt)
m_offset_digits = m_offset_cnt;
m_offset_digits += strlen("0x");

AVRMEM_ALIAS *a = avr_find_memalias(p, m);
const char *m_desc_a = a? a->desc: "";
char m_desc_str[256];
sprintf(m_desc_str,"%s%s%s", m->desc, a? "/": "", m_desc_a);

// Print memory table content
if(p->prog_modes & (PM_PDI | PM_UPDI)) {
fprintf(f, "%s%-*s %*d %*d %*s0x%x \n",
prefix,
m_char_max[0], m_desc_str,
m_char_max[1] < 4? 4: m_char_max[1], m->size,
m_char_max[2], m->page_size,
m_char_max[3]-m_offset_digits, "", m->offset);
} else {
fprintf(f, "%s%-*s %*d %*d\n",
prefix,
m_char_max[0], m_desc_str,
m_char_max[1] < 4? 4: m_char_max[1], m->size,
m_char_max[2], m->page_size);
}
}
if (verbose > 4) {
msg_trace2("%s Memory Ops:\n"
"%s Operation Inst Bit Bit Type Bitno Value\n"
"%s ----------- -------- -------- ----- -----\n",
prefix, prefix, prefix);
for (i=0; i<AVR_OP_MAX; i++) {
if (m->op[i]) {
for (j=31; j>=0; j--) {
if (j==31)
optr = avr_op_str(i);
else
optr = " ";
fprintf(f,
"%s %-11s %8d %8s %5d %5d\n",
prefix, optr, j,
bittype(m->op[i]->bit[j].type),
m->op[i]->bit[j].bitno,
m->op[i]->bit[j].value);
}
}
}
}

int avr_variants_display(FILE *f, const AVRPART *p, const char *prefix) {
const char *table_padding = "-------------------------------";
const char *var_table_column[] = {"Variants", "Package", "F max", "T range", "V range"};
char var_tok[5][50];
int var_tok_len[5] = {0};

if(lsize(p->variants)) {
// Split variants strings into tokens and find their strlen
for(LNODEID ln=lfirst(p->variants); ln; ln=lnext(ln)) {
sscanf(ldata(ln), "%49[^:]: %49[^,], Fmax=%49[^,], T=[%49[^]]], Vcc=[%49[^]]]",
var_tok[0], var_tok[1], var_tok[2], var_tok[3], var_tok[4]);
for(int i = 0; i < 5; i++) {
if(var_tok_len[i] < (int)strlen(var_tok[i]))
var_tok_len[i] = strlen(var_tok[i]);
if(var_tok_len[i] < (int)strlen(var_table_column[i]))
var_tok_len[i] = strlen(var_table_column[i]);
}
}

// Print variants table header
fprintf(f,
"\n%s%-*s %-*s %-*s %-*s %-*s\n"
"%s%*.*s--%*.*s--%*.*s--%*.*s--%*.*s\n",
prefix,
var_tok_len[0], var_table_column[0],
var_tok_len[1], var_table_column[1],
var_tok_len[2], var_table_column[2],
var_tok_len[3]+2, var_table_column[3],
var_tok_len[4]+2, var_table_column[4],
prefix,
var_tok_len[0], var_tok_len[0], table_padding,
var_tok_len[1], var_tok_len[1], table_padding,
var_tok_len[2], var_tok_len[2], table_padding,
var_tok_len[3]+2, var_tok_len[3]+2, table_padding,
var_tok_len[4]+2, var_tok_len[4]+2, table_padding);

// Print variants table content
for(LNODEID ln=lfirst(p->variants); ln; ln=lnext(ln)) {
sscanf(ldata(ln), "%49[^:]: %49[^,], Fmax=%49[^,], T=[%49[^]]], Vcc=[%49[^]]]",
var_tok[0], var_tok[1], var_tok[2], var_tok[3], var_tok[4]);
fprintf(f,
"%s%-*s %-*s %-*s [%-*s] [%-*s]\n",
prefix,
var_tok_len[0], var_tok[0],
var_tok_len[1], var_tok[1],
var_tok_len[2], var_tok[2],
var_tok_len[3], var_tok[3],
var_tok_len[4], var_tok[4]);
}
return 0;
}
return -1;
}


Expand Down Expand Up @@ -763,67 +827,49 @@ void sort_avrparts(LISTID avrparts)
lsort(avrparts,(int (*)(void*, void*)) sort_avrparts_compare);
}


static char * reset_disp_str(int r)
{
switch (r) {
case RESET_DEDICATED : return "dedicated";
case RESET_IO : return "possible i/o";
default : return "<invalid>";
}
const char *avr_prog_modes_str(int pm) {
static char type[1024];

strcpy(type, "0");
if(pm & PM_TPI)
strcat(type, ", TPI");
if(pm & PM_ISP)
strcat(type, ", ISP");
if(pm & PM_PDI)
strcat(type, ", PDI");
if(pm & PM_UPDI)
strcat(type, ", UPDI");
if(pm & PM_HVSP)
strcat(type, ", HVSP");
if(pm & PM_HVPP)
strcat(type, ", HVPP");
if(pm & PM_debugWIRE)
strcat(type, ", debugWIRE");
if(pm & PM_JTAG)
strcat(type, ", JTAG");
if(pm & PM_JTAGmkI)
strcat(type, ", JTAGmkI");
if(pm & PM_XMEGAJTAG)
strcat(type, ", XMEGAJTAG");
if(pm & PM_AVR32JTAG)
strcat(type, ", AVR32JTAG");
if(pm & PM_aWire)
strcat(type, ", aWire");
if(pm & PM_SPM)
strcat(type, ", SPM");

return type + (type[1] == 0? 0: 3);
}


void avr_display(FILE *f, const AVRPART *p, const char *prefix, int verbose) {
char * buf;
const char * px;
LNODEID ln;
AVRMEM * m;

fprintf( f, "%sAVR Part : %s\n", prefix, p->desc);
if (p->chip_erase_delay)
fprintf(f, "%sChip Erase delay : %d us\n", prefix, p->chip_erase_delay);
if (p->pagel)
fprintf(f, "%sPAGEL : P%02X\n", prefix, p->pagel);
if (p->bs2)
fprintf(f, "%sBS2 : P%02X\n", prefix, p->bs2);
fprintf( f, "%sRESET disposition : %s\n", prefix, reset_disp_str(p->reset_disposition));
fprintf( f, "%sRETRY pulse : %s\n", prefix, avr_pin_name(p->retry_pulse));
fprintf( f, "%sSerial program mode : %s\n", prefix, (p->flags & AVRPART_SERIALOK) ? "yes" : "no");
fprintf( f, "%sParallel program mode : %s\n", prefix, (p->flags & AVRPART_PARALLELOK) ?
((p->flags & AVRPART_PSEUDOPARALLEL) ? "pseudo" : "yes") : "no");
if(p->timeout)
fprintf(f, "%sTimeout : %d\n", prefix, p->timeout);
if(p->stabdelay)
fprintf(f, "%sStabDelay : %d\n", prefix, p->stabdelay);
if(p->cmdexedelay)
fprintf(f, "%sCmdexeDelay : %d\n", prefix, p->cmdexedelay);
if(p->synchloops)
fprintf(f, "%sSyncLoops : %d\n", prefix, p->synchloops);
if(p->bytedelay)
fprintf(f, "%sByteDelay : %d\n", prefix, p->bytedelay);
if(p->pollindex)
fprintf(f, "%sPollIndex : %d\n", prefix, p->pollindex);
if(p->pollvalue)
fprintf(f, "%sPollValue : 0x%02x\n", prefix, p->pollvalue);
fprintf( f, "%sMemory Detail :\n\n", prefix);

px = prefix;
buf = (char *) cfg_malloc("avr_display()", strlen(prefix) + 5);
strcpy(buf, prefix);
strcat(buf, " ");
px = buf;

if (verbose <= 2)
avr_mem_display(px, f, NULL, p, verbose);

for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
m = ldata(ln);
avr_mem_display(px, f, m, p, verbose);
}
fprintf(f, "%sAVR Part : %s\n", prefix, p->desc);
fprintf(f, "%sProgramming modes : %s\n", prefix, avr_prog_modes_str(p->prog_modes));

if (buf)
free(buf);
if(strlen(prefix) == 0 || verbose > 1) {
MCUdude marked this conversation as resolved.
Show resolved Hide resolved
avr_mem_display(f, p, prefix);
avr_variants_display(f, p, prefix);
}
}


Expand Down
Loading