Skip to content

Add precompiled sketches and index generation to make checking the firmware version possible #113

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 6 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 26 additions & 22 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,34 @@ def split_property_and_drop_first_level(s):
return (k, v)


# Generate and copy loader Sketch binary data for specified board
def create_loader_data(simple_fqbn, binary):
loader_path = f"firmwares/loader/{simple_fqbn}/loader{binary.suffix}"
loader = Path(__file__).parent / loader_path
loader.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(binary, loader)
# Generate and copy precompiled Sketch binary data for specified board
# (sketch type could be either "loader" or "getversion")
def create_precomp_sketch_data(simple_fqbn, sketch_type):

loader_dir = Path(
"..",
"firmwares",
sketch_type,
simple_fqbn,
)
sketch_source = Path(__file__).parent / loader_dir
sketch_files = list(x for x in sketch_source.iterdir() if x.is_file())
if len(sketch_files) != 1:
print(f"Invalid loader files found in {sketch_source}")
sys.exit(1)
sketch_file = sketch_files[0] # lets assume there's only a single file

sketch_dest = f"firmwares/{sketch_type}/{simple_fqbn}/{sketch_type}{sketch_file.suffix}"
sketch_dest_path = Path(__file__).parent / sketch_dest
sketch_dest_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(sketch_file, sketch_dest_path)

file_hash = sha2(loader)
file_hash = sha2(sketch_dest_path)

return {
"url": f"{DOWNLOAD_URL}/{loader_path}",
"url": f"{DOWNLOAD_URL}/{sketch_dest}",
"checksum": f"SHA-256:{file_hash}",
"size": f"{loader.stat().st_size}",
"size": f"{sketch_dest_path.stat().st_size}",
}


Expand Down Expand Up @@ -235,19 +250,8 @@ def generate_boards_json(input_data, arduino_cli_path):
for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

loader_dir = Path(
"..",
"firmwares",
"loader",
simple_fqbn,
)
loader_path = Path(__file__).parent / loader_dir
loader_files = list(x for x in loader_path.iterdir() if x.is_file())
if len(loader_files) != 1:
print(f"Invalid loader files found in {loader_path}")
sys.exit(1)

boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, loader_files[0])
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")

for firmware_version in data["versions"]:
module = data["moduleName"]
Expand Down