OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [mem_init.mk] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 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_span = $($(target_stem)_SPAN)
113
mem_width = $($(target_stem)_WIDTH)
114
mem_endianness = $($(target_stem)_ENDIANNESS)
115
mem_create_lanes = $($(target_stem)_CREATE_LANES)
116
 
117
mem_pad_flag = $($(target_stem)_PAD_FLAG)
118
mem_reloc_input_flag = $($(target_stem)_RELOC_INPUT_FLAG)
119
mem_no_zero_fill_flag = $($(target_stem)_NO_ZERO_FILL_FLAG)
120
 
121
flash_mem_epcs_flag = $($(target_stem)_EPCS_FLAGS)
122
flash_mem_cfi_flag = $($(target_stem)_CFI_FLAGS)
123
flash_mem_boot_loader_flag = $($(target_stem)_BOOT_LOADER_FLAG)
124
 
125
elf2dat_extra_args = $(mem_pad_flag)
126
elf2hex_extra_args = $(mem_no_zero_fill_flag)
127
elf2flash_extra_args = $(flash_mem_cfi_flag) $(flash_mem_epcs_flag) $(flash_mem_boot_loader_flag)
128
flash2dat_extra_args = $(mem_pad_flag) $(mem_reloc_input_flag)
129
 
130
#------------------------------------------------------------------------------
131
#                              BSP SPECIFIC CONTENT
132
#
133
# The content below is controlled by the BSP and SOPC System
134
#------------------------------------------------------------------------------
135
#START OF BSP SPECIFIC
136
 
137
#-------------------------------------
138
# Global Settings
139
#-------------------------------------
140
 
141
 
142
# The following TYPE comment allows tools to identify the 'type' of target this
143
# makefile is associated with.
144
# TYPE: BSP_MEMINIT_MAKEFILE
145
 
146
# This following VERSION comment indicates the version of the tool used to
147
# generate this makefile. A makefile variable is provided for VERSION as well.
148
# ACDS_VERSION: 14.0
149
ACDS_VERSION := 14.0
150
 
151
# This following BUILD_NUMBER comment indicates the build number of the tool
152
# used to generate this makefile.
153
# BUILD_NUMBER: 200
154
 
155
# Optimize for simulation
156
SIM_OPTIMIZE ?= 0
157
 
158
# The CPU reset address as needed by elf2flash
159
RESET_ADDRESS ?= 0x08008000
160
 
161
#-------------------------------------
162
# Pre-Initialized Memory Descriptions
163
#-------------------------------------
164
 
165
# Memory: onchip_memory2_0
166
MEM_0 := system_onchip_memory2_0
167
$(MEM_0)_NAME := onchip_memory2_0
168
$(MEM_0)_MEM_INIT_FILE_PARAM_NAME := INIT_FILE
169
HEX_FILES += $(MEM_INIT_DIR)/$(MEM_0).hex
170
MEM_INIT_INSTALL_FILES += $(MEM_INIT_INSTALL_DIR)/$(MEM_0).hex
171
DAT_FILES += $(HDL_SIM_DIR)/$(MEM_0).dat
172
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_0).dat
173
SYM_FILES += $(HDL_SIM_DIR)/$(MEM_0).sym
174
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_0).sym
175
$(MEM_0)_START := 0x08008000
176
$(MEM_0)_END := 0x0800ffff
177
$(MEM_0)_SPAN := 0x00008000
178
$(MEM_0)_HIERARCHICAL_PATH := onchip_memory2_0
179
$(MEM_0)_WIDTH := 32
180
$(MEM_0)_ENDIANNESS := --little-endian-mem
181
$(MEM_0)_CREATE_LANES := 0
182
 
183
.PHONY: onchip_memory2_0
184
onchip_memory2_0: check_elf_exists $(MEM_INIT_DIR)/$(MEM_0).hex $(HDL_SIM_DIR)/$(MEM_0).dat $(HDL_SIM_DIR)/$(MEM_0).sym
185
 
