Skip to content

Commit

Permalink
Merge branch 'main' into swig_libavrdude
Browse files Browse the repository at this point in the history
  • Loading branch information
dl8dtl committed Aug 12, 2024
2 parents 3a9857f + 11f419f commit 7b7b3d8
Show file tree
Hide file tree
Showing 38 changed files with 1,290 additions and 668 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
build-essential
automake
libtool
gettext
flex
bison
libelf-dev
Expand Down
14 changes: 14 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Changes since version 7.3:
- JTAGICE3 EDBG communication mode relies on hardcoded USBVID #1838
- avrdude documentation typo(s) attemps #1852
- Conflicting types for op16_is_mnemo: enum/integer #1851
- Writing BOOTROW for Curiosity Nano #1868
- Should AVRDUDE be run as root? #1860
- Auto-build avrdude.pdf from texinfo sources #1847

* Pull requests:

Expand Down Expand Up @@ -129,6 +132,17 @@ Changes since version 7.3:
- Refine auto-erase strategy #1862
- Provide -P usb:vid:pid for USB hid i/f and allow
long -P usb:serno for usblib and hidapi #186
- Initialise dryrun flash with realistic random code #1873
- Writing BOOTROW for Curiosity Nano #1870
- Refine programmer/part/memory compatibility modelling #1869
- Provide dev option -c \*/u that shows udev rules #1867
- Provide current avrdude.pdf documentation in repo root #1865
- doc: Stop building and installing .ps and .dvi #1857
- Improve autotools build (part 2/n) #1695
- Use correct file locations in the documentation #1637
- Deprecate obsolete features and options #1875
- Add more hard-coded usbvid/pid to udev rules #1876
- Fixes for jtag3 programmers and prep for jtagmkII #1877

* Internals:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The latest version of AVRDUDE is always available here:\

## Documentation

