Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 17 additions & 2 deletions cheshire.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ BENDER ?= bender
VLOGAN ?= vlogan

# Caution: Questasim requires this to point to the *actual* compiler install path
CXX_PATH := $(shell which $(CXX))
# If Make has been started from WSL, search Windows compiler,
# take first occurrence and replace '\' in path with '/'.
ifeq ($(strip $(WSL_DISTRO_NAME)),)
CXX_PATH := $(shell which $(CXX))
else
CXX_PATH := $(shell cmd.exe /c "where $(CXX)" | tr -d '\r' | head -n 1 | sed 's|\\|/|g')
endif

VLOG_ARGS ?= -suppress 2583 -suppress 13314 -timescale 1ns/1ps
VLOGAN_ARGS ?= -kdb -nc -assert svaext +v2k -timescale=1ns/1ps
Expand Down Expand Up @@ -146,10 +152,19 @@ CHS_BOOTROM_ALL += $(CHS_ROOT)/hw/bootrom/cheshire_bootrom.sv $(CHS_ROOT)/hw/boo
##############
# Simulation #
##############
ifneq ($(strip $(WSL_DISTRO_NAME)),)
CHS_ROOT_OS_SPECIFIC := $(shell wslpath -m $(realpath $(CHS_ROOT)))
else
CHS_ROOT_OS_SPECIFIC := $(realpath $(CHS_ROOT))
endif

$(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl: $(CHS_ROOT)/Bender.yml
$(BENDER) script vsim -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOG_ARGS)" > $@
echo 'vlog "$(realpath $(CHS_ROOT))/target/sim/src/elfloader.cpp" -ccflags "-std=c++11" -cpppath "$(CXX_PATH)"' >> $@
ifneq ($(strip $(WSL_DISTRO_NAME)),)
# If run from WSL, replace pattern like "/c/..." with "c:/..."
sed -i -E 's|(set ROOT ")/([a-zA-Z])/(.*)"|\1\2:/\3"|g' $@
endif
echo 'vlog "$(CHS_ROOT_OS_SPECIFIC)/target/sim/src/elfloader.cpp" -ccflags "-std=c++11" -cpppath "$(CXX_PATH)"' >> $@

$(CHS_ROOT)/target/sim/vcs/compile.cheshire_soc.sh: $(CHS_ROOT)/Bender.yml
$(BENDER) script vcs -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOGAN_ARGS)" --vlogan-bin="$(VLOGAN)" > $@
Expand Down
11 changes: 10 additions & 1 deletion target/sim/vsim/start.cheshire_soc.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ if { ![info exists CXX_PATH] } {
set CXX $::env(CXX)
}
}
set CXX_PATH [exec which $CXX]

# Cross-platform search g++, where '\' replaced with '/'
if {[string equal $tcl_platform(platform) "windows"]} {
set raw_path [exec cmd.exe /c "where $CXX"]
set lines [split $raw_path "\n"]
set first_line [string trim [lindex $lines 0]]
set CXX_PATH [string map {\\ /} $first_line]
} else {
set CXX_PATH [exec which $CXX]
}
}

# Set voptargs only if not already set to make overridable.
Expand Down
1 change: 0 additions & 1 deletion target/xilinx/scripts/impl_ip.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,3 @@ wait_on_run ${proj}_synth_1

# Symlink proj for easy access and build tracking, ensuring its update
file delete -force ${project_root}/out.xci
file link -symbolic ${project_root}/out.xci $xci
Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Windows, Vivado can't create symbolic links (hard links only).
Because of that, symlink creation moved to xilinx.mk

12 changes: 11 additions & 1 deletion target/xilinx/scripts/impl_sys.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ source ${xilinx_root}/scripts/common.tcl
init_impl $xilinx_root $argc $argv

# Addtional args provide IPs
read_ip [exec realpath {*}[lrange $argv 2 end]]
# Despite info provided by help, Vivado can't read_ip with multiple args
# on Windows. Because of that this script read_ip one by one.
set ip_paths {}
foreach arg [lrange $argv 2 end] {
lappend ip_paths [file normalize $arg]
}

foreach ip $ip_paths {
puts "Reading IP: $ip"
read_ip $ip
}

# Load constraints
import_files -fileset constrs_1 -norecurse ${xilinx_root}/constraints/${proj}.xdc
Expand Down
40 changes: 36 additions & 4 deletions target/xilinx/xilinx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@ CHS_XILINX_DIR ?= $(CHS_ROOT)/target/xilinx
$(CHS_XILINX_DIR)/build/%/:
mkdir -p $@

