1 # TOP - Name of the top-level module
2 # DEVICE - Name of the FPGA device (device-package-speed)
3 # PRJ - Name of .prj file with names of all source files. See XST manual.
4 # UCF - Name of the user constraints file
5 # SEARCH_DIRS - Directories to search when searching for netlists (.ngc, ...).
7 # INTSTYLE - Style of screen output. (ise | xflow | silent)
10 # - synthesize : Synthesize all VHDL and Verilog source files, libraries, etc.
11 # defined in PRJ files and produces NGC file.
12 # - translate : Translate all netlist files (.ngc, ...) into the NGD file,
13 # where the design is described in terms of deneral logic elements
14 # such as (RAM, flip-flop, XOR, ...).
15 # - map : Map the general logic from NGD file to the components in the
16 # target FPGA and produces NCD_MAP file.
17 # - par : PAR stands for Plase & Route. This procedure takes NCD_MAP file,
18 # places all components and makes routes between them (depending
19 # on the chosen optimization mode) and produces NCD file.
20 # - clean : Clean build directory, dependency (*.d) files and call
21 # - gen : Transfer placed and routed NCD file into the bin file, which can
22 # be then used to configure particular FPGA (this is further packaged
23 # for SelectMap interface via the ARM CPU)
24 # - firmware : Builds the firmware for Tumbl core
26 # Dependicies are handled, so in most cases only 'download' target is called.
28 DEVICE := xc6slx9-2tqg144
33 REQB := $(OUT)/$(OUTB)
36 SEARCH_DIRS := ipcore_dir
40 #===============================================================================
41 # Abbreviations of frequently used file names.
46 NCD_MAP := $(OUTB)_map.ncd
53 REQ_NGC := $(REQB).ngc
54 REQ_NGD := $(REQB).ngd
55 REQ_PCF := $(REQB).pcf
56 REQ_NCD_MAP := $(REQB)_map.ncd
57 REQ_NCD := $(REQB).ncd
58 REQ_BIN := $(REQB).bin
59 REQ_PKG := $(REQB).pkg
62 #REQ_FIRMWARE := $(OUT)/imem.bin $(OUT)/imem.asm $(OUT)/dmem.bin $(OUT)/firmware.lst
64 #===============================================================================
65 # Sythesis settings (SmartXplorer)
67 XST_GLOB_OPT := AllClockNets
70 XST_IOB_PACKING := False
72 XST_KEEP_HIEARCHY := No
73 XST_NETLIST_HIEARCHY := As_Optimized
75 XST_WRITE_TIMING_CONSTRAINTS := NO
76 XST_CROSS_CLOCK_ANALYSIS := NO
78 XST_REDUCE_CONTROL_SETS := Auto
79 XST_REGISTER_DUPLICATION := YES
80 XST_REGISTER_BALANCING := Yes
81 XST_MOVE_FIRST_STAGE := YES
82 XST_MOVE_LAST_STAGE := YES
83 XST_OPTIMIZE_PRIMITIVES := NO
84 XST_USE_CLOCK_ENABLE := AUTO
85 XST_EQUIVALENT_REGISTER_REMOVAL := YES
87 XST_MAX_FANOUT := 100000
88 XST_RESOURCE_SHARING := YES
89 XST_SLICE_UTILIZATION_RATIO_MARGIN := 5
90 XST_SLICE_UTILIZATION_RATIO := 100
91 XST_BRAM_UTILIZATION_RATIO := 100
92 XST_DSP_UTILIZATION_RATIO := 100
94 XST_USE_SYNC_SET := Auto
95 XST_USE_SYNC_RESET := Auto
96 XST_SAFE_IMPLEMENTATION := No
98 MAP_PLACER_COST_TABLE := 2
100 MAP_GLOBAL_OPT := off
101 MAP_EQUIVALENT_REGISTER_REMOVAL := off
102 MAP_LUT_COMBINING := off
104 #===============================================================================
107 MB_CROSS_COMPILE ?= mbtumbl-elf-
108 TARGET_CC := $(MB_CROSS_COMPILE)gcc
109 TARGET_LD := $(MB_CROSS_COMPILE)ld
110 TARGET_OBJCOPY := $(MB_CROSS_COMPILE)objcopy
111 TARGET_OBJDUMP := $(MB_CROSS_COMPILE)objdump
113 C_OBJS := $(OUT)/firmware.o
115 CFLAGS := -mxl-soft-div -msoft-float -Wno-main -Wl,-no-check-sections -ffunction-sections -fno-zero-initialized-in-bss -g -O2 -Wall
116 AFLAGS := -D__ASSEMBLY__ $(CFLAGS)
117 LDFLAGS := -static -nostdlib -relax -defsym _STACK_SIZE=0x0200 --gc-sections
119 OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
121 FIRMWARE_DIR := ./lx-dad_firmware
123 #===============================================================================
125 # Attempt to create a output directory.
126 $(shell [ -d ${OUT} ] || mkdir -p ${OUT})
128 # Verify if it was successful.
129 OUTPUT_DIR := $(shell cd $(OUT) && /bin/pwd)
130 $(if $(OUTPUT_DIR),,$(error output directory "$(OUT)" does not exist))
132 #===============================================================================
137 .PHONY: re-synthesize
138 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
142 $(addprefix -ifn $(SRC)/,$(PRJ)) \
148 -keep_hierarchy $(XST_KEEP_HIEARCHY) \
149 -glob_opt $(XST_GLOB_OPT) \
150 -opt_mode $(XST_OPT_MODE) \
151 -opt_level $(XST_OPT_LEVEL) \
152 -power $(XST_POWER) \
153 -iob $(XST_IOB_PACKING) \
154 -read_cores $(XST_READ_CORES) \
155 -write_timing_constraints $(XST_WRITE_TIMING_CONSTRAINTS) \
156 -cross_clock_analysis $(XST_CROSS_CLOCK_ANALYSIS) \
158 -reduce_control_sets $(XST_REDUCE_CONTROL_SETS) \
159 -resource_sharing $(XST_RESOURCE_SHARING) \
160 -iobuf $(XST_IOBUF) \
161 -max_fanout $(XST_MAX_FANOUT) \
162 -register_duplication $(XST_REGISTER_DUPLICATION) \
163 -register_balancing $(XST_REGISTER_BALANCING) \
164 -move_first_stage $(XST_MOVE_FIRST_STAGE) \
165 -move_last_stage $(XST_MOVE_LAST_STAGE) \
166 -optimize_primitives $(XST_OPTIMIZE_PRIMITIVES) \
167 -use_clock_enable $(XST_USE_CLOCK_ENABLE) \
168 -equivalent_register_removal $(XST_EQUIVALENT_REGISTER_REMOVAL) \
169 -slice_utilization_ratio_maxmargin $(XST_SLICE_UTILIZATION_RATIO_MARGIN) \
170 -slice_utilization_ratio $(XST_SLICE_UTILIZATION_RATIO) \
171 -bram_utilization_ratio $(XST_BRAM_UTILIZATION_RATIO) \
172 -dsp_utilization_ratio $(XST_DSP_UTILIZATION_RATIO)" | xst | tee xst.log
175 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
177 ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -nt timestamp -uc $(SRC)/$(UCF) \
178 $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
183 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
185 map -w -intstyle $(INTSTYLE) -p $(DEVICE) -logic_opt $(MAP_LOGIC_OPT) -ol high -t $(MAP_PLACER_COST_TABLE) -xt 0 \
186 -r 4 -global_opt $(MAP_GLOBAL_OPT) -mt off -ir off -pr off -lc $(MAP_LUT_COMBINING) \
187 -power off -equivalent_register_removal $(MAP_EQUIVALENT_REGISTER_REMOVAL) \
188 -o $(NCD_MAP) $(NGD) $(PCF) | tee map.log
191 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
193 par -w -intstyle $(INTSTYLE) -ol high -xe n -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
195 trce -e 20 -tsi $(TSI) -o $(TWR) $(NCD) $(PCF)
198 re-gen $(REQ_BIN): $(REQ_NCD)
200 bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
203 packager $(OUT)/packager:
204 gcc packager.c -o $(OUT)/packager
207 re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
209 ./packager le $(BIN) $(PKG)
211 $(OUT)/%.o: $(FIRMWARE_DIR)/%.c
212 $(TARGET_CC) $(CFLAGS) -c $< -o $@
214 $(OUT)/%.o: $(FIRMWARE_DIR)/%.S
215 $(TARGET_CC) $(AFLAGS) -c $< -o $@
217 $(OUT)/firmware.elf: $(OBJS)
218 $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
220 $(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
224 re-firmware $(REQ_FIRMWARE): $(REQ_PKG) $(OUT)/bin2mem $(OUT)/firmware.elf
225 $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .text -S $(OUT)/imem.bin
226 $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .data -S $(OUT)/dmem.bin
227 $(TARGET_OBJDUMP) -DSCz $(OUT)/firmware.elf >$(OUT)/firmware.lst
229 $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
232 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80000000 -l 0x200 -f dump -u -
234 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80001000 -l 0x200 -f dump -u -
236 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80003008 -l 0x4 -f dump -u -
238 #===============================================================================
245 synthesize: $(REQ_NGC)
248 translate: $(REQ_NGD)
251 map: $(REQ_NCD_MAP) $(REQ_PCF)
260 pkg: $(OUT)/packager $(REQ_PKG)
263 firmware: $(REQ_FIRMWARE)