Skip to content

Commit c7cb2fc

Browse files
Clean upload.py, make platform use write_flash
Make upload.py more concise and pythonic. Use the "write_flash" argument in platform.txt for uploads instead of assuming anything that is a file is the bin to upload.
1 parent 0c019c4 commit c7cb2fc

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ tools.esptool.upload.params.quiet=
149149
# First, potentially perform an erase or nothing
150150
# Next, do the binary upload
151151
# Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern
152-
tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" {upload.erase_cmd} {upload.resetmethod} "{build.path}/{build.project_name}.bin"
152+
tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" {upload.erase_cmd} {upload.resetmethod} write_flash 0x0 "{build.path}/{build.project_name}.bin"
153153

154154
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"
155155

tools/upload.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,16 @@
3939
# https://github.com/esp8266/Arduino/issues/6755#issuecomment-553208688
4040
if thisarg == "erase_flash":
4141
write_option = '--erase-all'
42-
thisarg = ''
43-
44-
if thisarg == 'erase_region':
42+
elif thisarg == 'erase_region':
4543
erase_addr = sys.argv.pop(0)
4644
erase_len = sys.argv.pop(0)
47-
thisarg = ''
48-
49-
# Backwards compatibility with fs upload tools, eat --end
50-
if thisarg == '--end':
51-
thisarg = ''
52-
53-
# Backwards compatibility with fs upload tools, parse write_flash for later use
54-
if thisarg == 'write_flash':
45+
elif thisarg == '--end':
46+
# Backwards compatibility with fs upload tools, eat --end
47+
pass
48+
elif thisarg == 'write_flash':
5549
write_addr = sys.argv.pop(0)
5650
binary = sys.argv.pop(0)
57-
thisarg = ''
58-
59-
if os.path.isfile(thisarg):
60-
binary = thisarg
61-
thisarg = ''
62-
63-
if len(thisarg):
51+
elif len(thisarg):
6452
cmdline = cmdline + [thisarg]
6553

6654
cmdline = cmdline + ['write_flash']
@@ -70,7 +58,7 @@
7058

7159
erase_file = ''
7260
if len(erase_addr):
73-
# generate temporary empty (0xff) file
61+
# Generate temporary empty (0xff) file
7462
eraser = tempfile.mkstemp()
7563
erase_file = eraser[1]
7664
os.write(eraser[0], bytearray([255] * int(erase_len, 0)))

0 commit comments

Comments
 (0)