diff --git a/scripts/build.py b/scripts/build.py index 54c0031..7cadd52 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -120,6 +120,22 @@ def build_sample(self) -> dict: return arifacts + def _find_elf_file(self) -> str: + """ + Search for an ELF file in the Zephyr build directory. + + Returns: + str: filename if an ELF exists, otherwise None. + """ + + for root, _, files in os.walk(os.path.dirname(self.temp_dir_path)): + for _file in files: + # zephyr_pre0.elf is always created, skip it + if _file.endswith(".elf") and _file != "zephyr_pre0.elf": + return os.path.join(root, _file) + + return None + def get_artifacts(self) -> dict: """ Retrieves the paths of all existing artifacts in the temporary directory. @@ -134,6 +150,11 @@ def get_artifacts(self) -> dict: if os.path.exists(expanded_path): artifacts[name] = expanded_path + # Platforms may change the default name of the ELF artifact (`esp32s3_devkitm_appcpu`). + if ("elf" not in artifacts) and (candidate := self._find_elf_file()): + print(f"zephyr.elf not found! Trying to use: {candidate}") + artifacts["elf"] = candidate + return artifacts def _copy_original_dts_file(self, dts_original_path: str) -> None: