Skip to content

Commit b827489

Browse files
committed
Improved selection of actions to be performed
Added description of changes to docu
1 parent fc74ac7 commit b827489

File tree

7 files changed

+746
-577
lines changed

7 files changed

+746
-577
lines changed

boards.txt

+594-519
Large diffs are not rendered by default.

doc/filesystem.rst

+49-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,55 @@ in the specific subdirectory. This mimics the POSIX behavior for
192192
directory traversal most C programmers are used to.
193193

194194

195-
Uploading files to file system
196-
------------------------------
195+
Uploading files to file system (new)
196+
------------------------------------
197+
198+
Since PullRequest #8266 Filsystem generation is integrated into the
199+
“compile and/or upload” action of Arduino.
200+
There is no need to download any additional tool.
201+
202+
This integration is done by adding 3 entries (“Upload”, "Filesystem" and “Export”)
203+
to the tools-menu. These entries are presented just like any other options
204+
for esp8266 (“Upload speed” ... “Non-32-Bit Access”) and placed right after
205+
the last.
206+
207+
Menu-Entry “Upload” let You choose between:
208+
- Sketch
209+
- Filesystem
210+
- Both
211+
This Menu controls which parts are uploaded when You choose "Sketch->Upload"
212+
(Ctrl-U) from the Arduino Menu.
213+
214+
Menu-Entry “Filesystem” let You choose between:
215+
- Off
216+
- LitteFs
217+
- SPIFFS
218+
This Menu controls which Fs will be created when You choose "Sketch->Compile"
219+
(Ctrl-R) from the Arduino Menu. The Fs will always be created inside the
220+
"export" dir (see below).
221+
222+
Menu-Entry “Export” let You choose between:
223+
- Off
224+
- .bin & .bin.signed)
225+
- Create & Export gzipped Binaries too
226+
This Menu controls export & generation of (extra) Sketch-Binaries.
227+
228+
The "export" dir
229+
................
230+
After a (successful) compile, the files will be exported to a subdir
231+
“bin/{variant}” of Your sketch directory
232+
(“{variant}” replaced with the name of the board as shown behind
233+
“Tools -> Board:”).
234+
Signed variants of all Binaries are generated similar to the
235+
“automatic signing” done for normal sketch binary.
236+
237+
As valid for the "old" tools mentioned below, it is nessesary to place
238+
files you want to be inside the generated file system into a directory
239+
named ``data`` inside Your sketch directory.
240+
241+
242+
Uploading files to file system (old tools)
243+
------------------------------------------
197244

198245
*ESP8266FS* is a tool which integrates into the Arduino IDE. It adds a
199246
menu item to *Tools* menu for uploading the contents of sketch data

platform.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ recipe.objcopy.hex.2.pattern="{runtime.tools.python3.path}/python3" -I "{runtime
131131
recipe.objcopy.hex.3.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.sizes}" --elf "{build.path}/{build.project_name}.elf" --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --mmu "{build.mmuflags}"
132132

133133
# Post-Build: Handle new Menu-Enties: Filesystem & Binaries
134-
recipe.hooks.objcopy.postobjcopy.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.postbuild}" -fi "{build.Filesystem}" -bi "{build.Binaries}" -na "{build.project_name}" -bp "{build.path}" -so "{build.source.path}" -va "{build.variant}" -ss "{build.spiffs_start}" -se "{build.spiffs_end}" -sp "{build.spiffs_pagesize}" -sl "{build.spiffs_blocksize}"
134+
recipe.hooks.objcopy.postobjcopy.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.postbuild}" -fi "{build.Filesystem}" -ex "{build.Export}" -na "{build.project_name}" -bp "{build.path}" -so "{build.source.path}" -va "{build.variant}" -ss "{build.spiffs_start}" -se "{build.spiffs_end}" -sp "{build.spiffs_pagesize}" -sl "{build.spiffs_blocksize}"
135135

