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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_trng/] [makefile] - Blame information for rev 13

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

Line No. Rev Author Line
1 2 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
# Compiler effort
42
EFFORT = -Os
43
 
44
# User's application sources (add additional files here)
45
APP_SRC = $(wildcard *.c)
46
 
47
# User's application include folders (don't forget the '-I' before each entry)
48
APP_INC = -I .
49
 
50
# Compiler toolchain (use default if not set by user)
51
RISCV_TOOLCHAIN ?= riscv32-unknown-elf
52
 
53
# CPU architecture and ABI
54
MARCH = -march=rv32i
55
MABI  = -mabi=ilp32
56
 
57
# Path to runtime c library (use default if not set by user)
58
LIBC_PATH   ?= $(dir $(shell which $(CC)))../$(RISCV_TOOLCHAIN)/lib/libc.a
59
LIBGCC_PATH ?= $(dir $(shell which $(CC)))../lib/gcc/$(RISCV_TOOLCHAIN)/*/libgcc.a
60
 
61
# Relative or absolute path to the NEORV32 home folder (use default if not set by user)
62
NEORV32_HOME ?= ../../..
63
# *****************************************************************************
64
 
65
 
66
 
67
# -----------------------------------------------------------------------------
68
# NEORV32 framework
69
# -----------------------------------------------------------------------------
70
# Path to NEORV32 linker script and startup file
71
NEORV32_COM_PATH=$(NEORV32_HOME)/sw/common
72
# Path to main NEORV32 library include files
73
NEORV32_INC_PATH=$(NEORV32_HOME)/sw/lib/include
74
# Path to main NEORV32 library source files
75
NEORV32_SRC_PATH=$(NEORV32_HOME)/sw/lib/source
76
# Path to NEORV32 executable generator
77
NEORV32_EXG_PATH=$(NEORV32_HOME)/sw/image_gen
78
# Path to NEORV32 core rtl folder
79
NEORV32_RTL_PATH=$(NEORV32_HOME)/rtl/core
80
# Marker file to verify NEORV32 home folder
81
NEORV32_HOME_MARKER=$(NEORV32_INC_PATH)/neorv32.h
82
 
83
 
84
# -----------------------------------------------------------------------------
85 6 zero_gravi
# NEORV32 core sources
86 2 zero_gravi
# -----------------------------------------------------------------------------
87 6 zero_gravi
CORE_SRC = $(wildcard $(NEORV32_SRC_PATH)/*.c)
88 2 zero_gravi
 
89
 
90
# -----------------------------------------------------------------------------
91
# Make defaults
92
# -----------------------------------------------------------------------------
93
.DEFAULT_GOAL := help
94
 
95
 
96
# -----------------------------------------------------------------------------
97
# Application output definitions
98
# -----------------------------------------------------------------------------
99
APP_EXE = neorv32_exe.bin
100
APP_ASM = main.s
101
 
102
compile: $(APP_ASM) $(APP_EXE)
103
install: $(APP_ASM) neorv32_application_image.vhd
104
all:     $(APP_ASM) $(APP_EXE) neorv32_application_image.vhd
105
 
106
# define all object files
107 6 zero_gravi
OBJ  = $(APP_SRC:.c=.o)
108
OBJ += $(CORE_SRC:.c=.o)
109 2 zero_gravi
 
110
 
111
# -----------------------------------------------------------------------------
112
# Tools and flags
113
# -----------------------------------------------------------------------------
114
# compiler tools
115
CC      = $(RISCV_TOOLCHAIN)-gcc
116
LD      = $(RISCV_TOOLCHAIN)-ld
117
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
118
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
119
SIZE    = $(RISCV_TOOLCHAIN)-size
120
 
121
# NEORV32 executable image generator
122
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
123
 
124
# Compiler flags
125
CC_OPTS = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -lm
126
 
127
# Linker flags
128
LD_OPTS = $(EFFORT) --gc-sections
129
 
130
# User flags for additional config
131
USER_FLAGS =
132
CC_OPTS += $(USER_FLAGS)
133
 
134
# Use embedded RISC-V CPU extension?
135
ifeq (,$(findstring rv32e,$(MARCH)))
136
        CC_OPTS +=
137
else
138
        CC_OPTS += -D__RISCV_EMBEDDED_CPU__
139
endif
140
 
141
# -----------------------------------------------------------------------------
142
# Host native compiler
143
# -----------------------------------------------------------------------------
144
CC_X86 = gcc -Wall -O -g
145
 
146
 
147
# -----------------------------------------------------------------------------
148
# Tool targets
149
# -----------------------------------------------------------------------------
150
# install/compile tools
151
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
152
        @echo Compiling $(IMAGE_GEN)
153
        @$(CC_X86) $< -o $(IMAGE_GEN)
154
 
155
 
156
# -----------------------------------------------------------------------------
157
# Application targets: Assemble, compile, link, dump
158
# -----------------------------------------------------------------------------
159
# Assemble startup code
160
crt0.elf: $(NEORV32_COM_PATH)/crt0.S
161
        @$(CC) $(CC_OPTS) -c $< -o $@
162
 
163
# Compile app sources
164
$(OBJ): %.o : %.c crt0.elf
165
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
166
 
167
# Link object files and show memory utilization
168
main.elf: $(OBJ)
169
        @$(LD) $(LD_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/neorv32.ld $(OBJ) $(LIBC_PATH) $(LIBGCC_PATH) -o $@
170
        @echo "Memory utilization:"
171
        @$(SIZE) main.elf
172
 
173
# Assembly listing file (for debugging)
174
$(APP_ASM): main.elf
175
        @$(OBJDUMP) -D -S -z  $< > $@
176
 
177
 
178
# -----------------------------------------------------------------------------
179
# Application targets: Generate binary executable, install (as VHDL file)
180
# -----------------------------------------------------------------------------
181
# Generate final executable: text, rodata, data (in THIS order!)
182
main.bin: main.elf
183
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
184
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
185
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
186
        @cat text.bin rodata.bin data.bin > $@
187
        @rm -f text.bin rodata.bin data.bin
188
 
189
# Generate NEORV32 executable image for bootloader update
190
$(APP_EXE): main.bin $(IMAGE_GEN)
191
        @set -e
192
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
193
        @echo "Executable ($(APP_EXE)) size in bytes:"
194
        @wc -c < $(APP_EXE)
195
 
196
# Generate NEORV32 executable VHDL boot image
197
neorv32_application_image.vhd: main.bin $(IMAGE_GEN)
198
        @set -e
199
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
200
        @echo "Installing application image to $(NEORV32_RTL_PATH)/neorv32_application_image.vhd"
201
        @cp neorv32_application_image.vhd $(NEORV32_RTL_PATH)/.
202
        @rm -f neorv32_application_image.vhd
203
 
204
 
205
# -----------------------------------------------------------------------------
206
# Bootloader targets
207
# -----------------------------------------------------------------------------
208
# Assemble startup code
209
bootloader_crt0.elf: $(NEORV32_COM_PATH)/bootloader_crt0.S
210
        @$(CC) $(CC_OPTS) -c $< -o $@
211
 
212
# Compile and install bootloader
213
bootloader: bootloader_crt0.elf $(OBJ) $(IMAGE_GEN)
214
        @set -e
215
        @$(LD) $(LD_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/bootloader_neorv32.ld $(OBJ) $(LIBC_PATH) $(LIBGCC_PATH) -o bootloader.elf
216
        @echo "Memory utilization:"
217
        @$(SIZE) bootloader.elf
218
        @$(OBJDUMP) -D -S -z bootloader.elf > bootloader.s
219
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .text   -O binary text.bin
220
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .rodata -O binary rodata.bin
221
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .data   -O binary data.bin
222
        @cat text.bin rodata.bin data.bin > bootloader.bin
223
        @$(IMAGE_GEN) -bld_img bootloader.bin neorv32_bootloader_image.vhd $(shell basename $(CURDIR))
224
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/neorv32_bootloader_image.vhd"
225
        @cp neorv32_bootloader_image.vhd $(NEORV32_RTL_PATH)/.
226
        @rm -f neorv32_bootloader_image.vhd text.bin rodata.bin data.bin
227
 
228
 
229
# -----------------------------------------------------------------------------
230
# Check toolchain
231
# -----------------------------------------------------------------------------
232
check: $(IMAGE_GEN)
233
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
234
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
235
$(error NEORV32_HOME folder not found!)
236
endif
237
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
238
        @echo "---------------- Check: $(CC) ----------------"
239
        @$(CC) -v
240
        @echo "---------------- Check: $(LD) ----------------"
241
        @$(LD) -V
242
        @echo "---------------- Check: $(OBJDUMP) ----------------"
243
        @$(OBJDUMP) -V
244
        @echo "---------------- Check: $(OBJCOPY) ----------------"
245
        @$(OBJCOPY) -V
246
        @echo "---------------- Check: $(SIZE) ----------------"
247
        @$(SIZE) -V
248
        @echo "---------------- Check: NEORV32 image_gen ----------------"
249
        @$(IMAGE_GEN) -help
250
        @echo "---------------- Check: native gcc ----------------"
251
        @$(CC_X86) -v
252
        @echo
253
        @echo "Toolchain check OK"
254
 
255
 
256
# -----------------------------------------------------------------------------
257
# Show configuration
258
# -----------------------------------------------------------------------------
259
info:
260
        @echo "---------------- Info: Project ----------------"
261 6 zero_gravi
        @echo "Project folder:    $(shell basename $(CURDIR))"
262
        @echo "Source files:      $(APP_SRC)"
263
        @echo "Include folder(s): $(APP_INC)"
264 2 zero_gravi
        @echo "---------------- Info: NEORV32 ----------------"
265
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
266
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
267 6 zero_gravi
        @echo "Core source files:"
268
        @echo "$(CORE_SRC)"
269
        @echo "Core include folder:"
270
        @echo "$(NEORV32_INC_PATH)"
271
        @echo "Project object files:"
272
        @echo "$(OBJ)"
273 2 zero_gravi
        @echo "---------------- Info: RISC-V CPU ----------------"
274
        @echo "MARCH:     $(MARCH)"
275
        @echo "MABI:      $(MABI)"
276
        @echo "---------------- Info: RISC-V Toolchain ----------------"
277
        @echo "Toolchain: $(RISCV_TOLLCHAIN)"
278
        @echo "CC:        $(CC)"
279
        @echo "LD:        $(LD)"
280
        @echo "OBJDUMP:   $(OBJDUMP)"
281
        @echo "OBJCOPY:   $(OBJCOPY)"
282
        @echo "SIZE:      $(SIZE)"
283
        @echo "---------------- Info: C Lib ----------------"
284
        @echo "CLIB:      $(LIBC_PATH)"
285
        @echo "GCCLIB:    $(LIBGCC_PATH)"
286
        @echo "---------------- Info: Flags ----------------"
287
        @echo "CC_OPTS:   $(CC_OPTS)"
288
        @echo "LD_OPTS:   $(LD_OPTS)"
289
        @echo "---------------- Info: Host Native GCC ----------------"
290
        @echo "CC_X86:    $(CC_X86)"
291
 
292
 
293
# -----------------------------------------------------------------------------
294
# Show final ELF details (just for debugging)
295
# -----------------------------------------------------------------------------
296
elf_info: main.elf
297
        @$(OBJDUMP) -x main.elf
298
 
299
 
300
# -----------------------------------------------------------------------------
301
# Help
302
# -----------------------------------------------------------------------------
303
help:
304
        @echo "<<< NEORV32 Application Makefile >>>"
305
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
306
        @echo "Targets:"
307
        @echo " help       - show this text"
308
        @echo " check      - check toolchain"
309
        @echo " info       - show makefile/toolchain configuration"
310
        @echo " compile    - compile and generate  executable for upload via bootloader"
311
        @echo " install    - compile, generate and install VHDL IMEM boot image"
312
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image"
313
        @echo " clean      - clean up project"
314
        @echo " clean_all  - clean up project, core libraries and image generator"
315
        @echo " bootloader - compile, generate and install VHDL BOOTROM bott image (for bootloader only!)"
316
 
317
 
318
# -----------------------------------------------------------------------------
319
# Clean up
320
# -----------------------------------------------------------------------------
321
clean:
322
        @rm -f *.elf *.o *.bin *.out *.s
323
 
324
clean_all: clean
325
        @rm -f $(OBJ) $(IMAGE_GEN)
326
 

powered by: WebSVN 2.1.0

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