Commit Graph

26 Commits

Author SHA1 Message Date
Stefan Rueger ccb576ebc1
Ensure memories are printed at most once for -p */S 2022-08-10 22:25:19 +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 8a717987ec
Change unsigned short eecr; to unsigned char eecr; in libavrdude's AVRPART 2022-08-09 13:19:40 +01:00
Stefan Rueger 7c8d336e27
Change dev_info() to stdout and no longer redirect stderr to stdout 2022-08-09 09:23:26 +01:00
Stefan Rueger f25bc55806
Treat -c* the same as -c*/s 2022-08-08 17:03:06 +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 81136688f6
Establish a third option to print out part definitions
Introduced -p <part>/A, which prints what -p <part>/S used to print, ie, all
components of the part structures including the default ones. Now -p <part>/S
prints the expanded part structure without use of parent and without printing
default values. This functionality is new and predominantly needed for
checking specific avrdude.conf entries, eg, avrdude -p*/St | grep pollindex

The option -p <part>/s continues to print a short entry of `avrdude.conf`
using its parent if so defined:

$ avrdude -p m328p/s

part parent "m328"
    desc                = "ATmega328P";
    id                  = "m328p";
    signature           = 0x1e 0x95 0x0f;
;
2022-08-07 08:53:24 +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 004b46b594 Move useful CMDBIT/part functions from developer_opts.c to avrpart.c 2022-07-27 00:12:57 +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 1549273529 Add comments with part names to -p*/s output 2022-07-25 20:30:40 +01:00
Stefan Rueger d5d3a0e09e Improve help message -p/h for developer option -p 2022-07-24 23:38:51 +01:00
Stefan Rueger 5a517fb74d Make developer opts portable: change statement exprs and index(); use size_t 2022-07-22 23:50:22 +01:00
Stefan Rueger 572849ec2a Provide avr_set_addr_mem() to set addresses in SPI opcodes within boundaries
The function avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd,
unsigned long addr) is meant to replace avr_set_addr(OPCODE *op, unsigned
char *cmd, unsigned long addr) in future.

avr_set_addr_mem() has more information about the context of the task in that
it knows the memory size, memory page size, whether or not the memory is a
flash memory (which gets words addressees supplied) and, crucially, knows
which SPI operation it is meant to compute the address bits for.

avr_set_addr_mem() first computes the interval of bit numbers that must be
supplied for the SPI command to stand a chance to work. The function only
sets those address bits that are needed. Once all avr_set_addr() function
calls have been replaced by avr_set_addr_mem(), the SPI commands that need an
address can afford to declare in avrdude.conf all 16 address bits in the
middle two bytes of the SPI command. This over-declaration will be corrected
during runtime by avr_set_addr_mem(). One consequence of this is that parts
can inherit smaller or larger memories from parents without the need to use
different SPI codes in avrdude.conf. Another consequence is that
avr_set_addr_mem() can, and does, tell the caller whether vital address bits
were not declared in the SPI opcode. During parsing of avrdude.conf this
might be utilised to generate a corresponding warning. This will uncover
problematic SPI codes in avrdude.conf that in the past went undetected.
2022-07-21 21:42:07 +01:00
Stefan Rueger 55f6765ea5 Make more useful functions from developer_optc.c available 2022-07-21 18:47:48 +01:00
Stefan Rueger 192e118d2c Make useful functions from developer_optc.c available 2022-07-21 18:36:04 +01:00
Stefan Rueger 696574d1eb Replace !fnmatch(p, s, 0) with own part_match(p, s) 2022-07-21 18:04:41 +01:00
Stefan Rueger 6afa115a5f Make -p*/s print SPI opcodes like "0100.0000--000.aaaa--aaaa.aaaa--iiii.iiii" 2022-07-19 23:44:58 +01:00
Stefan Rueger bdb5ba6055 Add avrdude.conf syntax ((pp|hvsp)_controlstack|(eeprom|flash)_instr) = NULL; 2022-07-19 16:16:55 +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 9e2cea3ada Implement developer options -p */[*cdosSrwt] for part descriptions 2022-07-07 18:32:19 +01:00
Stefan Rueger 3bd75e74c6 Move developer options into own source file and expand part description -p \*
-p \*/c  check address bits in SPI commands
  -p \*/d  description of core part features
  -p \*/o  opcodes for SPI programming parts and memories
  -p \*/s  show avrdude.conf entries of parts
  -p \*/ss show full avrdude.conf entry as tab separated table
  -p \*/w  wd_... constants for ISP parts
  -p \*/\* all of the above except -p \*/s
  -p \*    same as -p\*/\*
2022-06-28 20:34:31 +01:00