Commit Graph

83 Commits

Author SHA1 Message Date
Stefan Rueger e14e5d2f74
Update NEWS 2022-10-11 14:49:44 +01:00
Stefan Rueger 22362e9f08
Merge branch 'main' into pr-pointer-truncation 2022-10-11 14:43:19 +01:00
Stefan Rueger d3a3257cf7
Improve help message in terminal and provide new command pgerase (#1113) 2022-10-11 14:40:37 +01:00
Marius Greuel 9377acee0e Fix pointer truncation for Windows x64 2022-10-08 19:02:03 +02:00
Stefan Rueger d74b17b9b4
Provide cached byte-wise read/write API (#1106)
* Provide cached byte-wise read/write API

int avr_read_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const
  AVRMEM *mem, unsigned long addr, unsigned char *value);

int avr_write_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const
 AVRMEM *mem, unsigned long addr, unsigned char data);

int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);

int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p);

int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);

avr_read_byte_cached() and avr_write_byte_cached() use a cache if paged
routines are available and if the device memory is EEPROM or flash,
otherwise they fall back to pgm->read_byte() and pgm->write_byte(),
respectively. Byte-wise cached read always gets its data from the cache,
possibly after reading a page from the device memory. Byte-wise cached
write with an address in memory range only ever modifies the cache. Any
modifications are written to the device after calling avr_flush_cache() or
when attempting to read or write from a location outside the address range
of the device memory.

avr_flush_cache() synchronises pending writes to EEPROM and flash with the
device. With some programmer and part combinations, flash (and sometimes
EEPROM, too) looks like a NOR memory, ie, one can only write 0 bits, not 1
bits. When this is detected, either page erase is deployed (eg, with parts
that have PDI/UPDI interfaces), or if that is not available, both EEPROM
and flash caches are fully read in, a pgm->chip_erase() command is issued
and both EEPROM and flash are written back to the device. Hence, it can
take minutes to ensure that a single previously cleared bit is set and,
therefore, this routine should be called sparingly.

avr_chip_erase_cached() erases the chip and discards pending writes() to
flash or EEPROM. It presets the flash cache to all 0xff alleviating the
need to read from the device flash. However, if the programmer serves
bootloaders (pgm->prog_modes & PM_SPM) then the flash cache is reset
instead, necessitating flash memory be fetched from the device on first
read; the reason for this is that bootloaders emulate chip erase and they
won't overwrite themselves (some bootloaders, eg, optiboot ignore chip
erase commands altogether) making it truly unknowable what the flash
contents on device is after a chip erase. 

For EEPROM avr_chip_erase_cached() concludes that it has been deleted if a
previously cached EEPROM page that contained cleared bits now no longer
has these clear bits on the device. Only with this evidence is the EEPROM
cache preset to all 0xff otherwise the cache discards all pending writes
to EEPROM and is left unchanged otherwise.

Finally, avr_reset_cache() resets the cache without synchronising pending
writes() to the device.
2022-10-05 22:16:15 +01:00
MCUdude e39133daf5 Initial support for Power Debugger analog reading
Voltage and current though channel A and B
2022-10-01 21:17:01 +02:00
Stefan Rueger e332ecf0b4
Change array for copy mem->desc to const char * in term.c 2022-08-15 14:25:58 +01:00
Stefan Rueger c9cf308037
Include ctype.h in term.c to resolve missing functions 2022-08-10 16:24:39 +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 e7e062ec05 Fix terminal line parsing for strings (to some extent) 2022-07-15 18:50:20 +01:00
Stefan Rueger 7ceb163cba Echo terminal command line on Apple 2022-07-14 18:31:44 +01:00
Stefan Rueger 14b27726d4 Protect terminal dump from vagaries of C libray implementation of isalpha() etc
Some C libraries assign true to isalpha(0xff), isdigit(0xff) or
ispunct(0xff), which means that the Operating System terminal sees a
character 0xff which it may not have a useful display character for.

