Skip to content

Commit 9790e1c

Browse files
earlephilhowerd-a-v
authored andcommitted
Use esptool.py to handle sketch upload, make python available on Windows, too (#5635)
* Add esptool.py, pyserial, and python to JSON Add installation of python on Win32/Win64, and on all systems install esptool.py and pyserial. * Initial esptool.py upload test * First successfull esptool.py upload * Patch in verbose flag operation * Replace esptool-ck.exe with Python equivalent Remove need for binary esptool-ck.exe by implementing the same logic as esptool-ck uses in Python. Only image creation is supported, and only in the Arduino standard mode (with its custom bootloader and ROM layout). * Remove all esptool-ck.exe, hook Windows Python Remove all references to esptool-ck and use Python on Windows and Linux for all recipes where possible. * Use python to make core_version as well Avoid ugly bash and CMD.exe tricks in platform.txt by using python to make the core_version header. * Rename conflicting script, clean up packager * Windows test passes Need to make sure Python2 and Python3 compatible and paths are munged properly to avoid eaccidentally escaping things when calling esptool.py Able to compile, build a BIN and upload via esptool.py on a Windows machine without Python installed globally, only as part of the Arduino tools package. * Use github sources for pyserial * Erase calibration or all flash before programming Add back in erase support by calling esptool.py twice (since it does not support chained operations like esptool-ck.exe). * Make 460K default speed, remove 961K 961K doesn't seem to work with esptool, so make 460K the default upload speed and remove 961K. Even at this lower speed, esptool.py is much faster to upload (even before taking into account the compression when doing things like SPIFFS and code upload). * Make erase and upload work again Arduino does not support a upload.#.cmd pattern, so we need to do everything in a single command line. Make it cleaner by introducing a Python wrapper script which will run the same executable with different sets of commands (since we need to erase a block w/a separate invocation from the real upload). Update boards.txt to use the new options format, placing the esptool command as "version" when there is no "erase_flash" or "erase_region" to be done to keep things simple. * Move esptool/pyserial to submodules Since esptool.py and pyserial are coming directly from github repos, there is no need to include them as a tool in package.json. * Restore 921K upload opt, silent downgrade to 460k To enable full backward compatibility, restore the 921k option for upload speed but silently change it to 460k in the upload.py script. Add error checking on upload.py
1 parent e7e7a4d commit 9790e1c

12 files changed

+384
-202
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.DS_Store
22
tools/dist/
33
tools/xtensa-lx106-elf/
4-
tools/esptool/
54
tools/mkspiffs/
65
package/versions/
76
exclude.txt

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
[submodule "libraries/SoftwareSerial"]
88
path = libraries/SoftwareSerial
99
url = https://github.com/plerup/espsoftwareserial.git
10+
[submodule "tools/pyserial"]
11+
path = tools/pyserial
12+
url = https://github.com/pyserial/pyserial.git
13+
[submodule "tools/esptool"]
14+
path = tools/esptool
15+
url = https://github.com/espressif/esptool.git

boards.txt

+120-120
Large diffs are not rendered by default.

package/build_boards_manager_package.sh

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ $SED 's/runtime.tools.esptool.path={runtime.platform.path}\/tools\/esptool//g' |
7878
$SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' | \
7979
$SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' |\
8080
$SED 's/recipe.hooks.core.prebuild.2.pattern.*//g' |\
81-
$SED 's/recipe.hooks.core.prebuild.3.pattern.*//g' |\
8281
$SED "s/version=.*/version=$ver/g" |\
8382
$SED -E "s/name=([a-zA-Z0-9\ -]+).*/name=\1($ver)/g"\
8483
> $outdir/platform.txt

package/package_esp8266com_index.template.json

+19-54
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"packages": [
33
{
4+
"name": "esp8266",
45
"maintainer": "ESP8266 Community",
6+
"websiteURL": "https://github.com/esp8266/Arduino",
7+
"email": "[email protected]",
58
"help": {
69
"online": "http://esp8266.com/arduino"
710
},
8-
"websiteURL": "https://github.com/esp8266/Arduino",
911
"platforms": [
1012
{
1113
"category": "ESP8266",
@@ -110,17 +112,17 @@
110112
{
111113
"packager": "esp8266",
112114
"version": "2.5.0-3-20ed2b9",
113-
"name": "esptool"
115+
"name": "xtensa-lx106-elf-gcc"
114116
},
115117
{
116118
"packager": "esp8266",
117119
"version": "2.5.0-3-20ed2b9",
118-
"name": "xtensa-lx106-elf-gcc"
120+
"name": "mkspiffs"
119121
},
120122
{
121123
"packager": "esp8266",
122-
"version": "2.5.0-3-20ed2b9",
123-
"name": "mkspiffs"
124+
"version": "3.7.2-post1",
125+
"name": "python"
124126
}
125127
],
126128
"help": {
@@ -130,57 +132,22 @@
130132
],
131133
"tools": [
132134
{
133-
"version": "2.5.0-3-20ed2b9",
134-
"name": "esptool",
135+
"version": "3.7.2-post1",
136+
"name": "python",
135137
"systems": [
136138
{
137-
"host": "aarch64-linux-gnu",
138-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/aarch64-linux-gnu.esptool-f80ae31.tar.gz",
139-
"archiveFileName": "aarch64-linux-gnu.esptool-f80ae31.tar.gz",
140-
"checksum": "SHA-256:888425ff1e33a97ea155b6f128de6b578c34468895ba9b4acd1e4f28608d917a",
141-
"size": "14681"
142-
},
143-
{
144-
"host": "arm-linux-gnueabihf",
145-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/arm-linux-gnueabihf.esptool-f80ae31.tar.gz",
146-
"archiveFileName": "arm-linux-gnueabihf.esptool-f80ae31.tar.gz",
147-
"checksum": "SHA-256:71c878ac6a21ee69dcd615cd28f2dccd29a87079e0b3069eba625089d89e5058",
148-
"size": "13873"
139+
"host": "x86_64-mingw32",
140+
"url": "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip",
141+
"archiveFileName": "python-3.7.2.post1-embed-win32.zip",
142+
"checksum": "SHA-256:ceb06a5244e93e7e7523e26e1354447b79a9e6fd8c45891d81df9c7da1e02d05",
143+
"size": "6533256"
149144
},
150145
{
151146
"host": "i686-mingw32",
152-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/i686-w64-mingw32.esptool-f80ae31.zip",
153-
"archiveFileName": "i686-w64-mingw32.esptool-f80ae31.zip",
154-
"checksum": "SHA-256:e30f25a19a78635000401b083b479e111d591bac20cfd89b1bfdf36a60e9ee20",
155-
"size": "16466"
156-
},
157-
{
158-
"host": "i686-pc-linux-gnu",
159-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/i686-linux-gnu.esptool-f80ae31.tar.gz",
160-
"archiveFileName": "i686-linux-gnu.esptool-f80ae31.tar.gz",
161-
"checksum": "SHA-256:fe632f4602d02b6a9425c5bf95074095cb6d3c57912168a0f6b796fddd8ce991",
162-
"size": "16543"
163-
},
164-
{
165-
"host": "x86_64-apple-darwin",
166-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-apple-darwin14.esptool-f80ae31.tar.gz",
167-
"archiveFileName": "x86_64-apple-darwin14.esptool-f80ae31.tar.gz",
168-
"checksum": "SHA-256:0f51e487706a476b0b87299a769282ad65623774770655168a79d1748d2506e7",
169-
"size": "15003"
170-
},
171-
{
172-
"host": "x86_64-pc-linux-gnu",
173-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-linux-gnu.esptool-f80ae31.tar.gz",
174-
"archiveFileName": "x86_64-linux-gnu.esptool-f80ae31.tar.gz",
175-
"checksum": "SHA-256:bded1dca953377838b6086a9bcd40a1dc5286ba5f69f2372c22a1d1819baad24",
176-
"size": "16526"
177-
},
178-
{
179-
"host": "x86_64-mingw32",
180-
"url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/x86_64-w64-mingw32.esptool-f80ae31.zip",
181-
"archiveFileName": "x86_64-w64-mingw32.esptool-f80ae31.zip",
182-
"checksum": "SHA-256:d6d5976fde82d07e93d5a01f38bbb4f84a7796187ff0541ee62650041791d0e8",
183-
"size": "19724"
147+
"url": "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip",
148+
"archiveFileName": "python-3.7.2.post1-embed-win32.zip",
149+
"checksum": "SHA-256:ceb06a5244e93e7e7523e26e1354447b79a9e6fd8c45891d81df9c7da1e02d05",
150+
"size": "6533256"
184151
}
185152
]
186153
},
@@ -294,9 +261,7 @@
294261
}
295262
]
296263
}
297-
],
298-
"email": "[email protected]",
299-
"name": "esp8266"
264+
]
300265
}
301266
]
302267
}

