81 lines
2.3 KiB
Python
81 lines
2.3 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-dir "D:/Xilinx/Vivado/2018.1"
|
|
|
|
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
|
|
|
|
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",
|
|
required=True,
|
|
help="Vivado install root, e.g. D:/Xilinx/Vivado/2018.1",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
csv_path = os.path.join(
|
|
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()
|