# This file is part of the Universal Laboratory (uLab) # # © 2017 - 2019 Raptor Engineering, LLC # All Rights Reserved # # Licensed under the terms of the AGPL v3 MAX_FPGA_ROUTE_PASSES = 100 SOURCE_FILES = main.v # Default seed #ARACHNE_PNR_SEED = 1 # Selected seed from fastest placement search # NOTE: Must be updated every time the Verilog source is modified, no matter how trivially! # Does not need to be updated if firmware program (C) sources are modified # 0 automatically uses the best placement result ARACHNE_PNR_SEED = 0 #ARACHNE_PNR_SEED = 1 YOSYS_ICE40_SIM_LIB = $(shell yosys-config --datdir/ice40/cells_sim.v) .PRECIOUS: guest_fpga_%.int guest_fpga_%.tmg: guest_fpga_%.int guest_fpga.pcf echo "Total path delay: inf ns (0.0 MHz)" > $@ -icetime -tmd hx8k -p guest_fpga.pcf -P ct256 $< > $@ 2>&1 guest_fpga_%.int: guest_fpga.blif guest_fpga.pcf echo "" > $@ -arachne-pnr -s $* -d 8k -P ct256 -m $(MAX_FPGA_ROUTE_PASSES) -p guest_fpga.pcf $< -o $@ guest_fpga.int: guest_fpga_1.tmg guest_fpga_2.tmg guest_fpga_3.tmg guest_fpga_4.tmg guest_fpga_5.tmg guest_fpga_6.tmg guest_fpga_7.tmg guest_fpga_8.tmg guest_fpga_9.tmg \ guest_fpga_10.tmg guest_fpga_11.tmg guest_fpga_12.tmg guest_fpga_13.tmg guest_fpga_14.tmg guest_fpga_15.tmg guest_fpga_16.tmg guest_fpga_17.tmg guest_fpga_18.tmg guest_fpga_19.tmg \ guest_fpga_20.tmg guest_fpga_21.tmg guest_fpga_22.tmg guest_fpga_23.tmg guest_fpga_24.tmg guest_fpga_25.tmg guest_fpga_26.tmg guest_fpga_27.tmg guest_fpga_28.tmg guest_fpga_29.tmg \ guest_fpga_30.tmg guest_fpga_31.tmg guest_fpga_32.tmg guest_fpga_33.tmg guest_fpga_34.tmg guest_fpga_35.tmg guest_fpga_36.tmg guest_fpga_37.tmg guest_fpga_38.tmg guest_fpga_39.tmg \ guest_fpga_40.tmg guest_fpga_41.tmg guest_fpga_42.tmg guest_fpga_43.tmg guest_fpga_44.tmg guest_fpga_45.tmg guest_fpga_46.tmg guest_fpga_47.tmg guest_fpga_48.tmg guest_fpga_49.tmg \ guest_fpga_50.tmg guest_fpga_51.tmg guest_fpga_52.tmg guest_fpga_53.tmg guest_fpga_54.tmg guest_fpga_55.tmg guest_fpga_56.tmg guest_fpga_57.tmg guest_fpga_58.tmg guest_fpga_59.tmg \ guest_fpga_60.tmg guest_fpga_61.tmg guest_fpga_62.tmg guest_fpga_63.tmg guest_fpga_64.tmg BEST_TRIAL=0; \ BEST_TRIAL_RESULT=0; \ for trial in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64; do \ CURRENT_TRIAL_RESULT=$$(cat guest_fpga_$${trial}.tmg | grep "Total path delay" | awk '{print $$6}' | sed 's/(//g'); \ if [ "$$CURRENT_TRIAL_RESULT" != "" ]; then \ echo "guest_fpga_$${trial}.tmg : $$CURRENT_TRIAL_RESULT"; \ COMPARISON_RESULT=$$(echo "$$CURRENT_TRIAL_RESULT > $$BEST_TRIAL_RESULT" | bc -l); \ if [ $$COMPARISON_RESULT -eq 1 ]; then \ BEST_TRIAL=guest_fpga_$${trial}.tmg; \ BEST_TRIAL_RESULT=$$CURRENT_TRIAL_RESULT; \ fi; \ fi; \ done; \ if [ "$$BEST_TRIAL_RESULT" -eq "0" ]; then \ echo "Unable to determine fastest result. Selecting first run...."; \ BEST_TRIAL=guest_fpga_1.tmg; \ BEST_TRIAL_RESULT=0; \ fi; \ echo "Fastest result: $$BEST_TRIAL : $$BEST_TRIAL_RESULT"; \ cp `echo $$BEST_TRIAL | sed 's/\.tmg/\.int/g'` guest_fpga.int; \ cp $$BEST_TRIAL guest_fpga.tmg ifneq ($(ARACHNE_PNR_SEED),0) cp guest_fpga_$(ARACHNE_PNR_SEED).int guest_fpga.int cp guest_fpga_$(ARACHNE_PNR_SEED).tmg guest_fpga.tmg endif cat guest_fpga.tmg guest_fpga.ex: guest_fpga.int icebox_explain guest_fpga.int > guest_fpga.ex guest_fpga.blif: $(SOURCE_FILES) yosys -l yosys.log -q -p "synth_ice40 -top guest_fpga_top -blif guest_fpga.blif" $(SOURCE_FILES) guest_fpga.bin: guest_fpga.int icepack guest_fpga.int guest_fpga.bin blank.rom: dd if=/dev/zero ibs=1k count=256 | tr "\000" "\377" > blank.rom guest_fpga.rom: blank.rom guest_fpga.bin cp blank.rom guest_fpga.rom dd if=guest_fpga.bin of=guest_fpga.rom conv=notrunc guest_fpga_test.vcd: $(SOURCE_FILES) testbench.v rm -f guest_fpga_sim rm -f guest_fpga.vcd /usr/bin/iverilog -DSIMULATION -o guest_fpga_sim $(SOURCE_FILES) testbench.v ./guest_fpga_sim simulate: guest_fpga_test.vcd simulate_view: guest_fpga_test.vcd gtkwave guest_fpga_test.vcd all: guest_fpga.rom dump_toolchain_info: -@echo "================================================================================" -@echo "Base system:\t" -@echo -n "Architecture:\t" -@uname -m 2>/dev/null -@echo -n "gcc:\t\t" -@gcc -dumpversion 2>/dev/null -@echo -n "clang:\t\t" -@clang --version 2>/dev/null | head -n 1 -@echo "\nFPGA toolchain:" -@echo -n "Icarus verilog:\t" -@iverilog -V 2>/dev/null | head -n 1 -@echo -n "Yosys:\t\t" -@yosys -V 2>/dev/null -@echo -n "arachne-pnr:\t" -@arachne-pnr -v 2>/dev/null -@echo "================================================================================" test: guest_fpga.bin iceprog -S guest_fpga.bin flash: guest_fpga.bin iceprog guest_fpga.bin clean: rm -f guest_fpga.blif guest_fpga.ex guest_fpga.int guest_fpga.tmg guest_fpga_*.int guest_fpga_*.tmg guest_fpga.bin yosys.log