Skip to content

Commit 385f7d0

Browse files
Generate plugin_firmware_index.json with new boards data (#172)
* Add arduino uno r4 to boards.json * Add arduino uno r4 to the generated boards json * Do not use precompiled sketches and skip core installation for new boards * Hard code uploader_plugin and additional_tools * Add ESP32-S3 firmwares * replace uno r4 placeholder fw with released ones * Add mkr wifi 1010 to old_boards * Create a different json for the new boards * Use the same directory for both of the json files * Add plugin firmware index generation steps to the workflow * Reduce complexity using a new function to create the starting dictionary --------- Co-authored-by: Umberto Baldi <[email protected]>
1 parent 2c15254 commit 385f7d0

File tree

5 files changed

+91
-32
lines changed

5 files changed

+91
-32
lines changed

.github/workflows/generate-index.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ jobs:
5656
cd $GITHUB_WORKSPACE
5757
task poetry:install-deps
5858
59-
- name: Generate index
59+
- name: Generate plugin firmware index
6060
run: poetry run ./generator.py -a $(which arduino-cli)
6161

62+
- name: Generate module firmware index
63+
run: poetry run ./generator.py -a $(which arduino-cli) --no-new
64+
6265
# fix `gpg: signing failed: Inappropriate ioctl for device`
6366
# https://github.com/keybase/keybase-issues/issues/2798
6467
- name: Import GPG key
@@ -69,16 +72,24 @@ jobs:
6972
7073
# disable gpg pass prompt
7174
# https://stackoverflow.com/questions/49072403/suppress-the-passphrase-prompt-in-gpg-command
72-
- name: sign the json
75+
- name: sign the module firmware index json
7376
run: |
7477
gpg \
7578
--pinentry-mode=loopback \
7679
--passphrase "${{ secrets.PASSPHRASE }}" \
7780
--output boards/module_firmware_index.json.sig \
7881
--detach-sign boards/module_firmware_index.json
7982
83+
- name: sign the plugin firmware index json
84+
run: |
85+
gpg \
86+
--pinentry-mode=loopback \
87+
--passphrase "${{ secrets.PASSPHRASE }}" \
88+
--output boards/plugin_firmware_index.json.sig \
89+
--detach-sign boards/plugin_firmware_index.json
90+
8091
- name: create the gzip
81-
run: gzip --keep boards/module_firmware_index.json
92+
run: gzip --keep boards/module_firmware_index.json boards/plugin_firmware_index.json
8293

8394
- name: s3 sync
8495
run: |

firmwares/ESP32-S3/0.1.0/ESP32-S3.bin

3.77 MB
Binary file not shown.

firmwares/ESP32-S3/0.2.0/ESP32-S3.bin

3.77 MB
Binary file not shown.

generator/generator.py

+71-29
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@
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+
2965
# handle firmware name
3066
def 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:

generator/new_boards.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arduino:renesas_uno:unor4wifi": {
3+
"moduleName": "ESP32-S3",
4+
"versions": ["0.1.0", "0.2.0"]
5+
}
6+
}

0 commit comments

Comments
 (0)