]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - hw/Makefile
d2706c416b1fe1c4ef264fb11b2600729b6cee4d
[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
64
65 MAP_LOGIC_OPT := on
66 MAP_GLOBAL_OPT := off
67 MAP_EQUIVALENT_REGISTER_REMOVAL := off
68 MAP_LUT_COMBINING := off
69
70 #===============================================================================
71 # Firmware
72
73 MB_CROSS_COMPILE ?= mb-
74 TARGET_CC := $(MB_CROSS_COMPILE)gcc
75 TARGET_LD := $(MB_CROSS_COMPILE)ld
76 TARGET_OBJCOPY := $(MB_CROSS_COMPILE)objcopy
77 TARGET_OBJDUMP := $(MB_CROSS_COMPILE)objdump
78
79 C_OBJS := $(OUT)/firmware.o
80 A_OBJS :=
81 CFLAGS := -mxl-soft-div -msoft-float -mno-xl-soft-mul -mxl-barrel-shift -Wno-main -Wl,-no-check-sections -fno-zero-initialized-in-bss -g -O2 -Wall
82 AFLAGS := -D__ASSEMBLY__ $(CFLAGS)
83 LDFLAGS := -static -nostdlib -defsym _STACK_SIZE=0x0200
84
85 OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
86
87 FIRMWARE_DIR := ./lx-rocon_firmware
88
89 #===============================================================================
90
91 # Attempt to create a output directory.
92 $(shell [ -d ${OUT} ] || mkdir -p ${OUT})
93
94 # Verify if it was successful.
95 OUTPUT_DIR := $(shell cd $(OUT) && /bin/pwd)
96 $(if $(OUTPUT_DIR),,$(error output directory "$(OUT)" does not exist))
97
98 #===============================================================================
99
100 .PHONY: all
101 all: pkg firmware
102
103 .PHONY: re-synthesize
104 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
105         cd $(OUT); \
106         echo " \
107           run \
108           $(addprefix -ifn $(SRC)/,$(PRJ)) \
109           -ifmt mixed \
110           -ofn $(NGC) \
111           -ofmt NGC \
112           -top $(TOP) \
113           -p $(DEVICE) \
114           -opt_mode Speed \
115           -keep_hierarchy soft \
116           -opt_level 1" | xst | tee xst.log
117
118 .PHONY: re-translate
119 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
120         cd $(OUT); \
121         ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -uc $(SRC)/$(UCF) \
122           $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
123           $(NGC) \
124           $(NGD)
125
126 .PHONY: re-map
127 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
128         cd $(OUT); \
129         map -w -intstyle $(INTSTYLE) -p $(DEVICE) -logic_opt $(MAP_LOGIC_OPT) -ol high -t 1 -xt 0 \
130           -r 4 -global_opt $(MAP_GLOBAL_OPT) -mt off -ir off -pr off -lc $(MAP_LUT_COMBINING) \
131           -power off -equivalent_register_removal $(MAP_EQUIVALENT_REGISTER_REMOVAL) \
132           -o $(NCD_MAP) $(NGD) $(PCF) | tee map.log
133
134 .PHONY: re-par
135 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
136         cd $(OUT); \
137         par -w -intstyle $(INTSTYLE) -ol high -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
138
139 .PHONY: re-gen
140 re-gen $(REQ_BIN): $(REQ_NCD)
141         cd $(OUT); \
142         bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
143
144 .PHONY: packager
145 packager $(OUT)/packager:
146         gcc packager.c -o $(OUT)/packager
147
148 .PHONY: re-pkg
149 re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
150         cd $(OUT); \
151         ./packager le $(BIN) $(PKG)
152
153 $(OUT)/%.o: $(FIRMWARE_DIR)/%.c
154         $(TARGET_CC) $(CFLAGS) -c $< -o $@
155
156 $(OUT)/%.o: $(FIRMWARE_DIR)/%.S
157         $(TARGET_CC) $(AFLAGS) -c $< -o $@
158
159 $(OUT)/firmware.elf: $(OBJS)
160         $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
161
162 $(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
163         gcc $< -o $@
164
165 .PHONY: re-firmware
166 re-firmware $(REQ_FIRMWARE): $(REQ_PKG) $(OUT)/bin2mem $(OUT)/firmware.elf
167         $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .text -S $(OUT)/imem.bin
168         $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .data -S $(OUT)/dmem.bin
169         $(TARGET_OBJDUMP) -DSCz $(OUT)/firmware.elf > $@
170         cd $(OUT); \
171         $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
172
173 #===============================================================================
174
175 .PHONY: clean
176 clean:
177         rm -rf $(OUT)
178
179 .PHONY: synthesize
180 synthesize: $(REQ_NGC)
181
182 .PHONY: translate
183 translate: $(REQ_NGD)
184
185 .PHONY: map
186 map: $(REQ_NCD_MAP) $(REQ_PCF)
187
188 .PHONY: par
189 par: $(REQ_NCD)
190
191 .PHONY: gen
192 gen: $(REQ_BIN)
193
194 .PHONY: pkg
195 pkg: $(OUT)/packager $(REQ_PKG)
196
197 .PHONY: firmware
198 firmware: $(REQ_FIRMWARE)