platform.txt

+22-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ version=2.6.0-dev
1111
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf
1212
runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
1313
runtime.tools.signing={runtime.platform.path}/tools/signing.py
14+
runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py
15+
runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
16+
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
17+
runtime.tools.python=python
18+
runtime.tools.python.windows={runtime.platform.path}/tools/python/python.exe
1419

1520
compiler.warning_flags=-w
1621
compiler.warning_flags.none=-w
@@ -76,14 +81,8 @@ compiler.elf2hex.extra_flags=
7681

7782
## generate file with git version number
7883
## needs bash, git, and echo
79-
recipe.hooks.core.prebuild.1.pattern=python "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
80-
recipe.hooks.core.prebuild.2.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_VER 0x`git --git-dir {runtime.platform.path}/.git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff` >{build.path}/core/core_version.h"
81-
recipe.hooks.core.prebuild.3.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_DESC `cd "{runtime.platform.path}"; git describe --tags 2>/dev/null || echo unix-{version}` >>{build.path}/core/core_version.h"
82-
83-
## windows-compatible version without git
84-
recipe.hooks.core.prebuild.1.pattern.windows=cmd.exe /c rem cannot sign on windows
85-
recipe.hooks.core.prebuild.2.pattern.windows=cmd.exe /c mkdir {build.path}\core & (echo #define ARDUINO_ESP8266_GIT_VER 0x00000000 & echo #define ARDUINO_ESP8266_GIT_DESC win-{version} ) > {build.path}\core\core_version.h
86-
recipe.hooks.core.prebuild.3.pattern.windows=cmd.exe /c if exist {build.source.path}\public.key echo #error Cannot automatically build signed binaries on Windows > {build.path}\core\Updater_Signing.h
84+
recipe.hooks.core.prebuild.1.pattern="{runtime.tools.python}" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
85+
recipe.hooks.core.prebuild.2.pattern="{runtime.tools.python}" "{runtime.tools.makecorever}" --build_path "{build.path}' --platform_path "{runtime.platform.path}" --version "unix-{version}"
8786

8887
## Build the app.ld linker file
8988
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
@@ -107,14 +106,8 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_
107106
recipe.objcopy.eep.pattern=
108107

109108
## Create hex
110-
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
111-
112-
recipe.objcopy.hex.1.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
113-
recipe.objcopy.hex.2.pattern=python "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
114-
115-
# No signing on Windows
116-
recipe.objcopy.hex.1.pattern.windows="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
117-
recipe.objcopy.hex.2.pattern.windows=
109+
recipe.objcopy.hex.1.pattern="{runtime.tools.python}" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin"
110+
recipe.objcopy.hex.2.pattern="{runtime.tools.python}" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
118111

119112
## Save hex
120113
recipe.output.tmp_file={build.project_name}.bin
@@ -128,16 +121,23 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
128121

129122
# ------------------------------
130123

131-
tools.esptool.cmd=esptool
132-
tools.esptool.cmd.windows=esptool.exe
133-
tools.esptool.path={runtime.platform.path}/tools/esptool
124+
# Need to duplicate the python path because Arduino does not replace properly in this stage
125+
tools.esptool.cmd=python
126+
tools.esptool.cmd.windows={runtime.platform.path}/tools/python/python.exe
127+
tools.esptool.path=
134128
tools.esptool.network_cmd=python
135-
tools.esptool.network_cmd.windows=python.exe
129+
tools.esptool.network_cmd.windows={runtime.platform.path}/tools/python/python.exe
136130

137131
tools.esptool.upload.protocol=esp
138-
tools.esptool.upload.params.verbose=-vv
132+
tools.esptool.upload.params.verbose=--trace
139133
tools.esptool.upload.params.quiet=
140-
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" {upload.erase_cmd} -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
134+
135+
# First, potentially perform an erase or nothing
136+
# Next, do the binary upload
137+
# Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern
138+
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
139+
140+
141141
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"
142142

143143
tools.mkspiffs.cmd=mkspiffs

tools/boards.txt.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
( '.upload.tool', 'esptool' ),
852852
( '.upload.maximum_data_size', '81920' ),
853853
( '.upload.wait_for_upload_port', 'true' ),
854-
( '.upload.erase_cmd', ''),
854+
( '.upload.erase_cmd', 'version'),
855855
( '.serial.disableDTR', 'true' ),
856856
( '.serial.disableRTS', 'true' ),
857857
( '.build.mcu', 'esp8266' ),
@@ -1066,11 +1066,11 @@
10661066

10671067
'flash_erase_menu': collections.OrderedDict([
10681068
( '.menu.wipe.none', 'Only Sketch' ),
1069-
( '.menu.wipe.none.upload.erase_cmd', '' ),
1069+
( '.menu.wipe.none.upload.erase_cmd', 'version' ),
10701070
( '.menu.wipe.sdk', 'Sketch + WiFi Settings' ),
1071-
( '.menu.wipe.sdk.upload.erase_cmd', '-ca "{build.rfcal_addr}" -cz 0x4000' ),
1071+
( '.menu.wipe.sdk.upload.erase_cmd', 'erase_region "{build.rfcal_addr}" 0x4000' ),
10721072
( '.menu.wipe.all', 'All Flash Contents' ),
1073-
( '.menu.wipe.all.upload.erase_cmd', '-ca 0x0 -cz "{build.flash_size_bytes}"' ),
1073+
( '.menu.wipe.all.upload.erase_cmd', 'erase_flash' ),
10741074
]),
10751075

10761076
}

