From 602fab481c32f015d50de641ee88db1c0a16aad6 Mon Sep 17 00:00:00 2001
From: Stefan Rueger <stefan.rueger@urclocks.com>
Date: Wed, 31 Aug 2022 11:59:19 +0100
Subject: [PATCH] Relax uniqueness check of mcuid for parts that might be
 variants

Two parts are considered variants here if one part name starts with the name
of the other, flash memory sizes are the same, flash page sizes are the same
and the number of interrupts are the same.
---
 src/config.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/config.c b/src/config.c
index ebef8f4b..a0351833 100644
--- a/src/config.c
+++ b/src/config.c
@@ -861,11 +861,20 @@ void cfg_update_mcuid(AVRPART *part) {
     }
   }
 
-  // None have the same name: an entry with part->mcuid is an error
+  // None have the same name: an entry with part->mcuid might be an error
   for(int i=0; i < sizeof uP_table/sizeof *uP_table; i++)
     if(part->mcuid == (int) uP_table[i].mcuid) {
-      yywarning("mcuid %d is reserved for %s, use a free number >= %d",
-        part->mcuid, uP_table[i].name, sizeof uP_table/sizeof *uP_table);
+      // Complain unless it can be considered a variant, eg, ATmega32L and ATmega32
+      AVRMEM *flash = avr_locate_mem(part, "flash");
+      if(flash) {
+        size_t l1 = strlen(part->desc), l2 = strlen(uP_table[i].name);
+        if(strncasecmp(part->desc, uP_table[i].name, l1 < l2? l1: l2) ||
+            flash->size != uP_table[i].flashsize ||
+            flash->page_size != uP_table[i].pagesize ||
+            part->n_interrupts != uP_table[i].ninterrupts)
+          yywarning("mcuid %d is reserved for %s, use a free number >= %d",
+            part->mcuid, uP_table[i].name, sizeof uP_table/sizeof *uP_table);
+      }
       return;
     }