mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-08 09:04:29 +05:00
chore: updated esp32.py
Source: https://raw.githubusercontent.com/letscontrolit/ESPEasy/mega/tools/pio/post_esp32.py
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user