diff --git a/tools/esp32.py b/tools/esp32.py index 31e3a70..522d7aa 100644 --- a/tools/esp32.py +++ b/tools/esp32.py @@ -23,21 +23,15 @@ Import("env") platform = env.PioPlatform() import sys +import os +import subprocess from os.path import join -sys.path.append(join(platform.get_package_dir("tool-esptoolpy"))) -import esptool - -def esptool_call(cmd): - try: - esptool.main(cmd) - except SystemExit as e: - # Fetch sys.exit() without leaving the script - if e.code == 0: - return True - else: - print(f"❌ esptool failed with exit code: {e.code}") - return False +def normalize_paths(cmd): + for i, arg in enumerate(cmd): + if isinstance(arg, str) and '/' in arg: + cmd[i] = os.path.normpath(arg) + return cmd def esp32_create_combined_bin(source, target, env): print("Generating combined binary for serial flashing") @@ -77,9 +71,12 @@ def esp32_create_combined_bin(source, target, env): print(f" - {hex(app_offset)} | {firmware_name}") cmd += [hex(app_offset), firmware_name] - print('Using esptool.py arguments: %s' % ' '.join(cmd)) - - esptool_call(cmd) + # print('Using esptool.py arguments: %s' % ' '.join(cmd)) + cmdline = [env.subst("$OBJCOPY")] + normalize_paths(cmd) + print('Command Line: %s' % cmdline) + result = subprocess.run(cmdline, text=True, check=False, stdout=subprocess.DEVNULL) + if result.returncode != 0: + print(f"esptool create firmware failed with exit code: {result.returncode}") env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)