chore: updated esp32.py

Source: https://raw.githubusercontent.com/letscontrolit/ESPEasy/mega/tools/pio/post_esp32.py
This commit is contained in:
Yurii
2025-08-04 07:07:31 +03:00
parent 062468c6b1
commit 3e6a2d93d4

View File

@@ -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)