186
# Memory: sdram
187
MEM_1 := sdram
188
$(MEM_1)_NAME := sdram
189
DAT_FILES += $(HDL_SIM_DIR)/$(MEM_1).dat
190
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).dat
191
SYM_FILES += $(HDL_SIM_DIR)/$(MEM_1).sym
192
HDL_SIM_INSTALL_FILES += $(HDL_SIM_INSTALL_DIR)/$(MEM_1).sym
193
$(MEM_1)_START := 0x00000000
194
$(MEM_1)_END := 0x07ffffff
195
$(MEM_1)_SPAN := 0x08000000
196
$(MEM_1)_HIERARCHICAL_PATH := sdram
197
$(MEM_1)_WIDTH := 32
198
$(MEM_1)_ENDIANNESS := --little-endian-mem
199
$(MEM_1)_CREATE_LANES := 0
200
 
201
.PHONY: sdram
202
sdram: check_elf_exists $(HDL_SIM_DIR)/$(MEM_1).dat $(HDL_SIM_DIR)/$(MEM_1).sym
203
 
204
 
205
#END OF BSP SPECIFIC
206
 
207
#-------------------------------------
208
# Pre-Initialized Memory Targets
209
#-------------------------------------
210
 
211
.PHONY: mem_init_install mem_init_generate mem_init_clean
212
 
213
ifeq ($(QSYS),1)
214
# Target mem_init_install is deprecated for QSys based systems
215
# To initialize onchip memories for Quartus II Synthesis with Qsys based systems:
216
#  1) Use "make mem_init_genearate"
217
#  2) Add the generated mem_init/meminit.qip file to your Quartus II Project
218
#
219
mem_init_install:
220
        $(error Deprecated Makefile Target: '$@'. Use target 'mem_init_generate' and then add $(MEM_INIT_QIP_FILE) to your Quartus II Project)
221
 
222
else # QSYS != 1, if SopcBuilder based system
223
 
224
ifneq ($(MEM_INIT_INSTALL_DIR),)
225
mem_init_install: $(MEM_INIT_INSTALL_FILES)
226
endif
227
 
228
ifneq ($(HDL_SIM_INSTALL_DIR),)
229
mem_init_install: $(HDL_SIM_INSTALL_FILES)
230
endif
231
 
232
mem_init_install: mem_init_generate
233
ifeq ($(MEM_INIT_INSTALL_DIR),)
234
        @echo "WARNING: MEM_INIT_INSTALL_DIR not set. Set your QUARTUS_PROJECT_DIR environment variable."
235
endif
236
ifeq ($(HDL_SIM_INSTALL_DIR),)
237
        @echo "WARNING: HDL_SIM_INSTALL_DIR not set. Set your QUARTUS_PROJECT_DIR and SOPC_NAME environment variable."
238
endif
239
 
240
$(MEM_INIT_INSTALL_FILES): $(MEM_INIT_INSTALL_DIR)/%: $(MEM_INIT_DIR)/%
241
        @$(MKDIR) $(@D)
242
        @$(CP) -v $< $@
243
 
244
$(HDL_SIM_INSTALL_FILES): $(HDL_SIM_INSTALL_DIR)/%: $(HDL_SIM_DIR)/%
245
        @$(MKDIR) $(@D)
246
        @$(CP) -v $< $@
247
 
248
endif # QSYS == 1
249
 
250
 
251
mem_init_generate: hex dat sym flash $(MEM_INIT_DESCRIPTOR_FILE) $(MEM_INIT_QIP_FILE)
252
 
253
mem_init_clean:
254
        @$(RM) -r $(MEM_INIT_DIR) $(HDL_SIM_DIR) $(FLASH_FILES)
255
 
256
.PHONY: hex dat sym flash
257
 
258
hex: check_elf_exists $(HEX_FILES)
259
 
260
dat: check_elf_exists $(DAT_FILES)
261
 
262
sym: check_elf_exists $(SYM_FILES)
263
 
264
flash: check_elf_exists $(FLASH_FILES)
265
 
266
#-------------------------------------
267
# Pre-Initialized Memory Rules
268
#-------------------------------------
269
 
270
.PHONY: check_elf_exists
271
check_elf_exists: $(ELF)
272
ifeq ($(ELF),)
273
        $(error ELF var not set in mem_init.mk)
274
endif
275
 
276
$(filter-out $(FLASH_DAT_FILES),$(DAT_FILES)): %.dat: $(ELF)
277
        $(post-process-info)
