1 |
2 |
alfik |
|
2 |
|
|
#########################################################################
|
3 |
|
|
####### M E M I N I T M A K E F I L E C O N T E N T ######
|
4 |
|
|
#########################################################################
|
5 |
|
|
|
6 |
|
|
#########################################################################
|
7 |
|
|
# This file is intended to be included by public.mk
|
8 |
|
|
#
|
9 |
|
|
#
|
10 |
|
|
# The following variables must be defined before including this file:
|
11 |
|
|
# - ELF
|
12 |
|
|
#
|
13 |
|
|
# The following variables may be defined to override the default behavior:
|
14 |
|
|
# - HDL_SIM_DIR
|
15 |
|
|
# - HDL_SIM_INSTALL_DIR
|
16 |
|
|
# - MEM_INIT_DIR
|
17 |
|
|
# - MEM_INIT_INSTALL_DIR
|
18 |
|
|
# - QUARTUS_PROJECT_DIR
|
19 |
|
|
# - SOPC_NAME
|
20 |
|
|
# - SIM_OPTIMIZE
|
21 |
|
|
# - RESET_ADDRESS
|
22 |
|
|
#
|
23 |
|
|
#########################################################################
|
24 |
|
|
|
25 |
|
|
ifeq ($(MEM_INIT_FILE),)
|
26 |
|
|
# MEM_INIT_FILE should be set equal to the working relative path to this
|
27 |
|
|
# mem_init.mk makefile fragment
|
28 |
|
|
MEM_INIT_FILE := $(wildcard $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
29 |
|
|
endif
|
30 |
|
|
|
31 |
|
|
ifeq ($(ELF2DAT),)
|
32 |
|
|
ELF2DAT := elf2dat
|
33 |
|
|
endif
|
34 |
|
|
|
35 |
|
|
ifeq ($(ELF2HEX),)
|
36 |
|
|
ELF2HEX := elf2hex
|
37 |
|
|
endif
|
38 |
|
|
|
39 |
|
|
ifeq ($(ELF2FLASH),)
|
40 |
|
|
ELF2FLASH := elf2flash
|
41 |
|
|
endif
|
42 |
|
|
|
43 |
|
|
ifeq ($(FLASH2DAT),)
|
44 |
|
|
FLASH2DAT := flash2dat
|
45 |
|
|
endif
|
46 |
|
|
|
47 |
|
|
ifeq ($(NM),)
|
48 |
|
|
NM := nios2-elf-nm
|
49 |
|
|
endif
|
50 |
|
|
|
51 |
|
|
ifeq ($(MKDIR),)
|
52 |
|
|
MKDIR := mkdir -p
|
53 |
|
|
endif
|
54 |
|
|
|
55 |
|
|
ifeq ($(RM),)
|
56 |
|
|
RM := rm -f
|
57 |
|
|
endif
|
58 |
|
|
|
59 |
|
|
ifeq ($(CP),)
|
60 |
|
|
CP := cp
|
61 |
|
|
endif
|
62 |
|
|
|
63 |
|
|
ifeq ($(ECHO),)
|
64 |
|
|
ECHO := echo
|
65 |
|
|
endif
|
66 |
|
|
|
67 |
|
|
MEM_INIT_DIR ?= mem_init
|
68 |
|
|
HDL_SIM_DIR ?= $(MEM_INIT_DIR)/hdl_sim
|
69 |
|
|
|
70 |
|
|
ifdef QUARTUS_PROJECT_DIR
|
71 |
|
|
MEM_INIT_INSTALL_DIR ?= $(patsubst %/,%,$(QUARTUS_PROJECT_DIR))
|
72 |
|
|
ifdef SOPC_NAME
|
73 |
|
|
HDL_SIM_INSTALL_DIR ?= $(patsubst %/,%,$(QUARTUS_PROJECT_DIR))/$(SOPC_NAME)_sim
|
74 |
|
|
endif
|
75 |
|
|
endif
|
76 |
|
|
|
77 |
|
|
MEM_INIT_DESCRIPTOR_FILE ?= $(MEM_INIT_DIR)/meminit.spd
|
78 |
|
|
|
79 |
|
|
MEM_INIT_QIP_FILE ?= $(MEM_INIT_DIR)/meminit.qip
|
80 |
|
|
|
81 |
|
|
#-------------------------------------
|
82 |
|
|
# Default Flash Boot Loaders
|
83 |
|
|
#-------------------------------------
|
84 |
|
|
|
85 |
|
|
BOOT_LOADER_PATH ?= $(SOPC_KIT_NIOS2)/components/altera_nios2
|
86 |
|
|
BOOT_LOADER_CFI ?= $(BOOT_LOADER_PATH)/boot_loader_cfi.srec
|
87 |
|
|
BOOT_LOADER_CFI_BE ?= $(BOOT_LOADER_PATH)/boot_loader_cfi_be.srec
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
#-------------------------------------
|
91 |
|
|
# Default Target
|
92 |
|
|
#-------------------------------------
|
93 |
|
|
|
94 |
|
|
.PHONY: default_mem_init
|
95 |
|
|
ifeq ($(QSYS),1)
|
96 |
|
|
default_mem_init: mem_init_generate
|
97 |
|
|
else
|
98 |
|
|
default_mem_init: mem_init_install
|
99 |
|
|
endif
|
100 |
|
|
#-------------------------------------
|
101 |
|
|
# Runtime Macros
|
102 |
|
|
#-------------------------------------
|
103 |
|
|
|
104 |
|
|
define post-process-info
|
105 |
|
|
@echo Post-processing to create $@...
|
106 |
|
|
endef
|
107 |
|
|
|
108 |
|
|
target_stem = $(notdir $(basename $@))
|
109 |
|
|
|
110 |
|
|
mem_start_address = $($(target_stem)_START)
|
111 |
|
|
mem_end_address = $($(target_stem)_END)
|
112 |
|
|
mem_width = $($(target_stem)_WIDTH)
|
113 |
|
|
mem_endianness = $($(target_stem)_ENDIANNESS)
|
114 |
|
|
mem_create_lanes = $($(target_stem)_CREATE_LANES)
|
115 |
|
|
|
116 |
|
|
mem_pad_flag = $($(target_stem)_PAD_FLAG)
|
117 |
|
|
mem_reloc_input_flag = $($(target_stem)_RELOC_INPUT_FLAG)
|
118 |
|
|
mem_no_zero_fill_flag = $($(target_stem)_NO_ZERO_FILL_FLAG)
|
119 |
|
|
|
120 |
|
|
flash_mem_epcs_flag = $($(target_stem)_EPCS_FLAGS)
|
121 |
|
|
flash_mem_cfi_flag = $($(target_stem)_CFI_FLAGS)
|
122 |
|
|
flash_mem_boot_loader_flag = $($(target_stem)_BOOT_LOADER_FLAG)
|
123 |
|
|
|
124 |
|
|
elf2dat_extra_args = $(mem_pad_flag)
|
125 |
|
|
elf2hex_extra_args = $(mem_no_zero_fill_flag)
|
126 |
|
|
elf2flash_extra_args = $(flash_mem_cfi_flag) $(flash_mem_epcs_flag) $(flash_mem_boot_loader_flag)
|
127 |
|
|
flash2dat_extra_args = $(mem_pad_flag) $(mem_reloc_input_flag)
|
128 |
|
|
|
129 |
|
|
#------------------------------------------------------------------------------
|
130 |
|
|
# BSP SPECIFIC CONTENT
|
131 |
|
|
#
|
132 |
|
|
# The content below is controlled by the BSP and SOPC System
|
133 |
|
|
#------------------------------------------------------------------------------
|
134 |
|
|
#START OF BSP SPECIFIC
|
135 |
|
|
|
136 |
|
|
#-------------------------------------
|
137 |
|
|
# Global Settings
|
138 |
|
|
#-------------------------------------
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
# The following TYPE comment allows tools to identify the 'type' of target this
|
142 |
|
|
# makefile is associated with.
|
143 |
|
|
# TYPE: BSP_MEMINIT_MAKEFILE
|
144 |
|
|
|
145 |
|
|
# This following VERSION comment indicates the version of the tool used to
|
146 |
|
|
# generate this makefile. A makefile variable is provided for VERSION as well.
|
147 |
|
|
# ACDS_VERSION: 13.1
|
148 |
|
|
ACDS_VERSION := 13.1
|
149 |
|
|
|
150 |
|
|
# This following BUILD_NUMBER comment indicates the build number of the tool
|
151 |
|
|
# used to generate this makefile.
|
152 |
|
|
# BUILD_NUMBER: 162
|
153 |
|
|
|
154 |
|
|
# Optimize for simulation
|
155 |
|
|
SIM_OPTIMIZE ?= 0
|
156 |
|
|
|
157 |
|
|
# The CPU reset address as needed by elf2flash
|
158 |
|
|
RESET_ADDRESS ?= 0x00010000
|
159 |
|
|
|
160 |
|
|
#-------------------------------------
|
161 |
|
|
# Pre-Initialized Memory Descriptions
|
162 |
|
|
#-------------------------------------
|
163 |
|
|
|
164 |
|
|
# Memory: onchip_for_nios2
|
165 |
|
|
MEM_0 := system_onchip_for_nios2
|
166 |
|
|
$(MEM_0)_NAME := onchip_for_nios2
|
167 |
|
|
$(MEM_0)_MEM_INIT_FILE_PARAM_NAME := INIT_FILE
|
168 |
|
|
HEX_FILES += $(MEM_INIT_DIR)/$(MEM_0).hex
|
169 |
|
|
MEM_INIT_INSTALL_FILES += $(MEM_INIT_INSTALL_DIR)/$(MEM_0).hex
|
170 |
|
|
DAT_FILES += $(HDL_SIM_DIR)/$(MEM_0).dat
|
171 |
|
|
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_0).dat
|
172 |
|
|
SYM_FILES += $(HDL_SIM_DIR)/$(MEM_0).sym
|
173 |
|
|
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_0).sym
|
174 |
|
|
$(MEM_0)_START := 0x00010000
|
175 |
|
|
$(MEM_0)_END := 0x00017fff
|
176 |
|
|
$(MEM_0)_HIERARCHICAL_PATH := onchip_for_nios2
|
177 |
|
|
$(MEM_0)_WIDTH := 32
|
178 |
|
|
$(MEM_0)_ENDIANNESS := --little-endian-mem
|
179 |
|
|
$(MEM_0)_CREATE_LANES := 0
|
180 |
|
|
|
181 |
|
|
.PHONY: onchip_for_nios2
|
182 |
|
|
onchip_for_nios2: check_elf_exists $(MEM_INIT_DIR)/$(MEM_0).hex $(HDL_SIM_DIR)/$(MEM_0).dat $(HDL_SIM_DIR)/$(MEM_0).sym
|
183 |
|
|
|
184 |
|
|
# Memory: sdram
|
185 |
|
|
MEM_1 := sdram
|
186 |
|
|
$(MEM_1)_NAME := sdram
|
187 |
|
|
DAT_FILES += $(HDL_SIM_DIR)/$(MEM_1).dat
|
188 |
|
|
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).dat
|
189 |
|
|
SYM_FILES += $(HDL_SIM_DIR)/$(MEM_1).sym
|
190 |
|
|
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).sym
|
191 |
|
|
$(MEM_1)_START := 0x08000000
|
192 |
|
|
$(MEM_1)_END := 0x0fffffff
|
193 |
|
|
$(MEM_1)_HIERARCHICAL_PATH := sdram
|
194 |
|
|
$(MEM_1)_WIDTH := 32
|
195 |
|
|
$(MEM_1)_ENDIANNESS := --little-endian-mem
|
196 |
|
|
$(MEM_1)_CREATE_LANES := 0
|
197 |
|
|
|
198 |
|
|
.PHONY: sdram
|
199 |
|
|
sdram: check_elf_exists $(HDL_SIM_DIR)/$(MEM_1).dat $(HDL_SIM_DIR)/$(MEM_1).sym
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
#END OF BSP SPECIFIC
|
203 |
|
|
|
204 |
|
|
#-------------------------------------
|
205 |
|
|
# Pre-Initialized Memory Targets
|
206 |
|
|
#-------------------------------------
|
207 |
|
|
|
208 |
|
|
.PHONY: mem_init_install mem_init_generate mem_init_clean
|
209 |
|
|
|
210 |
|
|
ifeq ($(QSYS),1)
|
211 |
|
|
# Target mem_init_install is deprecated for QSys based systems
|
212 |
|
|
# To initialize onchip memories for Quartus II Synthesis with Qsys based systems:
|
213 |
|
|
# 1) Use "make mem_init_genearate"
|
214 |
|
|
# 2) Add the generated mem_init/meminit.qip file to your Quartus II Project
|
215 |
|
|
#
|
216 |
|
|
mem_init_install:
|
217 |
|
|
$(error Deprecated Makefile Target: '$@'. Use target 'mem_init_generate' and then add $(MEM_INIT_QIP_FILE) to your Quartus II Project)
|
218 |
|
|
|
219 |
|
|
else # QSYS != 1, if SopcBuilder based system
|
220 |
|
|
|
221 |
|
|
ifneq ($(MEM_INIT_INSTALL_DIR),)
|
222 |
|
|
mem_init_install: $(MEM_INIT_INSTALL_FILES)
|
223 |
|
|
endif
|
224 |
|
|
|
225 |
|
|
ifneq ($(HDL_SIM_INSTALL_DIR),)
|
226 |
|
|
mem_init_install: $(HDL_SIM_INSTALL_FILES)
|
227 |
|
|
endif
|
228 |
|
|
|
229 |
|
|
mem_init_install: mem_init_generate
|
230 |
|
|
ifeq ($(MEM_INIT_INSTALL_DIR),)
|
231 |
|
|
@echo "WARNING: MEM_INIT_INSTALL_DIR not set. Set your QUARTUS_PROJECT_DIR environment variable."
|
232 |
|
|
endif
|
233 |
|
|
ifeq ($(HDL_SIM_INSTALL_DIR),)
|
234 |
|
|
@echo "WARNING: HDL_SIM_INSTALL_DIR not set. Set your QUARTUS_PROJECT_DIR and SOPC_NAME environment variable."
|
235 |
|
|
endif
|
236 |
|
|
|
237 |
|
|
$(MEM_INIT_INSTALL_FILES): $(MEM_INIT_INSTALL_DIR)/%: $(MEM_INIT_DIR)/%
|
238 |
|
|
@$(MKDIR) $(@D)
|
239 |
|
|
@$(CP) -v $< $@
|
240 |
|
|
|
241 |
|
|
$(HDL_SIM_INSTALL_FILES): $(HDL_SIM_INSTALL_DIR)/%: $(HDL_SIM_DIR)/%
|
242 |
|
|
@$(MKDIR) $(@D)
|
243 |
|
|
@$(CP) -v $< $@
|
244 |
|
|
|
245 |
|
|
endif # QSYS == 1
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
mem_init_generate: hex dat sym flash $(MEM_INIT_DESCRIPTOR_FILE) $(MEM_INIT_QIP_FILE)
|
249 |
|
|
|
250 |
|
|
mem_init_clean:
|
251 |
|
|
@$(RM) -r $(MEM_INIT_DIR) $(HDL_SIM_DIR) $(FLASH_FILES)
|
252 |
|
|
|
253 |
|
|
.PHONY: hex dat sym flash
|
254 |
|
|
|
255 |
|
|
hex: check_elf_exists $(HEX_FILES)
|
256 |
|
|
|
257 |
|
|
dat: check_elf_exists $(DAT_FILES)
|
258 |
|
|
|
259 |
|
|
sym: check_elf_exists $(SYM_FILES)
|
260 |
|
|
|
261 |
|
|
flash: check_elf_exists $(FLASH_FILES)
|
262 |
|
|
|
263 |
|
|
#-------------------------------------
|
264 |
|
|
# Pre-Initialized Memory Rules
|
265 |
|
|
#-------------------------------------
|
266 |
|
|
|
267 |
|
|
.PHONY: check_elf_exists
|
268 |
|
|
check_elf_exists: $(ELF)
|
269 |
|
|
ifeq ($(ELF),)
|
270 |
|
|
$(error ELF var not set in mem_init.mk)
|
271 |
|
|
endif
|
272 |
|
|
|
273 |
|
|
$(filter-out $(FLASH_DAT_FILES),$(DAT_FILES)): %.dat: $(ELF)
|
274 |
|
|
$(post-process-info)
|
275 |
|
|
@$(MKDIR) $(@D)
|
276 |
|
|
bash -c '$(ELF2DAT) --infile=$< --outfile=$@ \
|
277 |
|
|
--base=$(mem_start_address) --end=$(mem_end_address) --width=$(mem_width) \
|
278 |
|
|
$(mem_endianness) --create-lanes=$(mem_create_lanes) $(elf2dat_extra_args)'
|
279 |
|
|
|
280 |
|
|
$(foreach i,0 1 2 3 4 5 6 7,%_lane$(i).dat): %.dat
|
281 |
|
|
@true
|
282 |
|
|
|
283 |
|
|
$(HEX_FILES): %.hex: $(ELF)
|
284 |
|
|
$(post-process-info)
|
285 |
|
|
@$(MKDIR) $(@D)
|
286 |
|
|
bash -c '$(ELF2HEX) $< $(mem_start_address) $(mem_end_address) --width=$(mem_width) \
|
287 |
|
|
$(mem_endianness) --create-lanes=$(mem_create_lanes) $(elf2hex_extra_args) $@'
|
288 |
|
|
|
289 |
|
|
$(SYM_FILES): %.sym: $(ELF)
|
290 |
|
|
$(post-process-info)
|
291 |
|
|
@$(MKDIR) $(@D)
|
292 |
|
|
$(NM) -n $< > $@
|
293 |
|
|
|
294 |
|
|
$(FLASH_FILES): %.flash: $(ELF)
|
295 |
|
|
$(post-process-info)
|
296 |
|
|
@$(MKDIR) $(@D)
|
297 |
|
|
bash -c '$(ELF2FLASH) --input=$< --outfile=$@ --sim_optimize=$(SIM_OPTIMIZE) $(mem_endianness) \
|
298 |
|
|
$(elf2flash_extra_args)'
|
299 |
|
|
|
300 |
|
|
#
|
301 |
|
|
# Function generate_spd_entry
|
302 |
|
|
# Arg1: path to the memory initialization file
|
303 |
|
|
# Arg2: Type HEX or DAT
|
304 |
|
|
# Arg3: Output spd file to append
|
305 |
|
|
gen_spd_entry.BASE_FILE = $(basename $(notdir $1))
|
306 |
|
|
gen_spd_entry.PARAM_NAME = $($(gen_spd_entry.BASE_FILE)_MEM_INIT_FILE_PARAM_NAME)
|
307 |
|
|
gen_spd_entry.MEM_PATH = $($(gen_spd_entry.BASE_FILE)_HIERARCHICAL_PATH)
|
308 |
|
|
gen_spd_entry.SETTINGS = $(strip \
|
309 |
|
|
path=\"$1\" \
|
310 |
|
|
type=\"$2\" \
|
311 |
|
|
$(if $(gen_spd_entry.PARAM_NAME),initParamName=\"$(gen_spd_entry.PARAM_NAME)\") \
|
312 |
|
|
$(if $(gen_spd_entry.MEM_PATH),memoryPath=\"$(gen_spd_entry.MEM_PATH)\") \
|
313 |
|
|
)
|
314 |
|
|
define gen_spd_entry
|
315 |
|
|
$(ECHO) "" >> $3
|
316 |
|
|
endef
|
317 |
|
|
|
318 |
|
|
$(MEM_INIT_DESCRIPTOR_FILE).DAT_FILESET := $(patsubst $(dir $(MEM_INIT_DESCRIPTOR_FILE))%,%,$(DAT_FILES))
|
319 |
|
|
$(MEM_INIT_DESCRIPTOR_FILE).HEX_FILESET := $(patsubst $(dir $(MEM_INIT_DESCRIPTOR_FILE))%,%,$(HEX_FILES))
|
320 |
|
|
|
321 |
|
|
$(MEM_INIT_DESCRIPTOR_FILE): %.spd: $(MEM_INIT_FILE)
|
322 |
|
|
$(post-process-info)
|
323 |
|
|
@$(MKDIR) $(@D)
|
324 |
|
|
@$(RM) $@
|
325 |
|
|
@$(ECHO) "" > $@
|
326 |
|
|
@$(ECHO) "" >> $@
|
327 |
|
|
@$(foreach dat_file,$($@.DAT_FILESET),$(call gen_spd_entry,$(dat_file),DAT,$@) &&)true
|
328 |
|
|
@$(foreach hex_file,$($@.HEX_FILESET),$(call gen_spd_entry,$(hex_file),HEX,$@) &&)true
|
329 |
|
|
@$(ECHO) "" >> $@
|
330 |
|
|
|
331 |
|
|
.DELETE_ON_ERROR: $(MEM_INIT_DESCRIPTOR_FILE)
|
332 |
|
|
|
333 |
|
|
$(MEM_INIT_QIP_FILE): %.qip: $(MEM_INIT_FILE)
|
334 |
|
|
$(post-process-info)
|
335 |
|
|
@$(MKDIR) $(@D)
|
336 |
|
|
@$(RM) $@
|
337 |
|
|
@$(ECHO) "set_global_assignment -name SEARCH_PATH $$::quartus(qip_path)" > $@
|
338 |
|
|
|
339 |
|
|
.DELETE_ON_ERROR: $(MEM_INIT_QIP_FILE)
|