Commit Graph

47 Commits

Author SHA1 Message Date
Stefan Rueger
2be7f7e527 Refer to memory rather than memory type 2023-10-27 00:28:29 +01:00
Stefan Rueger
03db6e5ca9 Use memory type for fuse memories instead of fuse names 2023-10-27 00:07:34 +01:00
Stefan Rueger
cd53766d1d Replace str_eq(m->desc, "...") with mem_is_...(m) 2023-10-25 16:35:11 +01:00
Stefan Rueger
26aedba188 Rename memtype to memstr, memchr or mtype
The name memtype can mean different things in the AVRDUDE src.
Mostly it means the name string of the memory, eg, "flash" or
"eeprom"; sometimes it is a character designating a memory, eg, 'E'
for "eeprom"; and yet at other times it means a programmer-defined
memory type, eg, MTYPE_BOOT_FLASH. The occurrences of memtype in
the code have now neen renamed appropriately.
2023-10-25 00:05:25 +01:00
Stefan Rueger
2a50032214 Review LED support (#1528)
The RDY LED is set once the programmer is initialised and switched
off when AVRDUDE exits. During reading, writing or erasing the target
the PGM LED flashes with around 2.5 Hz, whilst the VFY LED comes on
during -U verification of the uploaded contents. Errors are indicated
with the ERR LED.

Assuming AVRDUDE got to the point where LEDs are accessible and the RDY
LED was switched on then, on exit, AVRDUDE will leave the LEDs in the
following states:

| PGM | VFY | ERR | Semantics                                        |
| --- | --- | --- | ------------------------------------------------ |
| off | off | off | OK: all tasks done without errors                |
| off | off | on  | Some error not related to read/write/erase       |
| on  | off | on  | Read/write/erase error                           |
| off | on  | on  | Verification error but no read/write/erase error |
| on  | on  | on  | Read/write/erase error and verification error    |

Other combinations should not show after exit.
2023-10-23 23:57:59 +01:00
MCUdude
e6b5fb3a77 Replace even more strcmp/strncmp with str_eq/str_starts 2023-08-09 22:42:41 +02:00
Stefan Rueger
9fbc3d7a61 Update Brian Dean's email address 2023-06-27 21:31:07 +01:00
Stefan Rueger
07c5348ab4 Merge pull request #1405 from stefanrueger/pre-checks
Relax checks before executing the -T/-U operations
2023-06-16 00:06:01 +01:00
stefanrueger
14aba8ad65 Relax checks before executing the -T/-U operations
Now that terminal commands can create files, some of the checks before
executing the -T/-U operations need to be relaxed to avoid false errors.
The command below is perfectly fine, because the file to be read from in
the -U step will be created earlier.

$ rm -f /tmp/load.eep
$ avrdude -qq -cdryrun -pm328p \
  -T 'w ee 0 "avrdude"; save ee 0 8 /tmp/load.eep:h' \
  -U eeprom:w:/tmp/load.eep
2023-06-15 00:44:31 +01:00
Stefan Rueger
7d8f100878 Allow multiple -t interactive terminals on the command line
Think breakpoints for a series of memory operations. In this example

$ avrdude -t -U eeprom:r:dopp.eep:i -t -U eeprom:w:dopp.eep

the first -U makes a backup of the EEPROM that the second terminal can
then arbitrarily change because the second -U restores the EEPROM content.
2023-06-13 23:46:22 +01:00
Stefan Rueger
a694217603 Print all -U/-T arguments as headline when processing them 2023-06-02 21:23:25 +01:00
Stefan Rueger
fa9370d570 Insert a paragraph for each -T/-U option in AVRDUDE's output 2023-06-01 01:03:21 +01:00
Stefan Rueger
4a7d140b08 Move update_...() printing convenience functions to strutil.c and rename to str_...() 2023-05-31 22:50:27 +01:00
Stefan Rueger
bdbe13e1f6 Make arguments of update.c functions const if possible 2023-05-31 22:40:34 +01:00
Stefan Rueger
1126ff1621 Implement -T cmdline to mix terminal commands with -U commands 2023-05-31 22:23:23 +01:00
Stefan Rueger
5a8c051a22 Move file format conversions into one place 2023-05-19 15:28:56 +01:00
Stefan Rueger
d9e20708c1 Fix error in -U parsing 2023-05-18 00:22:05 +01:00
Stefan Rueger
fdedba8485 Simplify -U parsing so that more filenames with colons pass 2023-05-17 23:36:06 +01:00
Stefan Rueger
88d4d712df Extend <data> notion in terminal write to files
$ echo "The quick brown fox jumps over the lazy dog" >fox

$ avrdude -qqt
avrdude> w
Usage: write <memory> <addr> <data>[,] {<data>[,]}
       write <memory> <addr> <len> <data>[,] {<data>[,]} ...
       write <memory> <datum> # only for 1-byte memories
       write <memory> <file>  # only for memories with more than 1 byte

Ellipsis ... writes <len> bytes padded by repeating the last <data> item.

Both the <addr> and <len> can be negative numbers; a negative <addr> starts
an interval from that many bytes below the memory size; a negative <len> ends
the interval at that many bytes below the memory size.

<data> can be binary, octal, decimal or hexadecimal integers, floating point
numbers or C-style strings and characters. If nothing matches, <data> will be
interpreted as a file name containing data. In absence of a :<f> format
suffix, the terminal will try to auto-detect the file format.
[...]

avrdude> write eeprom 0 80 0xff ...

avrdude> write eeprom fox
avrdude error: (write) data fox: cannot determine format for file fox, specify explicitly

avrdude> write eeprom fox:r

avrdude> read eeprom 0 80
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0010  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0020  68 65 20 6c 61 7a 79 20  64 6f 67 0a ff ff ff ff  |he lazy dog ....|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write eeprom 0b10000 fox:r

avrdude> read eeprom 0 80
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0010  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0020  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0030  68 65 20 6c 61 7a 79 20  64 6f 67 0a ff ff ff ff  |he lazy dog ....|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write eeprom 0 80 0xff ...

avrdude> write eeprom 0 "Hello, world" 1 2 3 fox:r

avrdude> read eeprom 0 80
0000  48 65 6c 6c 6f 2c 20 77  6f 72 6c 64 00 01 02 03  |Hello, world....|
0010  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0020  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0030  68 65 20 6c 61 7a 79 20  64 6f 67 0a ff ff ff ff  |he lazy dog ....|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write eeprom 0 77 "Hello, world" 1 2 3 fox:r ...

avrdude> read eeprom 0 80
0000  48 65 6c 6c 6f 2c 20 77  6f 72 6c 64 00 01 02 03  |Hello, world....|
0010  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0020  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0030  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0040  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 ff ff ff  |quick brown f...|
2023-05-14 20:12:32 +01:00
Stefan Rueger
319ee2db9c Silence fall through warning in update.c 2023-01-11 17:34:51 +00:00
Stefan Rueger
68c6ffd7fc Silence compiler warnings, change comments, remove typos 2022-11-24 12:14:54 +00:00
Stefan Rueger
f276d325ec Handle verification errors in read only memory areas gracefully 2022-11-20 00:27:49 +00:00
Stefan Rueger
6e3a99be87 Add write statistics for patched flash input files at notice2 level 2022-11-11 01:27:55 +00:00
Stefan Rueger
c67bfe39a3 Show input file staistics before patching in update.c 2022-11-10 23:00:18 +00:00
Stefan Rueger
e6c26d8db4 Provide urclock programmer 2022-11-06 01:29:07 +00:00
Stefan Rueger
87df3216cb Make fileio() and do_op() arguments const where possible 2022-10-29 10:48:47 +01:00
Stefan Rueger
5b008a04cf Revamp terminal output: progress bar, callback and stdout/stderr (#1132)
* Print parms output to stdout
* Flush terminal writes and other minor changes
* Prepare terminal for periodic calls to programmer to reset bootloader WDT
* Only show progress reports for memories > 32 bytes or on -vv
* Freeze progress bar on serious error
* Allow cached r/w byte routines to be used in pgm->read_byte and pgm->write_byte
2022-10-23 21:56:45 +01:00
Stefan Rueger
e172877724 Review and overhaul AVRDUDE's messaging system (#1126)
* Change avrdude_message(MSG_XYZ, ...) to msg_xyz(...)
* Define and use pmsg_xyz(...) instead of msg_xyz("%s: ...", progname, ...)
* Review and change avrdude_message() levels
   - Introduce new levels warning, error and ext_error
   - Distribute info level to info, warning, error, ext_error
   - Assign levels (more) consistently
   - Unify grammar, punctuation and style of messages
* Use imsg_xyz() to print indented messages
* Show function name in errors and warnings on -v
* Reduce effective verbosity level by number of -q above one
2022-10-17 15:44:55 +01:00
Stefan Rueger
0b94ffdd3b Merge pull request #1059 from stefanrueger/programmer-devopts
Implement -c <wildcard>/dev_options for printing programmer entries of avrdude.conf
2022-08-15 00:48:35 +01:00
Stefan Rueger
f4c5a8350d Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.

config_gram.y now only needs to consider one type of string assignment.

This commit also

  - Replaces the simple linear-search cache_string() function with faster
    hashed cache_string(). Either way, the returned value is likely to be
    shared, so should never be free()'d.

  - Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()

  - Adds const qualifier to some function args in avrpart.c and pgm.c

  - Hardens some functions against being called with NULL pointers

  - Ensures _new() and _dup() functions for parts, programmers and memory
    return a suitable memory. Out of memory triggers exit in one of three
    functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
    rarely anything useful that AVRDUDE or, for that matter, any
    application compiled against libavrdude can do once you run out of
    memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 16:14:56 +01:00
Stefan Rueger
22c4dbf23e Harden string processing during parsing in lexer.l, config_gram.y and otherwise
- Replace strdup(s) with cfg_strdup(funname, s) that exits on out of mem
 - Replace malloc(n) with cfg_malloc(funname, n) that exits on out of mem
 - Change multiline string scanning in lexer.l to avoid core dump
 - Remove global variables string_buf and string_bug_ptr
 - Ensure reading strings unescapes strings C-Style
 - Ensure writing strings escapes strings C-Style again

Commit looks longer than needed as unescape() and auxiliary functions needed
to be moved from term.c (not in libavrdude) to config.c (in libavrdude).
2022-08-09 21:20:44 +01:00
Stefan Rueger
a8bbedcde3 Switch from strerror_r() to strerror() in update.c for portability 2022-08-06 00:20:43 +01:00
Stefan Rueger
b24a1cf667 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
2022-08-05 17:38:59 +01:00
Stefan Rueger
5f5002eeaa Change name of update helper functions for print messages 2022-08-04 18:25:14 +01:00
Stefan Rueger
ed36c7e1f6 Merge branch 'main' into fix_1041 2022-08-04 18:03:49 +01:00
Stefan Rueger
3412196cd9 Weaken -U memory type check and move after config file parsing in main.c
The check for typos in -U memory names against a list of known memory names
now happens after the config files have been read, so newly declared memory
names can be considered. This commit also weakens the check against existence
of a known memory: it is now sufficent for a name to pass when it could be
the initial string of any known memory of any part. Any -U memory that cannot
possibly be matched up with a known memory is considered a typo and leads to
an exit before the programmer is opened.

This to protect users from typos that leave a device partially programmed.

When every -U memory name might be matching one of the known memories, the
programming is attempted. If the part to be programmed turns out not to have
a particular -U memory, AVRDUDE warns the user and skips this -U update.

This to support unifying interfaces that call AVRDUDE with potentially more
memories than the actual part has (eg, efuse on ATmega8).
2022-08-04 00:14:19 +01:00
Stefan Rueger
648f3319a9 Ignore target memories not present in part
$ avrdude -qp m8 -c ... -U efuse:w:0xff:m && echo OK

avrdude: AVR device initialized and ready to accept instructions
avrdude: skipping -U efuse:... as memory not defined for part ATmega8

avrdude done.  Thank you.

OK
2022-08-03 00:23:15 +01:00
Stefan Rueger
9604a3ef36 Check -U option for unknown memories during parsing
$ avrdude -qp ATmega2560 -c usbtiny -U flesh:w:blink-mega2560+lext-test.hex:i
avrdude: unknown memory type flesh
avrdude: error parsing update operation 'flesh:w:blink-mega2560+lext-test.hex:i'
2022-08-03 00:04:14 +01:00
Stefan Rueger
02027ab766 Enable stdin verification and display correct number of bytes written/verified
Counting the number of bytes written to a memory and/or verified is not
trivial owing to potential holes in the input file and to potential trailing
0xff bytes in flash memory that are not written per default (but see -A). The
new function memstats(), which is best called just after an input file has
been read into mem->buf/mem->tags, computes the right number of bytes written
and allows easy computation of the number of bytes verified.

This commit also changes the strategy for the default verification after
writing to a chip memory, so that the input file only needs reading once thus
enabling successful verification of stdin input files.

Other, minor changes:
 - Improving the grammar of AVRDUDE output, eg, 1 byte written instead of
   1 bytes written
 - Better description of the input file structure in terms of its sections,
   the interval it spans, the number  of pages, the number of padding bytes
   in pages, and the number of actually cut off trailing 0xff bytes for flash
 - Printing <stdin> or <stdout> instead of - in the -U routines
 - Option -V no longer needs to be specified before option -U in order to work

As an aside this commit also provides useful helper functions for printing
plural(), inname(), outname() and interval() all of which return strings fit
for printing.

$ avrdude -qp ATmega2560 -c usbtiny -U blink-mega2560+lext-test.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: input file blink-mega2560+lext-test.hex auto detected as Intel Hex
avrdude: reading input file blink-mega2560+lext-test.hex for flash
         with 1346 bytes in 4 sections within [0, 0x3106d]
         using 7 pages and 446 pad bytes
avrdude: writing 1346 bytes flash ...
avrdude: 1346 bytes of flash written
avrdude: verifying flash memory against blink-mega2560+lext-test.hex
avrdude: 1346 bytes of flash verified

avrdude done.  Thank you.

$ avrdude -qp ATmega328P -c usb-bub-ii -U sketch-ending-in-ff.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: input file sketch-ending-in-ff.hex auto detected as Intel Hex
avrdude: reading input file sketch-ending-in-ff.hex for flash
         with 2160 bytes in 1 section within [0, 0x888]
         using 17 pages and 16 pad bytes, cutting off 25 trailing 0xff bytes
avrdude: writing 2160 bytes flash ...
avrdude: 2160 bytes of flash written
avrdude: verifying flash memory against sketch-ending-in-ff.hex
avrdude: 2185 bytes of flash verified

avrdude done.  Thank you.

$ echo "Hello, world..." | avrdude -qp ATmega328P -c ... -U eeprom:w:-:r

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file <stdin> for eeprom
avrdude: writing 16 bytes eeprom ...
avrdude: 16 bytes of eeprom written
avrdude: verifying eeprom memory against <stdin>
avrdude: 16 bytes of eeprom verified

avrdude done.  Thank you.
2022-08-02 23:26:01 +01:00
Joerg Wunsch
cc93bd2c83 Move the error handling for invalid file formats to fileio.c
The checks used to be in update.c, but as they are related to
the intended file operation, they are better placed in fileio.c.

The checks affected are to refuse 'm' on output (file write),
and 'd', 'h', 'o', and 'b' formats on input (file read).
2022-07-23 22:47:38 +02:00
Joerg Wunsch
26f431c944 Handle invalid -U file format specifiers for input
The file format specifiers 'h', 'd', 'o', and 'b' are only valid for
outputting data. Reject them with a proper error message when
attempting to use them for input.
2022-07-23 10:26:17 +02:00
Stefan Rueger
79921e52dc Provide file format I: Intel HEX with comments that ignores checksum errors
The new file type I is essentially Intel HEX that, on download, inserts
comments next to data records with the resolved effective address and an
ASCII dump of that same record. On upload the `I` format is permissive
with respect to check sum errors, eg, after manipulated an Intel HEX file
for debugging.
2022-07-16 23:40:36 +01:00
Stefan Rueger
f47ec634f8 On verify always verify full input file 2022-04-28 17:53:10 +01:00
MCUdude
3fc39c47ad Print memory name alias together with the canonical name if present
in avrdude.conf. An example would be "avrdude: reading fuse0/wdtcfg memory:"
2022-02-11 21:10:05 +01:00
MCUdude
b1cbbfc9f0 Reduce verbosity when setting fuses and uploading programs
Affects commands with no -v flag and one -v flag
2022-01-20 09:45:34 +01:00
Joerg Wunsch
cf35b7fe32 Include ac_cfg.h before libavrdude.h
On MSVC, this is required in order to have a definition of
PATH_MAX in place.
2022-01-10 14:51:48 +01:00
Marius Greuel
5633a6d88a Move source files to 'src' folder 2021-12-17 09:17:42 +01:00