Skip to content

Commit

Permalink
Fix cocotb with verilator
Browse files Browse the repository at this point in the history
When building the verilated model, the linker complains about missing python
symbols in some cases. We get around this by telling the linker to ignore
unknown symbols.
  • Loading branch information
olofk committed May 17, 2024
1 parent 0497097 commit d360d8f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion edalize/flows/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def configure_tools(self, flow):
[
"--vpi",
"--public-flat-rw --prefix Vtop",
'-LDFLAGS "-Wl,-rpath,`cocotb-config --lib-dir` -L`cocotb-config --lib-dir` -lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils"',
'-LDFLAGS "-Wl,-rpath,`cocotb-config --lib-dir` -L`cocotb-config --lib-dir` -lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils -Wl,--unresolved-symbols=ignore-in-shared-libs"',
],
),
}
Expand Down
19 changes: 19 additions & 0 deletions tests/flows/sim/with_cocotb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Auto generated by Edalize

all: post_build

pre_build:

Vtop.mk: design.vc sv_file.sv vlog_file.v vlog05_file.v vlog_incfile another_sv_file.sv | pre_build
$(EDALIZE_LAUNCHER) verilator -f design.vc `cocotb-config --share`/lib/verilator/verilator.cpp

Vtop: Vtop.mk c_file.c cpp_file.cpp
$(EDALIZE_LAUNCHER) make -f Vtop.mk

post_build: Vtop

pre_run:

run: pre_run

post_run: run
22 changes: 22 additions & 0 deletions tests/flows/sim/with_cocotb/design.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--Mdir .
--cc
--vpi
--public-flat-rw --prefix Vtop
-LDFLAGS "-Wl,-rpath,`cocotb-config --lib-dir` -L`cocotb-config --lib-dir` -lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils -Wl,--unresolved-symbols=ignore-in-shared-libs"
+incdir+.
-CFLAGS -I.
sv_file.sv
vlog_file.v
vlog05_file.v
another_sv_file.sv
--top-module top_module

--exe
c_file.c
cpp_file.cpp
-Gvlogparam_bool=1
-Gvlogparam_int=42
-Gvlogparam_str=\"hello\"
-Dvlogdefine_bool=1
-Dvlogdefine_int=42
-Dvlogdefine_str=hello
13 changes: 13 additions & 0 deletions tests/test_flow_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ def test_sim(flow_fixture):
"Makefile",
]
)


def test_sim_cocotb(flow_fixture):
flow_options = {"tool": "verilator", "cocotb_module": "some_cocotb_module"}
ff = flow_fixture("sim", flow_options=flow_options, ref_subdir="with_cocotb")

ff.flow.configure()
ff.compare_config_files(
[
"design.vc",
"Makefile",
]
)

0 comments on commit d360d8f

Please sign in to comment.