mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-20 10:24:18 +03:00
Use Pythonic way of calling esptool, avoid fork(#5797)
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.
This commit is contained in:
committed by
GitHub
parent
f08346a73e
commit
472faf73a2
@ -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"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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 @@ except:
|
||||
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:
|
||||
|
Reference in New Issue
Block a user