From 1836082a7a7fa835829ca56b22d1ca203c9b200f Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Fri, 21 Feb 2003 18:46:51 +0000 Subject: [PATCH] Add port name defaults to the config file instead of hard-coding. This adds 'default_parallel' and 'default_serial' keywords to the grammar, which take quoted string arguments. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@214 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/avrdude.conf.sample | 7 +++++++ avrdude/config.c | 3 +++ avrdude/config.h | 4 ++++ avrdude/config_gram.y | 17 ++++++++++++++++- avrdude/lexer.l | 2 ++ avrdude/main.c | 25 +++++++++++++++++++------ 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/avrdude/avrdude.conf.sample b/avrdude/avrdude.conf.sample index 8a853257..158d55bf 100644 --- a/avrdude/avrdude.conf.sample +++ b/avrdude/avrdude.conf.sample @@ -169,6 +169,13 @@ #define AT89S52 0xE1 +# +# Overall avrdude defaults +# +default_parallel = "/dev/ppi0"; +default_serial = "/dev/cuaa0"; + + # # PROGRAMMER DEFINITIONS # diff --git a/avrdude/config.c b/avrdude/config.c index 618850c8..f66e9a8f 100644 --- a/avrdude/config.c +++ b/avrdude/config.c @@ -30,6 +30,9 @@ #include "config.h" #include "config_gram.h" +char default_parallel[PATH_MAX]; +char default_serial[PATH_MAX]; + char string_buf[MAX_STR_CONST]; char *string_buf_ptr; diff --git a/avrdude/config.h b/avrdude/config.h index 00fb4b91..3e34b0ae 100644 --- a/avrdude/config.h +++ b/avrdude/config.h @@ -53,6 +53,10 @@ extern int lineno; extern char * infile; extern LISTID string_list; extern LISTID number_list; +extern char default_parallel[]; +extern char default_serial[]; + + #if !defined(HAS_YYSTYPE) #define YYSTYPE struct token_t * diff --git a/avrdude/config_gram.y b/avrdude/config_gram.y index 4ed73bd2..e06f3a1f 100644 --- a/avrdude/config_gram.y +++ b/avrdude/config_gram.y @@ -67,6 +67,8 @@ static int parse_cmdbits(OPCODE * op); %token K_BUFF %token K_CHIP_ERASE_DELAY %token K_DEDICATED +%token K_DEFAULT_PARALLEL +%token K_DEFAULT_SERIAL %token K_DESC %token K_DEVICECODE %token K_EEPROM @@ -126,7 +128,20 @@ config : def : prog_def TKN_SEMI | - part_def TKN_SEMI + + part_def TKN_SEMI | + + K_DEFAULT_PARALLEL TKN_EQUAL TKN_STRING TKN_SEMI { + strncpy(default_parallel, $3->value.string, PATH_MAX); + default_parallel[PATH_MAX-1] = 0; + free_token($3); + } | + + K_DEFAULT_SERIAL TKN_EQUAL TKN_STRING TKN_SEMI { + strncpy(default_serial, $3->value.string, PATH_MAX); + default_serial[PATH_MAX-1] = 0; + free_token($3); + } ; diff --git a/avrdude/lexer.l b/avrdude/lexer.l index c9f2d91d..26440d70 100644 --- a/avrdude/lexer.l +++ b/avrdude/lexer.l @@ -121,6 +121,8 @@ bs2 { yylval=NULL; return K_BS2; } buff { yylval=NULL; return K_BUFF; } chip_erase_delay { yylval=NULL; return K_CHIP_ERASE_DELAY; } desc { yylval=NULL; return K_DESC; } +default_parallel { yylval=NULL; return K_DEFAULT_PARALLEL; } +default_serial { yylval=NULL; return K_DEFAULT_SERIAL; } devicecode { yylval=NULL; return K_DEVICECODE; } eeprom { yylval=NULL; return K_EEPROM; } errled { yylval=NULL; return K_ERRLED; } diff --git a/avrdude/main.c b/avrdude/main.c index fb132e7b..f10a9257 100644 --- a/avrdude/main.c +++ b/avrdude/main.c @@ -86,9 +86,6 @@ #include "term.h" -#define DEFAULT_PARALLEL "/dev/ppi0" -#define DEFAULT_SERIAL "/dev/cuaa0" - char * version = "3.1.0"; int verbose; /* verbose output */ @@ -308,11 +305,14 @@ int main(int argc, char * argv []) else progname = argv[0]; + default_parallel[0] = 0; + default_serial[0] = 0; + init_config(); partdesc = NULL; readorwrite = 0; - port = DEFAULT_PARALLEL; + port = default_parallel; outputf = NULL; inputf = NULL; doread = 1; @@ -381,8 +381,8 @@ int main(int argc, char * argv []) case 'c': /* pin configuration */ pinconfig = optarg; if (strcmp(pinconfig, "stk500") == 0) { - if (port == DEFAULT_PARALLEL) { - port = DEFAULT_SERIAL; + if (port == default_parallel) { + port = default_serial; } } break; @@ -613,6 +613,19 @@ int main(int argc, char * argv []) /* * open the programmer */ + if (port[0] == 0) { + fprintf(stderr, "\n%s: no port has been specified on the command or the " + "config file\n", + progname); + fprintf(stderr, "%sSpecify a port using the -P option and try again\n\n", + progbuf); + exit(1); + } + + if (verbose) { + fprintf(stderr, "%sUsing Port : %s\n", progbuf, port); + } + pgm->open(pgm, port); if (verbose) {