136136
## Save hex
137137
recipe.output.tmp_file.1={build.project_name}.bin
@@ -163,9 +163,9 @@ tools.esptool.upload.params.quiet=
163163

164164
# Old behaviour (without integrated handling of filesystem & gzipd Binaries) can be (re)enabled by commenting in/out the following 2x2 entries
165165
#tools.esptool.upload.pattern="{cmd}" -I "{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"
166-
tools.esptool.upload.pattern="{cmd}" -I "{runtime.platform.path}/tools/uploadGn.py" -fi "{build.Filesystem}" --port "{serial.port}" --baud "{upload.speed}" {upload.resetmethod} --sk 0x0 "{build.path}/{build.project_name}.bin" --fs {build.spiffs_start} "{build.path}/{build.project_name}" {upload.erase_cmd} "{upload.verbose}"
166+
tools.esptool.upload.pattern="{cmd}" -I "{runtime.platform.path}/tools/uploadGn.py" -fi "{build.Filesystem}" -up "{build.Upload}" --port "{serial.port}" --baud "{upload.speed}" {upload.resetmethod} --sk 0x0 "{build.path}/{build.project_name}.bin" --fs {build.spiffs_start} "{build.path}/{build.project_name}" {upload.erase_cmd} "{upload.verbose}"
167167
#tools.esptool.upload.network_pattern="{network_cmd}" -I "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
168-
tools.esptool.upload.network_pattern="{network_cmd}" -I "{runtime.platform.path}/tools/netUploadGn.py" -fi "{build.Filesystem}" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" --sk "{build.path}/{build.project_name}.bin" --fs "{build.path}/{build.project_name}"
168+
tools.esptool.upload.network_pattern="{network_cmd}" -I "{runtime.platform.path}/tools/netUploadGn.py" -fi "{build.Filesystem}" -up "{build.Upload}" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" --sk "{build.path}/{build.project_name}.bin" --fs "{build.path}/{build.project_name}"
169169

170170
tools.mkspiffs.cmd=mkspiffs
171171
tools.mkspiffs.cmd.windows=mkspiffs.exe

tools/boards.txt.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -1033,23 +1033,26 @@
10331033
( '.build.debug_port', '' ),
10341034
( '.build.debug_level', '' ),
10351035

1036+
( '.menu.Upload.Sketch', 'Sketch' ),
1037+
( '.menu.Upload.Sketch.build.Upload', '1' ),
1038+
( '.menu.Upload.Filesystem', 'Filesystem' ),
1039+
( '.menu.Upload.Filesystem.build.Upload', '2' ),
1040+
( '.menu.Upload.Both', 'Both' ),
1041+
( '.menu.Upload.Both.build.Upload', '3' ),
1042+
10361043
( '.menu.Filesystem.Off', 'Off' ),
10371044
( '.menu.Filesystem.Off.build.Filesystem', '0' ),
1038-
( '.menu.Filesystem.LitteFsCreateUpload', 'LitteFs: Create & Upload' ),
1039-
( '.menu.Filesystem.LitteFsCreateUpload.build.Filesystem', '1' ),
1040-
( '.menu.Filesystem.LitteFsCreateExport', 'LitteFs: Create only' ),
1041-
( '.menu.Filesystem.LitteFsCreateExport.build.Filesystem', '2' ),
1042-
( '.menu.Filesystem.SPIFFSCreateUpload', 'SPIFFS: Create & Upload' ),
1043-
( '.menu.Filesystem.SPIFFSCreateUpload.build.Filesystem', '3' ),
1044-
( '.menu.Filesystem.SPIFFSCreateExport', 'SPIFFS: Create only' ),
1045-
( '.menu.Filesystem.SPIFFSCreateExport.build.Filesystem', '4' ),
1046-
1047-
( '.menu.Binaries.Off', 'Off' ),
1048-
( '.menu.Binaries.Off.build.Binaries', '0' ),
1049-
( '.menu.Binaries.Binaries', 'Export (.bin & .bin.signed)' ),
1050-
( '.menu.Binaries.Binaries.build.Binaries', '1' ),
1051-
( '.menu.Binaries.PackedBinaries', 'Create & Export gzipped Binaries too' ),
1052-
( '.menu.Binaries.PackedBinaries.build.Binaries', '2' ),
1045+
( '.menu.Filesystem.LitteFs', 'LitteFs' ),
1046+
( '.menu.Filesystem.LitteFs.build.Filesystem', '1' ),
1047+
( '.menu.Filesystem.SPIFFS', 'SPIFFS' ),
1048+
( '.menu.Filesystem.SPIFFS.build.Filesystem', '2' ),
1049+
1050+
( '.menu.Export.Off', 'Off' ),
1051+
( '.menu.Export.Off.build.Export', '0' ),
1052+
( '.menu.Export.Binaries', '.bin & .bin.signed' ),
1053+
( '.menu.Export.Binaries.build.Export', '1' ),
1054+
( '.menu.Export.GzBinaries', 'Create & Export gzipped Binaries too' ),
1055+
( '.menu.Export.GzBinaries.build.Export', '2' ),
10531056
]),
10541057

