Commit Graph

44 Commits

Author SHA1 Message Date
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 7375477f70
Replace string arrays with const char * and allocated space (part 1)
This commit deals with default_programmer, default_serial, default_parallel
and default_spi. The long term objective is to remove all fixed-size buffers
from the structures that lexer.l and config_gram.y deal with.
2022-08-10 11:36:17 +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 8a717987ec
Change unsigned short eecr; to unsigned char eecr; in libavrdude's AVRPART 2022-08-09 13:19:40 +01:00
Stefan Rueger 1da97f6825
Adjust declaration of locate_programmer_type_id() to definition 2022-08-08 17:21:21 +01:00
Stefan Rueger 49fcd8a96e
Implement -c */[sSA] (syntax-correct dump of programmer structure) 2022-08-08 16:52:09 +01:00
Stefan Rueger 075dee1dd3
Implement -c */r (raw dump of programmer structure) 2022-08-07 17:52:17 +01:00
Stefan Rueger 08049a40ea
Implement dev option -c */[ASsrt] skeleton
Also changed usbdev, usbsn, usbvendor and usbproduct components from
PROGRAMMER structure to be cached string pointers rather than fixed-size
arrays. These will be initialised by pgm_new() with a pointer to nul;
2022-08-07 14:06:04 +01:00
Stefan Rueger 5f5002eeaa Change name of update helper functions for print messages 2022-08-04 18:25:14 +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 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 42c8169c37 Add ordered list of known memories to avr.c with access functions 2022-08-02 23:53:00 +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
Stefan Rueger 7f63632c6e
Merge pull request #1040 from stefanrueger/partdesc
Developer options to describe parts and extend avrdude.conf syntax
2022-08-02 18:27:42 +01:00
Stefan Rueger 7730706498
Merge pull request #1030 from stefanrueger/ihexcomments
Provide file format I: Intel HEX with comments that ignores checksum errors
2022-08-02 18:23:23 +01:00
Stefan Rueger 62dcc2e6e8 Declare useful CMDBIT/part functions of developer_opts.c in libavrdude.h 2022-07-26 23:55:42 +01:00
Stefan Rueger 78754b8ccc Add parent id output for developer options -p*/s for parts 2022-07-26 23:43:56 +01:00
Stefan Rueger 8989e6515b Change macros __f() to _f() and adapt to config_file and hvupdi changes 2022-07-19 14:38:34 +01:00
Stefan Rueger 43e2955c61
Merge branch 'avrdudes:main' into partdesc 2022-07-19 13:20:25 +01:00
Stefan Rueger f95a1d3448 Cache config_file components in AVRPART and PROGRAMMER structures
Some 90% of the space of AVRPART and some 50% of PROGRAMMER is occupied by a
4 kB array config_file[] that contains the configuration file name. In
preparation of developer options that output a raw dump of the part
descriptions, this commit changes the config_file components from a large
array, which is duplicated in each part and programmer description, to a
cached string for each config file allowing for smaller raw dumps.

This commit also changes the config file name to its realpath(), eg, shortens
unwarranted `/bin/../etc/` file name components. It also changes the global
variable names `infile` and `fileno` to cfg_infile and cfg_fileno for an ever
so slight improvement of code clarity.
2022-07-18 18:10:09 +01:00
Stefan Rueger 068e78e832
Merge branch 'avrdudes:main' into partdesc 2022-07-18 16:02:01 +01:00
Stefan Rueger 6fa7400e4e
Merge pull request #1015 from MCUdude/hv-updi
Add support for high-voltage UPDI
2022-07-18 14:28:39 +01:00
Stefan Rueger 1d3a7591ea
Merge pull request #933 from MCUdude/linuxspi-default-port-fix
Fix linuxspi default port
2022-07-18 14:25:52 +01: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 3ef8122d90
Merge branch 'avrdudes:main' into partdesc 2022-07-12 18:19:17 +01:00
Stefan Rueger 0edb77bdf8
Merge branch 'main' into issue918 2022-07-12 15:05:45 +01:00
Stefan Rueger 215ea1af5c Merge branch 'partdesc' of github.com:stefanrueger/avrdude into partdesc 2022-07-07 18:34:26 +01:00
Stefan Rueger 9e2cea3ada Implement developer options -p */[*cdosSrwt] for part descriptions 2022-07-07 18:32:19 +01:00
Jan Egil Ruud 91310e6f50 Move hvupdi_support list to a new prog_parm_updi group, and initialize the list. 2022-07-07 12:23:05 +02:00
Ruud, Jan Egil 9e5ea25b9e Add HVUPDI_SUPPORT list for programmers. 2022-07-05 14:14:37 +02:00
MCUdude 577856cf15 Use HV UPDI constants rather than arbitrary numbers 2022-06-29 17:12:57 +02:00
MCUdude ba98e48880 add "hvupdi_variant" property to avrdude.conf 2022-06-29 17:12:52 +02:00
Joerg Wunsch 3082630430 Replace internal knowledge in jtag3.c by a public API
In certain situations (CRC failure, device locked), that JTAG3
read functions need to return an indication to the caller that
it is OK to proceed, and allow erasing the device anyway.

