| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/env python3
- """Fail-closed validation for the active 6400 lock."""
- from __future__ import annotations
- import sys
- from pathlib import Path
- try:
- import yaml
- except Exception as exc: # pragma: no cover
- print(f"LOCK_FAIL yaml unavailable: {exc}", file=sys.stderr)
- raise SystemExit(2)
- ROOT = Path(__file__).resolve().parents[1]
- LOCK = ROOT / "ACTIVE_6400_MANUAL_I2C_LOCK.yaml"
- EXPECTED = {
- "product": "6400-front-rear",
- "board": "FCB V1.1",
- "device": "EF2L45BG256B",
- "clock_hz": 25_000_000,
- "pll": "forbidden",
- "firmware_count": 1,
- "gui_count": 1,
- }
- def main() -> int:
- if not LOCK.is_file():
- print("LOCK_FAIL missing ACTIVE_6400_MANUAL_I2C_LOCK.yaml", file=sys.stderr)
- return 2
- data = yaml.safe_load(LOCK.read_text(encoding="utf-8"))
- for key, value in EXPECTED.items():
- if data.get(key) != value:
- print(f"LOCK_FAIL {key}: expected {value!r}, got {data.get(key)!r}", file=sys.stderr)
- return 2
- outputs = data.get("outputs", {})
- if outputs.get("ptc_count") != 24 or outputs.get("front_fan_count") != 4 or outputs.get("rear_fan_count") != 4:
- print("LOCK_FAIL actuator counts", file=sys.stderr)
- return 2
- if outputs.get("ptc_pwm_hz") != 500 or outputs.get("fan_pwm_hz") != 500:
- print("LOCK_FAIL PWM frequency", file=sys.stderr)
- return 2
- uart = data.get("uart", {})
- if uart.get("baud") != 921600 or uart.get("format") != "8N1":
- print("LOCK_FAIL UART", file=sys.stderr)
- return 2
- if data.get("host_i2c", {}).get("address_7bit") != 0x2A:
- print("LOCK_FAIL Host-I2C address", file=sys.stderr)
- return 2
- if "pid" in data:
- print("LOCK_FAIL legacy PID field is present", file=sys.stderr)
- return 2
- print("LOCK_PASS")
- return 0
- if __name__ == "__main__":
- raise SystemExit(main())
|