scripts: twister: fix regenerate serial device with unknown platform

Since BOOT-SERIAL isn't a recognized STMicroelectronics product name,
when Twister saves the new map.yaml, it will also check if the previous
map.yaml had the 'SERIAL-BOOT' product name and attach the corresponding
serial device.It won't generate a new one with an unknown platform name.


Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
This commit is contained in:
Fabrice DJIATSA 2025-04-08 10:46:48 +02:00 committed by Benjamin Cabé
commit cf517f92fc

View file

@ -382,6 +382,9 @@ class HardwareMap:
logger.warning(f"Unsupported device ({d.manufacturer}): {d}")
def save(self, hwm_file):
# list of board ids with boot-serial sequence
boot_ids = []
# use existing map
self.detected = natsorted(self.detected, key=lambda x: x.serial or '')
if os.path.exists(hwm_file):
@ -390,10 +393,13 @@ class HardwareMap:
if hwm:
hwm.sort(key=lambda x: x.get('id', ''))
# disconnect everything
# disconnect everything except boards with boot-serial sequence
for h in hwm:
if h['product'] != 'BOOT-SERIAL' :
h['connected'] = False
h['serial'] = None
else :
boot_ids.append(h['id'])
for _detected in self.detected:
for h in hwm:
@ -418,6 +424,11 @@ class HardwareMap:
else:
hwm = new
#remove duplicated devices with unknown platform names before saving the file
for h in hwm :
if h['id'] in boot_ids and h['platform'] == 'unknown':
hwm.remove(h)
with open(hwm_file, 'w') as yaml_file:
yaml.dump(hwm, yaml_file, Dumper=Dumper, default_flow_style=False)