@@ -58,6 +58,63 @@ $(ROOT_DIR)/Bender.lock:
5858 $(BENDER ) checkout
5959 touch $@
6060
61+ # #################################
62+ # #### Hardware dependencies ######
63+ # #################################
64+
65+ ifeq ($(shell test -d $(ROOT_DIR ) /.bender || echo 1) ,)
66+ CLINTROOT := $(shell $(BENDER ) path clint)
67+ REGTOOL := $(shell $(BENDER ) path register_interface) /vendor/lowrisc_opentitan/util/regtool.py
68+ OTPROOT := $(shell $(BENDER ) path opentitan_peripherals)
69+ else
70+ CLINTROOT := $(ROOT_DIR ) /clint
71+ REGTOOL := regtool.py
72+ OTPROOT := $(ROOT_DIR ) /opentitan_peripherals
73+ endif
74+
75+ CLINTCORES := 1
76+ include $(CLINTROOT ) /clint.mk
77+ $(CLINTROOT ) /.generated :
78+ flock -x $@ $(MAKE ) clint && touch $@
79+
80+ include $(OTPROOT ) /otp.mk
81+ $(OTPROOT ) /.generated : $(TEST_DIR ) /hw/rv_plic.cfg.hjson
82+ flock -x $@ sh -c " cp $< $( dir $@ ) /src/rv_plic/; $( MAKE) -j1 otp" && touch $@ || rm $@
83+
84+ HW_DEPS := $(CLINTROOT ) /.generated $(OTPROOT ) /.generated
85+
86+ # #################################
87+ # ########## Bootrom ##############
88+ # #################################
89+
90+ RV_BINROOT ?= $(dir $(shell which riscv64-unknown-elf-gcc) )
91+ RV_AR := $(RV_BINROOT ) /riscv64-unknown-elf-ar
92+ RV_CC := $(RV_BINROOT ) /riscv64-unknown-elf-gcc
93+ RV_OBJCOPY := $(RV_BINROOT ) /riscv64-unknown-elf-objcopy
94+ RV_OBJDUMP := $(RV_BINROOT ) /riscv64-unknown-elf-objdump
95+
96+ BROM_CC_FLAGS = -DOT_PLATFORM_RV32 -march=rv64gc_zifencei -mabi=lp64d \
97+ -mstrict-align -O2 -Wall -Wextra -static -ffunction-sections \
98+ -fdata-sections -frandom-seed=cheshire -fuse-linker-plugin \
99+ -nostartfiles -Os -fno-zero-initialized-in-bss \
100+ -fwhole-program -flto -Wl,-flto -Wl,--gc-sections
101+
102+ $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.bin : $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.ld $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.S
103+ $(RV_CC ) -T$< $(BROM_CC_FLAGS ) -o $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.elf $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.S
104+ $(RV_OBJDUMP ) -d $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.elf > $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.dump
105+ $(RV_OBJCOPY ) -O binary $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.elf $@
106+
107+ $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.sv : $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.bin $(TEST_DIR ) /util/gen_bootrom.py
108+ $(TEST_DIR ) /util/gen_bootrom.py --sv-module cva6tb_bootrom $< > $@
109+
110+ .PHONY : bootrom
111+ bootrom : $(TEST_DIR ) /hw/bootrom/cva6tb_bootrom.sv
112+
113+ .PHONY : bootrom-clean
114+ bootrom-clean :
115+ cd $(TEST_DIR ) /hw/bootrom && rm -f * .sv * .elf * .bin * .dump
116+
117+
61118# #################################
62119# ######### QuestaSim #############
63120# #################################
84141$(VSIM_BUILD_DIR ) :
85142 @mkdir -p $(VSIM_BUILD_DIR )
86143
87- $(VSIM_BUILD_DIR ) /vsim_compile.tcl : $(ROOT_DIR ) /Bender.lock | $(VSIM_BUILD_DIR )
144+ $(VSIM_BUILD_DIR ) /vsim_compile.tcl : $(ROOT_DIR ) /Bender.lock $( HW_DEPS ) | $(VSIM_BUILD_DIR )
88145 $(BENDER ) script vsim $(BENDER_FLAGS ) --vlog-arg=" $( VLOG_FLAGS) " > $@
89146 @echo ' vopt $(VOPT_FLAGS) test -o test_opt' >> $@
90147
@@ -125,7 +182,7 @@ VERILATOR_FLAGS := --binary -j 0 --Mdir $(VERILATOR_BUILD_DIR) $(VERILATOR_W
125182$(VERILATOR_LOG_DIR ) :
126183 @mkdir -p $(VERILATOR_LOG_DIR )
127184
128- $(VERILATOR_FLIST ) : $(ROOT_DIR ) /Bender.lock
185+ $(VERILATOR_FLIST ) : $(ROOT_DIR ) /Bender.lock $( HW_DEPS )
129186 $(BENDER ) script verilator $(BENDER_FLAGS ) -t verilator > $@
130187
131188$(VERILATOR_BUILD_DIR ) /Vtest : $(VERILATOR_FLIST ) | $(VERILATOR_LOG_DIR )
0 commit comments