Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 /c/Windows/System32/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

20 changes: 19 additions & 1 deletion target/xilinx/scripts/impl_sys.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ set xilinx_root [file dirname [file dirname [file normalize [info script]]]]
source ${xilinx_root}/scripts/common.tcl
init_impl $xilinx_root $argc $argv

# Cross-platform Tcl implementation of the realpath utility.
# Unlike a simple call to `normalize`, this function not only converts
# a path to an absolute path, but also resolves symbolic links.
proc realpath_tcl {path} {
set p [file normalize $path]

while {[file type $p] eq "link"} {
set p [file normalize [file readlink $p]]
}

return $p
}

# Addtional args provide IPs
read_ip [exec realpath {*}[lrange $argv 2 end]]
set ip_paths {}
foreach arg [lrange $argv 2 end] {
lappend ip_paths [realpath_tcl $arg]
}
puts [list read_ip $ip_paths]
read_ip $ip_paths

# Load constraints
import_files -fileset constrs_1 -norecurse ${xilinx_root}/constraints/${proj}.xdc
Expand Down
29 changes: 26 additions & 3 deletions target/xilinx/xilinx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,32 @@ 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

ifneq ($(strip $(WSL_DISTRO_NAME)),)
define PLATFORM_PATH
$(shell wslpath -m $(1))
endef
else
define PLATFORM_PATH
$(1)
endef
endif

# 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 $| && { \
$(VIVADO) -mode batch -log ../$*.log -jou ../$*.jou \
-source $(call PLATFORM_PATH,$<) -tclargs $(BOARD_AND_IP); \
ln -s $(@D)/$(IP_XCI_PATH) $(@D)/out.xci; \
}

##############
# Bitstreams #
Expand All @@ -42,6 +61,10 @@ 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

define chs_xilinx_bit_rule
$$(CHS_XILINX_DIR)/out/%.$(1).bit: \
Expand All @@ -51,8 +74,8 @@ $$(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 $$| && $$(VIVADO) -mode batch -log ../$$*.$(1).log -jou ../$$*.$(1).jou -source $$(call PLATFORM_PATH,$$<) \
-tclargs $(1) $$* $$(foreach ip,$$(CHS_XILINX_IPS_$(1)),$$(call PLATFORM_PATH,$$(CHS_XILINX_DIR)/build/$(1).$$(ip)/out.xci))

CHS_PHONY += chs-xilinx-$(1)
chs-xilinx-$(1): $$(CHS_XILINX_DIR)/out/cheshire.$(1).bit
Expand Down