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

Subversion Repositories neorv32

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

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 33 zero_gravi
# FreeRTOS
70
# -----------------------------------------------------------------------------
71
ifneq (,$(findstring RUN_FREERTOS_DEMO,$(USER_FLAGS)))
72
# FreeRTOS home folder (adapt this!)
73
FREERTOS_HOME ?= /mnt/n/Projects/FreeRTOS/FreeRTOS
74
 
75
# Application
76
APP_SRC += blinky_demo/main_blinky.c
77
 
78
# FreeRTOS core
79
APP_SRC += $(wildcard $(FREERTOS_HOME)/Source/*.c)
80
APP_SRC += $(wildcard $(FREERTOS_HOME)/Source/portable/MemMang/heap_1.c)
81
 
82
APP_INC += -I $(FREERTOS_HOME)/Source/include
83
 
84
# FreeRTOS RISC-V specific
85
APP_SRC += $(wildcard $(FREERTOS_HOME)/Source/portable/GCC/RISC-V/*.c)
86
APP_SRC += $(FREERTOS_HOME)/Source/portable/GCC/RISC-V/portASM.S
87
 
88
APP_INC += -I $(FREERTOS_HOME)/Source/portable/GCC/RISC-V
89
 
90
# NEORV32 specific
91
ASM_INC += -DportasmHANDLE_INTERRUPT=SystemIrqHandler
92
 
93
APP_INC += -I chip_specific_extensions/neorv32
94
 
95
ASM_INC += -I chip_specific_extensions/neorv32
96
endif
97
 
98
 
99
 
100
# -----------------------------------------------------------------------------
101 22 zero_gravi
# NEORV32 framework
102
# -----------------------------------------------------------------------------
103
# Path to NEORV32 linker script and startup file
104
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
105
# Path to main NEORV32 library include files
106
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
107
# Path to main NEORV32 library source files
108
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
109
# Path to NEORV32 executable generator
110
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
111
# Path to NEORV32 core rtl folder
112
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
113
# Marker file to check for NEORV32 home folder
114
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
115
 
116
# Core libraries (peripheral and CPU drivers)
117
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
118
# Application start-up code
119
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
120
 
121
# Linker script
122
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
123
 
124
# Main output files
125
APP_EXE  = neorv32_exe.bin
126
APP_ASM  = main.asm
127
APP_IMG  = neorv32_application_image.vhd
128
BOOT_IMG = neorv32_bootloader_image.vhd
129
 
130
 
131
# -----------------------------------------------------------------------------
132
# Sources and objects
133
# -----------------------------------------------------------------------------
134
# Define all sources
135
SRC  = $(APP_SRC)
136
SRC += $(CORE_SRC)
137
 
138
# Define all object files
139
OBJ = $(SRC:%=%.o)
140
 
141
 
142
# -----------------------------------------------------------------------------
143
# Tools and flags
144
# -----------------------------------------------------------------------------
145
# Compiler tools
146
CC      = $(RISCV_TOOLCHAIN)-gcc
147
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
148
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
149
SIZE    = $(RISCV_TOOLCHAIN)-size
150
 
151
# Host native compiler
152
CC_X86 = gcc -Wall -O -g
153
 
154
# NEORV32 executable image generator
155
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
156
 
157
# Compiler & linker flags
158
CC_OPTS  = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles
159
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
160 32 zero_gravi
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
161
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
162 22 zero_gravi
CC_OPTS += $(USER_FLAGS)
163
 
164
 
165
# -----------------------------------------------------------------------------
166
# Application output definitions
167
# -----------------------------------------------------------------------------
168
.PHONY: check info help elf_info clean clean_all bootloader
169
.DEFAULT_GOAL := help
170
 
171
# 'compile' is still here for compatibility
172
exe:     $(APP_ASM) $(APP_EXE)
173
compile: $(APP_ASM) $(APP_EXE)
174
install: $(APP_ASM) $(APP_IMG)
175
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG)
176
 
177
# Check if making bootloader
178
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
179 32 zero_gravi
# Also define "make_bootloader" for crt0.S
180
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
181 22 zero_gravi
 
182
 
183
# -----------------------------------------------------------------------------
184
# Image generator targets
185
# -----------------------------------------------------------------------------
186
# install/compile tools
187
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
188
        @echo Compiling $(IMAGE_GEN)
189
        @$(CC_X86) $< -o $(IMAGE_GEN)
190
 
191
 
192
# -----------------------------------------------------------------------------
193
# General targets: Assemble, compile, link, dump
194
# -----------------------------------------------------------------------------
195
# Compile app *.s sources (assembly)
196
%.s.o: %.s
197
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
198
 
199
# Compile app *.S sources (assembly + C pre-processor)
200
%.S.o: %.S
201
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
202
 
203
# Compile app *.c sources
204
%.c.o: %.c
205
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
206
 
207
# Compile app *.cpp sources
208
%.cpp.o: %.cpp
209
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
210
 
211
# Link object files and show memory utilization
212
main.elf: $(OBJ)
213
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@
214
        @echo "Memory utilization:"
215
        @$(SIZE) main.elf
216
 
217
# Assembly listing file (for debugging)
218
$(APP_ASM): main.elf
219
        @$(OBJDUMP) -D -S -z  $< > $@
220
 
221
# Generate final executable from .text + .rodata + .data (in THIS order!)
222
main.bin: main.elf $(APP_ASM)
223
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
224
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
225
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
226
        @cat text.bin rodata.bin data.bin > $@
227
        @rm -f text.bin rodata.bin data.bin
228
 
229
 
230
# -----------------------------------------------------------------------------
231
# Application targets: Generate binary executable, install (as VHDL file)
232
# -----------------------------------------------------------------------------
233
# Generate NEORV32 executable image for upload via bootloader
234
$(APP_EXE): main.bin $(IMAGE_GEN)
235
        @set -e
236
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
237
        @echo "Executable ($(APP_EXE)) size in bytes:"
238
        @wc -c < $(APP_EXE)
239
 
240
# Generate NEORV32 executable VHDL boot image
241
$(APP_IMG): main.bin $(IMAGE_GEN)
242
        @set -e
243
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
244
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
245
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
246
 
247
 
248
# -----------------------------------------------------------------------------
249
# Bootloader targets
250
# -----------------------------------------------------------------------------
251
# Create and install bootloader VHDL init image
252
$(BOOT_IMG): main.bin $(IMAGE_GEN)
253
        @set -e
254
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
255
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
256
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
257
 
258
# Just an alias that
259
bootloader: $(BOOT_IMG)
260
 
261
 
262
# -----------------------------------------------------------------------------
263
# Check toolchain
264
# -----------------------------------------------------------------------------
265
check: $(IMAGE_GEN)
266
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
267
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
268
$(error NEORV32_HOME folder not found!)
269
endif
270
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
271
        @echo "---------------- Check: $(CC) ----------------"
272
        @$(CC) -v
273
        @echo "---------------- Check: $(OBJDUMP) ----------------"
274
        @$(OBJDUMP) -V
275
        @echo "---------------- Check: $(OBJCOPY) ----------------"
276
        @$(OBJCOPY) -V
277
        @echo "---------------- Check: $(SIZE) ----------------"
278
        @$(SIZE) -V
279
        @echo "---------------- Check: NEORV32 image_gen ----------------"
280
        @$(IMAGE_GEN) -help
281
        @echo "---------------- Check: Native GCC ----------------"
282
        @$(CC_X86) -v
283
        @echo
284
        @echo "Toolchain check OK"
285
 
286
 
287
# -----------------------------------------------------------------------------
288
# Show configuration
289
# -----------------------------------------------------------------------------
290
info:
291
        @echo "---------------- Info: Project ----------------"
292
        @echo "Project folder:        $(shell basename $(CURDIR))"
293
        @echo "Source files:          $(APP_SRC)"
294
        @echo "Include folder(s):     $(APP_INC)"
295
        @echo "ASM include folder(s): $(ASM_INC)"
296
        @echo "---------------- Info: NEORV32 ----------------"
297
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
298
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
299
        @echo "Core source files:"
300
        @echo "$(CORE_SRC)"
301
        @echo "Core include folder:"
302
        @echo "$(NEORV32_INC_PATH)"
303
        @echo "---------------- Info: Objects ----------------"
304
        @echo "Project object files:"
305
        @echo "$(OBJ)"
306
        @echo "---------------- Info: RISC-V CPU ----------------"
307
        @echo "MARCH:      $(MARCH)"
308
        @echo "MABI:       $(MABI)"
309
        @echo "---------------- Info: Toolchain ----------------"
310
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
311
        @echo "CC:         $(CC)"
312
        @echo "OBJDUMP:    $(OBJDUMP)"
313
        @echo "OBJCOPY:    $(OBJCOPY)"
314
        @echo "SIZE:       $(SIZE)"
315
        @echo "---------------- Info: Compiler Libraries ----------------"
316
        @echo "LIBGCC:"
317
        @$(CC) -print-libgcc-file-name
318
        @echo "SEARCH-DIRS:"
319
        @$(CC) -print-search-dirs
320
        @echo "---------------- Info: Flags ----------------"
321
        @echo "USER_FLAGS: $(USER_FLAGS)"
322
        @echo "CC_OPTS:    $(CC_OPTS)"
323
        @echo "---------------- Info: Host Native GCC Flags ----------------"
324
        @echo "CC_X86:     $(CC_X86)"
325
 
326
 
327
# -----------------------------------------------------------------------------
328
# Show final ELF details (just for debugging)
329
# -----------------------------------------------------------------------------
330
elf_info: main.elf
331
        @$(OBJDUMP) -x main.elf
332
 
333
 
334
# -----------------------------------------------------------------------------
335
# Help
336
# -----------------------------------------------------------------------------
337
help:
338
        @echo "<<< NEORV32 Application Makefile >>>"
339
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
340
        @echo "Targets:"
341
        @echo " help       - show this text"
342
        @echo " check      - check toolchain"
343
        @echo " info       - show makefile/toolchain configuration"
344
        @echo " exe        - compile and generate  executable for upload via bootloader"
345
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
346
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
347
        @echo " clean      - clean up project"
348
        @echo " clean_all  - clean up project, core libraries and image generator"
349
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
350
 
351
 
352
# -----------------------------------------------------------------------------
353
# Clean up
354
# -----------------------------------------------------------------------------
355
clean:
356
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd
357
 
358
clean_all: clean
359
        @rm -f $(OBJ) $(IMAGE_GEN)

powered by: WebSVN 2.1.0

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