tools/elf2bin.py

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python
2+
3+
# Generate an Arduino compatible BIN file from bootloader and sketch ELF
4+
# Replaces esptool-ck.exe and emulates its behavior.
5+
#
6+
# Copyright (C) 2019 - Earle F. Philhower, III
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
21+
import argparse
22+
import re
23+
import os
24+
import subprocess
25+
import sys
26+
import tempfile
27+
28+
fmodeb = { 'dout': 3, 'dio': 2, 'quot': 1, 'qio': 0 }
29+
ffreqb = { '40': 0, '26': 1, '20': 2, '80': 15 }
30+
fsizeb = { '512K': 0, '256K': 1, '1M': 2, '2M': 3, '4M': 4, '8M': 8, '16M': 9 }
31+
32+
def get_elf_entry(elf, path):
33+
p = subprocess.Popen([path + "/xtensa-lx106-elf-readelf", '-h', elf], stdout=subprocess.PIPE, universal_newlines=True )
34+
lines = p.stdout.readlines()
35+
for line in lines:
36+
if 'Entry point address' in line:
37+
words = re.split('\s+', line)
38+
entry_point = words[-2]
39+
return int(entry_point, 16)
40+
raise Exception('Unable to find entry point in file "' + elf + '"')
41+
42+
def get_segment_size_addr(elf, segment, path):
43+
p = subprocess.Popen([path + '/xtensa-lx106-elf-objdump', '-h', '-j', segment, elf], stdout=subprocess.PIPE, universal_newlines=True )
44+
lines = p.stdout.readlines()
45+
for line in lines:
46+
if segment in line:
47+
words = re.split('\s+', line)
48+
size = int(words[3], 16)
49+
addr = int(words[4], 16)
50+
return [ size, addr ]
51+
raise Exception('Unable to find size and start point in file "' + elf + '" for "' + segment + '"')
52+
53+
def read_segment(elf, segment, path):
54+
tmpfile, dumpfile = tempfile.mkstemp()
55+
os.close(tmpfile)
56+
p = subprocess.check_call([path + "/xtensa-lx106-elf-objcopy", '-O', 'binary', '--only-section=' + segment, elf, dumpfile], stdout=subprocess.PIPE)
57+
binfile = open(dumpfile, "rb")
58+
raw = binfile.read()
59+
binfile.close()
60+
return raw
61+
62+
def write_bin(out, elf, segments, to_addr, flash_mode, flash_size, flash_freq, path):
63+
entry = int(get_elf_entry( elf, path ))
64+
header = [ 0xe9, len(segments), fmodeb[flash_mode], ffreqb[flash_freq] + 16 * fsizeb[flash_size],
65+
entry & 255, (entry>>8) & 255, (entry>>16) & 255, (entry>>24) & 255 ]
66+
out.write(bytearray(header))
67+
total_size = 8
68+
checksum = 0xef
69+
for segment in segments:
70+
[size, addr] = get_segment_size_addr(elf, segment, path)
71+
seghdr = [ addr & 255, (addr>>8) & 255, (addr>>16) & 255, (addr>>24) & 255,
72+
size & 255, (size>>8) & 255, (size>>16) & 255, (size>>24) & 255]
73+
out.write(bytearray(seghdr));
74+
total_size += 8;
75+
raw = read_segment(elf, segment, path)
76+
if len(raw) != size:
77+
raise Exception('Segment size doesn\'t match read data for "' + segment + '" in "' + elf + '"')
78+
out.write(raw)
79+
total_size += len(raw)
80+
try:
81+
for data in raw:
82+
checksum = checksum ^ ord(data)
83+
except:
84+
for data in raw:
85+
checksum = checksum ^ data
86+
total_size += 1
87+
while total_size & 15:
88+
total_size += 1
89+
out.write(bytearray([0]))
90+
out.write(bytearray([checksum]))
91+
if to_addr != 0:
92+
while total_size < to_addr:
93+
out.write(bytearray([0xaa]))
94+
total_size += 1
95+
96+
def main():
97+
parser = argparse.ArgumentParser(description='Create a BIN file from eboot.elf and Arduino sketch.elf for upload by esptool.py')
98+
parser.add_argument('-e', '--eboot', action='store', required=True, help='Path to the Arduino eboot.elf bootloader')
99+
parser.add_argument('-a', '--app', action='store', required=True, help='Path to the Arduino sketch ELF')
100+
parser.add_argument('-m', '--flash_mode', action='store', required=True, choices=['dout', 'dio', 'qout', 'qio'], help='SPI flash mode')
101+
parser.add_argument('-f', '--flash_freq', action='store', required=True, choices=['20', '26', '40', '80'], help='SPI flash speed')
102+
parser.add_argument('-s', '--flash_size', action='store', required=True, choices=['256K', '512K', '1M', '2M', '4M', '8M', '16M'], help='SPI flash size')
103+
parser.add_argument('-o', '--out', action='store', required=True, help='Output BIN filename')
104+
parser.add_argument('-p', '--path', action='store', required=True, help='Path to Xtensa toolchain binaries')
105+
106+
args = parser.parse_args()
107+
108+
print('Creating BIN file "' + args.out + '" using "' + args.app + '"')
109+
110+
out = open(args.out, "wb")
111+
write_bin(out, args.eboot, ['.text'], 4096, args.flash_mode, args.flash_size, args.flash_freq, args.path)
112+
write_bin(out, args.app, ['.irom0.text', '.text', '.data', '.rodata'], 0, args.flash_mode, args.flash_size, args.flash_freq, args.path)
113+
out.close()
114+
115+
return 0
116+
117+
118+
if __name__ == '__main__':
119+
sys.exit(main())

tools/esptool

Submodule esptool added at 9ad444a

0 commit comments

Comments
 (0)