mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge pull request #709 from rowr111/remove-version-checking
remove version checking from the extension tools
This commit is contained in:
commit
dd14964ca6
4 changed files with 1 additions and 148 deletions
|
|
@ -9,7 +9,6 @@ This tool is designed to be use by used by the VS Code extension at https://gith
|
||||||
|
|
||||||
- **Serial Port Management**: List and monitor available serial ports.
|
- **Serial Port Management**: List and monitor available serial ports.
|
||||||
- **Flashing**: Copy UF2 firmware images to a mounted boot drive.
|
- **Flashing**: Copy UF2 firmware images to a mounted boot drive.
|
||||||
- **Version Checking**: Compare local and device firmware versions to determine if updates are needed.
|
|
||||||
- **Artifact Listing**: List available UF2 images for flashing.
|
- **Artifact Listing**: List available UF2 images for flashing.
|
||||||
- **Environment Diagnostics**: Check Python and serial environment health.
|
- **Environment Diagnostics**: Check Python and serial environment health.
|
||||||
|
|
||||||
|
|
@ -82,20 +81,6 @@ List available UF2 images for flashing. Can output as JSON for scripting.
|
||||||
python tools-bao/bao.py artifacts --json
|
python tools-bao/bao.py artifacts --json
|
||||||
```
|
```
|
||||||
|
|
||||||
### `update-all`
|
|
||||||
Check if the board’s firmware version differs from the local version.
|
|
||||||
|
|
||||||
**Options:**
|
|
||||||
- `-p, --port` (required): Serial port to query
|
|
||||||
- `-b, --baud`: Baud rate (default: 115200)
|
|
||||||
- `--timeout`: Seconds to wait for version response (default: 3.0)
|
|
||||||
- `--json`: Output in JSON format
|
|
||||||
|
|
||||||
**Usage:**
|
|
||||||
```sh
|
|
||||||
python tools-bao/bao.py update-all -p COM3 --json
|
|
||||||
```
|
|
||||||
|
|
||||||
### `doctor`
|
### `doctor`
|
||||||
Check your Python environment and serial port setup for common issues.
|
Check your Python environment and serial port setup for common issues.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@ from commands.monitor import cmd_monitor
|
||||||
from commands.flash import cmd_flash
|
from commands.flash import cmd_flash
|
||||||
from commands.doctor import cmd_doctor
|
from commands.doctor import cmd_doctor
|
||||||
from commands.artifacts import cmd_artifacts
|
from commands.artifacts import cmd_artifacts
|
||||||
from commands.update_all import cmd_update_all
|
|
||||||
|
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ap = argparse.ArgumentParser(
|
ap = argparse.ArgumentParser(
|
||||||
|
|
@ -31,14 +30,6 @@ def main():
|
||||||
s = sub.add_parser("ports", help="List serial ports")
|
s = sub.add_parser("ports", help="List serial ports")
|
||||||
s.set_defaults(func=cmd_ports)
|
s.set_defaults(func=cmd_ports)
|
||||||
|
|
||||||
# update-all
|
|
||||||
ua = sub.add_parser("update-all", help="Return true if board Xous/loader version differs from local")
|
|
||||||
ua.add_argument("-p", "--port", required=True, help="Monitor serial port")
|
|
||||||
ua.add_argument("-b", "--baud", type=int, default=115200)
|
|
||||||
ua.add_argument("--timeout", type=float, default=3.0, help="Seconds to wait for version response")
|
|
||||||
ua.add_argument("--json", action="store_true", help='Emit {"updateAll": bool, "current": "...", "board": "..."}')
|
|
||||||
ua.set_defaults(func=cmd_update_all)
|
|
||||||
|
|
||||||
# monitor
|
# monitor
|
||||||
m = sub.add_parser("monitor", help="Open a serial monitor")
|
m = sub.add_parser("monitor", help="Open a serial monitor")
|
||||||
m.add_argument("-p", "--port", required=True, help="Serial port (e.g., COM5, /dev/ttyUSB0)")
|
m.add_argument("-p", "--port", required=True, help="Serial port (e.g., COM5, /dev/ttyUSB0)")
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
from utils.common import project_root
|
|
||||||
from utils.version_utils import read_local_versions, query_board_versions
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_update_all(args) -> None:
|
|
||||||
root = project_root()
|
|
||||||
|
|
||||||
local_semver, local_ts = read_local_versions(root)
|
|
||||||
if not local_semver:
|
|
||||||
logging.error("[bao] could not parse SEMVER from services/xous-ticktimer/src/version.rs")
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
board_semver, board_ts = query_board_versions(args.port, args.baud, timeout_s=args.timeout)
|
|
||||||
if board_semver is None:
|
|
||||||
logging.error("[bao] could not read board version (is the board connected and running?)")
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
# Decision uses SEMVER vs SEMVER (timestamps are logged but not decisive)
|
|
||||||
try:
|
|
||||||
needs = (local_semver.strip() != board_semver.strip())
|
|
||||||
except AttributeError:
|
|
||||||
# If the board didn't report a version, assume an update is needed
|
|
||||||
needs = True
|
|
||||||
|
|
||||||
if args.json:
|
|
||||||
print(json.dumps({
|
|
||||||
"updateAll": needs,
|
|
||||||
"localSemver": local_semver,
|
|
||||||
"localTimestamp": local_ts,
|
|
||||||
"boardSemver": board_semver,
|
|
||||||
"boardTimestamp": board_ts
|
|
||||||
}))
|
|
||||||
else:
|
|
||||||
print("true" if needs else "false")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
import re
|
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Optional, Tuple
|
|
||||||
import serial
|
|
||||||
|
|
||||||
|
|
||||||
BOOKEND_START: str = "_|TT|_"
|
|
||||||
BOOKEND_END: str = "_|TE|_"
|
|
||||||
|
|
||||||
SEMVER_RE = re.compile(r'pub\s+const\s+SEMVER\s*:\s*&\'static\s+str\s*=\s*"([^"]+)"')
|
|
||||||
TS_RE = re.compile(r'pub\s+const\s+TIMESTAMP\s*:\s*&\'static\s+str\s*=\s*"([^"]+)"')
|
|
||||||
|
|
||||||
def read_local_versions(repo_root: Path) -> Tuple[Optional[str], Optional[str]]:
|
|
||||||
f = repo_root / "services" / "xous-ticktimer" / "src" / "version.rs"
|
|
||||||
if not f.exists():
|
|
||||||
logging.warning(f"[bao] version.rs not found: {f}")
|
|
||||||
return None, None
|
|
||||||
text = f.read_text(encoding="utf-8", errors="ignore")
|
|
||||||
semver = (SEMVER_RE.search(text).group(1).strip()
|
|
||||||
if SEMVER_RE.search(text) else None)
|
|
||||||
ts = (TS_RE.search(text).group(1).strip()
|
|
||||||
if TS_RE.search(text) else None)
|
|
||||||
return semver, ts
|
|
||||||
|
|
||||||
def _between_bookends(buf: str) -> Optional[str]:
|
|
||||||
start_idx = buf.find(BOOKEND_START)
|
|
||||||
if start_idx == -1:
|
|
||||||
return None
|
|
||||||
end_idx = buf.find(BOOKEND_END, start_idx + len(BOOKEND_START))
|
|
||||||
if end_idx == -1:
|
|
||||||
return None
|
|
||||||
return buf[start_idx + len(BOOKEND_START): end_idx]
|
|
||||||
|
|
||||||
def parse_board_version_blob(buf: str) -> Tuple[Optional[str], Optional[str]]:
|
|
||||||
blob = _between_bookends(buf)
|
|
||||||
if blob is None:
|
|
||||||
return None, None
|
|
||||||
# normalize line endings and whitespace
|
|
||||||
blob = blob.replace("\r\n", "\n").replace("\r", "\n").strip()
|
|
||||||
# Expect two lines: first SEMVER, second TIMESTAMP (but be tolerant)
|
|
||||||
lines = [ln.strip() for ln in blob.split("\n") if ln.strip() != ""]
|
|
||||||
if not lines:
|
|
||||||
return None, None
|
|
||||||
semver = lines[0]
|
|
||||||
ts = lines[1] if len(lines) > 1 else None
|
|
||||||
return semver, ts
|
|
||||||
|
|
||||||
def query_board_versions(port: str, baud: int = 115200, timeout_s: float = 3.0, cmd: bytes = b"ver xous\r\n") -> Tuple[Optional[str], Optional[str]]:
|
|
||||||
try:
|
|
||||||
ser = serial.Serial(port, baud, timeout=0.2)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"[bao] cannot open {port}: {e}")
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
try:
|
|
||||||
with ser:
|
|
||||||
try:
|
|
||||||
ser.reset_input_buffer()
|
|
||||||
ser.reset_output_buffer()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
ser.write(cmd)
|
|
||||||
ser.flush()
|
|
||||||
|
|
||||||
deadline = time.time() + timeout_s
|
|
||||||
chunks = []
|
|
||||||
while time.time() < deadline:
|
|
||||||
try:
|
|
||||||
data = ser.read(4096)
|
|
||||||
if data:
|
|
||||||
chunks.append(data.decode(errors="replace"))
|
|
||||||
joined = "".join(chunks)
|
|
||||||
if BOOKEND_START in joined and BOOKEND_END in joined:
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
break
|
|
||||||
time.sleep(0.02)
|
|
||||||
finally:
|
|
||||||
pass
|
|
||||||
|
|
||||||
buf = "".join(chunks) if chunks else ""
|
|
||||||
return parse_board_version_blob(buf)
|
|
||||||
Loading…
Reference in a new issue