|
20 | 20 | sys.stderr.write("pyserial or esptool directories not found next to this upload.py tool.\n")
|
21 | 21 | sys.exit(1)
|
22 | 22 |
|
23 |
| -fakeargs = []; |
24 | 23 | cmdline = []
|
25 | 24 | write_option = ''
|
26 | 25 | erase_addr = ''
|
27 | 26 | erase_len = ''
|
| 27 | +compatibility = False |
| 28 | + |
| 29 | +arg_counter = len(sys.argv)-1 |
| 30 | +while (arg_counter): |
| 31 | + if sys.argv[arg_counter] == '--end': |
| 32 | + compatibility = True |
| 33 | + break |
| 34 | + arg_counter -= 1 |
| 35 | + |
| 36 | + |
| 37 | +while len(sys.argv) and not compatibility: |
| 38 | + thisarg = sys.argv.pop(0) |
| 39 | + |
| 40 | + # We silently replace the 921kbaud setting with 460k to enable backward |
| 41 | + # compatibility with the old esptool-ck.exe. Esptool.py doesn't seem |
| 42 | + # work reliably at 921k, but is still significantly faster at 460kbaud. |
| 43 | + if thisarg == "921600": |
| 44 | + thisarg = "460800" |
| 45 | + |
| 46 | + # 'erase_flash' command is translated to the write_flash --erase-all option |
| 47 | + # https://github.com/esp8266/Arduino/issues/6755#issuecomment-553208688 |
| 48 | + if thisarg == "erase_flash": |
| 49 | + write_option = '--erase-all' |
| 50 | + thisarg = '' |
| 51 | + |
| 52 | + if thisarg == 'erase_region': |
| 53 | + erase_addr = sys.argv.pop(0) |
| 54 | + erase_len = sys.argv.pop(0) |
| 55 | + thisarg = '' |
| 56 | + |
| 57 | + if os.path.isfile(thisarg): |
| 58 | + binary = thisarg |
| 59 | + thisarg = '' |
| 60 | + |
| 61 | + if len(thisarg): |
| 62 | + cmdline = cmdline + [thisarg] |
| 63 | + |
| 64 | +if not compatibility: |
| 65 | + cmdline = cmdline + ['write_flash'] |
| 66 | + |
| 67 | +if len(write_option): |
| 68 | + cmdline = cmdline + [write_option] |
28 | 69 |
|
29 |
| -if sys.argv[len(sys.argv)-1] == '--end': |
30 |
| - |
31 |
| - while len(sys.argv): |
32 |
| - if sys.argv[0] == '--end': |
33 |
| - esptool.main(fakeargs) |
34 |
| - sys.argv.pop(0) # Remove --end |
35 |
| - fakeargs = [] |
36 |
| - else: |
37 |
| - # We silently replace the 921kbaud setting with 460k to enable backward |
38 |
| - # compatibility with the old esptool-ck.exe. Esptool.py doesn't seem |
39 |
| - # work reliably at 921k, but is still significantly faster at 460kbaud. |
40 |
| - thisarg = sys.argv.pop(0) |
41 |
| - if thisarg == "921600": |
42 |
| - thisarg = "460800" |
43 |
| - fakeargs = fakeargs + [thisarg] |
44 |
| -else: |
45 |
| - |
46 |
| - while len(sys.argv): |
47 |
| - thisarg = sys.argv.pop(0) |
| 70 | +if not compatibility: |
| 71 | + cmdline = cmdline + ['0x0', binary] |
48 | 72 |
|
| 73 | +erase_file = '' |
| 74 | +if len(erase_addr): |
| 75 | + # generate temporary empty (0xff) file |
| 76 | + eraser = tempfile.mkstemp() |
| 77 | + erase_file = eraser[1] |
| 78 | + os.write(eraser[0], bytearray([255] * int(erase_len, 0))) |
| 79 | + os.close(eraser[0]) |
| 80 | + cmdline = cmdline + [ erase_addr, erase_file ] |
| 81 | + |
| 82 | +if not compatibility: |
| 83 | + #sys.stderr.write("\ncmdline:" + str(cmdline) + "\n") |
| 84 | + esptool.main(cmdline) |
| 85 | + |
| 86 | +while len(sys.argv) and compatibility: |
| 87 | + if sys.argv[0] == '--end': |
| 88 | + #sys.stderr.write("\ncmdline:" + str(cmdline) + " in compatibility mode\n") |
| 89 | + esptool.main(cmdline) |
| 90 | + sys.argv.pop(0) # Remove --end |
| 91 | + cmdline = [] |
| 92 | + else: |
49 | 93 | # We silently replace the 921kbaud setting with 460k to enable backward
|
50 | 94 | # compatibility with the old esptool-ck.exe. Esptool.py doesn't seem
|
51 | 95 | # work reliably at 921k, but is still significantly faster at 460kbaud.
|
| 96 | + thisarg = sys.argv.pop(0) |
52 | 97 | if thisarg == "921600":
|
53 | 98 | thisarg = "460800"
|
| 99 | + cmdline = cmdline + [thisarg] |
54 | 100 |
|
55 |
| - # 'erase_flash' command is translated to the write_flash --erase-all option |
56 |
| - # https://github.com/esp8266/Arduino/issues/6755#issuecomment-553208688 |
57 |
| - if thisarg == "erase_flash": |
58 |
| - write_option = '--erase-all' |
59 |
| - thisarg = '' |
60 |
| - |
61 |
| - if thisarg == 'erase_region': |
62 |
| - erase_addr = sys.argv.pop(0) |
63 |
| - erase_len = sys.argv.pop(0) |
64 |
| - thisarg = '' |
65 |
| - |
66 |
| - if os.path.isfile(thisarg): |
67 |
| - binary = thisarg |
68 |
| - thisarg = '' |
69 |
| - |
70 |
| - if len(thisarg): |
71 |
| - cmdline = cmdline + [thisarg] |
72 |
| - |
73 |
| - cmdline = cmdline + ['write_flash'] |
74 |
| - if len(write_option): |
75 |
| - cmdline = cmdline + [write_option] |
76 |
| - cmdline = cmdline + ['0x0', binary] |
77 |
| - |
78 |
| - erase_file = '' |
79 |
| - if len(erase_addr): |
80 |
| - # generate temporary empty (0xff) file |
81 |
| - eraser = tempfile.mkstemp() |
82 |
| - erase_file = eraser[1] |
83 |
| - os.write(eraser[0], bytearray([255] * int(erase_len, 0))) |
84 |
| - os.close(eraser[0]) |
85 |
| - cmdline = cmdline + [ erase_addr, erase_file ] |
86 |
| - esptool.main(cmdline) |
87 | 101 |
|
88 |
| - if len(erase_file): |
89 |
| - os.remove(erase_file) |
| 102 | +if len(erase_file): |
| 103 | + os.remove(erase_file) |
0 commit comments