Skip to content

Update upload.py #6781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions tools/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,70 @@
sys.stderr.write("pyserial or esptool directories not found next to this upload.py tool.\n")
sys.exit(1)

fakeargs = [];
cmdline = []
write_option = ''
erase_addr = ''
erase_len = ''

while len(sys.argv):
thisarg = sys.argv.pop(0)

# We silently replace the 921kbaud setting with 460k to enable backward
# compatibility with the old esptool-ck.exe. Esptool.py doesn't seem
# work reliably at 921k, but is still significantly faster at 460kbaud.
if thisarg == "921600":
thisarg = "460800"

# 'erase_flash' command is translated to the write_flash --erase-all option
# https://github.com/esp8266/Arduino/issues/6755#issuecomment-553208688
if thisarg == "erase_flash":
write_option = '--erase-all'
thisarg = ''

if thisarg == 'erase_region':
erase_addr = sys.argv.pop(0)
erase_len = sys.argv.pop(0)
thisarg = ''

if os.path.isfile(thisarg):
binary = thisarg
thisarg = ''

if len(thisarg):
cmdline = cmdline + [thisarg]

cmdline = cmdline + ['write_flash']
if len(write_option):
cmdline = cmdline + [write_option]
cmdline = cmdline + ['0x0', binary]

erase_file = ''
if len(erase_addr):
# generate temporary empty (0xff) file
eraser = tempfile.mkstemp()
erase_file = eraser[1]
os.write(eraser[0], bytearray([255] * int(erase_len, 0)))
os.close(eraser[0])
cmdline = cmdline + [ erase_addr, erase_file ]

esptool.main(cmdline)

if len(erase_file):
os.remove(erase_file)
if sys.argv[len(sys.argv)-1] == '--end':

while len(sys.argv):
if sys.argv[0] == '--end':
esptool.main(fakeargs)
sys.argv.pop(0) # Remove --end
fakeargs = []
else:
# We silently replace the 921kbaud setting with 460k to enable backward
# compatibility with the old esptool-ck.exe. Esptool.py doesn't seem
# work reliably at 921k, but is still significantly faster at 460kbaud.
thisarg = sys.argv.pop(0)
if thisarg == "921600":
thisarg = "460800"
fakeargs = fakeargs + [thisarg]
else:

while len(sys.argv):
thisarg = sys.argv.pop(0)

# We silently replace the 921kbaud setting with 460k to enable backward
# compatibility with the old esptool-ck.exe. Esptool.py doesn't seem
# work reliably at 921k, but is still significantly faster at 460kbaud.
if thisarg == "921600":
thisarg = "460800"

# 'erase_flash' command is translated to the write_flash --erase-all option
# https://github.com/esp8266/Arduino/issues/6755#issuecomment-553208688
if thisarg == "erase_flash":
write_option = '--erase-all'
thisarg = ''

if thisarg == 'erase_region':
erase_addr = sys.argv.pop(0)
erase_len = sys.argv.pop(0)
thisarg = ''

if os.path.isfile(thisarg):
binary = thisarg
thisarg = ''

if len(thisarg):
cmdline = cmdline + [thisarg]

cmdline = cmdline + ['write_flash']
if len(write_option):
cmdline = cmdline + [write_option]
cmdline = cmdline + ['0x0', binary]

erase_file = ''
if len(erase_addr):
# generate temporary empty (0xff) file
eraser = tempfile.mkstemp()
erase_file = eraser[1]
os.write(eraser[0], bytearray([255] * int(erase_len, 0)))
os.close(eraser[0])
cmdline = cmdline + [ erase_addr, erase_file ]
esptool.main(cmdline)

if len(erase_file):
os.remove(erase_file)