krishnax12/t113-minimal-linux

Allwinner T113-S3 dual-Cortex-A7 SoC with integrated 128MB DDR3, multi-rail decoupling, 24MHz and 32.768kHz oscillators, filtering, and exposed test points.

Version
0.1.1
License
unset
Stars
0

scripts/write-validation.py

"""Write release evidence only after every required board check passes."""
import collections
import datetime
import hashlib
import json
from pathlib import Path

from routing_geometry import Nets

project = Path(__file__).resolve().parent.parent

def digest(path):
    return hashlib.sha256(path.read_bytes()).hexdigest()

routed_path = project / "routed.circuit.json"
routed = json.loads(routed_path.read_text())
baseline_path = project / "routing/source-baseline.json"
baseline = json.loads(baseline_path.read_text())
copper_types = {"pcb_trace", "pcb_via", "pcb_copper_pour"}
record_key = lambda record: (record["type"], record.get(record["type"] + "_id"))
original = {record_key(record): record for record in baseline if record["type"] not in copper_types}
final = {record_key(record): record for record in routed if record["type"] not in copper_types}
assert all(final.get(key) == record for key, record in original.items()), "Routing changed source, placement or schematic records"
added_records = [record for key, record in final.items() if key not in original]
baseline_nets = Nets(baseline)
known_terminals = {record[record["type"] + "_id"] for record in baseline if record["type"] in {"source_port", "source_net"}}
for record in added_records:
    assert record["type"] == "source_trace", "Unexpected non-copper routing record"
    terminals = record.get("connected_source_port_ids", []) + record.get("connected_source_net_ids", [])
    assert terminals and set(terminals) <= known_terminals, "Unknown routing endpoint"
    assert len({baseline_nets.source(terminal) for terminal in terminals}) == 1, "Routing metadata joins different schematic nets"
checks = {name: json.loads((project / f"routing/{name}.json").read_text()) for name in ["design-check", "routing-check", "gerber-check", "schematic-check"]}
for name in ["design-check", "routing-check", "gerber-check"]:
    assert checks[name]["passed"], f"{name} failed"
assert not checks["schematic-check"]["formalWarnings"]
assert not checks["schematic-check"]["formalErrors"]
assert not any(record["type"].endswith(("_error", "_warning")) for record in routed)
source_files = [project / "index.circuit.tsx", project / "package.json", project / "bun.lock", project / "tscircuit.config.json"]
for directory in ["circuits", "imports", "scripts"]:
    source_files.extend(path for path in (project / directory).rglob("*") if path.is_file() and "__pycache__" not in path.parts)
report = {
    "createdAt": datetime.datetime.now(datetime.timezone.utc).isoformat(),
    "package": "krishnax12/t113-minimal-linux",
    "version": json.loads((project / "package.json").read_text())["version"],
    "sourceComponents": sum(record["type"] == "source_component" for record in routed),
    "circuitRecords": dict(collections.Counter(record["type"] for record in routed)),
    "checks": checks,
    "schematicAndPlacementPreserved": True,
    "addedRoutingSourceTraces": len(added_records),
    "filesSha256": {str(path.relative_to(project)): digest(path) for path in sorted(source_files + [routed_path, baseline_path, project / "dist/fabrication.zip"])},
    "limitations": [
        "Engineering prototype; no manufactured-board boot, assembly, power-transient or signal-integrity validation.",
        "Schematic zero-warning counts refer to Circuit JSON warning/error records. Runtime IRLS iteration diagnostics remain in the build log.",
        "Fabricator must review filled/capped via-in-pad processing, stackup and USB impedance. Supplier pick-and-place rotations are unverified.",
        "Gerbonara parser does not interpret LR aperture rotations in paste layers; its parser diagnostics are retained in gerber-check.json.",
        "These checks do not certify the entire Circuit JSON schema or a production-ready assembly.",
    ],
}
(project / "routing/validation.json").write_text(json.dumps(report, indent=2) + "\n")
print("Wrote routing/validation.json: all required checks passed")