Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use page erase for UPDI programming #1837

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 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
56 changes: 34 additions & 22 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
19 changes: 13 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,18 +1681,25 @@ int main(int argc, char * argv [])
}

if (uflags & UF_AUTO_ERASE) {
if ((p->prog_modes & PM_PDI) && pgm->page_erase && lsize(updates) > 0) {
pmsg_info("Note: programmer supports page erase for Xmega devices.\n");
imsg_info("Each page will be erased before programming it, but no chip erase is performed.\n");
imsg_info("To disable page erases, specify the -D option; for a chip-erase, use the -e option.\n");
if((p->prog_modes & (PM_PDI | PM_UPDI)) && pgm->page_erase && lsize(updates) > 0) {
for(ln=lfirst(updates); ln; ln=lnext(ln)) {
upd = ldata(ln);
if(upd->memstr && upd->op == DEVICE_WRITE && memlist_contains_flash(upd->memstr, p)) {
cx->avr_disableffopt = 1; // Must write full flash file including trailing 0xff
pmsg_info("NOT erasing chip as page erase will be used for new flash%s contents\n",
avr_locate_bootrow(p)? "/bootrow": "");
imsg_notice("unprogrammed flash contents remains: use -e for an explicit chip-erase\n");
break;
}
}
} else {
uflags &= ~UF_AUTO_ERASE;
for(ln=lfirst(updates); !erase && ln; ln=lnext(ln)) {
upd = ldata(ln);
if(upd->memstr && upd->op == DEVICE_WRITE && memlist_contains_flash(upd->memstr, p)) {
erase = 1;
pmsg_info("Note: carrying out an erase cycle as flash memory needs programming (-U %s:w:...)\n", upd->memstr);
imsg_info("specify the -D option to disable this feature\n");
pmsg_info("Performing a chip erase as flash memory needs programming (-U %s:w:...)\n", upd->memstr);
imsg_notice("specify the -D option to disable this feature\n");
}
}
}
Expand Down
Loading