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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [common/] [common.mk] - Blame information for rev 62

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

Line No. Rev Author Line
1 62 zero_gravi
# -----------------------------------------------------------------------------
2
# USER CONFIGURATION
3
# -----------------------------------------------------------------------------
4
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
5
APP_SRC ?= $(wildcard ./*.c) $(wildcard ./*.s) $(wildcard ./*.cpp) $(wildcard ./*.S)
6
 
7
# User's application include folders (don't forget the '-I' before each entry)
8
APP_INC ?= -I .
9
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
10
ASM_INC ?= -I .
11
 
12
# Optimization
13
EFFORT ?= -Os
14
 
15
# Compiler toolchain
16
RISCV_PREFIX ?= riscv32-unknown-elf-
17
 
18
# CPU architecture and ABI
19
MARCH ?= -march=rv32i
20
MABI  ?= -mabi=ilp32
21
 
22
# User flags for additional configuration (will be added to compiler flags)
23
USER_FLAGS ?=
24
 
25
# Relative or absolute path to the NEORV32 home folder
26
NEORV32_HOME ?= ../../..
27
 
28
 
29
# -----------------------------------------------------------------------------
30
# NEORV32 framework
31
# -----------------------------------------------------------------------------
32
# Path to NEORV32 linker script and startup file
33
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
34
# Path to main NEORV32 library include files
35
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
36
# Path to main NEORV32 library source files
37
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
38
# Path to NEORV32 executable generator
39
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
40
# Path to NEORV32 core rtl folder
41
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
42
# Marker file to check for NEORV32 home folder
43
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
44
 
45
# Core libraries (peripheral and CPU drivers)
46
CORE_SRC  = $(wildcard $(NEORV32_SRC_PATH)/*.c)
47
# Application start-up code
48
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
49
 
50
# Linker script
51
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
52
 
53
# Main output files
54
APP_EXE  = neorv32_exe.bin
55
APP_HEX  = neorv32_exe.hex
56
APP_ASM  = main.asm
57
APP_IMG  = neorv32_application_image.vhd
58
BOOT_IMG = neorv32_bootloader_image.vhd
59
 
60
 
61
# -----------------------------------------------------------------------------
62
# Sources and objects
63
# -----------------------------------------------------------------------------
64
# Define all sources
65
SRC  = $(APP_SRC)
66
SRC += $(CORE_SRC)
67
 
68
# Define all object files
69
OBJ = $(SRC:%=%.o)
70
 
71
 
72
# -----------------------------------------------------------------------------
73
# Tools and flags
74
# -----------------------------------------------------------------------------
75
# Compiler tools
76
CC      = $(RISCV_PREFIX)gcc
77
OBJDUMP = $(RISCV_PREFIX)objdump
78
OBJCOPY = $(RISCV_PREFIX)objcopy
79
SIZE    = $(RISCV_PREFIX)size
80
 
81
# Host native compiler
82
CC_X86 = g++ -Wall -O -g
83
 
84
# NEORV32 executable image generator
85
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
86
 
87
# Compiler & linker flags
88
CC_OPTS  = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
89
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
90
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
91
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
92
CC_OPTS += $(USER_FLAGS)
93
 
94
 
95
# -----------------------------------------------------------------------------
96
# Application output definitions
97
# -----------------------------------------------------------------------------
98
.PHONY: check info help elf_info clean clean_all bootloader
99
.DEFAULT_GOAL := help
100
 
101
# 'compile' is still here for compatibility
102
exe:     $(APP_ASM) $(APP_EXE)
103
hex:     $(APP_ASM) $(APP_HEX)
104
compile: $(APP_ASM) $(APP_EXE)
105
install: $(APP_ASM) $(APP_IMG)
106
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG) $(APP_HEX)
107
 
108
# Check if making bootloader
109
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
110
# Also define "make_bootloader" for crt0.S
111
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
112
 
113
 
114
# -----------------------------------------------------------------------------
115
# Image generator targets
116
# -----------------------------------------------------------------------------
117
# install/compile tools
118
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
119
        @echo Compiling $(IMAGE_GEN)
120
        @$(CC_X86) $< -o $(IMAGE_GEN)
121
 
122
 
123
# -----------------------------------------------------------------------------
124
# General targets: Assemble, compile, link, dump
125
# -----------------------------------------------------------------------------
126
# Compile app *.s sources (assembly)
127
%.s.o: %.s
128
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
129
 
130
# Compile app *.S sources (assembly + C pre-processor)
131
%.S.o: %.S
132
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
133
 
134
# Compile app *.c sources
135
%.c.o: %.c
136
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
137
 
138
# Compile app *.cpp sources
139
%.cpp.o: %.cpp
140
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
141
 
142
# Link object files and show memory utilization
143
main.elf: $(OBJ)
144
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
145
        @echo "Memory utilization:"
146
        @$(SIZE) main.elf
147
 
148
# Assembly listing file (for debugging)
149
$(APP_ASM): main.elf
150
        @$(OBJDUMP) -d -S -z  $< > $@
151
 
152
# Generate final executable from .text + .rodata + .data (in THIS order!)
153
main.bin: main.elf $(APP_ASM)
154
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
155
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
156
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
157
        @cat text.bin rodata.bin data.bin > $@
158
        @rm -f text.bin rodata.bin data.bin
159
 
160
 
161
# -----------------------------------------------------------------------------
162
# Application targets: Generate binary executable, install (as VHDL file)
163
# -----------------------------------------------------------------------------
164
# Generate NEORV32 executable image for upload via bootloader
165
$(APP_EXE): main.bin $(IMAGE_GEN)
166
        @set -e
167
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
168
        @echo "Executable ($(APP_EXE)) size in bytes:"
169
        @wc -c < $(APP_EXE)
170
 
171
# Generate NEORV32 executable VHDL boot image
172
$(APP_IMG): main.bin $(IMAGE_GEN)
173
        @set -e
174
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
175
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
176
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
177
 
178
# Generate NEORV32 executable image in plain hex format
179
$(APP_HEX): main.bin $(IMAGE_GEN)
180
        @set -e
181
        @$(IMAGE_GEN) -app_hex $< $@ $(shell basename $(CURDIR))
182
 
183
 
184
# -----------------------------------------------------------------------------
185
# Bootloader targets
186
# -----------------------------------------------------------------------------
187
# Create and install bootloader VHDL init image
188
$(BOOT_IMG): main.bin $(IMAGE_GEN)
189
        @set -e
190
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
191
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
192
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
193
 
194
# Just an alias that
195
bootloader: $(BOOT_IMG)
196
 
197
 
198
# -----------------------------------------------------------------------------
199
# Check toolchain
200
# -----------------------------------------------------------------------------
201
check: $(IMAGE_GEN)
202
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
203
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
204
$(error NEORV32_HOME folder not found!)
205
endif
206
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
207
        @echo "---------------- Check: $(CC) ----------------"
208
        @$(CC) -v
209
        @echo "---------------- Check: $(OBJDUMP) ----------------"
210
        @$(OBJDUMP) -V
211
        @echo "---------------- Check: $(OBJCOPY) ----------------"
212
        @$(OBJCOPY) -V
213
        @echo "---------------- Check: $(SIZE) ----------------"
214
        @$(SIZE) -V
215
        @echo "---------------- Check: NEORV32 image_gen ----------------"
216
        @$(IMAGE_GEN) -help
217
        @echo "---------------- Check: Native GCC ----------------"
218
        @$(CC_X86) -v
219
        @echo
220
        @echo "Toolchain check OK"
221
 
222
 
223
# -----------------------------------------------------------------------------
224
# Show configuration
225
# -----------------------------------------------------------------------------
226
info:
227
        @echo "---------------- Info: Project ----------------"
228
        @echo "Project folder:        $(shell basename $(CURDIR))"
229
        @echo "Source files:          $(APP_SRC)"
230
        @echo "Include folder(s):     $(APP_INC)"
231
        @echo "ASM include folder(s): $(ASM_INC)"
232
        @echo "---------------- Info: NEORV32 ----------------"
233
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
234
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
235
        @echo "Core source files:"
236
        @echo "$(CORE_SRC)"
237
        @echo "Core include folder:"
238
        @echo "$(NEORV32_INC_PATH)"
239
        @echo "---------------- Info: Objects ----------------"
240
        @echo "Project object files:"
241
        @echo "$(OBJ)"
242
        @echo "---------------- Info: RISC-V CPU ----------------"
243
        @echo "MARCH:      $(MARCH)"
244
        @echo "MABI:       $(MABI)"
245
        @echo "---------------- Info: Toolchain ----------------"
246
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
247
        @echo "CC:         $(CC)"
248
        @echo "OBJDUMP:    $(OBJDUMP)"
249
        @echo "OBJCOPY:    $(OBJCOPY)"
250
        @echo "SIZE:       $(SIZE)"
251
        @echo "---------------- Info: Compiler Configuration ----------------"
252
        @$(CC) -v
253
        @echo "---------------- Info: Compiler Libraries ----------------"
254
        @echo "LIBGCC:"
255
        @$(CC) -print-libgcc-file-name
256
        @echo "SEARCH-DIRS:"
257
        @$(CC) -print-search-dirs
258
        @echo "---------------- Info: Flags ----------------"
259
        @echo "USER_FLAGS: $(USER_FLAGS)"
260
        @echo "CC_OPTS:    $(CC_OPTS)"
261
        @echo "---------------- Info: Host Native GCC Flags ----------------"
262
        @echo "CC_X86:     $(CC_X86)"
263
 
264
 
265
# -----------------------------------------------------------------------------
266
# Show final ELF details (just for debugging)
267
# -----------------------------------------------------------------------------
268
elf_info: main.elf
269
        @$(OBJDUMP) -x main.elf
270
 
271
 
272
# -----------------------------------------------------------------------------
273
# Help
274
# -----------------------------------------------------------------------------
275
help:
276
        @echo "<<< NEORV32 Application Makefile >>>"
277
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
278
        @echo "Targets:"
279
        @echo " help       - show this text"
280
        @echo " check      - check toolchain"
281
        @echo " info       - show makefile/toolchain configuration"
282
        @echo " exe        - compile and generate  executable for upload via bootloader"
283
        @echo " hex        - compile and generate  executable raw file"
284
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
285
        @echo " all        - exe + hex + install"
286
        @echo " elf_info   - show ELF layout info"
287
        @echo " clean      - clean up project"
288
        @echo " clean_all  - clean up project, core libraries and image generator"
289
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
290
 
291
 
292
# -----------------------------------------------------------------------------
293
# Clean up
294
# -----------------------------------------------------------------------------
295
clean:
296
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd *.hex
297
 
298
clean_all: clean
299
        @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.