package_target.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #!/usr/bin/env python3
  2. """Target-bound source/review/firmware packager with fail-closed release pins."""
  3. from __future__ import annotations
  4. import argparse
  5. import hashlib
  6. import json
  7. import os
  8. import re
  9. import shutil
  10. import subprocess
  11. import sys
  12. import tempfile
  13. import zipfile
  14. from datetime import datetime, timezone
  15. from pathlib import Path
  16. _ROOT = Path(__file__).resolve().parents[1]
  17. if str(_ROOT) not in sys.path:
  18. sys.path.insert(0, str(_ROOT))
  19. from tools.generate_target import generate_named_target
  20. from tools.generate_6400_v1 import generate as generate_6400_v1
  21. from tools.run_6400_td import (
  22. EXPECTED_UNBOUND_PORTS,
  23. HARDWARE_PROFILES,
  24. input_manifest as td_input_manifest,
  25. source_closure as td_source_closure,
  26. )
  27. from tools.target_registry import ROOT, load_source_closure, release_blocked, resolve_target
  28. CANDIDATE_NOTICE_ZH_CN = "候选,仅供审核;未冻结TTL Pin/未做硬件验证前不要烧录"
  29. DO_NOT_PROGRAM_LINE = "DO NOT PROGRAM / 不要烧录"
  30. CONTROL_DEPLOYMENT_STATUS = (
  31. "UNSAFE_UNTIL_HOST_TTL_PINS_ARE_FROZEN_AND_HARDWARE_VALIDATED"
  32. )
  33. IDENTIFICATION_DEPLOYMENT_STATUS = (
  34. "IDENTIFICATION_ONLY_NOT_FOR_PRODUCTION_OR_DEPLOYMENT"
  35. )
  36. FORBIDDEN_PROGRAM_INSTRUCTIONS = (
  37. "Erase/Program",
  38. "执行 Erase",
  39. "执行 Program",
  40. "JTAG 下载器",
  41. )
  42. def _sha256(path: Path) -> str:
  43. digest = hashlib.sha256()
  44. with path.open("rb") as handle:
  45. for chunk in iter(lambda: handle.read(1024 * 1024), b""):
  46. digest.update(chunk)
  47. return digest.hexdigest()
  48. def _expected_deployment_status(profile_name: str) -> str:
  49. return (
  50. CONTROL_DEPLOYMENT_STATUS
  51. if bool(HARDWARE_PROFILES[profile_name]["production"])
  52. else IDENTIFICATION_DEPLOYMENT_STATUS
  53. )
  54. def _contract_sha256() -> str:
  55. payload = json.loads(
  56. (ROOT / "generated/6400/host-contract.json").read_text(encoding="utf-8")
  57. )
  58. value = payload.get("contract_sha256")
  59. if not isinstance(value, str) or not re.fullmatch(r"[0-9a-f]{64}", value):
  60. raise SystemExit("6400 package blocked: invalid generated contract SHA-256")
  61. return value
  62. def _git(repo: Path, *args: str) -> str:
  63. try:
  64. return subprocess.check_output(["git", *args], cwd=repo, text=True, stderr=subprocess.DEVNULL).strip()
  65. except (OSError, subprocess.CalledProcessError):
  66. return os.environ.get("PROD2U_COMMIT", "unknown")
  67. def _add(zipf: zipfile.ZipFile, src: Path, dest: str, sums: dict[str, str]) -> None:
  68. zipf.write(src, dest)
  69. sums[dest] = _sha256(src)
  70. def _check_active_6400_generated() -> None:
  71. expected = generate_6400_v1(ROOT / "generated/6400")
  72. drift = [
  73. str(path.relative_to(ROOT))
  74. for path, content in expected.items()
  75. if not path.is_file() or path.read_bytes() != content
  76. ]
  77. if drift:
  78. raise SystemExit("6400 package blocked: active generated contract drift: " + ", ".join(drift))
  79. def _resolve_6400_profile(target_name: str, profile_name: str | None) -> str:
  80. if target_name in HARDWARE_PROFILES:
  81. if profile_name is not None and profile_name != target_name:
  82. raise SystemExit("6400 package blocked: target/profile mismatch")
  83. return target_name
  84. if target_name == "6400-sim-debug" or profile_name == "6400-sim-debug":
  85. raise SystemExit("6400 package blocked: Sim-Debug cannot produce a hardware package")
  86. if target_name != "6400" or profile_name not in HARDWARE_PROFILES:
  87. raise SystemExit(
  88. "6400 package blocked: explicitly select --profile "
  89. "6400-control or 6400-identification"
  90. )
  91. return profile_name
  92. def _validated_td_bitstream(
  93. profile_name: str, receipt_path: Path | None, package_commit: str
  94. ) -> tuple[Path, dict[str, object]]:
  95. if receipt_path is None or not receipt_path.is_file():
  96. raise SystemExit("6400 firmware package blocked: explicit --td-receipt is required")
  97. receipt = json.loads(receipt_path.read_text(encoding="utf-8"))
  98. profile = HARDWARE_PROFILES[profile_name]
  99. project_path = ROOT / str(profile["project"])
  100. closure_path = ROOT / str(profile["closure"])
  101. current_inputs = td_input_manifest(profile_name)
  102. source_manifest_sha256 = hashlib.sha256(
  103. json.dumps(current_inputs, sort_keys=True, separators=(",", ":")).encode()
  104. ).hexdigest()
  105. expected = {
  106. "schema": "prod2u-6400-td-receipt-v1",
  107. "status": "PASS",
  108. "profile": profile_name,
  109. "project": str(profile["project"]),
  110. "source_closure": str(profile["closure"]),
  111. "production": bool(profile["production"]),
  112. "stimulus": bool(profile["stimulus"]),
  113. "simulation_only": False,
  114. "artifact_basename": str(profile["artifact_basename"]),
  115. "timing_pass_25mhz": True,
  116. "project_sha256": _sha256(project_path),
  117. "source_closure_sha256": _sha256(closure_path),
  118. "source_manifest_sha256": source_manifest_sha256,
  119. "inputs": current_inputs,
  120. "known_unbound_ports": list(EXPECTED_UNBOUND_PORTS),
  121. "deployment_status": _expected_deployment_status(profile_name),
  122. }
  123. mismatches = [
  124. f"{key}: expected {value!r}, got {receipt.get(key)!r}"
  125. for key, value in expected.items()
  126. if receipt.get(key) != value
  127. ]
  128. if mismatches:
  129. raise SystemExit("6400 firmware package blocked: TD receipt mismatch: " + "; ".join(mismatches))
  130. source_commit = receipt.get("commit")
  131. if not isinstance(source_commit, str) or not re.fullmatch(
  132. r"[0-9a-f]{40}", source_commit
  133. ):
  134. raise SystemExit(
  135. "6400 firmware package blocked: TD receipt has invalid source commit"
  136. )
  137. if not re.fullmatch(r"[0-9a-f]{40}", package_commit):
  138. raise SystemExit(
  139. "6400 firmware package blocked: exact package commit is unavailable"
  140. )
  141. warning_audit = receipt.get("warning_audit")
  142. expected_ports = list(EXPECTED_UNBOUND_PORTS)
  143. if not isinstance(warning_audit, dict) or any(
  144. warning_audit.get(key) != value
  145. for key, value in {
  146. "status": "PASS",
  147. "expected_unbound_ports": expected_ports,
  148. "observed_unbound_ports": expected_ports,
  149. "unexpected_unbound_ports": [],
  150. "missing_expected_unbound_ports": [],
  151. }.items()
  152. ):
  153. raise SystemExit(
  154. "6400 firmware package blocked: TD warning audit mismatch"
  155. )
  156. bitstream_value = receipt.get("bitstream")
  157. if not isinstance(bitstream_value, str) or not bitstream_value:
  158. raise SystemExit("6400 firmware package blocked: TD receipt has no bitstream")
  159. bitstream = Path(bitstream_value)
  160. if not bitstream.is_absolute():
  161. bitstream = receipt_path.parent / bitstream
  162. expected_name = f"{profile['artifact_basename']}.bit"
  163. if bitstream.name != expected_name or not bitstream.is_file() or bitstream.stat().st_size == 0:
  164. raise SystemExit("6400 firmware package blocked: receipt bitstream is missing or misnamed")
  165. if receipt.get("bitstream_sha256") != _sha256(bitstream):
  166. raise SystemExit("6400 firmware package blocked: receipt bitstream SHA-256 mismatch")
  167. return bitstream.resolve(), receipt
  168. def build_target_package(
  169. target_name: str,
  170. kind: str,
  171. output_dir: Path,
  172. include_reference: bool = False,
  173. *,
  174. profile_name: str | None = None,
  175. td_receipt: Path | None = None,
  176. ) -> Path:
  177. is_6400 = target_name == "6400" or target_name.startswith("6400-")
  178. receipt_payload: dict[str, object] | None = None
  179. expanded_closure: dict[str, object] | None = None
  180. hardware_validation = "NOT RUN"
  181. known_unbound_ports: tuple[str, ...] = ()
  182. deployment_status: str | None = None
  183. source_commit: str | None = None
  184. if is_6400:
  185. selected_profile = _resolve_6400_profile(target_name, profile_name)
  186. profile = HARDWARE_PROFILES[selected_profile]
  187. _check_active_6400_generated()
  188. project_path = ROOT / str(profile["project"])
  189. closure_path = ROOT / str(profile["closure"])
  190. generated_dir = ROOT / "generated/6400"
  191. project = json.loads(project_path.read_text(encoding="utf-8"))
  192. sources, _closure_inputs = td_source_closure(selected_profile)
  193. top_module = str(project["top"])
  194. project_id = selected_profile
  195. target_alias = "6400"
  196. package_label = selected_profile
  197. blocked, pins = False, ()
  198. expanded_closure = {
  199. "schema": "prod2u-source-closure-expanded-v1",
  200. "project_id": selected_profile,
  201. "top_module": top_module,
  202. "sources": sources,
  203. }
  204. else:
  205. target = resolve_target(target_name)
  206. generate_named_target(target.alias)
  207. project_path = target.project_config
  208. closure_path = target.source_closure
  209. generated_dir = target.generated_dir
  210. project = json.loads(project_path.read_text(encoding="utf-8"))
  211. blocked, pins = release_blocked(target, project)
  212. sources = list(load_source_closure(target))
  213. top_module = target.top_module
  214. project_id = target.project_id
  215. target_alias = target.alias
  216. package_label = target.alias
  217. selected_profile = target.profile
  218. if kind == "firmware" and blocked:
  219. raise SystemExit(
  220. "release_blocked\n" + "\n".join(f"{name} pin unresolved" for name in pins)
  221. )
  222. commit = _git(ROOT, "rev-parse", "HEAD")
  223. bitstream_path: Path | None = None
  224. if kind == "firmware" and is_6400:
  225. if not re.fullmatch(r"[0-9a-f]{40}", commit):
  226. raise SystemExit("6400 firmware package blocked: exact Git commit is unavailable")
  227. bitstream_path, receipt_payload = _validated_td_bitstream(
  228. selected_profile, td_receipt, commit
  229. )
  230. ports_value = receipt_payload["known_unbound_ports"]
  231. status_value = receipt_payload["deployment_status"]
  232. assert isinstance(ports_value, list)
  233. assert all(isinstance(port, str) for port in ports_value)
  234. assert isinstance(status_value, str)
  235. known_unbound_ports = tuple(ports_value)
  236. deployment_status = status_value
  237. source_commit_value = receipt_payload["commit"]
  238. assert isinstance(source_commit_value, str)
  239. source_commit = source_commit_value
  240. blocked = (
  241. bool(known_unbound_ports)
  242. or hardware_validation != "PASS"
  243. or not bool(profile["production"])
  244. )
  245. pins = known_unbound_ports
  246. run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
  247. name = f"prod2u-{package_label}-{kind}-{commit[:12]}-{run_id}"
  248. output_dir.mkdir(parents=True, exist_ok=True)
  249. zip_path = output_dir / f"{name}.zip"
  250. manifest = {
  251. "schema": "prod2u-target-package-v1",
  252. "target_alias": target_alias,
  253. "profile": selected_profile,
  254. "firmware_role": (
  255. "production"
  256. if selected_profile == "6400-control"
  257. else "identification" if selected_profile == "6400-identification" else "legacy"
  258. ),
  259. "project_id": project_id,
  260. "top": top_module,
  261. "kind": kind,
  262. "commit": commit,
  263. "run_id": run_id,
  264. "project_config_sha256": _sha256(project_path),
  265. "source_manifest_sha256": _sha256(closure_path),
  266. "bitstream_sha256": _sha256(bitstream_path) if bitstream_path else None,
  267. "hardware_validation": hardware_validation,
  268. "release_blocked": blocked,
  269. "unresolved_pins": list(pins),
  270. "include_reference": include_reference,
  271. }
  272. if is_6400:
  273. manifest.update(
  274. {
  275. "contract_sha256": _contract_sha256(),
  276. "production": bool(profile["production"]),
  277. "stimulus": bool(profile["stimulus"]),
  278. "simulation_only": False,
  279. }
  280. )
  281. if is_6400 and kind == "firmware":
  282. manifest.update(
  283. {
  284. "candidate_notice_zh_CN": CANDIDATE_NOTICE_ZH_CN,
  285. "candidate_only": blocked,
  286. "deployable": not blocked,
  287. "deployment_status": deployment_status,
  288. "source_commit": source_commit,
  289. "package_commit": commit,
  290. "known_unbound_ports": list(known_unbound_ports),
  291. "unresolved_ports": list(known_unbound_ports),
  292. }
  293. )
  294. with tempfile.TemporaryDirectory() as tmp:
  295. stage = Path(tmp)
  296. (stage / "manifest.json").write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
  297. if is_6400 and kind == "firmware" and blocked:
  298. (stage / "CANDIDATE-NOTICE.zh-CN.txt").write_text(
  299. DO_NOT_PROGRAM_LINE + "\n"
  300. + CANDIDATE_NOTICE_ZH_CN + "\n"
  301. + f"未冻结端口:{', '.join(known_unbound_ports)}\n"
  302. + f"部署状态:{deployment_status}\n"
  303. + f"硬件验证:{hardware_validation}\n",
  304. encoding="utf-8",
  305. )
  306. shutil.copy2(project_path, stage / "project.json")
  307. shutil.copy2(closure_path, stage / "source-closure.json")
  308. if expanded_closure is not None:
  309. (stage / "source-closure-expanded.json").write_text(
  310. json.dumps(expanded_closure, indent=2, sort_keys=True) + "\n",
  311. encoding="utf-8",
  312. )
  313. gen_dir = stage / ("generated/6400" if is_6400 else "generated")
  314. if generated_dir.is_dir():
  315. shutil.copytree(generated_dir, gen_dir)
  316. src_dir = stage / "src"
  317. src_dir.mkdir()
  318. for rel in sources:
  319. dest = stage / rel
  320. dest.parent.mkdir(parents=True, exist_ok=True)
  321. shutil.copy2(ROOT / rel, dest)
  322. if bitstream_path is not None:
  323. bitstream_name = bitstream_path.name
  324. shutil.copy2(bitstream_path, stage / bitstream_name)
  325. (stage / "BITSTREAM-SHA256.txt").write_text(
  326. f"{_sha256(bitstream_path)} {bitstream_name}\n",
  327. encoding="ascii",
  328. )
  329. role = "生产" if selected_profile == "6400-control" else "Identification 专用"
  330. (stage / "FLASH-INSTRUCTIONS.zh-CN.txt").write_text(
  331. DO_NOT_PROGRAM_LINE + "\n"
  332. + CANDIDATE_NOTICE_ZH_CN + "\n\n"
  333. + f"6400 {role}固件审核说明\n"
  334. "========================\n"
  335. "目标器件:EF2L45BG256B(6400 前后独立温控)\n"
  336. f"固件文件:{bitstream_name}\n"
  337. "请审核 BITSTREAM-SHA256.txt 与 TD-BUILD-RECEIPT.json 后再冻结制品。\n"
  338. f"Host 串口使用 921600 8N1;每条合法命令先独立 ACK;Profile={selected_profile}。\n"
  339. "本包只包含 6400 固件,不能用于 MRDIMM 门控板。\n"
  340. + (
  341. "本固件含 SET_STIMULUS,仅限 Identification,不得作为 Production。\n"
  342. if selected_profile == "6400-identification"
  343. else "Production 固件不包含 SET_STIMULUS(stimulus=false)。\n"
  344. )
  345. + "\n"
  346. "注意:本次交付未执行真实 JTAG/硬件烧录,硬件验证状态为 NOT RUN。\n",
  347. encoding="utf-8",
  348. )
  349. assert receipt_payload is not None
  350. (stage / "TD-BUILD-RECEIPT.json").write_text(
  351. json.dumps(receipt_payload, indent=2, sort_keys=True) + "\n",
  352. encoding="utf-8",
  353. )
  354. if include_reference:
  355. ref = ROOT / "reference"
  356. if ref.is_dir():
  357. shutil.copytree(ref, stage / "reference", dirs_exist_ok=True)
  358. sums: dict[str, str] = {}
  359. if zip_path.exists():
  360. zip_path.unlink()
  361. with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zipf:
  362. for path in sorted(stage.rglob("*")):
  363. if path.is_file():
  364. _add(zipf, path, path.relative_to(stage).as_posix(), sums)
  365. zipf.writestr("SHA256SUMS", "".join(f"{digest} {name}\n" for name, digest in sorted(sums.items())))
  366. _selftest(zip_path)
  367. return zip_path
  368. def _selftest(zip_path: Path) -> None:
  369. with tempfile.TemporaryDirectory() as tmp:
  370. dest = Path(tmp) / "unpacked"
  371. dest.mkdir()
  372. with zipfile.ZipFile(zip_path) as zipf:
  373. for info in zipf.infolist():
  374. if info.filename.startswith("/") or ".." in Path(info.filename).parts:
  375. raise SystemExit(f"unsafe zip path: {info.filename}")
  376. zipf.extractall(dest)
  377. manifest = json.loads((dest / "manifest.json").read_text(encoding="utf-8"))
  378. if manifest.get("hardware_validation") != "NOT RUN":
  379. raise SystemExit("package selftest: hardware_validation must be NOT RUN")
  380. sums = (dest / "SHA256SUMS").read_text(encoding="utf-8").splitlines()
  381. for line in sums:
  382. digest, name = line.split(" ", 1)
  383. observed = _sha256(dest / name)
  384. if observed != digest:
  385. raise SystemExit(f"hash mismatch {name}")
  386. if manifest.get("target_alias") == "6400":
  387. profile_name = manifest.get("profile")
  388. if profile_name not in HARDWARE_PROFILES:
  389. raise SystemExit("package selftest: invalid 6400 hardware profile")
  390. members = [path.relative_to(dest).as_posix() for path in dest.rglob("*")]
  391. if any(name.startswith("src/generated/6400/") for name in members):
  392. raise SystemExit("package selftest: historical src/generated/6400 leaked")
  393. closure = json.loads(
  394. (dest / "source-closure-expanded.json").read_text(encoding="utf-8")
  395. )
  396. closure_text = "\n".join(closure["sources"])
  397. if "src/generated/6400" in closure_text or "prod2u_6400_front_back_top" in closure_text:
  398. raise SystemExit("package selftest: historical 6400 closure leaked")
  399. if manifest.get("target_alias") == "6400" and manifest.get("kind") == "firmware":
  400. profile_name = manifest["profile"]
  401. profile = HARDWARE_PROFILES[profile_name]
  402. expected_name = (
  403. "prod2u_6400_front_back.bit"
  404. if profile_name == "6400-control"
  405. else "prod2u_6400_identification.bit"
  406. )
  407. bit = dest / expected_name
  408. if not bit.is_file() or _sha256(bit) != manifest.get("bitstream_sha256"):
  409. raise SystemExit("package selftest: 6400 bitstream identity mismatch")
  410. receipt = json.loads(
  411. (dest / "TD-BUILD-RECEIPT.json").read_text(encoding="utf-8")
  412. )
  413. if receipt.get("profile") != profile_name or receipt.get(
  414. "bitstream_sha256"
  415. ) != manifest["bitstream_sha256"]:
  416. raise SystemExit("package selftest: TD receipt/profile identity mismatch")
  417. embedded_contract = json.loads(
  418. (dest / "generated/6400/host-contract.json").read_text(
  419. encoding="utf-8"
  420. )
  421. )
  422. if (
  423. manifest.get("contract_sha256")
  424. != embedded_contract.get("contract_sha256")
  425. or manifest.get("source_commit") != receipt.get("commit")
  426. or manifest.get("package_commit") != manifest.get("commit")
  427. or receipt.get("inputs") != td_input_manifest(profile_name)
  428. ):
  429. raise SystemExit("package selftest: firmware provenance mismatch")
  430. expected_input_sha = hashlib.sha256(
  431. json.dumps(
  432. receipt["inputs"], sort_keys=True, separators=(",", ":")
  433. ).encode()
  434. ).hexdigest()
  435. if (
  436. receipt.get("source_manifest_sha256") != expected_input_sha
  437. or receipt.get("project_sha256") != _sha256(dest / "project.json")
  438. or receipt.get("source_closure_sha256")
  439. != _sha256(dest / "source-closure.json")
  440. ):
  441. raise SystemExit("package selftest: TD input digest mismatch")
  442. receipt_ports = receipt.get("known_unbound_ports")
  443. expected_ports = list(EXPECTED_UNBOUND_PORTS)
  444. warning_audit = receipt.get("warning_audit")
  445. if (
  446. manifest.get("release_blocked") is not True
  447. or manifest.get("deployable") is not False
  448. or manifest.get("candidate_only") is not True
  449. or receipt_ports != expected_ports
  450. or manifest.get("known_unbound_ports") != receipt_ports
  451. or manifest.get("unresolved_ports") != receipt_ports
  452. or manifest.get("unresolved_pins") != receipt_ports
  453. or receipt.get("deployment_status")
  454. != _expected_deployment_status(profile_name)
  455. or manifest.get("deployment_status")
  456. != receipt.get("deployment_status")
  457. or not isinstance(warning_audit, dict)
  458. or warning_audit.get("status") != "PASS"
  459. or warning_audit.get("observed_unbound_ports") != expected_ports
  460. ):
  461. raise SystemExit("package selftest: unsafe deployment gate mismatch")
  462. if not (dest / "CANDIDATE-NOTICE.zh-CN.txt").is_file():
  463. raise SystemExit("package selftest: candidate notice missing")
  464. if (
  465. manifest.get("production") is not bool(profile["production"])
  466. or manifest.get("stimulus") is not bool(profile["stimulus"])
  467. or (not bool(profile["production"]) and manifest.get("deployable"))
  468. ):
  469. raise SystemExit("package selftest: firmware profile semantics mismatch")
  470. instructions = (dest / "FLASH-INSTRUCTIONS.zh-CN.txt").read_text(
  471. encoding="utf-8"
  472. )
  473. if (
  474. not instructions.startswith(DO_NOT_PROGRAM_LINE)
  475. or "921600 8N1" not in instructions
  476. or "独立 ACK" not in instructions
  477. or any(token in instructions for token in FORBIDDEN_PROGRAM_INSTRUCTIONS)
  478. ):
  479. raise SystemExit("package selftest: Host UART/ACK contract missing")
  480. def main(argv: list[str] | None = None) -> int:
  481. parser = argparse.ArgumentParser()
  482. parser.add_argument("--target", required=True)
  483. parser.add_argument("--kind", choices=("source", "review", "firmware"), default="source")
  484. parser.add_argument(
  485. "--profile",
  486. choices=("6400-control", "6400-identification", "6400-sim-debug"),
  487. )
  488. parser.add_argument("--td-receipt", type=Path)
  489. parser.add_argument("--output-dir", type=Path, default=ROOT / "dist")
  490. parser.add_argument("--include-reference", action="store_true")
  491. args = parser.parse_args(argv)
  492. path = build_target_package(
  493. args.target,
  494. args.kind,
  495. args.output_dir,
  496. args.include_reference,
  497. profile_name=args.profile,
  498. td_receipt=args.td_receipt,
  499. )
  500. print(json.dumps({"status": "pass", "package": str(path), "sha256": _sha256(path)}, indent=2))
  501. return 0
  502. if __name__ == "__main__":
  503. raise SystemExit(main())