mirror of
https://github.com/commaai/agnos-builder.git
synced 2026-07-10 01:02:08 +08:00
4f3cbd21b8
* Remove firwmare.json * match order
78 lines
2.0 KiB
Python
Executable File
78 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
import os
|
|
import hashlib
|
|
import subprocess
|
|
from copy import deepcopy
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).parent.parent
|
|
OUTPUT_DIR = ROOT / "output"
|
|
FIRMWARE_DIR = ROOT / "firmware"
|
|
OTA_OUTPUT_DIR = OUTPUT_DIR / "ota"
|
|
BUILD_DIR = ROOT / "build"
|
|
|
|
AGNOS_UPDATE_URL = os.getenv("AGNOS_UPDATE_URL", "https://commadist.azureedge.net/agnosupdate")
|
|
AGNOS_STAGING_UPDATE_URL = os.getenv("AGNOS_STAGING_UPDATE_URL", "https://commadist.azureedge.net/agnosupdate-staging")
|
|
|
|
def checksum(fn):
|
|
sha256 = hashlib.sha256()
|
|
with open(fn, 'rb') as f:
|
|
for chunk in iter(lambda: f.read(4096), b""):
|
|
sha256.update(chunk)
|
|
return sha256.hexdigest()
|
|
|
|
def compress(fin, fout) -> None:
|
|
subprocess.check_call(f"xz -T4 -vc {fin} > {fout}", shell=True)
|
|
|
|
|
|
def process_file(fn, name, full_check=True, has_ab=True):
|
|
print(name)
|
|
hash_raw = hash = checksum(fn)
|
|
size = fn.stat().st_size
|
|
print(f" {size} bytes, hash {hash}")
|
|
|
|
print(" compressing")
|
|
xz_fn = OTA_OUTPUT_DIR / f"{fn.stem}-{hash_raw}.img.xz"
|
|
compress(fn, xz_fn)
|
|
|
|
ret = {
|
|
"name": name,
|
|
"url": "{remote_url}/" + xz_fn.name,
|
|
"hash": hash,
|
|
"hash_raw": hash_raw,
|
|
"size": size,
|
|
"sparse": False,
|
|
"full_check": full_check,
|
|
"has_ab": has_ab,
|
|
}
|
|
|
|
return ret
|
|
|
|
|
|
if __name__ == "__main__":
|
|
OTA_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
files = [
|
|
process_file(OUTPUT_DIR / "boot.img", "boot"),
|
|
process_file(OUTPUT_DIR / "system.img", "system", full_check=False),
|
|
]
|
|
for fw in ("xbl", "abl", "xbl_config", "devcfg", "aop"):
|
|
# firmware not built in this repo
|
|
files.append(process_file(FIRMWARE_DIR / f"{fw}.bin", fw))
|
|
|
|
configs = [
|
|
(AGNOS_UPDATE_URL, "ota.json"),
|
|
(AGNOS_STAGING_UPDATE_URL, "ota-staging.json"),
|
|
]
|
|
for remote_url, output_fn in configs:
|
|
processed_files = []
|
|
for f in deepcopy(files):
|
|
f["url"] = f["url"].format(remote_url=remote_url)
|
|
processed_files.append(f)
|
|
|
|
with open(OTA_OUTPUT_DIR / output_fn, "w") as out:
|
|
json.dump(processed_files, out, indent=2)
|
|
|
|
print("Done")
|