10551058
#######################
@@ -1676,8 +1679,9 @@ def all_boards ():
16761679
print('menu.ssl=SSL Support')
16771680
print('menu.mmu=MMU')
16781681
print('menu.non32xfer=Non-32-Bit Access')
1682+
print('menu.Upload=Upload')
16791683
print('menu.Filesystem=Filesystem')
1680-
print('menu.Binaries=Binaries')
1684+
print('menu.Export=Export')
16811685
print('')
16821686

16831687
missingboards = []

tools/postbuild.py

+33-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
def parse_args( argsIn ):
1717
parser = argparse.ArgumentParser( description = 'PostBuild for ESP8288' )
18-
parser.add_argument( '-fi', '--Filesystem', type = int, default = 0, help = '0: Off, 1: LitteFs: Create & Upload, 2: LitteFs: Create only, 3: SPIFFS: Create & Upload, 4: SPIFFS: Create only' )
19-
parser.add_argument( '-bi', '--Binaries', type = int, default = 0, help = '0: Off, 1: Export (.bin & .bin.signed), 2: Create & Export gzipped Binaries too' )
18+
parser.add_argument( '-fi', '--Filesystem', type = int, default = 0, help = '0: Off, 1: LitteFs, 3: SPIFFS' )
19+
parser.add_argument( '-ex', '--Export', type = int, default = 0, help = '0: Off, 1: .bin & .bin.signed, 2: Create & Export gzipped Binaries too' )
2020
parser.add_argument( '-na', '--name', type = str, required = True, help = 'Name of sketch (without extension)' )
2121
parser.add_argument( '-bp', '--buildPath', type = str, required = True, help = 'Path to temporary dir where sketch was build' )
2222
parser.add_argument( '-so', '--source', type = str, required = True, help = 'Path to sketch' )
@@ -71,11 +71,21 @@ def CreateSignedFile( dir, name ):
7171
raise FatalError( "Exception while signing '%s': %s" % ( name, e ) )
7272
return []
7373

