@@ -38,7 +38,7 @@ def split_property_and_drop_first_level(s):
38
38
39
39
# Generate and copy loader Sketch binary data for specified board
40
40
def create_loader_data (simple_fqbn , binary ):
41
- loader_path = f"firmwares/loader/{ simple_fqbn } /loader.bin "
41
+ loader_path = f"firmwares/loader/{ simple_fqbn } /loader{ binary . suffix } "
42
42
loader = Path (__file__ ).parent / loader_path
43
43
loader .parent .mkdir (parents = True , exist_ok = True )
44
44
shutil .copyfile (binary , loader )
@@ -79,7 +79,7 @@ def get_uploader_id(tools, tool_executable):
79
79
return f"{ packager } :{ name } @{ version } "
80
80
81
81
82
- def create_upload_data (fqbn , installed_cores ):
82
+ def create_upload_data (fqbn , installed_cores ): # noqa: C901
83
83
upload_data = {}
84
84
# Assume we're on Linux
85
85
arduino15 = Path .home () / ".arduino15"
@@ -90,16 +90,14 @@ def create_upload_data(fqbn, installed_cores):
90
90
# Get the core install dir
91
91
core = installed_cores [core_id ]
92
92
(maintainer , arch ) = core_id .split (":" )
93
- core_install_dir = (
94
- arduino15 / "packages" / maintainer / "hardware" / arch / core ["installed" ]
95
- )
93
+ core_install_dir = arduino15 / "packages" / maintainer / "hardware" / arch / core ["installed" ]
96
94
97
95
with open (core_install_dir / "boards.txt" ) as f :
98
96
boards_txt = f .readlines ()
99
97
100
98
board_upload_data = {}
101
99
for line in boards_txt :
102
- if line .startswith (f"{ board_id } .upload " ):
100
+ if line .startswith (f"{ board_id } ." ):
103
101
(k , v ) = split_property_and_drop_first_level (line )
104
102
board_upload_data [k ] = v
105
103
@@ -110,7 +108,7 @@ def create_upload_data(fqbn, installed_cores):
110
108
111
109
platform_upload_data = {}
112
110
for line in platform_txt :
113
- if line .startswith (f"tools.{ tool } " ):
111
+ if line .startswith (f"tools.{ tool } . " ):
114
112
(k , v ) = split_property_and_drop_first_level (line )
115
113
platform_upload_data [k ] = v
116
114
@@ -129,12 +127,11 @@ def create_upload_data(fqbn, installed_cores):
129
127
tools = installed_json_data ["packages" ][0 ]["platforms" ][0 ]["toolsDependencies" ]
130
128
upload_data ["uploader" ] = get_uploader_id (tools , tool_executable )
131
129
132
- # We already store the tool name in a different manner
133
- del board_upload_data ["upload.tool" ]
134
- # Save also all the upload properties
135
- for k , v in board_upload_data .items ():
136
- if v :
137
- upload_data [k ] = v
130
+ if "upload.use_1200bps_touch" in board_upload_data :
131
+ upload_data ["upload.use_1200bps_touch" ] = board_upload_data ["upload.use_1200bps_touch" ]
132
+
133
+ if "upload.wait_for_upload_port" in board_upload_data :
134
+ upload_data ["upload.wait_for_upload_port" ] = board_upload_data ["upload.wait_for_upload_port" ]
138
135
139
136
# Get the command used to upload and modifies it a bit
140
137
command = (
@@ -145,6 +142,26 @@ def create_upload_data(fqbn, installed_cores):
145
142
.replace ('\\ "' , "" )
146
143
)
147
144
145
+ if fqbn == "arduino:megaavr:uno2018" :
146
+ # Long story short if we don't do this we'd have to host also the bootloader
147
+ # for the Uno WiFi rev2 and we don't want to, so we just remove this field
148
+ # and use a precompiled Loader Sketh binary that includes the bootloader.
149
+ command = command .replace ("{upload.extra_files}" , "" )
150
+
151
+ # Get the rest of the params
152
+ params = {}
153
+ for k , v in platform_upload_data .items ():
154
+ if f"{ tool } .upload.params." in k :
155
+ param = k .split ("." )[- 1 ]
156
+ params [f"upload.{ param } " ] = v
157
+ elif f"{ tool } .upload." in k :
158
+ k = "." .join (k .split ("." )[1 :])
159
+ params [k ] = v
160
+
161
+ # Prepare the command
162
+ for k , v in {** board_upload_data , ** params }.items ():
163
+ command = command .replace (f"{{{ k } }}" , v )
164
+
148
165
upload_data ["uploader.command" ] = command
149
166
150
167
return upload_data
@@ -174,9 +191,7 @@ def generate_boards_json(input_data, arduino_cli_path):
174
191
}
175
192
176
193
# Gets the installed cores
177
- res = arduino_cli (
178
- cli_path = arduino_cli_path , args = ["core" , "list" , "--format" , "json" ]
179
- )
194
+ res = arduino_cli (cli_path = arduino_cli_path , args = ["core" , "list" , "--format" , "json" ])
180
195
installed_cores = {c ["id" ]: c for c in json .loads (res )}
181
196
182
197
# Verify all necessary cores are installed
@@ -193,15 +208,13 @@ def generate_boards_json(input_data, arduino_cli_path):
193
208
194
209
for _ , v in data .items ():
195
210
item = v [0 ]
196
- binary = Path (item ["Path" ])
211
+ binary = Path (__file__ ). parent / ".." / item ["Path" ]
197
212
198
213
if item ["IsLoader" ]:
199
214
boards [fqbn ]["loader_sketch" ] = create_loader_data (simple_fqbn , binary )
200
215
else :
201
216
module , version = item ["version" ].split ("/" )
202
- boards [fqbn ]["firmware" ].append (
203
- create_firmware_data (binary , module , version )
204
- )
217
+ boards [fqbn ]["firmware" ].append (create_firmware_data (binary , module , version ))
205
218
boards [fqbn ]["module" ] = module
206
219
207
220
res = arduino_cli (
0 commit comments