Skip to content

Commit

Permalink
Merge pull request #1555 from stefanrueger/option-N
Browse files Browse the repository at this point in the history
Provide option -N for do not load personal config file
  • Loading branch information
stefanrueger committed Nov 13, 2023
2 parents 0c38591 + ff3e65e commit fb55022
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
6 changes: 6 additions & 0 deletions src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
.Op Fl B Ar bitclock
.Op Fl c Ar programmer-id
.Op Fl C Ar config-file
.Op Fl N
.Op Fl A
.Op Fl D
.Op Fl e
Expand All @@ -45,6 +46,7 @@
.Op Fl n
.Op Fl O
.Op Fl P Ar port
.Op Fl r
.Op Fl q
.Op Fl T Ar cmd
.Op Fl t
Expand Down Expand Up @@ -444,6 +446,10 @@ files. This can be used to add entries to the configuration
without patching your system wide configuration file. It can be used
several times, the files are read in same order as given on the command
line.
.It Fl N
Do not load the personal configuration file that is usually located at
~/.config/avrdude/avrdude.rc, ~/.avrduderc or in the same directory as the
avrdude executable
.It Fl A
Disable the automatic removal of trailing-0xFF sequences in file
input that is to be programmed to flash and in AVR reads from
Expand Down
23 changes: 14 additions & 9 deletions src/doc/avrdude.texi
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,6 @@ ATmega328P MCU properties; for more information run @code{avrdude -p x/h}.
Override the RS-232 connection baud rate specified in the respective
programmer's entry of the configuration file.

@item -r
Opens the serial port at 1200 baud and immediately closes it, waits 400 ms
for each @code{-r} on the command line and then establishes communication
with the programmer. This is commonly known as a "1200bps touch", and is
used to trigger programming mode for certain boards like Arduino Leonardo,
Arduino Micro/Pro Micro and the Arduino Nano Every. Longer waits, and
therefore multiple @code{-r} options, are sometimes needed for slower, less
powerful hosts.

@item -B @var{bitclock}
Specify the bit clock period for the JTAG, PDI, TPI, UPDI, or ISP
interface. The value is a floating-point number in microseconds.
Expand Down Expand Up @@ -561,6 +552,11 @@ without patching your system wide configuration file. It can be used
several times, the files are read in same order as given on the command
line.

@item -N
Do not load the personal configuration file that is usually located at
@code{~/.config/avrdude/avrdude.rc}, @code{~/.avrduderc} or in the same
directory as the avrdude executable.

@item -A
Disable the automatic removal of trailing-0xFF sequences in file
input that is to be programmed to flash and in AVR reads from
Expand Down Expand Up @@ -779,6 +775,15 @@ for a STK500.
Note: The ability to handle IPv6 hostnames and addresses is limited to
Posix systems (by now).

@item -r
Opens the serial port at 1200 baud and immediately closes it, waits 400 ms
for each @code{-r} on the command line and then establishes communication
with the programmer. This is commonly known as a "1200bps touch", and is
used to trigger programming mode for certain boards like Arduino Leonardo,
Arduino Micro/Pro Micro and the Arduino Nano Every. Longer waits, and
therefore multiple @code{-r} options, are sometimes needed for slower, less
powerful hosts.

@item -q
Disable (or quell) output of the progress bar while reading or writing
to the device. Specify it a second time for even quieter operation.
Expand Down
51 changes: 32 additions & 19 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,19 @@ int ovsigck; // 1 = override sig check, 0 = don't
const char *partdesc; // Part -p string
const char *pgmid; // Programmer -c string

static char usr_config[PATH_MAX]; // Per-user config file

/*
* usage message
*/
static void usage(void)
{
char *home = getenv("HOME");
size_t l = home? strlen(home): 0;
char *cfg = home && str_casestarts(usr_config, home)?
str_sprintf("~/%s", usr_config+l+(usr_config[l]=='/')):
str_sprintf("%s", usr_config);

msg_error(
"Usage: %s [options]\n"
"Options:\n"
Expand All @@ -230,6 +238,8 @@ static void usage(void)
" -b <baudrate> Override RS-232 baud rate\n"
" -B <bitclock> Specify bit clock period (us)\n"
" -C <config-file> Specify location of configuration file\n"
" -C +<config-file> Specify additional config file, can be repeated\n"
" -N Do not load %s%s\n"
" -c <programmer> Specify programmer; -c ? and -c ?type list all\n"
" -c <wildcard>/<flags> Run developer options for matched programmers,\n"
" e.g., -c 'ur*'/s for programmer info/definition\n"
Expand All @@ -256,7 +266,9 @@ static void usage(void)
" -l logfile Use logfile rather than stderr for diagnostics\n"
" -? Display this usage\n"
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
progname, version);
progname, strlen(cfg) < 24? "config file ": "", cfg, version);

free(cfg);
}


Expand Down Expand Up @@ -519,12 +531,12 @@ int main(int argc, char * argv [])
/* options / operating mode variables */
int erase; /* 1=erase chip, 0=don't */
int calibrate; /* 1=calibrate RC oscillator, 0=don't */
int no_avrduderc; /* 1=don't load personal conf file */
char * port; /* device port (/dev/xxx) */
const char *exitspecs; /* exit specs string from command line */
int explicit_c; /* 1=explicit -c on command line, 0=not specified there */
int explicit_e; /* 1=explicit -e on command line, 0=not specified there */
char sys_config[PATH_MAX]; /* system wide config file */
char usr_config[PATH_MAX]; /* per-user config file */
char executable_abspath[PATH_MAX]; /* absolute path to avrdude executable */
char executable_dirpath[PATH_MAX]; /* absolute path to folder with executable */
bool executable_abspath_found = false; /* absolute path to executable found */
Expand Down Expand Up @@ -611,6 +623,7 @@ int main(int argc, char * argv [])
port = NULL;
erase = 0;
calibrate = 0;
no_avrduderc = 0;
p = NULL;
ovsigck = 0;
quell_progress = 0;
Expand Down Expand Up @@ -641,11 +654,22 @@ int main(int argc, char * argv [])
return 0;
}

// Determine the location of personal configuration file
#if defined(WIN32)
win_usr_config_set(usr_config);
#else
usr_config[0] = 0;
if(!concatpath(usr_config, getenv("XDG_CONFIG_HOME"), XDG_USER_CONF_FILE, sizeof usr_config))
concatpath(usr_config, getenv("HOME"), ".config/" XDG_USER_CONF_FILE, sizeof usr_config);
if(stat(usr_config, &sb) < 0 || (sb.st_mode & S_IFREG) == 0)
concatpath(usr_config, getenv("HOME"), USER_CONF_FILE, sizeof usr_config);
#endif


/*
* process command line arguments
*/
while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:np:OP:qrstT:U:uvVx:yY:")) != -1) {
while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVx:yY:")) != -1) {

switch (ch) {
case 'b': /* override default programmer baud rate */
Expand Down Expand Up @@ -760,6 +784,10 @@ int main(int argc, char * argv [])
uflags |= UF_NOWRITE;
break;

case 'N':
no_avrduderc = 1;
break;

case 'O': /* perform RC oscillator calibration */
calibrate = 1;
break;
Expand Down Expand Up @@ -942,21 +970,6 @@ int main(int argc, char * argv [])
msg_trace2("sys_config_found = %s\n", sys_config_found ? "true" : "false");
msg_trace2("\n");

/*
* USER CONFIG
* -----------
* Determine the location of '.avrduderc'.
*/
#if defined(WIN32)
win_usr_config_set(usr_config);
#else
usr_config[0] = 0;
if(!concatpath(usr_config, getenv("XDG_CONFIG_HOME"), XDG_USER_CONF_FILE, sizeof usr_config))
concatpath(usr_config, getenv("HOME"), ".config/" XDG_USER_CONF_FILE, sizeof usr_config);
if(stat(usr_config, &sb) < 0 || (sb.st_mode & S_IFREG) == 0)
concatpath(usr_config, getenv("HOME"), USER_CONF_FILE, sizeof usr_config);
#endif

if (quell_progress == 0)
terminal_setup_update_progress();

Expand Down Expand Up @@ -984,7 +997,7 @@ int main(int argc, char * argv [])
free(real_sys_config);
}

if (usr_config[0] != 0) {
if (usr_config[0] != 0 && !no_avrduderc) {
imsg_notice("User configuration file is %s\n", usr_config);

rc = stat(usr_config, &sb);
Expand Down

0 comments on commit fb55022

Please sign in to comment.