Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPGA prototyping platform VCS simulation #871

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
036f429
Adding a new config for Arty simulation.
Mar 15, 2021
ece1ca4
Don't tie off success IO in the harness when using sim serial. Not a …
Mar 15, 2021
bff86e2
First pass at using an Arty-specific TestDriver. Done in a kludgy way…
Mar 31, 2021
254f0c7
Adding ArtyTestDriver in the easiest place to avoid circular dependen…
Apr 1, 2021
193d55c
Small changes to ArtyTestDriver.
Apr 19, 2021
bf0225f
Makefile includes sim-fpga target that goes up to compiling vivado si…
Apr 20, 2021
1ad47a5
Make rule to generate additional VCS sim collateral. Now ready to add…
Apr 22, 2021
975d6c0
More collateral generation.
Apr 23, 2021
14f464a
Have Vivado generate list of System C files.
Apr 23, 2021
634ab89
Now have make target for building the simulation binary. Same problem…
Apr 29, 2021
96c45e8
Removed TestDriver from old location, which didn't work due to circul…
Apr 30, 2021
badbc0a
Addressed spacing issues, default sim_name, and SerialTLKey comments …
May 5, 2021
eba846c
Small fix to sim_name assignment, as it is already defined.
May 5, 2021
6156c7e
Adding makefile variable for vivado version, to be used in a version …
May 5, 2021
a28e846
Less hacky project creation .tcl script.
May 5, 2021
7cbc4ee
Fix ordering of config fragments.
May 5, 2021
03f8fde
Tie off success if no TL serial
May 7, 2021
6dc0d4b
Fixed floating success in testharness.
Jul 13, 2021
54b4ebc
debugging sim peripheral reset harnessbinder
Sep 21, 2021
b2f5d89
cleaned up binder
Sep 21, 2021
9a41942
Fixing binder ordering in config.
Oct 10, 2021
863e2d9
Making reset active low in Arty test driver to match the active low r…
Oct 10, 2021
9b0f10f
Setting SRST_n (JTAG reset, active low) to true by default. Arty rese…
Oct 11, 2021
dff7d2c
Making VCS run in debug mode in sim-fpga make target.
Oct 11, 2021
e45f82d
Merging dev into arty-sim to synchronize.
Oct 14, 2021
2bcc78a
Cleanup.
Oct 15, 2021
8f48540
Comments.
Oct 15, 2021
c2d00ae
Parameterizing testbench in sim flow
Oct 19, 2021
7c55be1
Merge branch 'dev' into arty-sim
Jan 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 98 additions & 2 deletions fpga/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ sim_name := none
#########################################################################################
# include shared variables
#########################################################################################

VIVADO_VERSION := $(shell vivado -version | head -1 | grep -o -P '(?<=\s).*(?=\s)')
Copy link
Contributor

@abejgonzalez abejgonzalez May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Vivado isn't on the path this pollutes the terminal output. Maybe pipe stderr to /dev/null. Also, where is this checked/used?


SUB_PROJECT ?= vcu118

ifeq ($(SUB_PROJECT),vcu118)
Expand Down Expand Up @@ -56,7 +59,25 @@ ifeq ($(SUB_PROJECT),arty)
TB ?= none # unused
TOP ?= ChipTop
BOARD ?= arty
FPGA_FAMILY ?= kintex7
FPGA_BRAND ?= xilinx
endif

ifeq ($(SUB_PROJECT),artysim)
# TODO: Fix with Arty
SBT_PROJECT ?= fpga_platforms
MODEL ?= ArtyFPGATestHarness
VLOG_MODEL ?= ArtyFPGATestHarness
MODEL_PACKAGE ?= chipyard.fpga.arty
CONFIG ?= TinyRocketArtySimConfig
CONFIG_PACKAGE ?= chipyard.fpga.arty
GENERATOR_PACKAGE ?= chipyard
TB ?= ArtyTestDriver
TOP ?= ChipTop
BOARD ?= arty
FPGA_FAMILY ?= kintex7
FPGA_BRAND ?= xilinx
sim_name = arty
endif

include $(base_dir)/variables.mk
Expand All @@ -77,7 +98,8 @@ fpga_common_script_dir := $(fpga_dir)/common/tcl
# setup misc. sim files
#########################################################################################
SIM_FILE_REQS += \
$(ROCKETCHIP_RSRCS_DIR)/vsrc/EICG_wrapper.v
$(ROCKETCHIP_RSRCS_DIR)/vsrc/EICG_wrapper.v \
$(base_dir)/generators/chipyard/src/main/resources/vsrc/ArtyTestDriver.v

# copy files but ignore *.h files in *.f (match vcs)
$(sim_files): $(SIM_FILE_REQS) | $(build_dir)
Expand Down Expand Up @@ -118,7 +140,7 @@ $(BIT_FILE): $(synth_list_f)
-tclargs \
-top-module "$(MODEL)" \
-F "$(synth_list_f)" \
-board "$(BOARD)" \
-board "$(BOARD)" \
-ip-vivado-tcls "$(shell find '$(build_dir)' -name '*.vivado.tcl')"

.PHONY: bitstream
Expand All @@ -135,6 +157,80 @@ debug-bitstream: $(build_dir)/obj/post_synth.dcp
$(build_dir)/debug_obj \
$(fpga_common_script_dir)

#########################################################################################
# sim rules
#########################################################################################

project-creation-script := $(sim_dir)/scripts/create_project.tcl

# generate the vivado project and add all sources
vivado-project := $(build_dir)/$(MODEL).xpr
$(vivado-project): $(synth_list_f) $(project-creation-script)
cd $(build_dir); vivado \
-nojournal -mode batch \
-source $(project-creation-script) \
-tclargs \
-top-module "$(MODEL)" \
-F "$(synth_list_f)" \
-ip-vivado-tcls "$(shell find '$(build_dir)' -name '*.vivado.tcl')" \
-board "$(BOARD)"

# generate vcs collateral
vivado-vcs-collateral := $(build_dir)/$(MODEL).cache/compile_simlib/synopsys_sim.setup
$(vivado-vcs-collateral): $(sim_dir)/scripts/generate_vcs_collateral.tcl $(vivado-project)
cd $(build_dir); vivado $(vivado-project) \
-nojournal -mode batch \
-source $(sim_dir)/scripts/generate_vcs_collateral.tcl \
-tclargs \
$(FPGA_FAMILY) \
abejgonzalez marked this conversation as resolved.
Show resolved Hide resolved
$(build_dir) \
$(MODEL) \
$(TB)

include $(base_dir)/vcs.mk

sim_prefix = simv
sim = $(build_dir)/$(sim_prefix)-$(MODEL_PACKAGE)-$(CONFIG)

fpga_sim_verilog_sources = $(build_dir)/fpga_sim_verilog_sources.f
fpga_sim_vhdl_sources = $(build_dir)/fpga_sim_vhdl_sources.f
fpga_sim_cc_sources = $(build_dir)/fpga_sim_cc_sources.f

xilinx_lib = xil_defaultlib

VCS = vcs -full64
VLOGAN = vlogan -full64
VHDLAN = vhdlan -full64

# todo: deduplication between this and other VCS sim makefile
VLOGAN_OPTS = \
-notice \
-line \
+lint=all,noVCDE,noONGS,noUI \
-error=PCWM-L \
-error=noZMMCM \
-timescale=1ns/10ps \
-quiet \
-q \
+rad \
+vcs+lic+wait \
+vc+list \
-sverilog +systemverilogext+.sv+.svi+.svh+.svt -assert svaext +libext+.sv \
+v2k +verilog2001ext+.v95+.vt+.vp +libext+.v \
-debug_pp \
+incdir+$(build_dir) \
$(PREPROC_DEFINES)

# vcs-mx flow
$(sim): $(vivado-vcs-collateral)
mkdir -p $(build_dir)/vcs_lib/xil_defaultlib
cd $(build_dir); $(VHDLAN) -work $(xilinx_lib) -f $(fpga_sim_vhdl_sources) -l vhdlan.log
cd $(build_dir); $(VLOGAN) $(VLOGAN_OPTS) +define+DEBUG -work $(xilinx_lib) -f $(fpga_sim_verilog_sources) -l vlogan.log
cd $(build_dir); $(VCS) $(VCS_CC_OPTS) $(xilinx_lib).$(TB) $(xilinx_lib).glbl -file $(fpga_sim_cc_sources) -o $@ -Mdir=$(build_dir)/$(long_name) -l vcs.log -debug_access+all

.PHONY: sim-fpga
sim-fpga: $(sim)

#########################################################################################
# general cleanup rules
#########################################################################################
Expand Down
9 changes: 9 additions & 0 deletions fpga/scripts/create_project.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set the variable for the directory that includes all scripts

set scriptdir [file join [file dirname [info script]] "../fpga-shells/xilinx/common/tcl"]

# Set up variables and Vivado objects
source [file join $scriptdir "prologue.tcl"]

# Initialize Vivado project files
source [file join $scriptdir "init.tcl"]
34 changes: 34 additions & 0 deletions fpga/scripts/generate_vcs_collateral.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#### Command line arguments to this script
# argv[0] = fpga family
# argv[1] = build directory
# argv[2] = chipyard model definition
# argv[3] = test driver

set family [lindex $argv 0]
set build_dir [lindex $argv 1]
set model [lindex $argv 2]
set tb [lindex $argv 3]

# compile the simulation libraries for vcs
compile_simlib -directory $build_dir/$model.cache/compile_simlib -family $family -simulator vcs_mx -library all
# set the top level of the design
set_property top $tb [current_fileset -simset]
# generate other vcs simulation collateral
export_simulation -force -simulator vcs -ip_user_files_dir $build_dir/$model.ip_user_files -lib_map_path $build_dir/$model.cache/compile_simlib -use_ip_compiled_libs -directory $build_dir/export_sim
# Add vivado library mapping to synopsys_sim.setup file
set synopsys_libraries [open $build_dir/synopsys_sim.setup a]
puts $synopsys_libraries "xil_defaultlib : vcs_lib/xil_defaultlib"
close $synopsys_libraries
# generate separate lists of verilog, vhdl, and cc sim sources
set fpga_sim_verilog_sources [open $build_dir/fpga_sim_verilog_sources.f w]
foreach source [get_files -compile_order sources -used_in simulation -filter {FILE_TYPE == Verilog}] {puts $fpga_sim_verilog_sources $source}
foreach source [get_files -compile_order sources -used_in simulation -filter {FILE_TYPE == SystemVerilog}] {puts $fpga_sim_verilog_sources $source}
# add vivado's glbl.v
puts $fpga_sim_verilog_sources $build_dir/export_sim/vcs/glbl.v
close $fpga_sim_verilog_sources
set fpga_sim_vhdl_sources [open $build_dir/fpga_sim_vhdl_sources.f w]
foreach source [get_files -compile_order sources -used_in simulation -filter {FILE_TYPE == VHDL}] {puts $fpga_sim_vhdl_sources $source}
close $fpga_sim_vhdl_sources
set fpga_sim_cc_sources [open $build_dir/fpga_sim_cc_sources.f w]
foreach source [get_files *.cc] {puts $fpga_sim_cc_sources $source}
close $fpga_sim_cc_sources
7 changes: 7 additions & 0 deletions fpga/src/main/scala/arty/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ class WithArtyTweaks extends Config(
class TinyRocketArtyConfig extends Config(
new WithArtyTweaks ++
new chipyard.TinyRocketConfig)

class TinyRocketArtySimConfig extends Config(
new WithFPGASimSerial ++
new testchipip.WithDefaultSerialTL ++
new chipyard.harness.WithSimSerial ++
new chipyard.harness.WithTiedOffDebug ++
new TinyRocketArtyConfig)
// DOC include end: AbstractArty and Rocket
43 changes: 41 additions & 2 deletions fpga/src/main/scala/arty/HarnessBinders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ import sifive.fpgashells.ip.xilinx.{IBUFG, IOBUF, PULLUP, PowerOnResetFPGAOnly}
import chipyard.harness.{ComposeHarnessBinder, OverrideHarnessBinder}
import chipyard.iobinders.JTAGChipIO

import testchipip._

import chisel3.util._
import chisel3.experimental.IO
import freechips.rocketchip.config.{Parameters, Field}
import freechips.rocketchip.subsystem._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.devices.debug.HasPeripheryDebug
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.util._
import freechips.rocketchip.prci.{ClockSinkDomain}
import scala.math.min

class WithArtyResetHarnessBinder extends ComposeHarnessBinder({
(system: HasPeripheryDebugModuleImp, th: ArtyFPGATestHarness, ports: Seq[Bool]) => {
require(ports.size == 2)

withClockAndReset(th.clock_32MHz, th.ck_rst) {
withClockAndReset(th.clock_32MHz, th.hReset) {
// Debug module reset
th.dut_ndreset := ports(0)

Expand All @@ -29,6 +42,32 @@ class WithArtyResetHarnessBinder extends ComposeHarnessBinder({
}
})

class WithFPGASimSerial extends OverrideHarnessBinder({
(system: CanHavePeripheryTLSerial, th: ArtyFPGATestHarness, ports: Seq[ClockedIO[SerialIO]]) => {
// This binder is the main difference between FPGA and Chipyard simulation.
// For FPGA sim, we want to wire the output of the Xilinx reset IP to
// the sim ram and serial modules, rather than connect the harness reset
// directly.
implicit val p = chipyard.iobinders.GetSystemParameters(system)
ports.map({ port =>
val bits = SerialAdapter.asyncQueue(port, th.buildtopClock, th.buildtopReset)
withClockAndReset(th.buildtopClock, th.buildtopReset.asBool) {
val ram = SerialAdapter.connectHarnessRAM(system.serdesser.get, bits, th.buildtopReset.asBool)

val success = {
val sim = Module(new SimSerial(ram.module.io.tsi_ser.w))
sim.io.clock := port.clock
sim.io.reset := th.buildtopReset.asBool
sim.io.serial <> ram.module.io.tsi_ser
sim.io.exit
}

when (success) { th.success := true.B }
}
})
}
})

class WithArtyJTAGHarnessBinder extends OverrideHarnessBinder({
(system: HasPeripheryDebug, th: ArtyFPGATestHarness, ports: Seq[Data]) => {
ports.map {
Expand Down Expand Up @@ -71,7 +110,7 @@ class WithArtyJTAGHarnessBinder extends OverrideHarnessBinder({

class WithArtyUARTHarnessBinder extends OverrideHarnessBinder({
(system: HasPeripheryUARTModuleImp, th: ArtyFPGATestHarness, ports: Seq[UARTPortIO]) => {
withClockAndReset(th.clock_32MHz, th.ck_rst) {
withClockAndReset(th.clock_32MHz, th.hReset) {
IOBUF(th.uart_rxd_out, ports.head.txd)
ports.head.rxd := IOBUF(th.uart_txd_in)
}
Expand Down
18 changes: 14 additions & 4 deletions fpga/src/main/scala/arty/TestHarness.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import chipyard.{BuildTop, HasHarnessSignalReferences}
import chipyard.harness.{ApplyHarnessBinders}
import chipyard.iobinders.{HasIOBinders}

import testchipip.{SerialTLKey}

class ArtyFPGATestHarness(override implicit val p: Parameters) extends ArtyShell with HasHarnessSignalReferences {

val lazyDut = LazyModule(p(BuildTop)(p)).suggestName("chiptop")
Expand All @@ -22,16 +24,24 @@ class ArtyFPGATestHarness(override implicit val p: Parameters) extends ArtyShell
val dReset = Wire(AsyncReset())
dReset := reset_core.asAsyncReset

// default to 32MHz clock
// Default to 32MHz clock
withClockAndReset(clock_32MHz, hReset) {
val dut = Module(lazyDut.module)
}

val buildtopClock = clock_32MHz
val buildtopReset = hReset
val success = false.B
// Set SRST_n (JTAG reset, active-low) to true unless overridden in the JTAG
// harness binder. This is necessary because the Xilinx reset IP depends on it
// in fpga-shells, and the simulation config does not include JTAG.
SRST_n := true.B

val buildtopClock = clock_32MHz
val buildtopReset = dReset
val dutReset = dReset
val success = IO(Output(Bool()))

// This will be overridden by the WithFPGASimSerial harness binder to set
// success to the output of the sim serial module.
success := false.B

// must be after HasHarnessSignalReferences assignments
lazyDut match { case d: HasIOBinders =>
Expand Down
Loading