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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_freeRTOS/] [makefile] - Blame information for rev 32

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

Line No. Rev Author Line
1 22 zero_gravi
#################################################################################################
2
# << NEORV32 - Application Makefile >>                                                          #
3
# ********************************************************************************************* #
4
# Make sure to add the riscv GCC compiler's bin folder to your PATH environment variable.       #
5
# ********************************************************************************************* #
6
# BSD 3-Clause License                                                                          #
7
#                                                                                               #
8
# Copyright (c) 2020, 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
# Relative or absolute path to the NEORV32 home folder
63
NEORV32_HOME ?= ../../..
64
# *****************************************************************************
65
 
66
 
67
 
68
# -----------------------------------------------------------------------------
69
# NEORV32 framework
70
# -----------------------------------------------------------------------------
71
# Path to NEORV32 linker script and startup file
72
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
73
# Path to main NEORV32 library include files
74
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
75
# Path to main NEORV32 library source files
76
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
77
# Path to NEORV32 executable generator
78
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
79
# Path to NEORV32 core rtl folder
80
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
81
# Marker file to check for NEORV32 home folder
82
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
83
 
84
# Core libraries (peripheral and CPU drivers)
85
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
86
# Application start-up code
87
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
88
 
89
# Linker script
90
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
91
 
92
# Main output files
93
APP_EXE  = neorv32_exe.bin
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_TOOLCHAIN)-gcc
115
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
116
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
117
SIZE    = $(RISCV_TOOLCHAIN)-size
118
 
119
# Host native compiler
120
CC_X86 = gcc -Wall -O -g
121
 
122
# NEORV32 executable image generator
123
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
124
 
125
# Compiler & linker flags
126
CC_OPTS  = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles
127
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
128 32 zero_gravi
# 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 22 zero_gravi
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
compile: $(APP_ASM) $(APP_EXE)
142
install: $(APP_ASM) $(APP_IMG)
143
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG)
144
 
145
# Check if making bootloader
146
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
147 32 zero_gravi
# Also define "make_bootloader" for crt0.S
148
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
149 22 zero_gravi
 
150
 
151
# -----------------------------------------------------------------------------
152
# Image generator targets
153
# -----------------------------------------------------------------------------
154
# install/compile tools
155
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
156
        @echo Compiling $(IMAGE_GEN)
157
        @$(CC_X86) $< -o $(IMAGE_GEN)
158
 
159
 
160
# -----------------------------------------------------------------------------
161
# General targets: Assemble, compile, link, dump
162
# -----------------------------------------------------------------------------
163
# Compile app *.s sources (assembly)
164
%.s.o: %.s
165
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
166
 
167
# Compile app *.S sources (assembly + C pre-processor)
168
%.S.o: %.S
169
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
170
 
171
# Compile app *.c sources
172
%.c.o: %.c
173
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
174
 
175
# Compile app *.cpp sources
176
%.cpp.o: %.cpp
177
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
178
 
179
# Link object files and show memory utilization
180
main.elf: $(OBJ)
181
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@
182
        @echo "Memory utilization:"
183
        @$(SIZE) main.elf
184
 
185
# Assembly listing file (for debugging)
186
$(APP_ASM): main.elf
187
        @$(OBJDUMP) -D -S -z  $< > $@
188
 
189
# Generate final executable from .text + .rodata + .data (in THIS order!)
190
main.bin: main.elf $(APP_ASM)
191
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
192
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
193
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
194
        @cat text.bin rodata.bin data.bin > $@
195
        @rm -f text.bin rodata.bin data.bin
196
 
197
 
198
# -----------------------------------------------------------------------------
199
# Application targets: Generate binary executable, install (as VHDL file)
200
# -----------------------------------------------------------------------------
201
# Generate NEORV32 executable image for upload via bootloader
202
$(APP_EXE): main.bin $(IMAGE_GEN)
203
        @set -e
204
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
205
        @echo "Executable ($(APP_EXE)) size in bytes:"
206
        @wc -c < $(APP_EXE)
207
 
208
# Generate NEORV32 executable VHDL boot image
209
$(APP_IMG): main.bin $(IMAGE_GEN)
210
        @set -e
211
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
212
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
213
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
214
 
215
 
