From bdbd88b3c4756036c585a43aa6d640faee166caa Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 20 Feb 2019 14:19:56 -0800 Subject: [PATCH 1/2] Point to proper uploaded python repackage w/subdir Fixes problem of python files expanding in tools/ dir and not in tools/python. --- package/package_esp8266com_index.template.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json index 1a35e90de3..132f34019d 100644 --- a/package/package_esp8266com_index.template.json +++ b/package/package_esp8266com_index.template.json @@ -137,17 +137,17 @@ "systems": [ { "host": "x86_64-mingw32", - "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32.zip", - "archiveFileName": "python-3.7.2.post1-embed-win32.zip", - "checksum": "SHA-256:8136937ac00c28549893d1241011054a0e90517e0a193c2986323fa9f6501ed9", - "size": "6612720" + "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32v2.zip", + "archiveFileName": "python-3.7.2.post1-embed-win32v2.zip", + "checksum": "SHA-256:26665d2925ee75118bb7d8620e9ee988adc2ca3e660a9f4c06a09a06c94c0c29", + "size": "6431781" }, { "host": "i686-mingw32", - "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32.zip", - "archiveFileName": "python-3.7.2.post1-embed-win32.zip", - "checksum": "SHA-256:8136937ac00c28549893d1241011054a0e90517e0a193c2986323fa9f6501ed9", - "size": "6612720" + "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32v2.zip", + "archiveFileName": "python-3.7.2.post1-embed-win32v2.zip", + "checksum": "SHA-256:26665d2925ee75118bb7d8620e9ee988adc2ca3e660a9f4c06a09a06c94c0c29", + "size": "6431781" } ] }, From 7a42940ae8ab79a0599548af443b27204e0bc169 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Thu, 21 Feb 2019 09:22:13 -0800 Subject: [PATCH 2/2] Use Pythonic way of calling esptool, avoid fork Simply import the pyserial and esptool modules directly into upload.py instead of trying to fake things with os.fork()s. Reduces code and is more pythonic. --- platform.txt | 3 +-- tools/upload.py | 18 +++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/platform.txt b/platform.txt index fda38b8c55..1ad902425f 100644 --- a/platform.txt +++ b/platform.txt @@ -137,8 +137,7 @@ tools.esptool.upload.params.quiet= # First, potentially perform an erase or nothing # Next, do the binary upload # Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern -tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" "{runtime.platform.path}/tools/pyserial" "{runtime.platform.path}/tools/esptool/esptool.py" --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" {upload.erase_cmd} --end --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" write_flash 0x0 "{build.path}/{build.project_name}.bin" --end - +tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" "{runtime.platform.path}/tools/pyserial" "{runtime.platform.path}/tools/esptool" --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" {upload.erase_cmd} --end --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" write_flash 0x0 "{build.path}/{build.project_name}.bin" --end tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin" diff --git a/tools/upload.py b/tools/upload.py index 0897c5be0a..d2ec57f3b3 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -3,17 +3,16 @@ # Wrapper for Arduino core / others that can call esptool.py possibly multiple times # Adds pyserial to sys.path automatically based on the path of the current file -# First patameter is pyserial path, then a series of command arguments separated with --end -# i.e. upload.py tools/pyserial tools/esptool/esptool.py erase_flash --end write_flash file 0x0 --end +# First parameter is pyserial path, second is esptool path, then a series of command arguments separated with --end +# i.e. upload.py tools/pyserial tools/esptool erase_flash --end write_flash file 0x0 --end -import inspect -import os import sys sys.argv.pop(0) # Remove executable name try: sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add pyserial dir to search path, in UNIX format - esptool = sys.argv.pop(0).replace('\\', '/') # Full path to esptool.py, in UNIX format + sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add esptool dir to search path, in UNIX format + import esptool # If this fails, we can't continue and will bomb below except: sys.stderr.write("Error in command line, need pyserial path as 1st arg and esptool path as 2nd.\n") sys.exit(1) @@ -21,14 +20,7 @@ fakeargs = []; while len(sys.argv): if sys.argv[0] == '--end': - pid = os.fork() - if pid == 0: - sys.argv = ['esptool.py'] + fakeargs - sys.stderr.write("Running: " + " ".join(sys.argv) + "\n") - exec(open(esptool).read()) - sys.exit(0) - else: - os.waitpid(pid, 0) + esptool.main(fakeargs) sys.argv.pop(0) # Remove --end fakeargs = [] else: