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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_twi/] [makefile] - Blame information for rev 19

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

powered by: WebSVN 2.1.0

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