Skip to content

Commit e241f76

Browse files
Migrate Nina firmwares to plugin system (#208)
* move boards to new_boards in order to add to plugin * move nina boards to the plugin system * remove useless sketches, in the plugin they are hardcoded * remove core installation from CI, this is no more required with the plugin system * move all the info required to support a plugin board inside `new_boards.json` file This way we have to modify this file only to add support for new boards. The `generate_boards_json()` function have been split: this way we can remove the old one when the time comes. * fix formatting * fix wrong loader for rp2040 --------- Co-authored-by: Alessio Perugini <[email protected]>
1 parent 61e036b commit e241f76

File tree

12 files changed

+140
-1106
lines changed

12 files changed

+140
-1106
lines changed

Diff for: .github/workflows/generate-index.yml

-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ jobs:
4444
arduino-cli core update-index -v
4545
arduino-cli version
4646
arduino-cli core install arduino:samd@${{ env.SAMD_V }} -v
47-
arduino-cli core install arduino:megaavr@${{ env.MEGAAVR_V }} -v
48-
arduino-cli core install arduino:mbed_nano@${{ env.MBED_NANO_V }} -v
4947
env:
5048
SAMD_V: 1.8.11
51-
MEGAAVR_V: 1.8.7
52-
MBED_NANO_V: 2.4.1
5349

5450
- name: Install dependencies
5551
run: |
Binary file not shown.

Diff for: firmwares/getversion/arduino.megaavr.uno2018/CheckFirmwareVersion.ino.with_bootloader.hex

-533
This file was deleted.
Binary file not shown.
Binary file not shown.
-1.6 MB
Binary file not shown.

Diff for: firmwares/loader/arduino.megaavr.uno2018/loader.hex

-433
This file was deleted.

Diff for: firmwares/loader/arduino.samd.mkrwifi1010/loader.bin

-13.4 KB
Binary file not shown.

Diff for: firmwares/loader/arduino.samd.nano_33_iot/loader.bin

-14 KB
Binary file not shown.

Diff for: generator/boards.json

-68
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,8 @@
33
"moduleName": "WINC1500",
44
"versions": ["19.4.4", "19.5.2", "19.5.4", "19.6.1"]
55
},
6-
"arduino:samd:mkrwifi1010": {
7-
"moduleName": "NINA",
8-
"versions": [
9-
"1.0.0",
10-
"1.1.0",
11-
"1.2.1",
12-
"1.2.2",
13-
"1.2.3",
14-
"1.2.4",
15-
"1.3.0",
16-
"1.4.0",
17-
"1.4.1",
18-
"1.4.2",
19-
"1.4.3",
20-
"1.4.4",
21-
"1.4.5",
22-
"1.4.6",
23-
"1.4.7",
24-
"1.4.8",
25-
"1.5.0"
26-
]
27-
},
28-
"arduino:samd:nano_33_iot": {
29-
"moduleName": "NINA",
30-
"versions": [
31-
"1.0.0",
32-
"1.1.0",
33-
"1.2.1",
34-
"1.2.2",
35-
"1.2.3",
36-
"1.2.4",
37-
"1.3.0",
38-
"1.4.0",
39-
"1.4.1",
40-
"1.4.2",
41-
"1.4.3",
42-
"1.4.4",
43-
"1.4.5",
44-
"1.4.6",
45-
"1.4.7",
46-
"1.4.8",
47-
"1.5.0"
48-
]
49-
},
506
"arduino:samd:mkrvidor4000": {
517
"moduleName": "NINA",
528
"versions": ["1.0.0", "1.1.0"]
53-
},
54-
"arduino:megaavr:uno2018": {
55-
"moduleName": "NINA",
56-
"versions": [
57-
"1.2.1",
58-
"1.2.2",
59-
"1.2.3",
60-
"1.2.4",
61-
"1.3.0",
62-
"1.4.0",
63-
"1.4.1",
64-
"1.4.2",
65-
"1.4.3",
66-
"1.4.4",
67-
"1.4.5",
68-
"1.4.6",
69-
"1.4.7",
70-
"1.4.8",
71-
"1.5.0"
72-
]
73-
},
74-
"arduino:mbed_nano:nanorp2040connect": {
75-
"moduleName": "NINA",
76-
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"]
779
}
7810
}

Diff for: generator/generator.py

+52-67
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,6 @@
2626
DOWNLOAD_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:[email protected]",
59-
"additional_tools": ["arduino:[email protected]", "arduino:[email protected]"],
60-
},
61-
}
62-
return boards
63-
64-
6529
# handle firmware name
6630
def get_firmware_file(module, simple_fqbn, version):
6731
firmware_full_path = Path(__file__).parent.parent / "firmwares" / module / version
@@ -258,50 +222,42 @@ def create_upload_data(fqbn, installed_cores): # noqa: C901
258222
return upload_data
259223

260224

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)
225+
def generate_boards_json(input_data, arduino_cli_path):
226+
boards = {
227+
"arduino:samd:mkr1000": {"fqbn": "arduino:samd:mkr1000", "firmware": []},
228+
"arduino:samd:mkrvidor4000": {
229+
"fqbn": "arduino:samd:mkrvidor4000",
230+
"firmware": [],
231+
},
232+
}
273233

274234
# Gets the installed cores
275235
res = arduino_cli(cli_path=arduino_cli_path, args=["core", "list", "--format", "json"])
276236
installed_cores = {c["id"]: c for c in json.loads(res)}
277237

278238
# Verify all necessary cores are installed
279239
# TODO: Should we check that the latest version is installed too?
280-
for fqbn in old_boards:
240+
for fqbn, data in input_data.items():
281241
core_id = ":".join(fqbn.split(":")[:2])
282242
if core_id not in installed_cores:
283243
print(f"Board {fqbn} is not installed, install its core {core_id}")
284244
sys.exit(1)
285245

286-
for fqbn, data in input_data.items():
287246
simple_fqbn = fqbn.replace(":", ".")
288247

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")
292-
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
293-
# Gets the old_board name
294-
res = arduino_cli(
295-
cli_path=arduino_cli_path,
296-
args=["board", "search", fqbn, "--format", "json"],
297-
)
298-
for board in json.loads(res):
299-
if board["fqbn"] == fqbn:
300-
boards[fqbn]["name"] = board["name"]
301-
break
302-
303-
else:
304-
boards[fqbn]["name"] = data["name"]
248+
# List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
249+
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
250+
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
251+
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
252+
# Gets the old_board name
253+
res = arduino_cli(
254+
cli_path=arduino_cli_path,
255+
args=["board", "search", fqbn, "--format", "json"],
256+
)
257+
for board in json.loads(res):
258+
if board["fqbn"] == fqbn:
259+
boards[fqbn]["name"] = board["name"]
260+
break
305261

306262
for firmware_version in data["versions"]:
307263
module = data["moduleName"]
@@ -316,6 +272,32 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
316272
return boards_json
317273

318274

