Lösung des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mem_init.mk 12KB

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