Skip to content

Commit

Permalink
Merge branch 'avrdudes:main' into issue1271
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuee authored Nov 14, 2023
2 parents af303dd + c82fec9 commit 3520157
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 69 deletions.
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Changes since version 7.2:
- Harmonise WIN32 and POSIX serial comms timeout #1249
- Old avrdude.conf can result in a segmentation fault #1544
- Support AVR EB series #1546
- Programmer in .avrduderc not recognised #1551
- JTAG signature write ineffective #1527
- Control forced loading of ~/.avrduderc #1548
- Warn if avrdude and avrdude.conf versions don't match #1562

* Pull requests:

Expand Down Expand Up @@ -73,9 +77,17 @@ Changes since version 7.2:
- Introduce memory types in lieu of memory name comparisons #1538
- Allow UPDI_SIB of AVR_EB in serialupdi #1549
- Harmonise WIN32 and POSIX serial comms timeout #1550
- Test programmers for prog_modes and type #1557
- Remove paged eeprom property from ATtiny43U #1556
- Review write_byte() functions #1554
- Provide option -N for do not load personal config file #1555
- Print warning when avrdude and avrdude.conf versions doesn't match #1564
- Always warn if part and programmer are incompatible #1563

* Internals:

- Introduce memory types in lieu of memory name comparisons #1538
This will enable to decouple memory names from function

Changes in version 7.2:

Expand Down
18 changes: 18 additions & 0 deletions src/avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
goto error;
}

if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
}

data = avr_bitmask_data(pgm, p, mem, addr, data);

if (p->prog_modes & PM_TPI) {
Expand Down Expand Up @@ -892,6 +901,15 @@ int avr_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem,
unsigned long addr, unsigned char data)
{

if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
}

if(pgm->write_byte != avr_write_byte_default)
if(!(p->prog_modes & (PM_UPDI | PM_aWire))) // Initialise unused bits in classic & XMEGA parts
data = avr_bitmask_data(pgm, p, mem, addr, data);
Expand Down
6 changes: 6 additions & 0 deletions src/avrdude.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
.Op Fl B Ar bitclock
.Op Fl c Ar programmer-id
.Op Fl C Ar config-file
.Op Fl N
.Op Fl A
.Op Fl D
.Op Fl e
Expand All @@ -45,6 +46,7 @@
.Op Fl n
.Op Fl O
.Op Fl P Ar port
.Op Fl r
.Op Fl q
.Op Fl T Ar cmd
.Op Fl t
Expand Down Expand Up @@ -444,6 +446,10 @@ files. This can be used to add entries to the configuration
without patching your system wide configuration file. It can be used
several times, the files are read in same order as given on the command
line.
.It Fl N
Do not load the personal configuration file that is usually located at
~/.config/avrdude/avrdude.rc, ~/.avrduderc or in the same directory as the
avrdude executable
.It Fl A
Disable the automatic removal of trailing-0xFF sequences in file
input that is to be programmed to flash and in AVR reads from
Expand Down
3 changes: 1 addition & 2 deletions src/avrdude.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ avrdude_conf_version = "@AVRDUDE_FULL_VERSION@";
# autobaud_sync = <num> ; # autobaud detection byte, default 0x30
#
# memory <memstr>
# paged = <yes/no> ; # yes/no (flash only, do not use for EEPROM)
# paged = <yes/no> ; # yes/no (flash of classic parts only)
# offset = <num> ; # memory offset
# size = <num> ; # bytes
# page_size = <num> ; # bytes
Expand Down Expand Up @@ -14223,7 +14223,6 @@ part # t43u
pgm_enable = "1010.1100--0101.0011--xxxx.xxxx--xxxx.xxxx";