74+
def RemoveFs( fsName ):
75+
""" Removes the (possible existing from prev. builds) given fs from {build.path}
76+
This enshures, that (at upload-stage) we don't use the wrong fs created formerly.
77+
fsName = "littlefs" "spiffs" used for naming the binary to remove. """
78+
imageName = "./%s.%s" % ( Args.name, fsName )
79+
if os.path.exists( imageName ):
80+
os.remove( imageName )
81+
7482
def CreateFs( fsName, mkFsName ):
7583
""" Creates the given fs from all files inside subdir 'data' of the sketch.
7684
fsName = "littlefs" "spiffs" used for naming the generated binary.
7785
mkFsName = "mklittlefs" | "mkspiffs" the name of the programm that generates the fs """
7886
mkFsPath = Which( mkFsName, os.path.join( ToolsDir, mkFsName ) )
87+
if mkFsPath is None:
88+
mkFsPath = Which( "%s.exe" % mkFsName, os.path.join( ToolsDir, mkFsName ) )
7989
res = []
8090
dataDir = "%s/data" % ( Args.source )
8191
if len( Args.spiffs_start ) == 0 or len( Args.spiffs_end ) == 0:
@@ -107,7 +117,7 @@ def CreateFs( fsName, mkFsName ):
107117
signing = Signing and os.path.exists( os.path.abspath( Args.name + ".bin.signed" ) )
108118
if signing:
109119
res += CreateSignedFile( DstDir, imageName )
110-
if Args.Binaries == 2:
120+
if Args.Export == 2:
111121
res += CreateGzFile( DstDir, imageName )
112122
if signing:
113123
res += CreateSignedFile( DstDir, "%s.%s.gz" % ( Args.name, fsName ) )
@@ -116,18 +126,20 @@ def CreateFs( fsName, mkFsName ):
116126
def ProcessFilesystem_():
117127
if Args.spiffs_start is None or Args.spiffs_end is None:
118128
raise ProcessError( "'spiffs_start' and/or 'spiffs_end' missing" )
119-
if Args.Filesystem == 1 or Args.Filesystem == 2:
129+
if Args.Filesystem == 1:
130+
RemoveFs( "spiffs" )
120131
return CreateFs( "littlefs", "mklittlefs" )
121-
elif Args.Filesystem == 3 or Args.Filesystem == 4:
132+
elif Args.Filesystem == 2:
133+
RemoveFs( "littlefs" )
122134
return CreateFs( "spiffs", "mkspiffs" )
123135

124-
def ProcessBinaries_():
136+
def ProcessExport_():
125137
res = []
126138
os.makedirs( DstDir, exist_ok = True )
127139
# Copy Binaries
128140
res += CopyToDir( Args.name, "bin", DstDir )
129141
res += CopyToDir( Args.name, "bin.signed", DstDir )
130-
if Args.Binaries == 2:
142+
if Args.Export == 2:
131143
# Create & Export gzipped Binaries too
132144
res += CreateGzFile( DstDir, "%s.bin" % Args.name )
133145
if os.path.exists( os.path.abspath( os.path.join( DstDir, "%s.bin.signed" % Args.name ) ) ):
@@ -141,10 +153,14 @@ def ProcessFilesystem():
141153
Msg( '...files generated: %s' % ", ".join( filesCreated ) )
142154
except ProcessError as e:
143155
Msg( '...aborted: %s' % e )
156+
try:
157+
WarningDialog( "Filesystem Create aborted", e )
158+
except ProcessError:
159+
pass
144160

145-
def ProcessBinaries():
161+
def ProcessExport():
146162
Msg( "Exporting Binaries..." )
147-
filesExported = ProcessBinaries_()
163+
filesExported = ProcessExport_()
148164
Msg( '...files exported: %s' % ", ".join( filesExported ) )
149165

150166
def main( argsIn = None ):
@@ -157,7 +173,7 @@ def main( argsIn = None ):
157173

158174
#Debug( "Python-Path: %s" % sys.executable )
159175
parse_args( argsIn )
160-
#Debug( "Args: %s" % ", "join( sys.argv[ 1: ] ) )
176+
#Debug( "Posbuild: Args: %s" % ", ".join( sys.argv[ 1: ] ) )
161177

162178
#!! For unknown reason using/concatinig Args.buildPath with "/" (or enything else) will result in an empthy string ???
163179
#if You uncomment the following two lines You will see something like:
@@ -169,6 +185,7 @@ def main( argsIn = None ):
169185
# Workaround: cd to the build/temp path
170186
cwd = os.getcwd()
171187
os.chdir( Args.buildPath )
188+
Msg( 'Build-Dir: %s\n' % Args.buildPath )
172189

