Skip to content

Commit ae8295a

Browse files
authored
refactor how the generator for the module_firmware_index.json works (#84)
* remove old loader sketch * rename and reordered loader sketches * rename uno wifi r2 using true fqbn * rename nano rp 2040 connect using true fqbn * rename mkr1000 using true fqbn * add loader sketch for mkrvidor * refactor how the firmwares and loaders generation works * apply formatting * fix C901 'generate_boards_json' is too complex * rename firmware files to include the name of the module used * make function to retrieve firmware names generic: name now depends on the module * apply suggestions by @silvanocerza
1 parent 00b1d72 commit ae8295a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+128
-1035
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

firmwares/NINA/FirmwareUpdater.unowifirev2.without_bl.ino.hex

-439
This file was deleted.
Binary file not shown.

generator/boards.json

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"arduino:samd:mkr1000":{
3+
"moduleName":"WINC1500",
4+
"versions":[
5+
"19.4.4",
6+
"19.5.2",
7+
"19.5.4",
8+
"19.6.1"
9+
]
10+
},
11+
"arduino:samd:mkrwifi1010":{
12+
"moduleName":"NINA",
13+
"versions":[
14+
"1.0.0",
15+
"1.1.0",
16+
"1.2.1",
17+
"1.2.2",
18+
"1.2.3",
19+
"1.2.4",
20+
"1.3.0",
21+
"1.4.0",
22+
"1.4.1",
23+
"1.4.2",
24+
"1.4.3",
25+
"1.4.4",
26+
"1.4.5",
27+
"1.4.6",
28+
"1.4.7"
29+
]
30+
},
31+
"arduino:samd:nano_33_iot":{
32+
"moduleName":"NINA",
33+
"versions":[
34+
"1.0.0",
35+
"1.1.0",
36+
"1.2.1",
37+
"1.2.2",
38+
"1.2.3",
39+
"1.2.4",
40+
"1.3.0",
41+
"1.4.0",
42+
"1.4.1",
43+
"1.4.2",
44+
"1.4.3",
45+
"1.4.4",
46+
"1.4.5",
47+
"1.4.6",
48+
"1.4.7"
49+
]
50+
},
51+
"arduino:samd:mkrvidor4000":{
52+
"moduleName":"NINA",
53+
"versions":[
54+
"1.0.0",
55+
"1.1.0",
56+
"1.2.1",
57+
"1.2.2",
58+
"1.2.3",
59+
"1.2.4",
60+
"1.3.0",
61+
"1.4.0",
62+
"1.4.1",
63+
"1.4.2",
64+
"1.4.3",
65+
"1.4.4",
66+
"1.4.5",
67+
"1.4.6",
68+
"1.4.7"
69+
]
70+
},
71+
"arduino:megaavr:uno2018":{
72+
"moduleName":"NINA",
73+
"versions":[
74+
"1.2.1",
75+
"1.2.2",
76+
"1.2.3",
77+
"1.2.4",
78+
"1.3.0",
79+
"1.4.0",
80+
"1.4.1",
81+
"1.4.2",
82+
"1.4.3",
83+
"1.4.4",
84+
"1.4.5",
85+
"1.4.6",
86+
"1.4.7"
87+
]
88+
},
89+
"arduino:mbed_nano:nanorp2040connect":{
90+
"moduleName":"NINA",
91+
"versions":[
92+
"1.4.5",
93+
"1.4.6",
94+
"1.4.7"
95+
]
96+
}
97+
}

generator/generator.py

+31-22
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
from pathlib import Path
1010

1111
DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"
12-
FQBNS = {
13-
"mkr1000": "arduino:samd:mkr1000",
14-
"mkrwifi1010": "arduino:samd:mkrwifi1010",
15-
"nano_33_iot": "arduino:samd:nano_33_iot",
16-
"mkrvidor4000": "arduino:samd:mkrvidor4000",
17-
"uno2018": "arduino:megaavr:uno2018",
18-
"nanorp2040connect": "arduino:mbed_nano:nanorp2040connect",
19-
}
12+
13+
14+
# handle firmware name
15+
def get_firmware_file(module, simple_fqbn, version):
16+
firmware_full_path = Path(__file__).parent.parent / "firmwares" / module / version
17+
fqbn_specific_file_name = f"{module}-{simple_fqbn}.bin"
18+
if (firmware_file := firmware_full_path / fqbn_specific_file_name).exists():
19+
return firmware_file
20+
return firmware_full_path / f"{module}.bin"
2021

2122

2223
# Runs arduino-cli, doesn't handle errors at all because am lazy
@@ -231,20 +232,28 @@ def generate_boards_json(input_data, arduino_cli_path):
231232
print(f"Board {fqbn} is not installed, install its core {core_id}")
232233
sys.exit(1)
233234

234-
for pseudo_fqbn, data in input_data.items():
235-
fqbn = FQBNS[pseudo_fqbn]
235+
for fqbn, data in input_data.items():
236236
simple_fqbn = fqbn.replace(":", ".")
237237

238-
for _, v in data.items():
239-
item = v[0]
240-
binary = Path(__file__).parent / ".." / item["Path"]
238+
loader_dir = Path(
239+
"..",
240+
"firmwares",
241+
"loader",
242+
simple_fqbn,
243+
)
244+
loader_path = Path(__file__).parent / loader_dir
245+
loader_files = list(x for x in loader_path.iterdir() if x.is_file())
246+
if len(loader_files) != 1:
247+
print(f"Invalid loader files found in {loader_path}")
248+
sys.exit(1)
249+
250+
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, loader_files[0])
241251

242-
if item["IsLoader"]:
243-
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, binary)
244-
else:
245-
module, version = item["version"].split("/")
246-
boards[fqbn]["firmware"].append(create_firmware_data(binary, module, version))
247-
boards[fqbn]["module"] = module
252+
for firmware_version in data["versions"]:
253+
module = data["moduleName"]
254+
firmware_file = get_firmware_file(module, simple_fqbn, firmware_version)
255+
boards[fqbn]["firmware"].append(create_firmware_data(firmware_file, module, firmware_version))
256+
boards[fqbn]["module"] = module
248257

249258
res = arduino_cli(
250259
cli_path=arduino_cli_path,
@@ -278,10 +287,10 @@ def generate_boards_json(input_data, arduino_cli_path):
278287

279288
# raw_boards.json has been generated using --get_available_for FirmwareUploader (version 0.1.8) flag.
280289
# It has been edited a bit to better handle parsing.
281-
with open("raw_boards.json", "r") as f:
282-
raw_boards = json.load(f)
290+
with open("boards.json", "r") as f:
291+
boards = json.load(f)
283292

284-
boards_json = generate_boards_json(raw_boards, args.arduino_cli)
293+
boards_json = generate_boards_json(boards, args.arduino_cli)
285294

286295
Path("boards").mkdir()
287296

0 commit comments

Comments
 (0)