|
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:" |
2 | 79 |
|
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 |
4 | 89 |
|
5 |
| -echo "AWS FPGA: Checking for vivado install:" |
6 |
| - |
7 | 90 | # 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 |
9 | 98 |
|
10 | 99 | export VIVADO_VER=`vivado -version | grep Vivado | head -1`
|
11 | 100 |
|
12 |
| -echo "AWS FPGA: Found $VIVADO_VER" |
| 101 | +info_msg "Using $VIVADO_VER" |
13 | 102 |
|
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 |
15 | 104 | then
|
16 |
| - echo "AWS FPGA: $VIVADO_VER is supported by this HDK release." |
| 105 | + debug_msg "$VIVADO_VER is supported by this HDK release." |
17 | 106 | 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 |
19 | 110 | return 1
|
20 | 111 | fi
|
21 | 112 |
|
22 |
| -echo "AWS FPGA: Vivado check successed" |
| 113 | +debug_msg "Vivado check succeeded" |
23 | 114 |
|
24 |
| -echo "AWS FPGA: Setting up environment variables" |
| 115 | +info_msg "Setting up environment variables" |
25 | 116 |
|
26 | 117 | # Clear environment variables
|
27 | 118 | unset HDK_DIR
|
28 | 119 | unset HDK_COMMON_DIR
|
29 | 120 | unset HDK_SHELL_DIR
|
30 |
| -unset CL_DIR |
| 121 | +# Don't unset CL_DIR if designer has already set it. |
| 122 | +#unset CL_DIR |
31 | 123 |
|
32 |
| -export HDK_DIR=${HDK_DIR:=$(pwd)/hdk} |
| 124 | +export HDK_DIR=$AWS_FPGA_REPO_DIR/hdk |
33 | 125 |
|
34 | 126 | # The next variable should not be modified and should always point to the /common directory under HDK_DIR
|
35 | 127 | export HDK_COMMON_DIR=$HDK_DIR/common
|
36 | 128 |
|
37 | 129 | # 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) |
39 | 132 |
|
40 | 133 | # The CL_DIR is where the actual Custom Logic design resides. The developer is expected to override this.
|
41 | 134 | # export CL_DIR=$HDK_DIR/cl/developer_designs
|
42 | 135 |
|
43 |
| -echo "AWS FPGA: Done setting environment variables."; |
| 136 | +debug_msg "Done setting environment variables."; |
44 | 137 |
|
45 | 138 | # 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 |
50 | 165 | # 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 |
56 | 175 | 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."; |
58 | 177 | 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