Add the ability to read a per-user config file located at

$HOME/.avrduderc.  Entries from .avrduderc take precedence over those
from the system wide config file in ${PREFIX}/etc/avrdude.conf.

Track and display the config file name and line number when we print
out the available parts and programmers.  This is useful in case
someone has overridden a definition in their .avrduderc file and is
wondering why the definition in the system wide config file is not
being used.

Remove the default programmer 'stk500' from the distributed config
file.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@222 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2003-02-22 16:45:13 +00:00
parent a2b9c401e3
commit 04da94efb9
8 changed files with 113 additions and 35 deletions

2
avr.c
View File

@ -60,6 +60,8 @@ AVRPART * avr_new_part(void)
p->reset_disposition = RESET_DEDICATED; p->reset_disposition = RESET_DEDICATED;
p->retry_pulse = PIN_AVR_SCK; p->retry_pulse = PIN_AVR_SCK;
p->flags = AVRPART_SERIALOK | AVRPART_PARALLELOK; p->flags = AVRPART_SERIALOK | AVRPART_PARALLELOK;
p->config_file[0] = 0;
p->lineno = 0;
p->mem = lcreat(NULL, 0); p->mem = lcreat(NULL, 0);

View File

@ -174,7 +174,6 @@
# #
default_parallel = "/dev/ppi0"; default_parallel = "/dev/ppi0";
default_serial = "/dev/cuaa0"; default_serial = "/dev/cuaa0";
default_programmer = "stk500";
# #

View File

@ -22,6 +22,8 @@
#ifndef __avrpart_h__ #ifndef __avrpart_h__
#define __avrpart_h__ #define __avrpart_h__
#include <limits.h>
#include "lists.h" #include "lists.h"
/* /*
@ -91,6 +93,8 @@ typedef struct avrpart {
OPCODE * op[AVR_OP_MAX]; /* opcodes */ OPCODE * op[AVR_OP_MAX]; /* opcodes */
LISTID mem; /* avr memory definitions */ LISTID mem; /* avr memory definitions */
char config_file[PATH_MAX]; /* config file where defined */
int lineno; /* config file line number */
} AVRPART; } AVRPART;
#define AVR_MEMDESCLEN 64 #define AVR_MEMDESCLEN 64

View File

@ -154,7 +154,10 @@ def :
prog_def : prog_def :
K_PROGRAMMER K_PROGRAMMER
{ current_prog = pgm_new(); } { current_prog = pgm_new();
strcpy(current_prog->config_file, infile);
current_prog->lineno = lineno;
}
prog_parms prog_parms
{ {
if (lsize(current_prog->id) == 0) { if (lsize(current_prog->id) == 0) {
@ -168,7 +171,7 @@ prog_def :
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
ladd(programmers, current_prog); PUSH(programmers, current_prog);
current_prog = NULL; current_prog = NULL;
} }
; ;
@ -176,7 +179,11 @@ prog_def :
part_def : part_def :
K_PART K_PART
{ current_part = avr_new_part(); } {
current_part = avr_new_part();
strcpy(current_part->config_file, infile);
current_part->lineno = lineno;
}
part_parms part_parms
{ {
LNODEID ln; LNODEID ln;
@ -226,7 +233,7 @@ part_def :
} }
} }
ladd(part_list, current_part); PUSH(part_list, current_part);
current_part = NULL; current_part = NULL;
} }
; ;

112
main.c
View File

