Skip to content

Commit

Permalink
Add precompiled sketches and index generation to make checking the fi…
Browse files Browse the repository at this point in the history
…rmware version possible (#113)

* add precompiled sketch to obtain the current firmware a board is using

* optimize how the generator works, no change in the generated files

* add version_sketch generation to the index

* make CI happy

* Update generator/generator.py

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>

* now it's working

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
  • Loading branch information
umbynos and silvanocerza committed Sep 22, 2021
1 parent f38e518 commit 813e19b
Show file tree
Hide file tree
Showing 7 changed files with 553 additions and 22 deletions.
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.
42 changes: 20 additions & 22 deletions generator/generator.py
Expand Up @@ -38,19 +38,28 @@ 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):

file_hash = sha2(loader)
sketch_dir = Path(__file__).parent / ".." / "firmwares" / sketch_type / simple_fqbn
sketch_files = list(sketch_dir.iterdir())
if len(sketch_files) != 1:
print(f"Invalid loader files found in {sketch_dir}")
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(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 +244,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

0 comments on commit 813e19b

Please sign in to comment.