Skip to content

Commit 201fb75

Browse files
committed
Restart for PR "Integrated handling for filesystem and gzipped Binaries"
1 parent 40b26b7 commit 201fb75

File tree

9 files changed

+1307
-63
lines changed

9 files changed

+1307
-63
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ boards.local.txt
2626
.vs/
2727
__vm/
2828
*.vcxproj*
29+
30+
#Ignore files generated by boards.txt.py
31+
*.orig
32+
tools/sdk/ld/backup/*
33+
34+
#Ignore my extra files
35+
*.odt*
36+
tools/Gui.py
37+
tools/Replace2SpceWith4.txt
38+
*(Kopie)*
39+
platform.local.txt
40+
41+

boards.txt

Lines changed: 669 additions & 0 deletions
Large diffs are not rendered by default.

doc/filesystem.rst

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,53 @@ 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 (combined firmware and filesystem)
196+
-----------------------------------------------------------------
197+
198+
Since PullRequest #???? 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+
Its configuration has 3 entries (“Upload”, "Filesystem" and "Export") in
203+
the IDE's "Tools" menu, and is described as follows:
204+
205+
Menu-Entry “Upload” lets You choose between:
206+
- Sketch
207+
- Filesystem
208+
- Both
209+
This Menu controls which parts are uploaded when "Sketch->Upload" (Ctrl-U)
210+
is selected from the Arduino Menu.
211+
212+
Menu-Entry “Filesystem” lets You choose between:
213+
- Off
214+
- LitteFs
215+
- SPIFFS
216+
This Menu controls which Fs will be created when "Sketch->Compile" (Ctrl-R)
217+
is selected from the Arduino Menu. The Fs will always be created inside the
218+
"export" dir (see below).
219+
220+
Menu-Entry “Export” let You choose between:
221+
- Off
222+
- .bin & .bin.signed)
223+
- Create & Export gzipped Binaries too
224+
This Menu controls export & generation of (extra) Sketch-Binaries.
225+
226+
The "export" dir
227+
................
228+
After a (successful) compile, the files will be exported to a subdir
229+
“bin/{variant}” of Your sketch directory
230+
(“{variant}” replaced with the name of the board as shown behind
231+
“Tools -> Board:”).
232+
Signed variants of all Binaries are generated similar to the
233+
“automatic signing” done for normal sketch binary.
234+
235+
As valid for the "old" tools mentioned below, it is nessesary to place
236+
files you want to be inside the generated file system into a directory
237+
named ``data`` inside Your sketch directory.
238+
239+
240+
Uploading files to file system (old tools)
241+
------------------------------------------
197242

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

platform.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
2020
runtime.tools.mkdir={runtime.platform.path}/tools/mkdir.py
2121
runtime.tools.cp={runtime.platform.path}/tools/cp.py
2222
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
23+
runtime.tools.postbuild={runtime.platform.path}/tools/postbuild.py
2324

2425
compiler.warning_flags=-w -Werror=return-type
2526
compiler.warning_flags.none=-w -Werror=return-type
@@ -129,9 +130,14 @@ recipe.objcopy.hex.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime
129130
recipe.objcopy.hex.2.pattern="{runtime.tools.python3.path}/python3" -I "{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" --legacy "{build.path}/{build.project_name}.bin.legacy_sig"
130131
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}"
131132

133+
# 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}" -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}"
135+
132136
## Save hex
133-
recipe.output.tmp_file={build.project_name}.bin
134-
recipe.output.save_file={build.project_name}.{build.variant}.bin
137+
recipe.output.tmp_file.1={build.project_name}.bin
138+
recipe.output.save_file.1=bin/{build.variant}/{build.project_name}.bin
139+
recipe.output.tmp_file.2={build.project_name}.bin.signed
140+
recipe.output.save_file.2=bin/{build.variant}/{build.project_name}.bin.signed
135141

136142
## Compute size
137143
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
@@ -155,11 +161,8 @@ tools.esptool.upload.protocol=esp
155161
tools.esptool.upload.params.verbose=
156162
tools.esptool.upload.params.quiet=
157163

158-
# First, potentially perform an erase or nothing
159-
# Next, do the binary upload
160-
# Combined in one rule because Arduino doesn't support upload.1.pattern/upload.3.pattern
161-
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"
162-
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"
164+
tools.esptool.upload.pattern="{cmd}" -I "{runtime.platform.path}/tools/upload.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}"
165+
tools.esptool.upload.network_pattern="{network_cmd}" -I "{runtime.platform.path}/tools/netUpload.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}"
163166

164167
tools.mkspiffs.cmd=mkspiffs
165168
tools.mkspiffs.cmd.windows=mkspiffs.exe

tools/boards.txt.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,27 @@
10321032
( '.build.spiffs_pagesize', '256' ),
10331033
( '.build.debug_port', '' ),
10341034
( '.build.debug_level', '' ),
1035+
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+
1043+
( '.menu.Filesystem.Off', 'Off' ),
1044+
( '.menu.Filesystem.Off.build.Filesystem', '0' ),
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' ),
10351056
]),
10361057

10371058
#######################
@@ -1658,6 +1679,9 @@ def all_boards ():
16581679
print('menu.ssl=SSL Support')
16591680
print('menu.mmu=MMU')
16601681
print('menu.non32xfer=Non-32-Bit Access')
1682+
print('menu.Upload=Upload')
1683+
print('menu.Filesystem=Filesystem')
1684+
print('menu.Export=Export')
16611685
print('')
16621686

16631687
missingboards = []

tools/netUpload.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
3+
# Network-Upload-Wrapper
4+
# 2021-08-08: G.N.: Written to support (optional) uploading of sketch & filesystem in one step
5+
6+
import os
7+
import sys
8+
ToolsDir = os.path.dirname( os.path.realpath( __file__ ) ).replace( '\\', '/' ) + "/" # convert to UNIX format
9+
try:
10+
sys.path.insert( 0, ToolsDir ) # ToolsDir
11+
from utilities import * # If this fails, we can't continue and will bomb below
12+
except Exception as e:
13+
sys.stderr.write( '\nImport of utilities.py failed.\n...Is it not next to this %s tool?\n...Exception was: %s\n' % ( __file__, e ) )
14+
sys.exit( 2 )
15+
16+
try:
17+
sys.path.insert( 0, ToolsDir ) # Add this dir to search path
18+
import espota # If this fails, we can't continue and will bomb below
19+
except Exception:
20+
Msg( '\nespota not found next to this netUpload.py tool.' )
21+
sys.exit( 2 )
22+
23+
#Args: (original)
24+
# As defined in 'platform.txt' for 'tools.esptool.upload.network_pattern'
25+
# -i "{serial.port}"
26+
# -p "{network.port}"
27+
# "--auth={network.password}"
28+
# -f "{build.path}/{build.project_name}.bin"
29+
30+
#Args: (new)
31+
# As defined in 'platform.txt' for 'tools.esptool.upload.network_pattern'
32+
# | possible values/meaning
33+
# | |
34+
# -fi "{build.Filesystem}" 0-4
35+
# -i "{serial.port}"
36+
# -p "{network.port}"
37+
# "--auth={network.password}"
38+
# --sk "{build.path}/{build.project_name}.bin" <filePath for sketch-bin>
39+
# --fs "{build.path}/{build.project_name}" <filePath for fs.bin, without ext>
40+
41+
def parse_args( argsIn ):
42+
parser = argparse.ArgumentParser( description = 'Network-Upload-Wrapper for Arduino esp8266' )
43+
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' )
44+
parser.add_argument( '-i', '--port', type = str, required = True, help = 'path to serial device' )
45+
parser.add_argument( '-p', '--netPort', type = str, required = True, help = 'network port' )
46+
parser.add_argument( '--auth', type = str, help = 'network password' )
47+
parser.add_argument( '--sk', type = str, required = True, help = 'path_path_to_sketch_binary' )
48+
parser.add_argument( '--fs', type = str, help = 'path_to_fs_binary_without_ext' )
49+
global Args
50+
Args = parser.parse_args( argsIn )
51+
52+
def main( argsIn = None ):
53+
"""
54+
Main function for netUpload
55+
56+
argsIn - Optional override for default arguments parsing (that uses sys.argv), can be a list of custom arguments.
57+
Arguments and their values need to be added as individual items to the list e.g. "-b 115200" thus becomes ['-b', '115200'].
58+
"""
59+
60+
parse_args( argsIn )
61+
62+
if not os.path.exists( Args.port ):
63+
Msg( "Port: '%s', does not exist!\n...Upload aborted" % Args.port )
64+
sys.exit( 1 )
65+
66+
baseArgs = [ '-i', Args.port, '-p', Args.netPort, '--auth', Args.auth ]
67+
68+
sketchArgs = baseArgs + [ '-f', Args.sk ]
69+
70+
Msg( "Uploading Binaries..." )
71+
72+
#Debug( str( sketchArgs ) )
73+
esptool.main( sketchArgs )
74+
filesUploaded = [ Args.sk ]
75+
76+
if Args.Filesystem == 1 or Args.Filesystem == 3:
77+
fsArgs = baseArgs + [ '-s', '-f' ]
78+
if Args.Filesystem == 1:
79+
fsArgs = baseArgs + [ "%s.littlefs" % Args.fs ]
80+
elif Args.Filesystem == 3:
81+
fsArgs = baseArgs + [ "%s.spiffs" % Args.fs ]
82+
83+
#Debug( str( fsArgs ) )
84+
esptool.main( fsArgs )
85+
filesUploaded += [ Args.fs ]
86+
87+
Msg( '...files uploaded: %s' % ", ".join( filesUploaded ) )
88+
89+
def main_():
90+
try:
91+
main()
92+
except RuntimeError as e:
93+
Msg( '\nA RuntimeError error occurred: %s' % e )
94+
sys.exit( 2 )
95+
96+
if __name__ == '__main__':
97+
main_()
98+

0 commit comments

Comments
 (0)