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