diff --git a/fuzzers/run_fuzzer.py b/fuzzers/run_fuzzer.py index 971dec79..7ea75a1e 100755 --- a/fuzzers/run_fuzzer.py +++ b/fuzzers/run_fuzzer.py @@ -22,8 +22,7 @@ import signal import subprocess import sys import traceback -from prjxray.util import get_part_information, get_part_resources -from prjxray.util import get_fabric_for_part +from utils.create_environment import get_environment_variables import junit_xml @@ -449,20 +448,10 @@ def main(argv): os.makedirs(fuzzer_logdir) assert os.path.exists(fuzzer_logdir) - # Set part information from the mapping files and set into the env - db_root = os.path.join( - os.environ['XRAY_DATABASE_DIR'], os.environ['XRAY_DATABASE']) - part = get_part_information(db_root, os.environ['XRAY_PART']) - os.environ['XRAY_DEVICE'] = part['device'] - os.environ['XRAY_PACKAGE'] = part['package'] - os.environ['XRAY_SPEED_GRADE'] = part['speedgrade'] - fabric = get_fabric_for_part(db_root, os.environ['XRAY_PART']) - os.environ['XRAY_FABRIC'] = fabric - res_path = os.path.join( - os.environ['XRAY_DIR'], 'settings', os.environ['XRAY_DATABASE']) - resources = get_part_resources(res_path, os.environ['XRAY_PART']) - for number, pin in resources['pins'].items(): - os.environ['XRAY_PIN_{:02d}'.format(number)] = pin + # Update the environment for a specific part + environment = get_environment_variables() + for key, value in environment.items(): + os.environ[key] = value exit_code = -1 args.retries += 1 diff --git a/settings/artix7.sh b/settings/artix7.sh index 2fe1a117..67c0a95b 100644 --- a/settings/artix7.sh +++ b/settings/artix7.sh @@ -32,3 +32,5 @@ export XRAY_ROI_GRID_Y1="0" export XRAY_ROI_GRID_Y2="51" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/settings/artix7_200t.sh b/settings/artix7_200t.sh index c898f331..b7010130 100644 --- a/settings/artix7_200t.sh +++ b/settings/artix7_200t.sh @@ -22,3 +22,5 @@ export XRAY_EXCLUDE_ROI_TILEGRID="" export XRAY_IOI3_TILES="RIOI3_X105Y9 LIOI3_X0Y9" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/settings/artix7_50t.sh b/settings/artix7_50t.sh index eff26c5a..b73d6417 100644 --- a/settings/artix7_50t.sh +++ b/settings/artix7_50t.sh @@ -31,3 +31,5 @@ export XRAY_ROI_GRID_Y1="0" export XRAY_ROI_GRID_Y2="51" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/settings/kintex7.sh b/settings/kintex7.sh index 4af4e030..a44a0e41 100644 --- a/settings/kintex7.sh +++ b/settings/kintex7.sh @@ -26,3 +26,5 @@ export XRAY_ROI_GRID_Y1="104" export XRAY_ROI_GRID_Y2="156" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/settings/zynq7.sh b/settings/zynq7.sh index 94f12845..ddd69c7d 100644 --- a/settings/zynq7.sh +++ b/settings/zynq7.sh @@ -28,3 +28,5 @@ export XRAY_ROI_GRID_Y1="105" export XRAY_ROI_GRID_Y2="155" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/settings/zynq7010.sh b/settings/zynq7010.sh index 9f6f46cc..4160a1cc 100644 --- a/settings/zynq7010.sh +++ b/settings/zynq7010.sh @@ -28,3 +28,5 @@ export XRAY_ROI_GRID_Y1="0" export XRAY_ROI_GRID_Y2="51" source $(dirname ${BASH_SOURCE[0]})/../utils/environment.sh + +eval $(python3 ${XRAY_UTILS_DIR}/create_environment.py) diff --git a/utils/create_environment.py b/utils/create_environment.py new file mode 100755 index 00000000..852c2218 --- /dev/null +++ b/utils/create_environment.py @@ -0,0 +1,59 @@ +#!/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 + +import os + +from prjxray.util import get_part_information, get_part_resources, get_fabric_for_part + + +def get_environment_variables(): + """ + This function returns a dict of environment settings for a given part. + + It requires a basic setup of the prjxray environment that contains + information about the databse directory location, the FPGA part, etc. + + One of the settings must be sourced, to set up the basic environment. + """ + environment = dict() + + # Get base environment variables and resources' paths + part = os.environ['XRAY_PART'] + database = os.environ['XRAY_DATABASE'] + database_dir = os.environ['XRAY_DATABASE_DIR'] + xray_root = os.environ['XRAY_DIR'] + db_root = os.path.join(database_dir, database) + res_path = os.path.join(xray_root, 'settings', database) + + # Get device information + part_info = get_part_information(db_root, part) + fabric = get_fabric_for_part(db_root, part) + resources = get_part_resources(res_path, os.environ['XRAY_PART']) + + environment['XRAY_DEVICE'] = part_info['device'] + environment['XRAY_PACKAGE'] = part_info['package'] + environment['XRAY_SPEED_GRADE'] = part_info['speedgrade'] + environment['XRAY_FABRIC'] = fabric + for number, pin in resources['pins'].items(): + environment['XRAY_PIN_{:02d}'.format(number)] = pin + + return environment + + +def main(): + environment = get_environment_variables() + + for key, value in environment.items(): + print("export {}={}".format(key, value)) + + +if __name__ == "__main__": + main()