ota_push.py, ota_mesh_push.py: a directory of a release's packages -- the delta from the node's image is picked (exit 3: none fits)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-14 20:34:57 +01:00
1 parent 96cbd7333a
commit 65f7965955
2 files changed
+105 -11

No files matched your search

+46 -3
View File
@@ -6,6 +6,11 @@
tools/ota_push.py b1 Xiao_nrf52_repeater-ota.mcfw --apply # ... and apply
tools/ota_push.py b1 pkg.mcfw --binary --drop 30 --prime old.mcfw
tools/ota_push.py CE:72:14:CD:FD:02 pkg.mcfw --apply # over BLE (NUS)
tools/ota_push.py CE:72:14:CD:FD:02 <dir> --apply # the package for the node's image
The package may be a directory with one release's packages (full image and
deltas): the delta from the image `fw status` reports is taken, else the full
image. Exit 3 = nothing there starts from the node's image (or no `fw`).
The board: a name from the local config (tools/mctools_config.py), a USB
serial number, a port path -- or a BLE MAC: the node's BLE console, bonded
@@ -38,6 +43,7 @@ import random
import re
import sys
import time
from pathlib import Path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
@@ -221,6 +227,43 @@ class BleConsole:
self._loop.call_soon_threadsafe(self._loop.stop)
NO_PACKAGE = 3 # exit code: no package starts from the node's image
def pick_package(where: str, status: str, full_ok: bool) -> bytes:
"""`package` may be a directory with one release's packages (the full image
and its deltas, as the firmware role fetches them): take the delta that
starts from the image `fw status` reports, else -- where a full image may
go -- the full one. Exits NO_PACKAGE when nothing fits: the node runs an
image no delta starts from, or has no `fw` at all (not an -ota build)."""
p = Path(where)
if not p.is_dir():
return p.read_bytes()
m = re.search(r"\bbase \d+ ([0-9a-f]{8})", status)
if not m:
print(f"no base image in `fw status`: {status!r}")
sys.exit(NO_PACKAGE)
base = m.group(1)
full = None
for f in sorted(p.glob("*.mcfw")):
data = f.read_bytes()
if data[:4] != b"MCFW":
continue
if data[16:48].hex().startswith(base): # raw_sha256 = the image it installs
print(f"the node already runs the image of {f.name}")
sys.exit(0)
if data[4] == 2 and data[160:192].hex().startswith(base):
print(f"package: {f.name} (delta from {base})")
return data
if data[4] == 1:
full = (f, data)
if full and full_ok:
print(f"package: {full[0].name} (full image, no delta from {base})")
return full[1]
print(f"no package in {where} starts from {base}")
sys.exit(NO_PACKAGE)
def open_console(target: str):
if MAC_RE.match(target):
return BleConsole(target)
@@ -280,8 +323,6 @@ def main() -> None:
)
args = ap.parse_args()
with open(args.package, "rb") as f:
data = f.read()
if args.binary and MAC_RE.match(args.board):
sys.exit("--binary is a bench test of the mesh path: USB only")
s = open_console(args.board)
@@ -289,7 +330,9 @@ def main() -> None:
if not isinstance(s, BleConsole): # over BLE its reply comes late, as the next one's
s.write(b"\r\n")
time.sleep(0.4)
print("status:", command(s, "fw status"))
st = command(s, "fw status")
print("status:", st)
data = pick_package(args.package, st, full_ok=True)
if args.prime:
with open(args.prime, "rb") as f:
other = f.read()