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

Subversion Repositories neorv32

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

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