Files
skills-win/fpga_flash/scripts/check_flash_csv.py
T
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

85 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
Step 1: Check and update Vivado Flash device CSV to include w25q128bv.
Checks whether 'w25q128bv-spi-x1_x2_x4' is present in Vivado's
xicom_cfgmem_part_table.csv. If not, appends the correct row.
Usage:
python check_flash_csv.py # Vivado path from ~/skills_env.md
python check_flash_csv.py --vivado-dir "<install root>" # or override it
Exit codes:
0 = device already present (no changes made)
2 = device was successfully added (Vivado restart required)
1 = error (CSV not found or write failure)
"""
import argparse
import os
import sys
from vivado_env import resolve_vivado_dir
DEVICE_NAME = "w25q128bv-spi-x1_x2_x4"
# Fields: NAME, MEM_DEVICE, MEM_TYPE, MEM_DENSITY, DATA_WIDTH,
# MEM_MANUFACTURER, NUM_CFG_FILES, MEM_DEVICE_ALIAS, MEM_FAMILY
NEW_ROW = "w25q128bv-spi-x1_x2_x4,w25q128bv,spi,128,x1_x2_x4,Winbond,1,w25q128b,w25q"
def main():
parser = argparse.ArgumentParser(
description="Check/update Vivado Flash CSV for w25q128bv"
)
parser.add_argument(
"--vivado-dir",
default=None,
help="Vivado install root; defaults to VIVADO_ROOT from ~/skills_env.md",
)
args = parser.parse_args()
csv_path = os.path.join(
resolve_vivado_dir(args.vivado_dir),
"data", "xicom", "xicom_cfgmem_part_table.csv"
)
csv_path = csv_path.replace("\\", "/")
if not os.path.isfile(csv_path):
print(f"ERROR: CSV not found at: {csv_path}", file=sys.stderr)
print(
" Please verify --vivado-dir points to a valid Vivado installation.",
file=sys.stderr,
)
sys.exit(1)
with open(csv_path, "r", encoding="utf-8") as f:
content = f.read()
if DEVICE_NAME in content:
print(f"[check_flash_csv] '{DEVICE_NAME}' already present. No changes needed.")
sys.exit(0)
# Append the new row (ensure trailing newline before adding)
if not content.endswith("\n"):
content += "\n"
content += NEW_ROW + "\n"
try:
with open(csv_path, "w", encoding="utf-8") as f:
f.write(content)
except PermissionError:
print(
f"ERROR: Cannot write to {csv_path}. Try running as Administrator.",
file=sys.stderr,
)
sys.exit(1)
print(f"[check_flash_csv] Added '{DEVICE_NAME}' to:")
print(f" {csv_path}")
print()
print("NOTE: You must restart Vivado for the new Flash device to be recognized.")
sys.exit(2)
if __name__ == "__main__":
main()