@ -39,6 +39,8 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "avr.h" #include "avr.h"
#include "config.h" #include "config.h"
@ -59,8 +61,6 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
PROGRAMMER * pgm = NULL; PROGRAMMER * pgm = NULL;
PROGRAMMER * compiled_in_pgm;
/* /*
* global options * global options
*/ */
@ -140,6 +140,7 @@ int read_config(char * file)
return -1; return -1;
} }
lineno = 1;
infile = file; infile = file;
yyin = f; yyin = f;
@ -155,7 +156,8 @@ int read_config(char * file)
void programmer_display(char * p) void programmer_display(char * p)
{ {
fprintf(stderr, "%sProgrammer Type: %s\n", p, pgm->type); fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type);
fprintf(stderr, "%sDescription : %s\n", p, pgm->desc);
pgm->display(pgm, p); pgm->display(pgm, p);
} }
@ -227,7 +229,23 @@ void list_parts(FILE * f, char * prefix, LISTID parts)
for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) { for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
p = ldata(ln1); p = ldata(ln1);
fprintf(f, "%s%-4s = %s\n", prefix, p->id, p->desc); fprintf(f, "%s%-4s = %-15s [%s:%d]\n",
prefix, p->id, p->desc, p->config_file, p->lineno);
}
return;
}
void list_programmers(FILE * f, char * prefix, LISTID programmers)
{
LNODEID ln1;
PROGRAMMER * p;
for (ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) {
p = ldata(ln1);
fprintf(f, "%s%-8s = %-30s [%s:%d]\n",
prefix, (char *)ldata(lfirst(p->id)), p->desc,
p->config_file, p->lineno);
} }
return; return;
@ -252,6 +270,7 @@ int main(int argc, char * argv [])
int ppidata; /* cached value of the ppi data register */ int ppidata; /* cached value of the ppi data register */
int vsize=-1; /* number of bytes to verify */ int vsize=-1; /* number of bytes to verify */
AVRMEM * sig; /* signature data */ AVRMEM * sig; /* signature data */
struct stat sb;
/* options / operating mode variables */ /* options / operating mode variables */
char * memtype; /* "flash", "eeprom", etc */ char * memtype; /* "flash", "eeprom", etc */
@ -270,10 +289,12 @@ int main(int argc, char * argv [])
char * exitspecs; /* exit specs string from command line */ char * exitspecs; /* exit specs string from command line */
char * programmer; /* programmer id */ char * programmer; /* programmer id */
char * partdesc; /* part id */ char * partdesc; /* part id */
char configfile[PATH_MAX]; /* pin configuration file */ char sys_config[PATH_MAX]; /* system wide config file */
char usr_config[PATH_MAX]; /* per-user config file */
int cycles; /* erase-rewrite cycles */ int cycles; /* erase-rewrite cycles */
int set_cycles; /* value to set the erase-rewrite cycles to */ int set_cycles; /* value to set the erase-rewrite cycles to */
char * e; /* for strtol() error checking */ char * e; /* for strtol() error checking */
char * homedir;
progname = rindex(argv[0],'/'); progname = rindex(argv[0],'/');
if (progname) if (progname)
@ -309,11 +330,21 @@ int main(int argc, char * argv [])
do_cycles = 0; do_cycles = 0;
set_cycles = -1; set_cycles = -1;
strcpy(configfile, CONFIG_DIR); strcpy(sys_config, CONFIG_DIR);
i = strlen(configfile); i = strlen(sys_config);
if (i && (configfile[i-1] != '/')) if (i && (sys_config[i-1] != '/'))
strcat(configfile, "/"); strcat(sys_config, "/");
strcat(configfile, "avrdude.conf"); strcat(sys_config, "avrdude.conf");
usr_config[0] = 0;
homedir = getenv("HOME");
if (homedir != NULL) {
strcpy(usr_config, homedir);
i = strlen(usr_config);
if (i && (usr_config[i-1] != '/'))
strcat(usr_config, "/");
strcat(usr_config, ".avrduderc");
}
len = strlen(progname) + 2; len = strlen(progname) + 2;
for (i=0; i<len; i++) for (i=0; i<len; i++)
@ -339,9 +370,9 @@ int main(int argc, char * argv [])
programmer = optarg; programmer = optarg;
break; break;
case 'C': /* pin configuration file */ case 'C': /* system wide configuration file */
strncpy(configfile, optarg, PATH_MAX); strncpy(sys_config, optarg, PATH_MAX);
configfile[PATH_MAX-1] = 0; sys_config[PATH_MAX-1] = 0;
break; break;
case 'm': /* select memory type to operate on */ case 'm': /* select memory type to operate on */
@ -481,13 +512,48 @@ int main(int argc, char * argv [])
progname, version, progbuf); progname, version, progbuf);
} }
rc = read_config(configfile); if (verbose) {
fprintf(stderr, "%sSystem wide configuration file is \"%s\"\n",
progbuf, sys_config);
}
rc = read_config(sys_config);
if (rc) { if (rc) {
fprintf(stderr, "%s: error reading configuration file \"%s\"\n", fprintf(stderr,
progname, configfile); "%s: error reading system wide configuration file \"%s\"\n",
progname, sys_config);
exit(1); exit(1);
} }
if (usr_config[0] != 0) {
if (verbose) {
fprintf(stderr, "%sUser configuration file is \"%s\"\n",
progbuf, usr_config);
}
rc = stat(usr_config, &sb);
if ((rc < 0) || ((sb.st_mode & S_IFREG) == 0)) {
if (verbose) {
fprintf(stderr,
"%sUser configuration file does not exist or is not a "
"regular file, skipping\n",
progbuf);
}
}
else {
rc = read_config(usr_config);
if (rc) {
fprintf(stderr, "%s: error reading user configuration file \"%s\"\n",
progname, usr_config);
exit(1);
}
}
}
if (verbose) {
fprintf(stderr, "\n");
}
if (programmer[0] == 0) { if (programmer[0] == 0) {
fprintf(stderr, fprintf(stderr,
"\n%s: no programmer has been specified on the command line " "\n%s: no programmer has been specified on the command line "
@ -501,9 +567,12 @@ int main(int argc, char * argv [])
pgm = locate_programmer(programmers, programmer); pgm = locate_programmer(programmers, programmer);
if (pgm == NULL) { if (pgm == NULL) {
fprintf(stderr,"\n");
fprintf(stderr, fprintf(stderr,
"%s: Can't find programmer id \"%s\"\n", "%s: Can't find programmer id \"%s\"\n",
progname, programmer); progname, programmer);
fprintf(stderr,"\nValid programmers are:\n");
list_programmers(stderr, " ", programmers);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
exit(1); exit(1);
} }
@ -516,13 +585,11 @@ int main(int argc, char * argv [])
if (partdesc == NULL) { if (partdesc == NULL) {
fprintf(stderr, fprintf(stderr,
"%s: No AVR part has been specified, use \"-p Part\"\n\n" "%s: No AVR part has been specified, use \"-p Part\"\n\n",
" Valid Parts are:\n\n",
progname); progname);
fprintf(stderr,"Valid parts are:\n");
list_parts(stderr, " ", part_list); list_parts(stderr, " ", part_list);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "(These come from the config file \"%s\")\n", configfile);
fprintf(stderr, "\n");
exit(1); exit(1);
} }
@ -530,12 +597,11 @@ int main(int argc, char * argv [])
p = locate_part(part_list, partdesc); p = locate_part(part_list, partdesc);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, fprintf(stderr,
"%s: AVR Part \"%s\" not found. Valid parts are:\n\n", "%s: AVR Part \"%s\" not found.\n\n",
progname, partdesc); progname, partdesc);
fprintf(stderr,"Valid parts are:\n");
list_parts(stderr, " ", part_list); list_parts(stderr, " ", part_list);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "(These come from the config file \"%s\")\n", configfile);
fprintf(stderr, "\n");
exit(1); exit(1);
} }

