Implement a dry run for -U updates before opening the programmer

This commit checks -U update requests for
  - Typos in memory names
  - Whether the files can be written or read
  - Automatic format detection if necessary

before opening the programmer. This to reduce the chances of the
programming failing midway through.

Minor additional changes:
  - Give strerror() system info when files are not read/writeable
  - Lift the auto detection message from MSG_INFO to MSG_NOTICE
  - Provide fileio_fmt_autodetect() in the AVRDUDE library
  - Rename fmtstr() in the AVRDUDE library to fileio_fmtstr() to
    avoid name clashes when an application links with it

Example:

$ avrdude -U - -U typo:r:.:h -U eeprom:w:testin:r -p ... -c ...
avrdude: can't auto detect file format for stdin/out, specify explicitly
avrdude: unknown memory type typo
avrdude: file . is not writeable (not a regular or character file?)
avrdude: file testin is not readable. No such file or directory
This commit is contained in:
Stefan Rueger
2022-08-05 17:38:59 +01:00
parent 5f5002eeaa
commit b24a1cf667
4 changed files with 175 additions and 22 deletions

View File

@@ -872,7 +872,9 @@ enum {
extern "C" {
#endif
char * fmtstr(FILEFMT format);
char * fileio_fmtstr(FILEFMT format);
int fileio_fmt_autodetect(const char * fname);
int fileio(int oprwv, char * filename, FILEFMT format,
struct avrpart * p, char * memtype, int size);
@@ -936,6 +938,14 @@ const char *update_inname(const char *fn);
const char *update_outname(const char *fn);
const char *update_interval(int a, int b);
// Helper functions for dry run to determine file access
int update_is_okfile(const char *fn);
int update_is_writeable(const char *fn);
int update_is_readable(const char *fn);
int update_dryrun(struct avrpart *p, UPDATE *upd);
#ifdef __cplusplus
}
#endif