diff --git a/minitests/roi_harness/runme.sh b/minitests/roi_harness/runme.sh index fc64fdca8..8eb39ff59 100755 --- a/minitests/roi_harness/runme.sh +++ b/minitests/roi_harness/runme.sh @@ -67,7 +67,7 @@ ${XRAY_VIVADO} -mode batch -source ../runme.tcl test -z "$(fgrep CRITICAL vivado.log)" ${XRAY_BITREAD} -F $XRAY_ROI_FRAMES -o design.bits -z -y design.bit -python3 ${XRAY_DIR}/utils/bit2fasm.py --verbose design.bit > design.fasm +python3 -m xc_fasm.bit2fasm --verbose design.bit > design.fasm python3 ${XRAY_DIR}/utils/fasm2frames.py design.fasm design.frm PYTHONPATH=$PYTHONPATH:$XRAY_DIR/utils python3 ../create_design_json.py \ --design_info_txt design_info.txt \ diff --git a/minitests/srl/README.md b/minitests/srl/README.md index c634fe1a3..ec267d080 100644 --- a/minitests/srl/README.md +++ b/minitests/srl/README.md @@ -2,4 +2,5 @@ This is a minitest for various SRL configurations. -Uses Yosys to generate EDIF which is then P&R'd by Vivado. The makefile also invokes bit2fasm and segprint \ No newline at end of file +Uses Yosys to generate EDIF which is then P&R'd by Vivado. +The makefile also invokes `xc_fasm.bit2fasm` and `segprint`. diff --git a/utils/bit2fasm.py b/utils/bit2fasm.py deleted file mode 100755 index 859ec1096..000000000 --- a/utils/bit2fasm.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (C) 2017-2020 The Project X-Ray Authors. -# -# Use of this source code is governed by a ISC-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/ISC -# -# SPDX-License-Identifier: ISC -''' -Take bitstream .bit files and decode them to FASM. -''' - -import contextlib -import os -import fasm -import fasm.output -from prjxray import fasm_disassembler -from prjxray import bitstream -from prjxray.db import Database -from prjxray.util import OpenSafeFile -import subprocess -import tempfile - - -def bit_to_bits(bitread, part_yaml, bit_file, bits_file, frame_range=None): - """ Calls bitread to create bits (ASCII) from bit file (binary) """ - if frame_range: - frame_range_arg = '-F {}'.format(frame_range) - else: - frame_range_arg = '' - - subprocess.check_output( - '{} --part_file {} {} -o {} -z -y {}'.format( - bitread, part_yaml, frame_range_arg, bits_file, bit_file), - shell=True) - - -def bits_to_fasm(db_root, part, bits_file, verbose, canonical): - db = Database(db_root, part) - grid = db.grid() - disassembler = fasm_disassembler.FasmDisassembler(db) - - with OpenSafeFile(bits_file) as f: - bitdata = bitstream.load_bitdata(f) - - model = fasm.output.merge_and_sort( - disassembler.find_features_in_bitstream(bitdata, verbose=verbose), - zero_function=disassembler.is_zero_feature, - sort_key=grid.tile_key, - ) - - print(fasm.fasm_tuple_to_string(model, canonical=canonical), end='') - - -def main(): - import argparse - - parser = argparse.ArgumentParser( - description='Convert 7-series bit file to FASM.') - - database_dir = os.getenv("XRAY_DATABASE_DIR") - database = os.getenv("XRAY_DATABASE") - db_root_kwargs = {} - if database_dir is None or database is None: - db_root_kwargs['required'] = True - else: - db_root_kwargs['required'] = False - db_root_kwargs['default'] = os.path.join(database_dir, database) - - default_part = os.getenv("XRAY_PART") - part_kwargs = {} - if default_part is None: - part_kwargs['required'] = True - else: - part_kwargs['required'] = False - part_kwargs['default'] = default_part - - if os.getenv("XRAY_TOOLS_DIR") is None: - default_bitread = 'bitread' - else: - default_bitread = os.path.join(os.getenv("XRAY_TOOLS_DIR"), 'bitread') - - parser.add_argument('--db-root', help="Database root.", **db_root_kwargs) - parser.add_argument( - '--bits-file', - help="Output filename for bitread output, default is deleted tempfile.", - default=None) - parser.add_argument( - '--part', help="Name of part being targetted.", **part_kwargs) - parser.add_argument( - '--bitread', - help="bitread tool to to use", - default=default_bitread) - parser.add_argument( - '--frame_range', help="Frame range to use with bitread.") - parser.add_argument('bit_file', help='') - parser.add_argument( - '--verbose', - help='Print lines for unknown tiles and bits', - action='store_true') - parser.add_argument( - '--canonical', help='Output canonical bitstream.', action='store_true') - args = parser.parse_args() - - with contextlib.ExitStack() as stack: - if args.bits_file: - bits_file = stack.enter_context(open(args.bits_file, 'wb')) - else: - bits_file = stack.enter_context(tempfile.NamedTemporaryFile()) - - bit_to_bits( - bitread=args.bitread, - part_yaml=os.path.join(args.db_root, args.part, "part.yaml"), - bit_file=args.bit_file, - bits_file=bits_file.name, - frame_range=args.frame_range, - ) - - bits_to_fasm( - args.db_root, args.part, bits_file.name, args.verbose, - args.canonical) - - -if __name__ == '__main__': - main() diff --git a/utils/environment.sh b/utils/environment.sh index 6e246cf89..b318e17df 100644 --- a/utils/environment.sh +++ b/utils/environment.sh @@ -6,6 +6,7 @@ # https://opensource.org/licenses/ISC # # SPDX-License-Identifier: ISC + XRAY_ENV_PATH="${BASH_SOURCE[0]}" while [ -h "$XRAY_ENV_PATH" ]; do # resolve $XRAY_ENV_PATH until the file is no longer a symlink XRAY_UTILS_DIR="$( cd -P "$( dirname "$XRAY_ENV_PATH" )" && pwd )" @@ -23,14 +24,14 @@ if [ -e "${XRAY_DIR}/env/bin/activate" ]; then source "${XRAY_DIR}/env/bin/activate" fi -# misc +pip3 install https://github.com/chipsalliance/f4pga-xc-fasm/archive/master.zip + export XRAY_PART_YAML="${XRAY_DATABASE_DIR}/${XRAY_DATABASE}/${XRAY_PART}/part.yaml" source $XRAY_UTILS_DIR/environment.python.sh # Set environment to default output and overwrite localisation settings export LC_ALL=C -# tools export XRAY_GENHEADER="${XRAY_UTILS_DIR}/genheader.sh" export XRAY_BITREAD="${XRAY_TOOLS_DIR}/bitread --part_file ${XRAY_PART_YAML}" export XRAY_MERGEDB="bash ${XRAY_UTILS_DIR}/mergedb.sh" @@ -38,7 +39,7 @@ export XRAY_DBFIXUP="python3 ${XRAY_UTILS_DIR}/dbfixup.py" export XRAY_MASKMERGE="bash ${XRAY_UTILS_DIR}/maskmerge.sh" export XRAY_SEGMATCH="${XRAY_TOOLS_DIR}/segmatch" export XRAY_SEGPRINT="python3 ${XRAY_UTILS_DIR}/segprint.py" -export XRAY_BIT2FASM="python3 ${XRAY_UTILS_DIR}/bit2fasm.py" +export XRAY_BIT2FASM="python3 -m xc_fasm.bit2fasm" export XRAY_FASM2FRAMES="python3 ${XRAY_UTILS_DIR}/fasm2frames.py" export XRAY_BITTOOL="${XRAY_TOOLS_DIR}/bittool" export XRAY_BLOCKWIDTH="python3 ${XRAY_UTILS_DIR}/blockwidth.py"