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

Subversion Repositories neorv32

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

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 65 zero_gravi
MARCH ?= rv32i
20
MABI  ?= ilp32
21 62 zero_gravi
 
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 65 zero_gravi
CC_OPTS  = -march=$(MARCH) -mabi=$(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
91 62 zero_gravi
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 65 zero_gravi
image:   $(APP_ASM) $(APP_IMG)
108
install: image install-$(APP_IMG)
109
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG) $(APP_HEX) install
110 62 zero_gravi
 
111
# Check if making bootloader
112 65 zero_gravi
# Use different base address and length for instruction memory/"rom" (BOOTROM instead of IMEM)
113
# Also define "make_bootloader" symbol for crt0.S
114 62 zero_gravi
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
115 65 zero_gravi
target bl_image:   CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
116 62 zero_gravi
 
117
 
118
# -----------------------------------------------------------------------------
119
# Image generator targets
120
# -----------------------------------------------------------------------------
121
# install/compile tools
122 63 zero_gravi
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.c
123 62 zero_gravi
        @echo Compiling $(IMAGE_GEN)
124
        @$(CC_X86) $< -o $(IMAGE_GEN)
125
 
126
 
127
# -----------------------------------------------------------------------------
128
# General targets: Assemble, compile, link, dump
129
# -----------------------------------------------------------------------------
130
# Compile app *.s sources (assembly)
131
%.s.o: %.s
132
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
133
 
134
# Compile app *.S sources (assembly + C pre-processor)
135
%.S.o: %.S
136
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
137
 
138
# Compile app *.c sources
139
%.c.o: %.c
140
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
141
 
142
# Compile app *.cpp sources
143
%.cpp.o: %.cpp
144
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
145
 
146
# Link object files and show memory utilization
147
main.elf: $(OBJ)
148
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
149
        @echo "Memory utilization:"
150
        @$(SIZE) main.elf
151
 
152
# Assembly listing file (for debugging)
153
$(APP_ASM): main.elf
154
        @$(OBJDUMP) -d -S -z  $< > $@
155
 
156
# Generate final executable from .text + .rodata + .data (in THIS order!)
157
main.bin: main.elf $(APP_ASM)
158
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
159
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
160
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
161
        @cat text.bin rodata.bin data.bin > $@
162
        @rm -f text.bin rodata.bin data.bin
163
 
164
 
165
# -----------------------------------------------------------------------------
166
# Application targets: Generate binary executable, install (as VHDL file)
167
# -----------------------------------------------------------------------------
168
# Generate NEORV32 executable image for upload via bootloader
169
$(APP_EXE): main.bin $(IMAGE_GEN)
170
        @set -e
171
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
172
        @echo "Executable ($(APP_EXE)) size in bytes:"
173
        @wc -c < $(APP_EXE)
174
 
175
# Generate NEORV32 executable VHDL boot image
176
$(APP_IMG): main.bin $(IMAGE_GEN)
177
        @set -e
178
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
179 65 zero_gravi
 
180
install-$(APP_IMG): $(APP_IMG)
181
        @set -e
182 62 zero_gravi
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
183
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
184
 
185
# Generate NEORV32 executable image in plain hex format
186
$(APP_HEX): main.bin $(IMAGE_GEN)
187
        @set -e
188
        @$(IMAGE_GEN) -app_hex $< $@ $(shell basename $(CURDIR))
189
 
190
 
191
# -----------------------------------------------------------------------------
192
# Bootloader targets
193
# -----------------------------------------------------------------------------
194
# Create and install bootloader VHDL init image
195
$(BOOT_IMG): main.bin $(IMAGE_GEN)
196
        @set -e
197
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
198 65 zero_gravi
 
199
install-$(BOOT_IMG): $(BOOT_IMG)
200
        @set -e
201 62 zero_gravi
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
202
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
203
 
204 65 zero_gravi
# Just an alias
205
bl_image: $(BOOT_IMG)
206
bootloader: bl_image install-$(BOOT_IMG)
207 62 zero_gravi
 
208
 
209
# -----------------------------------------------------------------------------
210
# Check toolchain
211
# -----------------------------------------------------------------------------
212
check: $(IMAGE_GEN)
213
        @echo "---------------- Check: NEORV32_HOME folder ----------------"
214
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
215
$(error NEORV32_HOME folder not found!)
216
endif
217
        @echo "NEORV32_HOME: $(NEORV32_HOME)"
218
        @echo "---------------- Check: $(CC) ----------------"
219
        @$(CC) -v
220
        @echo "---------------- Check: $(OBJDUMP) ----------------"
221
        @$(OBJDUMP) -V
222
        @echo "---------------- Check: $(OBJCOPY) ----------------"