This commit only outputs printable ASCII characters for an AVRDUDE
terminal dump reducing the risk of the OS terminal not being able
to print the character properly.
2022-07-14 17:16:30 +01:00
Stefan Rueger 5721908e63 Revert to double/float only in terminal write and clarify usage 2022-07-14 17:13:13 +01:00
Stefan Rueger 901d49c4e6 Change terminal write usage message to accommodate long double 2022-07-13 12:37:10 +01:00
Stefan Rueger b02cce38d7 Added long double data type for terminal write 2022-07-13 12:25:09 +01:00
Stefan Rueger 0b3a5781fc Flush stderr and stdout with all terminal error messages
Error messages are written to stderr whilst normal terminal output is stdout.
When redirecting output to pipelines or files these two streams can get
separated as they are buffered separately. To avoid this, term.c now provides
a function terminal_message() that works just like avrdude_message() but
flushes stderr and stdout before printing on stderr, and it flushes stderr
afterwards.

This commit replaces all avrdude_message() calls except for progress report
with terminal_message() to ensure stdout and stderr streams keep together.
2022-07-13 11:48:29 +01:00
Stefan Rueger 1efbc64922 Add terminal_setup_update_progress() library interface to term.c
This enables the new quell terminal command to switch on and off progress
reports to the terminal. The code for this was moved from main.c to term.c.

It can be used as library call for other frontends than main.c
2022-07-13 11:38:43 +01:00
Stefan Rueger ea226936b7 Fix isspace() and other isxxx() calls in term.c 2022-07-13 11:19:21 +01:00
Stefan Rueger f8145ae1c4 Echo >>> terminal command line for Windows or non-libreadline 2022-07-12 21:53:37 +01:00
Stefan Rueger b6204b181a Provide echo of terminal command line prompt under Windows 2022-07-12 15:22:52 +01:00
Stefan Rueger 1e8b56751e Add quell command in terminal
Sets the quell_progress global variable that can be, and is, consulted by
programmers.

Setting quell_progress to a positive number also switches off progress
bars. It is currently not possible to switch on progress bars again: that
is enabled in main.c once at the start of AVRDUDE.

That code in main should move to avr.c to enable report_update() to consult
quell_progress directly. Will do at another time when touching main.c and
avr.c. smr
2022-07-12 13:19:09 +01:00
Stefan Rueger d9cb9772d7 Fix verbosity level parsing in term.c 2022-07-12 12:30:29 +01:00
Stefan Rueger 63fb79accb Consolidate more error messages in term.c 2022-07-12 12:24:30 +01:00
Stefan Rueger f871a4dc1e Adapt capitalisation of comments in term.c to existing style 2022-07-12 12:02:43 +01:00
Stefan Rueger 7c766ef9bd Refine type detection in terminal write
The code no longer accepts valid mantissa-only doubles that are integer
rejects, eg, 078 or ULL overflows. These are most likely input errors by
the user: 8 is not an octal digit, they might have typed 17 hex digits,
not 16. It's just too hard to explain that 0xffffFFFFffffFFFFf writes
0x4430000000000000, which is the correct double representation of the
valid 17-digit hex mantissa that strtod() is perfectly happy to accept.
2022-07-12 12:01:14 +01:00
Stefan Rueger 704d253636 Remove comparisons between signed and unsigned integers in term.c 2022-07-12 11:59:42 +01:00
Stefan Rueger 8140c9c90b Consolidate error messages in term.c 2022-07-12 11:58:51 +01:00
Stefan Rueger 56113f6d8a Remove echo of tokenised terminal command 2022-07-12 11:51:04 +01:00
Stefan Rueger c5f522342d Improve terminal help message 2022-07-12 11:50:23 +01:00
Stefan Rueger 92425af0cc Improve terminal dump usage message 2022-07-12 11:47:33 +01:00
Stefan Rueger 602e9bb80c Change size for memory type variable in terminal read 2022-07-12 11:44:20 +01:00
Stefan Rueger 7205bbae80 Enhance terminal read with new mode: read <memory> <addr> 2022-07-12 11:43:45 +01:00
Stefan Rueger aa09bcf900 Ensure terminal writes little endian numbers 2022-07-12 11:42:59 +01:00
Stefan Rueger ddffabe86a Improve terminal write usage message 2022-07-12 11:40:40 +01:00
Stefan Rueger 0b2f38c67d Allow optional comma separators for data items in terminal write 2022-07-12 11:39:52 +01:00
Stefan Rueger 5c4cfa642a Parse terminal writes of string and character constants in C-style 2022-07-12 11:39:02 +01:00
Stefan Rueger 9fe6820236 Add double type for terminal write in anticipation of future avr-libc extension 2022-07-12 11:36:57 +01:00
Stefan Rueger feda75b60a Remove unnecessary bool is_float in terminal write 2022-07-12 11:35:27 +01:00
Stefan Rueger 51355d04fb Remodel logic of the size that integer items occupy in terminal write
Integers can be hexadecimal, decimal or octal. An optional case-insensitive
suffix specifies their size: HH: 8 bit, H/S: 16 bit, L: 32 bit, LL: 64 bit

