├── .gitignore ├── .gitmodules ├── Makefile ├── README.md └── img ├── dff-test.png └── dff-vcd.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | env/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cocotb"] 2 | path = cocotb 3 | url = https://github.com/antmicro/cocotb.git 4 | branch = verilator-infrastructure 5 | [submodule "verilator"] 6 | path = verilator 7 | url = https://github.com/antmicro/verilator.git 8 | branch = dev 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | QUIET ?= @ 3 | SIM ?= verilator 4 | 5 | VERBOSE ?= 0 6 | 7 | ifeq ($(VERBOSE),1) 8 | VL_C_FLAGS = -DVL_DEBUG 9 | VL_CPP_FLAGS = -DVL_DEBUG 10 | VL_CXX_FLAGS = -DVL_DEBUG 11 | 12 | COCOTB_APPEND = \ 13 | COCOTB_SCHEDULER_DEBUG=1 \ 14 | COCOTB_LOG_LEVEL=DEBUG 15 | endif 16 | 17 | IN_ENV = . env/bin/activate ; 18 | 19 | all: 20 | @true 21 | 22 | verilator/configure: verilator/configure.ac 23 | cd verilator && autoconf 24 | 25 | verilator/.conf: verilator/configure 26 | (cd verilator && \ 27 | CFLAGS="$(VL_C_FLAGS)" \ 28 | CPPFLAGS="$(VL_CPP_FLAGS)" \ 29 | CXXFLAGS="$(VL_CXX_FLAGS)" \ 30 | ./configure --prefix=$(PWD)/env) && touch $@ 31 | 32 | verilator/.build: verilator/.conf 33 | (cd verilator && make -j`nproc`) && touch $@ 34 | 35 | env/bin/verilator: verilator/.build 36 | (cd verilator && make install) 37 | 38 | env/bin/activate: 39 | virtualenv --python=python3 env 40 | 41 | env/bin/cocotb-config: env/bin/activate 42 | $(IN_ENV) pip install -e ./cocotb 43 | 44 | env/enter: env/bin/activate env/bin/cocotb-config env/bin/verilator 45 | $(QUIET)$(IN_ENV) env \ 46 | CMD=$(PWD)/env/bin/verilator \ 47 | SIM=verilator \ 48 | PYTHONDONTWRITEBYTECODE=1 \ 49 | bash --rcfile <( \ 50 | cat $$HOME/.bashrc ; \ 51 | echo 'PS1="(cocotb) $$PS1"' \ 52 | ) || true 53 | 54 | define cocotb_target_raw 55 | cocotb/$(1)/$(2): 56 | $$(QUIET)$$(IN_ENV) env \ 57 | CMD=$$(PWD)/env/bin/verilator \ 58 | SIM=$(SIM) \ 59 | PYTHONDONTWRITEBYTECODE=1 \ 60 | $(COCOTB_APPEND) \ 61 | bash -c "cd cocotb/examples/$(1)/tests ; make $(3)" 62 | endef 63 | 64 | define cocotb_target 65 | $(eval $(call cocotb_target_raw,$(1),run,)) 66 | $(eval $(call cocotb_target_raw,$(1),clean,clean)) 67 | endef 68 | 69 | COCOTB_EXAMPLES = $(shell for p in cocotb/examples/* ; do [ -d $$p ] && echo $$p | cut -d\/ -f3 ; done) 70 | 71 | $(foreach t,$(COCOTB_EXAMPLES),$(eval $(call cocotb_target,$(t)))) 72 | 73 | # ---------------------------------- TESTS --------------------------------- 74 | SYSTEMC_URL = https://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz 75 | VCDDIFF_URL = git@github.com:veripool/vcddiff.git 76 | 77 | tests/.dir: 78 | mkdir `dirname $@` && touch $@ 79 | 80 | 81 | tests/systemc.tar.gz: tests/.dir 82 | wget -c $(SYSTEMC_URL) -O $@ && touch $@ 83 | 84 | tests/systemc/.unpack: tests/systemc.tar.gz 85 | mkdir tests/systemc && tar xf $< --strip-components=1 -C tests/systemc && touch $@ 86 | 87 | tests/systemc/.conf: tests/systemc/.unpack 88 | (cd tests/systemc && ./configure --prefix=$(PWD)/tests/systemc/image) && touch $@ 89 | 90 | tests/systemc/.build: tests/systemc/.conf 91 | (cd tests/systemc && make -j`nproc`) && touch $@ 92 | 93 | tests/systemc/.install: tests/systemc/.build 94 | (cd tests/systemc && make install) && touch $@ 95 | 96 | 97 | tests/vcddiff/.clone: tests/.dir 98 | git clone $(VCDDIFF_URL) tests/vcddiff && touch $@ 99 | 100 | tests/vcddiff/vcddiff: tests/vcddiff/.clone 101 | (cd tests/vcddiff && make -j`nproc`) 102 | 103 | 104 | tests/.verilator_clone: tests/.dir 105 | git clone verilator tests/verilator && touch $@ 106 | 107 | tests/verilator/configure: tests/.verilator_clone 108 | (cd tests/verilator && autoconf) 109 | 110 | tests/.verilator_conf: tests/verilator/configure 111 | (cd tests/verilator && ./configure --enable-longtests) && touch $@ 112 | 113 | tests/.verilator_build: tests/.verilator_conf 114 | (cd tests/verilator && make -j`nproc`) && touch $@ 115 | 116 | 117 | tests/verilator: tests/.verilator_build tests/vcddiff/vcddiff tests/systemc/.install 118 | (cd tests/verilator && \ 119 | PATH=/home/lukas/cocotb/vcddiff:$$PATH \ 120 | LD_LIBRARY_PATH=$(PWD)/tests/systemc/image/lib-linux64 \ 121 | SYSTEMC_INCLUDE=$(PWD)/tests/systemc/image/include \ 122 | SYSTEMC_LIBDIR=$(PWD)/tests/systemc/image/lib-linux64 \ 123 | make test 2>&1 | tee $(PWD)/tests/log-`git rev-parse --verify HEAD`.txt) 124 | 125 | 126 | tests/clean: 127 | rm -rf tests 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *** 2 | 3 | **IMPORTANT** 4 | 5 | **This repository has been archived and is no longer maintained since all changes required to support Verilator in cocotb have been upstreamed.** 6 | 7 | *** 8 | 9 | # Verilator+cocotb integration quick start guide 10 | 11 | 1. Install dependencies: 12 | 13 | ``` 14 | sudo apt-get install virtualenv build-essential 15 | sudo apt-get install python3-dev 16 | sudo apt install gtkwave 17 | 18 | ``` 19 | 20 | 21 | 2. Clone the repository: 22 | 23 | ``` 24 | git clone https://github.com/antmicro/cocotb-verilator-build.git build 25 | ``` 26 | 27 | 3. Change working directory to cloned repository: 28 | 29 | ``` 30 | cd build 31 | ``` 32 | 33 | 4. Download missing submodules: 34 | 35 | ``` 36 | git submodule update --init 37 | ``` 38 | 39 | 5. Build and install Verilator in local environment 40 | 41 | ``` 42 | make env/bin/verilator 43 | ``` 44 | 45 | 6. Install cocotb in local environment: 46 | 47 | ``` 48 | make env/bin/cocotb-config 49 | ``` 50 | 51 | # Examples 52 | 53 | To run the examples included in Cocotb, simply run `make cocotb/name_of_the_example/run`. 54 | To clean the directory with the examples execute `make cocotb/name_of_the_example/clean`. 55 | 56 | Running the `adder` example: 57 | 58 | make cocotb/adder/run 59 | 60 | Runing the `D flip-flop` example: 61 | 62 | make cocotb/dff/run 63 | 64 | Running `axi_lite_slave`: 65 | 66 | make cocotb/axi_lite_slave/run 67 | 68 | To dump a vaweform from the simulation set the `VERILATOR_TRACE=1` env variable e.g: 69 | 70 | VERILATOR_TRACE=1 make cocotb/dff/run 71 | 72 | The vaweform file is written in the example folder. `gtkwave` can be used for viewing it e.g: 73 | 74 | gtkwave cocotb/examples/dff/tests/dump.vcd 75 | 76 | An example waveform you should get is shown below: 77 | 78 | ![DFF test waveform](img/dff-vcd.png) 79 | 80 | An example test output is shown in the picture bellow: 81 | 82 | ![DFF test waveform](img/dff-test.png) 83 | -------------------------------------------------------------------------------- /img/dff-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/cocotb-verilator-build/35048cfd2dd708f303e7dbe7a410a3e99274de1f/img/dff-test.png -------------------------------------------------------------------------------- /img/dff-vcd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/cocotb-verilator-build/35048cfd2dd708f303e7dbe7a410a3e99274de1f/img/dff-vcd.png --------------------------------------------------------------------------------