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