From 5eedc90ee474ef33d3610b125f376e62f0da780e Mon Sep 17 00:00:00 2001 From: gnu-emu <57782560+gnu-emu@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:24:08 +0100 Subject: [PATCH 1/2] Update upload.py --- tools/upload.py | 107 ++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/tools/upload.py b/tools/upload.py index 0f5cb78352..d544e269de 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -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) From e82159e874ff1e73a0f0cb8b4aa1892b758bb6ff Mon Sep 17 00:00:00 2001 From: gnu-emu <57782560+gnu-emu@users.noreply.github.com> Date: Sun, 17 Nov 2019 03:13:45 +0100 Subject: [PATCH 2/2] Add files via upload --- tools/upload.py | 122 +++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/tools/upload.py b/tools/upload.py index d544e269de..3567e0af21 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -20,70 +20,84 @@ 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 = '' +compatibility = False + +arg_counter = len(sys.argv)-1 +while (arg_counter): + if sys.argv[arg_counter] == '--end': + compatibility = True + break + arg_counter -= 1 + + +while len(sys.argv) and not compatibility: + 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] + +if not compatibility: + cmdline = cmdline + ['write_flash'] + +if len(write_option): + cmdline = cmdline + [write_option] -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) +if not compatibility: + 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 ] + +if not compatibility: + #sys.stderr.write("\ncmdline:" + str(cmdline) + "\n") + esptool.main(cmdline) + +while len(sys.argv) and compatibility: + if sys.argv[0] == '--end': + #sys.stderr.write("\ncmdline:" + str(cmdline) + " in compatibility mode\n") + esptool.main(cmdline) + sys.argv.pop(0) # Remove --end + cmdline = [] + 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" + cmdline = cmdline + [thisarg] - # '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 len(erase_file): + os.remove(erase_file)