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:
parent
2c3d88da51
commit
66d2a710db
2
avr.c
2
avr.c
|
@ -60,6 +60,8 @@ AVRPART * avr_new_part(void)
|
|||
p->reset_disposition = RESET_DEDICATED;
|
||||
p->retry_pulse = PIN_AVR_SCK;
|
||||
p->flags = AVRPART_SERIALOK | AVRPART_PARALLELOK;
|
||||
p->config_file[0] = 0;
|
||||
p->lineno = 0;
|
||||
|
||||
p->mem = lcreat(NULL, 0);
|
||||
|
||||
|
|
|
@ -174,7 +174,6 @@
|
|||
#
|
||||
default_parallel = "/dev/ppi0";
|
||||
default_serial = "/dev/cuaa0";
|
||||
default_programmer = "stk500";
|
||||
|
||||
|
||||
#
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef __avrpart_h__
|
||||
#define __avrpart_h__
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "lists.h"
|
||||
|
||||
/*
|
||||
|
@ -91,6 +93,8 @@ typedef struct avrpart {
|
|||
OPCODE * op[AVR_OP_MAX]; /* opcodes */
|
||||
|
||||
LISTID mem; /* avr memory definitions */
|
||||
char config_file[PATH_MAX]; /* config file where defined */
|
||||
int lineno; /* config file line number */
|
||||
} AVRPART;
|
||||
|
||||
#define AVR_MEMDESCLEN 64
|
||||
|
|
|
@ -154,7 +154,10 @@ def :
|
|||
|
||||
prog_def :
|
||||
K_PROGRAMMER
|
||||
{ current_prog = pgm_new(); }
|
||||
{ current_prog = pgm_new();
|
||||
strcpy(current_prog->config_file, infile);
|
||||
current_prog->lineno = lineno;
|
||||
}
|
||||
prog_parms
|
||||
{
|
||||
if (lsize(current_prog->id) == 0) {
|
||||
|
@ -168,7 +171,7 @@ prog_def :
|
|||
progname, infile, lineno);
|
||||
exit(1);
|
||||
}
|
||||
ladd(programmers, current_prog);
|
||||
PUSH(programmers, current_prog);
|
||||
current_prog = NULL;
|
||||
}
|
||||
;
|
||||
|
@ -176,7 +179,11 @@ prog_def :
|
|||
|
||||
part_def :
|
||||
K_PART
|
||||
{ current_part = avr_new_part(); }
|
||||
{
|
||||
current_part = avr_new_part();
|
||||
strcpy(current_part->config_file, infile);
|
||||
current_part->lineno = lineno;
|
||||
}
|
||||
part_parms
|
||||
{
|
||||
LNODEID ln;
|
||||
|
@ -226,7 +233,7 @@ part_def :
|
|||
}
|
||||
}
|
||||
|
||||
ladd(part_list, current_part);
|
||||
PUSH(part_list, current_part);
|
||||
current_part = NULL;
|
||||
}
|
||||
;
|
||||
|
|
110
main.c
110
main.c
|
@ -39,6 +39,8 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "avr.h"
|
||||
#include "config.h"
|
||||
|
@ -59,8 +61,6 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
|
|||
|
||||
PROGRAMMER * pgm = NULL;
|
||||
|
||||
PROGRAMMER * compiled_in_pgm;
|
||||
|
||||
/*
|
||||
* global options
|
||||
*/
|
||||
|
@ -140,6 +140,7 @@ int read_config(char * file)
|
|||
return -1;
|
||||
}
|
||||
|
||||
lineno = 1;
|
||||
infile = file;
|
||||
yyin = f;
|
||||
|
||||
|
@ -156,6 +157,7 @@ int read_config(char * file)
|
|||
void programmer_display(char * p)
|
||||
{
|
||||
fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type);
|
||||
fprintf(stderr, "%sDescription : %s\n", p, pgm->desc);
|
||||
|
||||
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)) {
|
||||
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;
|
||||
|
@ -252,6 +270,7 @@ int main(int argc, char * argv [])
|
|||
int ppidata; /* cached value of the ppi data register */
|
||||
int vsize=-1; /* number of bytes to verify */
|
||||
AVRMEM * sig; /* signature data */
|
||||
struct stat sb;
|
||||
|
||||
/* options / operating mode variables */
|
||||
char * memtype; /* "flash", "eeprom", etc */
|
||||
|
@ -270,10 +289,12 @@ int main(int argc, char * argv [])
|
|||
char * exitspecs; /* exit specs string from command line */
|
||||
char * programmer; /* programmer 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 set_cycles; /* value to set the erase-rewrite cycles to */
|
||||
char * e; /* for strtol() error checking */
|
||||
char * homedir;
|
||||
|
||||
progname = rindex(argv[0],'/');
|
||||
if (progname)
|
||||
|
@ -309,11 +330,21 @@ int main(int argc, char * argv [])
|
|||
do_cycles = 0;
|
||||
set_cycles = -1;
|
||||
|
||||
strcpy(configfile, CONFIG_DIR);
|
||||
i = strlen(configfile);
|
||||
if (i && (configfile[i-1] != '/'))
|
||||
strcat(configfile, "/");
|
||||
strcat(configfile, "avrdude.conf");
|
||||
strcpy(sys_config, CONFIG_DIR);
|
||||
i = strlen(sys_config);
|
||||
if (i && (sys_config[i-1] != '/'))
|
||||
strcat(sys_config, "/");
|
||||
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;
|
||||
for (i=0; i<len; i++)
|
||||
|
@ -339,9 +370,9 @@ int main(int argc, char * argv [])
|
|||
programmer = optarg;
|
||||
break;
|
||||
|
||||
case 'C': /* pin configuration file */
|
||||
strncpy(configfile, optarg, PATH_MAX);
|
||||
configfile[PATH_MAX-1] = 0;
|
||||
case 'C': /* system wide configuration file */
|
||||
strncpy(sys_config, optarg, PATH_MAX);
|
||||
sys_config[PATH_MAX-1] = 0;
|
||||
break;
|
||||
|
||||
case 'm': /* select memory type to operate on */
|
||||
|
@ -481,13 +512,48 @@ int main(int argc, char * argv [])
|
|||
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) {
|
||||
fprintf(stderr, "%s: error reading configuration file \"%s\"\n",
|
||||
progname, configfile);
|
||||
fprintf(stderr,
|
||||
"%s: error reading system wide configuration file \"%s\"\n",
|
||||
progname, sys_config);
|
||||
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) {
|
||||
fprintf(stderr,
|
||||
"\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);
|
||||
if (pgm == NULL) {
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr,
|
||||
"%s: Can't find programmer id \"%s\"\n",
|
||||
progname, programmer);
|
||||
fprintf(stderr,"\nValid programmers are:\n");
|
||||
list_programmers(stderr, " ", programmers);
|
||||
fprintf(stderr,"\n");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -516,13 +585,11 @@ int main(int argc, char * argv [])
|
|||
|
||||
if (partdesc == NULL) {
|
||||
fprintf(stderr,
|
||||
"%s: No AVR part has been specified, use \"-p Part\"\n\n"
|
||||
" Valid Parts are:\n\n",
|
||||
"%s: No AVR part has been specified, use \"-p Part\"\n\n",
|
||||
progname);
|
||||
fprintf(stderr,"Valid parts are:\n");
|
||||
list_parts(stderr, " ", part_list);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "(These come from the config file \"%s\")\n", configfile);
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -530,12 +597,11 @@ int main(int argc, char * argv [])
|
|||
p = locate_part(part_list, partdesc);
|
||||
if (p == NULL) {
|
||||
fprintf(stderr,
|
||||
"%s: AVR Part \"%s\" not found. Valid parts are:\n\n",
|
||||
"%s: AVR Part \"%s\" not found.\n\n",
|
||||
progname, partdesc);
|
||||
fprintf(stderr,"Valid parts are:\n");
|
||||
list_parts(stderr, " ", part_list);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "(These come from the config file \"%s\")\n", configfile);
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
4
par.c
4
par.c
|
@ -553,10 +553,6 @@ static void par_display(PROGRAMMER * pgm, char * p)
|
|||
strcpy(buffpins, " (not used)");
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, "%sProgrammer Pin Configuration: %s (%s)\n", p,
|
||||
(char *)ldata(lfirst(pgm->id)), pgm->desc);
|
||||
|
||||
fprintf(stderr,
|
||||
"%s VCC = 0x%02x%s\n"
|
||||
"%s BUFF = 0x%02x%s\n"
|
||||
|
|
2
pgm.c
2
pgm.c
|
@ -55,6 +55,8 @@ PROGRAMMER * pgm_new(void)
|
|||
pgm->id = lcreat(NULL, 0);
|
||||
pgm->desc[0] = 0;
|
||||
pgm->type[0] = 0;
|
||||
pgm->config_file[0] = 0;
|
||||
pgm->lineno = 0;
|
||||
|
||||
for (i=0; i<N_PINS; i++)
|
||||
pgm->pinno[i] = 0;
|
||||
|
|
2
pgm.h
2
pgm.h
|
@ -66,6 +66,8 @@ typedef struct programmer_t {
|
|||
int page_size, int n_bytes);
|
||||
int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
|
||||
int page_size, int n_bytes);
|
||||
char config_file[PATH_MAX]; /* config file where defined */
|
||||
int lineno; /* config file line number */
|
||||
} PROGRAMMER;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue