From fd276c1e88b326fd72dae379318f0a3054da1ba7 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 28 Dec 2021 23:32:48 +0100 Subject: [PATCH 1/4] Add SerialUPDI documentation to man page --- src/avrdude.1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/avrdude.1 b/src/avrdude.1 index 053505f0..940cd499 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -222,6 +222,17 @@ supported in UPDI mode. The Curiosity Nano board is dubbed thus the name .Pa pkobn_updi . .Pp +SerialUPDI programmer implementation is based on Microchip's +.Em pymcuprog Li https://github.com/microchip-pic-avr-tools/pymcuprog +utility, but it also contains some performance improvements included in +Spence Kohde's +.Em DxCore +Arduino core +.Li https://github.com/SpenceKonde/DCore . +In a nutshell, this programmer consists of simple USB->UART adapter, diode +and couple of resistors. It uses serial connection to provide UPDI interface. +See the texinfo documentation for more details and known issues. +.Pp Input files can be provided, and output files can be written in different file formats, such as raw binary files containing the data to download to the chip, Intel hex format, or Motorola S-record From 374861f62e9de8321c924fbe584eade03c5101ca Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 4 Jan 2022 22:45:47 +0100 Subject: [PATCH 2/4] Move the system config file search after option processing For one, this allows us to use MSG_DEBUG in order to emit debug messages (requires -v processing). As another effect, if the -C conffile option was given, there is no need at all to run through all the process of looking up a system config file - it's right there already. Also, move it after the logfile creation if -l logfile was given, so the respective debug message can go to the logfile. --- src/main.c | 253 +++++++++++++++++++++++++++-------------------------- 1 file changed, 128 insertions(+), 125 deletions(-) diff --git a/src/main.c b/src/main.c index c56c933a..a44540eb 100644 --- a/src/main.c +++ b/src/main.c @@ -362,6 +362,8 @@ int main(int argc, char * argv []) setvbuf(stdout, (char*)NULL, _IOLBF, 0); setvbuf(stderr, (char*)NULL, _IOLBF, 0); + sys_config[0] = '\0'; + progname = strrchr(argv[0],'/'); #if defined (WIN32NATIVE) @@ -422,131 +424,6 @@ int main(int argc, char * argv []) is_open = 0; logfile = NULL; - /* - * EXECUTABLE ABSPATH - * ------------------ - * Determine the absolute path to avrdude executable. This will be used to - * locate the 'avrdude.conf' file later. - */ - int executable_dirpath_len; - int executable_abspath_len = wai_getExecutablePath( - executable_abspath, - PATH_MAX, - &executable_dirpath_len - ); - if ( - (executable_abspath_len != -1) && - (executable_abspath_len != 0) && - (executable_dirpath_len != -1) && - (executable_dirpath_len != 0) - ) { - // All requirements satisfied, executable path was found - executable_abspath_found = true; - - // Make sure the string is null terminated - executable_abspath[executable_abspath_len] = '\0'; - - // Replace all backslashes with forward slashes - i = 0; - while (true) { - if (executable_abspath[i] == '\0') { - break; - } - if (executable_abspath[i] == '\\') { - executable_abspath[i] = '/'; - } - i++; - } - - // Define 'executable_dirpath' to be the path to the parent folder of the - // executable. - strcpy(executable_dirpath, executable_abspath); - executable_dirpath[executable_dirpath_len] = '\0'; - - // Debug output - // avrdude_message(MSG_INFO, "executable_abspath = %s\n", executable_abspath); - // avrdude_message(MSG_INFO, "executable_abspath_len = %i\n", executable_abspath_len); - // avrdude_message(MSG_INFO, "executable_dirpath = %s\n", executable_dirpath); - // avrdude_message(MSG_INFO, "executable_dirpath_len = %i\n", executable_dirpath_len); - } - - /* - * SYSTEM CONFIG - * ------------- - * Determine the location of 'avrdude.conf'. Check in this order: - * 1. /../etc/avrdude.conf - * 2. /avrdude.conf - * 3. CONFIG_DIR/avrdude.conf - * - * When found, write the result into the 'sys_config' variable. - */ - if (executable_abspath_found) { - // 1. Check /../etc/avrdude.conf - strcpy(sys_config, executable_dirpath); - sys_config[PATH_MAX - 1] = '\0'; - i = strlen(sys_config); - if (i && (sys_config[i - 1] != '/')) - strcat(sys_config, "/"); - strcat(sys_config, "../etc/avrdude.conf"); - sys_config[PATH_MAX - 1] = '\0'; - if (access(sys_config, F_OK) == 0) { - sys_config_found = true; - } - else { - // 2. Check /avrdude.conf - strcpy(sys_config, executable_dirpath); - sys_config[PATH_MAX - 1] = '\0'; - i = strlen(sys_config); - if (i && (sys_config[i - 1] != '/')) - strcat(sys_config, "/"); - strcat(sys_config, "avrdude.conf"); - sys_config[PATH_MAX - 1] = '\0'; - if (access(sys_config, F_OK) == 0) { - sys_config_found = true; - } - } - } - if (!sys_config_found) { - // 3. Check CONFIG_DIR/avrdude.conf -#if defined(WIN32NATIVE) - win_sys_config_set(sys_config); -#else - strcpy(sys_config, CONFIG_DIR); - i = strlen(sys_config); - if (i && (sys_config[i - 1] != '/')) - strcat(sys_config, "/"); - strcat(sys_config, "avrdude.conf"); -#endif - if (access(sys_config, F_OK) == 0) { - sys_config_found = true; - } - } - // Debug output - // avrdude_message(MSG_INFO, "sys_config = %s\n", sys_config); - // avrdude_message(MSG_INFO, "sys_config_found = %s\n", sys_config_found ? "true" : "false"); - // avrdude_message(MSG_INFO, "\n"); - - /* - * USER CONFIG - * ----------- - * Determine the location of '.avrduderc'. Nothing changed here. - */ -#if defined(WIN32NATIVE) - win_usr_config_set(usr_config); -#else - 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"); - } -#endif - - - len = strlen(progname) + 2; for (i=0; i/../etc/avrdude.conf + * 2. /avrdude.conf + * 3. CONFIG_DIR/avrdude.conf + * + * When found, write the result into the 'sys_config' variable. + */ + if (executable_abspath_found) { + // 1. Check /../etc/avrdude.conf + strcpy(sys_config, executable_dirpath); + sys_config[PATH_MAX - 1] = '\0'; + i = strlen(sys_config); + if (i && (sys_config[i - 1] != '/')) + strcat(sys_config, "/"); + strcat(sys_config, "../etc/avrdude.conf"); + sys_config[PATH_MAX - 1] = '\0'; + if (access(sys_config, F_OK) == 0) { + sys_config_found = true; + } + else { + // 2. Check /avrdude.conf + strcpy(sys_config, executable_dirpath); + sys_config[PATH_MAX - 1] = '\0'; + i = strlen(sys_config); + if (i && (sys_config[i - 1] != '/')) + strcat(sys_config, "/"); + strcat(sys_config, "avrdude.conf"); + sys_config[PATH_MAX - 1] = '\0'; + if (access(sys_config, F_OK) == 0) { + sys_config_found = true; + } + } + } + if (!sys_config_found) { + // 3. Check CONFIG_DIR/avrdude.conf +#if defined(WIN32NATIVE) + win_sys_config_set(sys_config); +#else + strcpy(sys_config, CONFIG_DIR); + i = strlen(sys_config); + if (i && (sys_config[i - 1] != '/')) + strcat(sys_config, "/"); + strcat(sys_config, "avrdude.conf"); +#endif + if (access(sys_config, F_OK) == 0) { + sys_config_found = true; + } + } + } + // Debug output + avrdude_message(MSG_DEBUG, "sys_config = %s\n", sys_config); + avrdude_message(MSG_DEBUG, "sys_config_found = %s\n", sys_config_found ? "true" : "false"); + avrdude_message(MSG_DEBUG, "\n"); + + /* + * USER CONFIG + * ----------- + * Determine the location of '.avrduderc'. Nothing changed here. + */ +#if defined(WIN32NATIVE) + win_usr_config_set(usr_config); +#else + 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"); + } +#endif + if (quell_progress == 0) { if (isatty (STDERR_FILENO)) update_progress = update_progress_tty; From 6a87a110ccde968b61c910b7ccb6ecc176909321 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 4 Jan 2022 23:03:47 +0100 Subject: [PATCH 3/4] Move the config file names out as #define into avrdude.h --- src/avrdude.h | 7 +++++++ src/confwin.c | 8 ++++---- src/main.c | 10 +++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/avrdude.h b/src/avrdude.h index 738578f1..b4c7ee87 100644 --- a/src/avrdude.h +++ b/src/avrdude.h @@ -21,6 +21,13 @@ #ifndef avrdude_h #define avrdude_h +#define SYSTEM_CONF_FILE "avrdude.conf" +#if defined(WIN32NATIVE) +#define USER_CONF_FILE "avrdude.rc" +#else +#define USER_CONF_FILE ".avrduderc" +#endif + extern char * progname; /* name of program, for messages */ extern char progbuf[]; /* spaces same length as progname */ diff --git a/src/confwin.c b/src/confwin.c index 95446156..1be95e87 100644 --- a/src/confwin.c +++ b/src/confwin.c @@ -32,9 +32,9 @@ static char *filename; void win_sys_config_set(char sys_config[PATH_MAX]) { sys_config[0] = 0; - + /* Use Windows API call to search for the Windows default system config file.*/ - SearchPath(NULL, "avrdude.conf", NULL, PATH_MAX, sys_config, &filename); + SearchPath(NULL, SYSTEM_CONF_FILE, NULL, PATH_MAX, sys_config, &filename); return; } @@ -42,9 +42,9 @@ void win_sys_config_set(char sys_config[PATH_MAX]) void win_usr_config_set(char usr_config[PATH_MAX]) { usr_config[0] = 0; - + /* Use Windows API call to search for the Windows default user config file. */ - SearchPath(NULL, "avrdude.rc", NULL, PATH_MAX, usr_config, &filename); + SearchPath(NULL, USER_CONF_FILE, NULL, PATH_MAX, usr_config, &filename); return; } diff --git a/src/main.c b/src/main.c index a44540eb..47081c1b 100644 --- a/src/main.c +++ b/src/main.c @@ -708,7 +708,7 @@ int main(int argc, char * argv []) i = strlen(sys_config); if (i && (sys_config[i - 1] != '/')) strcat(sys_config, "/"); - strcat(sys_config, "../etc/avrdude.conf"); + strcat(sys_config, "../etc/" SYSTEM_CONF_FILE); sys_config[PATH_MAX - 1] = '\0'; if (access(sys_config, F_OK) == 0) { sys_config_found = true; @@ -720,7 +720,7 @@ int main(int argc, char * argv []) i = strlen(sys_config); if (i && (sys_config[i - 1] != '/')) strcat(sys_config, "/"); - strcat(sys_config, "avrdude.conf"); + strcat(sys_config, SYSTEM_CONF_FILE); sys_config[PATH_MAX - 1] = '\0'; if (access(sys_config, F_OK) == 0) { sys_config_found = true; @@ -736,7 +736,7 @@ int main(int argc, char * argv []) i = strlen(sys_config); if (i && (sys_config[i - 1] != '/')) strcat(sys_config, "/"); - strcat(sys_config, "avrdude.conf"); + strcat(sys_config, SYSTEM_CONF_FILE); #endif if (access(sys_config, F_OK) == 0) { sys_config_found = true; @@ -751,7 +751,7 @@ int main(int argc, char * argv []) /* * USER CONFIG * ----------- - * Determine the location of '.avrduderc'. Nothing changed here. + * Determine the location of '.avrduderc'. */ #if defined(WIN32NATIVE) win_usr_config_set(usr_config); @@ -763,7 +763,7 @@ int main(int argc, char * argv []) i = strlen(usr_config); if (i && (usr_config[i - 1] != '/')) strcat(usr_config, "/"); - strcat(usr_config, ".avrduderc"); + strcat(usr_config, USER_CONF_FILE); } #endif From 124ef7fe3d1ec2db9dbcf0a593ee9033fba54e92 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 4 Jan 2022 23:10:14 +0100 Subject: [PATCH 4/4] Move the backslash replacement out into a separate function --- src/main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 47081c1b..94222f56 100644 --- a/src/main.c +++ b/src/main.c @@ -302,6 +302,17 @@ static void cleanup_main(void) cleanup_config(); } +static void replace_backslashes(char *s) +{ + // Replace all backslashes with forward slashes + for (int i = 0; i < strlen(s); i++) { + if (s[i] == '\\') { + s[i] = '/'; + } + } +} + + /* * main routine */ @@ -667,17 +678,7 @@ int main(int argc, char * argv []) // Make sure the string is null terminated executable_abspath[executable_abspath_len] = '\0'; - // Replace all backslashes with forward slashes - i = 0; - while (true) { - if (executable_abspath[i] == '\0') { - break; - } - if (executable_abspath[i] == '\\') { - executable_abspath[i] = '/'; - } - i++; - } + replace_backslashes(executable_abspath); // Define 'executable_dirpath' to be the path to the parent folder of the // executable.