|
| 1 | +# ******* project, board and chip name ******* |
| 2 | +PROJECT ?= project |
| 3 | +BOARD ?= board |
| 4 | +FPGA_SIZE ?= 12 |
| 5 | +FPGA_CHIP ?= lfe5u-$(FPGA_SIZE)f |
| 6 | +FPGA_PACKAGE ?= 6bg381c |
| 7 | +# config flash: 1:SPI (standard), 4:QSPI (quad) |
| 8 | +FLASH_SPI ?= 1 |
| 9 | +# chip: is25lp032d is25lp128f s25fl164k |
| 10 | +FLASH_CHIP ?= is25lp032d |
| 11 | + |
| 12 | +# ******* design files ******* |
| 13 | +CONSTRAINTS ?= board_constraints.lpf |
| 14 | +STRATEGY ?= $(SCRIPTS)/ulx3s.sty |
| 15 | +TOP_MODULE ?= top |
| 16 | +TOP_MODULE_FILE ?= $(TOP_MODULE).v |
| 17 | +VERILOG_FILES ?= $(TOP_MODULE_FILE) |
| 18 | +VHDL_FILES ?= |
| 19 | +SBX_FILES ?= |
| 20 | + |
| 21 | +# ******* tools installation paths ******* |
| 22 | +# include $(SCRIPTS)/trellis_path.mk |
| 23 | +# https://github.com/ldoolitt/vhd2vl |
| 24 | +#VHDL2VL ?= /mt/scratch/tmp/openfpga/vhd2vl/src/vhd2vl |
| 25 | +# https://github.com/YosysHQ/yosys |
| 26 | +#YOSYS ?= /mt/scratch/tmp/openfpga/yosys/yosys |
| 27 | +# https://github.com/YosysHQ/nextpnr |
| 28 | +#NEXTPNR-ECP5 ?= /mt/scratch/tmp/openfpga/nextpnr/nextpnr-ecp5 |
| 29 | +# https://github.com/SymbiFlow/prjtrellis |
| 30 | +#TRELLIS ?= /mt/scratch/tmp/openfpga/prjtrellis |
| 31 | + |
| 32 | +ifeq ($(FPGA_CHIP), lfe5u-12f) |
| 33 | + CHIP_ID=0x21111043 |
| 34 | + MASK_FILE=LFE5U-45F.msk |
| 35 | +endif |
| 36 | +ifeq ($(FPGA_CHIP), lfe5u-25f) |
| 37 | + CHIP_ID=0x41111043 |
| 38 | + MASK_FILE=LFE5U-45F.msk |
| 39 | +endif |
| 40 | +ifeq ($(FPGA_CHIP), lfe5u-45f) |
| 41 | + CHIP_ID=0x41112043 |
| 42 | + MASK_FILE=LFE5U-45F.msk |
| 43 | +endif |
| 44 | +ifeq ($(FPGA_CHIP), lfe5u-85f) |
| 45 | + CHIP_ID=0x41113043 |
| 46 | + MASK_FILE=LFE5U-85F.msk |
| 47 | +endif |
| 48 | + |
| 49 | +#ifeq ($(FPGA_SIZE), 12) |
| 50 | +# FPGA_K=25 |
| 51 | +# IDCODE_CHIPID=--idcode $(CHIP_ID) |
| 52 | +#else |
| 53 | + FPGA_K=$(FPGA_SIZE) |
| 54 | + IDCODE_CHIPID= |
| 55 | +#endif |
| 56 | + |
| 57 | +FPGA_CHIP_EQUIVALENT ?= lfe5u-$(FPGA_K)f |
| 58 | + |
| 59 | +# open source synthesis tools |
| 60 | +ECPPLL ?= $(TRELLIS)/libtrellis/ecppll |
| 61 | +ECPPACK ?= $(TRELLIS)/libtrellis/ecppack |
| 62 | +TRELLISDB ?= $(TRELLIS)/database |
| 63 | +LIBTRELLIS ?= $(TRELLIS)/libtrellis |
| 64 | +BIT2SVF ?= $(TRELLIS)/tools/bit_to_svf.py |
| 65 | +#BASECFG ?= $(TRELLIS)/misc/basecfgs/empty_$(FPGA_CHIP_EQUIVALENT).config |
| 66 | +# yosys options, sometimes those can be used: -noccu2 -nomux -nodram |
| 67 | +YOSYS_OPTIONS ?= |
| 68 | + |
| 69 | +# clock generator |
| 70 | +CLK0_NAME ?= clk0 |
| 71 | +CLK0_FILE_NAME ?= clocks/$(CLK0_NAME).v |
| 72 | +CLK0_OPTIONS ?= --input 25 --output 100 --s1 50 --p1 0 --s2 25 --p2 0 --s3 125 --p3 0 |
| 73 | +CLK1_NAME ?= clk1 |
| 74 | +CLK1_FILE_NAME ?= clocks/$(CLK1_NAME).v |
| 75 | +CLK1_OPTIONS ?= --input 25 --output 100 --s1 50 --p1 0 --s2 25 --p2 0 --s3 125 --p3 0 |
| 76 | +CLK2_NAME ?= clk2 |
| 77 | +CLK2_FILE_NAME ?= clocks/$(CLK2_NAME).v |
| 78 | +CLK2_OPTIONS ?= --input 25 --output 100 --s1 50 --p1 0 --s2 25 --p2 0 --s3 125 --p3 0 |
| 79 | +CLK3_NAME ?= clk3 |
| 80 | +CLK3_FILE_NAME ?= clocks/$(CLK3_NAME).v |
| 81 | +CLK3_OPTIONS ?= --input 25 --output 100 --s1 50 --p1 0 --s2 25 --p2 0 --s3 125 --p3 0 |
| 82 | + |
| 83 | +# closed source synthesis tools |
| 84 | +# include $(SCRIPTS)/diamond_path.mk |
| 85 | +#DIAMOND_BASE ?= /usr/local/diamond |
| 86 | +ifneq ($(wildcard $(DIAMOND_BASE)),) |
| 87 | + DIAMOND_BIN := $(shell find ${DIAMOND_BASE}/ -maxdepth 2 -name bin | sort -rn | head -1) |
| 88 | + DIAMONDC := $(shell find ${DIAMOND_BIN}/ -name diamondc) |
| 89 | + DDTCMD := $(shell find ${DIAMOND_BIN}/ -name ddtcmd) |
| 90 | + MASK_PATH := $(shell find ${DIAMOND_BASE}/ -maxdepth 5 -name xpga -type d)/ecp5 |
| 91 | +endif |
| 92 | + |
| 93 | +#PROJ_FILE := $(shell ls *.ldf | head -1) |
| 94 | +#PROJ_NAME := $(shell fgrep default_implementation ${PROJ_FILE} | cut -d'"' -f 4) |
| 95 | +#IMPL_NAME := $(shell fgrep default_implementation ${PROJ_FILE} | cut -d'"' -f 8) |
| 96 | +#IMPL_DIR := $(shell fgrep default_strategy ${PROJ_FILE} | cut -d'"' -f 4) |
| 97 | + |
| 98 | +# programming tools |
| 99 | +UJPROG ?= fujprog |
| 100 | +OPENFPGALOADER ?= openFPGALoader |
| 101 | +OPENFPGALOADER_OPTIONS ?= --board ulx3s |
| 102 | +FLEAFPGA_JTAG ?= FleaFPGA-JTAG |
| 103 | +OPENOCD ?= openocd |
| 104 | +OPENOCD_INTERFACE ?= $(SCRIPTS)/ft231x.ocd |
| 105 | +DFU_UTIL ?= dfu-util |
| 106 | +TINYFPGASP ?= tinyfpgasp |
| 107 | + |
| 108 | +# helper scripts directory |
| 109 | +SCRIPTS ?= scripts |
| 110 | + |
| 111 | +# rest of the include makefile |
| 112 | +FPGA_CHIP_UPPERCASE := $(shell echo $(FPGA_CHIP) | tr '[:lower:]' '[:upper:]') |
| 113 | +FPGA_PACKAGE_UPPERCASE := $(shell echo $(FPGA_PACKAGE) | tr '[:lower:]' '[:upper:]') |
| 114 | + |
| 115 | +BITSTREAM ?= $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 116 | +#BITSTREAM ?= $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).vme $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash_$(FLASH_CHIP).vme |
| 117 | + |
| 118 | +all: $(BITSTREAM) |
| 119 | + |
| 120 | +# VHDL to VERILOG conversion |
| 121 | +#%.v: %.vhd |
| 122 | +# $(VHDL2VL) $< $@ |
| 123 | + |
| 124 | +#*.v: *.vhdl |
| 125 | +# $(VHDL2VL) $< $@ |
| 126 | + |
| 127 | +#$(PROJECT).ys: makefile |
| 128 | +# $(SCRIPTS)/ysgen.sh $(VERILOG_FILES) $(VHDL_TO_VERILOG_FILES) > $@ |
| 129 | +# echo "hierarchy -top ${TOP_MODULE}" >> $@ |
| 130 | +# echo "synth_ecp5 -noccu2 -nomux -nodram -json ${PROJECT}.json" >> $@ |
| 131 | + |
| 132 | +#$(PROJECT).json: $(PROJECT).ys $(VERILOG_FILES) $(VHDL_TO_VERILOG_FILES) |
| 133 | +# $(YOSYS) $(PROJECT).ys |
| 134 | + |
| 135 | +$(PROJECT).json: $(VERILOG_FILES) $(VHDL_TO_VERILOG_FILES) |
| 136 | + $(YOSYS) \ |
| 137 | + -p "hierarchy -top ${TOP_MODULE}" \ |
| 138 | + -p "synth_ecp5 ${YOSYS_OPTIONS} -json ${PROJECT}.json" \ |
| 139 | + $(VERILOG_FILES) $(VHDL_TO_VERILOG_FILES) |
| 140 | + |
| 141 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).config: $(PROJECT).json $(BASECFG) |
| 142 | + $(NEXTPNR-ECP5) --$(FPGA_K)k --json $(PROJECT).json --lpf $(CONSTRAINTS) --basecfg $(BASECFG) --textcfg $@ |
| 143 | + |
| 144 | +#$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).config |
| 145 | +# LANG=C LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPACK) $(IDCODE_CHIPID) --db $(TRELLISDB) --input $< --bit $@ |
| 146 | + |
| 147 | +# generate LDF project file for diamond |
| 148 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).ldf: $(SCRIPTS)/project.ldf $(SCRIPTS)/ldf.xsl $(SCRIPTS)/$(BOARD)_sram.xcf |
| 149 | + xsltproc \ |
| 150 | + --stringparam FPGA_DEVICE $(FPGA_CHIP_UPPERCASE)-$(FPGA_PACKAGE_UPPERCASE) \ |
| 151 | + --stringparam CONSTRAINTS_FILE $(CONSTRAINTS) \ |
| 152 | + --stringparam STRATEGY_FILE $(STRATEGY) \ |
| 153 | + --stringparam XCF_FILE $(SCRIPTS)/$(BOARD)_sram.xcf \ |
| 154 | + --stringparam TOP_MODULE $(TOP_MODULE) \ |
| 155 | + --stringparam TOP_MODULE_FILE $(TOP_MODULE_FILE) \ |
| 156 | + --stringparam VHDL_FILES "$(VHDL_FILES)" \ |
| 157 | + --stringparam VERILOG_FILES "$(VERILOG_FILES)" \ |
| 158 | + --stringparam SBX_FILES "$(SBX_FILES)" \ |
| 159 | + $(SCRIPTS)/ldf.xsl $(SCRIPTS)/project.ldf > $@ |
| 160 | + |
| 161 | +project/project_project.bit: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).ldf $(VERILOG_FILES) $(VHDL_FILES) |
| 162 | + echo prj_project open $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).ldf \; prj_run Export -task Bitgen | ${DIAMONDC} |
| 163 | + |
| 164 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit: project/project_project.bit |
| 165 | + ln -sf project/project_project.bit $@ |
| 166 | + |
| 167 | +$(CLK0_FILE_NAME): |
| 168 | + LANG=C LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPLL) $(CLK0_OPTIONS) --file $@ |
| 169 | + |
| 170 | +$(CLK1_FILE_NAME): |
| 171 | + LANG=C LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPLL) $(CLK1_OPTIONS) --file $@ |
| 172 | + |
| 173 | +$(CLK2_FILE_NAME): |
| 174 | + LANG=C LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPLL) $(CLK2_OPTIONS) --file $@ |
| 175 | + |
| 176 | +$(CLK3_FILE_NAME): |
| 177 | + LANG=C LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPLL) $(CLK3_OPTIONS) --file $@ |
| 178 | + |
| 179 | +# generate sram programming XCF file for DDTCMD |
| 180 | +$(BOARD)_$(FPGA_SIZE)f.xcf: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit $(SCRIPTS)/$(BOARD)_sram.xcf $(SCRIPTS)/xcf.xsl |
| 181 | + xsltproc \ |
| 182 | + --stringparam FPGA_CHIP $(FPGA_CHIP_UPPERCASE) \ |
| 183 | + --stringparam CHIP_ID $(CHIP_ID) \ |
| 184 | + --stringparam BITSTREAM_FILE $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit \ |
| 185 | + $(SCRIPTS)/xcf.xsl $(SCRIPTS)/$(BOARD)_sram.xcf > $@ |
| 186 | + |
| 187 | +# run DDTCMD to generate sram VME file |
| 188 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).vme: $(BOARD)_$(FPGA_SIZE)f.xcf $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 189 | + LANG=C ${DDTCMD} -oft -fullvme -if $(BOARD)_$(FPGA_SIZE)f.xcf -nocompress -noheader -of $@ |
| 190 | + |
| 191 | +# run DDTCMD to generate SVF file |
| 192 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf: $(BOARD)_$(FPGA_SIZE)f.xcf $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 193 | + LANG=C ${DDTCMD} -oft -svfsingle -revd -maxdata 8 -if $(BOARD)_$(FPGA_SIZE)f.xcf -of $@ |
| 194 | + |
| 195 | +# run DDTCMD to generate flash MCS file |
| 196 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash.mcs: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 197 | + LANG=C ${DDTCMD} -dev $(FPGA_CHIP_UPPERCASE) \ |
| 198 | + -if $< -oft -int -quad $(FPGA_SPI) -of $@ |
| 199 | + |
| 200 | +# generate flash programming XCF file for DDTCMD |
| 201 | +$(BOARD)_$(FPGA_SIZE)f_flash_$(FLASH_CHIP).xcf: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit $(SCRIPTS)/$(BOARD)_flash_$(FLASH_CHIP).xcf $(SCRIPTS)/xcf.xsl |
| 202 | + xsltproc \ |
| 203 | + --stringparam FPGA_CHIP $(FPGA_CHIP_UPPERCASE) \ |
| 204 | + --stringparam CHIP_ID $(CHIP_ID) \ |
| 205 | + --stringparam MASK_FILE $(MASK_PATH)/$(MASK_FILE) \ |
| 206 | + --stringparam BITSTREAM_FILE $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash.mcs \ |
| 207 | + $(SCRIPTS)/xcf.xsl $(SCRIPTS)/$(BOARD)_flash_$(FLASH_CHIP).xcf > $@ |
| 208 | + |
| 209 | +# run DDTCMD to generate flash VME file |
| 210 | +$(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash_$(FLASH_CHIP).vme: $(BOARD)_$(FPGA_SIZE)f_flash_$(FLASH_CHIP).xcf $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash.mcs |
| 211 | + LANG=C ${DDTCMD} -oft -fullvme -if $(BOARD)_$(FPGA_SIZE)f_flash_$(FLASH_CHIP).xcf -nocompress -noheader -of $@ |
| 212 | + |
| 213 | +# generate SVF file by prjtrellis python script |
| 214 | +#$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 215 | +# $(BIT2SVF) $< $@ |
| 216 | + |
| 217 | +#$(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).config |
| 218 | +# LD_LIBRARY_PATH=$(LIBTRELLIS) $(ECPPACK) $(IDCODE_CHIPID) --db $(TRELLISDB) $< --freq 62.0 --svf-rowsize 8000 --svf $@ |
| 219 | + |
| 220 | +# program SRAM with ujrprog (temporary) |
| 221 | +prog: program |
| 222 | +program: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 223 | + $(UJPROG) $< |
| 224 | + |
| 225 | +# program SRAM with OPENFPGALOADER |
| 226 | +prog_ofl: program_ofl |
| 227 | +program_ofl: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 228 | + $(OPENFPGALOADER) $(OPENFPGALOADER_OPTIONS) $< |
| 229 | + |
| 230 | +# program SRAM with FleaFPGA-JTAG (temporary) |
| 231 | +program_flea: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).vme |
| 232 | + $(FLEAFPGA_JTAG) $< |
| 233 | + |
| 234 | +# program FLASH over US1 port with ujprog (permanently) |
| 235 | +flash: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 236 | + $(UJPROG) -j flash $< |
| 237 | + |
| 238 | +# program FLASH uver US1 with FleaFPGA-JTAG (permanent) |
| 239 | +flash_flea: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash_$(FLASH_CHIP).vme |
| 240 | + $(FLEAFPGA_JTAG) $< |
| 241 | + |
| 242 | +# program FLASH over US2 port with DFU bootloader (permanently) |
| 243 | +flash_dfu: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 244 | + $(DFU_UTIL) -a 0 -D $< |
| 245 | + $(DFU_UTIL) -a 0 -e |
| 246 | + |
| 247 | +# program FLASH over US2 port with tinyfpgasp bootloader (permanently) |
| 248 | +flash_tiny: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 249 | + $(TINYFPGASP) -w $< |
| 250 | + |
| 251 | +# generate chip-specific openocd programming file |
| 252 | +$(BOARD)_$(FPGA_SIZE)f.ocd: $(SCRIPTS)/ecp5-ocd.sh |
| 253 | + $(SCRIPTS)/ecp5-ocd.sh $(CHIP_ID) $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf > $@ |
| 254 | + |
| 255 | +# program SRAM with OPENOCD |
| 256 | +prog_ocd: program_ocd |
| 257 | +program_ocd: $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf $(BOARD)_$(FPGA_SIZE)f.ocd |
| 258 | + $(OPENOCD) --file=$(OPENOCD_INTERFACE) --file=$(BOARD)_$(FPGA_SIZE)f.ocd |
| 259 | + |
| 260 | +JUNK = *~ |
| 261 | +#JUNK += $(PROJECT).ys |
| 262 | +JUNK += $(PROJECT).json |
| 263 | +JUNK += $(VHDL_TO_VERILOG_FILES) |
| 264 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).config |
| 265 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).ldf |
| 266 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).bit |
| 267 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).vme |
| 268 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT).svf |
| 269 | +JUNK += $(BOARD)_$(FPGA_SIZE)f.xcf |
| 270 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash.mcs |
| 271 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_flash_$(FLASH_CHIP).xcf |
| 272 | +JUNK += $(BOARD)_$(FPGA_SIZE)f_$(PROJECT)_flash_$(FLASH_CHIP).vme |
| 273 | +JUNK += $(BOARD)_$(FPGA_SIZE)f.ocd |
| 274 | +JUNK += $(CLK0_FILE_NAME) $(CLK1_FILE_NAME) $(CLK2_FILE_NAME) $(CLK3_FILE_NAME) |
| 275 | +# diamond junk |
| 276 | +JUNK += ${IMPL_DIR} .recovery ._Real_._Math_.vhd *.sty reportview.xml |
| 277 | +JUNK += dummy_sym.sort project_tcl.html promote.xml .run_manager.ini |
| 278 | +JUNK += generate_core.tcl generate_ngd.tcl msg_file.log |
| 279 | + |
| 280 | +JUNK_DIR = project |
| 281 | +JUNK_DIR += project_tcr.dir |
| 282 | + |
| 283 | +clean: |
| 284 | + rm -rf $(JUNK_DIR) |
| 285 | + rm -f $(JUNK) |
0 commit comments