]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - hw/Makefile
Clean DAD test code a little to use symbolic names for registers and bits.
[fpga/lx-cpu1/lx-dad.git] / hw / Makefile
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, ...).
6 #                 See NGDBUILD manual.
7 # INTSTYLE      - Style of screen output. (ise | xflow | silent)
8
9 # Targets desctiption:
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
25
26 # Dependicies are handled, so in most cases only 'download' target is called.
27
28 DEVICE := xc6slx9-2tqg144
29
30 TOP    := lx_dad_top
31 OUT    := _build
32 OUTB   := lx-dad
33 REQB   := $(OUT)/$(OUTB)
34 PRJ    := lx_dad_top.prj
35 UCF    := lx-dad.ucf
36 SEARCH_DIRS := ipcore_dir
37 INTSTYLE    := xflow
38 SRC         := ..
39
40 #===============================================================================
41 # Abbreviations of frequently used file names.
42
43 NGC            := $(OUTB).ngc
44 NGD            := $(OUTB).ngd
45 PCF            := $(OUTB).pcf
46 NCD_MAP        := $(OUTB)_map.ncd
47 NCD            := $(OUTB).ncd
48 BIN            := $(OUTB).bin
49 PKG            := $(OUTB).pkg
50 TWR            := $(OUTB).twr
51 TSI            := $(OUTB).tsi
52
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
60 REQ_SRC            := .
61
62 #REQ_FIRMWARE       := $(OUT)/imem.bin $(OUT)/imem.asm $(OUT)/dmem.bin $(OUT)/firmware.lst
63
64 #===============================================================================
65 # Sythesis settings (SmartXplorer)
66
67 XST_GLOB_OPT := AllClockNets
68 XST_OPT_LEVEL := 2
69 XST_OPT_MODE := Speed
70 XST_IOB_PACKING := False
71 XST_POWER := NO
72 XST_KEEP_HIEARCHY := No
73 XST_NETLIST_HIEARCHY := As_Optimized
74 XST_READ_CORES := YES
75 XST_WRITE_TIMING_CONSTRAINTS := NO
76 XST_CROSS_CLOCK_ANALYSIS := NO
77 XST_CASE := Maintain
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
86 XST_IOBUF := 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
93 XST_USE_DSP48 := Auto
94 XST_USE_SYNC_SET := Auto
95 XST_USE_SYNC_RESET := Auto
96 XST_SAFE_IMPLEMENTATION := No
97
98 MAP_PLACER_COST_TABLE := 2
99 MAP_LOGIC_OPT := on
100 MAP_GLOBAL_OPT := off
101 MAP_EQUIVALENT_REGISTER_REMOVAL := off
102 MAP_LUT_COMBINING := off
103
104 #===============================================================================
105 # Firmware
106
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
112
113 C_OBJS := $(OUT)/firmware.o
114 A_OBJS :=
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
118
119 OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
120
121 FIRMWARE_DIR := ./lx-dad_firmware
122
123 #===============================================================================
124
125 # Attempt to create a output directory.
126 $(shell [ -d ${OUT} ] || mkdir -p ${OUT})
127
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))
131
132 #===============================================================================
133
134 .PHONY: all
135 all: pkg firmware
136
137 .PHONY: re-synthesize
138 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
139         cd $(OUT); \
140         echo " \
141           run \
142           $(addprefix -ifn $(SRC)/,$(PRJ)) \
143           -ifmt mixed \
144           -ofn $(NGC) \
145           -ofmt NGC \
146           -top $(TOP) \
147           -p $(DEVICE) \
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) \
157           -case $(XST_CASE) \
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
173
174 .PHONY: re-translate
175 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
176         cd $(OUT); \
177         ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -nt timestamp -uc $(SRC)/$(UCF) \
178           $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
179           $(NGC) \
180           $(NGD)
181
182 .PHONY: re-map
183 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
184         cd $(OUT); \
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
189
190 .PHONY: re-par
191 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
192         cd $(OUT); \
193         par -w -intstyle $(INTSTYLE) -ol high -xe n -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
194         cd $(OUT); \
195         trce -e 20 -tsi $(TSI) -o $(TWR) $(NCD) $(PCF)
196
197 .PHONY: re-gen
198 re-gen $(REQ_BIN): $(REQ_NCD)
199         cd $(OUT); \
200         bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
201
202 .PHONY: packager
203 packager $(OUT)/packager:
204         gcc packager.c -o $(OUT)/packager
205
206 .PHONY: re-pkg
207 re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
208         cd $(OUT); \
209         ./packager le $(BIN) $(PKG)
210
211 $(OUT)/%.o: $(FIRMWARE_DIR)/%.c
212         $(TARGET_CC) $(CFLAGS) -c $< -o $@
213
214 $(OUT)/%.o: $(FIRMWARE_DIR)/%.S
215         $(TARGET_CC) $(AFLAGS) -c $< -o $@
216
217 $(OUT)/firmware.elf: $(OBJS)
218         $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
219
220 $(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
221         gcc $< -o $@
222
223 .PHONY: re-firmware
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
228         cd $(OUT); \
229         $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
230
231 # imem
232 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80000000 -l 0x200 -f dump -u -
233 # dmem
234 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80001000 -l 0x200 -f dump -u -
235 # PC
236 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80003008 -l 0x4 -f dump -u -
237
238 #===============================================================================
239
240 .PHONY: clean
241 clean:
242         rm -rf $(OUT)
243
244 .PHONY: synthesize
245 synthesize: $(REQ_NGC)
246
247 .PHONY: translate
248 translate: $(REQ_NGD)
249
250 .PHONY: map
251 map: $(REQ_NCD_MAP) $(REQ_PCF)
252
253 .PHONY: par
254 par: $(REQ_NCD)
255
256 .PHONY: gen
257 gen: $(REQ_BIN)
258
259 .PHONY: pkg
260 pkg: $(OUT)/packager $(REQ_PKG)
261
262 .PHONY: firmware
263 firmware: $(REQ_FIRMWARE)