Skip to content

Commit 813e19b

Browse files
Add precompiled sketches and index generation to make checking the firmware 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>
1 parent f38e518 commit 813e19b

File tree

7 files changed

+553
-22
lines changed

7 files changed

+553
-22
lines changed
1.9 MB
Binary file not shown.

firmwares/getversion/arduino.megaavr.uno2018/CheckFirmwareVersion.ino.with_bootloader.hex

Lines changed: 533 additions & 0 deletions
Large diffs are not rendered by default.
47 KB
Binary file not shown.
668 KB
Binary file not shown.
23.2 KB
Binary file not shown.
22.4 KB
Binary file not shown.

generator/generator.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,28 @@ def split_property_and_drop_first_level(s):
3838
return (k, v)
3939

4040

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

48-
file_hash = sha2(loader)
45+
sketch_dir = Path(__file__).parent / ".." / "firmwares" / sketch_type / simple_fqbn
46+
sketch_files = list(sketch_dir.iterdir())
47+
if len(sketch_files) != 1:
48+
print(f"Invalid loader files found in {sketch_dir}")
49+
sys.exit(1)
50+
sketch_file = sketch_files[0] # lets assume there's only a single file
51+
52+
sketch_dest = f"firmwares/{sketch_type}/{simple_fqbn}/{sketch_type}{sketch_file.suffix}"
53+
sketch_dest_path = Path(__file__).parent / sketch_dest
54+
sketch_dest_path.parent.mkdir(parents=True, exist_ok=True)
55+
shutil.copyfile(sketch_file, sketch_dest_path)
56+
57+
file_hash = sha2(sketch_dest_path)
4958

5059
return {
51-
"url": f"{DOWNLOAD_URL}/{loader_path}",
60+
"url": f"{DOWNLOAD_URL}/{sketch_dest}",
5261
"checksum": f"SHA-256:{file_hash}",
53-
"size": f"{loader.stat().st_size}",
62+
"size": f"{sketch_dest_path.stat().st_size}",
5463
}
5564

5665

@@ -235,19 +244,8 @@ def generate_boards_json(input_data, arduino_cli_path):
235244
for fqbn, data in input_data.items():
236245
simple_fqbn = fqbn.replace(":", ".")
237246

238-
loader_dir = Path(
239-
"..",
240-
"firmwares",
241-
"loader",
242-
simple_fqbn,
243-
)
244-
loader_path = Path(__file__).parent / loader_dir
245-
loader_files = list(x for x in loader_path.iterdir() if x.is_file())
246-
if len(loader_files) != 1:
247-
print(f"Invalid loader files found in {loader_path}")
248-
sys.exit(1)
249-
250-
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, loader_files[0])
247+
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
248+
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
251249

252250
for firmware_version in data["versions"]:
253251
module = data["moduleName"]

0 commit comments

Comments
 (0)