2015-06-06 20:01:37 +08:00
|
|
|
|
2016-04-10 18:03:09 +08:00
|
|
|
RISCV_GNU_TOOLCHAIN_REV = 888ae43
|
2016-04-09 18:29:19 +08:00
|
|
|
GCC_URL = http://mirrors.kernel.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz
|
|
|
|
NEWLIB_URL = ftp://sourceware.org/pub/newlib/newlib-2.2.0.tar.gz
|
|
|
|
BINUTILS_URL = http://mirrors.kernel.org/gnu/binutils/binutils-2.26.tar.gz
|
|
|
|
|
2015-06-27 04:02:22 +08:00
|
|
|
TEST_OBJS = $(addsuffix .o,$(basename $(wildcard tests/*.S)))
|
2015-06-27 05:14:38 +08:00
|
|
|
FIRMWARE_OBJS = firmware/start.o firmware/irq.o firmware/print.o firmware/sieve.o firmware/multest.o firmware/stats.o
|
2015-07-04 22:31:26 +08:00
|
|
|
GCC_WARNS = -Werror -Wall -Wextra -Wshadow -Wundef -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
|
2015-07-04 17:47:19 +08:00
|
|
|
GCC_WARNS += -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes -pedantic # -Wconversion
|
2016-04-09 18:29:19 +08:00
|
|
|
TOOLCHAIN_PREFIX = /opt/riscv32i/bin/riscv32-unknown-elf-
|
2016-04-09 20:35:17 +08:00
|
|
|
COMPRESSED_ISA = C
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
test: testbench.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench.vvp
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench.vcd: testbench.vvp firmware/firmware.hex
|
2015-07-02 16:45:35 +08:00
|
|
|
vvp -N $< +vcd
|
|
|
|
|
2015-07-02 17:01:21 +08:00
|
|
|
view: testbench.vcd
|
2015-07-02 16:45:35 +08:00
|
|
|
gtkwave $< testbench.gtkw
|
|
|
|
|
2015-10-15 05:26:04 +08:00
|
|
|
check: check.smt2
|
2015-10-15 21:45:19 +08:00
|
|
|
yosys-smtbmc -t 30 -c check.vcd check.smt2
|
|
|
|
yosys-smtbmc -t 30 -c check.vcd -i check.smt2
|
2015-10-15 05:26:04 +08:00
|
|
|
|
|
|
|
check.smt2: picorv32.v
|
|
|
|
yosys -v2 -p 'read_verilog -formal picorv32.v' \
|
|
|
|
-p 'prep -top picorv32 -nordff' \
|
|
|
|
-p 'write_smt2 -bv -mem -wires check.smt2'
|
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
test_sp: testbench_sp.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench_sp.vvp
|
2015-06-27 05:54:12 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
test_axi: testbench.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench.vvp +axi_test
|
2015-06-07 01:22:28 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
test_synth: testbench_synth.vvp firmware/firmware.hex
|
|
|
|
vvp -N testbench_synth.vvp
|
2015-06-30 07:46:25 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench.vvp: testbench.v picorv32.v
|
|
|
|
iverilog -o testbench.vvp $(subst C,-DCOMPRESSED_ISA,$(COMPRESSED_ISA)) testbench.v picorv32.v
|
|
|
|
chmod -x testbench.vvp
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench_sp.vvp: testbench.v picorv32.v
|
|
|
|
iverilog -o testbench_sp.vvp $(subst C,-DCOMPRESSED_ISA,$(COMPRESSED_ISA)) -DSP_TEST testbench.v picorv32.v
|
|
|
|
chmod -x testbench_sp.vvp
|
2015-06-27 05:54:12 +08:00
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench_synth.vvp: testbench.v synth.v
|
|
|
|
iverilog -o testbench_synth.vvp testbench.v synth.v
|
|
|
|
chmod -x testbench_synth.vvp
|
2015-06-30 07:46:25 +08:00
|
|
|
|
|
|
|
synth.v: picorv32.v scripts/yosys/synth_sim.ys
|
|
|
|
yosys -qv3 -l synth.log scripts/yosys/synth_sim.ys
|
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
firmware/firmware.hex: firmware/firmware.bin firmware/makehex.py
|
2015-07-16 17:10:02 +08:00
|
|
|
python3 firmware/makehex.py $< 16384 > $@
|
2015-06-06 20:01:37 +08:00
|
|
|
|
|
|
|
firmware/firmware.bin: firmware/firmware.elf
|
2015-07-04 17:47:19 +08:00
|
|
|
$(TOOLCHAIN_PREFIX)objcopy -O binary $< $@
|
2015-06-06 20:01:37 +08:00
|
|
|
chmod -x $@
|
|
|
|
|
2015-06-27 04:02:22 +08:00
|
|
|
firmware/firmware.elf: $(FIRMWARE_OBJS) $(TEST_OBJS) firmware/sections.lds
|
2015-07-04 17:47:19 +08:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -Os -m32 -ffreestanding -nostdlib -o $@ \
|
2015-06-06 20:01:37 +08:00
|
|
|
-Wl,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \
|
2015-06-27 04:02:22 +08:00
|
|
|
$(FIRMWARE_OBJS) $(TEST_OBJS) -lgcc
|
2015-06-06 20:01:37 +08:00
|
|
|
chmod -x $@
|
|
|
|
|
2015-06-25 20:08:39 +08:00
|
|
|
firmware/start.o: firmware/start.S
|
2016-02-03 23:33:01 +08:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32IM$(COMPRESSED_ISA)Xcustom -o $@ $<
|
2015-06-25 20:08:39 +08:00
|
|
|
|
2015-06-27 04:02:22 +08:00
|
|
|
firmware/%.o: firmware/%.c
|
2016-02-03 23:33:01 +08:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32I$(COMPRESSED_ISA) -Os --std=c99 $(GCC_WARNS) -ffreestanding -nostdlib -o $@ $<
|
2015-06-27 04:02:22 +08:00
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
tests/%.o: tests/%.S tests/riscv_test.h tests/test_macros.h
|
2015-11-04 01:59:12 +08:00
|
|
|
$(TOOLCHAIN_PREFIX)gcc -c -m32 -march=RV32IM -o $@ -DTEST_FUNC_NAME=$(notdir $(basename $<)) \
|
2015-06-06 20:01:37 +08:00
|
|
|
-DTEST_FUNC_TXT='"$(notdir $(basename $<))"' -DTEST_FUNC_RET=$(notdir $(basename $<))_ret $<
|
|
|
|
|
2016-04-09 18:29:19 +08:00
|
|
|
download-tools:
|
|
|
|
sudo bash -c 'set -ex; mkdir -p /var/cache/distfiles; $(foreach URL,$(GCC_URL) $(NEWLIB_URL) $(BINUTILS_URL), \
|
|
|
|
if ! test -f /var/cache/distfiles/$(notdir $(URL)); then wget -O /var/cache/distfiles/$(notdir $(URL)).part $(URL); \
|
|
|
|
mv /var/cache/distfiles/$(notdir $(URL)).part /var/cache/distfiles/$(notdir $(URL)); fi;)'
|
|
|
|
|
|
|
|
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 18:46:29 +08:00
|
|
|
$(MAKE) build-$(1)-tools-bh
|
|
|
|
|
|
|
|
build-$(1)-tools-bh:
|
2016-04-09 18:29:19 +08:00
|
|
|
set -ex; if ! test -d riscv-gnu-toolchain-$(1); then git clone https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain-$(1); \
|
|
|
|
else cd riscv-gnu-toolchain-$(1); git checkout master; git pull; fi
|
|
|
|
set -ex; cd riscv-gnu-toolchain-$(1); rm -rf build; git checkout $(RISCV_GNU_TOOLCHAIN_REV); mkdir -p build
|
|
|
|
set -ex; cd riscv-gnu-toolchain-$(1)/build; ../configure --with-xlen=32 --with-arch=$(2) --prefix=/opt/$(1) --disable-float --disable-atomic
|
|
|
|
+set -ex; cd riscv-gnu-toolchain-$(1)/build; make
|
|
|
|
|
|
|
|
.PHONY: build-$(1)-tools
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(eval $(call build_tools_template,riscv32i,I))
|
|
|
|
$(eval $(call build_tools_template,riscv32ic,IC))
|
|
|
|
$(eval $(call build_tools_template,riscv32im,IM))
|
|
|
|
$(eval $(call build_tools_template,riscv32imc,IMC))
|
|
|
|
|
2016-04-11 18:46:29 +08: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-12 04:54:15 +08:00
|
|
|
$(MAKE) build-riscv32i-tools-bh
|
|
|
|
$(MAKE) build-riscv32ic-tools-bh
|
|
|
|
$(MAKE) build-riscv32im-tools-bh
|
|
|
|
$(MAKE) build-riscv32imc-tools-bh
|
2016-04-11 18:46:29 +08:00
|
|
|
|
2015-06-30 18:25:05 +08: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 20:01:37 +08:00
|
|
|
clean:
|
2016-04-09 18:51:50 +08:00
|
|
|
rm -rf riscv-gnu-toolchain-riscv32i riscv-gnu-toolchain-riscv32ic \
|
|
|
|
riscv-gnu-toolchain-riscv32im riscv-gnu-toolchain-riscv32imc
|
2015-10-15 05:26:04 +08:00
|
|
|
rm -vrf $(FIRMWARE_OBJS) $(TEST_OBJS) check.smt2 check.vcd synth.v synth.log \
|
2015-07-02 17:01:21 +08:00
|
|
|
firmware/firmware.elf firmware/firmware.bin firmware/firmware.hex firmware/firmware.map \
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench.vvp testbench_sp.vvp testbench_synth.vvp testbench.vcd
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2016-04-09 18:29:19 +08:00
|
|
|
.PHONY: test view test_sp test_axi test_synth download-tools toc clean
|
2015-06-06 20:01:37 +08:00
|
|
|
|