1
- SHELL = bash
2
-
1
+ # Source and target files/directories
2
+ project = $(shell grep object build.sc |grep -v extends |sed s/object//g |xargs)
3
+ scala_files = $(wildcard src/main/scala/* .scala)
3
4
generated_files = generated
5
+ BUILDTOOL ?= sbt # Can also be mill
4
6
5
7
# Define the SBT command (Docker or local)
6
8
DOCKERARGS = run --rm -v $(PWD ) :/src -w /src
@@ -20,16 +22,30 @@ YOSYS = docker $(DOCKERARGS) hdlc/yosys yosys
20
22
21
23
# Default board PLL
22
24
BOARD := bypass
25
+ BOARDPARAMS =-board ${BOARD} -cpufreq 50000000 -invreset false
26
+ CHISELPARAMS = --target:fpga -td $(generated_files ) --emission-options=disableMemRandomization,disableRegisterRandomization
23
27
24
28
# Targets
25
- chisel : check-board-vars clean # # Generates Verilog code from Chisel sources using SBT
26
- ${SBT} " run --target:fpga -board ${BOARD} -cpufreq 50000000 -td $( generated_files) -invreset false"
29
+ chisel : $(generated_files ) # # Generates Verilog code from Chisel sources using SBT
27
30
28
- rvfi : clean # # Generates Verilog code for RISC-V Formal tests
29
- ${SBT} " runMain chiselv.RVFITop"
31
+ $(generated_files ) : $(scala_files ) build.sbt
32
+ @rm -rf $(generated_files )
33
+ @test " $( BOARD) " ! = " bypass" || (echo " Set BOARD variable to one of the supported boards: " ; test -f chiselv.core && cat chiselv.core| grep " \-board" | cut -d ' -' -f 2| sed s/\" //g | sed s/board\ //g | tr -s ' \n' ' ,' | sed ' s/,$$/\n/' ; echo " Eg. make chisel BOARD=ulx3s" ; echo ; echo " Generating design with bypass PLL..." ; echo)
34
+ @if [ $( BUILDTOOL) = " sbt" ]; then \
35
+ ${SBT} " run $( CHISELPARAMS) $( BOARDPARAMS) " ; \
36
+ elif [ $(BUILDTOOL) = "mill" ]; then \
37
+ scripts/mill $(project).run $(CHISELPARAMS) $(BOARDPARAMS); \
38
+ fi
30
39
31
40
chisel_tests :
32
- ${SBT} " test"
41
+ @if [ $( BUILDTOOL) = " sbt" ]; then \
42
+ ${SBT} " test" ; \
43
+ elif [ $(BUILDTOOL) = "mill" ]; then \
44
+ scripts/mill $(project).test; \
45
+ fi
46
+
47
+ rvfi : clean # # Generates Verilog code for RISC-V Formal tests
48
+ ${SBT} " runMain chiselv.RVFITop --target:fpga -td $( generated_files) $( BOARDPARAMS) "
33
49
34
50
check : chisel_tests # # Run Chisel tests
35
51
test : chisel_tests
@@ -38,7 +54,7 @@ test: chisel_tests
38
54
# Adjust the rom and ram files below to match your test
39
55
romfile = gcc/helloUART/main-rom.mem
40
56
ramfile = gcc/helloUART/main-ram.mem
41
- verilator : chisel # # Generate Verilator simulation
57
+ verilator : $( generated_files ) # # Generate Verilator simulation
42
58
@rm -rf obj_dir
43
59
$(VERILATOR ) -O3 --assert $(foreach f,$(wildcard generated/* .v) ,--cc $(f ) ) --exe verilator/chiselv.cpp verilator/uart.c --top-module Toplevel -o chiselv --timescale 1ns/1ps
44
60
@make -C obj_dir -f VToplevel.mk -j` nproc`
@@ -51,9 +67,11 @@ verirun: ## Run Verilator simulation with ROM and RAM files to be loaded
51
67
@cp $(ramfile ) progload-RAM.mem
52
68
./chiselv
53
69
54
- dot : chisel # # Generate dot files for Core
70
+ MODULE ?= Toplevel
71
+ dot : $(generated_files ) # # Generate dot files for Core
72
+ @echo " Generating graphviz dot file for module \" $( MODULE) \" . For a different module, pass the argument as \" make dot MODULE=mymod\" ."
55
73
@touch progload.mem progload-RAM.mem
56
- $(YOSYS ) -p " read_verilog ./generated/*.v; proc; opt; show -colors 2 -width -format dot -prefix chiselv -signed SOC "
74
+ @ $(YOSYS ) -p " read_verilog ./generated/*.v; proc; opt; show -colors 2 -width -format dot -prefix $( MODULE ) -signed $( MODULE ) "
57
75
@rm progload.mem progload-RAM.mem
58
76
59
77
fmt : # # Formats code using scalafmt and scalafix
@@ -67,6 +85,11 @@ check-board-vars:
67
85
@test " $( BOARD) " ! = " bypass" || (echo " Set BOARD variable to one of the supported boards: " ; cat chiselv.core| grep " \-board" | cut -d ' -' -f 2| sed s/\" //g | sed s/board\ //g | tr -s ' \n' ' ,' | sed ' s/,$$/\n/' ; echo " Eg. make chisel BOARD=ulx3s" ; echo ; echo " Generating design with bypass PLL..." ; echo)
68
86
69
87
clean : # # Clean all generated files
88
+ @if [ $( BUILDTOOL) = " sbt" ]; then \
89
+ ${SBT} " clean" ; \
90
+ elif [ $(BUILDTOOL) = "mill" ]; then \
91
+ scripts/mill clean; \
92
+ fi
70
93
@rm -rf obj_dir test_run_dir target
71
94
@rm -rf $(generated_files)
72
95
@rm -rf out
83
106
@grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = "[:##]"}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$4}'
84
107
@echo " "
85
108
86
- .PHONY : chisel clean prog help verilator
109
+ .PHONY : clean prog help
87
110
.DEFAULT_GOAL := help
0 commit comments