Explorar o código

build(td): bind 6400 flow to active source closure

root hai 3 meses
pai
achega
b8897ce90b

+ 37 - 36
constraints/prod2u_6400_front_back.adc

@@ -1,39 +1,40 @@
-# Generated from 6400 project.json. Confirmed pins only.
-# Exhaust FAN PWM is CON64/66/62/60 pin 4. Pin 3 FG is unused and absent.
+# 6400-front-rear-v1 confirmed pins. TTL Host remains deliberately unbound.
 set_pin_assignment { sys_clk } { LOCATION = J1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { host_uart_rx } { LOCATION = N11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { host_uart_tx } { LOCATION = M10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { bmc_rs232_tx } { LOCATION = L10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { bmc_rs232_rx } { LOCATION = M9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { host_rs232_tx } { LOCATION = M10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { host_rs232_rx } { LOCATION = N11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { temp_scl } { LOCATION = M8; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { temp_sda } { LOCATION = N9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[0] } { LOCATION = R7; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[1] } { LOCATION = T6; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[2] } { LOCATION = R5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[3] } { LOCATION = T4; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[4] } { LOCATION = G16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[5] } { LOCATION = F16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[6] } { LOCATION = R3; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[7] } { LOCATION = T2; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[8] } { LOCATION = R1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[9] } { LOCATION = P1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[10] } { LOCATION = N1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[11] } { LOCATION = M1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[12] } { LOCATION = P7; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[13] } { LOCATION = P8; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[14] } { LOCATION = N16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[15] } { LOCATION = M16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[16] } { LOCATION = R16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[17] } { LOCATION = P16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[18] } { LOCATION = T12; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[19] } { LOCATION = T13; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[20] } { LOCATION = R10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[21] } { LOCATION = P10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[22] } { LOCATION = P9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[23] } { LOCATION = T9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[0] } { LOCATION = B1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[1] } { LOCATION = P15; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[2] } { LOCATION = C4; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[3] } { LOCATION = N15; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[4] } { LOCATION = B5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[5] } { LOCATION = M14; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[6] } { LOCATION = A14; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[7] } { LOCATION = P5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[0] } { LOCATION = R7; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[1] } { LOCATION = T6; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[2] } { LOCATION = R5; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[3] } { LOCATION = T4; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[4] } { LOCATION = G16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[5] } { LOCATION = F16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[6] } { LOCATION = R3; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[7] } { LOCATION = T2; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[8] } { LOCATION = R1; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[9] } { LOCATION = P1; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[10] } { LOCATION = N1; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[11] } { LOCATION = M1; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[12] } { LOCATION = P7; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[13] } { LOCATION = P8; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[14] } { LOCATION = N16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[15] } { LOCATION = M16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[16] } { LOCATION = R16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[17] } { LOCATION = P16; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[18] } { LOCATION = T12; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[19] } { LOCATION = T13; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[20] } { LOCATION = R10; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[21] } { LOCATION = P10; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[22] } { LOCATION = P9; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { ptc_pwm_out[23] } { LOCATION = T9; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { front_fan_pwm_out[0] } { LOCATION = B1; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { front_fan_pwm_out[1] } { LOCATION = C4; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { front_fan_pwm_out[2] } { LOCATION = B5; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { front_fan_pwm_out[3] } { LOCATION = A14; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { rear_fan_pwm_out[0] } { LOCATION = P15; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { rear_fan_pwm_out[1] } { LOCATION = N15; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { rear_fan_pwm_out[2] } { LOCATION = M14; IOSTANDARD = LVCMOS33; }
+set_pin_assignment { rear_fan_pwm_out[3] } { LOCATION = P5; IOSTANDARD = LVCMOS33; }

+ 1 - 1
constraints/prod2u_6400_front_back.sdc

@@ -1 +1 @@
-create_clock -name sys_clk -period 40 -waveform {0 20} [get_ports {sys_clk}]
+create_clock -name sys_clk -period 40.000 [get_ports {sys_clk}]

+ 1 - 1
td/prod2u_6400_front_back.prj

@@ -5,5 +5,5 @@
         <Family>EF2</Family>
         <Device>EF2L45BG256B</Device>
     </HardWare>
-    <Note>6400 production bitstream is fail-closed until four exhaust FAN pins are electrically confirmed.</Note>
+    <Note>6400 V1 active source closure; Host TTL pins remain deliberately unbound.</Note>
 </Project>

+ 36 - 63
td/syn/prod2u_6400_front_back.tcl

@@ -1,76 +1,49 @@
-# 6400 production synthesis.
-# Exhaust FAN PWM balls are assigned; pin 3 FG inputs are intentionally unused.
+# 6400 production synthesis. The generated source closure is mirrored here
+# explicitly so TD never falls back to the obsolete direct-duty design.
+if {![info exists ::env(PROD2U_SOURCE_ROOT)]} {
+    error {PROD2U_6400_SYN_BLOCKED|PROD2U_SOURCE_ROOT is not set}
+}
+set source_root [file normalize $::env(PROD2U_SOURCE_ROOT)]
+proc src {relative} {
+    global source_root
+    set path [file join $source_root $relative]
+    if {![file isfile $path]} { error "PROD2U_6400_SYN_BLOCKED|missing source: $path" }
+    return $path
+}
 
 import_device ef2_4.db -package EF2L45BG256B
 set_param rtl directive:async_reg on
 set_param place async_reg on
 
-analyze -file {src/generated/6400/prod2u_6400_front_back_params.vh}
-analyze -file {src/common/uart_rx_byte.v}
-analyze -file {src/common/uart_tx_byte.v}
-analyze -file {src/common/crc16_serial.v}
-analyze -file {src/common/frame_rx.v}
-analyze -file {src/common/frame_tx.v}
-analyze -file {src/common/payload_ram.v}
-analyze -file {src/modules/double_bank_target_store.v}
-analyze -file {src/modules/pwm_phase_scan_scheduler.v}
-analyze -file {src/modules/shared_500us_tick.v}
-analyze -file {src/modules/host_watchdog.v}
-analyze -file {src/modules/i2c_word_reader.v}
-analyze -file {src/modules/temperature_reader.v}
-analyze -file {src/modules/temperature_ram.v}
-analyze -file {src/project/prod2u_6400_command_controller.v}
-analyze -file {src/project/prod2u_6400_adapter.v}
-analyze -file {src/rtl/prod2u_por.v}
-analyze -file {src/rtl/prod2u_p4_i2c_stop_start_read.v}
-analyze -file {src/top/prod2u_6400_front_back_top.v}
+analyze -file [src {generated/6400/prod2u_6400_v1_params.vh}]
+analyze -file [src {src/common/uart_rx_byte.v}]
+analyze -file [src {src/common/uart_tx_byte.v}]
+analyze -file [src {src/common/crc16_serial.v}]
+analyze -file [src {src/common/frame_rx.v}]
+analyze -file [src {src/common/frame_tx.v}]
+analyze -file [src {src/common/payload_ram.v}]
+analyze -file [src {src/modules/shared_500us_tick.v}]
+analyze -file [src {src/modules/i2c_word_reader.v}]
+analyze -file [src {src/rtl/prod2u_por.v}]
+analyze -file [src {src/rtl/prod2u_p4_i2c_stop_start_read.v}]
+analyze -file [src {src/transport/host_port_selector.v}]
+analyze -file [src {src/transport/thermal_host_command.v}]
+analyze -file [src {src/acquisition/bmc_poll_engine.v}]
+analyze -file [src {src/acquisition/bmc_ascii_snapshot.v}]
+analyze -file [src {src/acquisition/ct7428_snapshot.v}]
+analyze -file [src {src/control/thermal_control_core.v}]
+analyze -file [src {src/actuator/pwm_bitmap_engine.v}]
+analyze -file [src {src/telemetry/thermal_snapshot_mux.v}]
+analyze -file [src {src/top/prod2u_6400_v1_top.v}]
 
-elaborate -top {prod2u_6400_front_back_top}
-read_adc {constraints/prod2u_6400_front_back.adc}
+elaborate -top {prod2u_6400_v1_top}
+read_adc [src {constraints/prod2u_6400_front_back.adc}]
 optimize_rtl
-read_sdc {constraints/prod2u_6400_front_back.sdc}
-
-proc fb_find_unique_regs {patterns} {
-    set matches {}
-    foreach pattern $patterns {
-        foreach reg [get_regs -quiet $pattern] {
-            if {[lsearch -exact $matches $reg] < 0} { lappend matches $reg }
-        }
-    }
-    return $matches
-}
-
-set cdc_specs {
-    {uart_rx_0 {{u_uart_rx/rx_sync_pipe\[0\]} {*/u_uart_rx/rx_sync_pipe\[0\]}} u_uart_rx/rx_sync_pipe[0]}
-    {uart_rx_1 {{u_uart_rx/rx_sync_pipe\[1\]} {*/u_uart_rx/rx_sync_pipe\[1\]}} u_uart_rx/rx_sync_pipe[1]}
-    {i2c_scl_0 {{u_temperature_i2c/impl/scl_sync\[0\]} {*/u_temperature_i2c/impl/scl_sync\[0\]}} u_temperature_i2c/scl_sync[0]}
-    {i2c_scl_1 {{u_temperature_i2c/impl/scl_sync\[1\]} {*/u_temperature_i2c/impl/scl_sync\[1\]}} u_temperature_i2c/scl_sync[1]}
-    {i2c_sda_0 {{u_temperature_i2c/impl/sda_sync\[0\]} {*/u_temperature_i2c/impl/sda_sync\[0\]}} u_temperature_i2c/sda_sync[0]}
-    {i2c_sda_1 {{u_temperature_i2c/impl/sda_sync\[1\]} {*/u_temperature_i2c/impl/sda_sync\[1\]}} u_temperature_i2c/sda_sync[1]}
-}
-set cdc_report [open {prod2u_6400_front_back_cdc.rpt} w]
-puts $cdc_report {schema=prod2u-6400-front-back-cdc-estimate-v1}
-set cdc_failures {}
-foreach group $cdc_specs {
-    lassign $group name patterns normalized
-    set matches [fb_find_unique_regs $patterns]
-    if {[llength $matches] != 1} {
-        lappend cdc_failures "$name:[llength $matches]"
-        puts $cdc_report "structural_failure=$name:[llength $matches]"
-    } else {
-        set_property async_reg true [lindex $matches 0]
-        puts $cdc_report "retained_sync_register=$normalized"
-    }
-}
-close $cdc_report
-if {[llength $cdc_failures] != 0} {
-    puts "6400_CDC_ESTIMATE_WARN:[join $cdc_failures ,]"
-}
-
+read_sdc [src {constraints/prod2u_6400_front_back.sdc}]
 report_area -io_info -file prod2u_6400_front_back_rtl.area
 set_param gate opt_area high
 set_param gate pack_effort high
 optimize_gate prod2u_6400_front_back_gate.area
 report_area -io_info -file prod2u_6400_front_back_gate.area
 export_db prod2u_6400_front_back_gate.db
-puts "6400_SYN_DONE=1"
+puts {6400_SYN_DONE=1}

+ 238 - 0
tools/run_6400_td.py

@@ -0,0 +1,238 @@
+#!/usr/bin/env python3
+"""Run clean, source-bound TD synthesis, place/route, and bit generation."""
+
+from __future__ import annotations
+
+import argparse
+from datetime import datetime, timezone
+import hashlib
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+import subprocess
+import sys
+import time
+
+
+ROOT = Path(__file__).resolve().parents[1]
+PROJECT = ROOT / "products/6400-control/project.json"
+CLOSURE = ROOT / "products/6400-control/source-closure.json"
+TD_PROJECT = "td/prod2u_6400_front_back.prj"
+TD_FILES = (
+    "td/syn/prod2u_6400_front_back.tcl",
+    "td/phy/prod2u_6400_front_back.tcl",
+    "td/bitgen/prod2u_6400_front_back.tcl",
+)
+CONSTRAINT_FILES = (
+    "constraints/prod2u_6400_front_back.adc",
+    "constraints/prod2u_6400_front_back.sdc",
+)
+
+
+def sha256(path: Path) -> str:
+    digest = hashlib.sha256()
+    with path.open("rb") as stream:
+        for chunk in iter(lambda: stream.read(1024 * 1024), b""):
+            digest.update(chunk)
+    return digest.hexdigest()
+
+
+def git(*args: str) -> str:
+    return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()
+
+
+def input_manifest() -> dict[str, str]:
+    closure = json.loads(CLOSURE.read_text(encoding="utf-8"))
+    paths = [*closure["sources"], *CONSTRAINT_FILES, TD_PROJECT, *TD_FILES, str(PROJECT.relative_to(ROOT)), str(CLOSURE.relative_to(ROOT))]
+    missing = [item for item in paths if not (ROOT / item).is_file()]
+    if missing:
+        raise RuntimeError(f"source closure contains missing inputs: {missing}")
+    return {item: sha256(ROOT / item) for item in paths}
+
+
+def run_stage(name: str, command: list[str], cwd: Path, env: dict[str, str]) -> dict[str, object]:
+    log_path = cwd / f"{name}.log"
+    started = time.monotonic()
+    with log_path.open("wb") as log:
+        completed = subprocess.run(command, cwd=cwd, env=env, stdout=log, stderr=subprocess.STDOUT, check=False)
+    duration = round(time.monotonic() - started, 3)
+    return {
+        "command": command,
+        "cwd": str(cwd),
+        "exit_code": completed.returncode,
+        "duration_seconds": duration,
+        "log": str(log_path),
+        "log_sha256": sha256(log_path),
+    }
+
+
+def first_int(text: str, patterns: tuple[str, ...]) -> int | None:
+    for pattern in patterns:
+        match = re.search(pattern, text, re.IGNORECASE | re.MULTILINE)
+        if match:
+            return int(match.group(1))
+    return None
+
+
+def first_float(text: str, patterns: tuple[str, ...]) -> float | None:
+    for pattern in patterns:
+        match = re.search(pattern, text, re.IGNORECASE | re.MULTILINE)
+        if match:
+            return float(match.group(1))
+    return None
+
+
+def parse_metrics(run_root: Path) -> dict[str, object]:
+    area_paths = [
+        run_root / "phy/prod2u_6400_front_back_phy.area",
+        run_root / "syn/prod2u_6400_front_back_gate.area",
+    ]
+    area = "\n".join(path.read_text(encoding="utf-8", errors="replace") for path in area_paths if path.is_file())
+    timing_path = run_root / "phy/prod2u_6400_front_back_pr.timing"
+    timing = timing_path.read_text(encoding="utf-8", errors="replace") if timing_path.is_file() else ""
+    return {
+        "total_luts": first_int(area, (r"^#Total_luts\s+(\d+)",)),
+        "lut": first_int(area, (r"^#lut\s+(\d+)",)),
+        "registers": first_int(area, (r"^#reg\s+(\d+)",)),
+        "dsp": first_int(area, (r"^#dsp\s+(\d+)",)),
+        "bram": first_int(area, (r"^#bram\s+(\d+)",)),
+        "mslice": first_int(area, (r"^#MSLICE\s+(\d+)", r"MSLICE\s*[:=]\s*(\d+)")),
+        "lslice": first_int(area, (r"^#LSLICE\s+(\d+)", r"LSLICE\s*[:=]\s*(\d+)")),
+        "packed_slices": first_int(area, (r"Packed(?:/Total)?\s+Slice\w*\s*[:=]\s*(\d+)",)),
+        "fmax_mhz": first_float(timing, (r"Fmax[^\n]*?([0-9]+(?:\.[0-9]+)?)\s*MHz", r"([0-9]+(?:\.[0-9]+)?)\s*MHz")),
+        "setup_slack_ns": first_float(timing, (r"(?:Setup|WNS)[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",)),
+        "hold_slack_ns": first_float(timing, (r"Hold[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",)),
+        "area_reports": [str(path) for path in area_paths if path.is_file()],
+        "timing_report": str(timing_path) if timing_path.is_file() else None,
+    }
+
+
+def warning_audit(stage_records: dict[str, dict[str, object]]) -> dict[str, object]:
+    lines: list[str] = []
+    blocking: list[str] = []
+    blocker = re.compile(r"\b(error|fatal|timing violation|unrouted|not routed|setup failed|hold failed)\b", re.IGNORECASE)
+    noteworthy = re.compile(r"\b(warn(?:ing)?|error|fatal|unconstrained|unassigned|latch|loop)\b", re.IGNORECASE)
+    for record in stage_records.values():
+        log = Path(str(record["log"]))
+        for line in log.read_text(encoding="utf-8", errors="replace").splitlines():
+            if noteworthy.search(line):
+                compact = line.strip()
+                if compact and compact not in lines:
+                    lines.append(compact)
+                if blocker.search(compact):
+                    blocking.append(compact)
+    return {
+        "status": "FAIL" if blocking else "PASS",
+        "noteworthy_count": len(lines),
+        "blocking_count": len(blocking),
+        "blocking": blocking[:100],
+        "noteworthy": lines[:300],
+    }
+
+
+def main(argv: list[str] | None = None) -> int:
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--run-root", type=Path)
+    args = parser.parse_args(argv)
+
+    td = shutil.which("td2026")
+    if td is None:
+        print("TD_MISSING: td2026 is not on PATH", file=sys.stderr)
+        return 4
+    dirty_before = git("status", "--porcelain")
+    if dirty_before:
+        print("TD_BLOCKED: source worktree must be clean", file=sys.stderr)
+        print(dirty_before, file=sys.stderr)
+        return 3
+
+    commit = git("rev-parse", "HEAD")
+    tree = git("rev-parse", "HEAD^{tree}")
+    stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
+    run_id = f"6400-td-{stamp}-{commit[:8]}"
+    run_root = args.run_root or Path(os.environ.get("PROD2U_TD_RUN_ROOT", "/data/prod2u/cpld-runs")) / run_id
+    for stage in ("syn", "phy", "bitgen"):
+        (run_root / stage).mkdir(parents=True, exist_ok=False)
+
+    inputs = input_manifest()
+    manifest_bytes = json.dumps(inputs, sort_keys=True, separators=(",", ":")).encode()
+    version_probe = subprocess.run([td, "-version"], capture_output=True, text=True, check=False)
+    version_text = (version_probe.stdout + version_probe.stderr).strip()
+    env = os.environ.copy()
+    env["PROD2U_SOURCE_ROOT"] = str(ROOT)
+    env["PATH"] = str(ROOT / "tools") + os.pathsep + env.get("PATH", "")
+    stages: dict[str, dict[str, object]] = {}
+    tcl = {
+        "syn": ROOT / TD_FILES[0],
+        "phy": ROOT / TD_FILES[1],
+        "bitgen": ROOT / TD_FILES[2],
+    }
+    status = "PASS"
+    for name in ("syn", "phy", "bitgen"):
+        stages[name] = run_stage(name, [td, str(tcl[name])], run_root / name, env)
+        print(f"{name}: exit={stages[name]['exit_code']} duration_s={stages[name]['duration_seconds']}", flush=True)
+        if stages[name]["exit_code"] != 0:
+            status = "FAIL"
+            break
+
+    expected = {
+        "syn": run_root / "syn/prod2u_6400_front_back_gate.db",
+        "phy": run_root / "phy/prod2u_6400_front_back_pr.db",
+        "bitgen": run_root / "bitgen/prod2u_6400_front_back.bit",
+    }
+    missing = [name for name, path in expected.items() if name in stages and stages[name]["exit_code"] == 0 and not path.is_file()]
+    if missing:
+        status = "FAIL"
+    audit = warning_audit(stages)
+    if audit["status"] != "PASS":
+        status = "FAIL"
+    bitstream = expected["bitgen"]
+    receipt = {
+        "schema": "prod2u-6400-td-receipt-v1",
+        "run_id": run_id,
+        "status": status,
+        "generated_at": datetime.now(timezone.utc).isoformat(),
+        "commit": commit,
+        "tree": tree,
+        "branch": git("branch", "--show-current"),
+        "clean_before": not bool(dirty_before),
+        "clean_after": not bool(git("status", "--porcelain")),
+        "project": str(PROJECT.relative_to(ROOT)),
+        "project_sha256": sha256(PROJECT),
+        "source_closure": str(CLOSURE.relative_to(ROOT)),
+        "source_closure_sha256": sha256(CLOSURE),
+        "source_manifest_sha256": hashlib.sha256(manifest_bytes).hexdigest(),
+        "inputs": inputs,
+        "tool": {
+            "command": "td2026",
+            "resolved": td,
+            "version_probe_exit": version_probe.returncode,
+            "version": version_text,
+            "container_image_id": os.environ.get("PROD2U_CONTAINER_IMAGE_ID"),
+            "container_digest": os.environ.get("PROD2U_CONTAINER_DIGEST"),
+        },
+        "safety": {"opens_serial": False, "programs_hardware": False, "jtag": False},
+        "stages": stages,
+        "missing_outputs": missing,
+        "warning_audit": audit,
+        "metrics": parse_metrics(run_root),
+        "bitstream": str(bitstream) if bitstream.is_file() else None,
+        "bitstream_sha256": sha256(bitstream) if bitstream.is_file() else None,
+    }
+    receipt_path = run_root / "td-receipt.json"
+    receipt_path.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8")
+    print(receipt_path)
+    if status != "PASS":
+        for name, record in stages.items():
+            if record["exit_code"] != 0:
+                log = Path(str(record["log"]))
+                print(f"--- {name} log tail ---", file=sys.stderr)
+                print("\n".join(log.read_text(encoding="utf-8", errors="replace").splitlines()[-120:]), file=sys.stderr)
+        return 1
+    print(f"TD_PASS bitstream_sha256={receipt['bitstream_sha256']}")
+    return 0
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())

+ 7 - 0
tools/td2026

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -euo pipefail
+td_root="${PRODU2_TD_ROOT:-/data/anlogic/TD_Release_2026.1_SP2_NL}"
+export LD_LIBRARY_PATH="${td_root}/lib:${td_root}/lib/Qt/lib"
+export QT_PLUGIN_PATH="${td_root}/lib/Qt/plugins"
+export QT_QPA_PLATFORM=offscreen
+exec "${td_root}/bin/td.sh" "$@"