An optional U suffix makes a number unsigned. Ordinary 0x hex numbers are
always treated as unsigned. +0x or -0x hex numbers are treated as signed
unless they have a U suffix. Unsigned integers cannot be larger than 2^64-1.

If n is an unsigned integer then -n is also a valid unsigned integer as in C.

Signed integers must fall into the [-2^63, 2^63-1] range or a correspondingly
smaller range when a suffix specifies a smaller type. Out of range signed
numbers trigger a warning.

Ordinary 0x hex numbers with n hex digits (counting leading zeros) use
the smallest size of 1, 2, 4 and 8 bytes that can accommodate any n-digit hex
number. If a suffix specifies a size explicitly the corresponding number of
least significant bytes are written. Otherwise, signed and unsigned integers
alike occupy the smallest of 1, 2, 4, or 8 bytes needed to accommodate them
in their respective representation.
2022-07-12 11:32:38 +01:00
Stefan Rueger 62d3eebd56 Fix 64-bit integer terminal write where high bit set
Using strtoll() can only return numbers in the range [-2^63, 2^63-1]. This
means that 0xffffFFFFffffFFFF (2^64-1) will be out of range and is written as
max LL. Actually, every 64-bit number with high-bit set will wrongly be
written as max LL.

This commit uses strtoull() instead to fix this, and checks for unsiged out-
of-range error. strtoull() also has the neat benefit that input with a minus
sign is treated like C unsigned numbers, ie, -u is also a valid unsigned
number if only u is one. In case the input is meant to be treated as signed,
it is therefore still OK to use strtoull() in the first instance only that in
this case a second check against the range of the signed domain is necessary.
2022-07-12 11:19:47 +01:00
Stefan Rueger 9afa56381e Remove unused component is_signed in terminal write 2022-07-12 11:19:05 +01:00
Stefan Rueger ff43e0544d Correct a parse message in terminal write 2022-07-12 11:18:15 +01:00
Stefan Rueger 177834ae7c Ensure enough memory is allocated for buf in terminal write 2022-07-12 11:16:16 +01:00
Stefan Rueger d3ad078577 Ensure terminal write fill mode ... always fills with last data item 2022-07-12 11:15:30 +01:00
Stefan Rueger 39a00bc71e Ensure +0x...f does not strip suffix f in terminal write 2022-07-12 11:14:41 +01:00
Stefan Rueger 360d7c502b Make suffix fully case insensitive (allow Hh, Ll, ...) in terminal write 2022-07-12 11:13:46 +01:00
Stefan Rueger d9450058c8 Cache strlen(argv[i]) in term.c cmd_write() and prevent negative array index 2022-07-12 11:12:20 +01:00
MCUdude 1363c7fe76 Fix buffer overflow issue
when in terminal fill mode
2022-04-09 20:08:44 +02:00
MCUdude 17b67da03e Make sure memory can be filled with a string
... and not just the last character
2022-04-04 09:38:02 +02:00
MCUdude 795dd91575 Code cleanup + formatting 2022-04-01 22:23:55 +02:00