memory "eeprom"
paged = yes;
size = 64;
page_size = 4;
num_pages = 16;
Expand Down
7 changes: 7 additions & 0 deletions src/avrftdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,13 @@ static int avrftdi_jtag_write_byte(const PROGRAMMER *pgm, const AVRPART *p,
while (!(avrftdi_jtag_dr_inout(pgm, 0x3300, 15) & 0x0200))
;

} else if(mem_is_readonly(m)) {
unsigned char is;
if(pgm->read_byte(pgm, p, m, addr, &is) >= 0 && is == value)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", m->desc, p->desc);
return -1;
} else {
return -1;
}
Expand Down
7 changes: 7 additions & 0 deletions src/butterfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ static int butterfly_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const A
cmd[0] = 'l';
cmd[1] = value;
size = 2;
} else if(mem_is_readonly(m)) {
unsigned char is;
if(pgm->read_byte(pgm, p, m, addr, &is) >= 0 && is == value)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", m->desc, p->desc);
return -1;
}
else
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/developer_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ void dev_output_part_defs(char *partdesc) {
for(LNODEID lnm=lfirst(p->mem); lnm; lnm=lnext(lnm)) {
AVRMEM *m = ldata(lnm);
// Write delays not needed for read-only calibration and signature memories
if(!mem_is_calibration(m) && !mem_is_signature(m)) {
if(!mem_is_readonly(m)) {
if(p->prog_modes & PM_ISP) {
if(m->min_write_delay == m->max_write_delay)
dev_info(".wd_%s %.3f ms %s\n", m->desc, m->min_write_delay/1000.0, p->desc);
Expand Down
25 changes: 15 additions & 10 deletions src/doc/avrdude.texi
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,6 @@ ATmega328P MCU properties; for more information run @code{avrdude -p x/h}.
Override the RS-232 connection baud rate specified in the respective
programmer's entry of the configuration file.

@item -r
Opens the serial port at 1200 baud and immediately closes it, waits 400 ms
for each @code{-r} on the command line and then establishes communication
with the programmer. This is commonly known as a "1200bps touch", and is
used to trigger programming mode for certain boards like Arduino Leonardo,
Arduino Micro/Pro Micro and the Arduino Nano Every. Longer waits, and
therefore multiple @code{-r} options, are sometimes needed for slower, less
powerful hosts.

@item -B @var{bitclock}
Specify the bit clock period for the JTAG, PDI, TPI, UPDI, or ISP
interface. The value is a floating-point number in microseconds.
Expand Down Expand Up @@ -561,6 +552,11 @@ without patching your system wide configuration file. It can be used
several times, the files are read in same order as given on the command
line.

@item -N
Do not load the personal configuration file that is usually located at
@code{~/.config/avrdude/avrdude.rc}, @code{~/.avrduderc} or in the same
directory as the avrdude executable.

@item -A
Disable the automatic removal of trailing-0xFF sequences in file
input that is to be programmed to flash and in AVR reads from
Expand Down Expand Up @@ -779,6 +775,15 @@ for a STK500.
Note: The ability to handle IPv6 hostnames and addresses is limited to
Posix systems (by now).

@item -r
Opens the serial port at 1200 baud and immediately closes it, waits 400 ms
for each @code{-r} on the command line and then establishes communication
with the programmer. This is commonly known as a "1200bps touch", and is
used to trigger programming mode for certain boards like Arduino Leonardo,
Arduino Micro/Pro Micro and the Arduino Nano Every. Longer waits, and
therefore multiple @code{-r} options, are sometimes needed for slower, less
powerful hosts.

@item -q
Disable (or quell) output of the progress bar while reading or writing
to the device. Specify it a second time for even quieter operation.
Expand Down Expand Up @@ -3120,7 +3125,7 @@ part
autobaud_sync = <num> ; # autobaud detection byte, default 0x30
memory <memstr>
paged = <yes/no> ; # yes/no (flash only, do not use for EEPROM)
paged = <yes/no> ; # yes/no (flash of classic parts only)
offset = <num> ; # memory offset
size = <num> ; # bytes
page_size = <num> ; # bytes
Expand Down
9 changes: 9 additions & 0 deletions src/flip1.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ int flip1_write_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
{
enum flip1_mem_unit mem_unit;

if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, part, mem, addr, &is) >= 0 && is == value)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, part->desc);
return -1;
}

if (FLIP1(pgm)->dfu == NULL)
return -1;

Expand Down
9 changes: 9 additions & 0 deletions src/flip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ int flip2_write_byte(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *m
{
enum flip2_mem_unit mem_unit;

if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, part, mem, addr, &is) >= 0 && is == value)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, part->desc);
return -1;
}

if (FLIP2(pgm)->dfu == NULL)
return -1;

