From 9d5b0440a460ff49de21de90604c58808dd4a6c8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 21 Jan 2025 21:34:00 +0100 Subject: fw: Add update_espressif_blobs.py This script does not depend on west and is able to load the Espressif blobs to the Espressif HAL module. --- fw/update_espressif_blobs.py | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 fw/update_espressif_blobs.py (limited to 'fw') diff --git a/fw/update_espressif_blobs.py b/fw/update_espressif_blobs.py new file mode 100755 index 0000000..55c7582 --- /dev/null +++ b/fw/update_espressif_blobs.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + + +import hashlib +import sys +import pathlib +import urllib.request + +import yaml + + +SCRIPT = pathlib.Path(__file__) +FW = SCRIPT.parent +ESPRESSIF_MODULE = FW / "zephyrproject/modules/hal/espressif" +MODULE_YAML = ESPRESSIF_MODULE / "zephyr/module.yml" +BLOBS = ESPRESSIF_MODULE / "zephyr/blobs" + + +def main() -> None: + text = MODULE_YAML.read_text() + data = yaml.safe_load(text) + + for entry in data["blobs"]: + url = entry["url"] + checksum = entry["sha256"] + path = entry["path"] + get_blob( + url=url, + checksum=checksum, + path=path, + ) + + +def get_blob(url, checksum, path): + sys.stdout.write(f"Downloading {path} ...") + with urllib.request.urlopen(url) as conn: + content = conn.read() + sys.stdout.write(" done\n") + + sha256 = hashlib.sha256() + sha256.update(content) + calculated = sha256.hexdigest() + if calculated == checksum: + print("Checksum matched.") + else: + print(f"Checksum mismatch for {path}!") + print(f"Expected: {checksum}") + print(f"Got: {calculated}") + + target: pathlib.Path = BLOBS / path + target.parent.mkdir(exist_ok=True, parents=True) + target.write_bytes(content) + print(f"Saved to {path}") + + +if __name__ == "__main__": + main() -- cgit v1.2.3-70-g09d2