From fdcfb543fcaa3a8af2d3f2b8da4f6dc6d28cb0fe Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 4 Jan 2023 18:52:51 +0000 Subject: [PATCH 1/2] Improve guessBootloaderStart() for modern AVR --- src/avrcache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/avrcache.c b/src/avrcache.c index c7bfae3a..29f1d437 100644 --- a/src/avrcache.c +++ b/src/avrcache.c @@ -318,6 +318,9 @@ static int guessBootStart(const PROGRAMMER *pgm, const AVRPART *p) { int bootstart = 0; const AVR_Cache *cp = pgm->cp_flash; + if(p->prog_modes & PM_UPDI) // Modern AVRs put the bootloader at 0 + return 0; + if(p->n_boot_sections > 0 && p->boot_section_size > 0) bootstart = cp->size - (p->boot_section_size<<(p->n_boot_sections-1)); From cf648373913696b5f566a086e618d175390bd47f Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 4 Jan 2023 19:04:16 +0000 Subject: [PATCH 2/2] Silence page erase in cache code --- src/avrcache.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/avrcache.c b/src/avrcache.c index 29f1d437..da40c7a7 100644 --- a/src/avrcache.c +++ b/src/avrcache.c @@ -331,6 +331,17 @@ static int guessBootStart(const PROGRAMMER *pgm, const AVRPART *p) { } +// Page erase but without error messages if it does not work +static int silent_page_erase(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m, unsigned int a) { + int bakverb = verbose; + verbose = -123; + int ret = pgm->page_erase? pgm->page_erase(pgm, p, m, a): -1; + verbose = bakverb; + + return ret; +} + + typedef struct { AVRMEM *mem; AVR_Cache *cp; @@ -400,7 +411,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) { } // Probably NOR memory, check out page erase - if(pgm->page_erase && pgm->page_erase(pgm, p, mem, n) >= 0) { + if(silent_page_erase(pgm, p, mem, n) >= 0) { if(writeCachePage(cp, pgm, p, mem, n, 1) < 0) return LIBAVRDUDE_GENERAL_FAILURE; // Worked OK? Can use page erase on this memory @@ -716,7 +727,7 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM if(fallback_write_byte(pgm, p, mem, uaddr, 0xff) < 0) return LIBAVRDUDE_GENERAL_FAILURE; } else { - if(!pgm->page_erase || pgm->page_erase(pgm, p, mem, uaddr) < 0) + if(silent_page_erase(pgm, p, mem, uaddr) < 0) return LIBAVRDUDE_GENERAL_FAILURE; }