Skip to content

Commit

Permalink
Merge branch 'main' into issue_1832
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuchwald committed Jul 7, 2024
2 parents 640bf85 + d10986f commit 69a5545
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 74 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Changes since version 7.3:
- ATtiny11 does not have EEPROM #1812
- AVRDUDE fails to return -1 on some write errors #1821
- Multi-memory files #1817
- Terminal erase command #1833

* Pull requests:

Expand Down Expand Up @@ -100,6 +101,8 @@ Changes since version 7.3:
- Downgrade out-of-range file input errors on -F #1818
- Multi-memory file handling #1828
- Add developer options -p*/vcr to explore SW compatibility #1830
- Improve chip erase emulation for dryboot/dryrun #1836
- Use page erase for UPDI programming #1837

* Internals:

Expand Down
21 changes: 11 additions & 10 deletions src/avrcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
* flash (and sometimes EEPROM, too) looks like a NOR memory, ie, a write can
* only clear bits, never set them. For NOR memories a page erase or, if not
* available, a chip erase needs to be issued before writing arbitrary data.
* Bootrow and usersig are generally unaffected by a chip erase, so will need
* a page erase. When a memory looks like a NOR memory, either page erase is
* Usersig is generally unaffected by a chip erase, so will always need a
* page erase. When a memory looks like a NOR memory, 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
Expand All @@ -90,7 +90,7 @@
* 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. avr_chip_erase_cached() does not
* affect the bootrow or usersig cache.
* affect the usersig cache.
*
* The avr_page_erase_cached() function erases a page and synchronises it
* with the cache.
Expand Down Expand Up @@ -689,10 +689,11 @@ int avr_write_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM

