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

Subversion Repositories neorv32

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

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