feat: strengthen BSP and PSP validation and handoff

This commit is contained in:
tangfahong committed 2026-09-24 11:52:22 +08:00
1 parent bcea35a91e
commit 1641fac631
39 files changed
+2695 -90

No files matched your search

@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import hashlib
import json
import tempfile
from pathlib import Path
import validate_hardware_topology
def main() -> int:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
psp = root / "psp"
sensor_dir = psp / "configs" / "media"
sensor_dir.mkdir(parents=True)
(sensor_dir / "sensor_cfg.ini").write_text(
"[sensor]\nname=0X00003A00\nbus_id=2\ni2c_addr=0x30\ndevno=1\nlane_num=1\n"
"[sensor2]\nname=0X00003A00\nbus_id=2\ni2c_addr=0x31\ndevno=0\nlane_num=1\n",
encoding="utf-8",
)
evidence = root / "spec.txt"
evidence.write_text("dual MIS40C1", encoding="utf-8")
digest = hashlib.sha256(evidence.read_bytes()).hexdigest()
topology = {
"schema_version": 1,
"project": "LY-SM-YT42-AI",
"chip": "CV1841CP",
"system_mode": "dualos",
"storage": {"type": "spinand", "capacity_bytes": 134217728},
"sources": [{"kind": "spec", "path": str(evidence), "sha256": digest}],
"conflicts": [],
"sensors": [
{"section": "sensor", "model": "MIS40C1", "enum_name": "MIS40C1_MIPI_4M_30FPS_12BIT", "i2c_bus": 2, "i2c_address": "0x30", "mipi_device": 1, "lane_count": 1, "evidence_sources": [0], "config_expectations": {"name": "0X00003A00", "bus_id": 2, "i2c_addr": "0x30", "devno": 1, "lane_num": 1}},
{"section": "sensor2", "model": "MIS40C1", "enum_name": "MIS40C1_MIPI_4M_30FPS_12BIT", "i2c_bus": 2, "i2c_address": "0x31", "mipi_device": 0, "lane_count": 1, "evidence_sources": [0], "config_expectations": {"name": "0X00003A00", "bus_id": 2, "i2c_addr": "0x31", "devno": 0, "lane_num": 1}},
],
}
topology_path = root / "hardware-topology.json"
topology_path.write_text(json.dumps(topology), encoding="utf-8")
assert validate_hardware_topology.validate(psp, topology_path)["passed"] is True
topology["sensors"] = topology["sensors"][:1]
topology_path.write_text(json.dumps(topology), encoding="utf-8")
failed = validate_hardware_topology.validate(psp, topology_path)
assert failed["passed"] is False
assert any("Sensor 数量不一致" in error for error in failed["errors"])
print("hardware topology tests passed")
return 0
if __name__ == "__main__":
raise SystemExit(main())