Skip to content

refactor how the generator for the module_firmware_index.json works #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 9, 2021
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.
439 changes: 0 additions & 439 deletions firmwares/NINA/FirmwareUpdater.unowifirev2.without_bl.ino.hex

This file was deleted.

File renamed without changes.
Binary file not shown.
97 changes: 97 additions & 0 deletions generator/boards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"arduino:samd:mkr1000":{
"moduleName":"WINC1500",
"versions":[
"19.4.4",
"19.5.2",
"19.5.4",
"19.6.1"
]
},
"arduino:samd:mkrwifi1010":{
"moduleName":"NINA",
"versions":[
"1.0.0",
"1.1.0",
"1.2.1",
"1.2.2",
"1.2.3",
"1.2.4",
"1.3.0",
"1.4.0",
"1.4.1",
"1.4.2",
"1.4.3",
"1.4.4",
"1.4.5",
"1.4.6",
"1.4.7"
]
},
"arduino:samd:nano_33_iot":{
"moduleName":"NINA",
"versions":[
"1.0.0",
"1.1.0",
"1.2.1",
"1.2.2",
"1.2.3",
"1.2.4",
"1.3.0",
"1.4.0",
"1.4.1",
"1.4.2",
"1.4.3",
"1.4.4",
"1.4.5",
"1.4.6",
"1.4.7"
]
},
"arduino:samd:mkrvidor4000":{
"moduleName":"NINA",
"versions":[
"1.0.0",
"1.1.0",
"1.2.1",
"1.2.2",
"1.2.3",
"1.2.4",
"1.3.0",
"1.4.0",
"1.4.1",
"1.4.2",
"1.4.3",
"1.4.4",
"1.4.5",
"1.4.6",
"1.4.7"
]
},
"arduino:megaavr:uno2018":{
"moduleName":"NINA",
"versions":[
"1.2.1",
"1.2.2",
"1.2.3",
"1.2.4",
"1.3.0",
"1.4.0",
"1.4.1",
"1.4.2",
"1.4.3",
"1.4.4",
"1.4.5",
"1.4.6",
"1.4.7"
]
},
"arduino:mbed_nano:nanorp2040connect":{
"moduleName":"NINA",
"versions":[
"1.4.5",
"1.4.6",
"1.4.7"
]
}
}
48 changes: 26 additions & 22 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import json
import hashlib
import shutil
import os
from pathlib import Path

DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"
FQBNS = {
"mkr1000": "arduino:samd:mkr1000",
"mkrwifi1010": "arduino:samd:mkrwifi1010",
"nano_33_iot": "arduino:samd:nano_33_iot",
"mkrvidor4000": "arduino:samd:mkrvidor4000",
"uno2018": "arduino:megaavr:uno2018",
"nanorp2040connect": "arduino:mbed_nano:nanorp2040connect",
}


# handle firmware name
def get_firmware_file(module, simple_fqbn, version):
file = Path(f'{module}-{simple_fqbn}.bin')
default_file = Path(f'{module}.bin')
firmware_path = f"firmwares/{module}/{version}/{file}"
firmware_full_path = Path(__file__).parent / ".." / firmware_path
if firmware_full_path.exists():
return firmware_full_path
return Path(str(firmware_full_path).replace(str(file), str(default_file)))


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

for pseudo_fqbn, data in input_data.items():
fqbn = FQBNS[pseudo_fqbn]
for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

for _, v in data.items():
item = v[0]
binary = Path(__file__).parent / ".." / item["Path"]
loader_dir = f"../firmwares/loader/{simple_fqbn}/"
loader_path = (
Path(__file__).parent / loader_dir / os.listdir(loader_dir)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am not sure I understand this line, why are you taking the first result of os.listdir?

I don't think this a good thing to do, the documentation says this:

The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory.

https://docs.python.org/3/library/os.html#os.listdir

Also might as well use Path.iterdir() since we're using pathlib: https://docs.python.org/3/library/pathlib.html#pathlib.Path.iterdir

) # there's only one loader bin in every fqbn dir
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, loader_path)

if item["IsLoader"]:
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, binary)
else:
module, version = item["version"].split("/")
boards[fqbn]["firmware"].append(create_firmware_data(binary, module, version))
boards[fqbn]["module"] = module
for firmware_version in data["versions"]:
module = data["moduleName"]
firmware_file = get_firmware_file(module, simple_fqbn, firmware_version)
boards[fqbn]["firmware"].append(create_firmware_data(firmware_file, module, firmware_version))
boards[fqbn]["module"] = module

res = arduino_cli(
cli_path=arduino_cli_path,
Expand Down Expand Up @@ -278,10 +282,10 @@ def generate_boards_json(input_data, arduino_cli_path):

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

boards_json = generate_boards_json(raw_boards, args.arduino_cli)
boards_json = generate_boards_json(boards, args.arduino_cli)

Path("boards").mkdir()

Expand Down
Loading