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