Documentation for current and previous releases is [on Github Pages](https://avrdudes.github.io/avrdude/).
Documentation for current and previous releases is [on Github Pages](https://avrdudes.github.io/avrdude/). Git main is documented only with the most recent [avrdude.pdf](https://github.com/avrdudes/avrdude/blob/main/avrdude.pdf).

## Getting AVRDUDE for Windows

Expand Down
Binary file added avrdude.pdf
Binary file not shown.
41 changes: 21 additions & 20 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ EXTRA_DIST = \
avrdude.spec \
bootstrap

CLEANFILES = \
config_gram.c \
config_gram.h \
lexer.c
BUILT_SOURCES =
CLEANFILES =

include build-helpers/versioninfo.mk
built_sources =
built_sources += config_gram.c
built_sources += config_gram.h
built_sources += lexer.c

BUILT_SOURCES += $(built_sources)
CLEANFILES += $(built_sources)

BUILT_SOURCES = $(CLEANFILES)
include build-helpers/versioninfo.mk

#SUBDIRS = doc
#DIST_SUBDIRS = doc
Expand All @@ -53,19 +57,16 @@ AM_YFLAGS = -d

avrdude_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\"

libavrdude_a_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\"
libavrdude_la_CPPFLAGS = $(libavrdude_a_CPPFLAGS)
libavrdude_la_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\"

avrdude_CFLAGS = @ENABLE_WARNINGS@

libavrdude_a_CFLAGS = @ENABLE_WARNINGS@ $(LIBGPIOD_CFLAGS)
libavrdude_la_CFLAGS = $(libavrdude_a_CFLAGS)
libavrdude_la_CFLAGS = @ENABLE_WARNINGS@ $(LIBGPIOD_CFLAGS)

avrdude_LDADD = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB_1_0@ @LIBHIDAPI@ @LIBUSB@ @LIBFTDI1@ @LIBFTDI@ @LIBHID@ @LIBELF@ @LIBPTHREAD@ @LIBSERIALPORT@ $(LIBGPIOD_LIBS) -lm
avrdude_LDADD = libavrdude.la @LIBUSB_1_0@ @LIBHIDAPI@ @LIBUSB@ @LIBFTDI1@ @LIBFTDI@ @LIBHID@ @LIBELF@ @LIBPTHREAD@ @LIBSERIALPORT@ $(LIBGPIOD_LIBS) -lm

bin_PROGRAMS = avrdude

noinst_LIBRARIES = libavrdude.a
lib_LTLIBRARIES = libavrdude.la

# automake thinks these generated files should be in the distribution,
Expand All @@ -77,13 +78,14 @@ lib_LTLIBRARIES = libavrdude.la
# https://savannah.nongnu.org/bugs/index.php?func=detailitem&item_id=15536
#
# for why we don't want to have them.
dist-hook:
rm -f \
$(distdir)/lexer.c \
$(distdir)/config_gram.c \
$(distdir)/config_gram.h
#
# We could avoid this dist-hook altogether if we could require
# Automake >= 1.16.4 and just use its no-dist-built-sources flag.
dist-hook: dist-hook-no-dist-built-sources-workaround
dist-hook-no-dist-built-sources-workaround:
cd "$(distdir)" && rm -f $(built_sources)

libavrdude_a_SOURCES = \
libavrdude_la_SOURCES = \
config_gram.y \
lexer.l \
arduino.h \
Expand Down Expand Up @@ -218,8 +220,7 @@ libavrdude_a_SOURCES = \
wiring.c \
xbee.h \
xbee.c
libavrdude_la_SOURCES = $(libavrdude_a_SOURCES)
libavrdude_la_LDFLAGS = -version-info 2:0
libavrdude_la_LDFLAGS = -version-info @LIBAVRDUDE_VERSION_INFO@

include_HEADERS = libavrdude.h
include_HEADERS += libavrdude-avrintel.h
Expand Down
44 changes: 27 additions & 17 deletions src/avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,6 @@ int avr_mem_hiaddr(const AVRMEM * mem)
{
int i, n;

// Deprecated: calling with NULL disables trailing 0xff optimisation (remove in v8.0)
if(!mem) {
cx->avr_disableffopt = 1;
return 0;
}

if(cx->avr_disableffopt)
return mem->size;

Expand Down Expand Up @@ -428,7 +422,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con

// HW programmers need a page size > 1, bootloader typ only offer paged r/w
if ((pgm->paged_load && mem->page_size > 1 && mem->size % mem->page_size == 0) ||
((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, mem))) {
((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, p, mem))) {
/*
* the programmer supports a paged mode read
*/
Expand Down Expand Up @@ -504,7 +498,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
if (rc != LIBAVRDUDE_SUCCESS) {
pmsg_error("unable to read byte at address 0x%04lx\n", i);
if (rc == LIBAVRDUDE_GENERAL_FAILURE) {
pmsg_error("read operation not supported for memory %s\n", mem->desc);
// pmsg_error("read operation not supported for memory %s\n", mem->desc);
report_progress(1, -1, NULL);
led_set(pgm, LED_ERR);
led_clr(pgm, LED_PGM);
Expand Down Expand Up @@ -873,8 +867,8 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
rc = pgm->initialize(pgm, p);
if (rc < 0) {
pmsg_error("initialization failed (rc = %d):\n", rc);
imsg_error("cannot re-initialize device after programming the %s bits; you\n", mem->desc);
imsg_error("must manually power-down the device and restart %s to continue\n", progname);
imsg_error("cannot re-initialize device after programming the %s bits;\n", mem->desc);
imsg_error("manually power-down the device and restart %s to continue\n", progname);
rc = -3;
goto rcerror;
}
Expand Down Expand Up @@ -1054,7 +1048,7 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int

// HW programmers need a page size > 1, bootloader typ only offer paged r/w
if ((pgm->paged_load && m->page_size > 1 && m->size % m->page_size == 0) ||
((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, m))) {
((pgm->prog_modes & PM_SPM) && avr_has_paged_access(pgm, p, m))) {
/*
* the programmer supports a paged mode write
*/
Expand Down Expand Up @@ -1384,14 +1378,14 @@ int avr_verify_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRPART *v, co
// Mismatch is only in unused bits
if ((buf1[i] | bitmask) != 0xff) {
// Programmer returned unused bits as 0, must be the part/programmer
pmsg_warning("ignoring mismatch in unused bits of %s\n", a->desc);
imsg_warning("(device 0x%02x != input 0x%02x); to prevent this warning fix\n", buf1[i], buf2[i]);
imsg_warning("the part or programmer definition in the config file\n");
pmsg_debug("ignoring mismatch in unused bits of %s\n", a->desc);
imsg_debug("(device 0x%02x != input 0x%02x); to prevent this warning fix\n", buf1[i], buf2[i]);
imsg_debug("the part or programmer definition in the config file\n");
} else {
// Programmer returned unused bits as 1, must be the user
pmsg_warning("ignoring mismatch in unused bits of %s\n", a->desc);
imsg_warning("(device 0x%02x != input 0x%02x); to prevent this warning set\n", buf1[i], buf2[i]);
imsg_warning("unused bits to 1 when writing (double check with datasheet)\n");
pmsg_debug("ignoring mismatch in unused bits of %s\n", a->desc);
imsg_debug("(device 0x%02x != input 0x%02x); to prevent this warning set\n", buf1[i], buf2[i]);
imsg_debug("unused bits to 1 when writing (double check with datasheet)\n");
}
}
}
Expand Down Expand Up @@ -1599,6 +1593,22 @@ Memtable avr_mem_order[100] = {
{"sib", MEM_SIB | MEM_READONLY},
};

#include "dryrun.h"
#include "jtag3.h"
#include "jtagmkII.h"
#define is_type(pgm, what) ((pgm)->initpgm == what ## _initpgm)

// Whether a memory is an exception that shouldn't be there for this particular i/face
int avr_mem_exclude(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem) {
return
is_type(pgm, dryrun)? 0: // Never exclude dryrun memories
(mem_is_sib(mem) && is_type(pgm, jtagmkII_updi)) || // jtag2updi cannot deal with sib
// jtag3 cannot read beyond addr 6 on classic prodsig, so exclude memories in prodsig/sigrow
(is_type(pgm, jtag3) && mem_is_in_sigrow(mem) && is_classic(p) && both_jtag(pgm, p)) ||
// Classic part usersig memories cannot be read/written using ISP
(mem_is_usersig(mem) && is_classic(p) && both_isp(pgm, p));
}

int avr_get_mem_type(const char *str) {
for(size_t i=0; i < sizeof avr_mem_order/sizeof *avr_mem_order; i++) {
if(avr_mem_order[i].str && str_eq(avr_mem_order[i].str, str))
Expand Down
43 changes: 43 additions & 0 deletions src/avr_opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ AVR_mnemo opcode_mnemo(int op, int avrlevel) {
return MNEMO_NONE;
}

// Is 16-bit opcode valid for AVR part with avrlevel architecture?
int op16_is_valid(int op16, int avrlevel) {
int mnemo = opcode_mnemo(op16, avrlevel);
return mnemo >= 0 && mnemo <= MNEMO_N;
}

// Is 16-bit opcode valid and benign for AVR part with avrlevel architecture?
int op16_is_benign(int op16, int avrlevel) { // Benign means no I/O or SRAM is being read/written
int mnemo = opcode_mnemo(op16, avrlevel);
return mnemo >= 0 && mnemo <= MNEMO_N && !(avr_opcodes[mnemo].type & OTY_EXTERNAL);
}

// Opcodes in avr_opcodes[] that a part ought to be able to run
int avr_get_archlevel(const AVRPART *p) {
int ret =
Expand Down Expand Up @@ -737,3 +749,34 @@ int z_width(int op16, AVR_mnemo *mnemop) {

return 0;
}

// Where else could the PC of the 16-bit opcode op16 at address here move to other than here + 2?
int op16_target(int here, int op16) {
AVR_mnemo mnemo = opcode_mnemo(op16, PART_ALL | OP_AVR_ILL);

if(mnemo >= 0 && mnemo < MNEMO_N) {
switch(avr_opcodes[mnemo].type & OTY_TYPE_MASK) {
case OTY_RJMX: // Relative call rcall, range [.-4096, .+4094] bytes
case OTY_RJMI: // Relative jump rjmp, range [.-4096, .+4094] bytes
return here + 2 + ((int16_t) (op16<<4) >> 3);

case OTY_JMPI: // Jump to potentially anywhere in flash (jmp, ijmp, eijmp)
case OTY_JMPX: // Jump to potentially anywhere in flash (calls and ret/i)
return INT_MIN;

case OTY_BRAI: // Conditional branch, range [.-128, .+126] bytes
return here + 2 + (int8_t) ((op16 & 0x3f8)>>2);

case OTY_SKPI: // Conditional skip, range [.+0, .+4] (cpse, sbrc, sbrs)
case OTY_SKPX: // Conditional skip, range [.+0, .+4] (sbic, sbis)
return here + 2 + 4;
}
}

return here + 2;
}

// Rjmp opcode from byte distance; 0xcfff is an endless loop, 0xc000 is a nop
int dist2rjmp(int dist) {
return 0xc000 | (((dist >> 1) - 1) & 0x0fff);
}
Loading

0 comments on commit 7b7b3d8

Please sign in to comment.