2 # Copyright 2018-2025 The University of Birmingham
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # shellcheck source=Other/CommonFunctions.sh
18 . $(dirname "$0")/Other/CommonFunctions.sh
22 # @brief Prints an help message
24 # The help message contains both the options available for the first line of the tcl, both the command usage
25 # This function uses echo to print to screen
27 # @param[in] $1 the invoked command
29 function help_message() {
31 echo " Hog - Initialise repository"
32 echo " ---------------------------"
33 echo " Initialise your Hog-handled firmware repository"
34 echo " - (optional) Compile questasim/modelsim/riviera libraries (if questasim executable is found)"
35 echo " - (optional) Create vivado projects (if vivado executable is found)"
42 # @brief main function, initialize the repository by compiling simulation libraries and creating projects
50 DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
52 if [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ] || [ "$1" == "-H" ]; then
60 ##! The script checks if Vivado is installed and set up on the shell.
61 ##! NOTE that these checks are performed using 'command -v '
62 if [ "$(command -v vivado)" ]; then
65 VIVADO=$(command -v vivado)
66 ##! If Vivado is installed it checks if vsim command is defined (Questasim or Modelsim is installed and set-up in the shell).
67 ##! NOTE that these checks are performed using 'command -v '
69 ##! Ask the user if he wants to compile the simulation libraries
70 ##! NOTE use read to grab user input
71 ##! NOTE if the user input contains Y or y then is accepted as yes
72 read -p " Do you want to compile the simulation libraries for Vivado (this might take some time)? " -n 1 -r
74 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
75 echo "Please select the target simulator"
76 printf "1. Questa Advanced Simulator \n2. ModelSim Simulator \n3. Riviera-PRO Simulator \n4. Incisive Enterprise Simulator (IES) \n5. Xcelium Parallel Simulator \n6. Verilog Compiler Simulator (VCS)"
79 if [ "${REPLY}" -le 6 ] && [ "${REPLY}" -gt 0 ]; then
101 echo "Where do you want the simulation libraries to be saved? (skip for default: SimulationLib)"
104 if [[ $SIMDIR == "" ]]; then
105 SIMDIR="SimulationLib"
108 Msg Info "Compiling $SIMULATOR libraries into $SIMDIR..."
109 "${VIVADO}" -mode batch -notrace -source ./Tcl/utils/compile_simlib.tcl -tclargs -simulator $SIMULATOR -output_dir $SIMDIR
111 rm -f ./Tcl/compile_simlib.log
114 echo "Chosen simulator is not valid. No simulation libraries will be compiled..."
120 # Repeat compilation using Quartus
121 if [ "$(command -v quartus_sh)" ]; then
124 QUARTUS=$(command -v quartus_sh)
125 ##! If Quartus is installed it checks if vsim command is defined (Questasim or Modelsim is installed and set-up in the shell).
126 ##! NOTE that these checks are performed using 'command -v '
127 if [ "$(command -v vsim)" ]; then
129 ##! If Questasim or Modelsim is installed ask user if he wants to compile
130 ##! NOTE use read to grab user input
131 ##! NOTE if the user input contains Y or y then is accepted as yes
132 read -p " Do you want to compile Questasim libraries for Quartus (this might take some time)? " -n 1 -r
134 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
135 Msg Info "Compiling Questasim libraries into SimulationLib..."
136 mkdir -p "${OLD_DIR}/SimulationLib_quartus/verilog/"
137 mkdir -p "${OLD_DIR}/SimulationLib_quartus/vhdl/"
138 "${QUARTUS}" --simlib_comp -suppress_messages -tool questasim -language verilog -family all -directory "${OLD_DIR}/SimulationLib_quartus/verilog/"
139 "${QUARTUS}" --simlib_comp -suppress_messages -tool questasim -language vhdl -family all -directory "${OLD_DIR}/SimulationLib_quartus/vhdl/"
141 read -p " Do you want to compile Modelsim libraries for Quartus (this might take some time)? " -n 1 -r
143 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
144 Msg Info "Compiling Modelsim libraries into SimulationLib..."
145 mkdir -p "${OLD_DIR}/SimulationLib_quartus/verilog/"
146 mkdir -p "${OLD_DIR}/SimulationLib_quartus/vhdl/"
147 "${QUARTUS}" --simlib_comp -suppress_messages -tool modelsim -language verilog -family all -directory "${OLD_DIR}/SimulationLib_quartus/verilog/"
148 "${QUARTUS}" --simlib_comp -suppress_messages -tool modelsim -language vhdl -family all -directory "${OLD_DIR}/SimulationLib_quartus/vhdl/"
152 Msg Warning "No modelsim executable found, will not compile libraries"
156 if ! $COMPILER_FOUND; then
157 Msg Warning "No Vivado or Quartus executable found!"
160 ##! Scan for existing Vivado projects and ask user to automatically create listFiles
161 ##! NOTE projects already in Projects directory have already a Hog structure, ignore them
162 ##! NOTE use read to grab user input
163 ##! NOTE if the user input contains Y or y then is accepted as yes
165 Vivado_prjs=$(find "$DIR/.." -path "$DIR/../Projects" -prune -false -o -name "*.xpr")
167 for Vivado_prj in $Vivado_prjs; do
169 Vivado_prj_base=$(basename "$Vivado_prj")
170 read -p " Found existing Vivado project $Vivado_prj_base. Do you want to convert it to a Hog compatible project? (creates listfiles and hog.conf) " -n 1 -r
171 echo # (optional) move to a new line
172 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
174 if [ -d "$DIR/../Top/${Vivado_prj_base%.*}" ]; then
175 read -p " Directory \"Top/${Vivado_prj_base%.*}\" exists. Do you want to overwrite it? " -n 1 -r
176 echo # (optional) move to a new line
177 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
183 vivado -mode batch -notrace -source $DIR/Tcl/utils/check_list_files.tcl $Vivado_prj -tclargs -recreate $Force -recreate_conf
187 ##! Ask user if he wants to create all projects in the repository
188 ##! NOTE use read to grab user input
189 ##! NOTE if the user input contains Y or y then is accepted as yes
191 read -p " Do you want to create projects now (can be done later with CreateProject.sh)? " -n 1 -r
192 echo # (optional) move to a new line
193 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
195 proj=$(search_projects Top)
196 Msg Info "Creating projects for: $proj..."
198 Msg Info "Creating Vivado project: $f..."
203 ##! Ask user if he wants to add custom Vivado GUI button to automatically update listfiles
204 ##! NOTE use read to grab user input
205 ##! NOTE if the user input contains Y or y then is accepted as yes
206 if [ "$(command -v vivado)" ]; then
208 read -p " Do you want to add four buttons to the Vivado GUI to check and update the list files and the project hog.conf file automatically? " -n 1 -r
211 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
212 vivado -mode batch -notrace -source $DIR/Tcl/utils/add_hog_custom_button.tcl
216 ##! Check if hog tags tag exist, and if not ask user if they want to create v0.0.1
218 if git describe --match "v*.*.*" >/dev/null 2>&1; then
219 Msg Info "Repository contains Hog-compatible tags."
221 read -p " Your repository does not have Hog-compatible tags, do you wish to create an initial tag v0.0.1 now?" -n 1 -r
222 echo # (optional) move to a new line
223 if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
224 git tag v0.0.1 -m "First Hog tag"
229 cd "${OLD_DIR}" || exit
234 function HogInitFunc(){
236 # echo "HogInitFunc ($*)"
241 if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
242 print_hog "$(dirname "$0")"