]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - hw/Makefile
Setup tumble specific tool-chain for firmware build.
[fpga/lx-cpu1/lx-rocon.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_rocon_top
31 OUT    := _build
32 OUTB   := lx-rocon
33 REQB   := $(OUT)/$(OUTB)
34 PRJ    := lx_rocon_top.prj
35 UCF    := lx-rocon.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
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
58 REQ_SRC            := .
59
60 REQ_FIRMWARE       := $(OUT)/imem.bin $(OUT)/imem.asm $(OUT)/dmem.bin $(OUT)/firmware.lst
61
62 #===============================================================================
63 # Sythesis settings (SmartXplorer)
64
65 XST_GLOB_OPT := AllClockNets
66 XST_OPT_LEVEL := 2
67 XST_OPT_MODE := Speed
68 XST_IOB_PACKING := False
69 XST_POWER := NO
70 XST_KEEP_HIEARCHY := No
71 XST_NETLIST_HIEARCHY := As_Optimized
72 XST_READ_CORES := YES
73 XST_WRITE_TIMING_CONSTRAINTS := NO
74 XST_CROSS_CLOCK_ANALYSIS := NO
75 XST_CASE := Maintain
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
84 XST_IOBUF := 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
91 XST_USE_DSP48 := Auto
92 XST_USE_SYNC_SET := Auto
93 XST_USE_SYNC_RESET := Auto
94 XST_SAFE_IMPLEMENTATION := No
95
96 MAP_PLACER_COST_TABLE := 2
97 MAP_LOGIC_OPT := on
98 MAP_GLOBAL_OPT := off
99 MAP_EQUIVALENT_REGISTER_REMOVAL := off
100 MAP_LUT_COMBINING := off
101
102 #===============================================================================
103 # Firmware
104
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
110
111 C_OBJS := $(OUT)/firmware.o
112 A_OBJS :=
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
116
117 OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
118
119 FIRMWARE_DIR := ./lx-rocon_firmware
120
121 #===============================================================================
122
123 # Attempt to create a output directory.
124 $(shell [ -d ${OUT} ] || mkdir -p ${OUT})
125
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))
129
130 #===============================================================================
131
132 .PHONY: all
133 all: pkg firmware
134
135 .PHONY: re-synthesize
136 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
137         cd $(OUT); \
138         echo " \
139           run \
140           $(addprefix -ifn $(SRC)/,$(PRJ)) \
141           -ifmt mixed \
142           -ofn $(NGC) \
143           -ofmt NGC \
144           -top $(TOP) \
145           -p $(DEVICE) \
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) \
155           -case $(XST_CASE) \
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
171
172 .PHONY: re-translate
173 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
174         cd $(OUT); \
175         ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -nt timestamp -uc $(SRC)/$(UCF) \
176           $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
177           $(NGC) \
178           $(NGD)
179
180 .PHONY: re-map
181 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
182         cd $(OUT); \
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
187
188 .PHONY: re-par
189 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
190         cd $(OUT); \
191         par -w -intstyle $(INTSTYLE) -ol high -xe n -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
192
193 .PHONY: re-gen
194 re-gen $(REQ_BIN): $(REQ_NCD)
195         cd $(OUT); \
196         bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
197
198 .PHONY: packager
199 packager $(OUT)/packager:
200         gcc packager.c -o $(OUT)/packager
201
202 .PHONY: re-pkg
203 re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
204         cd $(OUT); \
205         ./packager le $(BIN) $(PKG)
206
207 $(OUT)/%.o: $(FIRMWARE_DIR)/%.c
208         $(TARGET_CC) $(CFLAGS) -c $< -o $@
209
210 $(OUT)/%.o: $(FIRMWARE_DIR)/%.S
211         $(TARGET_CC) $(AFLAGS) -c $< -o $@
212
213 $(OUT)/firmware.elf: $(OBJS)
214         $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
215
216 $(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
217         gcc $< -o $@
218
219 .PHONY: re-firmware
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
224         cd $(OUT); \
225         $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
226
227 # imem
228 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80000000 -l 0x200 -f dump -u -
229 # dmem
230 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80001000 -l 0x200 -f dump -u -
231 # PC
232 # watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80003008 -l 0x4 -f dump -u -
233
234 #===============================================================================
235
236 .PHONY: clean
237 clean:
238         rm -rf $(OUT)
239
240 .PHONY: synthesize
241 synthesize: $(REQ_NGC)
242
243 .PHONY: translate
244 translate: $(REQ_NGD)
245
246 .PHONY: map
247 map: $(REQ_NCD_MAP) $(REQ_PCF)
248
249 .PHONY: par
250 par: $(REQ_NCD)
251
252 .PHONY: gen
253 gen: $(REQ_BIN)
254
255 .PHONY: pkg
256 pkg: $(OUT)/packager $(REQ_PKG)
257
258 .PHONY: firmware
259 firmware: $(REQ_FIRMWARE)