Files
Myfro9andClaude Opus 4.8 88f96fa5fa vivado: resolve install path from ~/skills_env.md instead of hardcoding D:\Xilinx
The Vivado install root differs per machine (C:\Xilinx here, D:\Xilinx on the
box these skills were written on), so every hardcoded path was already wrong
on this machine.

- new fpga_flash/scripts/vivado_env.py: resolves --vivado-dir > env var >
  VIVADO_ROOT (falling back to VIVADO_PATH) from ~/skills_env.md
- gen_mcs / program_flash / check_flash_csv: --vivado-dir now optional
- fpga_update/gen_update_mcs.py: same precedence for --vivado
- fpga_flash / smod_atsc_dev / vivado-prj-create SKILL.md: document the
  lookup instead of naming a drive letter
- skills_env template: VIVADO_ROOT/VIVADO_PATH are now blanks to fill in,
  so a new machine can't inherit a wrong default

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 07:48:04 -05:00

90 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
Step 3: Generate .mcs configuration memory file using Vivado batch mode.
Calls Vivado with step3_write_mcs.tcl (located in the same scripts/ directory)
via -tclargs so no temporary script files are created.
Usage:
python gen_mcs.py \
--bit-file "E:/project/RU_golden/RU_golden.runs/impl_1/RU_golden_top.bit" \
--mcs-file "E:/project/RU_golden/RU_golden.runs/impl_1/RU_golden_smod.mcs"
Exit codes:
0 = success ("write_cfgmem completed successfully" in output)
1 = failure
"""
import argparse
import os
import subprocess
import sys
from vivado_env import resolve_vivado_dir
def norm(path: str) -> str:
"""Normalize path to forward slashes (Vivado on Windows accepts both)."""
return path.replace("\\", "/")
def main():
parser = argparse.ArgumentParser(
description="Generate .mcs from .bit via Vivado write_cfgmem"
)
parser.add_argument(
"--vivado-dir",
default=None,
help="Vivado install root; defaults to VIVADO_ROOT from ~/skills_env.md",
)
parser.add_argument(
"--bit-file",
required=True,
help="Full path to the .bit file",
)
parser.add_argument(
"--mcs-file",
required=True,
help="Full path for the output .mcs file",
)
args = parser.parse_args()
vivado_dir = norm(resolve_vivado_dir(args.vivado_dir))
bit_file = norm(args.bit_file)
mcs_file = norm(args.mcs_file)
# Locate the TCL template alongside this script
scripts_dir = os.path.dirname(os.path.abspath(__file__))
tcl_template = os.path.join(scripts_dir, "step3_write_mcs.tcl").replace("\\", "/")
# Validate inputs
vivado_exe = os.path.join(vivado_dir, "bin", "vivado.bat")
if not os.path.isfile(vivado_exe):
print(f"ERROR: Vivado not found: {vivado_exe}", file=sys.stderr)
sys.exit(1)
if not os.path.isfile(bit_file):
print(f"ERROR: .bit file not found: {bit_file}", file=sys.stderr)
sys.exit(1)
if not os.path.isfile(tcl_template):
print(f"ERROR: TCL template not found: {tcl_template}", file=sys.stderr)
sys.exit(1)
cmd = [
vivado_exe,
"-mode", "batch",
"-source", tcl_template,
"-tclargs", bit_file, mcs_file,
]
print(f"[gen_mcs] Vivado: {vivado_exe}")
print(f"[gen_mcs] bit : {bit_file}")
print(f"[gen_mcs] mcs : {mcs_file}")
print()
result = subprocess.run(cmd)
sys.exit(result.returncode)
if __name__ == "__main__":
main()