OTA phase 5: tools and docs ready for the public export
pub-release / release (push) Successful in 32m57s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-13 18:07:39 +01:00
1 parent 97618f223f
commit d22005a6fd
12 files changed
+704 -24

No files matched your search

+69 -17
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Pack a firmware image for the admin-pushed OTA (src/helpers/FwUpdate.*).
ota_pack.py keygen [--key PATH]
@@ -14,11 +15,14 @@
ota_pack.py archive <env>
store the env's image in the archive (pack and diff do it too)
ota_pack.py info <file.mcfw> [--pubkey HEX]
ota_pack.py fetch <env> --release fw-<sha8> (--base <sha-prefix> | --full) [--out FILE]
download a package that CI built (tth-fw-release.yml) and check it: the
ssh signature of SHA256SUMS (meshcore-fw@tth, tools/fw_allowed_signers),
ota_pack.py fetch <artifact> [--release TAG|latest] (--base <sha-prefix> | --full) [--out FILE]
download an OTA package of a public release and check it: the ssh
signature of SHA256SUMS (meshcore-ota@tth-pub, tools/ota_allowed_signers),
the file's sha256, and the manifest signature against [ota] pubkey.
<artifact> is the image's name in the release, e.g.
Xiao_nrf52_repeater-ota or SenseCap_Solar_repeater-observer-ota.
--base picks the delta for the image the node runs (`fw status`).
--private: our mast releases fw-<sha8> instead (token, fleet signer).
Image archive: ~/.local/share/meshcore-ota/images/<sha256>.bin -- every image
that may become a base has to land there BEFORE it is flashed by other means
@@ -51,6 +55,7 @@ import struct
import subprocess
import sys
import tempfile
import urllib.parse
import urllib.request
import zlib
from pathlib import Path
@@ -76,9 +81,21 @@ MANIFEST = 256
PAGE = 4096
HS_WINDOW, HS_LOOKAHEAD = 11, 10
ARCHIVE = Path.home() / ".local/share/meshcore-ota/images"
API = "https://git.rfa.cz/api/v1/repos/tth/meshcore-tth"
SIGNERS = REPO / "tools/fw_allowed_signers"
SIGNER, NAMESPACE = "meshcore-fw@tth", "meshcore-fw"
# where `fetch` looks: the public releases, or (--private) our mast releases
SOURCES = {
"public": {
"api": "https://git.rfa.cz/api/v1/repos/tth-pub/meshcore-tth",
"signers": REPO / "tools/ota_allowed_signers",
"signer": "meshcore-ota@tth-pub",
"namespace": "meshcore-ota",
},
"private": {
"api": "https://git.rfa.cz/api/v1/repos/tth/meshcore-tth",
"signers": REPO / "tools/fw_allowed_signers",
"signer": "meshcore-fw@tth",
"namespace": "meshcore-fw",
},
}
def load_key(path: Path) -> Ed25519PrivateKey:
@@ -363,15 +380,35 @@ def release_pubkey() -> str | None:
def cmd_fetch(args: argparse.Namespace) -> None:
tag = args.release if args.release.startswith("fw-") else f"fw-{args.release[:8]}"
tok = gitea_token()
src = SOURCES["private" if args.private else "public"]
api = str(src["api"])
# the public releases are readable without a token, and get none
headers = {"Authorization": f"token {gitea_token()}"} if args.private else {}
def get(url: str) -> bytes:
req = urllib.request.Request(url, headers={"Authorization": f"token {tok}"})
req = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req, timeout=60) as r:
return r.read()
rel = json.loads(get(f"{API}/releases/tags/{tag}"))
if args.private:
tag = (
args.release if args.release.startswith("fw-") else f"fw-{args.release[:8]}"
)
rel = json.loads(get(f"{api}/releases/tags/{tag}"))
elif args.release == "latest":
rels = [
r
for r in json.loads(get(f"{api}/releases?limit=20"))
if "+tth." in r["tag_name"]
and any(a["name"] == "manifest.json" for a in r.get("assets", []))
]
if not rels:
sys.exit("no public release with OTA packages yet")
rel = max(rels, key=lambda r: r["created_at"])
tag = rel["tag_name"]
else:
tag = args.release
rel = json.loads(get(f"{api}/releases/tags/{urllib.parse.quote(tag, safe='')}"))
assets = {a["name"]: a["browser_download_url"] for a in rel.get("assets", [])}
for name in ("SHA256SUMS", "SHA256SUMS.sig", "manifest.json"):
if name not in assets:
@@ -386,11 +423,11 @@ def cmd_fetch(args: argparse.Namespace) -> None:
"-Y",
"verify",
"-f",
str(args.allowed_signers),
str(args.allowed_signers or src["signers"]),
"-I",
SIGNER,
str(src["signer"]),
"-n",
NAMESPACE,
str(src["namespace"]),
"-s",
sig.name,
],
@@ -437,7 +474,8 @@ def cmd_fetch(args: argparse.Namespace) -> None:
)
sys.exit(
f"{tag}: {len(hits)} deltas for base {spec}; built for: {have or 'none'}"
" -- rerun tth-fw-release with delta_from, or --full"
" -- a release has deltas only from the earlier releases it was built"
" against (tth-fw-release: delta_from); otherwise --full over USB/BLE"
)
name = hits[0]["file"]
data = checked(name)
@@ -483,8 +521,19 @@ def main() -> None:
p.add_argument("file")
p.add_argument("--pubkey")
p = sub.add_parser("fetch")
p.add_argument("env")
p.add_argument("--release", required=True, help="fw-<sha8> or a commit sha")
p.add_argument(
"env", help="artifact, e.g. Xiao_nrf52_repeater-ota (--private: the env)"
)
p.add_argument(
"--release",
default="latest",
help="public tag (v1.18.0+tth.YYYYMMDD) or latest; --private: fw-<sha8>",
)
p.add_argument(
"--private",
action="store_true",
help="our mast releases (tth/meshcore-tth, token, fleet signer)",
)
g = p.add_mutually_exclusive_group(required=True)
g.add_argument("--base", help="sha256 prefix of the node's image (`fw status`)")
g.add_argument("--full", action="store_true", help="the full image package")
@@ -492,7 +541,10 @@ def main() -> None:
p.add_argument(
"--pubkey", help="default: the release OTA key, [ota] pubkey of platformio.ini"
)
p.add_argument("--allowed-signers", default=str(SIGNERS))
p.add_argument(
"--allowed-signers",
help="default: tools/ota_allowed_signers (--private: fw_allowed_signers)",
)
args = ap.parse_args()
{
"keygen": cmd_keygen,