Historically, the JTAG3 code passed the respective protocol
errors directly (and unexplained) up to the caller, leaving
the decision to the caller how to handle the situation.

Replace that by a more common return value API. New code should
prefer this API instead of any hardcoded return values.
2022-06-15 23:32:22 +02:00
Stefan Rueger f47ec634f8 On verify always verify full input file 2022-04-28 17:53:10 +01:00
Stefan Rueger 52b20f4a28 Provide self-documenting API for disabling trailing-0xff removal 2022-04-28 17:26:09 +01:00
MCUdude 6fceea8f71 Fix linuxspi default port
If no port is specified, Avrdude will try to use the default port specified in avrdude.conf. If not present, use port specified in linuxspi.c
2022-04-11 22:28:12 +02:00
Jörg Wunsch d134dc8fff
Alias keyword (#868)
Implementation for an "alias" keyword.

By now, only applied inside memory descriptions.

* Make "mem_alias" a separate nonterminal.

The previous implementation attempt caused a syntax error in
yacc code, and separating mem_alias on the same level as
mem_spec appears to be the cleaner solution anyway.

* Maintain real memory aliases.

Instead of duplicating the aliased memory with a new name, maintain a
second list of memory aliases (per device) that contains a pointer to
the memory area it is aliased to. That way, a memory name can be
clearly distinguished between the canonical one and any aliases.

* Check p->mem_alias != NULL before touching it

* Add avr_find_memalias()

This takes a memory region as input, and searches whether an
alias can be found for it.

* We need to add a list structure for the mem_alias list, always.

By that means, mem_alias won't ever be NULL, so no need to check
later.

Also, in avr_dup_part(), duplicate the alias list.

* In a memory alias, actually remember the current name.

* In avr_dup_part(), adjust pointers of aliased memories

While walking the list of memories, for each entry, see if there is an
alias pointing to it. If so, allocate a duplicated one, and fix its
aliased_mem pointer to point to the duplicated memory region instead
of the original one.

* Add avr_locate_mem_noalias()

When looking whether any memory region has already been defined for
the current part while parsing the config file, only non-aliased names
must be considered. Otherwise, a newly defined alias would kick out
the memory definition it is being aliased to.

* When defining a mem_alias, drop any existing one of that name.

* Actually use avr_find_memalias() to find aliases

* Add declaration for avr_find_memalias()

* When defining a memory, also search for an existing alias

If the newly defined name has the same as an existing alias, the alias
can be removed.

Note that we do explicitly *not* remove any memory by the same name of
a later defined alias, as this might invalidate another alias'es
pointer. If someone defines that, the alias name just won't ever be
found by avr_locate_mem().
2022-02-10 20:39:19 +01:00
Joerg Wunsch 8c6c6a14ec Remove the "safemode" feature.
This feature has been designed with the sometimes quite flakey direct
(parallel or serial port attached) bitbang programming adapters in
mind that were quite common about two decades ago.

With parallel ports vanishing from modern PCs almost completely, and
the advent of various USB-attached low-cost programming devices,
this class of programmers disappeared almost completely.

Furthermore, the fuse combinations that were covered by the feature
are no longer around on all recent AVR devices, so for an ever
increasing number of devices, safemode already became meaningless and
was turned off anyway.

With the prospective version 7.x release, it's a good point in time to
introduce a major change like this one.
2022-01-31 20:44:32 +01:00
Jörg Wunsch cce7a934d6
Merge pull request #815 from MCUdude/add-memory-sections
Add more memory sections to read from
2022-01-21 21:49:29 +01:00
Joerg Wunsch fa8a31740f Remove ac_cfg.h from libavrdude.h 2022-01-10 14:27:08 +01:00
MCUdude 8f16c2a1e4 Add more memory sections to read from
+ improve Avrdude output in verbose mode
2022-01-08 23:57:37 +01:00
Marius Greuel fc54ef5e59 Clean up legacy code 2022-01-07 17:57:02 +01:00
Dawid Buchwald 291549d021 Merged AVRDUDES/main into SerialUPDI branch 2021-12-21 21:38:51 +01:00
Marius Greuel 5633a6d88a Move source files to 'src' folder 2021-12-17 09:17:42 +01:00