173190
#! Even this will not give the correct path !
174191
#Debug( "abspath: %s" % os.path.abspath( "./" ) )
@@ -179,10 +196,13 @@ def main( argsIn = None ):
179196
SigningPrivKeyPath = os.path.abspath( "%s/private.key" % Args.source )
180197
Signing = os.path.isfile( SigningPrivKeyPath )
181198
DstDir = os.path.join( Args.source, "bin", Args.variant )
182-
if Args.Filesystem != 0:
199+
if Args.Filesystem == 0:
200+
RemoveFs( "littlefs" )
201+
RemoveFs( "spiffs" )
202+
else:
183203
ProcessFilesystem()
184-
if Args.Binaries != 0:
185-
ProcessBinaries()
204+
if Args.Export != 0:
205+
ProcessExport()
186206
finally:
187207
# restore working dir
188208
os.chdir( cwd )

tools/uploadGn.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
#Args: (new)
3838
# As defined in 'platform.txt' for 'tools.esptool.upload.pattern' possible values
3939
# | |
40-
# -fi "{build.Filesystem}" 0-4
40+
# -up "{build.Upload}" 1-3
41+
# -fi "{build.Filesystem}" 0-2
4142
# --port "{serial.port}" e.g.: /dev/ttyUSB0
4243
# --baud "{upload.speed}" e.g.: 115200
4344
# {upload.resetmethod} --before { default_reset | no_reset | no_reset_no_sync } --after { hard_reset | soft_reset }
@@ -50,7 +51,8 @@
5051

5152
def parse_args( argsIn ):
5253
parser = argparse.ArgumentParser( description = 'Upload-Wrapper for Arduino esp8266' )
53-
parser.add_argument( '-fi', '--Filesystem', type = int, default = 0, help = '0: Off, 1: LitteFs: Create & Upload, 2: LitteFs: Create only, 3: SPIFFS: Create & Upload, 4: SPIFFS: Create only' )
54+
parser.add_argument( '-up', '--Upload', type = int, default = 1, help = '1: Sketch, 2: Filesystem, 3: Both' )
55+
parser.add_argument( '-fi', '--Filesystem', type = int, default = 0, help = '0: Off, 1: LitteFs, 3: SPIFFS' )
5456
parser.add_argument( '--port', type = str, required = True, help = 'path to serial device' )
5557
parser.add_argument( '--baud', type = str, required = True, help = 'baudrate' )
5658
parser.add_argument( '--before', type = str, required = True, help = 'before (default_reset/no_reset/no_reset_no_sync)' )
@@ -87,27 +89,29 @@ def main( argsIn = None ):
8789
esptoolArgs += [ '--trace' ]
8890
esptoolArgs += [ 'write_flash' ]
8991

