2626DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"
2727
2828
29+ # create a different dictionary for new boards
30+ def create_boards_dictionary (new ):
31+ boards = {
32+ "arduino:samd:mkr1000" : {"fqbn" : "arduino:samd:mkr1000" , "firmware" : []},
33+ "arduino:samd:mkrwifi1010" : {
34+ "fqbn" : "arduino:samd:mkrwifi1010" ,
35+ "firmware" : [],
36+ },
37+ "arduino:samd:nano_33_iot" : {
38+ "fqbn" : "arduino:samd:nano_33_iot" ,
39+ "firmware" : [],
40+ },
41+ "arduino:samd:mkrvidor4000" : {
42+ "fqbn" : "arduino:samd:mkrvidor4000" ,
43+ "firmware" : [],
44+ },
45+ "arduino:megaavr:uno2018" : {"fqbn" : "arduino:megaavr:uno2018" , "firmware" : []},
46+ "arduino:mbed_nano:nanorp2040connect" : {
47+ "fqbn" : "arduino:mbed_nano:nanorp2040connect" ,
48+ "firmware" : [],
49+ },
50+ }
51+ if new :
52+ boards = {
53+ "arduino:renesas_uno:unor4wifi" : {
54+ "fqbn" : "arduino:renesas_uno:unor4wifi" ,
55+ "firmware" : [],
56+ # "uploader_plugin" and "additional_tools" need to be hard coded because
57+ # there is no way to retrieve them dinamically
58+ "uploader_plugin" : "arduino:uno-r4-wifi-fwuploader@1.0.0" ,
59+ "additional_tools" : ["arduino:espflash@2.0.0" , "arduino:bossac@1.9.1-arduino5" ],
60+ },
61+ }
62+ return boards
63+
64+
2965# handle firmware name
3066def get_firmware_file (module , simple_fqbn , version ):
3167 firmware_full_path = Path (__file__ ).parent .parent / "firmwares" / module / version
@@ -222,35 +258,26 @@ def create_upload_data(fqbn, installed_cores): # noqa: C901
222258 return upload_data
223259
224260
225- def generate_boards_json (input_data , arduino_cli_path ):
226- boards = {
227- "arduino:samd:mkr1000" : {"fqbn" : "arduino:samd:mkr1000" , "firmware" : []},
228- "arduino:samd:mkrwifi1010" : {
229- "fqbn" : "arduino:samd:mkrwifi1010" ,
230- "firmware" : [],
231- },
232- "arduino:samd:nano_33_iot" : {
233- "fqbn" : "arduino:samd:nano_33_iot" ,
234- "firmware" : [],
235- },
236- "arduino:samd:mkrvidor4000" : {
237- "fqbn" : "arduino:samd:mkrvidor4000" ,
238- "firmware" : [],
239- },
240- "arduino:megaavr:uno2018" : {"fqbn" : "arduino:megaavr:uno2018" , "firmware" : []},
241- "arduino:mbed_nano:nanorp2040connect" : {
242- "fqbn" : "arduino:mbed_nano:nanorp2040connect" ,
243- "firmware" : [],
244- },
245- }
261+ def generate_boards_json (input_data , arduino_cli_path , new_boards ):
262+ # List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
263+ old_boards = [
264+ "arduino:samd:mkr1000" ,
265+ "arduino:samd:mkrwifi1010" ,
266+ "arduino:samd:nano_33_iot" ,
267+ "arduino:samd:mkrvidor4000" ,
268+ "arduino:megaavr:uno2018" ,
269+ "arduino:mbed_nano:nanorp2040connect" ,
270+ ]
271+
272+ boards = create_boards_dictionary (new_boards )
246273
247274 # Gets the installed cores
248275 res = arduino_cli (cli_path = arduino_cli_path , args = ["core" , "list" , "--format" , "json" ])
249276 installed_cores = {c ["id" ]: c for c in json .loads (res )}
250277
251278 # Verify all necessary cores are installed
252279 # TODO: Should we check that the latest version is installed too?
253- for fqbn in boards . keys () :
280+ for fqbn in old_boards :
254281 core_id = ":" .join (fqbn .split (":" )[:2 ])
255282 if core_id not in installed_cores :
256283 print (f"Board { fqbn } is not installed, install its core { core_id } " )
@@ -259,8 +286,9 @@ def generate_boards_json(input_data, arduino_cli_path):
259286 for fqbn , data in input_data .items ():
260287 simple_fqbn = fqbn .replace (":" , "." )
261288
262- boards [fqbn ]["loader_sketch" ] = create_precomp_sketch_data (simple_fqbn , "loader" )
263- boards [fqbn ]["version_sketch" ] = create_precomp_sketch_data (simple_fqbn , "getversion" )
289+ if fqbn in old_boards :
290+ boards [fqbn ]["loader_sketch" ] = create_precomp_sketch_data (simple_fqbn , "loader" )
291+ boards [fqbn ]["version_sketch" ] = create_precomp_sketch_data (simple_fqbn , "getversion" )
264292
265293 for firmware_version in data ["versions" ]:
266294 module = data ["moduleName" ]
@@ -278,7 +306,8 @@ def generate_boards_json(input_data, arduino_cli_path):
278306 boards [fqbn ]["name" ] = board ["name" ]
279307 break
280308
281- boards [fqbn ].update (create_upload_data (fqbn , installed_cores ))
309+ if fqbn in old_boards :
310+ boards [fqbn ].update (create_upload_data (fqbn , installed_cores ))
282311
283312 boards_json = []
284313 for _ , b in boards .items ():
@@ -296,18 +325,31 @@ def generate_boards_json(input_data, arduino_cli_path):
296325 help = "Path to arduino-cli executable" ,
297326 required = True ,
298327 )
328+ parser .add_argument (
329+ "--new" ,
330+ action = argparse .BooleanOptionalAction ,
331+ default = True ,
332+ help = "Generate the index for old boards" ,
333+ )
299334 args = parser .parse_args (sys .argv [1 :])
300335
336+ if args .new :
337+ input_file = "new_boards.json"
338+ output_file = "plugin_firmware_index.json"
339+ else :
340+ input_file = "boards.json"
341+ output_file = "module_firmware_index.json"
342+
301343 # raw_boards.json has been generated using --get_available_for FirmwareUploader (version 0.1.8) flag.
302344 # It has been edited a bit to better handle parsing.
303- with open ("boards.json" , "r" ) as f :
345+ with open (input_file , "r" ) as f :
304346 boards = json .load (f )
305347
306- boards_json = generate_boards_json (boards , args .arduino_cli )
348+ boards_json = generate_boards_json (boards , args .arduino_cli , args . new )
307349
308- Path ("boards" ).mkdir ()
350+ Path ("boards" ).mkdir (exist_ok = True )
309351
310- with open ("boards/module_firmware_index.json" , "w" ) as f :
352+ with open ("boards/" + output_file , "w" ) as f :
311353 json .dump (boards_json , f , indent = 2 )
312354
313355# board_index.json must be formatted like so:
0 commit comments