Skip to content

Commit

Permalink
Migrate Nina firmwares to plugin system (#208)
Browse files Browse the repository at this point in the history
* 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 <alessioper.98@gmail.com>
  • Loading branch information
umbynos and alessio-perugini committed Aug 9, 2023
1 parent 61e036b commit e241f76
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 1,106 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/generate-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ jobs:
arduino-cli core update-index -v
arduino-cli version
arduino-cli core install arduino:samd@${{ env.SAMD_V }} -v
arduino-cli core install arduino:megaavr@${{ env.MEGAAVR_V }} -v
arduino-cli core install arduino:mbed_nano@${{ env.MBED_NANO_V }} -v
env:
SAMD_V: 1.8.11
MEGAAVR_V: 1.8.7
MBED_NANO_V: 2.4.1

- name: Install dependencies
run: |
Expand Down
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
433 changes: 0 additions & 433 deletions firmwares/loader/arduino.megaavr.uno2018/loader.hex

This file was deleted.

Binary file removed firmwares/loader/arduino.samd.mkrwifi1010/loader.bin
Binary file not shown.
Binary file not shown.
68 changes: 0 additions & 68 deletions generator/boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,8 @@
"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",
"1.4.8",
"1.5.0"
]
},
"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",
"1.4.8",
"1.5.0"
]
},
"arduino:samd:mkrvidor4000": {
"moduleName": "NINA",
"versions": ["1.0.0", "1.1.0"]
},
"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",
"1.4.8",
"1.5.0"
]
},
"arduino:mbed_nano:nanorp2040connect": {
"moduleName": "NINA",
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"]
}
}
119 changes: 52 additions & 67 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,6 @@
DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"


# create a different dictionary for new boards
def create_boards_dictionary(new):
boards = {
"arduino:samd:mkr1000": {"fqbn": "arduino:samd:mkr1000", "firmware": []},
"arduino:samd:mkrwifi1010": {
"fqbn": "arduino:samd:mkrwifi1010",
"firmware": [],
},
"arduino:samd:nano_33_iot": {
"fqbn": "arduino:samd:nano_33_iot",
"firmware": [],
},
"arduino:samd:mkrvidor4000": {
"fqbn": "arduino:samd:mkrvidor4000",
"firmware": [],
},
"arduino:megaavr:uno2018": {"fqbn": "arduino:megaavr:uno2018", "firmware": []},
"arduino:mbed_nano:nanorp2040connect": {
"fqbn": "arduino:mbed_nano:nanorp2040connect",
"firmware": [],
},
}
if new:
boards = {
"arduino:renesas_uno:unor4wifi": {
"fqbn": "arduino:renesas_uno:unor4wifi",
"firmware": [],
# "uploader_plugin" and "additional_tools" need to be hard coded because
# there is no way to retrieve them dinamically
"uploader_plugin": "arduino:uno-r4-wifi-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:espflash@2.0.0", "arduino:bossac@1.9.1-arduino5"],
},
}
return boards


# handle firmware name
def get_firmware_file(module, simple_fqbn, version):
firmware_full_path = Path(__file__).parent.parent / "firmwares" / module / version
Expand Down Expand Up @@ -258,50 +222,42 @@ def create_upload_data(fqbn, installed_cores): # noqa: C901
return upload_data


def generate_boards_json(input_data, arduino_cli_path, new_boards):
# List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
old_boards = [
"arduino:samd:mkr1000",
"arduino:samd:mkrwifi1010",
"arduino:samd:nano_33_iot",
"arduino:samd:mkrvidor4000",
"arduino:megaavr:uno2018",
"arduino:mbed_nano:nanorp2040connect",
]

boards = create_boards_dictionary(new_boards)
def generate_boards_json(input_data, arduino_cli_path):
boards = {
"arduino:samd:mkr1000": {"fqbn": "arduino:samd:mkr1000", "firmware": []},
"arduino:samd:mkrvidor4000": {
"fqbn": "arduino:samd:mkrvidor4000",
"firmware": [],
},
}

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

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

for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

if fqbn in old_boards:
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
# Gets the old_board name
res = arduino_cli(
cli_path=arduino_cli_path,
args=["board", "search", fqbn, "--format", "json"],
)
for board in json.loads(res):
if board["fqbn"] == fqbn:
boards[fqbn]["name"] = board["name"]
break

else:
boards[fqbn]["name"] = data["name"]
# List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
# Gets the old_board name
res = arduino_cli(
cli_path=arduino_cli_path,
args=["board", "search", fqbn, "--format", "json"],
)
for board in json.loads(res):
if board["fqbn"] == fqbn:
boards[fqbn]["name"] = board["name"]
break

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


def generate_new_boards_json(input_data):
# init the boards dict
boards = {}
for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

# populate the boards dict
boards[fqbn] = {}
boards[fqbn]["fqbn"] = fqbn
module = data["moduleName"]
boards[fqbn]["firmware"] = []
for firmware_version in data["versions"]:
firmware_file = get_firmware_file(module, simple_fqbn, firmware_version)
boards[fqbn]["firmware"].append(create_firmware_data(firmware_file, module, firmware_version))
boards[fqbn]["uploader_plugin"] = data["uploader_plugin"]
boards[fqbn]["additional_tools"] = data["additional_tools"]
boards[fqbn]["module"] = module
boards[fqbn]["name"] = data["name"]

boards_json = []
for _, b in boards.items():
boards_json.append(b)

return boards_json


if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="generator.py")
parser.add_argument(
Expand Down Expand Up @@ -345,7 +327,10 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
with open(input_file, "r") as f:
boards = json.load(f)

boards_json = generate_boards_json(boards, args.arduino_cli, args.new)
if args.new:
boards_json = generate_new_boards_json(boards)
else:
boards_json = generate_boards_json(boards, args.arduino_cli)

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

Expand Down
89 changes: 88 additions & 1 deletion generator/new_boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,93 @@
"arduino:renesas_uno:unor4wifi": {
"moduleName": "ESP32-S3",
"versions": ["0.1.0", "0.2.0", "0.2.1"],
"name": "Arduino UNO R4 WiFi"
"name": "Arduino UNO R4 WiFi",
"uploader_plugin": "arduino:uno-r4-wifi-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:espflash@2.0.0", "arduino:bossac@1.9.1-arduino5"],
"module": "ESP32-S3"
},
"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",
"1.4.8",
"1.5.0"
],
"name": "Arduino MKR WiFi 1010",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:bossac@1.7.0-arduino3"],
"module": "NINA"
},
"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",
"1.4.8",
"1.5.0"
],
"name": "Arduino NANO 33 IoT",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:bossac@1.7.0-arduino3"],
"module": "NINA"
},
"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",
"1.4.8",
"1.5.0"
],
"name": "Arduino Uno WiFi Rev2",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:avrdude@6.3.0-arduino17"],
"module": "NINA"
},
"arduino:mbed_nano:nanorp2040connect": {
"moduleName": "NINA",
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"],
"name": "Arduino Nano RP2040 Connect",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:rp2040tools@1.0.6"],
"module": "NINA"
}
}

0 comments on commit e241f76

Please sign in to comment.