90-
if len( Args.erase_cmd ) and Args.erase_cmd[ 0 ] == "erase_flash":
91-
esptoolArgs += [ '--erase-all' ]
92-
esptoolArgs += [ '--flash_size', 'detect', Args.sk[ 0 ], Args.sk[ 1 ] ]
93-
9492
EraseFilePath = ''
93+
filesUploaded = []
9594
try:
96-
if len( Args.erase_cmd ) and Args.erase_cmd[ 0 ] == "erase_region":
97-
# Generate temporary empty (0xff) file
98-
f, EraseFilePath = tempfile.mkstemp()
99-
os.write( f, bytearray( [ 255 ] * int( Args.erase_cmd[ 2 ], 0 ) ) )
100-
os.close( f )
101-
esptoolArgs += [ Args.erase_cmd[ 1 ], EraseFilePath ]
102-
103-
filesUploaded = [ Path( Args.sk[ 1 ] ).name ]
104-
if Args.Filesystem == 1:
105-
esptoolArgs += [ Args.fs[ 0 ], "%s.littlefs" % Args.fs[ 1 ] ]
106-
filesUploaded += [ Path( Args.fs[ 1 ] ).name ]
107-
elif Args.Filesystem == 3:
108-
esptoolArgs += [ Args.fs[ 0 ], "%s.spiffs" % Args.fs[ 1 ] ]
109-
filesUploaded += [ Path( Args.fs[ 1 ] ).name ]
110-
95+
if ( Args.Upload & 1 ) == 1:
96+
if len( Args.erase_cmd ) and Args.erase_cmd[ 0 ] == "erase_flash":
97+
esptoolArgs += [ '--erase-all' ]
98+
esptoolArgs += [ '--flash_size', 'detect', Args.sk[ 0 ], Args.sk[ 1 ] ]
99+
100+
if len( Args.erase_cmd ) and Args.erase_cmd[ 0 ] == "erase_region":
101+
# Generate temporary empty (0xff) file
102+
f, EraseFilePath = tempfile.mkstemp()
103+
os.write( f, bytearray( [ 255 ] * int( Args.erase_cmd[ 2 ], 0 ) ) )
104+
os.close( f )
105+
esptoolArgs += [ Args.erase_cmd[ 1 ], EraseFilePath ]
106+
107+
filesUploaded += [ Path( Args.sk[ 1 ] ).name ]
108+
109+
if ( Args.Upload & 2 ) == 2:
110+
fsName = "%s.%s" % ( Args.fs[ 1 ], "littlefs" if Args.Filesystem == 1 else "spiffs" )
111+
if os.path.exists( fsName ):
112+
esptoolArgs += [ Args.fs[ 0 ], fsName ]
113+
filesUploaded += [ Path( fsName ).name ]
114+
111115
Msg( "Uploading Binaries..." )
112116
#Debug( str( esptoolArgs ) )
113117
esptool.main( esptoolArgs )

tools/utillities.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def RemoveIno( path ):
7575
if path[ -4: ] == ".ino":
7676
path = name[ 0:-4 ]
7777
return path
78-
79-
def ConfirmDialog( title, text ):
78+
79+
def TkDialog( title, text, mbName ):
8080
try:
8181
import tkinter
8282
from tkinter import messagebox
@@ -86,5 +86,24 @@ def ConfirmDialog( title, text ):
8686
rootWin.overrideredirect( 1 ) # Avoid it appearing and then disappearing quickly
8787
#rootWin.iconbitmap("PythonIcon.ico") # Set an icon (this is optional - must be in a .ico format)
8888
rootWin.withdraw() # Hide the window as we do not want to see this one
89-
return messagebox.askyesno( title, text, parent = rootWin )
89+
mbFunc = getattr( messagebox, mbName )
90+
return mbFunc( title, text, parent = rootWin )
91+
def InfoDialog( title, text ):
92+
return TkDialog( title, text, 'showinfo' )
93+
def WarningDialog( title, text ):
94+
return TkDialog( title, text, 'showwarning' )
95+
def ErrorDialog( title, text ):
96+
return TkDialog( title, text, 'showerror' )
97+
def QuestionDialog( title, text ):
98+
return TkDialog( title, text, 'askquestion' )
99+
def OkCancelDialog( title, text ):
100+
return TkDialog( title, text, 'askokcancel' )
101+
def RetryCancelDialog( title, text ):
102+
return TkDialog( title, text, 'askretrycancel' )
103+
def YesNoDialog( title, text ):
104+
return TkDialog( title, text, 'askyesno' )
105+
def ConfirmDialog( title, text ):
106+
return TkDialog( title, text, 'askyesno' )
107+
def YesNoCancelDialog( title, text ):
108+
return TkDialog( title, text, 'askyesnocancel' )
90109

0 commit comments

Comments
 (0)