275+
def generate_new_boards_json(input_data):
276+
# init the boards dict
277+
boards = {}
278+
for fqbn, data in input_data.items():
279+
simple_fqbn = fqbn.replace(":", ".")
280+
281+
# populate the boards dict
282+
boards[fqbn] = {}
283+
boards[fqbn]["fqbn"] = fqbn
284+
module = data["moduleName"]
285+
boards[fqbn]["firmware"] = []
286+
for firmware_version in data["versions"]:
287+
firmware_file = get_firmware_file(module, simple_fqbn, firmware_version)
288+
boards[fqbn]["firmware"].append(create_firmware_data(firmware_file, module, firmware_version))
289+
boards[fqbn]["uploader_plugin"] = data["uploader_plugin"]
290+
boards[fqbn]["additional_tools"] = data["additional_tools"]
291+
boards[fqbn]["module"] = module
292+
boards[fqbn]["name"] = data["name"]
293+
294+
boards_json = []
295+
for _, b in boards.items():
296+
boards_json.append(b)
297+
298+
return boards_json
299+
300+
319301
if __name__ == "__main__":
320302
parser = argparse.ArgumentParser(prog="generator.py")
321303
parser.add_argument(
@@ -345,7 +327,10 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
345327
with open(input_file, "r") as f:
346328
boards = json.load(f)
347329

348-
boards_json = generate_boards_json(boards, args.arduino_cli, args.new)
330+
if args.new:
331+
boards_json = generate_new_boards_json(boards)
332+
else:
333+
boards_json = generate_boards_json(boards, args.arduino_cli)
349334

350335
Path("boards").mkdir(exist_ok=True)
351336

Diff for: generator/new_boards.json

+88-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,93 @@
22
"arduino:renesas_uno:unor4wifi": {
33
"moduleName": "ESP32-S3",
44
"versions": ["0.1.0", "0.2.0", "0.2.1"],
5-
"name": "Arduino UNO R4 WiFi"
5+
"name": "Arduino UNO R4 WiFi",
6+
"uploader_plugin": "arduino:[email protected]",
7+
"additional_tools": ["arduino:[email protected]", "arduino:[email protected]"],
8+
"module": "ESP32-S3"
9+
},
10+
"arduino:samd:mkrwifi1010": {
11+
"moduleName": "NINA",
12+
"versions": [
13+
"1.0.0",
14+
"1.1.0",
15+
"1.2.1",
16+
"1.2.2",
17+
"1.2.3",
18+
"1.2.4",
19+
"1.3.0",
20+
"1.4.0",
21+
"1.4.1",
22+
"1.4.2",
23+
"1.4.3",
24+
"1.4.4",
25+
"1.4.5",
26+
"1.4.6",
27+
"1.4.7",
28+
"1.4.8",
29+
"1.5.0"
30+
],
31+
"name": "Arduino MKR WiFi 1010",
32+
"uploader_plugin": "arduino:[email protected]",
33+
"additional_tools": ["arduino:[email protected]"],
34+
"module": "NINA"
35+
},
36+
"arduino:samd:nano_33_iot": {
37+
"moduleName": "NINA",
38+
"versions": [
39+
"1.0.0",
40+
"1.1.0",
41+
"1.2.1",
42+
"1.2.2",
43+
"1.2.3",
44+
"1.2.4",
45+
"1.3.0",
46+
"1.4.0",
47+
"1.4.1",
48+
"1.4.2",
49+
"1.4.3",
50+
"1.4.4",
51+
"1.4.5",
52+
"1.4.6",
53+
"1.4.7",
54+
"1.4.8",
55+
"1.5.0"
56+
],
57+
"name": "Arduino NANO 33 IoT",
58+
"uploader_plugin": "arduino:[email protected]",
59+
"additional_tools": ["arduino:[email protected]"],
60+
"module": "NINA"
61+
},
62+
"arduino:megaavr:uno2018": {
63+
"moduleName": "NINA",
64+
"versions": [
65+
"1.2.1",
66+
"1.2.2",
67+
"1.2.3",
68+
"1.2.4",
69+
"1.3.0",
70+
"1.4.0",
71+
"1.4.1",
72+
"1.4.2",
73+
"1.4.3",
74+
"1.4.4",
75+
"1.4.5",
76+
"1.4.6",
77+
"1.4.7",
78+
"1.4.8",
79+
"1.5.0"
80+
],
81+
"name": "Arduino Uno WiFi Rev2",
82+
"uploader_plugin": "arduino:[email protected]",
83+
"additional_tools": ["arduino:[email protected]"],
84+
"module": "NINA"
85+
},
86+
"arduino:mbed_nano:nanorp2040connect": {
87+
"moduleName": "NINA",
88+
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"],
89+
"name": "Arduino Nano RP2040 Connect",
90+
"uploader_plugin": "arduino:[email protected]",
91+
"additional_tools": ["arduino:[email protected]"],
92+
"module": "NINA"
693
}
794
}

0 commit comments

Comments
 (0)