Bug 620 - post-layout simulation needed using cocotb
Summary: post-layout simulation needed using cocotb
Status: RESOLVED FIXED
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Hardware Layout (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- enhancement
Assignee: Staf Verhaegen
URL:
Depends on:
Blocks: 199
  Show dependency treegraph
 
Reported: 2021-03-29 13:32 BST by Luke Kenneth Casson Leighton
Modified: 2021-04-24 18:24 BST (History)
2 users (show)

See Also:
NLnet milestone: NLNet.2019.Coriolis2
total budget (EUR) for completion of task and all subtasks: 2500
budget (EUR) for this task, excluding subtasks' budget: 2500
parent task for budget allocation: 199
child tasks for budget allocation:
The table of payments (in EUR) for this task; TOML format:
"lkcl"={amount=1250, submitted=2021-04-24} "staf"={amount=1250, submitted=2021-04-21}


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Kenneth Casson Leighton 2021-03-29 13:32:46 BST
taking the VST (VHDL) files from coriolis2 post-layout modifications
(including insertion of buffers) needs to be verified.  this to be done
using cocotb to connect up to JTAG (c4m-jtag) and perform tests.

code repository:

https://git.libre-soc.org/?p=soc-cocotb-sim.git;a=summary
Comment 1 Luke Kenneth Casson Leighton 2021-03-29 13:54:43 BST
first most immediate things, we need some sort of wrapper-processor of the
VST files.  i renamed one (from soclayout experiments13) from memory.vst
to memory.vhdl and we have this:

ghdl -a memory.vhdl 
memory.vhdl:323:10:error: two underscores can't be consecutive
memory.vhdl:324:10:error: two underscores can't be consecutive

editing to replace the underscores we have this:

ghdl -a memory.vhdl 
memory.vhdl:1938:21:error: cannot associate in signal interface "vdd" with actual port of mode linkage

so there is quite a bit of processing which needs to be done, which i
recommend be done with an auto-parser.
Comment 2 Staf Verhaegen 2021-04-01 13:04:09 BST
Commit first setup for cocotb testing:
https://git.libre-soc.org/?p=libresoc-litex.git;a=commit;h=3e69d2095ab2e0dd64fe94ca1547ecc8a2f56719

Usage can be seen in readme file:
https://git.libre-soc.org/?p=libresoc-litex.git;a=blob;f=cocotb/README.md;h=f239eccb541bf389d98fea8dac1033eb24e73ca6;hb=3e69d2095ab2e0dd64fe94ca1547ecc8a2f56719

Update by `git pull` in soc and doing `make gitupdate`; then go to
'src/soc/litex/florent/cocotb'
Comment 3 Staf Verhaegen 2021-04-01 13:42:48 BST
You also need to update c4m-jtag and `pip install modgrammar`.
modgrammar is now dependency of c4m-jtag so will be automatically installed when you (re-)install c4m-jtag.
Comment 4 Luke Kenneth Casson Leighton 2021-04-02 16:06:05 BST
this has shown up some naming clashes due to verilog / ilang using capital letters in netnames and vhdl being case insensitive.
Comment 5 Luke Kenneth Casson Leighton 2021-04-08 00:44:19 BST
https://tomverbeure.github.io/2020/11/04/VHDL_Verilog_Cosimulation_with_CXXRTL.html


https://github.com/tomverbeure/cxxrtl_eval/blob/master/blink_basic/main.cpp

https://git.libre-soc.org/?p=litex.git;a=blob;f=litex/build/sim/core/modules/jtagremote/jtagremote.c;h=87c7c159842231bba2c5e94e1e054f71c5d90e36;hb=35929c0f8a8f1cc098a6b6ebb569caca8df8c08d

https://git.libre-soc.org/?p=soc.git;a=blob;f=src/soc/debug/test/test_jtag_tap.py;hb=HEAD

i believe it should be extremely straightforward to combine the above, this is not nmigen just cxxrtl from yosys, to create a jtag tester which speaks openocd "jtagremote" socket protocol.

at that point it will be possible to connect directly to the simulation with .svf files, from openocd commandline, as if it was a real ASIC or FPGA.

with cxxsim or more to the point yosys having both verilog and ghdl it should be possible to do pre and post pnr simulation.
Comment 6 Luke Kenneth Casson Leighton 2021-04-08 11:27:38 BST
https://gist.github.com/brabect1/9f8d7d144367b9f3dd77ba2a3b459f1d#file-xindep_clk-cpp-L137

this is what it would take - modifying cocotb - to allow it to
run external (c++) clocks.  neither iverilog nor verilator support
"always #period" unfortunately.
Comment 7 Staf Verhaegen 2021-04-08 13:54:27 BST
I seem to have success in iverilog with the following code:

> `timescale 1ns/1ps
> 
> module clkdrv(output reg clk);
> 
> initial begin
>     clk = 0;
>     forever begin
>         #10 clk = ~clk;
>     end
> end
> 
> endmodule
Comment 8 Luke Kenneth Casson Leighton 2021-04-08 14:07:01 BST
(In reply to Staf Verhaegen from comment #7)
> I seem to have success in iverilog with the following code:
> 
> > `timescale 1ns/1ps
> > 
> > module clkdrv(output reg clk);
> > 
> > initial begin
> >     clk = 0;
> >     forever begin
> >         #10 clk = ~clk;
> >     end
> > end
> > 
> > endmodule

ah good! does the wb example work? or does it hang, still?
(i will run it in a bit, am in the middle of the cxxrtl test)
Comment 9 Luke Kenneth Casson Leighton 2021-04-08 18:45:17 BST
ok the cxxrtl compilation of ls180, including the litex peripheral set, was successful.  took several minutes to compile.

results of running an openocd jtagremote "upload" are that the wishbone interface is not entirely functional yet.

however the DMI interface, which allows the core to be stopped, reset, and restarted, was successful.

because cxxsim can output gtkwave VCD i was able to ascertain that the core is executing at address 0x700 in a loop, which is a good sign.

investigating wishbone over jtag is the next priority.
Comment 10 Luke Kenneth Casson Leighton 2021-04-08 19:52:28 BST
ah ha! the error with wishbone jtag is that it is going through a converter (64 downto 32) which takes 2 cycles, and there is no "stall" signal.

consequently the stb line is dropped at the 1st of those cycles, in the middle of the conversion, because the TAP WB FSM moves from READ to READACK too early.

i will try creating a "fake" stall to stop that hspoening.
Comment 11 Luke Kenneth Casson Leighton 2021-04-08 21:31:20 BST
a really quick solution: set the JTAG WB Master bus data width to 32-bit wide.
this will get it to match directly with the litex bus which is also 32-bit
and the "converter" will be switched off.  this also saves gates.
Comment 12 Luke Kenneth Casson Leighton 2021-04-09 00:19:36 BST
the tap wb code assumed that it would be talking to a pipelined wb.  litex does not support stall and so i used that to enable "single" read/write.

wb jtag therefore now works.

the last remaining thing to do is to get the pc to reset when DMI RESET is called.
Comment 13 Luke Kenneth Casson Leighton 2021-04-09 10:49:27 BST
https://github.com/YosysHQ/yosys/pull/2724

cxxsim bug, but there's a workaround: use "memory" pass before
write_cxxsim.
Comment 14 Luke Kenneth Casson Leighton 2021-04-09 18:01:01 BST
thanks to staf for correcting sff1r_x4.vhd which had errors in it, a quick simulation of the adder test works, post BLIF.
Comment 15 Staf Verhaegen 2021-04-10 12:39:22 BST
Out of discussion on IRC here minimal clock generation block in VHDL:

    entity clkgen is port(clk: out bit);
    end entity clkgen;
    
    architecture sim of clkgen is
    signal intclk: bit := '0';
    begin
        intclk <= not intclk after 10 ns;
        clk <= intclk;
    end architecture sim;
Comment 16 Luke Kenneth Casson Leighton 2021-04-11 14:38:58 BST
currently doing ghdl cocotb post layout P&R using the cts.vst files.

both chip.vst / chip_r.vst and corona are a bit of a mess:

* to/from pad signals exist which have the same name as the chip in/out ports
* the names iovdd gpio iovss vdd and vss are used for both components and signals (niolib)
* gpio in niolib uses std_ulogic for the pad port but in chip/chip_r it is declared as a bit.

some of these can be corrected with post-processing, others involve renaming niolib cell components, others need the corona/chip generation to be updated.

quite a lot to do
Comment 17 Luke Kenneth Casson Leighton 2021-04-12 11:01:06 BST
Staf you will temporarily need this patch to blif2vst.py in alliance-check-toolkit in order to perform any kind of build:

https://gitlab.lip6.fr/vlsi-eda/coriolis/uploads/b4b17e8907b0f4a002a4d542e7f5dc2f/z7
Comment 18 Staf Verhaegen 2021-04-12 11:30:42 BST
I am currently using a script (ln_vst.sh) to link vst files:

    #!/bin/sh
    for f in *.vst; do
        n1=`basename "$f" .vst`
        n2=`awk -F " " -e '/entity/ {print $2}' "$f"`
        if [ $n1 != $n2 ]; then
            ln -s "$f" "$n2.vst"
        fi
    done
Comment 19 Luke Kenneth Casson Leighton 2021-04-14 13:05:53 BST
slightly messy however it is functional:

https://git.libre-soc.org/?p=soc-cocotb-sim.git;a=blob;f=ls180/post_pnr/cocotb/test_add_boundary.py;h=b518224664cd7c2ad4a2e2672aa05aac3a012a59;hb=HEAD#l177

this test uses experiments10_verilog post-P&R vst files (*cts*), running a JTAG boundary scan.
Comment 20 Luke Kenneth Casson Leighton 2021-04-19 19:58:00 BST
the code is written and functions, on both pre- and post-  JTAG tests can be run successfully.  several bugs found (and fixed)