From b99a145b9f9234bae0a1b36df264205db1db18b1 Mon Sep 17 00:00:00 2001 From: Tomasz 'CeDeROM' CEDRO Date: Sun, 10 Apr 2022 22:28:44 +0200 Subject: [PATCH 01/65] Added KT-LINK FT2232H interface with IO switching and voltage buffers. Example TPI run: https://github.com/avrdudes/avrdude/issues/928 Signed-off-by: Tomasz 'CeDeROM' CEDRO --- src/avrdude.conf.in | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 096751d0..231147ee 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -593,6 +593,38 @@ programmer reset = 3; # TMS 7 ; +# Kristech KT-LINK FT2232H interface with IO switching and voltage buffers. +# Created on 20220410 by CeDeROM Tomasz CEDRO (www.cederom.io). +# Interface DataSheet: https://kristech.pl/files/KT-LINK-UM-ENG.pdf +# AVRDUDE FT2232H PIN NUMBER DECODE: +# | 0 | 1 | .. | 7 | 8 | 9 | .. | 15 | +# | ADBUS0 | ADBUS1 | .. | ADBUS7 | ACBUS0 | ACBUS1 | .. | ACBUS7 | +# KT-LINK JTAG CONN: +# 1=Vsense(->EXT13), 19=5V(EXT1->EXT3), 20=GND, 3=TPIRST, 9=TPICLK, 7=TPIDATA. +# INTERNALS CONFIGURATION ("~" MEANS ACTIVE LOW): +# ~TRST_EN=10(ACBUS2), ~CLK_EN=14(ACBUS6), ~MOSI_EN=13(ACBUS5), +# TMS_SEL=5(ADBUS5), ~TMS_EN=12(ACBUS4), LED=~15(ACBUS7). +# CONNECTION NOTES: +# * Connect EXT connector pin 1 with 3 to get 5V on JTAG connector pin 19. +# * Connect JTAG connector pin 1 to 5V (i.e. EXT pin 13 or JTAG pin 19). +# * For TPI connection use resistors: TDO --[470R]-- TPIDATA --[470R]-- TDI. +# * Powering target from JTAG pin 19 allows KT-LINK current measurement. +programmer + id = "ktlink"; + desc = "KT-LINK FT2232H interface with IO switching and voltage buffers."; + type = "avrftdi"; + connection_type = usb; + usbvid= 0x0403; + usbpid= 0xBBE2; + usbdev= "A"; + reset = 8; + sck = 0; + mosi = 1; + miso = 2; + buff = ~10,~14,~13,5; + rdyled = ~15; +; + programmer id = "serialupdi"; desc = "SerialUPDI"; From 9d025e6a709ae105b2a0d8cc3588877cb9636f28 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 10 Apr 2022 23:36:53 +0200 Subject: [PATCH 02/65] Fix linuxspi baud to clock period calculation #927 related --- src/linuxspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linuxspi.c b/src/linuxspi.c index d0912e1a..df497057 100644 --- a/src/linuxspi.c +++ b/src/linuxspi.c @@ -223,7 +223,7 @@ static int linuxspi_open(PROGRAMMER *pgm, char *port) avrdude_message(MSG_INFO, "%s: obsolete use of -b option for bit clock; use -B \n", progname); - pgm->bitclock = 1E6 / pgm->baudrate; + pgm->bitclock = 1.0 / pgm->baudrate; } if (pgm->bitclock == 0) { avrdude_message(MSG_NOTICE, From 74a92d79917f47bdc457d287d9d34464316eb4e1 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 26 Apr 2022 21:29:46 +0200 Subject: [PATCH 03/65] Try to exclude the 'onlinedocs' branch from actions There's no sourcecode within that branch, anyway. --- .github/workflows/build.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7951592c..900864f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,8 +20,14 @@ name: Build on: push: + branches-ignore: + - 'onlinedocs' pull_request: + branches-ignore: + - 'onlinedocs' workflow_call: + branches-ignore: + - 'onlinedocs' env: BUILD_TYPE: RelWithDebInfo From 5a3ff7884485aecd72129436928030b5b8cc1cf2 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 26 Apr 2022 21:41:03 +0200 Subject: [PATCH 04/65] Fix syntax error in workflow build.yml file --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 900864f3..01a23f7e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,8 +26,6 @@ on: branches-ignore: - 'onlinedocs' workflow_call: - branches-ignore: - - 'onlinedocs' env: BUILD_TYPE: RelWithDebInfo From 08ad5ea44591c488c84f28b0b1183f1113597a0b Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 26 Apr 2022 23:19:20 +0200 Subject: [PATCH 05/65] Fix broken texinfo @ must be escaped as @@ --- src/doc/avrdude.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/avrdude.texi b/src/doc/avrdude.texi index ad4a6598..92cf4df4 100644 --- a/src/doc/avrdude.texi +++ b/src/doc/avrdude.texi @@ -1561,7 +1561,7 @@ Info: Writing 24 bytes starting from address 0x00 avrdude> dump eeprom 0 32 >>> dump eeprom 0 32 -0000 d2 02 96 49 41 56 52 55 f8 2d 40 48 65 6c 6c 6f |...IAVRU.-@Hello| +0000 d2 02 96 49 41 56 52 55 f8 2d 40 48 65 6c 6c 6f |...IAVRU.-@@Hello| 0010 20 57 6f 72 6c 64 21 00 ff ff ff ff ff ff ff ff | World!.........| avrdude> q From 033b2ed796ffbf8327ab51be0d6f528c83bbab1a Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Fri, 29 Apr 2022 00:37:28 +0100 Subject: [PATCH 06/65] Treat x bits in .conf SPI commands as 0 --- src/avrpart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/avrpart.c b/src/avrpart.c index dc6def44..fdff0f78 100644 --- a/src/avrpart.c +++ b/src/avrpart.c @@ -82,11 +82,11 @@ int avr_set_bits(OPCODE * op, unsigned char * cmd) unsigned char mask; for (i=0; i<32; i++) { - if (op->bit[i].type == AVR_CMDBIT_VALUE) { + if (op->bit[i].type == AVR_CMDBIT_VALUE || op->bit[i].type == AVR_CMDBIT_IGNORE) { j = 3 - i / 8; bit = i % 8; mask = 1 << bit; - if (op->bit[i].value) + if (op->bit[i].value && op->bit[i].type == AVR_CMDBIT_VALUE) cmd[j] = cmd[j] | mask; else cmd[j] = cmd[j] & ~mask; From 4bcd0eaa1d548ff659c4a5579070cfddcfeda1ea Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 1 May 2022 21:55:50 +0200 Subject: [PATCH 07/65] Fix a number of mistakes in avrdude.conf.in Stefan Rueger found a lot of mistakes in this file. Closes #915 --- NEWS | 1 + src/avrdude.conf.in | 164 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 147 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index f2ec51a2..36a475a3 100644 --- a/NEWS +++ b/NEWS @@ -88,6 +88,7 @@ Changes since version 6.4: where the EDBG AVRISP 'Enter Programming Mode' command fails #900 - Terminal write mode doesn't support string input (yet) #913 - Terminal mode: memory fill with strings may cause Avrdude to crash. #922 + - Some parts have wrong or missing ISP commands #915 * Pull requests: diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 096751d0..18db5ec2 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -4741,16 +4741,79 @@ part parent "m324p" signature = 0x1e 0x94 0x0a; memory "eeprom" + paged = no; /* leave this "no" */ size = 512; page_size = 4; - ; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; memory "flash" paged = yes; size = 16384; page_size = 128; num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 256; + readsize = 256; ; + ; #------------------------------------------------------------ @@ -5907,7 +5970,7 @@ part " i i i i i i i i"; writepage = " 0 1 0 0 1 1 0 0", - " x x x a12 a11 a10 a9 a8", + " x a14 a13 a12 a11 a10 a9 a8", " a7 a6 x x x x x x", " x x x x x x x x"; @@ -6161,7 +6224,7 @@ part " i i i i i i i i"; writepage = " 0 1 0 0 1 1 0 0", - " x x x a12 a11 a10 a9 a8", + "a15 a14 a13 a12 a11 a10 a9 a8", " a7 x x x x x x x", " x x x x x x x x"; @@ -8846,7 +8909,7 @@ part "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; write = "1 1 0 0 0 0 0 0 0 0 x x x x x a8", - "a8 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; loadpage_lo = " 1 1 0 0 0 0 0 1", " 0 0 0 0 0 0 0 0", @@ -8854,8 +8917,8 @@ part " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x x x x", - " 0 0 a5 a4 a3 a2 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -9033,7 +9096,7 @@ part "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; write = "1 1 0 0 0 0 0 0 0 0 x x x x x a8", - "a8 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; loadpage_lo = " 1 1 0 0 0 0 0 1", " 0 0 0 0 0 0 0 0", @@ -9041,8 +9104,8 @@ part " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x x x x", - " 0 0 a5 a4 a3 a2 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -9777,8 +9840,37 @@ part parent "m328" bs2 = 0xe2; memory "eeprom" + paged = no; size = 2048; page_size = 8; + min_write_delay = 3600; + max_write_delay = 3600; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 4; + readsize = 256; ; memory "flash" @@ -9786,6 +9878,40 @@ part parent "m328" size = 65536; page_size = 256; num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 128; + readsize = 256; + ; memory "efuse" @@ -10259,7 +10385,7 @@ part " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x x x x", + " 0 0 x x x x x a8", " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; @@ -12127,7 +12253,7 @@ part writepage = " 1 1 0 0 0 0 1 0", " 0 0 x x x x x x", - " x a6 a5 a4 a3 a2 0 0", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -12319,8 +12445,8 @@ part " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x x x x", - " x a6 a5 a4 a3 a2 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -12621,7 +12747,7 @@ part readback_p1 = 0xff; readback_p2 = 0xff; read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", - "0 0 a4 a3 a2 a1 a0 o o o o o o o o"; + "0 0 a5 a4 a3 a2 a1 a0 o o o o o o o o"; write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", "0 0 a5 a4 a3 a2 a1 a0 i i i i i i i i"; @@ -12690,6 +12816,8 @@ part size = 1; write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", "x x x x x x x x 1 1 i i i i i i"; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; min_write_delay = 4500; max_write_delay = 4500; ; @@ -13404,7 +13532,7 @@ part " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x a10 a9 a8", + " 0 0 x x a11 a10 a9 a8", " a7 a6 a5 a4 a3 0 0 0", " x x x x x x x x"; @@ -16463,12 +16591,12 @@ part readback_p1 = 0xff; readback_p2 = 0xff; read_lo = " 0 0 1 0 0 0 0 0", - " 0 0 0 a12 a11 a10 a9 a8", + " 0 0 a13 a12 a11 a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; read_hi = " 0 0 1 0 1 0 0 0", - " 0 0 0 a12 a11 a10 a9 a8", + " 0 0 a13 a12 a11 a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; @@ -16483,7 +16611,7 @@ part " i i i i i i i i"; writepage = " 0 1 0 0 1 1 0 0", - " 0 0 0 a12 a11 a10 a9 a8", + " 0 0 a13 a12 a11 a10 a9 a8", " a7 a6 x x x x x x", " x x x x x x x x"; From 28ccd82edcda75b0f8c520ceb0455f3801a7ff09 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 1 May 2022 22:31:19 +0200 Subject: [PATCH 08/65] PR 930 931 issue 927 are done --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 36a475a3..da5c09a2 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,8 @@ Changes since version 6.4: - Teensy bootloader (PR #802) - Micronucleus bootloader (PR #786) - ft232h (generic variant, PR #842) + - Kristech KT-LINK FT2232H interface with IO switching and voltage + buffers (PR #930) * Issues fixed: @@ -89,6 +91,7 @@ Changes since version 6.4: - Terminal write mode doesn't support string input (yet) #913 - Terminal mode: memory fill with strings may cause Avrdude to crash. #922 - Some parts have wrong or missing ISP commands #915 + - Incorrect -b conversion for linuxspi programmer #927 * Pull requests: @@ -176,6 +179,8 @@ Changes since version 6.4: - Add terminal write string functionality #914 - Update documentation link to new URL #929 - Fix terminal write buffer overflow issue #924 + - Fix linuxspi baud to clock period calculation #931 + - Added KT-LINK FT2232H interface with IO switching and voltage buffers. #930 * Internals: From a4c9fcdcd7746f2aafae1ae5155d561a2af07cca Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Mon, 2 May 2022 22:51:22 +0200 Subject: [PATCH 09/65] More fixes for PR #915 --- src/avrdude.conf.in | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 02671614..d33a26a3 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -9880,23 +9880,23 @@ part parent "m328" readback_p1 = 0xff; readback_p2 = 0xff; read = " 1 0 1 0 0 0 0 0", - " 0 0 0 x x x a9 a8", + " 0 0 0 x x a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; write = " 1 1 0 0 0 0 0 0", - " 0 0 0 x x x a9 a8", + " 0 0 0 x x a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " i i i i i i i i"; loadpage_lo = " 1 1 0 0 0 0 0 1", " 0 0 0 0 0 0 0 0", - " 0 0 0 0 0 0 a1 a0", + " 0 0 0 0 0 a2 a1 a0", " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x x a9 a8", - " a7 a6 a5 a4 a3 a2 0 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", " x x x x x x x x"; mode = 0x41; @@ -9915,28 +9915,28 @@ part parent "m328" readback_p1 = 0xff; readback_p2 = 0xff; read_lo = " 0 0 1 0 0 0 0 0", - " 0 0 a13 a12 a11 a10 a9 a8", + " a15 a14 a13 a12 a11 a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; read_hi = " 0 0 1 0 1 0 0 0", - " 0 0 a13 a12 a11 a10 a9 a8", + " a15 a14 a13 a12 a11 a10 a9 a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; loadpage_lo = " 0 1 0 0 0 0 0 0", " 0 0 0 x x x x x", - " x x a5 a4 a3 a2 a1 a0", + " x a6 a5 a4 a3 a2 a1 a0", " i i i i i i i i"; loadpage_hi = " 0 1 0 0 1 0 0 0", " 0 0 0 x x x x x", - " x x a5 a4 a3 a2 a1 a0", + " x a6 a5 a4 a3 a2 a1 a0", " i i i i i i i i"; writepage = " 0 1 0 0 1 1 0 0", - " 0 0 a13 a12 a11 a10 a9 a8", - " a7 a6 x x x x x x", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", " x x x x x x x x"; mode = 0x41; @@ -12963,23 +12963,23 @@ part readback_p1 = 0x00; readback_p2 = 0x00; read = " 1 0 1 0 0 0 0 0", - " x x x x x a10 a9 a8", + " x x x x x x x a8", " a7 a6 a5 a4 a3 a2 a1 a0", " o o o o o o o o"; write = " 1 1 0 0 0 0 0 0", - " x x x x x a10 a9 a8", + " x x x x x x x a8", " a7 a6 a5 a4 a3 a2 a1 a0", " i i i i i i i i"; loadpage_lo = " 1 1 0 0 0 0 0 1", " 0 0 0 0 0 0 0 0", - " 0 0 0 0 0 a2 a1 a0", + " 0 0 0 0 0 0 a1 a0", " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", - " 0 0 x x x a10 a9 a8", - " a7 a6 a5 a4 a3 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -13165,12 +13165,12 @@ part loadpage_lo = " 1 1 0 0 0 0 0 1", " 0 0 0 0 0 0 0 0", - " 0 0 0 0 0 a2 a1 a0", + " 0 0 0 0 0 0 a1 a0", " i i i i i i i i"; writepage = " 1 1 0 0 0 0 1 0", " 0 0 x x x a10 a9 a8", - " a7 a6 a5 a4 a3 0 0 0", + " a7 a6 a5 a4 a3 a2 0 0", " x x x x x x x x"; mode = 0x41; @@ -16634,17 +16634,17 @@ part loadpage_lo = " 0 1 0 0 0 0 0 0", " 0 0 0 x x x x x", - " x x a5 a4 a3 a2 a1 a0", + " x x x x a3 a2 a1 a0", " i i i i i i i i"; loadpage_hi = " 0 1 0 0 1 0 0 0", " 0 0 0 x x x x x", - " x x a5 a4 a3 a2 a1 a0", + " x x x x a3 a2 a1 a0", " i i i i i i i i"; writepage = " 0 1 0 0 1 1 0 0", " 0 0 a13 a12 a11 a10 a9 a8", - " a7 a6 x x x x x x", + " a7 a6 a5 a4 x x x x", " x x x x x x x x"; mode = 0x41; From 3bdf138721bd4a08ed743312e11a95aa8a2ee892 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 20:45:47 +0200 Subject: [PATCH 10/65] Fix micronucleus bootloader to check for unresponsive USB devices --- src/micronucleus.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/micronucleus.c b/src/micronucleus.c index b3c25341..b8d9d7ee 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -744,6 +744,19 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { avrdude_message(MSG_INFO, "%s: ERROR: Failed to open USB device: %s\n", progname, usb_strerror()); } + else + { + // Send a dummy request to check for a unresponsive USB device. + int result = micronucleus_get_bootloader_info(pdata); + if (result < 0) + { + avrdude_message(MSG_NOTICE, "%s: WARNING: Failed to probe device (error %d), skipping...\n", + progname, result); + + usb_close(pdata->usb_handle); + pdata->usb_handle = NULL; + } + } } } } From c64f2030a175341ee8943757d12dcf91f5af829c Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 21:42:27 +0200 Subject: [PATCH 11/65] Improve micronucleus bootloader user experience for unresponsive USB devices --- src/micronucleus.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/micronucleus.c b/src/micronucleus.c index b8d9d7ee..28dac2cb 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -139,6 +139,22 @@ static int micronucleus_check_connection(pdata_t* pdata) } } +static bool micronucleus_is_device_responsive(pdata_t* pdata, struct usb_device* device) +{ + pdata->usb_handle = usb_open(device); + if (pdata->usb_handle == NULL) + { + return false; + } + + int result = micronucleus_check_connection(pdata); + + usb_close(pdata->usb_handle); + pdata->usb_handle = NULL; + + return result >= 0; +} + static int micronucleus_reconnect(pdata_t* pdata) { struct usb_device* device = usb_device(pdata->usb_handle); @@ -696,6 +712,7 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) usb_init(); bool show_retry_message = true; + bool show_unresponsive_device_message = true; time_t start_time = time(NULL); for (;;) @@ -717,6 +734,19 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) pdata->major_version = (uint8_t)(device->descriptor.bcdDevice >> 8); pdata->minor_version = (uint8_t)(device->descriptor.bcdDevice >> 0); + if (!micronucleus_is_device_responsive(pdata, device)) + { + if (show_unresponsive_device_message) + { + avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect....\n", + progname); + + show_unresponsive_device_message = false; + } + + continue; + } + avrdude_message(MSG_NOTICE, "%s: Found device with Micronucleus V%d.%d, bus:device: %s:%s\n", progname, pdata->major_version, pdata->minor_version, @@ -744,19 +774,6 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { avrdude_message(MSG_INFO, "%s: ERROR: Failed to open USB device: %s\n", progname, usb_strerror()); } - else - { - // Send a dummy request to check for a unresponsive USB device. - int result = micronucleus_get_bootloader_info(pdata); - if (result < 0) - { - avrdude_message(MSG_NOTICE, "%s: WARNING: Failed to probe device (error %d), skipping...\n", - progname, result); - - usb_close(pdata->usb_handle); - pdata->usb_handle = NULL; - } - } } } } From 01a9e42d7d43bb4329740f9d72b1c3591e342726 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 22:08:46 +0200 Subject: [PATCH 12/65] Fix typo in micronucleus message --- src/micronucleus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/micronucleus.c b/src/micronucleus.c index 28dac2cb..c3dd007d 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -738,7 +738,7 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { if (show_unresponsive_device_message) { - avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect....\n", + avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect...\n", progname); show_unresponsive_device_message = false; From 43ddea910254df8c92d48b3d73b49c823b4b62b2 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 5 May 2022 22:58:45 +0200 Subject: [PATCH 13/65] Calibration memory of ATtiny43U is only 1 byte Closes issue #921. --- NEWS | 1 + src/avrdude.conf.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index da5c09a2..7bcbd142 100644 --- a/NEWS +++ b/NEWS @@ -92,6 +92,7 @@ Changes since version 6.4: - Terminal mode: memory fill with strings may cause Avrdude to crash. #922 - Some parts have wrong or missing ISP commands #915 - Incorrect -b conversion for linuxspi programmer #927 + - ATtiny43U calibration memory size #921 * Pull requests: diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index d33a26a3..362b6167 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -12888,7 +12888,7 @@ part ; memory "calibration" - size = 2; + size = 1; read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", "0 0 0 0 0 0 0 a0 o o o o o o o o"; ; From a2e456ca8a88557cf6ae567e1712b8804fdc6442 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 7 May 2022 22:20:31 +0200 Subject: [PATCH 14/65] v7.0 release preparation --- src/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configure.ac b/src/configure.ac index 5527ad6c..ae60e3f1 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -23,7 +23,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) -AC_INIT(avrdude, 6.99-20211218, avrdude-dev@nongnu.org) +AC_INIT(avrdude, 7.0, avrdude-dev@nongnu.org) AC_CANONICAL_BUILD AC_CANONICAL_HOST From ec5033743469f229ccabf7c12cfcc361a98b5659 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 7 May 2022 22:39:47 +0200 Subject: [PATCH 15/65] Correctly name the release in NEWS --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 7bcbd142..2a190861 100644 --- a/NEWS +++ b/NEWS @@ -5,7 +5,7 @@ Approximate change log for AVRDUDE by version. (For detailed changes, see the version control system logs.) ---------------------------------------------------------------------- -Changes since version 6.4: +Changes in version 7.0: * Major changes compared to the previous version: From 9bc28d410e7e646b29f8f3e03f5afb2225e118af Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 7 May 2022 22:57:49 +0200 Subject: [PATCH 16/65] Post-7.0 changes Update version date in configure.ac. Update template in NEWS --- NEWS | 14 ++++++++++++++ src/configure.ac | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 2a190861..558831ab 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,20 @@ Approximate change log for AVRDUDE by version. (For detailed changes, see the version control system logs.) ---------------------------------------------------------------------- +Changes since version 7.0: + + * Major changes compared to the previous version: + + * New devices supported: + + * New programmers supported: + + * Issues fixed: + + * Pull requests: + + * Internals: + Changes in version 7.0: * Major changes compared to the previous version: diff --git a/src/configure.ac b/src/configure.ac index ae60e3f1..e6629c73 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -23,7 +23,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) -AC_INIT(avrdude, 7.0, avrdude-dev@nongnu.org) +AC_INIT(avrdude, 7.0-20220508, avrdude-dev@nongnu.org) AC_CANONICAL_BUILD AC_CANONICAL_HOST From a855692d973c2e72d38b59be545375982af3d4f7 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 8 May 2022 13:58:44 +0200 Subject: [PATCH 17/65] Correctly name the release in CMakeLists.txt as well --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d6f8dd..95c89d2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ # cmake --build build cmake_minimum_required(VERSION 3.12) -project(avrdude VERSION 6.99) +project(avrdude VERSION 7.0) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED True) From d6347f4187451653371b83edf6ff6a2c02567d61 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 8 May 2022 13:58:44 +0200 Subject: [PATCH 18/65] Correctly name the release in CMakeLists.txt as well --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d6f8dd..95c89d2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ # cmake --build build cmake_minimum_required(VERSION 3.12) -project(avrdude VERSION 6.99) +project(avrdude VERSION 7.0) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED True) From b9a012cebb96a4ec73763a58b45ace9aeb7af00d Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Sun, 8 May 2022 20:35:32 +0530 Subject: [PATCH 19/65] Fix .Dd macro in manpage The correct format for .Dd according to mdoc(7) is - .Dd month day, year --- src/avrdude.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avrdude.1 b/src/avrdude.1 index cc05cf4c..81834d30 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -18,7 +18,7 @@ .\" .\" $Id$ .\" -.Dd DATE November 22, 2021 +.Dd November 22, 2021 .Os .Dt AVRDUDE 1 .Sh NAME From 4601bee4afa76fb4aa8392ffdd4a4dd56ede1bae Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 8 May 2022 20:39:12 +0200 Subject: [PATCH 20/65] Mention PR 949 --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 558831ab..ca827290 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ Changes since version 7.0: * Pull requests: + - Fix .Dd macro in manpage #949 + * Internals: Changes in version 7.0: From 75bfbf7bef53a54a6824626913253d0b4bebc9e8 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 9 May 2022 02:02:42 +0200 Subject: [PATCH 21/65] fix M1 homebrew path --- build.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index baea4516..4fceb6e3 100755 --- a/build.sh +++ b/build.sh @@ -50,7 +50,13 @@ case "${ostype}" in then build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/local/lib" else - build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar" + # Apple M1 (may be new version of homebrew also) + if [ -d /opt/homebrew ] + then + build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/homebrew/Cellar" + else + build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar" + fi fi ;; From a23055d6481f268f1782a55303cc5427072bbe1e Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 9 May 2022 14:51:16 +0200 Subject: [PATCH 22/65] fix typo --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4fceb6e3..0b664807 100755 --- a/build.sh +++ b/build.sh @@ -53,7 +53,7 @@ case "${ostype}" in # Apple M1 (may be new version of homebrew also) if [ -d /opt/homebrew ] then - build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/homebrew/Cellar" + build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/Cellar" else build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar" fi From 8b61c9dd8f0c0e99bd89389c4f19f186beeef3ef Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Wed, 11 May 2022 20:56:05 +0200 Subject: [PATCH 23/65] CMake: Move MSVC compatibility shim into library --- src/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a8e0262b..7d6771f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,7 +51,7 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) add_compile_definitions(CONFIG_DIR=\"${CONFIG_DIR}\") if(WIN32) - set(EXTRA_WINDOWS_SOURCES "${PROJECT_BINARY_DIR}/src/windows.rc") + set(EXTRA_WINDOWS_RESOURCES "${PROJECT_BINARY_DIR}/src/windows.rc") set(EXTRA_WINDOWS_LIBRARIES setupapi ws2_32) endif() @@ -216,6 +216,7 @@ add_library(libavrdude xbee.c ${FLEX_Parser_OUTPUTS} ${BISON_Parser_OUTPUTS} + "${EXTRA_WINDOWS_SOURCES}" ) set_target_properties(libavrdude PROPERTIES @@ -253,7 +254,7 @@ add_executable(avrdude term.h whereami.c whereami.h - "${EXTRA_WINDOWS_SOURCES}" + "${EXTRA_WINDOWS_RESOURCES}" ) target_link_libraries(avrdude PUBLIC libavrdude) From 053c2dcdd3cb24e0778bd54073c7456a66056a68 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Wed, 11 May 2022 20:57:14 +0200 Subject: [PATCH 24/65] CMake: Include GCC specific options also for MSYS2 --- src/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d6771f3..7577e113 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,11 +55,6 @@ if(WIN32) set(EXTRA_WINDOWS_LIBRARIES setupapi ws2_32) endif() -if(NOT WIN32) - set(LIB_MATH m) - add_compile_options(-Wall) # -Wextra -endif() - if(MSVC) add_compile_definitions(_CRT_SECURE_NO_WARNINGS=1) add_compile_definitions(_CRT_NONSTDC_NO_WARNINGS=1) @@ -79,6 +74,9 @@ if(MSVC) set(EXTRA_WINDOWS_INCLUDES ${EXTRA_WINDOWS_INCLUDES} "msvc" ) +else() + set(LIB_MATH m) + add_compile_options(-Wall) # -Wextra endif() # ===================================== From 0ea4b08b2f895ed89dcc0f0557acf9de0bd0dcd3 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Wed, 11 May 2022 21:02:03 +0200 Subject: [PATCH 25/65] CMake: If installed, use static version of libreadline for MSYS2 --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95c89d2b..cf3623e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ if(WIN32) set(PREFERRED_LIBHIDAPI libhidapi.a libhidapi-libusb.a libhidapi-hidraw.a hidapi hidapi-libusb hidapi-hidraw) set(PREFERRED_LIBFTDI libftdi.a ftdi) set(PREFERRED_LIBFTDI1 libftdi1.a ftdi1) + set(PREFERRED_LIBREADLINE libreadline.a) else() set(PREFERRED_LIBELF elf) set(PREFERRED_LIBUSB usb) @@ -125,6 +126,7 @@ else() set(PREFERRED_LIBHIDAPI hidapi hidapi-libusb hidapi-hidraw) set(PREFERRED_LIBFTDI ftdi) set(PREFERRED_LIBFTDI1 ftdi1) + set(PREFERRED_LIBREADLINE readline) endif() # ------------------------------------- @@ -212,7 +214,7 @@ endif() # ------------------------------------- # Find libreadline -find_library(HAVE_LIBREADLINE NAMES readline) +find_library(HAVE_LIBREADLINE NAMES ${PREFERRED_LIBREADLINE}) if(HAVE_LIBREADLINE) set(LIB_LIBREADLINE ${HAVE_LIBREADLINE}) endif() From 65bb41f8e9bd500d2afe2462a7ff7f93b3c277b7 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Wed, 11 May 2022 21:08:05 +0200 Subject: [PATCH 26/65] CMake: Add build option to select static or shared libraries --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf3623e9..19897c72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,13 @@ option(USE_LIBUSBWIN32 "Prefer libusb-win32 over libusb" OFF) option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +if(WIN32) + # Prefer static libraries over DLLs on Windows + option(USE_STATIC_LIBS "Use static libraries" ON) +else() + option(USE_STATIC_LIBS "Use static libraries" OFF) +endif() + include(CheckIncludeFile) include(CheckSymbolExists) include(FetchContent) @@ -110,8 +117,7 @@ endif() # Detect installed libraries # ===================================== -# Prefer static libraries over DLLs on Windows -if(WIN32) +if(USE_STATIC_LIBS) set(PREFERRED_LIBELF libelf.a elf) set(PREFERRED_LIBUSB libusb.a usb) set(PREFERRED_LIBUSB_1_0 libusb-1.0.a usb-1.0) From 3b0d7e5d5d325362d4ca1f4ebc7271c653a89766 Mon Sep 17 00:00:00 2001 From: Ebben Aries Date: Sat, 21 May 2022 14:25:27 -0600 Subject: [PATCH 27/65] Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a8e0262b..d4472481 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -264,8 +264,8 @@ target_link_libraries(avrdude PUBLIC libavrdude) install(TARGETS avrdude DESTINATION bin) install(TARGETS libavrdude - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION include COMPONENT dev ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/avrdude.conf" TYPE SYSCONF) From feaa1c6a6b0a0cf234dbd9e86e5b0d13d745c09a Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Mon, 30 May 2022 07:01:22 +0200 Subject: [PATCH 28/65] PR 950 done --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index ca827290..1a0c4824 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ Changes since version 7.0: * Pull requests: - Fix .Dd macro in manpage #949 + - fix M1 homebrew path #950 * Internals: From bdb4128de3f63a1fb4abc208ec9bfa90ef3dd676 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 29 May 2022 13:12:50 +0200 Subject: [PATCH 29/65] Fix JTAG transaction close issue Fixes issue #366 --- src/jtagmkII.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtagmkII.c b/src/jtagmkII.c index fc06301c..b1024b53 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -1840,8 +1840,8 @@ void jtagmkII_close(PROGRAMMER * pgm) avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close()\n", progname); - if (pgm->flag & PGM_FL_IS_PDI) { - /* When in PDI mode, restart target. */ + if (pgm->flag & (PGM_FL_IS_PDI | PGM_FL_IS_JTAG)) { + /* When in PDI or JTAG mode, restart target. */ buf[0] = CMND_GO; avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close(): Sending GO command: ", progname); From bd8c17b35f772978dd12f866e4de569963f27162 Mon Sep 17 00:00:00 2001 From: prchal Date: Tue, 7 Jun 2022 11:50:03 +0200 Subject: [PATCH 30/65] adding support for all Linux baud rates v.2 If optiboot can work at higher bauds, why not avrdude. Versoin 2 of #985. Linux uses the old-style bitmapped version of the Bxxxx macros. --- src/ser_posix.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ser_posix.c b/src/ser_posix.c index 2c5d45b5..53d8cd15 100644 --- a/src/ser_posix.c +++ b/src/ser_posix.c @@ -76,6 +76,45 @@ static struct baud_mapping baud_lookup_table [] = { #endif #ifdef B230400 { 230400, B230400 }, +#endif +#ifdef B250000 + { 250000, B250000 }, +#endif +#ifdef B460800 + { 460800, B460800 }, +#endif +#ifdef B500000 + { 500000, B500000 }, +#endif +#ifdef B576000 + { 576000, B576000 }, +#endif +#ifdef B921600 + { 921600, B921600 }, +#endif +#ifdef B1000000 + { 1000000, B1000000 }, +#endif +#ifdef B1152000 + { 1152000, B1152000 }, +#endif +#ifdef B1500000 + { 1500000, B1500000 }, +#endif +#ifdef B2000000 + { 2000000, B2000000 }, +#endif +#ifdef B2500000 + { 2500000, B2500000 }, +#endif +#ifdef B3000000 + { 3000000, B3000000 }, +#endif +#ifdef B3500000 + { 3500000, B3500000 }, +#endif +#ifdef B4000000 + { 4000000, B4000000 }, #endif { 0, 0 } /* Terminator. */ }; From cb114233ef68625332df5fff876467f57648cd9d Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Fri, 10 Jun 2022 20:38:54 +0200 Subject: [PATCH 31/65] Mention PR #945, #962, #972 --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 1a0c4824..4638746a 100644 --- a/NEWS +++ b/NEWS @@ -15,10 +15,15 @@ Changes since version 7.0: * Issues fixed: + - Fix micronucleus bootloader to check for unresponsive USB + devices #945 + - Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972 + * Pull requests: - Fix .Dd macro in manpage #949 - fix M1 homebrew path #950 + - CMake Enhancements #962 * Internals: From 308263043087c15f58ebaa501bd8da69c9188b68 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 15 Jun 2022 23:32:22 +0200 Subject: [PATCH 32/65] Replace internal knowledge in jtag3.c by a public API In certain situations (CRC failure, device locked), that JTAG3 read functions need to return an indication to the caller that it is OK to proceed, and allow erasing the device anyway. Historically, the JTAG3 code passed the respective protocol errors directly (and unexplained) up to the caller, leaving the decision to the caller how to handle the situation. Replace that by a more common return value API. New code should prefer this API instead of any hardcoded return values. --- src/avr.c | 12 ++++++------ src/jtag3.c | 31 +++++++++++++++++++++---------- src/jtag3_private.h | 1 + src/libavrdude.h | 10 ++++++++++ src/main.c | 5 ++--- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/avr.c b/src/avr.c index d6e78bb5..a8945d86 100644 --- a/src/avr.c +++ b/src/avr.c @@ -439,16 +439,16 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, (vmem->tags[i] & TAG_ALLOCATED) != 0) { rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i); - if (rc != 0) { + if (rc != LIBAVRDUDE_SUCCESS) { avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i); - if (rc == -1) { + if (rc == LIBAVRDUDE_GENERAL_FAILURE) { avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n", memtype); - return -2; + return LIBAVRDUDE_NOTSUPPORTED; } avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n", memtype); - return rc; + return LIBAVRDUDE_SOFTFAIL; } } report_progress(i, mem->size, NULL); @@ -1035,14 +1035,14 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p) report_progress (0,1,"Reading"); rc = avr_read(pgm, p, "signature", 0); - if (rc < 0) { + if (rc < LIBAVRDUDE_SUCCESS) { avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n", progname, p->desc, rc); return rc; } report_progress (1,1,NULL); - return 0; + return LIBAVRDUDE_SUCCESS; } static uint8_t get_fuse_bitmask(AVRMEM * m) { diff --git a/src/jtag3.c b/src/jtag3.c index 6d358dfa..23df86ff 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -313,6 +313,16 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len) } } +static int jtag3_errcode(int status) +{ + if (status >= LIBAVRDUDE_SUCCESS) + return status; + if (status == RSP3_FAIL_OCD_LOCKED || + status == RSP3_FAIL_CRC_FAILURE) + return LIBAVRDUDE_SOFTFAIL; + return LIBAVRDUDE_GENERAL_FAILURE; +} + static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len) { int i; @@ -850,7 +860,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { putc('\n', stderr); avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n", progname, descr, status); - return -1; + return LIBAVRDUDE_GENERAL_FAILURE; } else if (verbose >= 3) { putc('\n', stderr); jtag3_prmsg(pgm, *resp, status); @@ -871,10 +881,11 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { status = (*resp)[3]; free(*resp); resp = 0; - return -status; + + return jtag3_errcode(status); } - return status; + return LIBAVRDUDE_SUCCESS; } @@ -987,10 +998,10 @@ static int jtag3_program_enable(PROGRAMMER * pgm) free(resp); PDATA(pgm)->prog_enabled = 1; - return 0; + return LIBAVRDUDE_SUCCESS; } - return status; + return jtag3_errcode(status); } static int jtag3_program_disable(PROGRAMMER * pgm) @@ -1921,7 +1932,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (!(pgm->flag & PGM_FL_IS_DW)) if ((status = jtag3_program_enable(pgm)) < 0) - return status; + return jtag3_errcode(status); cmd[0] = SCOPE_AVR; cmd[1] = CMD3_READ_MEMORY; @@ -2007,7 +2018,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (addr == 0) { if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return status; + return jtag3_errcode(status); signature_cache[0] = resp[4]; signature_cache[1] = resp[5]; @@ -2057,7 +2068,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, } if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return status; + return jtag3_errcode(status); if (resp[1] != RSP3_DATA || status < (pagesize? pagesize: 1) + 4) { @@ -2185,7 +2196,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, cmd[13] = data; if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0) - return status; + return jtag3_errcode(status); free(resp); @@ -2316,7 +2327,7 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib) u32_to_b4(cmd + 8, AVR_SIBLEN); if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0) - return status; + return jtag3_errcode(status); memcpy(sib, resp+3, AVR_SIBLEN); sib[AVR_SIBLEN] = 0; // Zero terminate string diff --git a/src/jtag3_private.h b/src/jtag3_private.h index a3e7fb08..6385aa4c 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -145,6 +145,7 @@ # define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */ # define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */ # define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */ +# define RSP3_FAIL_CRC_FAILURE 0x47 /* CRC failure in device */ # define RSP3_FAIL_NOT_UNDERSTOOD 0x91 /* ICE events */ diff --git a/src/libavrdude.h b/src/libavrdude.h index ddb72b48..46789f4f 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -27,6 +27,16 @@ #include typedef uint32_t pinmask_t; +/* + * Values returned by library functions. + * Some library functions also return a count, i.e. a positive + * number greater than 0. + */ +#define LIBAVRDUDE_SUCCESS 0 +#define LIBAVRDUDE_GENERAL_FAILURE (-1) +#define LIBAVRDUDE_NOTSUPPORTED (-2) // operation not supported +#define LIBAVRDUDE_SOFTFAIL (-3) // returned by avr_signature() if caller + // might proceed with chip erase /* formerly lists.h */ diff --git a/src/main.c b/src/main.c index 253c6e51..5b0a6e38 100644 --- a/src/main.c +++ b/src/main.c @@ -1116,9 +1116,8 @@ int main(int argc, char * argv []) usleep(waittime); if (init_ok) { rc = avr_signature(pgm, p); - if (rc != 0) { - // -68 == -(0x44) == -(RSP3_FAIL_OCD_LOCKED) - if ((rc == -68) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) { + if (rc != LIBAVRDUDE_SUCCESS) { + if ((rc == LIBAVRDUDE_SOFTFAIL) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) { attempt++; if (pgm->read_sib) { // Read SIB and compare FamilyID From c8350f816c2ec26022bba5758aadebd4b3095230 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sat, 18 Jun 2022 22:34:54 +0100 Subject: [PATCH 33/65] Fix support for ATmega2560 et al (load extended address) --- src/avrftdi.c | 41 +++++++++++++++++++---------------------- src/avrftdi_private.h | 2 ++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/avrftdi.c b/src/avrftdi.c index e41d775e..c6d2f86e 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -917,8 +917,15 @@ static int avrftdi_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int avrftdi_lext(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int address) { + avrftdi_t *pdata = to_pdata(pgm); unsigned char buf[] = { 0x00, 0x00, 0x00, 0x00 }; + /* only send load extended address command if high byte changed */ + if(pdata->lext_byte == (uint8_t) (address>>16)) + return 0; + + pdata->lext_byte = (uint8_t) (address>>16); + avr_set_bits(m->op[AVR_OP_LOAD_EXT_ADDR], buf); avr_set_addr(m->op[AVR_OP_LOAD_EXT_ADDR], buf, address); @@ -983,8 +990,6 @@ static int avrftdi_eeprom_read(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int page_size, unsigned int addr, unsigned int len) { - int use_lext_address = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL; - unsigned int word; unsigned int poll_index; @@ -1013,22 +1018,12 @@ static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, page_size = m->page_size; - /* if we do cross a 64k word boundary (or write the - * first page), we need to issue a 'load extended - * address byte' command, which is defined as 0x4d - * 0x00
0x00. As far as i know, this - * is only available on 256k parts. 64k word is 128k - * bytes. - * write the command only once. - */ - if(use_lext_address && (((addr/2) & 0xffff0000))) { - if (0 > avrftdi_lext(pgm, p, m, addr/2)) - return -1; - } + /* on large-flash devices > 128k issue extended address command when needed */ + if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, addr/2) < 0) + return -1; /* prepare the command stream for the whole page */ - /* addr is in bytes, but we program in words. addr/2 should be something - * like addr >> WORD_SHIFT, though */ + /* addr is in bytes, but we program in words. */ for(word = addr/2; word < (len + addr)/2; word++) { log_debug("-< bytes = %d of %d\n", word * 2, len + addr); @@ -1107,7 +1102,6 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, { OPCODE * readop; int byte, word; - int use_lext_address = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL; unsigned int address = addr/2; unsigned int buf_size = 4 * len + 4; @@ -1128,10 +1122,8 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return -1; } - if(use_lext_address && ((address & 0xffff0000))) { - if (0 > avrftdi_lext(pgm, p, m, address)) - return -1; - } + if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, address) < 0) + return -1; /* word addressing! */ for(word = addr/2, index = 0; word < (addr + len)/2; word++) @@ -1210,7 +1202,11 @@ avrftdi_setup(PROGRAMMER * pgm) { avrftdi_t* pdata; - pgm->cookie = malloc(sizeof(avrftdi_t)); + + if(!(pgm->cookie = calloc(sizeof(avrftdi_t), 1))) { + log_err("Error allocating memory.\n"); + exit(1); + } pdata = to_pdata(pgm); pdata->ftdic = ftdi_new(); @@ -1224,6 +1220,7 @@ avrftdi_setup(PROGRAMMER * pgm) pdata->pin_value = 0; pdata->pin_direction = 0; pdata->led_mask = 0; + pdata->lext_byte = 0xff; } static void diff --git a/src/avrftdi_private.h b/src/avrftdi_private.h index 3c965ed8..15b9caec 100644 --- a/src/avrftdi_private.h +++ b/src/avrftdi_private.h @@ -81,6 +81,8 @@ typedef struct avrftdi_s { int tx_buffer_size; /* use bitbanging instead of mpsse spi */ bool use_bitbanging; + /* bits 16-23 of extended 24-bit word flash address for parts with flash > 128k */ + uint8_t lext_byte; } avrftdi_t; void avrftdi_log(int level, const char * func, int line, const char * fmt, ...); From 3b0a2abc20e88101a194b953ab31cd8ab89d27dd Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 19 Jun 2022 10:53:07 +0200 Subject: [PATCH 34/65] Reduce programmer description string length to less than 80 characters. #941 related --- src/avrdude.conf.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 362b6167..ba7f4f8e 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -947,9 +947,10 @@ programmer ; # commercial version of USBtiny, using a separate VID/PID +# https://github.com/IowaScaledEngineering/ckt-avrprogrammer programmer id = "iseavrprog"; - desc = "USBtiny-based USB programmer, https://github.com/IowaScaledEngineering/ckt-avrprogrammer"; + desc = "USBtiny-based programmer, https://iascaled.com"; type = "usbtiny"; connection_type = usb; usbvid = 0x1209; From aa211f75800d320548cc051c8f830886f4f09c7e Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 19 Jun 2022 19:23:34 +0200 Subject: [PATCH 35/65] Add missing efuse write delay for ATmega169/A/P/PA and ATmega328P --- src/avrdude.conf.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 362b6167..c0ba9c4b 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -5823,6 +5823,8 @@ part memory "efuse" size = 1; + min_write_delay = 2000; + max_write_delay = 2000; write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", "x x x x x x x x x x x x i i i i"; @@ -9852,6 +9854,8 @@ part parent "m328" memory "efuse" size = 1; + min_write_delay = 4500; + max_write_delay = 4500; read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", "x x x x x x x x o o o o o o o o"; write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", From 692c13ed98a80b0728f2a4e78c6b61fcf181fa3b Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 19 Jun 2022 19:40:31 +0200 Subject: [PATCH 36/65] Add missing chip erase delay for ATmega48/88/168/328PB --- src/avrdude.conf.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index c0ba9c4b..bf2892aa 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -8215,6 +8215,7 @@ part parent "m48" id = "m48pb"; desc = "ATmega48PB"; signature = 0x1e 0x92 0x10; + chip_erase_delay = 10500; ; #------------------------------------------------------------ @@ -8442,6 +8443,7 @@ part parent "m88" id = "m88pb"; desc = "ATmega88PB"; signature = 0x1e 0x93 0x16; + chip_erase_delay = 10500; ; #------------------------------------------------------------ @@ -8671,6 +8673,7 @@ part parent "m168" id = "m168pb"; desc = "ATmega168PB"; signature = 0x1e 0x94 0x15; + chip_erase_delay = 10500; ; #------------------------------------------------------------ @@ -9827,6 +9830,7 @@ part parent "m328" id = "m328pb"; desc = "ATmega328PB"; signature = 0x1e 0x95 0x16; + chip_erase_delay = 10500; memory "efuse" size = 1; From 1aa59aaa98e6a79bb4a321be80c5113184dd2668 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 19 Jun 2022 19:56:56 +0200 Subject: [PATCH 37/65] PR #1000 is done now --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 4638746a..888796ca 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,8 @@ Changes since version 7.0: - Fix .Dd macro in manpage #949 - fix M1 homebrew path #950 - CMake Enhancements #962 + - Reduce programmer desc string length in avrdude.conf + to < 80 characters #1000 * Internals: From ae0e3e2f8e239c5075cd5a8507c9ada021197bcf Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 22 Jun 2022 23:33:53 +0200 Subject: [PATCH 38/65] Fix a number of logic errors in the previous commits RSP3_FAIL_CRC_FAILURE is 0x43 rather than 0x47. jtag3_errcode() must only be applied to a reason code, not to any general status code. --- src/jtag3.c | 32 +++++++++++++++----------------- src/jtag3_private.h | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/jtag3.c b/src/jtag3.c index 23df86ff..4c159ee8 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -313,12 +313,10 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len) } } -static int jtag3_errcode(int status) +static int jtag3_errcode(int reason) { - if (status >= LIBAVRDUDE_SUCCESS) - return status; - if (status == RSP3_FAIL_OCD_LOCKED || - status == RSP3_FAIL_CRC_FAILURE) + if (reason == RSP3_FAIL_OCD_LOCKED || + reason == RSP3_FAIL_CRC_FAILURE) return LIBAVRDUDE_SOFTFAIL; return LIBAVRDUDE_GENERAL_FAILURE; } @@ -844,7 +842,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { } } - int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, +int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, unsigned char **resp, const char *descr) { int status; @@ -868,9 +866,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status); } - c = (*resp)[1]; - if ((c & RSP3_STATUS_MASK) != RSP3_OK) { - if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED)) { + c = (*resp)[1] & RSP3_STATUS_MASK; + if (c != RSP3_OK) { + if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED || + (*resp)[3] == RSP3_FAIL_CRC_FAILURE)) { avrdude_message(MSG_INFO, "%s: Device is locked! Chip erase required to unlock.\n", progname); @@ -881,11 +880,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { status = (*resp)[3]; free(*resp); resp = 0; - return jtag3_errcode(status); } - return LIBAVRDUDE_SUCCESS; + return status; } @@ -1001,7 +999,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm) return LIBAVRDUDE_SUCCESS; } - return jtag3_errcode(status); + return status; } static int jtag3_program_disable(PROGRAMMER * pgm) @@ -1932,7 +1930,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (!(pgm->flag & PGM_FL_IS_DW)) if ((status = jtag3_program_enable(pgm)) < 0) - return jtag3_errcode(status); + return status; cmd[0] = SCOPE_AVR; cmd[1] = CMD3_READ_MEMORY; @@ -2018,7 +2016,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (addr == 0) { if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return jtag3_errcode(status); + return status; signature_cache[0] = resp[4]; signature_cache[1] = resp[5]; @@ -2068,7 +2066,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, } if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return jtag3_errcode(status); + return status; if (resp[1] != RSP3_DATA || status < (pagesize? pagesize: 1) + 4) { @@ -2196,7 +2194,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, cmd[13] = data; if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0) - return jtag3_errcode(status); + return status; free(resp); @@ -2327,7 +2325,7 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib) u32_to_b4(cmd + 8, AVR_SIBLEN); if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0) - return jtag3_errcode(status); + return status; memcpy(sib, resp+3, AVR_SIBLEN); sib[AVR_SIBLEN] = 0; // Zero terminate string diff --git a/src/jtag3_private.h b/src/jtag3_private.h index 6385aa4c..7d0cbb74 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -144,8 +144,8 @@ # define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */ # define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */ # define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */ +# define RSP3_FAIL_CRC_FAILURE 0x43 /* CRC failure in device */ # define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */ -# define RSP3_FAIL_CRC_FAILURE 0x47 /* CRC failure in device */ # define RSP3_FAIL_NOT_UNDERSTOOD 0x91 /* ICE events */ From 89b0aa72e0f605e4408989ae9a579dbffd65688d Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sat, 25 Jun 2022 11:39:16 +0200 Subject: [PATCH 39/65] Attempt to fix EEPROM write issue #1009 --- src/jtag3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag3.c b/src/jtag3.c index 6d358dfa..bb41431f 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1761,7 +1761,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, free(cmd); return n_bytes; } - cmd[3] = ( p->flags & AVRPART_HAS_PDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE; + cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE; PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L; } else if (strcmp(m->desc, "usersig") == 0 || strcmp(m->desc, "userrow") == 0) { From 1b997968a526c630a45ba8c705162140f86a7419 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 26 Jun 2022 22:58:25 +0200 Subject: [PATCH 40/65] Closing PR 979 --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 888796ca..16fef572 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ Changes since version 7.0: - Fix micronucleus bootloader to check for unresponsive USB devices #945 - Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972 + - [bug #43898] atmega644p remains stopped after JTAG transaction #366 * Pull requests: @@ -26,6 +27,7 @@ Changes since version 7.0: - CMake Enhancements #962 - Reduce programmer desc string length in avrdude.conf to < 80 characters #1000 + - Dragon JTAG fix #979 * Internals: From 362e6993acc863c282a16fd4d3642ebbeab4eae7 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 26 Jun 2022 23:00:32 +0200 Subject: [PATCH 41/65] PR 993 done --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 16fef572..da4e42d0 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ Changes since version 7.0: - Reduce programmer desc string length in avrdude.conf to < 80 characters #1000 - Dragon JTAG fix #979 + - adding support for all Linux baud rates v.2 #993 * Internals: From a6ea797c1cd51ccebdb44ac5cc5fc71b4c2a8cc7 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 28 Jun 2022 22:53:24 +0200 Subject: [PATCH 42/65] PR 996 and 1013 done --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index da4e42d0..d5ce1df4 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ Changes since version 7.0: to < 80 characters #1000 - Dragon JTAG fix #979 - adding support for all Linux baud rates v.2 #993 + - Replace internal knowledge in jtag3.c by a public API #996 + - JTAG3 UPDI EEPROM fix #1013 * Internals: From 43c6b0422681ca271b9f32537bdba488df221e06 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 28 Jun 2022 22:46:06 +0100 Subject: [PATCH 43/65] Update NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index d5ce1df4..e78362b3 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ Changes since version 7.0: - adding support for all Linux baud rates v.2 #993 - Replace internal knowledge in jtag3.c by a public API #996 - JTAG3 UPDI EEPROM fix #1013 + - Treat x bits in .conf SPI commands as 0 #943 * Internals: From d95c1a91f72578a761c579b103c3a1c787a741e1 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Mon, 4 Jul 2022 12:25:50 +0100 Subject: [PATCH 44/65] Steamline avrftdi support for ATmega2560 et al --- src/avrftdi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/avrftdi.c b/src/avrftdi.c index c6d2f86e..54490dc0 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -917,6 +917,10 @@ static int avrftdi_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int avrftdi_lext(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int address) { + /* nothing to do if load extended address command unavailable */ + if(m->op[AVR_OP_LOAD_EXT_ADDR] == NULL) + return 0; + avrftdi_t *pdata = to_pdata(pgm); unsigned char buf[] = { 0x00, 0x00, 0x00, 0x00 }; @@ -1019,7 +1023,7 @@ static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, page_size = m->page_size; /* on large-flash devices > 128k issue extended address command when needed */ - if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, addr/2) < 0) + if(avrftdi_lext(pgm, p, m, addr/2) < 0) return -1; /* prepare the command stream for the whole page */ @@ -1102,7 +1106,6 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, { OPCODE * readop; int byte, word; - unsigned int address = addr/2; unsigned int buf_size = 4 * len + 4; unsigned char* o_buf = alloca(buf_size); @@ -1122,7 +1125,7 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return -1; } - if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, address) < 0) + if(avrftdi_lext(pgm, p, m, addr/2) < 0) return -1; /* word addressing! */ From 3893a21164c0adec19e5d29f34efddb9b007d56a Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sat, 18 Jun 2022 22:34:54 +0100 Subject: [PATCH 45/65] Fix avrftdi support for ATmega2560 et al (load extended address) --- src/avrftdi.c | 41 +++++++++++++++++++---------------------- src/avrftdi_private.h | 2 ++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/avrftdi.c b/src/avrftdi.c index e41d775e..c6d2f86e 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -917,8 +917,15 @@ static int avrftdi_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int avrftdi_lext(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int address) { + avrftdi_t *pdata = to_pdata(pgm); unsigned char buf[] = { 0x00, 0x00, 0x00, 0x00 }; + /* only send load extended address command if high byte changed */ + if(pdata->lext_byte == (uint8_t) (address>>16)) + return 0; + + pdata->lext_byte = (uint8_t) (address>>16); + avr_set_bits(m->op[AVR_OP_LOAD_EXT_ADDR], buf); avr_set_addr(m->op[AVR_OP_LOAD_EXT_ADDR], buf, address); @@ -983,8 +990,6 @@ static int avrftdi_eeprom_read(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int page_size, unsigned int addr, unsigned int len) { - int use_lext_address = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL; - unsigned int word; unsigned int poll_index; @@ -1013,22 +1018,12 @@ static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, page_size = m->page_size; - /* if we do cross a 64k word boundary (or write the - * first page), we need to issue a 'load extended - * address byte' command, which is defined as 0x4d - * 0x00
0x00. As far as i know, this - * is only available on 256k parts. 64k word is 128k - * bytes. - * write the command only once. - */ - if(use_lext_address && (((addr/2) & 0xffff0000))) { - if (0 > avrftdi_lext(pgm, p, m, addr/2)) - return -1; - } + /* on large-flash devices > 128k issue extended address command when needed */ + if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, addr/2) < 0) + return -1; /* prepare the command stream for the whole page */ - /* addr is in bytes, but we program in words. addr/2 should be something - * like addr >> WORD_SHIFT, though */ + /* addr is in bytes, but we program in words. */ for(word = addr/2; word < (len + addr)/2; word++) { log_debug("-< bytes = %d of %d\n", word * 2, len + addr); @@ -1107,7 +1102,6 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, { OPCODE * readop; int byte, word; - int use_lext_address = m->op[AVR_OP_LOAD_EXT_ADDR] != NULL; unsigned int address = addr/2; unsigned int buf_size = 4 * len + 4; @@ -1128,10 +1122,8 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return -1; } - if(use_lext_address && ((address & 0xffff0000))) { - if (0 > avrftdi_lext(pgm, p, m, address)) - return -1; - } + if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, address) < 0) + return -1; /* word addressing! */ for(word = addr/2, index = 0; word < (addr + len)/2; word++) @@ -1210,7 +1202,11 @@ avrftdi_setup(PROGRAMMER * pgm) { avrftdi_t* pdata; - pgm->cookie = malloc(sizeof(avrftdi_t)); + + if(!(pgm->cookie = calloc(sizeof(avrftdi_t), 1))) { + log_err("Error allocating memory.\n"); + exit(1); + } pdata = to_pdata(pgm); pdata->ftdic = ftdi_new(); @@ -1224,6 +1220,7 @@ avrftdi_setup(PROGRAMMER * pgm) pdata->pin_value = 0; pdata->pin_direction = 0; pdata->led_mask = 0; + pdata->lext_byte = 0xff; } static void diff --git a/src/avrftdi_private.h b/src/avrftdi_private.h index 3c965ed8..15b9caec 100644 --- a/src/avrftdi_private.h +++ b/src/avrftdi_private.h @@ -81,6 +81,8 @@ typedef struct avrftdi_s { int tx_buffer_size; /* use bitbanging instead of mpsse spi */ bool use_bitbanging; + /* bits 16-23 of extended 24-bit word flash address for parts with flash > 128k */ + uint8_t lext_byte; } avrftdi_t; void avrftdi_log(int level, const char * func, int line, const char * fmt, ...); From b167e88422e769db93de12c1e8d820569fdb3fdd Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 19 Jun 2022 10:53:07 +0200 Subject: [PATCH 46/65] Reduce programmer description string length to less than 80 characters. #941 related --- src/avrdude.conf.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/avrdude.conf.in b/src/avrdude.conf.in index 362b6167..ba7f4f8e 100644 --- a/src/avrdude.conf.in +++ b/src/avrdude.conf.in @@ -947,9 +947,10 @@ programmer ; # commercial version of USBtiny, using a separate VID/PID +# https://github.com/IowaScaledEngineering/ckt-avrprogrammer programmer id = "iseavrprog"; - desc = "USBtiny-based USB programmer, https://github.com/IowaScaledEngineering/ckt-avrprogrammer"; + desc = "USBtiny-based programmer, https://iascaled.com"; type = "usbtiny"; connection_type = usb; usbvid = 0x1209; From 37026cad52f1952732b0807974149db5280cde82 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 19 Jun 2022 19:56:56 +0200 Subject: [PATCH 47/65] PR #1000 is done now --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 4638746a..888796ca 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,8 @@ Changes since version 7.0: - Fix .Dd macro in manpage #949 - fix M1 homebrew path #950 - CMake Enhancements #962 + - Reduce programmer desc string length in avrdude.conf + to < 80 characters #1000 * Internals: From 963a1e54afee8f828e2b3f36ace79f1d55f6a5b0 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sun, 29 May 2022 13:12:50 +0200 Subject: [PATCH 48/65] Fix JTAG transaction close issue Fixes issue #366 --- src/jtagmkII.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtagmkII.c b/src/jtagmkII.c index fc06301c..b1024b53 100644 --- a/src/jtagmkII.c +++ b/src/jtagmkII.c @@ -1840,8 +1840,8 @@ void jtagmkII_close(PROGRAMMER * pgm) avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close()\n", progname); - if (pgm->flag & PGM_FL_IS_PDI) { - /* When in PDI mode, restart target. */ + if (pgm->flag & (PGM_FL_IS_PDI | PGM_FL_IS_JTAG)) { + /* When in PDI or JTAG mode, restart target. */ buf[0] = CMND_GO; avrdude_message(MSG_NOTICE2, "%s: jtagmkII_close(): Sending GO command: ", progname); From 8bd39157c199508c0d3f61b62d159d0ba271387c Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 26 Jun 2022 22:58:25 +0200 Subject: [PATCH 49/65] Closing PR 979 --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 888796ca..16fef572 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ Changes since version 7.0: - Fix micronucleus bootloader to check for unresponsive USB devices #945 - Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972 + - [bug #43898] atmega644p remains stopped after JTAG transaction #366 * Pull requests: @@ -26,6 +27,7 @@ Changes since version 7.0: - CMake Enhancements #962 - Reduce programmer desc string length in avrdude.conf to < 80 characters #1000 + - Dragon JTAG fix #979 * Internals: From 134509cc6fcee6c595f7ccaed21956c251647fcb Mon Sep 17 00:00:00 2001 From: prchal Date: Tue, 7 Jun 2022 11:50:03 +0200 Subject: [PATCH 50/65] adding support for all Linux baud rates v.2 If optiboot can work at higher bauds, why not avrdude. Versoin 2 of #985. Linux uses the old-style bitmapped version of the Bxxxx macros. --- src/ser_posix.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ser_posix.c b/src/ser_posix.c index 2c5d45b5..53d8cd15 100644 --- a/src/ser_posix.c +++ b/src/ser_posix.c @@ -76,6 +76,45 @@ static struct baud_mapping baud_lookup_table [] = { #endif #ifdef B230400 { 230400, B230400 }, +#endif +#ifdef B250000 + { 250000, B250000 }, +#endif +#ifdef B460800 + { 460800, B460800 }, +#endif +#ifdef B500000 + { 500000, B500000 }, +#endif +#ifdef B576000 + { 576000, B576000 }, +#endif +#ifdef B921600 + { 921600, B921600 }, +#endif +#ifdef B1000000 + { 1000000, B1000000 }, +#endif +#ifdef B1152000 + { 1152000, B1152000 }, +#endif +#ifdef B1500000 + { 1500000, B1500000 }, +#endif +#ifdef B2000000 + { 2000000, B2000000 }, +#endif +#ifdef B2500000 + { 2500000, B2500000 }, +#endif +#ifdef B3000000 + { 3000000, B3000000 }, +#endif +#ifdef B3500000 + { 3500000, B3500000 }, +#endif +#ifdef B4000000 + { 4000000, B4000000 }, #endif { 0, 0 } /* Terminator. */ }; From ad2be990b762e92872e16d969634e252434ff71f Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 26 Jun 2022 23:00:32 +0200 Subject: [PATCH 51/65] PR 993 done --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 16fef572..da4e42d0 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ Changes since version 7.0: - Reduce programmer desc string length in avrdude.conf to < 80 characters #1000 - Dragon JTAG fix #979 + - adding support for all Linux baud rates v.2 #993 * Internals: From ef785a617ac9a79f4f438fdb87500855f2a2a9a8 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Fri, 29 Apr 2022 00:37:28 +0100 Subject: [PATCH 52/65] Treat x bits in .conf SPI commands as 0 --- src/avrpart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/avrpart.c b/src/avrpart.c index dc6def44..fdff0f78 100644 --- a/src/avrpart.c +++ b/src/avrpart.c @@ -82,11 +82,11 @@ int avr_set_bits(OPCODE * op, unsigned char * cmd) unsigned char mask; for (i=0; i<32; i++) { - if (op->bit[i].type == AVR_CMDBIT_VALUE) { + if (op->bit[i].type == AVR_CMDBIT_VALUE || op->bit[i].type == AVR_CMDBIT_IGNORE) { j = 3 - i / 8; bit = i % 8; mask = 1 << bit; - if (op->bit[i].value) + if (op->bit[i].value && op->bit[i].type == AVR_CMDBIT_VALUE) cmd[j] = cmd[j] | mask; else cmd[j] = cmd[j] & ~mask; From 8953967fc38fc3785e4cb9eb7cf3354ebf5b8a83 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 15 Jun 2022 23:32:22 +0200 Subject: [PATCH 53/65] Replace internal knowledge in jtag3.c by a public API In certain situations (CRC failure, device locked), that JTAG3 read functions need to return an indication to the caller that it is OK to proceed, and allow erasing the device anyway. Historically, the JTAG3 code passed the respective protocol errors directly (and unexplained) up to the caller, leaving the decision to the caller how to handle the situation. Replace that by a more common return value API. New code should prefer this API instead of any hardcoded return values. --- src/avr.c | 12 ++++++------ src/jtag3.c | 31 +++++++++++++++++++++---------- src/jtag3_private.h | 1 + src/libavrdude.h | 10 ++++++++++ src/main.c | 5 ++--- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/avr.c b/src/avr.c index d6e78bb5..a8945d86 100644 --- a/src/avr.c +++ b/src/avr.c @@ -439,16 +439,16 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, (vmem->tags[i] & TAG_ALLOCATED) != 0) { rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i); - if (rc != 0) { + if (rc != LIBAVRDUDE_SUCCESS) { avrdude_message(MSG_INFO, "avr_read(): error reading address 0x%04lx\n", i); - if (rc == -1) { + if (rc == LIBAVRDUDE_GENERAL_FAILURE) { avrdude_message(MSG_INFO, " read operation not supported for memory \"%s\"\n", memtype); - return -2; + return LIBAVRDUDE_NOTSUPPORTED; } avrdude_message(MSG_INFO, " read operation failed for memory \"%s\"\n", memtype); - return rc; + return LIBAVRDUDE_SOFTFAIL; } } report_progress(i, mem->size, NULL); @@ -1035,14 +1035,14 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p) report_progress (0,1,"Reading"); rc = avr_read(pgm, p, "signature", 0); - if (rc < 0) { + if (rc < LIBAVRDUDE_SUCCESS) { avrdude_message(MSG_INFO, "%s: error reading signature data for part \"%s\", rc=%d\n", progname, p->desc, rc); return rc; } report_progress (1,1,NULL); - return 0; + return LIBAVRDUDE_SUCCESS; } static uint8_t get_fuse_bitmask(AVRMEM * m) { diff --git a/src/jtag3.c b/src/jtag3.c index 6d358dfa..23df86ff 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -313,6 +313,16 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len) } } +static int jtag3_errcode(int status) +{ + if (status >= LIBAVRDUDE_SUCCESS) + return status; + if (status == RSP3_FAIL_OCD_LOCKED || + status == RSP3_FAIL_CRC_FAILURE) + return LIBAVRDUDE_SOFTFAIL; + return LIBAVRDUDE_GENERAL_FAILURE; +} + static void jtag3_prevent(PROGRAMMER * pgm, unsigned char * data, size_t len) { int i; @@ -850,7 +860,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { putc('\n', stderr); avrdude_message(MSG_NOTICE2, "%s: %s command: timeout/error communicating with programmer (status %d)\n", progname, descr, status); - return -1; + return LIBAVRDUDE_GENERAL_FAILURE; } else if (verbose >= 3) { putc('\n', stderr); jtag3_prmsg(pgm, *resp, status); @@ -871,10 +881,11 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { status = (*resp)[3]; free(*resp); resp = 0; - return -status; + + return jtag3_errcode(status); } - return status; + return LIBAVRDUDE_SUCCESS; } @@ -987,10 +998,10 @@ static int jtag3_program_enable(PROGRAMMER * pgm) free(resp); PDATA(pgm)->prog_enabled = 1; - return 0; + return LIBAVRDUDE_SUCCESS; } - return status; + return jtag3_errcode(status); } static int jtag3_program_disable(PROGRAMMER * pgm) @@ -1921,7 +1932,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (!(pgm->flag & PGM_FL_IS_DW)) if ((status = jtag3_program_enable(pgm)) < 0) - return status; + return jtag3_errcode(status); cmd[0] = SCOPE_AVR; cmd[1] = CMD3_READ_MEMORY; @@ -2007,7 +2018,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (addr == 0) { if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return status; + return jtag3_errcode(status); signature_cache[0] = resp[4]; signature_cache[1] = resp[5]; @@ -2057,7 +2068,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, } if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return status; + return jtag3_errcode(status); if (resp[1] != RSP3_DATA || status < (pagesize? pagesize: 1) + 4) { @@ -2185,7 +2196,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, cmd[13] = data; if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0) - return status; + return jtag3_errcode(status); free(resp); @@ -2316,7 +2327,7 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib) u32_to_b4(cmd + 8, AVR_SIBLEN); if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0) - return status; + return jtag3_errcode(status); memcpy(sib, resp+3, AVR_SIBLEN); sib[AVR_SIBLEN] = 0; // Zero terminate string diff --git a/src/jtag3_private.h b/src/jtag3_private.h index a3e7fb08..6385aa4c 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -145,6 +145,7 @@ # define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */ # define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */ # define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */ +# define RSP3_FAIL_CRC_FAILURE 0x47 /* CRC failure in device */ # define RSP3_FAIL_NOT_UNDERSTOOD 0x91 /* ICE events */ diff --git a/src/libavrdude.h b/src/libavrdude.h index ddb72b48..46789f4f 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -27,6 +27,16 @@ #include typedef uint32_t pinmask_t; +/* + * Values returned by library functions. + * Some library functions also return a count, i.e. a positive + * number greater than 0. + */ +#define LIBAVRDUDE_SUCCESS 0 +#define LIBAVRDUDE_GENERAL_FAILURE (-1) +#define LIBAVRDUDE_NOTSUPPORTED (-2) // operation not supported +#define LIBAVRDUDE_SOFTFAIL (-3) // returned by avr_signature() if caller + // might proceed with chip erase /* formerly lists.h */ diff --git a/src/main.c b/src/main.c index 253c6e51..5b0a6e38 100644 --- a/src/main.c +++ b/src/main.c @@ -1116,9 +1116,8 @@ int main(int argc, char * argv []) usleep(waittime); if (init_ok) { rc = avr_signature(pgm, p); - if (rc != 0) { - // -68 == -(0x44) == -(RSP3_FAIL_OCD_LOCKED) - if ((rc == -68) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) { + if (rc != LIBAVRDUDE_SUCCESS) { + if ((rc == LIBAVRDUDE_SOFTFAIL) && (p->flags & AVRPART_HAS_UPDI) && (attempt < 1)) { attempt++; if (pgm->read_sib) { // Read SIB and compare FamilyID From f22b81c00e81604596cab1ab57c89b526c9d92bc Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 22 Jun 2022 23:33:53 +0200 Subject: [PATCH 54/65] Fix a number of logic errors in the previous commits RSP3_FAIL_CRC_FAILURE is 0x43 rather than 0x47. jtag3_errcode() must only be applied to a reason code, not to any general status code. --- src/jtag3.c | 32 +++++++++++++++----------------- src/jtag3_private.h | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/jtag3.c b/src/jtag3.c index 23df86ff..4c159ee8 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -313,12 +313,10 @@ static void jtag3_prmsg(PROGRAMMER * pgm, unsigned char * data, size_t len) } } -static int jtag3_errcode(int status) +static int jtag3_errcode(int reason) { - if (status >= LIBAVRDUDE_SUCCESS) - return status; - if (status == RSP3_FAIL_OCD_LOCKED || - status == RSP3_FAIL_CRC_FAILURE) + if (reason == RSP3_FAIL_OCD_LOCKED || + reason == RSP3_FAIL_CRC_FAILURE) return LIBAVRDUDE_SOFTFAIL; return LIBAVRDUDE_GENERAL_FAILURE; } @@ -844,7 +842,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { } } - int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, +int jtag3_command(PROGRAMMER *pgm, unsigned char *cmd, unsigned int cmdlen, unsigned char **resp, const char *descr) { int status; @@ -868,9 +866,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { avrdude_message(MSG_NOTICE2, "0x%02x (%d bytes msg)\n", (*resp)[1], status); } - c = (*resp)[1]; - if ((c & RSP3_STATUS_MASK) != RSP3_OK) { - if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED)) { + c = (*resp)[1] & RSP3_STATUS_MASK; + if (c != RSP3_OK) { + if ((c == RSP3_FAILED) && ((*resp)[3] == RSP3_FAIL_OCD_LOCKED || + (*resp)[3] == RSP3_FAIL_CRC_FAILURE)) { avrdude_message(MSG_INFO, "%s: Device is locked! Chip erase required to unlock.\n", progname); @@ -881,11 +880,10 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) { status = (*resp)[3]; free(*resp); resp = 0; - return jtag3_errcode(status); } - return LIBAVRDUDE_SUCCESS; + return status; } @@ -1001,7 +999,7 @@ static int jtag3_program_enable(PROGRAMMER * pgm) return LIBAVRDUDE_SUCCESS; } - return jtag3_errcode(status); + return status; } static int jtag3_program_disable(PROGRAMMER * pgm) @@ -1932,7 +1930,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (!(pgm->flag & PGM_FL_IS_DW)) if ((status = jtag3_program_enable(pgm)) < 0) - return jtag3_errcode(status); + return status; cmd[0] = SCOPE_AVR; cmd[1] = CMD3_READ_MEMORY; @@ -2018,7 +2016,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (addr == 0) { if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return jtag3_errcode(status); + return status; signature_cache[0] = resp[4]; signature_cache[1] = resp[5]; @@ -2068,7 +2066,7 @@ static int jtag3_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, } if ((status = jtag3_command(pgm, cmd, 12, &resp, "read memory")) < 0) - return jtag3_errcode(status); + return status; if (resp[1] != RSP3_DATA || status < (pagesize? pagesize: 1) + 4) { @@ -2196,7 +2194,7 @@ static int jtag3_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, cmd[13] = data; if ((status = jtag3_command(pgm, cmd, 14, &resp, "write memory")) < 0) - return jtag3_errcode(status); + return status; free(resp); @@ -2327,7 +2325,7 @@ int jtag3_read_sib(PROGRAMMER * pgm, AVRPART * p, char * sib) u32_to_b4(cmd + 8, AVR_SIBLEN); if ((status = jtag3_command(pgm, cmd, 12, &resp, "read SIB")) < 0) - return jtag3_errcode(status); + return status; memcpy(sib, resp+3, AVR_SIBLEN); sib[AVR_SIBLEN] = 0; // Zero terminate string diff --git a/src/jtag3_private.h b/src/jtag3_private.h index 6385aa4c..7d0cbb74 100644 --- a/src/jtag3_private.h +++ b/src/jtag3_private.h @@ -144,8 +144,8 @@ # define RSP3_FAIL_WRONG_MODE 0x32 /* progmode vs. non-prog */ # define RSP3_FAIL_UNSUPP_MEMORY 0x34 /* unsupported memory type */ # define RSP3_FAIL_WRONG_LENGTH 0x35 /* wrong lenth for mem access */ +# define RSP3_FAIL_CRC_FAILURE 0x43 /* CRC failure in device */ # define RSP3_FAIL_OCD_LOCKED 0x44 /* device is locked */ -# define RSP3_FAIL_CRC_FAILURE 0x47 /* CRC failure in device */ # define RSP3_FAIL_NOT_UNDERSTOOD 0x91 /* ICE events */ From d2bb964fc74e7703a25a2256d0bf6cb0992eb4f6 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Sat, 25 Jun 2022 11:39:16 +0200 Subject: [PATCH 55/65] Attempt to fix EEPROM write issue #1009 --- src/jtag3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag3.c b/src/jtag3.c index 4c159ee8..6a4004f3 100644 --- a/src/jtag3.c +++ b/src/jtag3.c @@ -1770,7 +1770,7 @@ static int jtag3_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, free(cmd); return n_bytes; } - cmd[3] = ( p->flags & AVRPART_HAS_PDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE; + cmd[3] = ( p->flags & AVRPART_HAS_PDI || p->flags & AVRPART_HAS_UPDI ) ? MTYPE_EEPROM_XMEGA : MTYPE_EEPROM_PAGE; PDATA(pgm)->eeprom_pageaddr = (unsigned long)-1L; } else if (strcmp(m->desc, "usersig") == 0 || strcmp(m->desc, "userrow") == 0) { From bdab12d8fbdf0bc674c81edac5e34b1b9d3f7c05 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 28 Jun 2022 22:53:24 +0200 Subject: [PATCH 56/65] PR 996 and 1013 done --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index da4e42d0..d5ce1df4 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ Changes since version 7.0: to < 80 characters #1000 - Dragon JTAG fix #979 - adding support for all Linux baud rates v.2 #993 + - Replace internal knowledge in jtag3.c by a public API #996 + - JTAG3 UPDI EEPROM fix #1013 * Internals: From 2827c2695ee938735d10ea2d34c8ad69642df14b Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 28 Jun 2022 22:46:06 +0100 Subject: [PATCH 57/65] Update NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index d5ce1df4..e78362b3 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ Changes since version 7.0: - adding support for all Linux baud rates v.2 #993 - Replace internal knowledge in jtag3.c by a public API #996 - JTAG3 UPDI EEPROM fix #1013 + - Treat x bits in .conf SPI commands as 0 #943 * Internals: From 237cb6321116ab30f02984148758a9db633ce07e Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Mon, 4 Jul 2022 12:25:50 +0100 Subject: [PATCH 58/65] Steamline avrftdi support for ATmega2560 et al --- src/avrftdi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/avrftdi.c b/src/avrftdi.c index c6d2f86e..54490dc0 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -917,6 +917,10 @@ static int avrftdi_chip_erase(PROGRAMMER * pgm, AVRPART * p) static int avrftdi_lext(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int address) { + /* nothing to do if load extended address command unavailable */ + if(m->op[AVR_OP_LOAD_EXT_ADDR] == NULL) + return 0; + avrftdi_t *pdata = to_pdata(pgm); unsigned char buf[] = { 0x00, 0x00, 0x00, 0x00 }; @@ -1019,7 +1023,7 @@ static int avrftdi_flash_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, page_size = m->page_size; /* on large-flash devices > 128k issue extended address command when needed */ - if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, addr/2) < 0) + if(avrftdi_lext(pgm, p, m, addr/2) < 0) return -1; /* prepare the command stream for the whole page */ @@ -1102,7 +1106,6 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, { OPCODE * readop; int byte, word; - unsigned int address = addr/2; unsigned int buf_size = 4 * len + 4; unsigned char* o_buf = alloca(buf_size); @@ -1122,7 +1125,7 @@ static int avrftdi_flash_read(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return -1; } - if(m->op[AVR_OP_LOAD_EXT_ADDR] && avrftdi_lext(pgm, p, m, address) < 0) + if(avrftdi_lext(pgm, p, m, addr/2) < 0) return -1; /* word addressing! */ From a721e485cb873c1ef38bbe756c85cc012d412327 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Mon, 4 Jul 2022 23:04:36 +0100 Subject: [PATCH 59/65] Refactor paged read/write routines in ft245r.c --- src/ft245r.c | 326 +++++++++++++++++++++++---------------------------- 1 file changed, 149 insertions(+), 177 deletions(-) diff --git a/src/ft245r.c b/src/ft245r.c index d5af4ca9..4525cab1 100644 --- a/src/ft245r.c +++ b/src/ft245r.c @@ -107,10 +107,10 @@ void ft245r_initpgm(PROGRAMMER * pgm) { #else -#define FT245R_CYCLES 2 -#define FT245R_FRAGMENT_SIZE 512 -#define REQ_OUTSTANDINGS 10 -//#define USE_INLINE_WRITE_PAGE +#define FT245R_CYCLES 2 +#define FT245R_CMD_SIZE (4 * 8*FT245R_CYCLES) +#define FT245R_FRAGMENT_SIZE (8 * FT245R_CMD_SIZE) +#define REQ_OUTSTANDINGS 10 #define FT245R_DEBUG 0 /* @@ -992,40 +992,18 @@ static void ft245r_display(PROGRAMMER * pgm, const char * p) { pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS); } -static int ft245r_paged_write_gen(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, unsigned int addr, - unsigned int n_bytes) { - unsigned long i, pa; - int rc; - for (i=0; ibuf[addr]); - if (rc != 0) { +static int ft245r_paged_write_gen(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { + + for(int i=0; i < (int) n_bytes; i++, addr++) + if(avr_write_byte_default(pgm, p, m, addr, m->buf[addr]) != 0) return -2; - } - if (m->paged) { - // Can this piece of code ever be activated?? Do AVRs exist that - // have paged non-flash memories? -- REW - // XXX Untested code below. - /* - * check to see if it is time to flush the page with a page - * write - */ - - if (((addr % m->page_size) == m->page_size-1) || (i == n_bytes-1)) { - pa = addr - (addr % m->page_size); - - rc = avr_write_page(pgm, p, m, pa); - if (rc != 0) { - return -2; - } - } - } - } - return i; + return n_bytes; } + static struct ft245r_request { int addr; int bytes; @@ -1081,178 +1059,172 @@ static int do_request(PROGRAMMER * pgm, AVRMEM *m) { return 1; } -static int ft245r_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - int page_size, int addr, int n_bytes) { - unsigned int i,j; - int addr_save,buf_pos,do_page_write,req_count; - unsigned char buf[FT245R_FRAGMENT_SIZE+1+128]; - req_count = 0; - for (i=0; i> 9) & 0xff ); - buf_pos += set_data(pgm, buf+buf_pos, (addr >> 1) & 0xff ); - buf_pos += set_data(pgm, buf+buf_pos, m->buf[addr]); - addr ++; - i++; - if ( (m->paged) && - (((i % m->page_size) == 0) || (i == n_bytes))) { - do_page_write = 1; - break; - } - } -#if defined(USE_INLINE_WRITE_PAGE) - if (do_page_write) { - int addr_wk = addr_save - (addr_save % m->page_size); - /* If this device has a "load extended address" command, issue it. */ - if (m->op[AVR_OP_LOAD_EXT_ADDR]) { - unsigned char cmd[4]; - OPCODE *lext = m->op[AVR_OP_LOAD_EXT_ADDR]; +static int ft245r_paged_write_flash(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { - memset(cmd, 0, 4); - avr_set_bits(lext, cmd); - avr_set_addr(lext, cmd, addr_wk/2); - buf_pos += set_data(pgm, buf+buf_pos, cmd[0]); - buf_pos += set_data(pgm, buf+buf_pos, cmd[1]); - buf_pos += set_data(pgm, buf+buf_pos, cmd[2]); - buf_pos += set_data(pgm, buf+buf_pos, cmd[3]); + int i, j, addr_save, buf_pos, req_count, do_page_write; + unsigned char buf[FT245R_FRAGMENT_SIZE+1]; + unsigned char cmd[4]; + + if(m->op[AVR_OP_LOADPAGE_LO] == NULL || m->op[AVR_OP_LOADPAGE_HI] == NULL) { + avrdude_message(MSG_INFO, "AVR_OP_LOADPAGE_HI/LO command not defined for %s\n", p->desc); + return -1; + } + + do_page_write = req_count = i = j = buf_pos = 0; + addr_save = addr; + while(i < (int) n_bytes) { + int spi = addr&1? AVR_OP_LOADPAGE_HI: AVR_OP_LOADPAGE_LO; + + // put the SPI loadpage command as FT245R_CMD_SIZE bytes into buffer + memset(cmd, 0, sizeof cmd); + avr_set_bits(m->op[spi], cmd); + avr_set_addr(m->op[spi], cmd, addr/2); + avr_set_input(m->op[spi], cmd, m->buf[addr]); + for(int k=0; kpaged && (i%m->page_size == 0 || i >= (int) n_bytes)) + do_page_write = 1; + + // page boundary, finished or buffer exhausted? queue up requests + if(do_page_write || i >= (int) n_bytes || j >= FT245R_FRAGMENT_SIZE/FT245R_CMD_SIZE) { + if(i >= n_bytes) { + ft245r_out = SET_BITS_0(ft245r_out, pgm, PIN_AVR_SCK, 0); // SCK down + buf[buf_pos++] = ft245r_out; + } else { + // stretch sequence to allow correct readout, see extract_data() + buf[buf_pos] = buf[buf_pos - 1]; + buf_pos++; } - buf_pos += set_data(pgm, buf+buf_pos, 0x4C); /* Issue Page Write */ - buf_pos += set_data(pgm, buf+buf_pos,(addr_wk >> 9) & 0xff); - buf_pos += set_data(pgm, buf+buf_pos,(addr_wk >> 1) & 0xff); - buf_pos += set_data(pgm, buf+buf_pos, 0); - } -#endif - if (i >= n_bytes) { - ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); // sck down - buf[buf_pos++] = ft245r_out; - } - else { - /* stretch sequence to allow correct readout, see extract_data() */ - buf[buf_pos] = buf[buf_pos - 1]; - buf_pos++; - } - ft245r_send(pgm, buf, buf_pos); - put_request(addr_save, buf_pos, 0); - //ft245r_sync(pgm); -#if 0 - avrdude_message(MSG_INFO, "send addr 0x%04x bufsize %d [%02x %02x] page_write %d\n", - addr_save,buf_pos, - extract_data_out(pgm, buf , (0*4 + 3) ), - extract_data_out(pgm, buf , (1*4 + 3) ), - do_page_write); -#endif - req_count++; - if (req_count > REQ_OUTSTANDINGS) - do_request(pgm, m); - if (do_page_write) { -#if defined(USE_INLINE_WRITE_PAGE) - while (do_request(pgm, m)) - ; - ft245r_usleep(pgm, m->max_write_delay); -#else - int addr_wk = addr_save - (addr_save % m->page_size); - int rc; - while (do_request(pgm, m)) - ; - rc = avr_write_page(pgm, p, m, addr_wk); - if (rc != 0) { - return -2; + ft245r_send(pgm, buf, buf_pos); + put_request(addr_save, buf_pos, 0); + + if(++req_count > REQ_OUTSTANDINGS) + do_request(pgm, m); + + if(do_page_write) { + while(do_request(pgm, m)) + continue; + if(avr_write_page(pgm, p, m, addr_save - (addr_save % m->page_size)) != 0) + return -2; + do_page_write = req_count = 0; } -#endif - req_count = 0; + + // reset buffer variables + j = buf_pos = 0; + addr_save = addr; } } - while (do_request(pgm, m)) - ; - return i; + + while(do_request(pgm, m)) + continue; + + return n_bytes; } static int ft245r_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, unsigned int addr, unsigned int n_bytes) { - if (strcmp(m->desc, "flash") == 0) { + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { + + if(!n_bytes) + return 0; + + if(strcmp(m->desc, "flash") == 0) return ft245r_paged_write_flash(pgm, p, m, page_size, addr, n_bytes); - } else if (strcmp(m->desc, "eeprom") == 0) { + + if(strcmp(m->desc, "eeprom") == 0) return ft245r_paged_write_gen(pgm, p, m, page_size, addr, n_bytes); - } else { - return -2; - } + + return -2; } -static int ft245r_paged_load_gen(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, unsigned int addr, - int n_bytes) { - unsigned char rbyte; - unsigned long i; - int rc; +static int ft245r_paged_load_gen(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { - for (i=0; ibuf[i+addr] = rbyte; + + m->buf[addr+i] = rbyte; } + return 0; } -static int ft245r_paged_load_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, unsigned int addr, - unsigned int n_bytes) { - unsigned long i,j,n; - int addr_save,buf_pos; - int req_count = 0; + +static int ft245r_paged_load_flash(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { + + int i, j, addr_save, buf_pos, req_count; unsigned char buf[FT245R_FRAGMENT_SIZE+1]; + unsigned char cmd[4]; - for (i=0; i= n_bytes) break; - buf_pos += set_data(pgm, buf+buf_pos, (addr & 1)?0x28:0x20 ); - buf_pos += set_data(pgm, buf+buf_pos, (addr >> 9) & 0xff ); - buf_pos += set_data(pgm, buf+buf_pos, (addr >> 1) & 0xff ); - buf_pos += set_data(pgm, buf+buf_pos, 0); - addr ++; - i++; - } - if (i >= n_bytes) { - ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); // sck down - buf[buf_pos++] = ft245r_out; - } - else { - /* stretch sequence to allow correct readout, see extract_data() */ - buf[buf_pos] = buf[buf_pos - 1]; - buf_pos++; - } - n = j; - ft245r_send(pgm, buf, buf_pos); - put_request(addr_save, buf_pos, n); - req_count++; - if (req_count > REQ_OUTSTANDINGS) - do_request(pgm, m); - + if(m->op[AVR_OP_READ_LO] == NULL || m->op[AVR_OP_READ_HI] == NULL) { + avrdude_message(MSG_INFO, "AVR_OP_READ_HI/LO command not defined for %s\n", p->desc); + return -1; } - while (do_request(pgm, m)) - ; + + req_count = i = j = buf_pos = 0; + addr_save = addr; + while(i < (int) n_bytes) { + int spi = addr&1? AVR_OP_READ_HI: AVR_OP_READ_LO; + + // put the SPI read command as FT245R_CMD_SIZE bytes into buffer + memset(cmd, 0, sizeof cmd); + avr_set_bits(m->op[spi], cmd); + avr_set_addr(m->op[spi], cmd, addr/2); + for(int k=0; k= (int) n_bytes || j >= FT245R_FRAGMENT_SIZE/FT245R_CMD_SIZE) { + if(i >= (int) n_bytes) { + ft245r_out = SET_BITS_0(ft245r_out, pgm, PIN_AVR_SCK, 0); // SCK down + buf[buf_pos++] = ft245r_out; + } else { + // stretch sequence to allow correct readout, see extract_data() + buf[buf_pos] = buf[buf_pos - 1]; + buf_pos++; + } + ft245r_send(pgm, buf, buf_pos); + put_request(addr_save, buf_pos, j); + + if(++req_count > REQ_OUTSTANDINGS) + do_request(pgm, m); + + // reset buffer variables + j = buf_pos = 0; + addr_save = addr; + } + } + + while(do_request(pgm, m)) + continue; + return 0; } -static int ft245r_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, unsigned int addr, - unsigned int n_bytes) { - if (strcmp(m->desc, "flash") == 0) { +static int ft245r_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { + + if(!n_bytes) + return 0; + + if(strcmp(m->desc, "flash") == 0) return ft245r_paged_load_flash(pgm, p, m, page_size, addr, n_bytes); - } else if (strcmp(m->desc, "eeprom") == 0) { + + if(strcmp(m->desc, "eeprom") == 0) return ft245r_paged_load_gen(pgm, p, m, page_size, addr, n_bytes); - } else { - return -2; - } + + return -2; } void ft245r_initpgm(PROGRAMMER * pgm) { From 7aad03cbcdd762b912f9ef920c2badd2463efabb Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Mon, 4 Jul 2022 23:11:32 +0100 Subject: [PATCH 60/65] Fix paged read for ATmega2560 et al for ft245r.c --- src/ft245r.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ft245r.c b/src/ft245r.c index 4525cab1..874167ac 100644 --- a/src/ft245r.c +++ b/src/ft245r.c @@ -1170,6 +1170,19 @@ static int ft245r_paged_load_flash(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, return -1; } + // always called with addr at page boundary, and n_bytes == m->page_size; + // hence, OK to prepend load extended address command (at most) once + if(m->op[AVR_OP_LOAD_EXT_ADDR]) { + memset(cmd, 0, sizeof cmd); + avr_set_bits(m->op[AVR_OP_LOAD_EXT_ADDR], cmd); + avr_set_addr(m->op[AVR_OP_LOAD_EXT_ADDR], cmd, addr/2); + + buf_pos = 0; + for(int k=0; k Date: Mon, 4 Jul 2022 23:54:02 +0100 Subject: [PATCH 61/65] Adapt whitespace to existing style in avrftdi.c --- src/avrftdi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avrftdi.c b/src/avrftdi.c index 54490dc0..f0c07a6a 100644 --- a/src/avrftdi.c +++ b/src/avrftdi.c @@ -918,7 +918,7 @@ static int avrftdi_lext(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int address) { /* nothing to do if load extended address command unavailable */ - if(m->op[AVR_OP_LOAD_EXT_ADDR] == NULL) + if(m->op[AVR_OP_LOAD_EXT_ADDR] == NULL) return 0; avrftdi_t *pdata = to_pdata(pgm); From 9742c7b97aa78bb0e96435f7c4ac39e627bbd2c4 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 5 Jul 2022 00:55:58 +0100 Subject: [PATCH 62/65] Add #474 and #976 to NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index e78362b3..78f59f95 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,8 @@ Changes since version 7.0: - Replace internal knowledge in jtag3.c by a public API #996 - JTAG3 UPDI EEPROM fix #1013 - Treat x bits in .conf SPI commands as 0 #943 + - Fix avrftdi support for ATmega2560 et al #474 + - Fix avrdude.conf timings for ATmega328PB and other parts #976 * Internals: From d3b22fa3c620c0f8dad856214b4a5cccd0c3baff Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 5 Jul 2022 00:57:40 +0100 Subject: [PATCH 63/65] Update debug message in avr.c with correct function name --- src/avr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avr.c b/src/avr.c index a8945d86..7f267622 100644 --- a/src/avr.c +++ b/src/avr.c @@ -234,7 +234,7 @@ int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (readop == NULL) { #if DEBUG - avrdude_message(MSG_INFO, "avr_read_byte(): operation not supported on memory type \"%s\"\n", + avrdude_message(MSG_INFO, "avr_read_byte_default(): operation not supported on memory type \"%s\"\n", mem->desc); #endif return -1; From 64ee4858fd5e4a2ce65cf3c280274674c4320de5 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 5 Jul 2022 01:00:45 +0100 Subject: [PATCH 64/65] Update 2nd debug message in avr.c with correct function name --- src/avr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avr.c b/src/avr.c index 7f267622..17f85f34 100644 --- a/src/avr.c +++ b/src/avr.c @@ -650,7 +650,7 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, if (writeop == NULL) { #if DEBUG - avrdude_message(MSG_INFO, "avr_write_byte(): write not supported for memory type \"%s\"\n", + avrdude_message(MSG_INFO, "avr_write_byte_default(): write not supported for memory type \"%s\"\n", mem->desc); #endif return -1; From ff8f519a34ed4e167be442ca4abeac6f11cccdca Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sun, 10 Jul 2022 23:25:31 +0100 Subject: [PATCH 65/65] Fix PICKit2 ATmega2560 flash paged flash read The paged read in pickit2.c has two errors: - It drops load extended address commands unless a paged read happens at a 64k byte boundary; this is invalid when reading files with holes - It wrongly assumed that flash memory is byte addressed The fix is to carry out a load extended address command, if needed, at the beginning of each paged flash read with the correct word address. Although the pickit2_paged_load() has independent parameters page_size, addr and n_bytes, AVRDUDE only ever calls paged read/write functions with page_size and n_bytes both set to mem->page_size and addr aligned with a page boundary. Therefore, it is sufficient to set the load extended address at the beginning of each page read. --- src/pickit2.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/pickit2.c b/src/pickit2.c index 9e4be94c..ac3781f5 100644 --- a/src/pickit2.c +++ b/src/pickit2.c @@ -491,18 +491,15 @@ static int pickit2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, pgm->pgm_led(pgm, ON); + if (lext) { + memset(cmd, 0, sizeof(cmd)); + avr_set_bits(lext, cmd); + avr_set_addr(lext, cmd, addr/2); + pgm->cmd(pgm, cmd, res); + } + for (addr_base = addr; addr_base < max_addr; ) { - if ((addr_base == 0 || (addr_base % /*ext_address_boundary*/ 65536) == 0) - && lext != NULL) - { - memset(cmd, 0, sizeof(cmd)); - - avr_set_bits(lext, cmd); - avr_set_addr(lext, cmd, addr_base); - pgm->cmd(pgm, cmd, res); - } - // bytes to send in the next packet -- not necessary as pickit2_spi() handles breaking up // the data into packets -- but we need to keep transfers frequent so that we can update the // status indicator bar