278
        @$(MKDIR) $(@D)
279
        bash -c '$(ELF2DAT) --infile=$< --outfile=$@ \
280
                --base=$(mem_start_address) --end=$(mem_end_address) --width=$(mem_width) \
281
                $(mem_endianness) --create-lanes=$(mem_create_lanes) $(elf2dat_extra_args)'
282
 
283
$(foreach i,0 1 2 3 4 5 6 7,%_lane$(i).dat): %.dat
284
        @true
285
 
286
$(HEX_FILES): %.hex: $(ELF)
287
        $(post-process-info)
288
        @$(MKDIR) $(@D)
289
        bash -c '$(ELF2HEX) $< $(mem_start_address) $(mem_end_address) --width=$(mem_width) \
290
                $(mem_endianness) --create-lanes=$(mem_create_lanes) $(elf2hex_extra_args) $@'
291
 
292
$(SYM_FILES): %.sym: $(ELF)
293
        $(post-process-info)
294
        @$(MKDIR) $(@D)
295
        $(NM) -n $< > $@
296
 
297
$(FLASH_FILES): %.flash: $(ELF)
298
        $(post-process-info)
299
        @$(MKDIR) $(@D)
300
        bash -c '$(ELF2FLASH) --input=$< --outfile=$@ --sim_optimize=$(SIM_OPTIMIZE) $(mem_endianness) \
301
                $(elf2flash_extra_args)'
302
 
303
#
304
# Function generate_spd_entry
305
# Arg1: path to the memory initialization file
306
# Arg2: Type HEX or DAT
307
# Arg3: Output spd file to append
308
gen_spd_entry.BASE_FILE = $(basename $(notdir $1))
309
gen_spd_entry.PARAM_NAME = $($(gen_spd_entry.BASE_FILE)_MEM_INIT_FILE_PARAM_NAME)
310
gen_spd_entry.MEM_PATH = $($(gen_spd_entry.BASE_FILE)_HIERARCHICAL_PATH)
311
gen_spd_entry.SETTINGS = $(strip \
312
        path=\"$1\" \
313
        type=\"$2\" \
314
        $(if $(gen_spd_entry.PARAM_NAME),initParamName=\"$(gen_spd_entry.PARAM_NAME)\") \
315
        $(if $(gen_spd_entry.MEM_PATH),memoryPath=\"$(gen_spd_entry.MEM_PATH)\") \
316
)
317
define gen_spd_entry
318
$(ECHO) "" >> $3
319
endef
320
 
321
$(MEM_INIT_DESCRIPTOR_FILE).DAT_FILESET := $(patsubst $(dir $(MEM_INIT_DESCRIPTOR_FILE))%,%,$(DAT_FILES))
322
$(MEM_INIT_DESCRIPTOR_FILE).HEX_FILESET := $(patsubst $(dir $(MEM_INIT_DESCRIPTOR_FILE))%,%,$(HEX_FILES))
323
 
324
$(MEM_INIT_DESCRIPTOR_FILE): %.spd: $(MEM_INIT_FILE)
325
        $(post-process-info)
326
        @$(MKDIR) $(@D)
327
        @$(RM) $@
328
        @$(ECHO) "" > $@
329
        @$(ECHO) "" >> $@
330
        @$(foreach dat_file,$($@.DAT_FILESET),$(call gen_spd_entry,$(dat_file),DAT,$@) &&)true
331
        @$(foreach hex_file,$($@.HEX_FILESET),$(call gen_spd_entry,$(hex_file),HEX,$@) &&)true
332
        @$(ECHO) "" >> $@
333
 
334
.DELETE_ON_ERROR: $(MEM_INIT_DESCRIPTOR_FILE)
335
 
336
$(MEM_INIT_QIP_FILE): %.qip: $(MEM_INIT_FILE)
337
        $(post-process-info)
338
        @$(MKDIR) $(@D)
339
        @$(RM) $@
340
        @$(ECHO) "set_global_assignment -name SEARCH_PATH $$::quartus(qip_path)" > $@
341
 
342
.DELETE_ON_ERROR: $(MEM_INIT_QIP_FILE)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.