feat(tools): add firmware deploy tool (sign + stage for server)
This commit is contained in:
43
tools/deploy_firmware.py
Normal file
43
tools/deploy_firmware.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sign firmware and stage it for the server OTA endpoint."""
|
||||
import argparse, hashlib, json
|
||||
from pathlib import Path
|
||||
|
||||
from sign_firmware import sign_firmware
|
||||
|
||||
|
||||
def deploy(firmware_path: Path, key_path: Path,
|
||||
version: str, output_dir: Path) -> None:
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
data = firmware_path.read_bytes()
|
||||
sig = sign_firmware(firmware_path, key_path)
|
||||
|
||||
(output_dir / "current.bin").write_bytes(data)
|
||||
(output_dir / "current.sig").write_bytes(sig)
|
||||
(output_dir / "manifest.json").write_text(json.dumps({
|
||||
"version": version,
|
||||
"size": len(data),
|
||||
"sha256": hashlib.sha256(data).hexdigest(),
|
||||
}, indent=2))
|
||||
|
||||
print(f"Deployed {firmware_path.name} v{version} → {output_dir}/")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument("firmware", help="Path to .bin")
|
||||
p.add_argument("version", help="Version string, e.g. 1.2.3")
|
||||
p.add_argument("--key", default="secrets/firmware_signing_key.pem")
|
||||
p.add_argument("--out-dir", default="server/firmware")
|
||||
args = p.parse_args()
|
||||
deploy(
|
||||
firmware_path=Path(args.firmware),
|
||||
key_path=Path(args.key),
|
||||
version=args.version,
|
||||
output_dir=Path(args.out_dir),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user