3b64e2ae3d900326f544368e68f5abca1d99438f
[DuneNvme.git] / vivado / Vivado.mk
1 ################################################################################
2 #       Vivado.mk       General common Makefile targets
3 #                       T.Barnaby,      BEAM Ltd,       2020-02-18
4 ################################################################################
5 #
6 # Parameters
7 #  PROJECT:     The projects name
8 #  BOARD:       The board type if a specific standard board
9 #  FPGA_PART:   FPGA device (e.g. xcvu095-ffva2104-2-e)
10 #  FPGA_TOP:    Top module name
11 #  SYN_FILES:   Space-separated list of source files
12 #  INC_FILES:   Space-separated list of include files
13 #  XDC_FILES:   Space-separated list of timing constraint files
14 #  XCI_FILES:   Space-separated list of IP XCI files
15 #
16 # Targets
17 #  all:         Build everything
18 #  clean:       Remove output files and project files
19 #  distclean:   Clean all files
20 #
21
22 export PATH:=/opt/Xilinx/Vivado/2019.2/bin:${PATH}
23
24 .PHONY: clean fpga
25
26 # Prevent make from deleting intermediate files and reports
27 .PRECIOUS: ${PROJECT}.xpr ${PROJECT}.bit ${PROJECT}.mcs ${PROJECT}.prm
28 .SECONDARY:
29
30 all: fpga
31
32 fpga: $(PROJECT).bit
33
34 clean:
35         -rm -rf *.log *.jou *.cache *.hw *.ip_user_files *.runs *.xpr *.html *.xml *.sim *.srcs *.str .Xil defines.v
36         -rm -rf create_project.tcl run_synth.tcl run_impl.tcl generate_bit.tcl
37         -rm -rf *.bit program.tcl generate_mcs.tcl *.mcs *.prm flash.tcl
38
39 distclean: clean
40         -rm -rf rev
41
42 # Vivado project file
43 ${PROJECT}.xpr: Makefile $(XCI_FILES)
44         rm -rf defines.v
45         touch defines.v
46         for x in $(DEFS); do echo '`define' $$x >> defines.v; done
47         echo "create_project -force -part $(FPGA_PART) ${PROJECT}" > create_project.tcl
48         if [ "${BOARD}" != "" ]; then echo "set_property board_part ${BOARD} [current_project]" >> create_project.tcl; fi
49         echo "set_property target_language VHDL [current_project]" >> create_project.tcl
50         echo "add_files -fileset sources_1 defines.v" >> create_project.tcl
51         for x in $(SYN_FILES); do echo "add_files -fileset sources_1 $$x" >> create_project.tcl; done
52         for x in $(XDC_FILES); do echo "add_files -fileset constrs_1 $$x" >> create_project.tcl; done
53         for x in $(XCI_FILES); do echo "import_ip $$x" >> create_project.tcl; done
54         echo "exit" >> create_project.tcl
55         vivado -nojournal -nolog -mode batch -source create_project.tcl
56
57 # Synthesis run
58 ${PROJECT}.runs/synth_1/${PROJECT}.dcp: ${PROJECT}.xpr $(SYN_FILES) $(INC_FILES) $(XDC_FILES)
59         rm -f $(PROJECT).bit
60         echo "open_project ${PROJECT}.xpr" > run_synth.tcl
61         echo "reset_run synth_1" >> run_synth.tcl
62         echo "launch_runs synth_1 -jobs 4" >> run_synth.tcl
63         echo "wait_on_run synth_1" >> run_synth.tcl
64         echo "set runStatus [ get_property STATUS [get_runs synth_1] ]" >> run_synth.tcl
65         #echo 'puts stderr "RunStatus: $${runStatus}"' >> run_synth.tcl
66         echo 'if { $${runStatus} != "synth_design Complete!"} {' >> run_synth.tcl
67         echo "  exit 1" >> run_synth.tcl
68         echo "}" >> run_synth.tcl
69         echo "exit 0" >> run_synth.tcl
70         vivado -nojournal -nolog -mode batch -source run_synth.tcl
71
72 # Implementation run
73 ${PROJECT}.runs/impl_1/${PROJECT}_routed.dcp: ${PROJECT}.runs/synth_1/${PROJECT}.dcp
74         rm -f $(PROJECT).bit
75         echo "open_project ${PROJECT}.xpr" > run_impl.tcl
76         echo "reset_run impl_1" >> run_impl.tcl
77         echo "launch_runs impl_1 -jobs 4" >> run_impl.tcl
78         #echo "launch_runs impl_1 -to_step write_bitstream -jobs 4" >> run_impl.tcl
79         echo "wait_on_run impl_1" >> run_impl.tcl
80         echo "set runStatus [ get_property STATUS [get_runs impl_1] ]" >> run_impl.tcl
81         echo 'puts stderr "RunStatus: $${runStatus}"' >> run_impl.tcl
82         echo 'if { $${runStatus} != "route_design Complete!"} {' >> run_impl.tcl
83         #echo 'if { $${runStatus} != "write_bitstream Complete!"} {' >> run_impl.tcl
84         echo "  exit 1" >> run_impl.tcl
85         echo "}" >> run_impl.tcl
86
87         echo "report_utilization -hierarchical -file utilisation.txt" >> run_impl.tcl
88         echo "exit 0" >> run_impl.tcl
89         vivado -nojournal -nolog -mode batch -source run_impl.tcl
90
91 # Bit file
92 ${PROJECT}.bit: ${PROJECT}.runs/impl_1/${PROJECT}_routed.dcp
93         rm -f $(PROJECT).bit
94         echo "open_project ${PROJECT}.xpr" > generate_bit.tcl
95         echo "open_run impl_1" >> generate_bit.tcl
96         echo "write_bitstream -force ${PROJECT}.bit" >> generate_bit.tcl
97         echo "exit" >> generate_bit.tcl
98         time vivado -nojournal -nolog -mode batch -source generate_bit.tcl
99         mkdir -p rev
100         EXT=bit; COUNT=100; \
101         while [ -e rev/${PROJECT}_rev$$COUNT.$$EXT ]; \
102         do COUNT=$$((COUNT+1)); done; \
103         cp $@ rev/${PROJECT}_rev$$COUNT.$$EXT; \
104         echo "Output: rev/${PROJECT}_rev$$COUNT.$$EXT";
105
106 # Extras for flash etc
107 ${PROJECT}_primary.mcs ${PROJECT}_secondary.mcs ${PROJECT}_primary.prm ${PROJECT}_secondary.prm: ${PROJECT}.bit
108         echo "write_cfgmem -force -format mcs -size 256 -interface SPIx8 -loadbit {up 0x0000000 $*.bit} -checksum -file $*.mcs" > generate_mcs.tcl
109         echo "exit" >> generate_mcs.tcl
110         vivado -nojournal -nolog -mode batch -source generate_mcs.tcl
111         mkdir -p rev
112         COUNT=100; \
113         while [ -e rev/$*_rev$$COUNT.bit ]; \
114         do COUNT=$$((COUNT+1)); done; \
115         COUNT=$$((COUNT-1)); \
116         for x in _primary.mcs _secondary.mcs _primary.prm _secondary.prm; \
117         do cp $*$$x rev/$*_rev$$COUNT$$x; \
118         echo "Output: rev/$*_rev$$COUNT$$x"; done;
119
120 flash: $(PROJECT)_primary.mcs $(PROJECT)_secondary.mcs $(PROJECT)_primary.prm $(PROJECT)_secondary.prm
121         echo "open_hw" > flash.tcl
122         echo "connect_hw_server" >> flash.tcl
123         echo "open_hw_target" >> flash.tcl
124         echo "current_hw_device [lindex [get_hw_devices] 0]" >> flash.tcl
125         echo "refresh_hw_device -update_hw_probes false [current_hw_device]" >> flash.tcl
126         echo "create_hw_cfgmem -hw_device [current_hw_device] [lindex [get_cfgmem_parts {mt25qu01g-spi-x1_x2_x4_x8}] 0]" >> flash.tcl
127         echo "current_hw_cfgmem -hw_device [current_hw_device] [get_property PROGRAM.HW_CFGMEM [current_hw_device]]" >> flash.tcl
128         echo "set_property PROGRAM.FILES [list \"$(PROJECT)_primary.mcs\" \"$(PROJECT)_secondary.mcs\"] [current_hw_cfgmem]" >> flash.tcl
129         echo "set_property PROGRAM.PRM_FILES [list \"$(PROJECT)_primary.prm\" \"$(PROJECT)_secondary.prm\"] [current_hw_cfgmem]" >> flash.tcl
130         echo "set_property PROGRAM.ERASE 1 [current_hw_cfgmem]" >> flash.tcl
131         echo "set_property PROGRAM.CFG_PROGRAM 1 [current_hw_cfgmem]" >> flash.tcl
132         echo "set_property PROGRAM.VERIFY 1 [current_hw_cfgmem]" >> flash.tcl
133         echo "set_property PROGRAM.CHECKSUM 0 [current_hw_cfgmem]" >> flash.tcl
134         echo "set_property PROGRAM.ADDRESS_RANGE {use_file} [current_hw_cfgmem]" >> flash.tcl
135         echo "set_property PROGRAM.UNUSED_PIN_TERMINATION {pull-none} [current_hw_cfgmem]" >> flash.tcl
136         echo "create_hw_bitstream -hw_device [current_hw_device] [get_property PROGRAM.HW_CFGMEM_BITFILE [current_hw_device]]" >> flash.tcl
137         echo "program_hw_devices [current_hw_device]" >> flash.tcl
138         echo "refresh_hw_device [current_hw_device]" >> flash.tcl
139         echo "program_hw_cfgmem -hw_cfgmem [current_hw_cfgmem]" >> flash.tcl
140         echo "boot_hw_device [current_hw_device]" >> flash.tcl
141         echo "exit" >> flash.tcl
142         vivado -nojournal -nolog -mode batch -source flash.tcl