216
# -----------------------------------------------------------------------------
217
# Bootloader targets
218
# -----------------------------------------------------------------------------
219
# Create and install bootloader VHDL init image
220
$(BOOT_IMG): main.bin $(IMAGE_GEN)
221
        @set -e
222
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
223
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
224
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
225
 
226
# Just an alias that
227
bootloader: $(BOOT_IMG)
228
 
229
 
230
# -----------------------------------------------------------------------------
231
# Check toolchain
232
# -----------------------------------------------------------------------------
233
check: $(IMAGE_GEN)
234
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
235
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
236
$(error NEORV32_HOME folder not found!)
237
endif
238
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
239
        @echo "---------------- Check: $(CC) ----------------"
240
        @$(CC) -v
241
        @echo "---------------- Check: $(OBJDUMP) ----------------"
242
        @$(OBJDUMP) -V
243
        @echo "---------------- Check: $(OBJCOPY) ----------------"
244
        @$(OBJCOPY) -V
245
        @echo "---------------- Check: $(SIZE) ----------------"
246
        @$(SIZE) -V
247
        @echo "---------------- Check: NEORV32 image_gen ----------------"
248
        @$(IMAGE_GEN) -help
249
        @echo "---------------- Check: Native GCC ----------------"
250
        @$(CC_X86) -v
251
        @echo
252
        @echo "Toolchain check OK"
253
 
254
 
255
# -----------------------------------------------------------------------------
256
# Show configuration
257
# -----------------------------------------------------------------------------
258
info:
259
        @echo "---------------- Info: Project ----------------"
260
        @echo "Project folder:        $(shell basename $(CURDIR))"
261
        @echo "Source files:          $(APP_SRC)"
262
        @echo "Include folder(s):     $(APP_INC)"
263
        @echo "ASM include folder(s): $(ASM_INC)"
264
        @echo "---------------- Info: NEORV32 ----------------"
265
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
266
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
267
        @echo "Core source files:"
268
        @echo "$(CORE_SRC)"
269
        @echo "Core include folder:"
270
        @echo "$(NEORV32_INC_PATH)"
271
        @echo "---------------- Info: Objects ----------------"
272
        @echo "Project object files:"
273
        @echo "$(OBJ)"
274
        @echo "---------------- Info: RISC-V CPU ----------------"
275
        @echo "MARCH:      $(MARCH)"
276
        @echo "MABI:       $(MABI)"
277
        @echo "---------------- Info: Toolchain ----------------"
278
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
279
        @echo "CC:         $(CC)"
280
        @echo "OBJDUMP:    $(OBJDUMP)"
281
        @echo "OBJCOPY:    $(OBJCOPY)"
282
        @echo "SIZE:       $(SIZE)"
283
        @echo "---------------- Info: Compiler Libraries ----------------"
284
        @echo "LIBGCC:"
285
        @$(CC) -print-libgcc-file-name
286
        @echo "SEARCH-DIRS:"
287
        @$(CC) -print-search-dirs
288
        @echo "---------------- Info: Flags ----------------"
289
        @echo "USER_FLAGS: $(USER_FLAGS)"
290
        @echo "CC_OPTS:    $(CC_OPTS)"
291
        @echo "---------------- Info: Host Native GCC Flags ----------------"
292
        @echo "CC_X86:     $(CC_X86)"
293
 
294
 
295
# -----------------------------------------------------------------------------
296
# Show final ELF details (just for debugging)
297
# -----------------------------------------------------------------------------
298
elf_info: main.elf
299
        @$(OBJDUMP) -x main.elf
300
 
301
 
302
# -----------------------------------------------------------------------------
303
# Help
304
# -----------------------------------------------------------------------------
305
help:
306
        @echo "<<< NEORV32 Application Makefile >>>"
307
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
308
        @echo "Targets:"
309
        @echo " help       - show this text"
310
        @echo " check      - check toolchain"
311
        @echo " info       - show makefile/toolchain configuration"
312
        @echo " exe        - compile and generate  executable for upload via bootloader"
313
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
314
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
315
        @echo " clean      - clean up project"
316
        @echo " clean_all  - clean up project, core libraries and image generator"
317
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
318
 
319
 
320
# -----------------------------------------------------------------------------
321
# Clean up
322
# -----------------------------------------------------------------------------
323
clean:
324
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd
325
 
326
clean_all: clean
327
        @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.