How to Simulate VHDL with GHDL
Goal: Analyze, elaborate, and simulate a VHDL design using the open-source GHDL simulator.
Note
GHDL requires no Vivado or Xilinx license. It is an independent open-source
VHDL simulator and works on any Linux system where ghdl is installed.
Prerequisites
Before running the simulation flow, ensure the following are in place:
ghdlbinary installed and on PATH (version 2.0+ recommended)gtkwaveinstalled for waveform viewingvhdepsinstalled (used bymake analysisto order the sources)A project
ruckus.tcltree that loads the design’s VHDL sourcesyosyswith the GHDL plugin installed (only required for the optionalmake export_verilogstep)Project
Makefileincludessystem_ghdl.mk
Makefile Setup
Add the following to your project Makefile:
include $(TOP_DIR)/submodules/ruckus/system_ghdl.mk
No PDK variables are required. GHDL uses only the VHDL sources loaded by the
project’s ruckus.tcl tree.
Steps
GHDL uses a staged pipeline. Steps 3 through 7 each correspond to a distinct GHDL command. Run targets in the order shown below.
Create output directories:
make dirRemoves any existing
$(OUT_DIR)(dirdepends onclean), then creates$(OUT_DIR)and$(IMAGES_DIR).Load source file list:
make load_source_codeRuns ruckus’s
ghdl/load_source_code.tcl, which generates the build info package and loads the project’sruckus.tcltree to enumerate the VHDL source files.Analyze VHDL sources (
ghdl -a):make analysisParses and type-checks all VHDL source files in dependency order (computed with
vhdeps). Errors here indicate syntax or type-checking problems in your HDL.Import design units (
ghdl -i):make importImports design units into the working library.
Determine elaboration order (
ghdl --elab-order):make elab_orderPrints the elaboration order of the top-level design unit.
Build (elaborate) the design (
ghdl -m):make buildElaborates the top-level design unit into a simulation executable and writes the source analysis order to
$(IMAGES_DIR)/$(PROJECT).elab_orderfor reference.Run simulation (
ghdl -r):make tbRuns the simulation and produces a waveform file at
$(OUT_DIR)/$(PROJECT).ghw. Simulation stops atGHDL_STOP_TIME(default:10ns).View waveform in GTKWave:
make gtkwaveOpens GTKWave with the
.ghwwaveform file produced bymake tb.
Note
Steps 1 through 7 can be run individually in sequence, or you can run
make tb directly. Because make tb depends on every prior target
except analysis, it executes the full chain automatically from a clean
state. make analysis is a standalone check and is not part of the
make tb chain.
Optional: Export Synthesizable Verilog
If you have yosys with the GHDL plugin installed, you can export a
synthesizable Verilog netlist from the VHDL design:
make export_verilog
This runs yosys -m ghdl to synthesize the VHDL design into Verilog,
written to $(IMAGES_DIR)/$(PROJECT).v. This step is independent of the
simulation flow and does not require GTKWave.
Key Variables
Variable |
Default |
Description |
|---|---|---|
|
|
GHDL executable path or name. Override if |
|
|
Top-level VHDL library name. Must match the |
|
|
Simulation stop time. Increase this for testbenches that require longer run times. |
|
|
Full set of flags passed to all GHDL commands. The complete default is:
|
|
|
Git dirty-state check bypassed by default. |
Note
To override GHDLFLAGS, set it in your project Makefile before the
include line:
export GHDLFLAGS = --workdir=$(OUT_DIR) --std=93 --ieee=standard
include $(TOP_DIR)/submodules/ruckus/system_ghdl.mk
Troubleshooting
- “ghdl: command not found”
Install GHDL on your system:
# Debian / Ubuntu sudo apt install ghdl
For other distributions or to build from source, see the GHDL repository at https://github.com/ghdl/ghdl.
- “bound check failure” or simulation stops immediately
Increase
GHDL_STOP_TIME. The default (10ns) is intentionally short and will be too brief for most testbenches. Set a longer stop time in your projectMakefile:export GHDL_STOP_TIME = 1us
- Analysis errors: “no library” or unresolved references
Verify that
GHDL_TOP_LIBmatches the library name used in your VHDLlibraryanduseclauses. If your design useslibrary work;, the default value ofworkis correct. Mismatches cause GHDL to fail to find design units during elaboration.- GTKWave shows an empty or unreadable waveform
Ensure
make tbcompleted successfully and the.ghwfile exists in$(OUT_DIR)/before runningmake gtkwave. An incomplete simulation (stopped by a runtime assertion) may produce a truncated waveform file.