quasar/demo/Makefile

86 lines
2.7 KiB
Makefile
Raw Normal View History

2022-03-10 21:12:28 +08:00
export RV_ROOT = ${PWD}/..
GCC_PREFIX = /opt/riscv/bin/riscv32-unknown-elf
2022-03-10 11:56:21 +08:00
GDB_PREFIX = /opt/riscv/bin/riscv32-unknown-elf-gdb
ABI = -mabi=ilp32 -march=rv32imc
DEMODIR = ${PWD}
BUILD_DIR = ${DEMODIR}/build
2022-03-10 21:12:28 +08:00
DEFINE_DIR = ${DEMODIR}/../design/snapshots/default
RV_SOC = ${RV_ROOT}/soc
2022-03-10 11:56:21 +08:00
TEST = jtag
ifdef debug
DEBUG_PLUS = +dumpon
VERILATOR_DEBUG = --trace
endif
LINK = $(DEMODIR)/link.ld
2022-03-10 21:12:28 +08:00
LINKPRO = $(DEMODIR)/link_pro.ld
2022-03-10 11:56:21 +08:00
# CFLAGS for verilator generated Makefiles. Without -std=c++11 it complains for `auto` variables
CFLAGS += "-std=c++11"
# Optimization for better performance; alternative is nothing for slower runtime (faster compiles)
# -O2 for faster runtime (slower compiles), or -O for balance.
VERILATOR_MAKE_FLAGS = OPT_FAST="-Os"
# Targets
all: clean verilator
clean:
rm -rf build obj_dir
##################### Verilog Builds #####################################
2022-03-10 21:12:28 +08:00
verilator-build:
echo '`undef RV_ASSERT_ON' >> ${DEFINE_DIR}/common_defines.vh
2022-03-10 11:56:21 +08:00
verilator --cc -CFLAGS ${CFLAGS} \
2022-03-10 21:12:28 +08:00
$(DEFINE_DIR)/common_defines.vh \
-I${DEFINE_DIR} \
2022-03-10 11:56:21 +08:00
-Wno-WIDTH \
2022-03-10 21:12:28 +08:00
-Wno-UNOPTFLAT \
2022-03-10 11:56:21 +08:00
-Wno-LATCH \
-F ${RV_SOC}/soc_top.mk \
-F ${RV_SOC}/soc_sim.mk \
$(RV_SOC)/soc_sim.sv \
--top-module soc_sim -exe test_soc_sim.cpp --autoflush $(VERILATOR_DEBUG)
cp ${DEMODIR}/test_soc_sim.cpp obj_dir
2022-03-10 21:12:28 +08:00
$(MAKE) -j -e -C obj_dir/ -f Vsoc_sim.mk $(VERILATOR_MAKE_FLAGS)
2022-03-10 11:56:21 +08:00
##################### Simulation Runs #####################################
2022-03-10 21:12:28 +08:00
verilator: program.hex verilator-build
cd build && ../obj_dir/Vsoc_sim ${DEBUG_PLUS}
sim:
2022-03-10 11:56:21 +08:00
cd build && ../obj_dir/Vsoc_sim ${DEBUG_PLUS}
##################### Test hex Build #####################################
2022-03-10 21:12:28 +08:00
program.hex: $(TEST).o $(LINK)
@echo Building $(TEST)
$(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINKPRO) -o $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/$(TEST).o -nostartfiles $(TEST_LIBS)
$(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/program.hex
$(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINK) -o $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/$(TEST).o -nostartfiles $(TEST_LIBS)
$(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).bin > $(BUILD_DIR)/$(TEST).dis
@echo Completed building $(TEST)
%.o : %.s
@mkdir -p $(BUILD_DIR)
$(GCC_PREFIX)-cpp -g -I${DEFINE_DIR} $< > $(BUILD_DIR)/$*.cpp.s
$(GCC_PREFIX)-as -g $(ABI) $(BUILD_DIR)/$*.cpp.s -o $(BUILD_DIR)/$@
2022-03-10 11:56:21 +08:00
##################### openocd #####################################
openocd:
openocd -f swerv.cfg
gdb:
$(GDB_PREFIX) -x gdbinit ./build/jtag.bin
help:
@echo Possible targets: verilator help clean all verilator-build program.hex
.PHONY: help clean verilator