From b864d7e73afbaf2a94a4398913e2972a2984bb73 Mon Sep 17 00:00:00 2001
From: Stefan Rueger <stefan.rueger@urclocks.com>
Date: Mon, 17 Oct 2022 16:39:45 +0100
Subject: [PATCH] Update NEWS and resolve minor residual messaging issues

---
 NEWS           | 17 +++++++++++++++--
 src/avr.c      |  7 +++----
 src/avrcache.c |  6 +++---
 src/jtag3.c    |  2 +-
 src/term.c     |  2 +-
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/NEWS b/NEWS
index 0cba791f..85a65c84 100644
--- a/NEWS
+++ b/NEWS
@@ -54,7 +54,10 @@ Changes since version 7.0:
     - Make flash writes work in terminal mode #1020
     - Add support for XMEGA specific AVR109 protocol extensions
       used by XBoot #200
-
+    - jtag2updi can not write EEPROM in terminal mode #1116
+    - Make UPDI programmers less verbose during initialization
+      #1084
+    - Quell mode isn't handled systematically #1114
 
   * Pull requests:
 
@@ -140,8 +143,16 @@ Changes since version 7.0:
     - Provide cached byte-wise read/write API #1106
     - AVR109: support for prodsig read and usersig read/write #1108
     - Add missing AVR variants the original JTAG ICE supports #1109
-    - Improve help message in terminal and provide new command pgerase #1113
+    - Improve help message in terminal and provide new command
+      pgerase #1113
     - Fix pointer truncation for Windows x64 #1119
+    - Fix jtag3_page_erase for targets with UPDI #1112
+    - Fix writing of last word on DWORD TPI parts #1115
+    - Use byte-wise read/write when page size is 1 in terminal
+      cache #1121
+    - Suppress Teensy USB communication error message on reboot #1122
+    - Fix UPDI erase when target is locked #1125
+    - Review and overhaul AVRDUDE's messaging system #1126
 
   * Internals:
 
@@ -150,6 +161,8 @@ Changes since version 7.0:
     - Reviewed API for prgrammer functions: use const for
       programmer functions where useful; add second argument for
       void (*enable)(PROGRAMMER *pgm, const AVRPART *p) #1078
+    - Reviewed messaging system making warnings and errors explicit
+      and treat them systematically
 
 
 Changes in version 7.0:
diff --git a/src/avr.c b/src/avr.c
index 8f27f8c8..553e3ec4 100644
--- a/src/avr.c
+++ b/src/avr.c
@@ -854,10 +854,9 @@ int avr_write_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, int
      * Ensure that we align our write size to this boundary.
      */
     if (m->n_word_writes < 0 || m->n_word_writes > 4 || m->n_word_writes == 3) {
-      avrdude_message(MSG_INFO, "\n%s: ERROR: Unsupported n_word_writes value of %d "
-                      "configured for %s memory\n"
-                      "%sAborting write\n",
-                      progname, m->n_word_writes, m->desc, progbuf);
+      msg_error("\n");
+      pmsg_error("unsupported n_word_writes value of %d for %s memory\n",
+        m->n_word_writes, m->desc);
       return LIBAVRDUDE_GENERAL_FAILURE;
     }
     chunk = m->n_word_writes > 0 ? 2*m->n_word_writes : 2;
diff --git a/src/avrcache.c b/src/avrcache.c
index 88735cb9..c573014b 100644
--- a/src/avrcache.c
+++ b/src/avrcache.c
@@ -222,7 +222,7 @@ static int cacheAddress(int addr, const AVR_Cache *cp, const AVRMEM *mem) {
   int cacheaddr = addr + (int) (mem->offset - cp->offset);
 
   if(cacheaddr < 0 || cacheaddr >= cp->size) { // Should never happen (unless offsets wrong in avrdude.conf)
-    pmsg_error("%s cache address 0x%04x out of range [0, 0x%04x]\n", mem->desc, cacheaddr, cp->size);
+    pmsg_error("%s cache address 0x%04x out of range [0, 0x%04x]\n", mem->desc, cacheaddr, cp->size-1);
     return LIBAVRDUDE_GENERAL_FAILURE;
   }
 
@@ -267,8 +267,8 @@ static int writeCachePage(AVR_Cache *cp, const PROGRAMMER *pgm, const AVRPART *p
            pgm->read_byte(pgm, p, mem, base+i, cp->copy+base+i) < 0) {
           report_progress(1, -1, NULL);
           if(nlOnErr && quell_progress)
-            avrdude_message(MSG_INFO, "\n");
-          avrdude_message(MSG_INFO, "%s: writeCachePage() %s access error at addr 0x%04x\n", progname, mem->desc, base+i);
+            msg_info("\n");
+          pmsg_error("writeCachePage() %s access error at addr 0x%04x\n", mem->desc, base+i);
           return LIBAVRDUDE_GENERAL_FAILURE;
         }
 
diff --git a/src/jtag3.c b/src/jtag3.c
index 8f1d2f5b..e3e39fbe 100644
--- a/src/jtag3.c
+++ b/src/jtag3.c
@@ -1628,7 +1628,7 @@ static int jtag3_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRME
   pmsg_notice2("jtag3_page_erase(.., %s, 0x%x)\n", m->desc, addr);
 
   if (!(p->prog_modes & (PM_PDI | PM_UPDI))) {
-    avrdude_message(MSG_INFO, "%s: jtag3_page_erase: not supported\n", progname);
+    pmsg_error("page erase not supported\n");
     return -1;
   }
 
diff --git a/src/term.c b/src/term.c
index 25f95f53..321722f7 100644
--- a/src/term.c
+++ b/src/term.c
@@ -421,7 +421,7 @@ static int cmd_write(PROGRAMMER *pgm, AVRPART *p, int argc, char *argv[]) {
 
   if (addr < 0 || addr >= maxsize) {
     terminal_message(MSG_INFO, "%s (write): %s address 0x%05x is out of range [0, 0x%05x]\n",
-      progname, mem->desc, addr, maxsize);
+      progname, mem->desc, addr, maxsize-1);
     return -1;
   }