| 1 |
59 |
zero_gravi |
#################################################################################################
|
| 2 |
|
|
# << NEORV32 - Application Makefile >> #
|
| 3 |
|
|
# ********************************************************************************************* #
|
| 4 |
|
|
# Make sure to add the RISC-V GCC compiler's bin folder to your PATH environment variable. #
|
| 5 |
|
|
# ********************************************************************************************* #
|
| 6 |
|
|
# FOR DEBUGGER "PARK LOOP" CODE ONLY! #
|
| 7 |
|
|
# ********************************************************************************************* #
|
| 8 |
|
|
# BSD 3-Clause License #
|
| 9 |
|
|
# #
|
| 10 |
|
|
# Copyright (c) 2021, Stephan Nolting. All rights reserved. #
|
| 11 |
|
|
# #
|
| 12 |
|
|
# Redistribution and use in source and binary forms, with or without modification, are #
|
| 13 |
|
|
# permitted provided that the following conditions are met: #
|
| 14 |
|
|
# #
|
| 15 |
|
|
# 1. Redistributions of source code must retain the above copyright notice, this list of #
|
| 16 |
|
|
# conditions and the following disclaimer. #
|
| 17 |
|
|
# #
|
| 18 |
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
| 19 |
|
|
# conditions and the following disclaimer in the documentation and/or other materials #
|
| 20 |
|
|
# provided with the distribution. #
|
| 21 |
|
|
# #
|
| 22 |
|
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
| 23 |
|
|
# endorse or promote products derived from this software without specific prior written #
|
| 24 |
|
|
# permission. #
|
| 25 |
|
|
# #
|
| 26 |
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
| 27 |
|
|
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
| 28 |
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
| 29 |
|
|
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
| 30 |
|
|
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
| 31 |
|
|
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
| 32 |
|
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
| 33 |
|
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
| 34 |
|
|
# OF THE POSSIBILITY OF SUCH DAMAGE. #
|
| 35 |
|
|
# ********************************************************************************************* #
|
| 36 |
|
|
# The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
|
| 37 |
|
|
#################################################################################################
|
| 38 |
|
|
|
| 39 |
|
|
|
| 40 |
|
|
# *****************************************************************************
|
| 41 |
|
|
# USER CONFIGURATION
|
| 42 |
|
|
# *****************************************************************************
|
| 43 |
|
|
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
|
| 44 |
|
|
APP_SRC ?= $(wildcard ./*.S)
|
| 45 |
|
|
|
| 46 |
|
|
# User's application include folders (don't forget the '-I' before each entry)
|
| 47 |
|
|
APP_INC ?= -I .
|
| 48 |
|
|
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
|
| 49 |
|
|
ASM_INC ?= -I .
|
| 50 |
|
|
|
| 51 |
|
|
# Optimization
|
| 52 |
|
|
EFFORT ?= -Os
|
| 53 |
|
|
|
| 54 |
|
|
# Compiler toolchain
|
| 55 |
62 |
zero_gravi |
RISCV_PREFIX ?= riscv32-unknown-elf-
|
| 56 |
59 |
zero_gravi |
|
| 57 |
|
|
# CPU architecture and ABI
|
| 58 |
|
|
MARCH = -march=rv32i
|
| 59 |
|
|
MABI = -mabi=ilp32
|
| 60 |
|
|
|
| 61 |
|
|
# User flags for additional configuration (will be added to compiler flags)
|
| 62 |
|
|
USER_FLAGS ?=
|
| 63 |
|
|
|
| 64 |
|
|
# Relative or absolute path to the NEORV32 home folder
|
| 65 |
|
|
NEORV32_HOME ?= ../..
|
| 66 |
|
|
# *****************************************************************************
|
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
|
| 70 |
|
|
# -----------------------------------------------------------------------------
|
| 71 |
|
|
# NEORV32 framework
|
| 72 |
|
|
# -----------------------------------------------------------------------------
|
| 73 |
|
|
# Path to NEORV32 linker script and startup file
|
| 74 |
|
|
NEORV32_COM_PATH = $(NEORV32_HOME)/sw/common
|
| 75 |
|
|
# Path to main NEORV32 library include files
|
| 76 |
|
|
NEORV32_INC_PATH = $(NEORV32_HOME)/sw/lib/include
|
| 77 |
|
|
# Path to main NEORV32 library source files
|
| 78 |
|
|
NEORV32_SRC_PATH = $(NEORV32_HOME)/sw/lib/source
|
| 79 |
|
|
# Path to NEORV32 executable generator
|
| 80 |
|
|
NEORV32_EXG_PATH = $(NEORV32_HOME)/sw/image_gen
|
| 81 |
|
|
# Path to NEORV32 core rtl folder
|
| 82 |
|
|
NEORV32_RTL_PATH = $(NEORV32_HOME)/rtl/core
|
| 83 |
|
|
# Marker file to check for NEORV32 home folder
|
| 84 |
|
|
NEORV32_HOME_MARKER = $(NEORV32_INC_PATH)/neorv32.h
|
| 85 |
|
|
|
| 86 |
|
|
# Linker script
|
| 87 |
|
|
LD_SCRIPT = ./debug_rom.ld
|
| 88 |
|
|
|
| 89 |
|
|
# Main output files
|
| 90 |
|
|
APP_ASM = main.asm
|
| 91 |
|
|
APP_IMG = neorv32_debug_mem.code.vhd
|
| 92 |
|
|
|
| 93 |
|
|
|
| 94 |
|
|
# -----------------------------------------------------------------------------
|
| 95 |
|
|
# Sources and objects
|
| 96 |
|
|
# -----------------------------------------------------------------------------
|
| 97 |
|
|
# Define all sources
|
| 98 |
|
|
SRC = $(APP_SRC)
|
| 99 |
|
|
|
| 100 |
|
|
# Define all object files
|
| 101 |
|
|
OBJ = $(SRC:%=%.o)
|
| 102 |
|
|
|
| 103 |
|
|
|
| 104 |
|
|
# -----------------------------------------------------------------------------
|
| 105 |
|
|
# Tools and flags
|
| 106 |
|
|
# -----------------------------------------------------------------------------
|
| 107 |
|
|
# Compiler tools
|
| 108 |
62 |
zero_gravi |
CC = $(RISCV_PREFIX)gcc
|
| 109 |
|
|
OBJDUMP = $(RISCV_PREFIX)objdump
|
| 110 |
|
|
OBJCOPY = $(RISCV_PREFIX)objcopy
|
| 111 |
|
|
SIZE = $(RISCV_PREFIX)size
|
| 112 |
59 |
zero_gravi |
|
| 113 |
|
|
# Host native compiler
|
| 114 |
|
|
CC_X86 = g++ -Wall -O -g
|
| 115 |
|
|
|
| 116 |
|
|
# NEORV32 executable image generator
|
| 117 |
|
|
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
|
| 118 |
|
|
|
| 119 |
|
|
# Compiler & linker flags
|
| 120 |
|
|
CC_OPTS = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
|
| 121 |
|
|
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
|
| 122 |
|
|
# This accelerates instruction fetch after branches when C extension is enabled (irrelevant when C extension is disabled)
|
| 123 |
|
|
CC_OPTS += -falign-functions=4 -falign-labels=4 -falign-loops=4 -falign-jumps=4
|
| 124 |
|
|
CC_OPTS += $(USER_FLAGS)
|
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
# -----------------------------------------------------------------------------
|
| 128 |
|
|
# Application output definitions
|
| 129 |
|
|
# -----------------------------------------------------------------------------
|
| 130 |
|
|
.PHONY: check info help elf_info clean clean_all bootloader
|
| 131 |
|
|
.DEFAULT_GOAL := help
|
| 132 |
|
|
|
| 133 |
|
|
# 'compile' is still here for compatibility
|
| 134 |
|
|
compile: $(APP_ASM)
|
| 135 |
|
|
install: $(APP_ASM) $(APP_IMG)
|
| 136 |
|
|
all: $(APP_ASM) $(APP_IMG)
|
| 137 |
|
|
|
| 138 |
|
|
# Check if making bootloader
|
| 139 |
|
|
# Use different base address and legth for instruction memory/"rom" (BOOTMEM instead of IMEM)
|
| 140 |
|
|
# Also define "make_bootloader" for crt0.S
|
| 141 |
|
|
target bootloader: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader
|
| 142 |
|
|
|
| 143 |
|
|
|
| 144 |
|
|
# -----------------------------------------------------------------------------
|
| 145 |
|
|
# Image generator targets
|
| 146 |
|
|
# -----------------------------------------------------------------------------
|
| 147 |
|
|
# install/compile tools
|
| 148 |
63 |
zero_gravi |
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.c
|
| 149 |
59 |
zero_gravi |
@echo Compiling $(IMAGE_GEN)
|
| 150 |
|
|
@$(CC_X86) $< -o $(IMAGE_GEN)
|
| 151 |
|
|
|
| 152 |
|
|
|
| 153 |
|
|
# -----------------------------------------------------------------------------
|
| 154 |
|
|
# General targets: Assemble, compile, link, dump
|
| 155 |
|
|
# -----------------------------------------------------------------------------
|
| 156 |
|
|
# Compile app *.s sources (assembly)
|
| 157 |
|
|
%.s.o: %.s
|
| 158 |
|
|
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
|
| 159 |
|
|
|
| 160 |
|
|
# Compile app *.S sources (assembly + C pre-processor)
|
| 161 |
|
|
%.S.o: %.S
|
| 162 |
|
|
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
|
| 163 |
|
|
|
| 164 |
|
|
# Compile app *.c sources
|
| 165 |
|
|
%.c.o: %.c
|
| 166 |
|
|
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
|
| 167 |
|
|
|
| 168 |
|
|
# Compile app *.cpp sources
|
| 169 |
|
|
%.cpp.o: %.cpp
|
| 170 |
|
|
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
|
| 171 |
|
|
|
| 172 |
|
|
# Link object files and show memory utilization
|
| 173 |
|
|
main.elf: $(OBJ)
|
| 174 |
|
|
@$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
|
| 175 |
|
|
@echo "Memory utilization:"
|
| 176 |
|
|
@$(SIZE) main.elf
|
| 177 |
|
|
|
| 178 |
|
|
# Assembly listing file (for debugging)
|
| 179 |
|
|
$(APP_ASM): main.elf
|
| 180 |
|
|
@$(OBJDUMP) -d -S -z $< > $@
|
| 181 |
|
|
|
| 182 |
|
|
# Generate final executable from .text only
|
| 183 |
|
|
main.bin: main.elf $(APP_ASM)
|
| 184 |
|
|
@$(OBJCOPY) -I elf32-little $< -j .text -O binary text.bin
|
| 185 |
|
|
@cat text.bin > $@
|
| 186 |
|
|
@rm -f text.bin
|
| 187 |
|
|
|
| 188 |
|
|
|
| 189 |
|
|
# -----------------------------------------------------------------------------
|
| 190 |
|
|
# Application targets: install (as VHDL file)
|
| 191 |
|
|
# -----------------------------------------------------------------------------
|
| 192 |
|
|
|
| 193 |
|
|
# Generate NEORV32 executable VHDL boot image
|
| 194 |
|
|
$(APP_IMG): main.bin $(IMAGE_GEN)
|
| 195 |
|
|
@set -e
|
| 196 |
|
|
@$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
|
| 197 |
|
|
|
| 198 |
|
|
|
| 199 |
|
|
# -----------------------------------------------------------------------------
|
| 200 |
|
|
# Check toolchain
|
| 201 |
|
|
# -----------------------------------------------------------------------------
|
| 202 |
|
|
check: $(IMAGE_GEN)
|
| 203 |
|
|
@echo "---------------- Check: NEORV32_HOME folder ----------------"
|
| 204 |
|
|
ifneq ($(shell [ -e $(NEORV32_HOME_MARKER) ] && echo 1 || echo 0 ), 1)
|
| 205 |
|
|
$(error NEORV32_HOME folder not found!)
|
| 206 |
|
|
endif
|
| 207 |
|
|
@echo "NEORV32_HOME: $(NEORV32_HOME)"
|
| 208 |
|
|
@echo "---------------- Check: $(CC) ----------------"
|
| 209 |
|
|
@$(CC) -v
|
| 210 |
|
|
@echo "---------------- Check: $(OBJDUMP) ----------------"
|
| 211 |
|
|
@$(OBJDUMP) -V
|
| 212 |
|
|
@echo "---------------- Check: $(OBJCOPY) ----------------"
|
| 213 |
|
|
@$(OBJCOPY) -V
|
| 214 |
|
|
@echo "---------------- Check: $(SIZE) ----------------"
|
| 215 |
|
|
@$(SIZE) -V
|
| 216 |
|
|
@echo "---------------- Check: NEORV32 image_gen ----------------"
|
| 217 |
|
|
@$(IMAGE_GEN) -help
|
| 218 |
|
|
@echo "---------------- Check: Native GCC ----------------"
|
| 219 |
|
|
@$(CC_X86) -v
|
| 220 |
|
|
@echo
|
| 221 |
|
|
@echo "Toolchain check OK"
|
| 222 |
|
|
|
| 223 |
|
|
|
| 224 |
|
|
# -----------------------------------------------------------------------------
|
| 225 |
|
|
# Show configuration
|
| 226 |
|
|
# -----------------------------------------------------------------------------
|
| 227 |
|
|
info:
|
| 228 |
|
|
@echo "---------------- Info: Project ----------------"
|
| 229 |
|
|
@echo "Project folder: $(shell basename $(CURDIR))"
|
| 230 |
|
|
@echo "Source files: $(APP_SRC)"
|
| 231 |
|
|
@echo "Include folder(s): $(APP_INC)"
|
| 232 |
|
|
@echo "ASM include folder(s): $(ASM_INC)"
|
| 233 |
|
|
@echo "---------------- Info: NEORV32 ----------------"
|
| 234 |
|
|
@echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
|
| 235 |
|
|
@echo "IMAGE_GEN: $(IMAGE_GEN)"
|
| 236 |
|
|
@echo "Core source files:"
|
| 237 |
|
|
@echo "$(CORE_SRC)"
|
| 238 |
|
|
@echo "Core include folder:"
|
| 239 |
|
|
@echo "$(NEORV32_INC_PATH)"
|
| 240 |
|
|
@echo "---------------- Info: Objects ----------------"
|
| 241 |
|
|
@echo "Project object files:"
|
| 242 |
|
|
@echo "$(OBJ)"
|
| 243 |
|
|
@echo "---------------- Info: RISC-V CPU ----------------"
|
| 244 |
|
|
@echo "MARCH: $(MARCH)"
|
| 245 |
|
|
@echo "MABI: $(MABI)"
|
| 246 |
|
|
@echo "---------------- Info: Toolchain ----------------"
|
| 247 |
|
|
@echo "Toolchain: $(RISCV_TOLLCHAIN)"
|
| 248 |
|
|
@echo "CC: $(CC)"
|
| 249 |
|
|
@echo "OBJDUMP: $(OBJDUMP)"
|
| 250 |
|
|
@echo "OBJCOPY: $(OBJCOPY)"
|
| 251 |
|
|
@echo "SIZE: $(SIZE)"
|
| 252 |
|
|
@echo "---------------- Info: Compiler Libraries ----------------"
|
| 253 |
|
|
@echo "LIBGCC:"
|
| 254 |
|
|
@$(CC) -print-libgcc-file-name
|
| 255 |
|
|
@echo "SEARCH-DIRS:"
|
| 256 |
|
|
@$(CC) -print-search-dirs
|
| 257 |
|
|
@echo "---------------- Info: Flags ----------------"
|
| 258 |
|
|
@echo "USER_FLAGS: $(USER_FLAGS)"
|
| 259 |
|
|
@echo "CC_OPTS: $(CC_OPTS)"
|
| 260 |
|
|
@echo "---------------- Info: Host Native GCC Flags ----------------"
|
| 261 |
|
|
@echo "CC_X86: $(CC_X86)"
|
| 262 |
|
|
|
| 263 |
|
|
|
| 264 |
|
|
# -----------------------------------------------------------------------------
|
| 265 |
|
|
# Show final ELF details (just for debugging)
|
| 266 |
|
|
# -----------------------------------------------------------------------------
|
| 267 |
|
|
elf_info: main.elf
|
| 268 |
|
|
@$(OBJDUMP) -x main.elf
|
| 269 |
|
|
|
| 270 |
|
|
|
| 271 |
|
|
# -----------------------------------------------------------------------------
|
| 272 |
|
|
# Help
|
| 273 |
|
|
# -----------------------------------------------------------------------------
|
| 274 |
|
|
help:
|
| 275 |
|
|
@echo "<<< NEORV32 Application Makefile >>>"
|
| 276 |
|
|
@echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
|
| 277 |
|
|
@echo "Targets:"
|
| 278 |
|
|
@echo " help - show this text"
|
| 279 |
|
|
@echo " check - check toolchain"
|
| 280 |
|
|
@echo " info - show makefile/toolchain configuration"
|
| 281 |
|
|
@echo " exe - compile and generate executable for upload via bootloader"
|
| 282 |
|
|
@echo " all - compile and generate executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
|
| 283 |
|
|
@echo " clean - clean up project"
|
| 284 |
|
|
@echo " clean_all - clean up project, core libraries and image generator"
|
| 285 |
|
|
|
| 286 |
|
|
|
| 287 |
|
|
# -----------------------------------------------------------------------------
|
| 288 |
|
|
# Clean up
|
| 289 |
|
|
# -----------------------------------------------------------------------------
|
| 290 |
|
|
clean:
|
| 291 |
|
|
@rm -f *.elf *.o *.bin *.out *.asm *.vhd
|
| 292 |
|
|
|
| 293 |
|
|
clean_all: clean
|
| 294 |
|
|
@rm -f $(OBJ) $(IMAGE_GEN)
|