2015-06-06 08:01:37 -04:00
|
|
|
|
2016-12-08 08:09:09 -05:00
|
|
|
RISCV_GNU_TOOLCHAIN_REV = 805ee1d
|
2016-04-09 06:29:19 -04:00
|
|
|
|
2016-08-16 19:06:10 -04:00
|
|
|
SHELL = bash
|
2015-06-26 16:02:22 -04:00
|
|
|
TEST_OBJS = $(addsuffix .o,$(basename $(wildcard tests/*.S)))
|
2015-06-26 17:14:38 -04:00
|
|
|
FIRMWARE_OBJS = firmware/start.o firmware/irq.o firmware/print.o firmware/sieve.o firmware/multest.o firmware/stats.o
|
2015-07-04 10:31:26 -04:00
|
|
|
GCC_WARNS = -Werror -Wall -Wextra -Wshadow -Wundef -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
|
2015-07-04 05:47:19 -04:00
|
|
|
GCC_WARNS += -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes -pedantic # -Wconversion
|
2016-04-09 06:29:19 -04:00
|
|
|
TOOLCHAIN_PREFIX = /opt/riscv32i/bin/riscv32-unknown-elf-
|
2016-04-09 08:35:17 -04:00
|
|
|
COMPRESSED_ISA = C
|
2015-06-06 08:01:37 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
test: testbench.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench.vvp
|
2015-06-06 08:01:37 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
testbench.vcd: testbench.vvp firmware/firmware.hex
|
2016-08-26 08:54:27 -04:00
|
|
|
vvp -N $< +vcd +trace +noerror
|
2015-07-02 04:45:35 -04:00
|
|
|
|
2015-07-02 05:01:21 -04:00
|
|
|
view: testbench.vcd
|
2015-07-02 04:45:35 -04:00
|
|
|
gtkwave $< testbench.gtkw
|
|
|
|
|
2016-09-03 09:16:24 -04:00
|
|
|
check: check-yices
|
2016-08-29 11:23:00 -04:00
|
|
|
|
2016-09-03 09:16:24 -04:00
|
|
|
check-%: check.smt2
|
|
|
|
yosys-smtbmc -s $(subst check-,,$@) -t 30 --dump-vcd check.vcd check.smt2
|
2016-09-13 13:34:14 -04:00
|
|
|
yosys-smtbmc -s $(subst check-,,$@) -t 25 --dump-vcd check.vcd -i check.smt2
|
2015-10-14 17:26:04 -04:00
|
|
|
|
|
|
|
check.smt2: picorv32.v
|
|
|
|
yosys -v2 -p 'read_verilog -formal picorv32.v' \
|
|
|
|
-p 'prep -top picorv32 -nordff' \
|
2016-09-07 06:40:19 -04:00
|
|
|
-p 'assertpmux -noinit; opt -fast' \
|
2016-08-30 08:37:21 -04:00
|
|
|
-p 'write_smt2 -wires check.smt2'
|
2015-10-14 17:26:04 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
test_sp: testbench_sp.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench_sp.vvp
|
2015-06-26 17:54:12 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
test_axi: testbench.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench.vvp +axi_test
|
2015-06-06 13:22:28 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
test_synth: testbench_synth.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench_synth.vvp
|
2015-06-29 19:46:25 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
testbench.vvp: testbench.v picorv32.v
|
2016-11-22 21:02:02 -05:00
|
|
|
iverilog -o testbench.vvp $(subst C,-DCOMPRESSED_ISA,$(COMPRESSED_ISA)) -DRISCV_FORMAL testbench.v picorv32.v
|
2016-05-04 02:57:16 -04:00
|
|
|
chmod -x testbench.vvp
|
2015-06-06 08:01:37 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
testbench_sp.vvp: testbench.v picorv32.v
|
2016-11-22 21:02:02 -05:00
|
|
|
iverilog -o testbench_sp.vvp $(subst C,-DCOMPRESSED_ISA,$(COMPRESSED_ISA)) -DRISCV_FORMAL -DSP_TEST testbench.v picorv32.v
|
2016-05-04 02:57:16 -04:00
|
|
|
chmod -x testbench_sp.vvp
|
2015-06-26 17:54:12 -04:00
|
|
|
|
2016-05-04 02:57:16 -04:00
|
|
|
testbench_synth.vvp: testbench.v synth.v
|
|
|
|
iverilog -o testbench_synth.vvp testbench.v synth.v
|
|
|
|
chmod -x testbench_synth.vvp
|
2015-06-29 19:46:25 -04:00
|
|
|
|
|
|
|
synth.v: picorv32.v scripts/yosys/synth_sim.ys
|
|
|
|
yosys -qv3 -l synth.log scripts/yosys/synth_sim.ys
|
|
|
|
|
2015-06-06 08:01:37 -04:00
|
|
|
firmware/firmware.hex: firmware/firmware.bin firmware/makehex.py
|
2015-07-16 05:10:02 -04:00
|
|
|
python3 firmware/makehex.py $< 16384 > $@
|
2015-06-06 08:01:37 -04:00
|
|
|
|
|
|
|
firmware/firmware.bin: firmware/firmware.elf
|
2015-07-04 05:47:19 -04:00
|
|
|
$(TOOLCHAIN_PREFIX)objcopy -O binary $< $@
|
2015-06-06 08:01:37 -04:00
|
|
|
chmod -x $@
|
|
|
|
|
2015-06-26 16:02:22 -04:00
|
|
|
firmware/firmware.elf: $(FIRMWARE_OBJS) $(TEST_OBJS) firmware/sections.lds
|
2015-07-04 05:47:19 -04:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -Os -m32 -ffreestanding -nostdlib -o $@ \
|
2015-06-06 08:01:37 -04:00
|
|
|
-Wl,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \
|
2015-06-26 16:02:22 -04:00
|
|
|
$(FIRMWARE_OBJS) $(TEST_OBJS) -lgcc
|
2015-06-06 08:01:37 -04:00
|
|
|
chmod -x $@
|
|
|
|
|
2015-06-25 08:08:39 -04:00
|
|
|
firmware/start.o: firmware/start.S
|
2016-02-03 10:33:01 -05:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32IM$(COMPRESSED_ISA)Xcustom -o $@ $<
|
2015-06-25 08:08:39 -04:00
|
|
|
|
2015-06-26 16:02:22 -04:00
|
|
|
firmware/%.o: firmware/%.c
|
2016-02-03 10:33:01 -05:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32I$(COMPRESSED_ISA) -Os --std=c99 $(GCC_WARNS) -ffreestanding -nostdlib -o $@ $<
|
2015-06-26 16:02:22 -04:00
|
|
|
|
2015-06-06 08:01:37 -04:00
|
|
|
tests/%.o: tests/%.S tests/riscv_test.h tests/test_macros.h
|
2015-11-03 12:59:12 -05:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32IM -o $@ -DTEST_FUNC_NAME=$(notdir $(basename $<)) \
|
2015-06-06 08:01:37 -04:00
|
|
|
-DTEST_FUNC_TXT='"$(notdir $(basename $<))"' -DTEST_FUNC_RET=$(notdir $(basename $<))_ret $<
|
|
|
|
|
2016-04-09 06:29:19 -04:00
|
|
|
download-tools:
|
2016-12-08 08:09:09 -05:00
|
|
|
sudo bash -c 'set -ex; mkdir -p /var/cache/distfiles; \
|
|
|
|
$(foreach REPO,riscv-gnu-toolchain riscv-binutils-gdb riscv-dejagnu riscv-gcc riscv-glibc riscv-newlib, \
|
2016-08-16 19:06:10 -04:00
|
|
|
if ! test -d /var/cache/distfiles/$(REPO).git; then rm -rf /var/cache/distfiles/$(REPO).git.part; \
|
|
|
|
git clone --bare https://github.com/riscv/$(REPO) /var/cache/distfiles/$(REPO).git.part; \
|
|
|
|
mv /var/cache/distfiles/$(REPO).git.part /var/cache/distfiles/$(REPO).git; else \
|
|
|
|
(cd /var/cache/distfiles/$(REPO).git; git fetch https://github.com/riscv/$(REPO)); fi;)'
|
2016-04-09 06:29:19 -04:00
|
|
|
|
|
|
|
define build_tools_template
|
|
|
|
build-$(1)-tools:
|
|
|
|
@read -p "This will remove all existing data from /opt/$(1). Type YES to continue: " reply && [[ "$$$$reply" == [Yy][Ee][Ss] || "$$$$reply" == [Yy] ]]
|
|
|
|
sudo bash -c "set -ex; rm -rf /opt/$(1); mkdir -p /opt/$(1); chown $$$${USER}. /opt/$(1)"
|
2016-04-11 06:46:29 -04:00
|
|
|
$(MAKE) build-$(1)-tools-bh
|
|
|
|
|
|
|
|
build-$(1)-tools-bh:
|
2016-08-16 19:06:10 -04:00
|
|
|
+set -ex; \
|
|
|
|
if [ -d /var/cache/distfiles/riscv-gnu-toolchain.git ]; then reference_riscv_gnu_toolchain="--reference /var/cache/distfiles/riscv-gnu-toolchain.git"; else reference_riscv_gnu_toolchain=""; fi; \
|
|
|
|
if [ -d /var/cache/distfiles/riscv-binutils-gdb.git ]; then reference_riscv_binutils_gdb="--reference /var/cache/distfiles/riscv-binutils-gdb.git"; else reference_riscv_binutils_gdb=""; fi; \
|
|
|
|
if [ -d /var/cache/distfiles/riscv-dejagnu.git ]; then reference_riscv_dejagnu="--reference /var/cache/distfiles/riscv-dejagnu.git"; else reference_riscv_dejagnu=""; fi; \
|
|
|
|
if [ -d /var/cache/distfiles/riscv-gcc.git ]; then reference_riscv_gcc="--reference /var/cache/distfiles/riscv-gcc.git"; else reference_riscv_gcc=""; fi; \
|
|
|
|
if [ -d /var/cache/distfiles/riscv-glibc.git ]; then reference_riscv_glibc="--reference /var/cache/distfiles/riscv-glibc.git"; else reference_riscv_glibc=""; fi; \
|
2016-12-08 08:09:09 -05:00
|
|
|
if [ -d /var/cache/distfiles/riscv-newlib.git ]; then reference_riscv_newlib="--reference /var/cache/distfiles/riscv-newlib.git"; else reference_riscv_newlib=""; fi; \
|
2016-08-16 19:06:10 -04:00
|
|
|
rm -rf riscv-gnu-toolchain-$(1); git clone $$$$reference_riscv_gnu_toolchain https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain-$(1); \
|
|
|
|
cd riscv-gnu-toolchain-$(1); git checkout $(RISCV_GNU_TOOLCHAIN_REV); \
|
|
|
|
git submodule update --init $$$$reference_riscv_binutils_gdb riscv-binutils-gdb; \
|
|
|
|
git submodule update --init $$$$reference_riscv_dejagnu riscv-dejagnu; \
|
|
|
|
git submodule update --init $$$$reference_riscv_gcc riscv-gcc; \
|
|
|
|
git submodule update --init $$$$reference_riscv_glibc riscv-glibc; \
|
2016-12-08 08:09:09 -05:00
|
|
|
git submodule update --init $$$$reference_riscv_newlib riscv-newlib; \
|
2016-08-16 19:06:10 -04:00
|
|
|
mkdir build; cd build; ../configure --with-arch=$(2) --prefix=/opt/$(1); make
|
2016-04-09 06:29:19 -04:00
|
|
|
|
|
|
|
.PHONY: build-$(1)-tools
|
|
|
|
endef
|
|
|
|
|
2016-05-31 10:21:24 -04:00
|
|
|
$(eval $(call build_tools_template,riscv32i,RV32I))
|
|
|
|
$(eval $(call build_tools_template,riscv32ic,RV32IC))
|
|
|
|
$(eval $(call build_tools_template,riscv32im,RV32IM))
|
|
|
|
$(eval $(call build_tools_template,riscv32imc,RV32IMC))
|
2016-04-09 06:29:19 -04:00
|
|
|
|
2016-04-11 06:46:29 -04:00
|
|
|
build-tools:
|
|
|
|
@echo "This will remove all existing data from /opt/riscv32i, /opt/riscv32ic, /opt/riscv32im, and /opt/riscv32imc."
|
|
|
|
@read -p "Type YES to continue: " reply && [[ "$$reply" == [Yy][Ee][Ss] || "$$reply" == [Yy] ]]
|
|
|
|
sudo bash -c "set -ex; rm -rf /opt/riscv32{i,ic,im,imc}; mkdir -p /opt/riscv32{i,ic,im,imc}; chown $${USER}. /opt/riscv32{i,ic,im,imc}"
|
2016-04-11 16:54:15 -04:00
|
|
|
$(MAKE) build-riscv32i-tools-bh
|
|
|
|
$(MAKE) build-riscv32ic-tools-bh
|
|
|
|
$(MAKE) build-riscv32im-tools-bh
|
|
|
|
$(MAKE) build-riscv32imc-tools-bh
|
2016-04-11 06:46:29 -04:00
|
|
|
|
2015-06-30 06:25:05 -04:00
|
|
|
toc:
|
|
|
|
gawk '/^-+$$/ { y=tolower(x); gsub("[^a-z0-9]+", "-", y); gsub("-$$", "", y); printf("- [%s](#%s)\n", x, y); } { x=$$0; }' README.md
|
|
|
|
|
2015-06-06 08:01:37 -04:00
|
|
|
clean:
|
2016-04-09 06:51:50 -04:00
|
|
|
rm -rf riscv-gnu-toolchain-riscv32i riscv-gnu-toolchain-riscv32ic \
|
|
|
|
riscv-gnu-toolchain-riscv32im riscv-gnu-toolchain-riscv32imc
|
2015-10-14 17:26:04 -04:00
|
|
|
rm -vrf $(FIRMWARE_OBJS) $(TEST_OBJS) check.smt2 check.vcd synth.v synth.log \
|
2015-07-02 05:01:21 -04:00
|
|
|
firmware/firmware.elf firmware/firmware.bin firmware/firmware.hex firmware/firmware.map \
|
2016-08-25 08:15:42 -04:00
|
|
|
testbench.vvp testbench_sp.vvp testbench_synth.vvp testbench.vcd testbench.trace
|
2015-06-06 08:01:37 -04:00
|
|
|
|
2016-09-03 09:16:24 -04:00
|
|
|
.PHONY: test view test_sp test_axi test_synth download-tools build-tools toc clean
|
2015-06-06 08:01:37 -04:00
|
|
|
|