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)
34 PRJ := lx_rocon_top.prj
36 SEARCH_DIRS := ipcore_dir
40 #===============================================================================
41 # Abbreviations of frequently used file names.
46 NCD_MAP := $(OUTB)_map.ncd
51 REQ_NGC := $(REQB).ngc
52 REQ_NGD := $(REQB).ngd
53 REQ_PCF := $(REQB).pcf
54 REQ_NCD_MAP := $(REQB)_map.ncd
55 REQ_NCD := $(REQB).ncd
56 REQ_BIN := $(REQB).bin
57 REQ_PKG := $(REQB).pkg
60 REQ_FIRMWARE := $(OUT)/imem.bin $(OUT)/imem.asm $(OUT)/dmem.bin $(OUT)/firmware.lst
62 #===============================================================================
63 # Sythesis settings (SmartXplorer)
65 XST_GLOB_OPT := AllClockNets
68 XST_IOB_PACKING := False
70 XST_KEEP_HIEARCHY := No
71 XST_NETLIST_HIEARCHY := As_Optimized
73 XST_WRITE_TIMING_CONSTRAINTS := NO
74 XST_CROSS_CLOCK_ANALYSIS := NO
76 XST_REDUCE_CONTROL_SETS := Auto
77 XST_REGISTER_DUPLICATION := YES
78 XST_REGISTER_BALANCING := Yes
79 XST_MOVE_FIRST_STAGE := YES
80 XST_MOVE_LAST_STAGE := YES
81 XST_OPTIMIZE_PRIMITIVES := NO
82 XST_USE_CLOCK_ENABLE := AUTO
83 XST_EQUIVALENT_REGISTER_REMOVAL := YES
85 XST_MAX_FANOUT := 100000
86 XST_RESOURCE_SHARING := YES
87 XST_SLICE_UTILIZATION_RATIO_MARGIN := 5
88 XST_SLICE_UTILIZATION_RATIO := 100
89 XST_BRAM_UTILIZATION_RATIO := 100
90 XST_DSP_UTILIZATION_RATIO := 100
92 XST_USE_SYNC_SET := Auto
93 XST_USE_SYNC_RESET := Auto
94 XST_SAFE_IMPLEMENTATION := No
96 MAP_PLACER_COST_TABLE := 2
99 MAP_EQUIVALENT_REGISTER_REMOVAL := off
100 MAP_LUT_COMBINING := off
102 #===============================================================================
105 MB_CROSS_COMPILE ?= mbtumbl-elf-
106 TARGET_CC := $(MB_CROSS_COMPILE)gcc
107 TARGET_LD := $(MB_CROSS_COMPILE)ld
108 TARGET_OBJCOPY := $(MB_CROSS_COMPILE)objcopy
109 TARGET_OBJDUMP := $(MB_CROSS_COMPILE)objdump
111 C_OBJS := $(OUT)/firmware.o
113 CFLAGS := -mxl-soft-div -msoft-float -Wno-main -Wl,-no-check-sections -ffunction-sections -fno-zero-initialized-in-bss -g -O2 -Wall
114 AFLAGS := -D__ASSEMBLY__ $(CFLAGS)
115 LDFLAGS := -static -nostdlib -relax -defsym _STACK_SIZE=0x0200 --gc-sections
117 OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
119 FIRMWARE_DIR := ./lx-rocon_firmware
121 #===============================================================================
123 # Attempt to create a output directory.
124 $(shell [ -d ${OUT} ] || mkdir -p ${OUT})
126 # Verify if it was successful.
127 OUTPUT_DIR := $(shell cd $(OUT) && /bin/pwd)
128 $(if $(OUTPUT_DIR),,$(error output directory "$(OUT)" does not exist))
130 #===============================================================================
135 .PHONY: re-synthesize
136 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
140 $(addprefix -ifn $(SRC)/,$(PRJ)) \
146 -keep_hierarchy $(XST_KEEP_HIEARCHY) \
147 -glob_opt $(XST_GLOB_OPT) \
148 -opt_mode $(XST_OPT_MODE) \
149 -opt_level $(XST_OPT_LEVEL) \
150 -power $(XST_POWER) \
151 -iob $(XST_IOB_PACKING) \
152 -read_cores $(XST_READ_CORES) \
153 -write_timing_constraints $(XST_WRITE_TIMING_CONSTRAINTS) \
154 -cross_clock_analysis $(XST_CROSS_CLOCK_ANALYSIS) \
156 -reduce_control_sets $(XST_REDUCE_CONTROL_SETS) \
157 -resource_sharing $(XST_RESOURCE_SHARING) \
158 -iobuf $(XST_IOBUF) \
159 -max_fanout $(XST_MAX_FANOUT) \
160 -register_duplication $(XST_REGISTER_DUPLICATION) \
161 -register_balancing $(XST_REGISTER_BALANCING) \
162 -move_first_stage $(XST_MOVE_FIRST_STAGE) \
163 -move_last_stage $(XST_MOVE_LAST_STAGE) \
164 -optimize_primitives $(XST_OPTIMIZE_PRIMITIVES) \
165 -use_clock_enable $(XST_USE_CLOCK_ENABLE) \
166 -equivalent_register_removal $(XST_EQUIVALENT_REGISTER_REMOVAL) \
167 -slice_utilization_ratio_maxmargin $(XST_SLICE_UTILIZATION_RATIO_MARGIN) \
168 -slice_utilization_ratio $(XST_SLICE_UTILIZATION_RATIO) \
169 -bram_utilization_ratio $(XST_BRAM_UTILIZATION_RATIO) \
170 -dsp_utilization_ratio $(XST_DSP_UTILIZATION_RATIO)" | xst | tee xst.log
173 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
175 ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -nt timestamp -uc $(SRC)/$(UCF) \
176 $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
181 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
183 map -w -intstyle $(INTSTYLE) -p $(DEVICE) -logic_opt $(MAP_LOGIC_OPT) -ol high -t $(MAP_PLACER_COST_TABLE) -xt 0 \
184 -r 4 -global_opt $(MAP_GLOBAL_OPT) -mt off -ir off -pr off -lc $(MAP_LUT_COMBINING) \
185 -power off -equivalent_register_removal $(MAP_EQUIVALENT_REGISTER_REMOVAL) \
186 -o $(NCD_MAP) $(NGD) $(PCF) | tee map.log
189 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
191 par -w -intstyle $(INTSTYLE) -ol high -xe n -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
194 re-gen $(REQ_BIN): $(REQ_NCD)
196 bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
199 packager $(OUT)/packager:
200 gcc packager.c -o $(OUT)/packager
203 re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
205 ./packager le $(BIN) $(PKG)
207 $(OUT)/%.o: $(FIRMWARE_DIR)/%.c
208 $(TARGET_CC) $(CFLAGS) -c $< -o $@
210 $(OUT)/%.o: $(FIRMWARE_DIR)/%.S
211 $(TARGET_CC) $(AFLAGS) -c $< -o $@
213 $(OUT)/firmware.elf: $(OBJS)
214 $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
216 $(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
220 re-firmware $(REQ_FIRMWARE): $(REQ_PKG) $(OUT)/bin2mem $(OUT)/firmware.elf
221 $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .text -S $(OUT)/imem.bin
222 $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .data -S $(OUT)/dmem.bin
223 $(TARGET_OBJDUMP) -DSCz $(OUT)/firmware.elf >$(OUT)/firmware.lst
225 $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
228 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80000000 -l 0x200 -f dump -u -
230 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80001000 -l 0x200 -f dump -u -
232 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80003008 -l 0x4 -f dump -u -
234 #===============================================================================
241 synthesize: $(REQ_NGC)
244 translate: $(REQ_NGD)
247 map: $(REQ_NCD_MAP) $(REQ_PCF)
256 pkg: $(OUT)/packager $(REQ_PKG)
259 firmware: $(REQ_FIRMWARE)