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