Skip to content

Commit

Permalink
xilinx: Finishing vanilla makefile flow
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilKoe committed Feb 2, 2024
1 parent 499be08 commit 32854bb
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 299 deletions.
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ sw/deps/.patched
# Test models
target/sim/models

# VSIM generated files
# VSIM generated files
target/sim/vsim/compile.*.tcl
target/sim/vsim/*.log
target/sim/vsim/modelsim.ini
target/sim/vsim/transcript
target/sim/vsim/vsim.wlf
target/sim/vsim/work/

# Xilinx flow generated files
*.generated_env
*.generated_sha256

# Vivado generated files
*.cache
*.gen
*.hw
*.runs
*.xpr
*.xci
7 changes: 1 addition & 6 deletions Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ sources:
- target/sim/src/fixture_cheshire_soc.sv
- target/sim/src/tb_cheshire_soc.sv

- target: all(fpga, xilinx, xilinx_vanilla)
- target: all(fpga, xilinx, flavor_vanilla)
files:
- target/xilinx/flavor_vanilla/src/fan_ctrl.sv
- target/xilinx/flavor_vanilla/src/dram_wrapper_xilinx.sv
- target/xilinx/flavor_vanilla/src/phy_definitions.svh
- target/xilinx/flavor_vanilla/src/cheshire_top_xilinx.sv

- target: all(fpga, xilinx, xilinx_bd)
files:
- target/xilinx/flavor_bd/src/cheshire_ip_wrapper.v
- target/xilinx/flavor_bd/src/cheshire_top_xilinx.sv
2 changes: 1 addition & 1 deletion cheshire.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ chs-clean-deps:
######################

CHS_NONFREE_REMOTE ?= [email protected]:pulp-restricted/cheshire-nonfree.git
CHS_NONFREE_COMMIT ?= d31389c3b559e48496b7264a55ae33eda994bded
CHS_NONFREE_COMMIT ?= bb52c7ddb3f23e394054e340fdfae3929ebbb60c

chs-nonfree-init:
git clone $(CHS_NONFREE_REMOTE) $(CHS_ROOT)/nonfree
Expand Down
27 changes: 0 additions & 27 deletions sw/boot/cheshire_vcu128_bd.dts

This file was deleted.

3 changes: 2 additions & 1 deletion sw/sw.mk
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ $(CHS_CVA6_SDK_IMGS):
@echo "error: Missing CVA6 SDK images. Did you build your kernel?"
@exit 1


# Create full Linux disk image for a given board config
$(CHS_SW_DIR)/boot/linux-%.gpt.bin: $(CHS_SW_DIR)/boot/zsl.rom.bin $(CHS_SW_DIR)/boot/cheshire_%.dtb $(CHS_CVA6_SDK_IMGS)
$(CHS_SW_DIR)/boot/linux_%.gpt.bin: $(CHS_SW_DIR)/boot/zsl.rom.bin $(CHS_SW_DIR)/boot/%.dtb $(CHS_CVA6_SDK_IMGS)
truncate -s $(CHS_SW_DISK_SIZE) $@
sgdisk --clear -g --set-alignment=1 \
--new=1:64:96 --typecode=1:$(CHS_SW_ZSL_TGUID) \
Expand Down
16 changes: 10 additions & 6 deletions target/xilinx/flavor_vanilla/flavor_vanilla.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ xilinx_ips_paths_vanilla := $(foreach ip-name,$(xilinx_ips_names_vanil

# Flavor specific bender args
# (add the enabled ips in bender args, used by phy_definitions.svh)
xilinx_targs_vanilla := $(foreach ip-name,$(xilinx_ips_names_vanilla),$(addprefix -t ,$(ip-name)))
xilinx_targs_vanilla += -t xilinx_vanilla
xilinx_targs_vanilla := $(xilinx_targs_common) $(foreach ip-name,$(xilinx_ips_names_vanilla),$(addprefix -t ,$(ip-name)))
xilinx_targs_vanilla += -t flavor_vanilla

# Vivado variables
vivado_env_vanilla := \
Expand All @@ -48,15 +48,19 @@ vivado_env_vanilla := \

# Generate bender script
$(CHS_XIL_DIR)/flavor_vanilla/scripts/add_sources.tcl: Bender.yml
$(BENDER) script vivado $(xilinx_targs) $(xilinx_targs_vanilla) > $@
$(BENDER) script vivado $(xilinx_targs_vanilla) > $@

# Compile bitstream
$(CHS_XIL_DIR)/flavor_vanilla/out/%.bit: $(xilinx_ips_paths_vanilla) $(CHS_XIL_DIR)/flavor_vanilla/scripts/add_sources.tcl
@mkdir -p $(CHS_XIL_DIR)/flavor_vanilla/out
cd $(CHS_XIL_DIR)/flavor_vanilla && $(vivado_env) $(VIVADO) $(VIVADO_FLAGS) -source scripts/run.tcl
cd $(CHS_XIL_DIR)/flavor_vanilla && $(vivado_env_vanilla) $(VIVADO) $(VIVADO_FLAGS) -source scripts/run.tcl
find $(CHS_XIL_DIR)/flavor_vanilla -name "*.ltx" -o -name "*.bit" -o -name "*routed.rpt" | xargs -I {} cp {} $(CHS_XIL_DIR)/flavor_vanilla/out

chs-xil-clean-vanilla:
cd $(CHS_XIL_DIR)/flavor_vanilla && rm -rf scripts/add_sources.tcl* *.log *.jou *.str *.mif carfield.* .Xil/
cd $(CHS_XIL_DIR)/flavor_vanilla && rm -rf scripts/add_sources.tcl *.log *.jou cheshire.* .Xil/

.PHONY: chs-xil-clean-vanilla
.PHONY: chs-xil-clean-vanilla

# Add simulation rules to verify Xilinx IP integration

include $(CHS_XIL_DIR)/flavor_vanilla/sim/sim.mk
20 changes: 4 additions & 16 deletions target/xilinx/flavor_vanilla/sim/run_simulation.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,34 @@
# SPDX-License-Identifier: SHL-0.51
#
# Cyril Koenig <[email protected]>

source ../scripts/add_sources_vsim.tcl

source add_sources_vsim.tcl
if {[string first "xlnx_clk_wiz" $::env(IPS)] != -1} {
source ips/xlnx_clk_wiz/questa/compile.do

if {[string first "xlnx_vio" $::env(IPS)] != -1} {
source ips/xlnx_vio/questa/compile.do
}}

if {[string first "xlnx_mig_7_ddr3" $::env(IPS)] != -1} {
source ips/xlnx_mig_7_ddr3_ex/questa/compile.do
source ips/xlnx_mig_7_ddr3/questa/compile.do
vlog -work work -L xil_defaultlib -64 -incr -sv "./ips/xlnx_mig_7_ddr3_ex/questa/srcs/sim_tb_top.v"
vlog -work work ips/xlnx_mig_7_ddr3_ex/imports/sim_tb_top.v -L xil_defaultlib
}

if {[string first "xlnx_mig_ddr4" $::env(IPS)] != -1} {
source ips/xlnx_mig_ddr4_ex/questa/compile.do
source ips/xlnx_mig_ddr4/questa/compile.do
vlog -work work -L xil_defaultlib -64 -incr -sv "./ips/xlnx_mig_ddr4_ex/questa/srcs/sim_tb_top.sv"
vlog -work work ips/xlnx_mig_ddr4_ex/imports/sim_tb_top.sv -L xil_defaultlib
}

# Note : this testbench does not implenent the ddr4 memory model
## Note : this testbench does not implenent the ddr4 memory model
set TESTBENCH "work.sim_tb_top xil_defaultlib.glbl"

set XLIB_ARGS "-L secureip -L xpm -L unisims_ver -L unimacro_ver -L work -L xil_defaultlib"

if {![info exists VOPTARGS]} {
set VOPTARGS "+acc"
}

set flags "-permissive -suppress 3009 -suppress 8386 -error 7"

set pargs ""
if {[info exists BOOTMODE]} { append pargs "+BOOTMODE=${BOOTMODE} " }
if {[info exists PRELMODE]} { append pargs "+PRELMODE=${PRELMODE} " }
if {[info exists BINARY]} { append pargs "+BINARY=${BINARY} " }
if {[info exists IMAGE]} { append pargs "+IMAGE=${IMAGE} " }

eval "vsim ${TESTBENCH} -t 1ps -vopt -voptargs=\"${VOPTARGS}\"" ${XLIB_ARGS} ${pargs} ${flags}

set StdArithNoWarnings 1
set NumericStdNoWarnings 1
14 changes: 13 additions & 1 deletion target/xilinx/flavor_vanilla/sim/setup_simulation.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if { $argc == 1 } {
set command [lindex $argv 0]
}

puts "Running with SIMULATOR_PATH=$::env(SIMULATOR_PATH) ; GCC_PATH=$::env(GCC_PATH) ; XILINX_SIMLIB_PATH=$::env(XILINX_SIMLIB_PATH)"
puts "Running with SIMULATOR_PATH=$::env(SIMULATOR_PATH) ; GCC_PATH=$::env(GCC_PATH) ; XILINX_SIMLIB_PATH=$::env(XILINX_SIMLIB_PATH) ; VIVADO_PROJECT=$::env(VIVADO_PROJECT)"

# Compile the vivado simlib to XILINX_SIMLIB_PATH
if { $command == "compile_simlib" } {
Expand All @@ -26,6 +26,18 @@ if { $command == "compile_simlib" } {
export_simulation -simulator questa -directory "./ips" -lib_map_path "$::env(XILINX_SIMLIB_PATH)" \
-absolute_path -force -of_objects [get_ips *]

# Export simulation scripts for each ip
} elseif { $command == "export_example" } {
open_project $::env(VIVADO_PROJECT)
open_example_project -dir "./ips" -force [get_ips xlnx_mig_*]

# Export simulation scripts for each ip
} elseif { $command == "export_example_simulation" } {
open_project $::env(VIVADO_PROJECT)
export_simulation -lib_map_path "$::env(XILINX_SIMLIB_PATH)" -directory "." -simulator questa \
-ip_user_files_dir "./ips/$::env(DDR_EXAMPLE)/$::env(DDR_EXAMPLE).ip_user_files" \
-ipstatic_source_dir "./ips/$::env(DDR_EXAMPLE)/$::env(DDR_EXAMPLE).ip_user_files/ipstatic" -use_ip_compiled_libs -directory "./ips/$::env(DDR_EXAMPLE)/" -absolute_path

# Unknown command
} else {
puts "[$argv0] Unknown command: $command"
Expand Down
29 changes: 17 additions & 12 deletions target/xilinx/flavor_vanilla/sim/sim.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,55 @@ SIMULATOR_PATH ?= /usr/pack/questa-2022.3-bt/questasim/bin
GCC_PATH ?= /usr/pack/questa-2022.3-bt/questasim/gcc-7.4.0-linux_x86_64/bin

# Compile script for each IP model
chs-ip-sim-scripts := $(addsuffix /questa/compile.do, $(addprefix $(CHS_XIL_SIM_DIR)/ips/, $(ips-names)))
chs-ip-sim-scripts := $(addsuffix /questa/compile.do, $(addprefix $(CHS_XIL_SIM_DIR)/ips/, $(xilinx_ips_names_vanilla)))

# Getting the DDR model requires exporting the Vivado example project for the controller's IP
chs-ddr-example-project := $(filter xlnx_mig_,$(ips-names))_ex
chs-ddr-sim-script := $(CHS_XIL_SIM_DIR)/ips/$(chs-ddr-example-projects)/questa/compile.do
chs-ddr-example-name := $(filter xlnx_mig_%,$(xilinx_ips_names_vanilla))_ex
chs-ddr-sim-script := $(CHS_XIL_SIM_DIR)/ips/$(chs-ddr-example-name)/questa/compile.do

chs-vivado-env-sim := $(VIVADOENV) \
chs-vivado-env-sim := $(vivado_env_vanilla) \
XILINX_SIMLIB_PATH=$(XILINX_SIMLIB_PATH) \
SIMULATOR_PATH=$(SIMULATOR_PATH) \
GCC_PATH=$(GCC_PATH) \
VIVADO_PROJECT=$(CHS_XIL_DIR)/flavor_vanilla/chesire.xpr
VIVADO_PROJECT=$(CHS_XIL_DIR)/flavor_vanilla/cheshire.xpr

chs-xil-vlog-args := -suppress 2583 -suppress 13314

# First generate the generic Xilinx simulation libraries for questa
$(XILINX_SIMLIB_PATH)/modelsim.ini:
cd $(CHS_XIL_SIM_DIR) && $(VIVADOENV_SIM) vitis-2022.1 vivado -nojournal -mode batch -source setup_simulation.tcl -tclargs "compile_simlib"
cd $(CHS_XIL_SIM_DIR) && $(chs-vivado-env-sim) vitis-2022.1 vivado -nojournal -mode batch -source setup_simulation.tcl -tclargs "compile_simlib"

# Then generate the IP models for the project cheshire.xpr
$(CHS_XIL_SIM_DIR)/ips/%/questa/compile.do:
mkdir -p $(CHS_XIL_SIM_DIR)/ips
cd $(CHS_XIL_SIM_DIR) && $(VIVADOENV_SIM) $(VIVADO) -nojournal -mode batch -source setup_simulation.tcl -tclargs "export_simulation"
cd $(CHS_XIL_SIM_DIR) && $(chs-vivado-env-sim) $(VIVADO) -nojournal -mode batch -source setup_simulation.tcl -tclargs "export_simulation"

# Get the DRAM simulation models
$(CHS_XIL_SIM_DIR)/ips/%_ex/questa/compile.do:
mkdir -p $(CHS_XIL_SIM_DIR)/ips
# First create the example project
cd $(CHS_XIL_SIM_DIR) && $(chs-vivado-env-sim) $(VIVADO) -nojournal -mode batch -source setup_simulation.tcl -tclargs "export_example"
# Then export the simulation models
cd $(CHS_XIL_SIM_DIR) && $(chs-vivado-env-sim) VIVADO_PROJECT=$(CHS_XIL_SIM_DIR)/ips/$*_ex/$*_ex.xpr $(VIVADO) -nojournal -mode batch -source setup_simulation.tcl -tclargs "export_example_simulation"
cd $(CHS_XIL_SIM_DIR) && $(chs-vivado-env-sim) DDR_EXAMPLE=$(chs-ddr-example-name) VIVADO_PROJECT=$(CHS_XIL_SIM_DIR)/ips/$*_ex/$*_ex.xpr $(VIVADO) -nojournal -mode batch -source setup_simulation.tcl -tclargs "export_example_simulation"
# And replace the DUT by cheshire top
patch $(CHS_XIL_SIM_DIR)/ips/$*_ex/imports/sim_tb_top.sv $(CHS_XIL_SIM_DIR)/sim_tb_top.diff
cp $(CHS_XIL_SIM_DIR)/ips/$*_ex/imports/sim_tb_top.*v $(CHS_XIL_SIM_DIR)/ips/$*_ex/imports/sim_tb_top_copy.*v
patch $(CHS_XIL_SIM_DIR)/ips/$*_ex/imports/sim_tb_top.*v $(CHS_XIL_SIM_DIR)/sim_tb_top.diff

# Export the Cheshire questa compile script
$(CHS_XIL_SIM_DIR)/add_sources_vsim.tcl:
$(BENDER) script vsim -t sim -t test $(xilinx_targs) --vlog-arg="$(chs-xil-vlog-args)" > $@
$(BENDER) script vsim -t sim -t test $(xilinx_targs_vanilla) --vlog-arg="$(chs-xil-vlog-args)" > $@

# Run all
chs-xil-sim: $(CHS_XIL_DIR)/flavor_vanilla/cheshire.xpr $(XILINX_SIMLIB_PATH)/modelsim.ini $(chs-ddr-sim-script) $(chs-ip-sim-scripts) $(CHS_XIL_SIM_DIR)/add_sources_vsim.tcl
mkdir -p $(CHS_XIL_SIM_DIR)/questa_lib
cp $(XILINX_SIMLIB_PATH)/modelsim.ini $(CHS_XIL_SIM_DIR)
chmod +w $(CHS_XIL_SIM_DIR)/modelsim.ini
cd $(CHS_XIL_SIM_DIR) && IPS="$(ips-names)" questa-2022.3 vsim -work work -do "run_simulation.tcl"
cd $(CHS_XIL_SIM_DIR) && IPS="$(xilinx_ips_names_vanilla)" questa-2022.3 vsim -work work -do "run_simulation.tcl"

testt:
echo $(filter xlnx_mig_%,$(xilinx_ips_names_vanilla))_ex

chs-xil-clean-sim:
cd $(CHS_XIL_SIM_DIR) && rm -rf *.log questa_lib work transcript vsim.wlf vsim_cheshire.tcl .Xil modelsim.ini
cd $(CHS_XIL_SIM_DIR) && rm -rf *.log questa_lib work transcript vsim.wlf vsim_cheshire.tcl .Xil modelsim.ini ips

.PHONY: clean-sim sim
107 changes: 107 additions & 0 deletions target/xilinx/flavor_vanilla/sim/sim_tb_top.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
437,438c437,463
< example_top #
< (
---
> wire cpu_reset;
> wire cpu_resetn;
> `ifdef TARGET_XLNX_MIG_DDR4
> wire sys_clk_p;
> wire sys_clk_n;
> `endif
> wire testmode_i;
> wire [1:0] boot_mode_i;
> wire jtag_tck_i;
> wire jtag_tms_i;
> wire jtag_tdi_i;
> wire jtag_tdo_o;
> wire jtag_trst_ni;
> wire jtag_vdd_o;
> wire jtag_gnd_o;
> wire uart_tx_o;
> wire uart_rx_i;
>
> assign cpu_reset = sys_rst;
> assign cpu_resetn = ~cpu_reset;
> assign boot_mode_i = '0;
> assign testmode_i = '0;
> assign jtag_tck_i = '0;
> assign jtag_tms_i = '0;
> assign jtag_tdi_i = '0;
> assign jtag_trst_ni = '0;
> assign uart_rx_i = '0;
440,443c465,468
< .SIMULATION (SIMULATION),
< .BEGIN_ADDRESS (BEGIN_ADDRESS),
< .END_ADDRESS (END_ADDRESS),
< .PRBS_EADDR_MASK_POS (PRBS_EADDR_MASK_POS),
---
> `ifdef TARGET_XLNX_MIG_DDR4
> assign sys_clk_p = c0_sys_clk_p;
> assign sys_clk_n = c0_sys_clk_n;
> `endif
445,457d469
< .COL_WIDTH (COL_WIDTH),
< .CS_WIDTH (CS_WIDTH),
< .DM_WIDTH (DM_WIDTH),
<
< .DQ_WIDTH (DQ_WIDTH),
< .DQS_CNT_WIDTH (DQS_CNT_WIDTH),
< .DRAM_WIDTH (DRAM_WIDTH),
< .ECC_TEST (ECC_TEST),
< .RANKS (RANKS),
< .ROW_WIDTH (ROW_WIDTH),
< .ADDR_WIDTH (ADDR_WIDTH),
< .BURST_MODE (BURST_MODE),
< .TCQ (TCQ),
459,473c471,472
<
< .DRAM_TYPE (DRAM_TYPE),
<
<
< .nCK_PER_CLK (nCK_PER_CLK),
<
<
< .C_S_AXI_ID_WIDTH (C_S_AXI_ID_WIDTH),
< .C_S_AXI_ADDR_WIDTH (C_S_AXI_ADDR_WIDTH),
< .C_S_AXI_DATA_WIDTH (C_S_AXI_DATA_WIDTH),
< .C_S_AXI_SUPPORTS_NARROW_BURST (C_S_AXI_SUPPORTS_NARROW_BURST),
<
< .DEBUG_PORT (DEBUG_PORT),
<
< .RST_ACT_LOW (RST_ACT_LOW)
---
> cheshire_top_xilinx #
> (
475c474
< u_ip_top
---
> u_cheshire_top_xilinx
477,502c476
<
< .ddr3_dq (ddr3_dq_fpga),
< .ddr3_dqs_n (ddr3_dqs_n_fpga),
< .ddr3_dqs_p (ddr3_dqs_p_fpga),
<
< .ddr3_addr (ddr3_addr_fpga),
< .ddr3_ba (ddr3_ba_fpga),
< .ddr3_ras_n (ddr3_ras_n_fpga),
< .ddr3_cas_n (ddr3_cas_n_fpga),
< .ddr3_we_n (ddr3_we_n_fpga),
< .ddr3_reset_n (ddr3_reset_n),
< .ddr3_ck_p (ddr3_ck_p_fpga),
< .ddr3_ck_n (ddr3_ck_n_fpga),
< .ddr3_cke (ddr3_cke_fpga),
< .ddr3_cs_n (ddr3_cs_n_fpga),
<
< .ddr3_dm (ddr3_dm_fpga),
<
< .ddr3_odt (ddr3_odt_fpga),
<
<
< .sys_clk_i (sys_clk_i),
<
< .init_calib_complete (init_calib_complete),
< .tg_compare_error (tg_compare_error),
< .sys_rst (sys_rst)
---
> .*
Loading

0 comments on commit 32854bb

Please sign in to comment.