223
        @$(OBJCOPY) -V
224
        @echo "---------------- Check: $(SIZE) ----------------"
225
        @$(SIZE) -V
226
        @echo "---------------- Check: NEORV32 image_gen ----------------"
227
        @$(IMAGE_GEN) -help
228
        @echo "---------------- Check: Native GCC ----------------"
229
        @$(CC_X86) -v
230
        @echo
231
        @echo "Toolchain check OK"
232
 
233
 
234
# -----------------------------------------------------------------------------
235
# Show configuration
236
# -----------------------------------------------------------------------------
237
info:
238
        @echo "---------------- Info: Project ----------------"
239
        @echo "Project folder:        $(shell basename $(CURDIR))"
240
        @echo "Source files:          $(APP_SRC)"
241
        @echo "Include folder(s):     $(APP_INC)"
242
        @echo "ASM include folder(s): $(ASM_INC)"
243
        @echo "---------------- Info: NEORV32 ----------------"
244
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
245
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
246
        @echo "Core source files:"
247
        @echo "$(CORE_SRC)"
248
        @echo "Core include folder:"
249
        @echo "$(NEORV32_INC_PATH)"
250
        @echo "---------------- Info: Objects ----------------"
251
        @echo "Project object files:"
252
        @echo "$(OBJ)"
253
        @echo "---------------- Info: RISC-V CPU ----------------"
254
        @echo "MARCH:      $(MARCH)"
255
        @echo "MABI:       $(MABI)"
256
        @echo "---------------- Info: Toolchain ----------------"
257
        @echo "Toolchain:  $(RISCV_TOLLCHAIN)"
258
        @echo "CC:         $(CC)"
259
        @echo "OBJDUMP:    $(OBJDUMP)"
260
        @echo "OBJCOPY:    $(OBJCOPY)"
261
        @echo "SIZE:       $(SIZE)"
262
        @echo "---------------- Info: Compiler Configuration ----------------"
263
        @$(CC) -v
264
        @echo "---------------- Info: Compiler Libraries ----------------"
265
        @echo "LIBGCC:"
266
        @$(CC) -print-libgcc-file-name
267
        @echo "SEARCH-DIRS:"
268
        @$(CC) -print-search-dirs
269
        @echo "---------------- Info: Flags ----------------"
270
        @echo "USER_FLAGS: $(USER_FLAGS)"
271
        @echo "CC_OPTS:    $(CC_OPTS)"
272
        @echo "---------------- Info: Host Native GCC Flags ----------------"
273
        @echo "CC_X86:     $(CC_X86)"
274
 
275
 
276
# -----------------------------------------------------------------------------
277 64 zero_gravi
# In-console simulation using default/simple testbench and GHDL
278 63 zero_gravi
# -----------------------------------------------------------------------------
279 65 zero_gravi
sim: $(APP_IMG) install
280 63 zero_gravi
        @echo "Simulating $(APP_IMG)..."
281 64 zero_gravi
        @sh $(NEORV32_SIM_PATH)/simple/ghdl.sh
282 63 zero_gravi
 
283
# -----------------------------------------------------------------------------
284 62 zero_gravi
# Show final ELF details (just for debugging)
285
# -----------------------------------------------------------------------------
286
elf_info: main.elf
287
        @$(OBJDUMP) -x main.elf
288
 
289
 
290
# -----------------------------------------------------------------------------
291
# Help
292
# -----------------------------------------------------------------------------
293
help:
294
        @echo "<<< NEORV32 Application Makefile >>>"
295
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
296
        @echo "Targets:"
297
        @echo " help       - show this text"
298
        @echo " check      - check toolchain"
299
        @echo " info       - show makefile/toolchain configuration"
300
        @echo " exe        - compile and generate  executable for upload via bootloader"
301
        @echo " hex        - compile and generate  executable raw file"
302 65 zero_gravi
        @echo " image      - compile and generate VHDL IMEM boot image (for application) in local folder"
303 62 zero_gravi
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
304 64 zero_gravi
        @echo " sim        - in-console simulation using default/simple testbench and GHDL"
305 62 zero_gravi
        @echo " all        - exe + hex + install"
306
        @echo " elf_info   - show ELF layout info"
307
        @echo " clean      - clean up project"
308
        @echo " clean_all  - clean up project, core libraries and image generator"
309 65 zero_gravi
        @echo " bl_image   - compile and generate VHDL BOOTROM boot image (for bootloader only!) in local folder"
310 62 zero_gravi
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
311
 
312
 
313
# -----------------------------------------------------------------------------
314
# Clean up
315
# -----------------------------------------------------------------------------
316
clean:
317
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd *.hex
318
 
319
clean_all: clean
320
        @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.