Bug 620 - post-layout simulation needed using cocotb
Summary: post-layout simulation needed using cocotb
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
Depends on:
Blocks: 199
  Show dependency treegraph
Reported: 2021-03-29 13:32 BST by Luke Kenneth Casson Leighton
Modified: 2022-06-28 13:22 BST (History)
2 users (show)

See Also:
NLnet milestone: NLNet.2019.02.029.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, paid = 2021-05-01 } staf = { amount = 1250, submitted = 2021-04-21, paid=2021-04-21}


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:

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:

Usage can be seen in readme file:

Update by `git pull` in soc and doing `make gitupdate`; then go to
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




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

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

cxxsim bug, but there's a workaround: use "memory" pass before
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';
        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:

Comment 18 Staf Verhaegen 2021-04-12 11:30:42 BST
I am currently using a script (ln_vst.sh) to link vst files:

    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"
Comment 19 Luke Kenneth Casson Leighton 2021-04-14 13:05:53 BST
slightly messy however it is functional:


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)