Skip to content

Commit 24b6057

Browse files
cartallaAWSwinefred
authored andcommitted
On FPGA Developer AMI use the correct vivado version (aws#167)
This is to enable having both vivado and sdx installed in the AMI so can use both the master and prelease branches which use different versions of vivado. Use module load to use the correct vivado version based on the HDK version. Save the vivado version used to build the models. Rebuild the models if they were built with the wrong vivado version. Add a lock file to prevent multiple process from trying to build the models at the same time, potentially with different vivado versions. This requires procmail to be installed otherwise the lockfile isn't created/used. Merged changes from prelease. Not downloading the shell dcp from S3. Leaving that the same. This shouldn't be an issue when switching between prelease and master because they use different shell versions.
1 parent 0d28174 commit 24b6057

File tree

3 files changed

+227
-54
lines changed

3 files changed

+227
-54
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ waves.shm
2929
.nfs*
3030
*.so
3131
*.a
32+
33+
build.lock
34+
hdk/common/verif/models/.vivado_version

hdk/common/verif/scripts/init.sh

+70-25
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,74 @@
1515
## implied. See the License for the specific language governing permissions and
1616
## limitations under the License.
1717

18-
vivado -mode batch -source $HDK_COMMON_DIR/verif/scripts/init.tcl
19-
20-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/arch_defines.v $HDK_COMMON_DIR/verif/models/ddr4_model/
21-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/arch_package.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
22-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_model.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
23-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_sdram_model_wrapper.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
24-
#cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/dimm_interface.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
25-
#cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/dimm_subtest.vh $HDK_COMMON_DIR/verif/models/ddr4_model/
26-
#cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/dimm.vh $HDK_COMMON_DIR/verif/models/ddr4_model/
27-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/interface.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
28-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/MemoryArray.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
29-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/proj_package.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
30-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/StateTableCore.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
31-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/StateTable.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
32-
#cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/subtest.vh $HDK_COMMON_DIR/verif/models/ddr4_model/
33-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/timing_tasks.sv $HDK_COMMON_DIR/verif/models/ddr4_model/
34-
35-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_bi_delay.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
36-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_db_delay_model.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
37-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_db_dly_dir.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
38-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_dimm.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
39-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_dir_detect.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
40-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_rank.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
41-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_rcd_model.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
42-
cp tmp/tmp_ddr_ex/ddr4_core_ex/imports/ddr4_rdimm_wrapper.sv $HDK_COMMON_DIR/verif/models/ddr4_rdimm_wrapper/
18+
if [[ ":$HDK_COMMON_DIR" == ":" ]]; then
19+
echo "error: HDK_COMMON_DIR not set. Source hdk_setup.sh first."
20+
exit 2
21+
fi
4322

23+
if [[ ":$VIVADO_VER" == ":" ]]; then
24+
echo "error: VIVADO_VER not set. Source hdk_setup.sh first."
25+
exit 2
26+
fi
27+
28+
models_dir=$1
29+
if [[ ":$models_dir" == ":" ]]; then
30+
models_dir=$HDK_COMMON_DIR/verif/models
31+
fi
32+
33+
if [ ! -e $models_dir ]; then
34+
mkdir -p $models_dir
35+
fi
36+
37+
lockfile_filename=$models_dir/build.lock
38+
39+
# Prevent multiple users from building in the same directory.
40+
# Set the number of retries to 0 so that we will just fail
41+
# and let the other process complete the build.
42+
if [ -e /bin/lockfile ]; then
43+
if ! lockfile -r 0 $lockfile_filename; then
44+
echo "error: $lockfile_filename exists"
45+
echo "error: Another process is already building the models."
46+
exit 2
47+
fi
48+
fi
49+
50+
echo "$VIVADO_VER" > $models_dir/.vivado_version
51+
52+
if ! vivado -mode batch -source $HDK_COMMON_DIR/verif/scripts/init.tcl; then
53+
rm -f $lockfile_filename
54+
exit 2
55+
fi
56+
57+
ddr4_imports_dir=tmp/tmp_ddr_ex/ddr4_core_ex/imports
58+
ddr4_model_dir=$models_dir/ddr4_model
59+
ddr4_rdimm_model_dir=$models_dir/ddr4_rdimm_wrapper
60+
if [ ! -d $ddr4_model_dir ]; then mkdir -p $ddr4_model_dir; fi
61+
if [ ! -d $ddr4_rdimm_model_dir ]; then mkdir -p $ddr4_rdimm_model_dir; fi
62+
echo "Copying files to $ddr4_model_dir"
63+
cp $ddr4_imports_dir/arch_defines.v $ddr4_model_dir/
64+
cp $ddr4_imports_dir/arch_package.sv $ddr4_model_dir/
65+
cp $ddr4_imports_dir/ddr4_model.sv $ddr4_model_dir/
66+
cp $ddr4_imports_dir/ddr4_sdram_model_wrapper.sv $ddr4_model_dir/
67+
#cp $ddr4_imports_dir/dimm_interface.sv $ddr4_model_dir/
68+
#cp $ddr4_imports_dir/dimm_subtest.vh $ddr4_model_dir/
69+
#cp $ddr4_imports_dir/dimm.vh $ddr4_model_dir/
70+
cp $ddr4_imports_dir/interface.sv $ddr4_model_dir/
71+
cp $ddr4_imports_dir/MemoryArray.sv $ddr4_model_dir/
72+
cp $ddr4_imports_dir/proj_package.sv $ddr4_model_dir/
73+
cp $ddr4_imports_dir/StateTableCore.sv $ddr4_model_dir/
74+
cp $ddr4_imports_dir/StateTable.sv $ddr4_model_dir/
75+
#cp $ddr4_imports_dir/subtest.vh $ddr4_model_dir/
76+
cp $ddr4_imports_dir/timing_tasks.sv $ddr4_model_dir/
77+
78+
echo "Copying files to $ddr4_rdimm_model_dir"
79+
cp $ddr4_imports_dir/ddr4_bi_delay.sv $ddr4_rdimm_model_dir/
80+
cp $ddr4_imports_dir/ddr4_db_delay_model.sv $ddr4_rdimm_model_dir/
81+
cp $ddr4_imports_dir/ddr4_db_dly_dir.sv $ddr4_rdimm_model_dir/
82+
cp $ddr4_imports_dir/ddr4_dimm.sv $ddr4_rdimm_model_dir/
83+
cp $ddr4_imports_dir/ddr4_dir_detect.sv $ddr4_rdimm_model_dir/
84+
cp $ddr4_imports_dir/ddr4_rank.sv $ddr4_rdimm_model_dir/
85+
cp $ddr4_imports_dir/ddr4_rcd_model.sv $ddr4_rdimm_model_dir/
86+
cp $ddr4_imports_dir/ddr4_rdimm_wrapper.sv $ddr4_rdimm_model_dir/
87+
88+
rm -f $lockfile_filename

hdk_setup.sh

100755100644
+154-29
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,187 @@
1-
#!/bin/bash
1+
# Script must be sourced from a bash shell or it will not work
2+
# When being sourced $0 will be the interactive shell and $BASH_SOURCE_ will contain the script being sourced
3+
# When being run $0 and $_ will be the same.
4+
script=${BASH_SOURCE[0]}
5+
if [ $script == $0 ]; then
6+
echo "ERROR: You must source this script"
7+
exit 2
8+
fi
9+
full_script=$(readlink -f $script)
10+
script_name=$(basename $full_script)
11+
script_dir=$(dirname $full_script)
12+
13+
debug=0
14+
15+
function info_msg {
16+
echo -e "AWS FPGA-INFO: $1"
17+
}
18+
19+
function debug_msg {
20+
if [[ $debug == 0 ]]; then
21+
return
22+
fi
23+
echo -e "AWS FPGA-DEBUG: $1"
24+
}
25+
26+
function err_msg {
27+
echo -e >&2 "AWS FPGA-ERROR: $1"
28+
}
29+
30+
function usage {
31+
echo -e "USAGE: source [\$AWS_FPGA_REPO_DIR/]$script_name [-d|-debug] [-h|-help]"
32+
}
33+
34+
function help {
35+
info_msg "$script_name"
36+
info_msg " "
37+
info_msg "Sets up the environment for AWS FPGA HDK tools."
38+
info_msg " "
39+
info_msg "hdk_setup.sh script will:"
40+
info_msg " (1) check if Xilinx's vivado is installed,"
41+
info_msg " (2) set up key environment variables HDK_*, and"
42+
info_msg " (3) Download/update the HDK shell's checkpoint"
43+
info_msg " (4) prepare DRAM controller and PCIe IP modules if they are not already available in your directory."
44+
echo " "
45+
usage
46+
}
47+
48+
# Process command line args
49+
args=( "$@" )
50+
for (( i = 0; i < ${#args[@]}; i++ )); do
51+
arg=${args[$i]}
52+
case $arg in
53+
-d|-debug)
54+
debug=1
55+
;;
56+
-h|-help)
57+
help
58+
return 0
59+
;;
60+
*)
61+
err_msg "Invalid option: $arg\n"
62+
usage
63+
return 1
64+
esac
65+
done
66+
67+
# Make sure that AWS_FPGA_REPO_DIR is set to the location of this script.
68+
if [[ ":$AWS_FPGA_REPO_DIR" == ':' ]]; then
69+
debug_msg "AWS_FPGA_REPO_DIR not set so setting to $script_dir"
70+
export AWS_FPGA_REPO_DIR=$script_dir
71+
elif [[ $AWS_FPGA_REPO_DIR != $script_dir ]]; then
72+
info_msg "Changing AWS_FPGA_REPO_DIR from $AWS_FPGA_REPO_DIR to $script_dir"
73+
export AWS_FPGA_REPO_DIR=$script_dir
74+
else
75+
debug_msg "AWS_FPGA_REPO_DIR=$AWS_FPGA_REPO_DIR"
76+
fi
77+
78+
debug_msg "Checking for vivado install:"
279

3-
echo "AWS FPGA: hdk_setup.sh script will (i) check if Xilinx's vivado is installed, (ii) set up key environment variables HDK_*, and (iii) prepare DRAM controller and PCIe IP modules if they are not already available in your directory."
80+
# On the FPGA Developer AMI use module load to use the correct version of vivado
81+
if [ -e /usr/local/Modules/$MODULE_VERSION/bin/modulecmd ]; then
82+
# Module command is installed.
83+
# This branch requires sdx, not vivado
84+
# Load and unload the modules just to make sure have the environment set correctly
85+
module unload vivado
86+
module unload sdx
87+
module load vivado
88+
fi
489

5-
echo "AWS FPGA: Checking for vivado install:"
6-
790
# before going too far make sure Vivado is available
8-
vivado -version >/dev/null 2>&1 || { echo >&2 "ERROR - Please install/enable Vivado." ; return 1; }
91+
if ! vivado -version > /dev/null 2>&1; then
92+
err_msg "Please install/enable Vivado."
93+
err_msg " If you are using the FPGA Developer AMI then please request support."
94+
return 1
95+
fi
96+
97+
#Searching for Vivado version and comparing it with the list of supported versions
998

1099
export VIVADO_VER=`vivado -version | grep Vivado | head -1`
11100

12-
echo "AWS FPGA: Found $VIVADO_VER"
101+
info_msg "Using $VIVADO_VER"
13102

14-
if grep -Fxq "$VIVADO_VER" $(pwd)/hdk/supported_vivado_versions.txt
103+
if grep -Fxq "$VIVADO_VER" $AWS_FPGA_REPO_DIR/hdk/supported_vivado_versions.txt
15104
then
16-
echo "AWS FPGA: $VIVADO_VER is supported by this HDK release."
105+
debug_msg "$VIVADO_VER is supported by this HDK release."
17106
else
18-
echo "AWS FPGA: ERROR - $VIVADO_VER is not supported by this HDK release."
107+
err_msg "$VIVADO_VER is not supported by this HDK release."
108+
err_msg "Supported versions are:"
109+
cat $AWS_FPGA_REPO_DIR/hdk/supported_vivado_versions.txt
19110
return 1
20111
fi
21112

22-
echo "AWS FPGA: Vivado check successed"
113+
debug_msg "Vivado check succeeded"
23114

24-
echo "AWS FPGA: Setting up environment variables"
115+
info_msg "Setting up environment variables"
25116

26117
# Clear environment variables
27118
unset HDK_DIR
28119
unset HDK_COMMON_DIR
29120
unset HDK_SHELL_DIR
30-
unset CL_DIR
121+
# Don't unset CL_DIR if designer has already set it.
122+
#unset CL_DIR
31123

32-
export HDK_DIR=${HDK_DIR:=$(pwd)/hdk}
124+
export HDK_DIR=$AWS_FPGA_REPO_DIR/hdk
33125

34126
# The next variable should not be modified and should always point to the /common directory under HDK_DIR
35127
export HDK_COMMON_DIR=$HDK_DIR/common
36128

37129
# Point to the latest version of AWS shell
38-
export HDK_SHELL_DIR=$HDK_COMMON_DIR/shell_latest
130+
export HDK_SHELL_DIR=$(readlink -f $HDK_COMMON_DIR/shell_latest)
131+
hdk_shell_version=$(readlink $HDK_COMMON_DIR/shell_latest)
39132

40133
# The CL_DIR is where the actual Custom Logic design resides. The developer is expected to override this.
41134
# export CL_DIR=$HDK_DIR/cl/developer_designs
42135

43-
echo "AWS FPGA: Done setting environment variables.";
136+
debug_msg "Done setting environment variables.";
44137

45138
# Create DDR and PCIe IP models and patch PCIe
46-
if [ ! -f $HDK_COMMON_DIR/verif/models/ddr4_model/arch_defines.v ]
47-
then
48-
echo "DDR4 model files in "$HDK_COMMON_DIR/verif/models/ddr4_model/" do NOT exist. Running model creation step.";
49-
echo "This could take 5-10 minutes, please be patient!";
139+
models_dir=$HDK_COMMON_DIR/verif/models
140+
ddr4_model_dir=$models_dir/ddr4_model
141+
if [ -f $ddr4_model_dir/arch_defines.v ]; then
142+
# Models already built
143+
# Check to make sure they were built with this version of vivado
144+
if [[ -f $models_dir/.vivado_version ]]; then
145+
models_vivado_version=$(cat $models_dir/.vivado_version)
146+
info_msg "DDR4 model files in $ddr4_model_dir/ were built with $models_vivado_version"
147+
if [[ $models_vivado_version != $VIVADO_VER ]]; then
148+
info_msg " Wrong vivado version so rebuilding with $VIVADO_VER"
149+
fi
150+
else
151+
models_vivado_version=UNKNOWN
152+
info_msg "DDR4 model files in $ddr4_model_dir/ were built with UNKNOWN vivado version so rebuilding."
153+
fi
154+
else
155+
# Models haven't been built
156+
models_vivado_version=NOT_BUILT
157+
info_msg "DDR4 model files in "$ddr4_model_dir/" do NOT exist. Running model creation step.";
158+
fi
159+
if [[ $models_vivado_version != $VIVADO_VER ]]; then
160+
ddr4_build_dir=$AWS_FPGA_REPO_DIR/ddr4_model_build
161+
info_msg " Building in $ddr4_build_dir"
162+
info_msg " This could take 5-10 minutes, please be patient!";
163+
mkdir -p $ddr4_build_dir
164+
pushd $ddr4_build_dir &> /dev/null
50165
# Run init.sh then clean-up
51-
source $HDK_DIR/common/verif/scripts/init.sh
52-
echo "Done with model creation step. Cleaning up temporary files.";
53-
rm -fr tmp
54-
rm vivado*jou
55-
rm vivado*log
166+
if ! $HDK_DIR/common/verif/scripts/init.sh $models_dir; then
167+
err_msg "DDR4 model build failed."
168+
err_msg " Build dir=$ddr4_build_dir"
169+
popd &> /dev/null
170+
return 2
171+
fi
172+
info_msg "DDR4 model build passed."
173+
popd &> /dev/null
174+
rm -rf $ddr4_build_dir
56175
else
57-
echo "DDR4 model files exist in "$HDK_COMMON_DIR/verif/models/ddr4_model/". Skipping model creation step.";
176+
debug_msg "DDR4 model files exist in "$ddr4_model_dir/". Skipping model creation step.";
58177
fi
59-
echo "AWS FPGA: Done with AWS HDK setup.";
60-
echo "AWS FPGA: ATTENTION: Don't forget to change the CL_DIR variable for the directory of your Custom Logic.";
61-
62-
178+
if [[ ":$CL_DIR" == ':' ]]; then
179+
info_msg "ATTENTION: Don't forget to set the CL_DIR variable for the directory of your Custom Logic.";
180+
else
181+
info_msg "CL_DIR is $CL_DIR"
182+
if [ ! -d $CL_DIR ]; then
183+
err_msg "CL_DIR doesn't exist. Set CL_DIR to a valid directory."
184+
unset CL_DIR
185+
fi
186+
fi
187+
info_msg "AWS HDK setup PASSED.";

0 commit comments

Comments
 (0)