generate_6400_manual.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. #!/usr/bin/env python3
  2. """Generate the active 6400 V1.1 manual-uart contract artifacts.
  3. Every generated artifact is rendered from the original contract inputs in
  4. ``contracts/`` (YAML/JSON sources). Generated outputs are never read back as
  5. templates: deleting ``generated/`` entirely and regenerating must produce
  6. byte-identical results, and ``--check`` never writes.
  7. The wire protocol is the single 8-bit-length frame:
  8. A5 5A | TYPE:u8 | LENGTH:u8 | PAYLOAD | CRC_L | CRC_H
  9. CRC-16/CCITT-FALSE covers TYPE, LENGTH and PAYLOAD; the header is excluded and
  10. the low byte goes first. There is no version, product id, sequence number, Tag,
  11. TLV or historical autodetection, and no Host I2C.
  12. """
  13. from __future__ import annotations
  14. import argparse
  15. import hashlib
  16. import json
  17. import sys
  18. from pathlib import Path
  19. from typing import Any
  20. ROOT = Path(__file__).resolve().parents[1]
  21. if str(ROOT) not in sys.path:
  22. sys.path.insert(0, str(ROOT))
  23. site_pkg = Path("/workspace/site-packages")
  24. if site_pkg.is_dir() and str(site_pkg) not in sys.path:
  25. sys.path.insert(0, str(site_pkg))
  26. import yaml
  27. from tools.crc16_ccitt_table import crc16_ccitt_false_table # noqa: E402
  28. CONTRACTS = ROOT / "contracts"
  29. OUT = ROOT / "generated" / "6400"
  30. # Frozen macro names (docs/architecture/final-rtl-interfaces.md). The emitted
  31. # header defines exactly this set and nothing else.
  32. FB_FROZEN_MACROS = (
  33. "FB_CLOCK_HZ", "FB_PTC_COUNT", "FB_FRONT_FAN_COUNT", "FB_REAR_FAN_COUNT",
  34. "FB_OUTPUT_COUNT", "FB_BMC_COUNT", "FB_CT_COUNT", "FB_HOST_BAUD",
  35. "FB_BMC_BAUD", "FB_HOST_CLKS_PER_BIT", "FB_BMC_CLKS_PER_BIT",
  36. "FB_PWM_PHASES", "FB_PTC_PWM_HZ", "FB_FAN_PWM_HZ", "FB_PWM_PHASE_CLKS",
  37. "FB_PWM_PERIOD_CLKS", "FAN_BOARD_INVERT_MASK", "CONTROL_WATCHDOG_SECONDS",
  38. "FB_FRAME_LENGTH_WIDTH", "FB_CMD_SET_ALL", "FB_CMD_GET_ALL",
  39. "FB_RSP_SET_ACK", "FB_RSP_GET_ACK", "FB_RSP_GET_DATA", "FB_RSP_NACK",
  40. "FB_NACK_UNSUPPORTED", "FB_NACK_BAD_LENGTH", "FB_NACK_BAD_VALUE",
  41. "FB_NACK_QUEUE_FULL", "FB_NACK_BUSY", "FB_SET_ALL_BYTES",
  42. "FB_GET_DATA_BYTES", "FB_HOST_INTER_BYTE_TIMEOUT_CLKS",
  43. "FB_HOST_BAUD_DIV", "FB_HOST_BAUD_MUL",
  44. )
  45. FIELD_SIZES = {"u8": 1, "u16": 2, "u16le": 2, "u32": 4, "bytes": 1}
  46. def macro_key(name: str) -> str:
  47. """FB_* macros map to short value keys; FAN_/CONTROL_ names are literal."""
  48. return name[3:] if name.startswith("FB_") else name
  49. def canon(value: Any) -> bytes:
  50. return (json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n").encode()
  51. def load_yaml(name: str, contracts: Path = CONTRACTS) -> Any:
  52. return yaml.safe_load((contracts / name).read_text(encoding="utf-8"))
  53. def contract_sha256(payload: Any) -> str:
  54. return hashlib.sha256(canon(payload)).hexdigest()
  55. def fields_layout(fields: list[dict[str, Any]]) -> tuple[dict[str, dict[str, Any]], int]:
  56. result: dict[str, dict[str, Any]] = {}
  57. offset = 0
  58. for field in fields:
  59. name = str(field["name"])
  60. if name in result:
  61. raise ValueError("duplicate layout field " + name)
  62. if field["type"] not in FIELD_SIZES:
  63. raise ValueError(f"unsupported field type {field['type']!r} for {name}")
  64. count = int(field.get("count", 1))
  65. size = FIELD_SIZES[field["type"]] * count
  66. result[name] = {**field, "count": count, "offset": offset, "size": size}
  67. offset += size
  68. return result, offset
  69. def frame(frame_type: int, payload: bytes) -> str:
  70. """New 8-bit-length frame, CRC-16/CCITT-FALSE low byte first."""
  71. body = bytes((frame_type & 0xFF, len(payload) & 0xFF)) + payload
  72. return (b"\xA5\x5A" + body + crc16_ccitt_false_table(body).to_bytes(2, "little")).hex().upper()
  73. def nack(request_type: int, reason: int) -> str:
  74. return frame(0xC0, bytes((request_type & 0xFF, reason & 0xFF)))
  75. def generate(root: Path | None = None, *, product: str = "6400") -> dict[Path, bytes]:
  76. base = root if root is not None else ROOT
  77. contracts = (base / "contracts") if root is not None else CONTRACTS
  78. if product not in ("6400", "6400-v2"):
  79. raise ValueError("unsupported 6400 product " + product)
  80. out = base / "generated" / product
  81. prefix = product
  82. manual = load_yaml(prefix + "-manual.yaml", contracts)
  83. wire = load_yaml(prefix + "-wire.yaml", contracts)
  84. snapshot = load_yaml(prefix + "-snapshot.yaml", contracts)
  85. fan = load_yaml("fan-control-parameters.yaml", contracts)
  86. channel_source = load_yaml("6400-v2-channel-map.yaml" if product == "6400-v2" else "channel-map.yaml", contracts)
  87. clock = int(manual["clock_hz"])
  88. if int(wire["clock_hz"]) != clock:
  89. raise ValueError("manual/wire clock disagreement")
  90. if wire["device"] != manual["device"]:
  91. raise ValueError("manual/wire device disagreement")
  92. uart = manual["uart"]
  93. if int(uart["length_width_bits"]) != 8 or int(wire["length_width_bits"]) != 8:
  94. raise ValueError("6400 frame LENGTH must be one byte")
  95. if wire["frame"]["fields"][1] != {"length": "u8"}:
  96. raise ValueError("frame schema must declare length: u8")
  97. if wire["crc"]["coverage"] != "type_length_payload":
  98. raise ValueError("CRC coverage must be TYPE+LENGTH+PAYLOAD")
  99. commands = wire["commands"]
  100. responses = wire["responses"]
  101. if int(uart["set_all_type"]) != int(commands["SET_ALL"]["type"]):
  102. raise ValueError("manual/wire SET_ALL identifiers disagree")
  103. if int(uart["get_all_type"]) != int(commands["GET_ALL"]["type"]):
  104. raise ValueError("manual/wire GET_ALL identifiers disagree")
  105. if int(uart["set_ack_type"]) != int(responses["SET_ACK"]["type"]):
  106. raise ValueError("manual/wire SET_ACK identifiers disagree")
  107. if int(uart["get_ack_type"]) != int(responses["GET_ACK"]["type"]):
  108. raise ValueError("manual/wire GET_ACK identifiers disagree")
  109. if int(uart["get_data_type"]) != int(responses["GET_DATA"]["type"]):
  110. raise ValueError("manual/wire GET_DATA identifiers disagree")
  111. if int(uart["nack_type"]) != int(responses["NACK"]["type"]):
  112. raise ValueError("manual/wire NACK identifiers disagree")
  113. outputs = manual["outputs"]
  114. duty_count = int(outputs["ptc_count"]) + int(outputs["front_fan_count"]) + int(outputs["rear_fan_count"])
  115. ssr_count = int(outputs.get("ssr_count", 0))
  116. buzzer_count = int(outputs.get("buzzer_count", 0))
  117. output_count = duty_count + ssr_count + buzzer_count
  118. set_all_bytes = int(commands["SET_ALL"]["payload_length"])
  119. if set_all_bytes != int(uart["set_all_payload_bytes"]) or set_all_bytes != output_count:
  120. raise ValueError("SET_ALL payload must cover every output exactly once")
  121. fields, length = fields_layout(snapshot["fields"])
  122. if length != int(snapshot["payload_length"]) or length != int(uart["get_data_payload_bytes"]):
  123. raise ValueError("GET_DATA length disagreement")
  124. if fields["ptc_percent"]["offset"] != 0 or fields["front_fan_percent"]["offset"] != 24:
  125. raise ValueError("PTC/Front offsets must be 0/24")
  126. if fields["rear_fan_percent"]["offset"] != 28 or fields["rear_fan_percent"]["count"] != 4:
  127. raise ValueError("Rear block must be offset 28..31")
  128. if fields["bmc_temp_c"]["offset"] != 32 or fields["bmc_temp_c"]["count"] != 24:
  129. raise ValueError("BMC24 block must be offset 32..55")
  130. if fields["ct_temp_c"]["offset"] != 56 or fields["ct_temp_c"]["count"] != 27:
  131. raise ValueError("CT27 block must be offset 56..82")
  132. if ssr_count and (ssr_count != 3 or fields["ssr_percent"]["offset"] != 83 or fields["ssr_percent"]["count"] != 3):
  133. raise ValueError("V2 SSR block must append three bytes at 83..85")
  134. if buzzer_count:
  135. if (
  136. fields.get("estop_btn", {}).get("offset") != 86
  137. or fields.get("hood_open_btn", {}).get("offset") != 87
  138. or fields.get("hood_close_btn", {}).get("offset") != 88
  139. or fields.get("buzzer_state", {}).get("offset") != 89
  140. ):
  141. raise ValueError("V2 estop_btn/hood_open_btn/hood_close_btn/buzzer_state must append at 86..89")
  142. pwm = fan["pwm"]
  143. if int(pwm["ptc_hz"]) != int(outputs["ptc_pwm_hz"]) or int(pwm["fan_hz"]) != int(outputs["fan_pwm_hz"]):
  144. raise ValueError("PWM frequency disagreement")
  145. period_clks = clock // int(pwm["fan_hz"])
  146. if clock % int(pwm["fan_hz"]):
  147. raise ValueError("PWM frequency must divide the clock")
  148. phases = int(pwm["phases"])
  149. if period_clks % phases:
  150. raise ValueError("PWM phases must divide the period")
  151. phase_clks = period_clks // phases
  152. if int(pwm["ptc_phase_clks"]) != phase_clks or int(pwm["fan_phase_clks"]) != phase_clks:
  153. raise ValueError("PWM phase budget disagreement")
  154. host_baud = int(wire["host_uart"]["baud"])
  155. bmc_baud = int(wire["bmc_uart"]["baud"])
  156. host_clks_per_bit = int(wire["host_uart"]["fixed_candidate_clks_per_bit"])
  157. bmc_clks_per_bit = int(wire["bmc_uart"]["clks_per_bit"])
  158. if (clock + host_baud // 2) // host_baud != host_clks_per_bit:
  159. raise ValueError("host clks_per_bit mismatch")
  160. if (clock + bmc_baud // 2) // bmc_baud != bmc_clks_per_bit:
  161. raise ValueError("BMC clks_per_bit mismatch")
  162. # Retain the public mathematical ratio macros for compatibility. The
  163. # production UART uses HOST_CLKS_PER_BIT, a nearest-integer divider.
  164. from math import gcd
  165. baud_gcd = gcd(clock, host_baud)
  166. baud_div, baud_mul = clock // baud_gcd, host_baud // baud_gcd
  167. values = {
  168. "CLOCK_HZ": clock,
  169. "PTC_COUNT": int(outputs["ptc_count"]),
  170. "FRONT_FAN_COUNT": int(outputs["front_fan_count"]),
  171. "REAR_FAN_COUNT": int(outputs["rear_fan_count"]),
  172. "OUTPUT_COUNT": output_count,
  173. "BMC_COUNT": int(manual["temperature"]["bmc_channels"]),
  174. "CT_COUNT": int(manual["temperature"]["ct_channels"]),
  175. "HOST_BAUD": host_baud,
  176. "BMC_BAUD": bmc_baud,
  177. "HOST_CLKS_PER_BIT": host_clks_per_bit,
  178. "BMC_CLKS_PER_BIT": bmc_clks_per_bit,
  179. "PWM_PHASES": phases,
  180. "PTC_PWM_HZ": int(pwm["ptc_hz"]),
  181. "FAN_PWM_HZ": int(pwm["fan_hz"]),
  182. "PWM_PHASE_CLKS": phase_clks,
  183. "PWM_PERIOD_CLKS": period_clks,
  184. "FAN_BOARD_INVERT_MASK": "8'h%02X" % int(str(outputs["fan_board_invert_mask"]), 0),
  185. "CONTROL_WATCHDOG_SECONDS": int(manual["watchdog"]["seconds"]),
  186. "FRAME_LENGTH_WIDTH": int(wire["length_width_bits"]),
  187. "CMD_SET_ALL": "8'h%02X" % int(commands["SET_ALL"]["type"]),
  188. "CMD_GET_ALL": "8'h%02X" % int(commands["GET_ALL"]["type"]),
  189. "RSP_SET_ACK": "8'h%02X" % int(responses["SET_ACK"]["type"]),
  190. "RSP_GET_ACK": "8'h%02X" % int(responses["GET_ACK"]["type"]),
  191. "RSP_GET_DATA": "8'h%02X" % int(responses["GET_DATA"]["type"]),
  192. "RSP_NACK": "8'h%02X" % int(responses["NACK"]["type"]),
  193. "NACK_UNSUPPORTED": "8'd%d" % int(responses["NACK"]["reason"]["UNSUPPORTED"]),
  194. "NACK_BAD_LENGTH": "8'd%d" % int(responses["NACK"]["reason"]["BAD_LENGTH"]),
  195. "NACK_BAD_VALUE": "8'd%d" % int(responses["NACK"]["reason"]["BAD_VALUE"]),
  196. "NACK_QUEUE_FULL": "8'd%d" % int(responses["NACK"]["reason"]["QUEUE_FULL"]),
  197. "NACK_BUSY": "8'd%d" % int(responses["NACK"]["reason"]["BUSY"]),
  198. "SET_ALL_BYTES": set_all_bytes,
  199. "GET_DATA_BYTES": length,
  200. "HOST_INTER_BYTE_TIMEOUT_CLKS": int(wire["inter_byte_timeout_clks"]),
  201. "HOST_BAUD_DIV": baud_div,
  202. "HOST_BAUD_MUL": baud_mul,
  203. }
  204. if set(values) != set(macro_key(name) for name in FB_FROZEN_MACROS):
  205. raise ValueError("frozen macro set mismatch")
  206. if values["PWM_PHASE_CLKS"] * values["PWM_PHASES"] != values["PWM_PERIOD_CLKS"]:
  207. raise ValueError("PWM phase budget mismatch")
  208. sha = contract_sha256({"manual": manual, "wire": wire, "snapshot": snapshot,
  209. "fan": fan, "channel_map": channel_source})
  210. header = ["`ifndef PROD2U_6400_V1_PARAMS_VH", "`define PROD2U_6400_V1_PARAMS_VH",
  211. "// Generated from raw manual/wire/snapshot/fan/channel-map contracts; SHA256 " + sha]
  212. header += ["`define " + name + " " + str(values[macro_key(name)]) for name in FB_FROZEN_MACROS]
  213. header += ["`endif", ""]
  214. snapshot_layout = {
  215. "schema": snapshot["schema"],
  216. "contract_sha256": sha,
  217. "payload_type": int(snapshot["payload_type"]),
  218. "byte_order": snapshot["byte_order"],
  219. "length": length,
  220. "payload_length": length,
  221. "fields": fields,
  222. "temperature_encoding": snapshot["temperature_encoding"],
  223. "output_defaults": snapshot["output_defaults"],
  224. }
  225. channel_map = dict(channel_source)
  226. channel_map["contract_sha256"] = sha
  227. fan_output = {
  228. "schema": "prod2u-6400-manual-fan-control-v2",
  229. "contract_sha256": sha,
  230. "board_invert_mask": outputs["fan_board_invert_mask"],
  231. "connector_duty_semantics": outputs["fan_duty_semantics"],
  232. "ptc_hz": int(pwm["ptc_hz"]),
  233. "fan_hz": int(pwm["fan_hz"]),
  234. "pwm_phases": phases,
  235. "pwm_phase_clks": phase_clks,
  236. "pwm_period_clks": period_clks,
  237. "safe_ptc_percent": int(outputs["default_ptc_percent"]),
  238. "safe_front_percent": int(outputs["default_front_percent"]),
  239. "safe_rear_percent": int(outputs["default_rear_percent"]),
  240. "temperature": fan["temperature"],
  241. "hardware_validation": "NOT_RUN",
  242. }
  243. sample = (bytes([int(outputs["default_ptc_percent"])] * int(outputs["ptc_count"]))
  244. + bytes([int(outputs["default_front_percent"])] * int(outputs["front_fan_count"]))
  245. + bytes([int(outputs["default_rear_percent"])] * int(outputs["rear_fan_count"]))
  246. + bytes(25 + index for index in range(int(manual["temperature"]["bmc_channels"])))
  247. + bytes(60 + index for index in range(int(manual["temperature"]["ct_channels"]))))
  248. invalid = (bytes([int(outputs["default_ptc_percent"])] * int(outputs["ptc_count"]))
  249. + bytes([int(outputs["default_front_percent"])] * int(outputs["front_fan_count"]))
  250. + bytes([int(outputs["default_rear_percent"])] * int(outputs["rear_fan_count"]))
  251. + bytes([0xFF] * (int(manual["temperature"]["bmc_channels"]) + int(manual["temperature"]["ct_channels"]))))
  252. sample += bytes([int(outputs.get("default_ssr_percent", 0))] * ssr_count)
  253. invalid += bytes([int(outputs.get("default_ssr_percent", 0))] * ssr_count)
  254. if buzzer_count:
  255. sample += bytes([0, 0, 0, int(outputs.get("default_buzzer", 0))])
  256. invalid += bytes([0, 0, 0, int(outputs.get("default_buzzer", 0))])
  257. if len(sample) != length or len(invalid) != length:
  258. raise ValueError("GET_DATA sample length mismatch")
  259. set_all_idle = bytes([0] * int(outputs["ptc_count"])) + bytes(
  260. [int(outputs["default_front_percent"])] * int(outputs["front_fan_count"])
  261. ) + bytes([int(outputs["default_rear_percent"])] * int(outputs["rear_fan_count"]))
  262. set_all_idle += bytes([int(outputs.get("default_ssr_percent", 0))] * ssr_count)
  263. if buzzer_count:
  264. set_all_idle += bytes([int(outputs.get("default_buzzer", 0))])
  265. set_all_full = bytes([100] * (duty_count + ssr_count)) + (bytes([1]) if buzzer_count else b"")
  266. set_all_ptc_zero_fan_zero = bytes(output_count)
  267. fixed = {
  268. "get_all_request": frame(0x02, b""),
  269. "set_ack": frame(0x81, b""),
  270. "get_ack": frame(0x82, b""),
  271. "nack_set_queue_full": nack(0x01, 0x04),
  272. "motor_done_axis4_upper_limit_4387": frame(0x50, bytes((4, 2)) + (4387).to_bytes(2, "little")),
  273. "motor_done_axis4_both_limits_0": frame(0x50, bytes((4, 3, 0, 0))),
  274. }
  275. golden = {
  276. "schema": "prod2u-6400-manual-golden-v3-8bit",
  277. "contract_sha256": sha,
  278. "protocol": "A5 5A | TYPE:u8 | LENGTH:u8 | PAYLOAD | CRC_L | CRC_H (CRC-16/CCITT-FALSE over TYPE+LENGTH+PAYLOAD)",
  279. "fixed_vectors": {
  280. "get_all_request": fixed["get_all_request"],
  281. "set_ack": fixed["set_ack"],
  282. "get_ack": fixed["get_ack"],
  283. "nack_set_queue_full": fixed["nack_set_queue_full"],
  284. },
  285. "protocol_fixed_vectors": fixed,
  286. "protocol_fixed_vectors_note": (
  287. "CRC anchors from the shared protocol table. MOTOR_DONE and QUEUE_FULL are "
  288. "MRDIMM-only behaviours; the 6400 encoder still produces these bytes and the "
  289. "independent CRC cross-check must agree. 6400 does not emit MOTOR_DONE."
  290. ),
  291. "frames": {
  292. "get_all_request": frame(0x02, b""),
  293. "get_ack": frame(0x82, b""),
  294. "set_ack": frame(0x81, b""),
  295. "set_all_idle_defaults": frame(0x01, set_all_idle),
  296. "set_all_ptc_zero_fan_zero": frame(0x01, set_all_ptc_zero_fan_zero),
  297. "set_all_all_100": frame(0x01, set_all_full),
  298. "nack_unsupported": nack(0x01, 0x01),
  299. "nack_bad_length": nack(0x01, 0x02),
  300. "nack_bad_value": nack(0x01, 0x03),
  301. "nack_queue_full_encoding": nack(0x01, 0x04),
  302. "nack_busy": nack(0x01, 0x05),
  303. "nack_unsupported_request_7f": nack(0x7F, 0x01),
  304. "get_data_sample": frame(0x42, sample),
  305. "get_data_invalid_temperature": frame(0x42, invalid),
  306. },
  307. "nack_reasons": {name: int(code) for name, code in responses["NACK"]["reason"].items()},
  308. }
  309. host = {
  310. "schema": "prod2u-6400-manual-host-contract-v2",
  311. "contract_sha256": sha,
  312. "product": manual["product"],
  313. "board": manual["board"],
  314. "device": manual["device"],
  315. "canonical_profiles": {
  316. "6400-front-rear": {
  317. "allowed_commands": ["SET_ALL", "GET_ALL"],
  318. "production": True,
  319. "simulation_only": False,
  320. }
  321. },
  322. "wire": {
  323. "frame": wire["frame"],
  324. "crc": wire["crc"],
  325. "uart": uart,
  326. "commands": commands,
  327. "responses": responses,
  328. "invalid_behavior": wire["invalid_behavior"],
  329. },
  330. "snapshot": {"payload_length": length, "payload_type": int(snapshot["payload_type"]), "fields": fields},
  331. "outputs": outputs,
  332. "watchdog": manual["watchdog"],
  333. "temperature": manual["temperature"],
  334. }
  335. uart_contract = {
  336. "schema": "prod2u-6400-manual-uart-v4-8bit",
  337. "contract_sha256": sha,
  338. "product": manual["product"],
  339. "board": manual["board"],
  340. "device": manual["device"],
  341. "wire": {
  342. "uart": uart,
  343. "commands": commands,
  344. "responses": responses,
  345. "inter_byte_timeout_clks": int(wire["inter_byte_timeout_clks"]),
  346. "inter_byte_timeout_us": int(wire["inter_byte_timeout_us"]),
  347. "host_uart": wire["host_uart"],
  348. "bmc_uart": wire["bmc_uart"],
  349. },
  350. "outputs": outputs,
  351. "watchdog": manual["watchdog"],
  352. "temperature": manual["temperature"],
  353. "snapshot": snapshot_layout,
  354. }
  355. params_text = "\n".join(header)
  356. if product == "6400-v2":
  357. params_text = params_text.replace("PROD2U_6400_V1_PARAMS_VH", "PROD2U_6400_V2_PARAMS_VH")
  358. host["canonical_profiles"] = {"6400-v2": host["canonical_profiles"]["6400-front-rear"]}
  359. return {
  360. out / "host-contract.json": canon(host),
  361. out / "manual-uart-contract.json": canon(uart_contract),
  362. out / "golden-vectors.json": canon(golden),
  363. out / "channel-map.json": canon(channel_map),
  364. out / "fan-control-parameters.json": canon(fan_output),
  365. out / "snapshot-layout.json": canon(snapshot_layout),
  366. out / "contract-sha256.txt": (sha + chr(10)).encode(),
  367. out / ("prod2u_6400_v2_params.vh" if product == "6400-v2" else "prod2u_6400_v1_params.vh"): params_text.encode(),
  368. }
  369. def main() -> int:
  370. ap = argparse.ArgumentParser()
  371. ap.add_argument("--check", action="store_true")
  372. args = ap.parse_args()
  373. drift = []
  374. for path, data in generate().items():
  375. if args.check:
  376. if not path.is_file() or path.read_bytes() != data:
  377. drift.append(path.relative_to(ROOT).as_posix())
  378. else:
  379. path.parent.mkdir(parents=True, exist_ok=True)
  380. path.write_bytes(data)
  381. if drift:
  382. print("generated drift: " + ", ".join(drift))
  383. return 1
  384. print("PASS: manual 6400 generated")
  385. return 0
  386. if __name__ == "__main__":
  387. raise SystemExit(main())