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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [floating_point_test/] [makefile] - Blame information for rev 55

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

Line No. Rev Author Line
1 55 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
 
38
# *****************************************************************************
39
# USER CONFIGURATION
40
# *****************************************************************************
41
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
42
APP_SRC ?= $(wildcard ./*.c) $(wildcard ./*.s) $(wildcard ./*.cpp) $(wildcard ./*.S)
43
 
44
# User's application include folders (don't forget the '-I' before each entry)
45
APP_INC ?= -I .
46
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
47
ASM_INC ?= -I .
48
 
49
# Optimization
50
EFFORT ?= -Os
51
 
52
# Compiler toolchain
53
RISCV_TOOLCHAIN ?= riscv32-unknown-elf
54
 
55
# CPU architecture and ABI
56
MARCH ?= -march=rv32i
57
MABI  ?= -mabi=ilp32
58
 
59
# User flags for additional configuration (will be added to compiler flags)
60
USER_FLAGS ?=
61
 
62
# Serial port for executable upload via bootloer
63
COM_PORT ?= /dev/ttyUSB0
64
 
65
# Relative or absolute path to the NEORV32 home folder
66
NEORV32_HOME ?= ../../..
67
# *****************************************************************************
68
 
69
 
70
 
71
# -----------------------------------------------------------------------------
72
# NEORV32 framework
73
# -----------------------------------------------------------------------------
74
# Path to NEORV32 linker script and startup file
75
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
76
# Path to main NEORV32 library include files
77
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
78
# Path to main NEORV32 library source files
79
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
80
# Path to NEORV32 executable generator
81
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
82
# Path to NEORV32 core rtl folder
83
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
84
# Marker file to check for NEORV32 home folder
85
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
86
 
87
# Core libraries (peripheral and CPU drivers)
88
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
89
# Application start-up code
90
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
91
 
92
# Linker script
93
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
94
 
95
# Main output files
96
APP_EXE  = neorv32_exe.bin
97
APP_ASM  = main.asm
98
APP_IMG  = neorv32_application_image.vhd
99
BOOT_IMG = neorv32_bootloader_image.vhd
100
 
101
 
102
# -----------------------------------------------------------------------------
103
# Sources and objects
104
# -----------------------------------------------------------------------------
105
# Define all sources
106
SRC  = $(APP_SRC)
107
SRC += $(CORE_SRC)
108
 
109
# Define all object files
110
OBJ = $(SRC:%=%.o)
111
 
112
 
113
# -----------------------------------------------------------------------------
114
# Tools and flags
115
# -----------------------------------------------------------------------------
116
# Compiler tools
117
CC      = $(RISCV_TOOLCHAIN)-gcc
118
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
119
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
120
SIZE    = $(RISCV_TOOLCHAIN)-size
121
 
122
# Host native compiler
123
CC_X86 = g++ -Wall -O -g
124
 
125
# NEORV32 executable image generator
126
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
127
 
128
# Compiler & linker flags
129
CC_OPTS  = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
130
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
131
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
132
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
133
CC_OPTS += $(USER_FLAGS)
134
 
135
 
136
# -----------------------------------------------------------------------------
137
# Application output definitions
138
# -----------------------------------------------------------------------------
139
.PHONY: check info help elf_info clean clean_all bootloader
140
.DEFAULT_GOAL := help
141
 
142
# 'compile' is still here for compatibility
143
exe:     $(APP_ASM) $(APP_EXE)
144
compile: $(APP_ASM) $(APP_EXE)
145
install: $(APP_ASM) $(APP_IMG)
146
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG)
147
 
148
# Check if making bootloader
149
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
150
# Also define "make_bootloader" for crt0.S
151
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
152
 
153
 
154
# -----------------------------------------------------------------------------
155
# Image generator targets
156
# -----------------------------------------------------------------------------
157
# install/compile tools
158
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
159
        @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
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
216
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
217
 
218
 
219
# -----------------------------------------------------------------------------
220
# Bootloader targets
221
# -----------------------------------------------------------------------------
222
# Create and install bootloader VHDL init image
223
$(BOOT_IMG): main.bin $(IMAGE_GEN)
224
        @set -e
225
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
226
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
227
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
228
 
229
# Just an alias that
230
bootloader: $(BOOT_IMG)
231
 
232
 
233
# -----------------------------------------------------------------------------
234
# Check toolchain
235
# -----------------------------------------------------------------------------
236
check: $(IMAGE_GEN)
237
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
238
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
239
$(error NEORV32_HOME folder not found!)
240
endif
241
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
242
        @echo "---------------- Check: $(CC) ----------------"
243
        @$(CC) -v
244
        @echo "---------------- Check: $(OBJDUMP) ----------------"
245
        @$(OBJDUMP) -V
246
        @echo "---------------- Check: $(OBJCOPY) ----------------"
247
        @$(OBJCOPY) -V
248
        @echo "---------------- Check: $(SIZE) ----------------"
249
        @$(SIZE) -V
250
        @echo "---------------- Check: NEORV32 image_gen ----------------"
251
        @$(IMAGE_GEN) -help
252
        @echo "---------------- Check: Native GCC ----------------"
253
        @$(CC_X86) -v
254
        @echo
255
        @echo "Toolchain check OK"
256
 
257
 
258
# -----------------------------------------------------------------------------
259
# Upload executable via serial port to bootloader
260
# -----------------------------------------------------------------------------
261
upload: $(APP_EXE)
262
        @sh $(NEORV32_EXG_PATH)/uart_upload.sh $(COM_PORT) $(APP_EXE)
263
 
264
 
265
# -----------------------------------------------------------------------------
266
# Show configuration
267
# -----------------------------------------------------------------------------
268
info:
269
        @echo "---------------- Info: Project ----------------"
270
        @echo "Project folder:        $(shell basename $(CURDIR))"
271
        @echo "Source files:          $(APP_SRC)"
272
        @echo "Include folder(s):     $(APP_INC)"
273
        @echo "ASM include folder(s): $(ASM_INC)"
274
        @echo "---------------- Info: NEORV32 ----------------"
275
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
276
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
277
        @echo "Core source files:"
278
        @echo "$(CORE_SRC)"
279
        @echo "Core include folder:"
280
        @echo "$(NEORV32_INC_PATH)"
281
        @echo "---------------- Info: Objects ----------------"
282
        @echo "Project object files:"
283
        @echo "$(OBJ)"
284
        @echo "---------------- Info: RISC-V CPU ----------------"
285
        @echo "MARCH:      $(MARCH)"
286
        @echo "MABI:       $(MABI)"
287
        @echo "---------------- Info: Toolchain ----------------"
288
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
289
        @echo "CC:         $(CC)"
290
        @echo "OBJDUMP:    $(OBJDUMP)"
291
        @echo "OBJCOPY:    $(OBJCOPY)"
292
        @echo "SIZE:       $(SIZE)"
293
        @echo "---------------- Info: Compiler Libraries ----------------"
294
        @echo "LIBGCC:"
295
        @$(CC) -print-libgcc-file-name
296
        @echo "SEARCH-DIRS:"
297
        @$(CC) -print-search-dirs
298
        @echo "---------------- Info: Flags ----------------"
299
        @echo "USER_FLAGS: $(USER_FLAGS)"
300
        @echo "CC_OPTS:    $(CC_OPTS)"
301
        @echo "---------------- Info: Host Native GCC Flags ----------------"
302
        @echo "CC_X86:     $(CC_X86)"
303
 
304
 
305
# -----------------------------------------------------------------------------
306
# Show final ELF details (just for debugging)
307
# -----------------------------------------------------------------------------
308
elf_info: main.elf
309
        @$(OBJDUMP) -x main.elf
310
 
311
 
312
# -----------------------------------------------------------------------------
313
# Help
314
# -----------------------------------------------------------------------------
315
help:
316
        @echo "<<< NEORV32 Application Makefile >>>"
317
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
318
        @echo "Targets:"
319
        @echo " help       - show this text"
320
        @echo " check      - check toolchain"
321
        @echo " info       - show makefile/toolchain configuration"
322
        @echo " exe        - compile and generate  executable for upload via bootloader"
323
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
324
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
325
        @echo " clean      - clean up project"
326
        @echo " clean_all  - clean up project, core libraries and image generator"
327
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
328
        @echo " upload     - upload  executable via serial port  to bootloader"
329
 
330
 
331
# -----------------------------------------------------------------------------
332
# Clean up
333
# -----------------------------------------------------------------------------
334
clean:
335
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd
336
 
337
clean_all: clean
338
        @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.