diff options
author | xengineering <me@xengineering.eu> | 2025-01-21 21:34:00 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-01-21 21:34:00 +0100 |
commit | 9d5b0440a460ff49de21de90604c58808dd4a6c8 (patch) | |
tree | f6dd4f926c20a28dea14e0ae56263186164c4524 | |
parent | d732a84ababe382f066c613c85142b8403c9e423 (diff) | |
download | soundbox-9d5b0440a460ff49de21de90604c58808dd4a6c8.tar soundbox-9d5b0440a460ff49de21de90604c58808dd4a6c8.tar.zst soundbox-9d5b0440a460ff49de21de90604c58808dd4a6c8.zip |
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.
-rwxr-xr-x | fw/update_espressif_blobs.py | 57 |
1 files changed, 57 insertions, 0 deletions
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() |