Expand Down
17 changes: 12 additions & 5 deletions src/jtag3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ static int jtag3_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
if (unsupp && pgm->flag & PGM_FL_IS_DW)
pmsg_error("debugWire interface does not support writing to memory %s\n", mem->desc);
else
pmsg_error("cannot write to read-only memory %s %s\n", p->desc, mem->desc);
pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
}

Expand All @@ -2355,10 +2355,8 @@ static int jtag3_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
memcpy(mem->buf + addr, cache_ptr, pagesize);
/* step #3: write back */
i = jtag3_paged_write(pgm, p, mem, pagesize, addr, pagesize);
if (i < 0)
return -1;
else
return 0;

return i < 0? -1: 0;
}

/* non-paged writes go here */
Expand Down Expand Up @@ -2978,6 +2976,15 @@ static int jtag3_write_byte_tpi(const PROGRAMMER *pgm, const AVRPART *p, const A
int status;
unsigned long paddr = 0UL;

if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
}

status = jtag3_erase_tpi(pgm, p, mem, addr);
if (status < 0) {
pmsg_error("error in communication, received status 0x%02x\n", status);
Expand Down
14 changes: 8 additions & 6 deletions src/jtagmkI.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
unsigned char resp[1], writedata;
int len, need_progmode = 1, need_dummy_read = 0;

pmsg_notice2("jtagmkI_write_byte(.., %s, 0x%lx, ...)\n", mem->desc, addr);
pmsg_notice2("jtagmkI_write_byte(.., %s, 0x%lx, 0x%02x)\n", mem->desc, addr, data);

writedata = data;
cmd[0] = CMD_WRITE_MEM;
Expand All @@ -989,11 +989,13 @@ static int jtagmkI_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
} else if (mem_is_lock(mem)) {
cmd[1] = MTYPE_LOCK_BITS;
need_dummy_read = 1;
} else if (mem_is_calibration(mem)) {
cmd[1] = MTYPE_OSCCAL_BYTE;
need_dummy_read = 1;
} else if (mem_is_signature(mem)) {
cmd[1] = MTYPE_SIGN_JTAG;
} else if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
} else {
pmsg_error("unknown memory %s\n", mem->desc);
return -1;
Expand Down
21 changes: 10 additions & 11 deletions src/jtagmkII.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,30 +2342,29 @@ static int jtagmkII_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AV
unsupp = 1;
} else if (mem_is_userrow(mem)) {
cmd[1] = MTYPE_USERSIG;
} else if (mem_is_sigrow(mem)) {
cmd[1] = MTYPE_PRODSIG;
} else if (mem_is_lock(mem)) {
cmd[1] = MTYPE_LOCK_BITS;
if (pgm->flag & PGM_FL_IS_DW)
unsupp = 1;
} else if (mem_is_calibration(mem)) {
cmd[1] = MTYPE_OSCCAL_BYTE;
if (pgm->flag & PGM_FL_IS_DW)
unsupp = 1;
} else if (mem_is_io(mem)) {
cmd[1] = MTYPE_FLASH; // Works with jtag2updi, does not work with any xmega
addr += avr_data_offset(p);
} else if (mem_is_signature(mem)) {
cmd[1] = MTYPE_SIGN_JTAG;
if (pgm->flag & PGM_FL_IS_DW)
unsupp = 1;
} else if(mem_is_readonly(mem)) {
unsigned char is;
if(pgm->read_byte(pgm, p, mem, addr, &is) >= 0 && is == data)
return 0;

pmsg_error("cannot write to read-only memory %s of %s\n", mem->desc, p->desc);
return -1;
} else {
pmsg_error("unknown memory %s\n", mem->desc);
return -1;
}

if (unsupp)
if (unsupp) {
pmsg_error("unsupported memory %s in debugWIRE mode\n", mem->desc);
return -1;
}

if (need_progmode) {
if (jtagmkII_program_enable(pgm) < 0)
Expand Down
3 changes: 3 additions & 0 deletions src/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ int led_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
int led_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m,
unsigned long addr, unsigned char value) {

if(mem_is_readonly(m))
return pgm->write_byte(pgm, p, m, addr, value);

led_clr(pgm, LED_ERR);
led_set(pgm, LED_PGM);

Expand Down
Loading

0 comments on commit 3520157

Please sign in to comment.