|
@@ -22,12 +22,29 @@ if str(_ROOT) not in sys.path:
|
|
|
|
|
|
|
|
from tools.generate_target import generate_named_target
|
|
from tools.generate_target import generate_named_target
|
|
|
from tools.generate_6400_v1 import generate as generate_6400_v1
|
|
from tools.generate_6400_v1 import generate as generate_6400_v1
|
|
|
-from tools.run_6400_td import HARDWARE_PROFILES, source_closure as td_source_closure
|
|
|
|
|
|
|
+from tools.run_6400_td import (
|
|
|
|
|
+ EXPECTED_UNBOUND_PORTS,
|
|
|
|
|
+ HARDWARE_PROFILES,
|
|
|
|
|
+ input_manifest as td_input_manifest,
|
|
|
|
|
+ source_closure as td_source_closure,
|
|
|
|
|
+)
|
|
|
from tools.target_registry import ROOT, load_source_closure, release_blocked, resolve_target
|
|
from tools.target_registry import ROOT, load_source_closure, release_blocked, resolve_target
|
|
|
|
|
|
|
|
|
|
|
|
|
CANDIDATE_NOTICE_ZH_CN = "候选,仅供审核;未冻结TTL Pin/未做硬件验证前不要烧录"
|
|
CANDIDATE_NOTICE_ZH_CN = "候选,仅供审核;未冻结TTL Pin/未做硬件验证前不要烧录"
|
|
|
DO_NOT_PROGRAM_LINE = "DO NOT PROGRAM / 不要烧录"
|
|
DO_NOT_PROGRAM_LINE = "DO NOT PROGRAM / 不要烧录"
|
|
|
|
|
+CONTROL_DEPLOYMENT_STATUS = (
|
|
|
|
|
+ "UNSAFE_UNTIL_HOST_TTL_PINS_ARE_FROZEN_AND_HARDWARE_VALIDATED"
|
|
|
|
|
+)
|
|
|
|
|
+IDENTIFICATION_DEPLOYMENT_STATUS = (
|
|
|
|
|
+ "IDENTIFICATION_ONLY_NOT_FOR_PRODUCTION_OR_DEPLOYMENT"
|
|
|
|
|
+)
|
|
|
|
|
+FORBIDDEN_PROGRAM_INSTRUCTIONS = (
|
|
|
|
|
+ "Erase/Program",
|
|
|
|
|
+ "执行 Erase",
|
|
|
|
|
+ "执行 Program",
|
|
|
|
|
+ "JTAG 下载器",
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
|
|
|
|
|
def _sha256(path: Path) -> str:
|
|
def _sha256(path: Path) -> str:
|
|
@@ -38,6 +55,24 @@ def _sha256(path: Path) -> str:
|
|
|
return digest.hexdigest()
|
|
return digest.hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _expected_deployment_status(profile_name: str) -> str:
|
|
|
|
|
+ return (
|
|
|
|
|
+ CONTROL_DEPLOYMENT_STATUS
|
|
|
|
|
+ if bool(HARDWARE_PROFILES[profile_name]["production"])
|
|
|
|
|
+ else IDENTIFICATION_DEPLOYMENT_STATUS
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _contract_sha256() -> str:
|
|
|
|
|
+ payload = json.loads(
|
|
|
|
|
+ (ROOT / "generated/6400/host-contract.json").read_text(encoding="utf-8")
|
|
|
|
|
+ )
|
|
|
|
|
+ value = payload.get("contract_sha256")
|
|
|
|
|
+ if not isinstance(value, str) or not re.fullmatch(r"[0-9a-f]{64}", value):
|
|
|
|
|
+ raise SystemExit("6400 package blocked: invalid generated contract SHA-256")
|
|
|
|
|
+ return value
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _git(repo: Path, *args: str) -> str:
|
|
def _git(repo: Path, *args: str) -> str:
|
|
|
try:
|
|
try:
|
|
|
return subprocess.check_output(["git", *args], cwd=repo, text=True, stderr=subprocess.DEVNULL).strip()
|
|
return subprocess.check_output(["git", *args], cwd=repo, text=True, stderr=subprocess.DEVNULL).strip()
|
|
@@ -77,7 +112,7 @@ def _resolve_6400_profile(target_name: str, profile_name: str | None) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
def _validated_td_bitstream(
|
|
def _validated_td_bitstream(
|
|
|
- profile_name: str, receipt_path: Path | None, commit: str
|
|
|
|
|
|
|
+ profile_name: str, receipt_path: Path | None, package_commit: str
|
|
|
) -> tuple[Path, dict[str, object]]:
|
|
) -> tuple[Path, dict[str, object]]:
|
|
|
if receipt_path is None or not receipt_path.is_file():
|
|
if receipt_path is None or not receipt_path.is_file():
|
|
|
raise SystemExit("6400 firmware package blocked: explicit --td-receipt is required")
|
|
raise SystemExit("6400 firmware package blocked: explicit --td-receipt is required")
|
|
@@ -85,13 +120,16 @@ def _validated_td_bitstream(
|
|
|
profile = HARDWARE_PROFILES[profile_name]
|
|
profile = HARDWARE_PROFILES[profile_name]
|
|
|
project_path = ROOT / str(profile["project"])
|
|
project_path = ROOT / str(profile["project"])
|
|
|
closure_path = ROOT / str(profile["closure"])
|
|
closure_path = ROOT / str(profile["closure"])
|
|
|
|
|
+ current_inputs = td_input_manifest(profile_name)
|
|
|
|
|
+ source_manifest_sha256 = hashlib.sha256(
|
|
|
|
|
+ json.dumps(current_inputs, sort_keys=True, separators=(",", ":")).encode()
|
|
|
|
|
+ ).hexdigest()
|
|
|
expected = {
|
|
expected = {
|
|
|
"schema": "prod2u-6400-td-receipt-v1",
|
|
"schema": "prod2u-6400-td-receipt-v1",
|
|
|
"status": "PASS",
|
|
"status": "PASS",
|
|
|
"profile": profile_name,
|
|
"profile": profile_name,
|
|
|
"project": str(profile["project"]),
|
|
"project": str(profile["project"]),
|
|
|
"source_closure": str(profile["closure"]),
|
|
"source_closure": str(profile["closure"]),
|
|
|
- "commit": commit,
|
|
|
|
|
"production": bool(profile["production"]),
|
|
"production": bool(profile["production"]),
|
|
|
"stimulus": bool(profile["stimulus"]),
|
|
"stimulus": bool(profile["stimulus"]),
|
|
|
"simulation_only": False,
|
|
"simulation_only": False,
|
|
@@ -99,6 +137,10 @@ def _validated_td_bitstream(
|
|
|
"timing_pass_25mhz": True,
|
|
"timing_pass_25mhz": True,
|
|
|
"project_sha256": _sha256(project_path),
|
|
"project_sha256": _sha256(project_path),
|
|
|
"source_closure_sha256": _sha256(closure_path),
|
|
"source_closure_sha256": _sha256(closure_path),
|
|
|
|
|
+ "source_manifest_sha256": source_manifest_sha256,
|
|
|
|
|
+ "inputs": current_inputs,
|
|
|
|
|
+ "known_unbound_ports": list(EXPECTED_UNBOUND_PORTS),
|
|
|
|
|
+ "deployment_status": _expected_deployment_status(profile_name),
|
|
|
}
|
|
}
|
|
|
mismatches = [
|
|
mismatches = [
|
|
|
f"{key}: expected {value!r}, got {receipt.get(key)!r}"
|
|
f"{key}: expected {value!r}, got {receipt.get(key)!r}"
|
|
@@ -107,22 +149,31 @@ def _validated_td_bitstream(
|
|
|
]
|
|
]
|
|
|
if mismatches:
|
|
if mismatches:
|
|
|
raise SystemExit("6400 firmware package blocked: TD receipt mismatch: " + "; ".join(mismatches))
|
|
raise SystemExit("6400 firmware package blocked: TD receipt mismatch: " + "; ".join(mismatches))
|
|
|
- known_unbound_ports = receipt.get("known_unbound_ports")
|
|
|
|
|
- if (
|
|
|
|
|
- not isinstance(known_unbound_ports, list)
|
|
|
|
|
- or any(
|
|
|
|
|
- not isinstance(port, str) or not port
|
|
|
|
|
- for port in known_unbound_ports
|
|
|
|
|
- )
|
|
|
|
|
- or len(set(known_unbound_ports)) != len(known_unbound_ports)
|
|
|
|
|
|
|
+ source_commit = receipt.get("commit")
|
|
|
|
|
+ if not isinstance(source_commit, str) or not re.fullmatch(
|
|
|
|
|
+ r"[0-9a-f]{40}", source_commit
|
|
|
):
|
|
):
|
|
|
raise SystemExit(
|
|
raise SystemExit(
|
|
|
- "6400 firmware package blocked: TD receipt has invalid known_unbound_ports"
|
|
|
|
|
|
|
+ "6400 firmware package blocked: TD receipt has invalid source commit"
|
|
|
|
|
+ )
|
|
|
|
|
+ if not re.fullmatch(r"[0-9a-f]{40}", package_commit):
|
|
|
|
|
+ raise SystemExit(
|
|
|
|
|
+ "6400 firmware package blocked: exact package commit is unavailable"
|
|
|
)
|
|
)
|
|
|
- deployment_status = receipt.get("deployment_status")
|
|
|
|
|
- if not isinstance(deployment_status, str) or not deployment_status:
|
|
|
|
|
|
|
+ warning_audit = receipt.get("warning_audit")
|
|
|
|
|
+ expected_ports = list(EXPECTED_UNBOUND_PORTS)
|
|
|
|
|
+ if not isinstance(warning_audit, dict) or any(
|
|
|
|
|
+ warning_audit.get(key) != value
|
|
|
|
|
+ for key, value in {
|
|
|
|
|
+ "status": "PASS",
|
|
|
|
|
+ "expected_unbound_ports": expected_ports,
|
|
|
|
|
+ "observed_unbound_ports": expected_ports,
|
|
|
|
|
+ "unexpected_unbound_ports": [],
|
|
|
|
|
+ "missing_expected_unbound_ports": [],
|
|
|
|
|
+ }.items()
|
|
|
|
|
+ ):
|
|
|
raise SystemExit(
|
|
raise SystemExit(
|
|
|
- "6400 firmware package blocked: TD receipt has invalid deployment_status"
|
|
|
|
|
|
|
+ "6400 firmware package blocked: TD warning audit mismatch"
|
|
|
)
|
|
)
|
|
|
bitstream_value = receipt.get("bitstream")
|
|
bitstream_value = receipt.get("bitstream")
|
|
|
if not isinstance(bitstream_value, str) or not bitstream_value:
|
|
if not isinstance(bitstream_value, str) or not bitstream_value:
|
|
@@ -153,6 +204,7 @@ def build_target_package(
|
|
|
hardware_validation = "NOT RUN"
|
|
hardware_validation = "NOT RUN"
|
|
|
known_unbound_ports: tuple[str, ...] = ()
|
|
known_unbound_ports: tuple[str, ...] = ()
|
|
|
deployment_status: str | None = None
|
|
deployment_status: str | None = None
|
|
|
|
|
+ source_commit: str | None = None
|
|
|
if is_6400:
|
|
if is_6400:
|
|
|
selected_profile = _resolve_6400_profile(target_name, profile_name)
|
|
selected_profile = _resolve_6400_profile(target_name, profile_name)
|
|
|
profile = HARDWARE_PROFILES[selected_profile]
|
|
profile = HARDWARE_PROFILES[selected_profile]
|
|
@@ -206,7 +258,14 @@ def build_target_package(
|
|
|
assert isinstance(status_value, str)
|
|
assert isinstance(status_value, str)
|
|
|
known_unbound_ports = tuple(ports_value)
|
|
known_unbound_ports = tuple(ports_value)
|
|
|
deployment_status = status_value
|
|
deployment_status = status_value
|
|
|
- blocked = bool(known_unbound_ports) or hardware_validation != "PASS"
|
|
|
|
|
|
|
+ source_commit_value = receipt_payload["commit"]
|
|
|
|
|
+ assert isinstance(source_commit_value, str)
|
|
|
|
|
+ source_commit = source_commit_value
|
|
|
|
|
+ blocked = (
|
|
|
|
|
+ bool(known_unbound_ports)
|
|
|
|
|
+ or hardware_validation != "PASS"
|
|
|
|
|
+ or not bool(profile["production"])
|
|
|
|
|
+ )
|
|
|
pins = known_unbound_ports
|
|
pins = known_unbound_ports
|
|
|
run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
|
name = f"prod2u-{package_label}-{kind}-{commit[:12]}-{run_id}"
|
|
name = f"prod2u-{package_label}-{kind}-{commit[:12]}-{run_id}"
|
|
@@ -237,6 +296,7 @@ def build_target_package(
|
|
|
if is_6400:
|
|
if is_6400:
|
|
|
manifest.update(
|
|
manifest.update(
|
|
|
{
|
|
{
|
|
|
|
|
+ "contract_sha256": _contract_sha256(),
|
|
|
"production": bool(profile["production"]),
|
|
"production": bool(profile["production"]),
|
|
|
"stimulus": bool(profile["stimulus"]),
|
|
"stimulus": bool(profile["stimulus"]),
|
|
|
"simulation_only": False,
|
|
"simulation_only": False,
|
|
@@ -249,6 +309,8 @@ def build_target_package(
|
|
|
"candidate_only": blocked,
|
|
"candidate_only": blocked,
|
|
|
"deployable": not blocked,
|
|
"deployable": not blocked,
|
|
|
"deployment_status": deployment_status,
|
|
"deployment_status": deployment_status,
|
|
|
|
|
+ "source_commit": source_commit,
|
|
|
|
|
+ "package_commit": commit,
|
|
|
"known_unbound_ports": list(known_unbound_ports),
|
|
"known_unbound_ports": list(known_unbound_ports),
|
|
|
"unresolved_ports": list(known_unbound_ports),
|
|
"unresolved_ports": list(known_unbound_ports),
|
|
|
}
|
|
}
|
|
@@ -361,9 +423,11 @@ def _selftest(zip_path: Path) -> None:
|
|
|
if "src/generated/6400" in closure_text or "prod2u_6400_front_back_top" in closure_text:
|
|
if "src/generated/6400" in closure_text or "prod2u_6400_front_back_top" in closure_text:
|
|
|
raise SystemExit("package selftest: historical 6400 closure leaked")
|
|
raise SystemExit("package selftest: historical 6400 closure leaked")
|
|
|
if manifest.get("target_alias") == "6400" and manifest.get("kind") == "firmware":
|
|
if manifest.get("target_alias") == "6400" and manifest.get("kind") == "firmware":
|
|
|
|
|
+ profile_name = manifest["profile"]
|
|
|
|
|
+ profile = HARDWARE_PROFILES[profile_name]
|
|
|
expected_name = (
|
|
expected_name = (
|
|
|
"prod2u_6400_front_back.bit"
|
|
"prod2u_6400_front_back.bit"
|
|
|
- if manifest["profile"] == "6400-control"
|
|
|
|
|
|
|
+ if profile_name == "6400-control"
|
|
|
else "prod2u_6400_identification.bit"
|
|
else "prod2u_6400_identification.bit"
|
|
|
)
|
|
)
|
|
|
bit = dest / expected_name
|
|
bit = dest / expected_name
|
|
@@ -372,27 +436,62 @@ def _selftest(zip_path: Path) -> None:
|
|
|
receipt = json.loads(
|
|
receipt = json.loads(
|
|
|
(dest / "TD-BUILD-RECEIPT.json").read_text(encoding="utf-8")
|
|
(dest / "TD-BUILD-RECEIPT.json").read_text(encoding="utf-8")
|
|
|
)
|
|
)
|
|
|
- if receipt.get("profile") != manifest["profile"] or receipt.get(
|
|
|
|
|
|
|
+ if receipt.get("profile") != profile_name or receipt.get(
|
|
|
"bitstream_sha256"
|
|
"bitstream_sha256"
|
|
|
) != manifest["bitstream_sha256"]:
|
|
) != manifest["bitstream_sha256"]:
|
|
|
raise SystemExit("package selftest: TD receipt/profile identity mismatch")
|
|
raise SystemExit("package selftest: TD receipt/profile identity mismatch")
|
|
|
|
|
+ embedded_contract = json.loads(
|
|
|
|
|
+ (dest / "generated/6400/host-contract.json").read_text(
|
|
|
|
|
+ encoding="utf-8"
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ if (
|
|
|
|
|
+ manifest.get("contract_sha256")
|
|
|
|
|
+ != embedded_contract.get("contract_sha256")
|
|
|
|
|
+ or manifest.get("source_commit") != receipt.get("commit")
|
|
|
|
|
+ or manifest.get("package_commit") != manifest.get("commit")
|
|
|
|
|
+ or receipt.get("inputs") != td_input_manifest(profile_name)
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise SystemExit("package selftest: firmware provenance mismatch")
|
|
|
|
|
+ expected_input_sha = hashlib.sha256(
|
|
|
|
|
+ json.dumps(
|
|
|
|
|
+ receipt["inputs"], sort_keys=True, separators=(",", ":")
|
|
|
|
|
+ ).encode()
|
|
|
|
|
+ ).hexdigest()
|
|
|
|
|
+ if (
|
|
|
|
|
+ receipt.get("source_manifest_sha256") != expected_input_sha
|
|
|
|
|
+ or receipt.get("project_sha256") != _sha256(dest / "project.json")
|
|
|
|
|
+ or receipt.get("source_closure_sha256")
|
|
|
|
|
+ != _sha256(dest / "source-closure.json")
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise SystemExit("package selftest: TD input digest mismatch")
|
|
|
receipt_ports = receipt.get("known_unbound_ports")
|
|
receipt_ports = receipt.get("known_unbound_ports")
|
|
|
|
|
+ expected_ports = list(EXPECTED_UNBOUND_PORTS)
|
|
|
|
|
+ warning_audit = receipt.get("warning_audit")
|
|
|
if (
|
|
if (
|
|
|
manifest.get("release_blocked") is not True
|
|
manifest.get("release_blocked") is not True
|
|
|
or manifest.get("deployable") is not False
|
|
or manifest.get("deployable") is not False
|
|
|
or manifest.get("candidate_only") is not True
|
|
or manifest.get("candidate_only") is not True
|
|
|
|
|
+ or receipt_ports != expected_ports
|
|
|
or manifest.get("known_unbound_ports") != receipt_ports
|
|
or manifest.get("known_unbound_ports") != receipt_ports
|
|
|
or manifest.get("unresolved_ports") != receipt_ports
|
|
or manifest.get("unresolved_ports") != receipt_ports
|
|
|
or manifest.get("unresolved_pins") != receipt_ports
|
|
or manifest.get("unresolved_pins") != receipt_ports
|
|
|
- or manifest.get("deployment_status") != receipt.get("deployment_status")
|
|
|
|
|
|
|
+ or receipt.get("deployment_status")
|
|
|
|
|
+ != _expected_deployment_status(profile_name)
|
|
|
|
|
+ or manifest.get("deployment_status")
|
|
|
|
|
+ != receipt.get("deployment_status")
|
|
|
|
|
+ or not isinstance(warning_audit, dict)
|
|
|
|
|
+ or warning_audit.get("status") != "PASS"
|
|
|
|
|
+ or warning_audit.get("observed_unbound_ports") != expected_ports
|
|
|
):
|
|
):
|
|
|
raise SystemExit("package selftest: unsafe deployment gate mismatch")
|
|
raise SystemExit("package selftest: unsafe deployment gate mismatch")
|
|
|
if not (dest / "CANDIDATE-NOTICE.zh-CN.txt").is_file():
|
|
if not (dest / "CANDIDATE-NOTICE.zh-CN.txt").is_file():
|
|
|
raise SystemExit("package selftest: candidate notice missing")
|
|
raise SystemExit("package selftest: candidate notice missing")
|
|
|
- production = manifest["profile"] == "6400-control"
|
|
|
|
|
- if manifest.get("production") is not production or manifest.get(
|
|
|
|
|
- "stimulus"
|
|
|
|
|
- ) is production:
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ manifest.get("production") is not bool(profile["production"])
|
|
|
|
|
+ or manifest.get("stimulus") is not bool(profile["stimulus"])
|
|
|
|
|
+ or (not bool(profile["production"]) and manifest.get("deployable"))
|
|
|
|
|
+ ):
|
|
|
raise SystemExit("package selftest: firmware profile semantics mismatch")
|
|
raise SystemExit("package selftest: firmware profile semantics mismatch")
|
|
|
instructions = (dest / "FLASH-INSTRUCTIONS.zh-CN.txt").read_text(
|
|
instructions = (dest / "FLASH-INSTRUCTIONS.zh-CN.txt").read_text(
|
|
|
encoding="utf-8"
|
|
encoding="utf-8"
|
|
@@ -401,6 +500,7 @@ def _selftest(zip_path: Path) -> None:
|
|
|
not instructions.startswith(DO_NOT_PROGRAM_LINE)
|
|
not instructions.startswith(DO_NOT_PROGRAM_LINE)
|
|
|
or "921600 8N1" not in instructions
|
|
or "921600 8N1" not in instructions
|
|
|
or "独立 ACK" not in instructions
|
|
or "独立 ACK" not in instructions
|
|
|
|
|
+ or any(token in instructions for token in FORBIDDEN_PROGRAM_INSTRUCTIONS)
|
|
|
):
|
|
):
|
|
|
raise SystemExit("package selftest: Host UART/ACK contract missing")
|
|
raise SystemExit("package selftest: Host UART/ACK contract missing")
|
|
|
|
|
|