|
|
@@ -440,6 +440,160 @@ def compute_release_set_id(
|
|
|
)
|
|
|
|
|
|
|
|
|
+# Canonical A1 full-chip TD on ff44128a (Round-9 identity source — not hardcoded nulls).
|
|
|
+CANONICAL_TD_A1_RECEIPT = "receipts/mse-r4-td-a1-ff44128.json"
|
|
|
+CANONICAL_TD_A1_RECEIPT_FULL = "receipts/mse-r4-td-a1-ff44128-full.json"
|
|
|
+CANONICAL_TD_A1_BITSTREAM = (
|
|
|
+ "b4b0eda4ee8d774109eff83b519bdaa19d5e73d770562983121a596df00952d0"
|
|
|
+)
|
|
|
+CANONICAL_TD_A1_BOUND_COMMIT = "ff44128a540b7ffd9d82314093b242ac3aee92d7"
|
|
|
+
|
|
|
+
|
|
|
+def load_canonical_td_a1_fields(repo_root: Path | None = None) -> dict[str, Any]:
|
|
|
+ """Load TD run IDs / bitstream / receipt SHA from the on-disk A1 TD receipts.
|
|
|
+
|
|
|
+ When a package claims bitstream ``b4b0eda4…``, identity MUST carry
|
|
|
+ ``td_artifact_run_id`` and ``td_receipt_sha256`` derived here — never null.
|
|
|
+ """
|
|
|
+ root = Path(repo_root or ROOT)
|
|
|
+ compact = root / CANONICAL_TD_A1_RECEIPT
|
|
|
+ full = root / CANONICAL_TD_A1_RECEIPT_FULL
|
|
|
+ if not compact.is_file():
|
|
|
+ raise FileNotFoundError(f"missing canonical TD receipt: {compact}")
|
|
|
+ compact_bytes = compact.read_bytes()
|
|
|
+ compact_doc = json.loads(compact_bytes.decode("utf-8"))
|
|
|
+ full_doc: dict[str, Any] = {}
|
|
|
+ if full.is_file():
|
|
|
+ full_doc = json.loads(full.read_text(encoding="utf-8"))
|
|
|
+ run_id = str(compact_doc.get("run_id") or full_doc.get("run_id") or "").strip()
|
|
|
+ if not run_id:
|
|
|
+ raise ValueError(f"canonical TD receipt missing run_id: {compact}")
|
|
|
+ bitstream = str(
|
|
|
+ compact_doc.get("bitstream_sha256") or full_doc.get("bitstream_sha256") or ""
|
|
|
+ ).strip()
|
|
|
+ if bitstream and bitstream != CANONICAL_TD_A1_BITSTREAM:
|
|
|
+ raise ValueError(
|
|
|
+ f"canonical TD bitstream mismatch: {bitstream} != {CANONICAL_TD_A1_BITSTREAM}"
|
|
|
+ )
|
|
|
+ bound = str(
|
|
|
+ compact_doc.get("commit")
|
|
|
+ or full_doc.get("commit")
|
|
|
+ or CANONICAL_TD_A1_BOUND_COMMIT
|
|
|
+ ).strip()
|
|
|
+ verification_run_id = str(
|
|
|
+ full_doc.get("verification_run_id")
|
|
|
+ or compact_doc.get("verification_run_id")
|
|
|
+ or ""
|
|
|
+ ).strip()
|
|
|
+ resources = compact_doc.get("resources") or full_doc.get("resources") or {}
|
|
|
+ util = resources.get("utilization") if isinstance(resources, dict) else {}
|
|
|
+ lut = None
|
|
|
+ mslice = None
|
|
|
+ dsp = None
|
|
|
+ if isinstance(util, dict):
|
|
|
+ lut = (util.get("lut") or {}).get("used")
|
|
|
+ # Anlogic area: LE≈MSLICE packing proxy used historically as mslice
|
|
|
+ mslice = (util.get("le") or {}).get("used") or lut
|
|
|
+ dsp = (util.get("dsp") or {}).get("used")
|
|
|
+ return {
|
|
|
+ "td_bound_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|
|
|
+ "artifact_source_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|
|
|
+ "bitstream_sha256": bitstream or CANONICAL_TD_A1_BITSTREAM,
|
|
|
+ "td_artifact_run_id": run_id,
|
|
|
+ "td_verification_run_id": verification_run_id or None,
|
|
|
+ "td_receipt_path": str(compact.relative_to(root)).replace("\\", "/"),
|
|
|
+ "td_receipt_sha256": _sha256_bytes(compact_bytes),
|
|
|
+ "td_receipt_full_path": (
|
|
|
+ str(full.relative_to(root)).replace("\\", "/") if full.is_file() else None
|
|
|
+ ),
|
|
|
+ "td_receipt_full_sha256": (
|
|
|
+ _sha256_bytes(full.read_bytes()) if full.is_file() else None
|
|
|
+ ),
|
|
|
+ "td_binding_status": "pass",
|
|
|
+ "production_binding": "37/37/0/0",
|
|
|
+ "lut": lut,
|
|
|
+ "mslice": mslice,
|
|
|
+ "dsp": dsp,
|
|
|
+ "status": compact_doc.get("status") or full_doc.get("status"),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+def build_shared_release_identity(
|
|
|
+ *,
|
|
|
+ delivery_commit: str,
|
|
|
+ package_stage: str,
|
|
|
+ matrix_verification_tip: str | None,
|
|
|
+ software_verification_run_id: str | None,
|
|
|
+ config_fingerprint: str,
|
|
|
+ reference_set_fingerprint: str,
|
|
|
+ repo_root: Path | None = None,
|
|
|
+ base_dev_commit: str = BASE_DEV_COMMIT_DEFAULT,
|
|
|
+ hardware_validation: str = "not_run",
|
|
|
+ non_final: bool | None = None,
|
|
|
+ claim_bound_bitstream: bool = True,
|
|
|
+ extra: dict[str, Any] | None = None,
|
|
|
+) -> dict[str, Any]:
|
|
|
+ """Single shared release identity for review + firmware packages.
|
|
|
+
|
|
|
+ When ``claim_bound_bitstream`` is true, TD fields are loaded from the
|
|
|
+ canonical A1 receipt (never null run_id / receipt SHA).
|
|
|
+ """
|
|
|
+ stage = package_stage.strip()
|
|
|
+ if non_final is None:
|
|
|
+ non_final = stage == "intermediate-review"
|
|
|
+ delivery = str(delivery_commit).strip()
|
|
|
+ if not delivery:
|
|
|
+ raise ValueError("delivery_commit required")
|
|
|
+ td = load_canonical_td_a1_fields(repo_root) if claim_bound_bitstream else {}
|
|
|
+ artifact = str(td.get("artifact_source_commit") or CANONICAL_TD_A1_BOUND_COMMIT)
|
|
|
+ td_run = str(td.get("td_artifact_run_id") or "")
|
|
|
+ bitstream = str(td.get("bitstream_sha256") or "")
|
|
|
+ if claim_bound_bitstream and (not td_run or not bitstream):
|
|
|
+ raise ValueError("claim_bound_bitstream requires td_artifact_run_id + bitstream")
|
|
|
+ release_set_id = compute_release_set_id(
|
|
|
+ artifact_commit=artifact,
|
|
|
+ delivery_commit=delivery,
|
|
|
+ bitstream_sha256=bitstream or ("0" * 64),
|
|
|
+ config_fingerprint=config_fingerprint,
|
|
|
+ td_run_id=td_run or f"nonfinal-{delivery[:8]}",
|
|
|
+ reference_set_fingerprint_sha256=reference_set_fingerprint,
|
|
|
+ base_dev_commit=base_dev_commit,
|
|
|
+ td_bound_commit=str(td.get("td_bound_commit") or artifact),
|
|
|
+ package_stage=stage,
|
|
|
+ hardware_validation=hardware_validation,
|
|
|
+ )
|
|
|
+ identity: dict[str, Any] = {
|
|
|
+ "schema": "prod2u-release-set-identity-v1",
|
|
|
+ "algorithm_version": "prod2u-release-set-id-v1",
|
|
|
+ "package_stage": stage,
|
|
|
+ "non_final": bool(non_final),
|
|
|
+ "release_set_id": release_set_id,
|
|
|
+ "base_dev_commit": base_dev_commit,
|
|
|
+ "matrix_verification_tip": matrix_verification_tip or None,
|
|
|
+ "software_verification_run_id": software_verification_run_id or None,
|
|
|
+ "verification_tip": matrix_verification_tip or None,
|
|
|
+ "verification_run_id": software_verification_run_id or None,
|
|
|
+ "td_bound_commit": td.get("td_bound_commit") or artifact,
|
|
|
+ "artifact_source_commit": artifact,
|
|
|
+ "delivery_commit": delivery,
|
|
|
+ "bitstream_sha256": bitstream or None,
|
|
|
+ "td_verification_run_id": td.get("td_verification_run_id"),
|
|
|
+ "td_artifact_run_id": td_run or None,
|
|
|
+ "td_receipt_sha256": td.get("td_receipt_sha256"),
|
|
|
+ "td_binding_status": td.get("td_binding_status") or ("pass" if claim_bound_bitstream else None),
|
|
|
+ "production_binding": td.get("production_binding") if claim_bound_bitstream else None,
|
|
|
+ "production_polarity_fingerprint": config_fingerprint,
|
|
|
+ "reference_set_fingerprint": reference_set_fingerprint,
|
|
|
+ "hardware_validation": hardware_validation,
|
|
|
+ "lut": td.get("lut"),
|
|
|
+ "mslice": td.get("mslice"),
|
|
|
+ "dsp": td.get("dsp"),
|
|
|
+ }
|
|
|
+ if extra:
|
|
|
+ identity.update(extra)
|
|
|
+ return identity
|
|
|
+
|
|
|
+
|
|
|
def sibling_role_stub(
|
|
|
*,
|
|
|
role: str,
|