4
par.c
View File

@ -553,10 +553,6 @@ static void par_display(PROGRAMMER * pgm, char * p)
strcpy(buffpins, " (not used)"); strcpy(buffpins, " (not used)");
} }
fprintf(stderr, "%sProgrammer Pin Configuration: %s (%s)\n", p,
(char *)ldata(lfirst(pgm->id)), pgm->desc);
fprintf(stderr, fprintf(stderr,
"%s VCC = 0x%02x%s\n" "%s VCC = 0x%02x%s\n"
"%s BUFF = 0x%02x%s\n" "%s BUFF = 0x%02x%s\n"

2
pgm.c
View File

@ -55,6 +55,8 @@ PROGRAMMER * pgm_new(void)
pgm->id = lcreat(NULL, 0); pgm->id = lcreat(NULL, 0);
pgm->desc[0] = 0; pgm->desc[0] = 0;
pgm->type[0] = 0; pgm->type[0] = 0;
pgm->config_file[0] = 0;
pgm->lineno = 0;
for (i=0; i<N_PINS; i++) for (i=0; i<N_PINS; i++)
pgm->pinno[i] = 0; pgm->pinno[i] = 0;

2
pgm.h
View File

@ -66,6 +66,8 @@ typedef struct programmer_t {
int page_size, int n_bytes); int page_size, int n_bytes);
int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes); int page_size, int n_bytes);
char config_file[PATH_MAX]; /* config file where defined */
int lineno; /* config file line number */
} PROGRAMMER; } PROGRAMMER;