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

Subversion Repositories neorv32

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

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
# Add NEORV32 sources to input SRCs
86
# -----------------------------------------------------------------------------
87
APP_SRC += $(wildcard $(NEORV32_SRC_PATH)/*.c)
88
 
89
 
90
# -----------------------------------------------------------------------------
91
# Make defaults
92
# -----------------------------------------------------------------------------
93
.SUFFIXES:
94
.PHONY: all
95
.DEFAULT_GOAL := help
96
 
97
 
98
# -----------------------------------------------------------------------------
99
# Application output definitions
100
# -----------------------------------------------------------------------------
101
APP_EXE = neorv32_exe.bin
102
APP_ASM = main.s
103
 
104
compile: $(APP_ASM) $(APP_EXE)
105
install: $(APP_ASM) neorv32_application_image.vhd
106
all:     $(APP_ASM) $(APP_EXE) neorv32_application_image.vhd
107
 
108
# define all object files
109
OBJ = $(APP_SRC:.c=.o)
110
 
111
 
112
# -----------------------------------------------------------------------------
113
# Tools and flags
114
# -----------------------------------------------------------------------------
115
# compiler tools
116
CC      = $(RISCV_TOOLCHAIN)-gcc
117
LD      = $(RISCV_TOOLCHAIN)-ld
118
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
119
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
120
SIZE    = $(RISCV_TOOLCHAIN)-size
121
 
122
# NEORV32 executable image generator
123
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
124
 
125
# Compiler flags
126
CC_OPTS = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -lm
127
 
128
# Linker flags
129
LD_OPTS = $(EFFORT) --gc-sections
130
 
131
# User flags for additional config
132
USER_FLAGS =
133
CC_OPTS += $(USER_FLAGS)
134
 
135
# Use embedded RISC-V CPU extension?
136
ifeq (,$(findstring rv32e,$(MARCH)))
137
        CC_OPTS +=
138
else
139
        CC_OPTS += -D__RISCV_EMBEDDED_CPU__
140
endif
141
 
142
# -----------------------------------------------------------------------------
143
# Host native compiler
144
# -----------------------------------------------------------------------------
145
CC_X86 = gcc -Wall -O -g
146
 
147
 
148
# -----------------------------------------------------------------------------
149
# Tool targets
150
# -----------------------------------------------------------------------------
151
# install/compile tools
152
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
153
        @echo Compiling $(IMAGE_GEN)
154
        @$(CC_X86) $< -o $(IMAGE_GEN)
155
 
156
 
157
# -----------------------------------------------------------------------------
158
# Application targets: Assemble, compile, link, dump
159
# -----------------------------------------------------------------------------
160
# Assemble startup code
161
crt0.elf: $(NEORV32_COM_PATH)/crt0.S
162
        @$(CC) $(CC_OPTS) -c $< -o $@
163
 
164
# Compile app sources
165
$(OBJ): %.o : %.c crt0.elf
166
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
167
 
168
# Link object files and show memory utilization
169
main.elf: $(OBJ)
170
        @$(LD) $(LD_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/neorv32.ld $(OBJ) $(LIBC_PATH) $(LIBGCC_PATH) -o $@
171
        @echo "Memory utilization:"
172
        @$(SIZE) main.elf
173
 
174
# Assembly listing file (for debugging)
175
$(APP_ASM): main.elf
176
        @$(OBJDUMP) -D -S -z  $< > $@
177
 
178
 
179
# -----------------------------------------------------------------------------
180
# Application targets: Generate binary executable, install (as VHDL file)
181
# -----------------------------------------------------------------------------
182
# Generate final executable: text, rodata, data (in THIS order!)
183
main.bin: main.elf
184
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
185
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
186
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
187
        @cat text.bin rodata.bin data.bin > $@
188
        @rm -f text.bin rodata.bin data.bin
189
 
190
# Generate NEORV32 executable image for bootloader update
191
$(APP_EXE): main.bin $(IMAGE_GEN)
192
        @set -e
193
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
194
        @echo "Executable ($(APP_EXE)) size in bytes:"
195
        @wc -c < $(APP_EXE)
196
 
197
# Generate NEORV32 executable VHDL boot image
198
neorv32_application_image.vhd: main.bin $(IMAGE_GEN)
199
        @set -e
200
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
201
        @echo "Installing application image to $(NEORV32_RTL_PATH)/neorv32_application_image.vhd"
202
        @cp neorv32_application_image.vhd $(NEORV32_RTL_PATH)/.
203
        @rm -f neorv32_application_image.vhd
204
 
205
 
206
# -----------------------------------------------------------------------------
207
# Bootloader targets
208
# -----------------------------------------------------------------------------
209
# Assemble startup code
210
bootloader_crt0.elf: $(NEORV32_COM_PATH)/bootloader_crt0.S
211
        @$(CC) $(CC_OPTS) -c $< -o $@
212
 
213
# Compile and install bootloader
214
bootloader: bootloader_crt0.elf $(OBJ) $(IMAGE_GEN)
215
        @set -e
216
        @$(LD) $(LD_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/bootloader_neorv32.ld $(OBJ) $(LIBC_PATH) $(LIBGCC_PATH) -o bootloader.elf
217
        @echo "Memory utilization:"
218
        @$(SIZE) bootloader.elf
219
        @$(OBJDUMP) -D -S -z bootloader.elf > bootloader.s
220
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .text   -O binary text.bin
221
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .rodata -O binary rodata.bin
222
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .data   -O binary data.bin
223
        @cat text.bin rodata.bin data.bin > bootloader.bin
224
        @$(IMAGE_GEN) -bld_img bootloader.bin neorv32_bootloader_image.vhd $(shell basename $(CURDIR))
225
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/neorv32_bootloader_image.vhd"
226
        @cp neorv32_bootloader_image.vhd $(NEORV32_RTL_PATH)/.
227
        @rm -f neorv32_bootloader_image.vhd text.bin rodata.bin data.bin
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: $(LD) ----------------"
242
        @$(LD) -V
243
        @echo "---------------- Check: $(OBJDUMP) ----------------"
244
        @$(OBJDUMP) -V
245
        @echo "---------------- Check: $(OBJCOPY) ----------------"
246
        @$(OBJCOPY) -V
247
        @echo "---------------- Check: $(SIZE) ----------------"
248
        @$(SIZE) -V
249
        @echo "---------------- Check: NEORV32 image_gen ----------------"
250
        @$(IMAGE_GEN) -help
251
        @echo "---------------- Check: native gcc ----------------"
252
        @$(CC_X86) -v
253
        @echo
254
        @echo "Toolchain check OK"
255
 
256
 
257
# -----------------------------------------------------------------------------
258
# Show configuration
259
# -----------------------------------------------------------------------------
260
info:
261
        @echo "---------------- Info: Project ----------------"
262
        @echo "Project: $(shell basename $(CURDIR))"
263
        @echo "Project source files: $(APP_SRC)"
264
        @echo "Project include folders: $(NEORV32_INC_PATH) $(APP_INC)"
265
        @echo "Project object files: $(OBJ)"
266
        @echo "---------------- Info: NEORV32 ----------------"
267
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
268
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
269
        @echo "---------------- Info: RISC-V CPU ----------------"
270
        @echo "MARCH:     $(MARCH)"
271
        @echo "MABI:      $(MABI)"
272
        @echo "---------------- Info: RISC-V Toolchain ----------------"
273
        @echo "Toolchain: $(RISCV_TOLLCHAIN)"
274
        @echo "CC:        $(CC)"
275
        @echo "LD:        $(LD)"
276
        @echo "OBJDUMP:   $(OBJDUMP)"
277
        @echo "OBJCOPY:   $(OBJCOPY)"
278
        @echo "SIZE:      $(SIZE)"
279
        @echo "---------------- Info: C Lib ----------------"
280
        @echo "CLIB:      $(LIBC_PATH)"
281
        @echo "GCCLIB:    $(LIBGCC_PATH)"
282
        @echo "---------------- Info: Flags ----------------"
283
        @echo "CC_OPTS:   $(CC_OPTS)"
284
        @echo "LD_OPTS:   $(LD_OPTS)"
285
        @echo "---------------- Info: Host Native GCC ----------------"
286
        @echo "CC_X86:    $(CC_X86)"
287
 
288
 
289
# -----------------------------------------------------------------------------
290
# Show final ELF details (just for debugging)
291
# -----------------------------------------------------------------------------
292
elf_info: main.elf
293
        @$(OBJDUMP) -x main.elf
294
 
295
 
296
# -----------------------------------------------------------------------------
297
# Help
298
# -----------------------------------------------------------------------------
299
help:
300
        @echo "<<< NEORV32 Application Makefile >>>"
301
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
302
        @echo "Targets:"
303
        @echo " help       - show this text"
304
        @echo " check      - check toolchain"
305
        @echo " info       - show makefile/toolchain configuration"
306
        @echo " compile    - compile and generate  executable for upload via bootloader"
307
        @echo " install    - compile, generate and install VHDL IMEM boot image"
308
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image"
309
        @echo " clean      - clean up project"
310
        @echo " clean_all  - clean up project, core libraries and image generator"
311
        @echo " bootloader - compile, generate and install VHDL BOOTROM bott image (for bootloader only!)"
312
 
313
 
314
# -----------------------------------------------------------------------------
315
# Clean up
316
# -----------------------------------------------------------------------------
317
clean:
318
        @rm -f *.elf *.o *.bin *.out *.s
319
 
320
clean_all: clean
321
        @rm -f $(OBJ) $(IMAGE_GEN)
322
 

powered by: WebSVN 2.1.0

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