// Erase the chip and set the cache accordingly
int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p) {
Cache_desc mems[3] = {
Cache_desc mems[] = {
{ avr_locate_flash(p), pgm->cp_flash, 1, 0, -1, 0 },
{ avr_locate_eeprom(p), pgm->cp_eeprom, 0, 1, -1, 0 },
// bootrow/usersig is unaffected by CE
{ avr_locate_bootrow(p), pgm->cp_bootrow, 0, 0, -1, 0 },
// usersig is unaffected by CE
};
int rc;

Expand All @@ -718,19 +719,19 @@ int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p) {
memset(cp->cont, 0xff, cp->size);
memset(cp->iscached, 1, cp->size/cp->page_size);
}
} else if(mems[i].iseeprom) { // Test whether cached EEPROM pages were zapped
bool erasedee = 0;
} else { // Test whether cached EEPROM/bootrow pages were zapped
bool erased = 0;
for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) {
if(cp->iscached[pgno]) {
if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // Page has EEPROM data?
if(!is_memset(cp->copy + n, 0xff, cp->page_size)) { // Page has data?
if(avr_read_page_default(pgm, p, mem, n, cp->copy + n) < 0)
return LIBAVRDUDE_GENERAL_FAILURE;
erasedee = is_memset(cp->copy + n, 0xff, cp->page_size);
erased = is_memset(cp->copy + n, 0xff, cp->page_size);
break;
}
}
}
if(erasedee) { // EEPROM was erased, set cache correspondingly
if(erased) { // Memory was erased, set cache correspondingly
memset(cp->copy, 0xff, cp->size);
memset(cp->cont, 0xff, cp->size);
memset(cp->iscached, 1, cp->size/cp->page_size);
Expand Down
61 changes: 39 additions & 22 deletions src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,15 @@ arduino.
.It Fl D
Disable auto erase for flash. When the
.Fl U
option with flash memory is specified,
option for writing to any flash memory is specified,
.Nm
will perform a chip erase before starting any of the programming
operations, since it generally is a mistake to program the flash
without performing an erase first. This option disables that.
Auto erase is not used for ATxmega devices as these devices can
use page erase before writing each page so no explicit chip erase
is required.
Note however that any page not affected by the current operation
will retain its previous contents.
Setting
operations, since it generally is a mistake to program the flash without
performing an erase first. This option disables that. Auto erase is not
used for ATxmega parts nor for the UPDI (AVR8X family) parts as these can
use page erase before writing each page so no explicit chip erase is
required. Note, however, that any flash page not affected by the current
operation will retain its previous contents. Setting
.Fl D
implies
.Fl A.
Expand All @@ -491,9 +489,9 @@ Causes a chip erase to be executed. This will reset the contents of the
flash ROM and EEPROM to the value
.Ql 0xff ,
and clear all lock bits.
Except for ATxmega devices which can use page erase,
it is basically a prerequisite command before the flash ROM can be
reprogrammed again. The only exception would be if the new
Except for ATxmega and UPDI (AVR8X family) devices, all of which can use
page erase, it is basically a prerequisite command before the flash ROM
can be reprogrammed again. The only exception would be if the new
contents would exclusively cause bits to be programmed from the value
.Ql 1
to
Expand Down Expand Up @@ -797,6 +795,7 @@ The available memory types are device-dependent, the actual configuration
can be viewed with the
.Cm part
command in terminal mode.
.Pp
Typically, a device's memory configuration at least contains
the memories
.Ar flash ,
Expand All @@ -812,10 +811,26 @@ memory contains the three device signature bytes, which should
be, but not always are, unique for the part. The
.Ar lock
memory of one or four bytes typically details whether or not external
reading/writing of the flash memory, or parts of it, is allowed. Parts
will also typically have fuse bytes, which are read/write memories for
configuration of the device and calibration memories that typically
contain read-only factory calibration values.
reading/writing of the flash memory, or parts of it, is allowed. After
restricting access via the lock memory, often the only way to unlock
memory is via a chip erase. Parts will also typically have fuse bytes,
which are read/write memories for configuration of the device and
calibration memories that typically contain read-only factory calibration
values.
.Pp
The flash memory, being physically implemented as NOR-memory, is special
in the sense that it is normally only possible to program bits to change
from 1 to 0. Before reprogramming takes place normally flash memory has
to be erased. Older parts would only offer a chip erase to do so, which
also erases EEPROM unless a fuse configuration preserves its contents. If
AVRDUDE detects a -U option that writes to a flash memory it will
automatically trigger a chip erase for these older parts. ATxmegas or
UPDI parts (AVR8X family) offer a page erase, and AVRDUDE takes advantage
of that by erasing pages before programming them unless -e (chip erase) or
-D (do not erase before writing) was requested. It should be noted that in
absence of the -e chip erase option any ATxmega or UPDI flash pages not
affected by the programming will retain their previous content.

.Pp
Classic devices may have the following memories in addition to eeprom, flash, signature and lock:
.Bl -tag -width " calibration" -compact
Expand Down Expand Up @@ -937,10 +952,11 @@ Temperature sensor calibration values
.It bootrow
Extra page of memory that is only accessible by the MCU in bootloader
code; UDPI can read and write this memory only when the device is
unlocked; bootrow is not erased during chip erase
unlocked
.It userrow
Extra page of EEPROM memory that can be used for firmware settings; this
memory is not erased during a chip erase
memory is not erased during a chip erase; UPDI cannot read this memory
when the device is locked
.It sib
Special system information block memory with information about AVR family, chip revision etc.
.It io
Expand Down Expand Up @@ -1263,8 +1279,9 @@ command line argument.
.Ar verify
flushes the cache before verifying memories.
.It Ar erase
Perform a chip erase and discard all pending writes to EEPROM and flash.
Note that EEPROM will be preserved if the EESAVE fuse bit is set.
Perform a chip erase and discard all pending writes to flash, EEPROM and bootrow.
Note that EEPROM will be preserved if the EESAVE fuse bit is active, ie, had
a corresponding value at the last reset prior to the operation.
.It Ar erase memory
Erase the entire specified memory.
.It Ar erase memory addr len
Expand All @@ -1274,8 +1291,8 @@ Synchronise with the device all pending writes to flash, EEPROM, bootrow and
usersig. With some programmer and part combinations, flash (and sometimes
EEPROM, too) looks like a NOR memory, i.e., a write can only clear bits,
never set them. For NOR memories a page erase or, if not available, a chip
erase needs to be issued before writing arbitrary data. Bootrow and usersig are
generally unaffected by a chip erase. When a memory looks like a NOR
erase needs to be issued before writing arbitrary data. Usersig is
unaffected by a chip erase. When a memory looks like a NOR
memory, either page erase is deployed (e.g., with parts that have PDI/UPDI
interfaces), or if that is not available, both EEPROM and flash caches are
fully read in, a chip erase command is issued and both EEPROM and flash
Expand Down
67 changes: 40 additions & 27 deletions src/doc/avrdude.texi
Original file line number Diff line number Diff line change
Expand Up @@ -584,31 +584,28 @@ engaged by default when specifying -c arduino.

@item -D
@cindex Option @code{-D}
Disable auto erase for flash. When the -U option with flash memory is
specified, avrdude will perform a chip erase before starting any of the
programming operations, since it generally is a mistake to program the flash
without performing an erase first. This option disables that.
Auto erase is not used for ATxmega devices as these devices can
use page erase before writing each page so no explicit chip erase
is required.
Note however that any page not affected by the current operation
will retain its previous contents.
Setting -D implies -A.
Disable auto erase for flash. When the -U option for writing to any
flash memory is specified, AVRDUDE will perform a chip erase before
starting any of the programming operations, since it generally is a
mistake to program the flash without performing an erase first. This
option disables that. Auto erase is not used for ATxmega parts nor for the
UPDI (AVR8X family) parts as these can use page erase before writing each
page so no explicit chip erase is required. Note, however, that any flash
page not affected by the current operation will retain its previous
contents. Setting -D implies -A.

@item -e
@cindex Option @code{-e}
Causes a chip erase to be executed. This will reset the contents of the
flash and EEPROM to the value `0xff', and clear all lock bits.
Except for ATxmega devices which can use page erase,
it is basically a
prerequisite command before the flash can be reprogrammed again.
The only exception would be if the new contents would exclusively cause
bits to be programmed from the value `1' to `0'. Note that in order
to reprogram EERPOM cells, no explicit prior chip erase is required
since the MCU provides an auto-erase cycle in that case before
flash and EEPROM to the value `0xff', and clear all lock bits. Except for
ATxmega and UPDI (AVR8X family) devices, all of which can use page erase,
it is basically a prerequisite command before the flash ROM can be
reprogrammed again. The only exception would be if the new contents would
exclusively cause bits to be programmed from the value `1' to `0'. Note
that in order to reprogram EERPOM cells, no explicit prior chip erase is
required since the MCU provides an auto-erase cycle in that case before
programming the cell.


@item -E @var{exitspec}[,@dots{}]
@cindex Option @code{-E} @var{exitspec}[,@dots{}]
By default, AVRDUDE leaves the parallel port in the same state at exit
Expand Down Expand Up @@ -860,9 +857,24 @@ is sometimes known as @code{lockbits}. The signature memory contains the
three device signature bytes, which should be, but not always are, unique
for the part. The @code{lock} memory of one or four bytes typically
details whether or not external reading/writing of the flash memory, or
parts of it, is allowed. Parts will also typically have fuse bytes, which
are read/write memories for configuration of the device and calibration
memories that typically contain read-only factory calibration values.
parts of it, is allowed. After restricting access via the lock memory,
often the only way to unlock memory is via a chip erase. Parts will also
typically have fuse bytes, which are read/write memories for configuration
of the device and calibration memories that typically contain read-only
factory calibration values.

The flash memory, being physically implemented as NOR-memory, is special
in the sense that it is normally only possible to program bits to change
from 1 to 0. Before reprogramming takes place normally flash memory has to
be erased. Older parts would only offer a chip erase to do so, which also
erases EEPROM unless a fuse configuration preserves its contents. If
AVRDUDE detects a -U option that writes to a flash memory it will
automatically trigger a chip erase for these older parts. ATxmegas or
UPDI parts (AVR8X family) offer a page erase, and AVRDUDE takes advantage
of that by erasing pages before programming them unless -e (chip erase) or
-D (do not erase before writing) was requested. It should be noted that in
absence of the -e chip erase option any ATxmega or UPDI flash pages not
affected by the programming will retain their previous content.

Classic devices may have the following memories in addition to
@code{eeprom}, @code{flash}, @code{signature} and @code{lock}:
Expand Down Expand Up @@ -981,7 +993,7 @@ Temperature sensor calibration values
@item bootrow
Extra page of memory that is only accessible by the MCU in bootloader
code; UDPI can read and write this memory only when the device is
unlocked; bootrow is not erased during chip erase
unlocked
@item userrow
Extra page of EEPROM memory that can be used for firmware settings; this
memory is not erased during a chip erase
Expand Down Expand Up @@ -2509,8 +2521,9 @@ comma separated list of memories just as in the @code{-U} command line
argument. @code{verify} flushes the cache before verifying memories.

@item erase
Perform a chip erase and discard all pending writes to EEPROM and flash.
Note that EEPROM will be preserved if the EESAVE fuse bit is set.
Perform a chip erase and discard all pending writes to flash, EEPROM and bootrow.
Note that EEPROM will be preserved if the EESAVE fuse bit is active, ie, had
a corresponding value at the last reset prior to the operation.

@item erase @var{memory}
Erase the entire specified memory.
Expand All @@ -2523,8 +2536,8 @@ Synchronise with the device all pending writes to flash, EEPROM, bootrow and
usersig. With some programmer and part combinations, flash (and sometimes
EEPROM, too) looks like a NOR memory, i.e., a write can only clear bits,
never set them. For NOR memories a page erase or, if not available, a chip
erase needs to be issued before writing arbitrary data. Bootrow and usersig are
generally unaffected by a chip erase. When a memory looks like a NOR
erase needs to be issued before writing arbitrary data. Usersig is
unaffected by a chip erase. When a memory looks like a NOR
memory, either page erase is deployed (e.g., with parts that have PDI/UPDI
interfaces), or if that is not available, both EEPROM and flash caches are
fully read in, a chip erase command is issued and both EEPROM and flash
Expand Down
Loading

0 comments on commit 69a5545

Please sign in to comment.