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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [common/] [common.mk] - Blame information for rev 67

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 67 zero_gravi
#################################################################################################
2
# << NEORV32 - Application Makefile >>                                                          #
3
# ********************************************************************************************* #
4
# Make sure to add the RISC-V GCC compiler's bin folder to your PATH environment variable.      #
5
# ********************************************************************************************* #
6
# BSD 3-Clause License                                                                          #
7
#                                                                                               #
8
# Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
9
#                                                                                               #
10
# Redistribution and use in source and binary forms, with or without modification, are          #
11
# permitted provided that the following conditions are met:                                     #
12
#                                                                                               #
13
# 1. Redistributions of source code must retain the above copyright notice, this list of        #
14
#    conditions and the following disclaimer.                                                   #
15
#                                                                                               #
16
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
17
#    conditions and the following disclaimer in the documentation and/or other materials        #
18
#    provided with the distribution.                                                            #
19
#                                                                                               #
20
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
21
#    endorse or promote products derived from this software without specific prior written      #
22
#    permission.                                                                                #
23
#                                                                                               #
24
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
25
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
26
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
27
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
28
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
29
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
30
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
31
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
32
# OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
33
# ********************************************************************************************* #
34
# The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
35
#################################################################################################
36
 
37 62 zero_gravi
# -----------------------------------------------------------------------------
38
# USER CONFIGURATION
39
# -----------------------------------------------------------------------------
40
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
41
APP_SRC ?= $(wildcard ./*.c) $(wildcard ./*.s) $(wildcard ./*.cpp) $(wildcard ./*.S)
42
 
43
# User's application include folders (don't forget the '-I' before each entry)
44
APP_INC ?= -I .
45
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
46
ASM_INC ?= -I .
47
 
48
# Optimization
49
EFFORT ?= -Os
50
 
51
# Compiler toolchain
52
RISCV_PREFIX ?= riscv32-unknown-elf-
53
 
54
# CPU architecture and ABI
55 65 zero_gravi
MARCH ?= rv32i
56
MABI  ?= ilp32
57 62 zero_gravi
 
58
# User flags for additional configuration (will be added to compiler flags)
59
USER_FLAGS ?=
60
 
61
# Relative or absolute path to the NEORV32 home folder
62
NEORV32_HOME ?= ../../..
63 64 zero_gravi
NEORV32_LOCAL_RTL ?= $(NEORV32_HOME)/rtl
64 62 zero_gravi
 
65
# -----------------------------------------------------------------------------
66
# NEORV32 framework
67
# -----------------------------------------------------------------------------
68
# Path to NEORV32 linker script and startup file
69
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
70
# Path to main NEORV32 library include files
71
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
72
# Path to main NEORV32 library source files
73
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
74
# Path to NEORV32 executable generator
75
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
76
# Path to NEORV32 core rtl folder
77 64 zero_gravi
NEORV32_RTL_PATH = $(NEORV32_LOCAL_RTL)/core
78 63 zero_gravi
# Path to NEORV32 sim folder
79
NEORV32_SIM_PATH = $(NEORV32_HOME)/sim
80 62 zero_gravi
# Marker file to check for NEORV32 home folder
81
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
82
 
83
# Core libraries (peripheral and CPU drivers)
84
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
85
# Application start-up code
86
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
87
 
88
# Linker script
89
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
90
 
91
# Main output files
92
APP_EXE  = neorv32_exe.bin
93
APP_HEX  = neorv32_exe.hex
94
APP_ASM  = main.asm
95
APP_IMG  = neorv32_application_image.vhd
96
BOOT_IMG = neorv32_bootloader_image.vhd
97
 
98
 
99
# -----------------------------------------------------------------------------
100
# Sources and objects
101
# -----------------------------------------------------------------------------
102
# Define all sources
103
SRC  = $(APP_SRC)
104
SRC += $(CORE_SRC)
105
 
106
# Define all object files
107
OBJ = $(SRC:%=%.o)
108
 
109
 
110
# -----------------------------------------------------------------------------
111
# Tools and flags
112
# -----------------------------------------------------------------------------
113
# Compiler tools
114
CC      = $(RISCV_PREFIX)gcc
115
OBJDUMP = $(RISCV_PREFIX)objdump
116
OBJCOPY = $(RISCV_PREFIX)objcopy
117
SIZE    = $(RISCV_PREFIX)size
118
 
119
# Host native compiler
120
CC_X86 = g++ -Wall -O -g
121
 
122
# NEORV32 executable image generator
123
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
124
 
125
# Compiler & linker flags
126 65 zero_gravi
CC_OPTS  = -march=$(MARCH) -mabi=$(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
127 62 zero_gravi
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
128
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
129
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
130
CC_OPTS += $(USER_FLAGS)
131
 
132
 
133
# -----------------------------------------------------------------------------
134
# Application output definitions
135
# -----------------------------------------------------------------------------
136
.PHONY: check info help elf_info clean clean_all bootloader
137
.DEFAULT_GOAL := help
138
 
139
# 'compile' is still here for compatibility
140
exe:     $(APP_ASM) $(APP_EXE)
141
hex:     $(APP_ASM) $(APP_HEX)
142
compile: $(APP_ASM) $(APP_EXE)
143 65 zero_gravi
image:   $(APP_ASM) $(APP_IMG)
144
install: image install-$(APP_IMG)
145
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG) $(APP_HEX) install
146 62 zero_gravi
 
147
# Check if making bootloader
148 65 zero_gravi
# Use different base address and length for instruction memory/"rom" (BOOTROM instead of IMEM)
149
# Also define "make_bootloader" symbol for crt0.S
150 62 zero_gravi
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
151 65 zero_gravi
target bl_image:   CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
152 62 zero_gravi
 
153
 
154
# -----------------------------------------------------------------------------
155
# Image generator targets
156
# -----------------------------------------------------------------------------
157
# install/compile tools
158 63 zero_gravi
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.c
159 62 zero_gravi
        @echo Compiling $(IMAGE_GEN)
160
        @$(CC_X86) $< -o $(IMAGE_GEN)
161
 
162
 
163
# -----------------------------------------------------------------------------
164
# General targets: Assemble, compile, link, dump
165
# -----------------------------------------------------------------------------
166
# Compile app *.s sources (assembly)
167
%.s.o: %.s
168
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
169
 
170
# Compile app *.S sources (assembly + C pre-processor)
171
%.S.o: %.S
172
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
173
 
174
# Compile app *.c sources
175
%.c.o: %.c
176
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
177
 
178
# Compile app *.cpp sources
179
%.cpp.o: %.cpp
180
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
181
 
182
# Link object files and show memory utilization
183
main.elf: $(OBJ)
184
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
185
        @echo "Memory utilization:"
186
        @$(SIZE) main.elf
187
 
188
# Assembly listing file (for debugging)
189
$(APP_ASM): main.elf
190
        @$(OBJDUMP) -d -S -z  $< > $@
191
 
192
# Generate final executable from .text + .rodata + .data (in THIS order!)
193
main.bin: main.elf $(APP_ASM)
194
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
195
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
196
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
197
        @cat text.bin rodata.bin data.bin > $@
198
        @rm -f text.bin rodata.bin data.bin
199
 
200
 
201
# -----------------------------------------------------------------------------
202
# Application targets: Generate binary executable, install (as VHDL file)
203
# -----------------------------------------------------------------------------
204
# Generate NEORV32 executable image for upload via bootloader
205
$(APP_EXE): main.bin $(IMAGE_GEN)
206
        @set -e
207
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
208
        @echo "Executable ($(APP_EXE)) size in bytes:"
209
        @wc -c < $(APP_EXE)
210
 
211
# Generate NEORV32 executable VHDL boot image
212
$(APP_IMG): main.bin $(IMAGE_GEN)
213
        @set -e
214
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
215 65 zero_gravi
 
216
install-$(APP_IMG): $(APP_IMG)
217
        @set -e
218 62 zero_gravi
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
219
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
220
 
221
# Generate NEORV32 executable image in plain hex format
222
$(APP_HEX): main.bin $(IMAGE_GEN)
223
        @set -e
224
        @$(IMAGE_GEN) -app_hex $< $@ $(shell basename $(CURDIR))
225
 
226
 
227
# -----------------------------------------------------------------------------
228
# Bootloader targets
229
# -----------------------------------------------------------------------------
230
# Create and install bootloader VHDL init image
231
$(BOOT_IMG): main.bin $(IMAGE_GEN)
232
        @set -e
233
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
234 65 zero_gravi
 
235
install-$(BOOT_IMG): $(BOOT_IMG)
236
        @set -e
237 62 zero_gravi
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
238
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
239
 
240 65 zero_gravi
# Just an alias
241
bl_image: $(BOOT_IMG)
242
bootloader: bl_image install-$(BOOT_IMG)
243 62 zero_gravi
 
244
 
245
# -----------------------------------------------------------------------------
246
# Check toolchain
247
# -----------------------------------------------------------------------------
248
check: $(IMAGE_GEN)
249
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
250
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
251
$(error NEORV32_HOME folder not found!)
252
endif
253
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
254
        @echo "---------------- Check: $(CC) ----------------"
255
        @$(CC) -v
256
        @echo "---------------- Check: $(OBJDUMP) ----------------"
257
        @$(OBJDUMP) -V
258
        @echo "---------------- Check: $(OBJCOPY) ----------------"
259
        @$(OBJCOPY) -V
260
        @echo "---------------- Check: $(SIZE) ----------------"
261
        @$(SIZE) -V
262
        @echo "---------------- Check: NEORV32 image_gen ----------------"
263
        @$(IMAGE_GEN) -help
264
        @echo "---------------- Check: Native GCC ----------------"
265
        @$(CC_X86) -v
266
        @echo
267
        @echo "Toolchain check OK"
268
 
269
 
270
# -----------------------------------------------------------------------------
271
# Show configuration
272
# -----------------------------------------------------------------------------
273
info:
274
        @echo "---------------- Info: Project ----------------"
275
        @echo "Project folder:        $(shell basename $(CURDIR))"
276
        @echo "Source files:          $(APP_SRC)"
277
        @echo "Include folder(s):     $(APP_INC)"
278
        @echo "ASM include folder(s): $(ASM_INC)"
279
        @echo "---------------- Info: NEORV32 ----------------"
280
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
281
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
282
        @echo "Core source files:"
283
        @echo "$(CORE_SRC)"
284
        @echo "Core include folder:"
285
        @echo "$(NEORV32_INC_PATH)"
286
        @echo "---------------- Info: Objects ----------------"
287
        @echo "Project object files:"
288
        @echo "$(OBJ)"
289
        @echo "---------------- Info: RISC-V CPU ----------------"
290
        @echo "MARCH:      $(MARCH)"
291
        @echo "MABI:       $(MABI)"
292
        @echo "---------------- Info: Toolchain ----------------"
293
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
294
        @echo "CC:         $(CC)"
295
        @echo "OBJDUMP:    $(OBJDUMP)"
296
        @echo "OBJCOPY:    $(OBJCOPY)"
297
        @echo "SIZE:       $(SIZE)"
298
        @echo "---------------- Info: Compiler Configuration ----------------"
299
        @$(CC) -v
300
        @echo "---------------- Info: Compiler Libraries ----------------"
301
        @echo "LIBGCC:"
302
        @$(CC) -print-libgcc-file-name
303
        @echo "SEARCH-DIRS:"
304
        @$(CC) -print-search-dirs
305
        @echo "---------------- Info: Flags ----------------"
306
        @echo "USER_FLAGS: $(USER_FLAGS)"
307
        @echo "CC_OPTS:    $(CC_OPTS)"
308
        @echo "---------------- Info: Host Native GCC Flags ----------------"
309
        @echo "CC_X86:     $(CC_X86)"
310
 
311
 
312
# -----------------------------------------------------------------------------
313 64 zero_gravi
# In-console simulation using default/simple testbench and GHDL
314 63 zero_gravi
# -----------------------------------------------------------------------------
315 65 zero_gravi
sim: $(APP_IMG) install
316 63 zero_gravi
        @echo "Simulating $(APP_IMG)..."
317 64 zero_gravi
        @sh $(NEORV32_SIM_PATH)/simple/ghdl.sh
318 63 zero_gravi
 
319
# -----------------------------------------------------------------------------
320 62 zero_gravi
# Show final ELF details (just for debugging)
321
# -----------------------------------------------------------------------------
322
elf_info: main.elf
323
        @$(OBJDUMP) -x main.elf
324
 
325
 
326
# -----------------------------------------------------------------------------
327
# Help
328
# -----------------------------------------------------------------------------
329
help:
330
        @echo "<<< NEORV32 Application Makefile >>>"
331
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
332
        @echo "Targets:"
333
        @echo " help       - show this text"
334
        @echo " check      - check toolchain"
335
        @echo " info       - show makefile/toolchain configuration"
336
        @echo " exe        - compile and generate  executable for upload via bootloader"
337
        @echo " hex        - compile and generate  executable raw file"
338 65 zero_gravi
        @echo " image      - compile and generate VHDL IMEM boot image (for application) in local folder"
339 62 zero_gravi
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
340 64 zero_gravi
        @echo " sim        - in-console simulation using default/simple testbench and GHDL"
341 62 zero_gravi
        @echo " all        - exe + hex + install"
342
        @echo " elf_info   - show ELF layout info"
343
        @echo " clean      - clean up project"
344
        @echo " clean_all  - clean up project, core libraries and image generator"
345 65 zero_gravi
        @echo " bl_image   - compile and generate VHDL BOOTROM boot image (for bootloader only!) in local folder"
346 62 zero_gravi
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
347
 
348
 
349
# -----------------------------------------------------------------------------
350
# Clean up
351
# -----------------------------------------------------------------------------
352
clean:
353
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd *.hex
354
 
355
clean_all: clean
356
        @rm -f $(OBJ) $(IMAGE_GEN)

powered by: WebSVN 2.1.0

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