BOARD_AND_IP = $(subst ., ,$*)
IP = $(word 2,$(BOARD_AND_IP))
IP_SUFFIX = .srcs/sources_1/ip/$(IP)
IP_XCI_PATH = $(IP)$(IP_SUFFIX)/$(IP).xci

# We split the stem into a board and an IP and resolve dependencies accordingly
$(CHS_XILINX_DIR)/build/%/out.xci: \
$(CHS_XILINX_DIR)/scripts/impl_ip.tcl \
$$(wildcard $(CHS_XILINX_DIR)/src/ips/$$*.prj) \
| $(CHS_XILINX_DIR)/build/%/
@rm -f $(CHS_XILINX_DIR)/build/$(*)*.log $(CHS_XILINX_DIR)/build/$(*)*.jou
cd $| && $(VIVADO) -mode batch -log ../$*.log -jou ../$*.jou -source $< -tclargs $(subst ., ,$*)
cd $| && { \
IMPL_TCL="$<"; \
if [ -n "$$WSL_DISTRO_NAME" ]; then \
IMPL_TCL=$$(wslpath -m $$IMPL_TCL); \
fi; \
$(VIVADO) -mode batch -log ../$*.log -jou ../$*.jou \
-source $$IMPL_TCL -tclargs $(BOARD_AND_IP); \
ln -s $(@D)/$(IP_XCI_PATH) $(@D)/out.xci; \
}

##############
# Bitstreams #
Expand All @@ -42,7 +55,13 @@ CHS_XILINX_IPS_vcu128 := clkwiz vio ddr4

$(CHS_XILINX_DIR)/scripts/add_sources.%.tcl: $(CHS_ROOT)/Bender.yml
$(BENDER) script vivado -t fpga -t $* $(CHS_BENDER_RTL_FLAGS) > $@
ifneq ($(strip $(WSL_DISTRO_NAME)),)
# If run from WSL, replace pattern like "/c/..." with "c:/..."
sed -i -E 's|(set ROOT ")/([a-zA-Z])/(.*)"|\1\2:/\3"|g' $@
endif

# wslpath can't work with multiple path at once, so we need to process them in
# a loop.
define chs_xilinx_bit_rule
$$(CHS_XILINX_DIR)/out/%.$(1).bit: \
$$(CHS_XILINX_DIR)/scripts/impl_sys.tcl \
Expand All @@ -51,9 +70,22 @@ $$(CHS_XILINX_DIR)/out/%.$(1).bit: \
$$(CHS_HW_ALL) \
| $$(CHS_XILINX_DIR)/build/$(1).%/
@rm -f $$(CHS_XILINX_DIR)/build/$$*.$(1)*.log $$(CHS_XILINX_DIR)/build/$$*.$(1)*.jou
cd $$| && $$(VIVADO) -mode batch -log ../$$*.$(1).log -jou ../$$*.$(1).jou -source $$< \
-tclargs $(1) $$* $$(CHS_XILINX_IPS_$(1):%=$$(CHS_XILINX_DIR)/build/$(1).%/out.xci)

cd $$| && { \
IMPL_TCL=$$<; \
if [ -n "$$$$WSL_DISTRO_NAME" ]; then \
IMPL_TCL=$$$$(wslpath -m $$$$IMPL_TCL); \
XCI_LIST="$(CHS_XILINX_IPS_$(1):%=$(CHS_XILINX_DIR)/build/$(1).%/out.xci)";\
XCI_LIST_PROCESSED=""; \
for f in $$$$XCI_LIST; do \
XCI_LIST_PROCESSED="$$$$XCI_LIST_PROCESSED $$$$(wslpath -m $$$$f)"; \
done; \
else \
XCI_LIST_PROCESSED="$$$$XCI_LIST"; \
fi; \
echo $$$$XCI_LIST_PROCESSED; \
$$(VIVADO) -mode batch -log ../$$*.$(1).log -jou ../$$*.$(1).jou -source \
$$$$IMPL_TCL -tclargs $(1) $$* $$$$XCI_LIST_PROCESSED; \
}
CHS_PHONY += chs-xilinx-$(1)
chs-xilinx-$(1): $$(CHS_XILINX_DIR)/out/cheshire.$(1).bit
endef
Expand Down