Skip to content

Commit d61843f

Browse files
authored
Improve ROM ELF file selection process not to crash when none found
Refactor ROM ELF file pattern matching and sorting logic.
1 parent f1f3f70 commit d61843f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

monitor/filter_exception_decoder.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def find_rom_elf(self, chip_name):
143143
The package must be defined as a dependency in platform.json and
144144
will be automatically installed when the platform is installed.
145145
146+
Searches for ROM ELF files with various naming patterns and selects
147+
the one with the lowest revision number for maximum compatibility.
148+
146149
Args:
147150
chip_name: Name of the ESP32 chip variant (e.g., "esp32s3")
148151
@@ -173,23 +176,33 @@ def find_rom_elf(self, chip_name):
173176
)
174177
return None
175178

176-
# Patterns commonly seen: <chip>_rev<rev>_rom.elf, <chip>_rev<rev>.elf, <chip>_rom.elf
179+
# Patterns commonly seen: <chip>_rev<rev>_rom.elf, <chip>_rev<rev>.elf, <chip>*_rom.elf
177180
patterns = [
178181
os.path.join(rom_elfs_dir, f"{chip_name}_rev*_rom.elf"),
179182
os.path.join(rom_elfs_dir, f"{chip_name}_rev*.elf"),
180183
os.path.join(rom_elfs_dir, f"{chip_name}*_rom.elf"),
181184
os.path.join(rom_elfs_dir, f"{chip_name}*.elf"),
182185
]
186+
183187
rom_files = []
184-
for p in patterns:
185-
rom_files.extend(glob.glob(p))
186-
# de-dup
188+
for pattern in patterns:
189+
rom_files.extend(glob.glob(pattern))
190+
191+
# Remove duplicates and sort
187192
rom_files = sorted(set(rom_files))
188193

194+
if not rom_files:
195+
sys.stderr.write(
196+
"%s: No ROM ELF files found for chip %s in %s\n"
197+
% (self.__class__.__name__, chip_name, rom_elfs_dir)
198+
)
199+
return None
200+
189201
# Sort by numeric revision (lowest first) if present; otherwise push to the end
190202
def _rev_key(path):
191203
m = re.search(r"_rev(\d+)", os.path.basename(path))
192204
return int(m.group(1)) if m else 10**9
205+
193206
rom_files.sort(key=_rev_key)
194207
return rom_files[0]
195208

0 commit comments

Comments
 (0)