Skip to content

Commit 472faf7

Browse files
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.
1 parent f08346a commit 472faf7

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

package/package_esp8266com_index.template.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@
137137
"systems": [
138138
{
139139
"host": "x86_64-mingw32",
140-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32.zip",
141-
"archiveFileName": "python-3.7.2.post1-embed-win32.zip",
142-
"checksum": "SHA-256:8136937ac00c28549893d1241011054a0e90517e0a193c2986323fa9f6501ed9",
143-
"size": "6612720"
140+
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32v2.zip",
141+
"archiveFileName": "python-3.7.2.post1-embed-win32v2.zip",
142+
"checksum": "SHA-256:26665d2925ee75118bb7d8620e9ee988adc2ca3e660a9f4c06a09a06c94c0c29",
143+
"size": "6431781"
144144
},
145145
{
146146
"host": "i686-mingw32",
147-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32.zip",
148-
"archiveFileName": "python-3.7.2.post1-embed-win32.zip",
149-
"checksum": "SHA-256:8136937ac00c28549893d1241011054a0e90517e0a193c2986323fa9f6501ed9",
150-
"size": "6612720"
147+
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-3.7.2.post1-embed-win32v2.zip",
148+
"archiveFileName": "python-3.7.2.post1-embed-win32v2.zip",
149+
"checksum": "SHA-256:26665d2925ee75118bb7d8620e9ee988adc2ca3e660a9f4c06a09a06c94c0c29",
150+
"size": "6431781"
151151
}
152152
]
153153
},

platform.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ tools.esptool.upload.params.quiet=
137137
# First, potentially perform an erase or nothing
138138
# Next, do the binary upload
139139
# Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern
140-
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
141-
140+
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
142141

143142
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"
144143

tools/upload.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,24 @@
33
# Wrapper for Arduino core / others that can call esptool.py possibly multiple times
44
# Adds pyserial to sys.path automatically based on the path of the current file
55

6-
# First patameter is pyserial path, then a series of command arguments separated with --end
7-
# i.e. upload.py tools/pyserial tools/esptool/esptool.py erase_flash --end write_flash file 0x0 --end
6+
# First parameter is pyserial path, second is esptool path, then a series of command arguments separated with --end
7+
# i.e. upload.py tools/pyserial tools/esptool erase_flash --end write_flash file 0x0 --end
88

9-
import inspect
10-
import os
119
import sys
1210

1311
sys.argv.pop(0) # Remove executable name
1412
try:
1513
sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add pyserial dir to search path, in UNIX format
16-
esptool = sys.argv.pop(0).replace('\\', '/') # Full path to esptool.py, in UNIX format
14+
sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add esptool dir to search path, in UNIX format
15+
import esptool # If this fails, we can't continue and will bomb below
1716
except:
1817
sys.stderr.write("Error in command line, need pyserial path as 1st arg and esptool path as 2nd.\n")
1918
sys.exit(1)
2019

2120
fakeargs = [];
2221
while len(sys.argv):
2322
if sys.argv[0] == '--end':
24-
pid = os.fork()
25-
if pid == 0:
26-
sys.argv = ['esptool.py'] + fakeargs
27-
sys.stderr.write("Running: " + " ".join(sys.argv) + "\n")
28-
exec(open(esptool).read())
29-
sys.exit(0)
30-
else:
31-
os.waitpid(pid, 0)
23+
esptool.main(fakeargs)
3224
sys.argv.pop(0) # Remove --end
3325
fakeargs = []
3426
else:

0 commit comments

Comments
 (0)