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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_wdt/] [makefile] - Diff between revs 19 and 21

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 19 Rev 21
Line 34... Line 34...
# The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
# The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
#################################################################################################
#################################################################################################
 
 
 
 
# *****************************************************************************
# *****************************************************************************
# USER CONFIGURATION (use default if not set by user)
# USER CONFIGURATION
# *****************************************************************************
# *****************************************************************************
# Compiler effort
# User's application sources (*.c, *.cpp, *.s, *.S); add additional files here
EFFORT ?= -Os
APP_SRC ?= $(wildcard ./*.c) $(wildcard ./*.s) $(wildcard ./*.cpp) $(wildcard ./*.S)
 
 
# User's application sources (add additional files here)
 
APP_SRC ?= $(wildcard *.c)
 
 
 
# User's application include folders (don't forget the '-I' before each entry)
# User's application include folders (don't forget the '-I' before each entry)
APP_INC ?= -I .
APP_INC ?= -I .
 
# User's application include folders - for assembly files only (don't forget the '-I' before each entry)
 
ASM_INC ?= -I .
 
 
 
# Optimization
 
EFFORT ?= -Os
 
 
# Compiler toolchain
# Compiler toolchain
RISCV_TOOLCHAIN ?= riscv32-unknown-elf
RISCV_TOOLCHAIN ?= riscv32-unknown-elf
 
 
# CPU architecture and ABI
# CPU architecture and ABI
MARCH ?= -march=rv32i
MARCH ?= -march=rv32i
MABI  ?= -mabi=ilp32
MABI  ?= -mabi=ilp32
 
 
 
# User flags for additional configuration (will be added to compiler flags)
 
USER_FLAGS ?=
 
 
# Relative or absolute path to the NEORV32 home folder
# Relative or absolute path to the NEORV32 home folder
NEORV32_HOME ?= ../../..
NEORV32_HOME ?= ../../..
# *****************************************************************************
# *****************************************************************************
 
 
 
 
Line 71... Line 76...
NEORV32_SRC_PATH=$(NEORV32_HOME)/sw/lib/source
NEORV32_SRC_PATH=$(NEORV32_HOME)/sw/lib/source
# Path to NEORV32 executable generator
# Path to NEORV32 executable generator
NEORV32_EXG_PATH=$(NEORV32_HOME)/sw/image_gen
NEORV32_EXG_PATH=$(NEORV32_HOME)/sw/image_gen
# Path to NEORV32 core rtl folder
# Path to NEORV32 core rtl folder
NEORV32_RTL_PATH=$(NEORV32_HOME)/rtl/core
NEORV32_RTL_PATH=$(NEORV32_HOME)/rtl/core
# Marker file to verify NEORV32 home folder
# Marker file to check for NEORV32 home folder
NEORV32_HOME_MARKER=$(NEORV32_INC_PATH)/neorv32.h
NEORV32_HOME_MARKER=$(NEORV32_INC_PATH)/neorv32.h
 
 
 
# Core libraries (peripheral and CPU drivers)
# -----------------------------------------------------------------------------
 
# NEORV32 core sources
 
# -----------------------------------------------------------------------------
 
CORE_SRC = $(wildcard $(NEORV32_SRC_PATH)/*.c)
CORE_SRC = $(wildcard $(NEORV32_SRC_PATH)/*.c)
 
# Application start-up code
 
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S
 
 
 
# Default linker script
 
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
 
 
# -----------------------------------------------------------------------------
# Main output files
# Make defaults
APP_EXE  = neorv32_exe.bin
# -----------------------------------------------------------------------------
APP_ASM  = main.asm
.DEFAULT_GOAL := help
APP_IMG  = neorv32_application_image.vhd
 
BOOT_IMG = neorv32_bootloader_image.vhd
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Application output definitions
# Sources and objects
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
APP_EXE = neorv32_exe.bin
# Define all sources
APP_ASM = main.s
SRC  = $(APP_SRC)
 
SRC += $(CORE_SRC)
compile: $(APP_ASM) $(APP_EXE)
 
install: $(APP_ASM) neorv32_application_image.vhd
 
all:     $(APP_ASM) $(APP_EXE) neorv32_application_image.vhd
 
 
 
# define all object files
# Define all object files
OBJ  = $(APP_SRC:.c=.o)
OBJ = $(SRC:%=%.o)
OBJ += $(CORE_SRC:.c=.o)
 
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Tools and flags
# Tools and flags
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# compiler tools
# Compiler tools
CC      = $(RISCV_TOOLCHAIN)-gcc
CC      = $(RISCV_TOOLCHAIN)-gcc
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
OBJDUMP = $(RISCV_TOOLCHAIN)-objdump
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
OBJCOPY = $(RISCV_TOOLCHAIN)-objcopy
SIZE    = $(RISCV_TOOLCHAIN)-size
SIZE    = $(RISCV_TOOLCHAIN)-size
 
 
 
# Host native compiler
 
CC_X86 = gcc -Wall -O -g
 
 
# NEORV32 executable image generator
# NEORV32 executable image generator
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
 
 
# Compiler & linker flags
# Compiler & linker flags
CC_OPTS = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles
CC_OPTS = $(MARCH) $(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc
 
 
# User flags for additional configuration
 
USER_FLAGS =
 
CC_OPTS += $(USER_FLAGS)
CC_OPTS += $(USER_FLAGS)
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Host native compiler
# Application output definitions
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
CC_X86 = gcc -Wall -O -g
.PHONY: check info help elf_info clean clean_all bootloader
 
.DEFAULT_GOAL := help
 
 
 
# 'compile' is still here for compatibility
 
exe:     $(APP_ASM) $(APP_EXE)
 
compile: $(APP_ASM) $(APP_EXE)
 
install: $(APP_ASM) $(APP_IMG)
 
all:     $(APP_ASM) $(APP_EXE) $(APP_IMG)
 
 
 
# Check if making bootloader
 
# This will disable some functions in crt0.S that are not relevant for the bootloader
 
target bootloader: USER_FLAGS += -D__BOOTLOADER_START_CODE__
 
target bootloader: LD_SCRIPT = $(NEORV32_COM_PATH)/bootloader_neorv32.ld
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Tool targets
# Image generator targets
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# install/compile tools
# install/compile tools
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.cpp
        @echo Compiling $(IMAGE_GEN)
        @echo Compiling $(IMAGE_GEN)
        @$(CC_X86) $< -o $(IMAGE_GEN)
        @$(CC_X86) $< -o $(IMAGE_GEN)
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Application targets: Assemble, compile, link, dump
# General targets: Assemble, compile, link, dump
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Assemble startup code
# Compile app *.s sources (assembly)
crt0.elf: $(NEORV32_COM_PATH)/crt0.S
%.s.o: %.s
        @$(CC) $(CC_OPTS) -c $< -o $@
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
 
 
 
# Compile app *.S sources (assembly + C pre-processor)
 
%.S.o: %.S
 
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
 
 
 
# Compile app *.c sources
 
%.c.o: %.c
 
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
 
 
# Compile app sources
# Compile app *.cpp sources
$(OBJ): %.o : %.c crt0.elf
%.cpp.o: %.cpp
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
        @$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
 
 
# Link object files and show memory utilization
# Link object files and show memory utilization
main.elf: $(OBJ)
main.elf: $(OBJ)
        @$(CC) $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/neorv32.ld $(OBJ) -o $@
        @$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@
        @echo "Memory utilization:"
        @echo "Memory utilization:"
        @$(SIZE) main.elf
        @$(SIZE) main.elf
 
 
# Assembly listing file (for debugging)
# Assembly listing file (for debugging)
$(APP_ASM): main.elf
$(APP_ASM): main.elf
        @$(OBJDUMP) -D -S -z  $< > $@
        @$(OBJDUMP) -D -S -z  $< > $@
 
 
 
# Generate final executable from .text + .rodata + .data (in THIS order!)
# -----------------------------------------------------------------------------
main.bin: main.elf $(APP_ASM)
# Application targets: Generate binary executable, install (as VHDL file)
 
# -----------------------------------------------------------------------------
 
# Generate final executable: text, rodata, data (in THIS order!)
 
main.bin: main.elf
 
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
        @$(OBJCOPY) -I elf32-little $< -j .text   -O binary text.bin
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
        @$(OBJCOPY) -I elf32-little $< -j .rodata -O binary rodata.bin
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
        @$(OBJCOPY) -I elf32-little $< -j .data   -O binary data.bin
        @cat text.bin rodata.bin data.bin > $@
        @cat text.bin rodata.bin data.bin > $@
        @rm -f text.bin rodata.bin data.bin
        @rm -f text.bin rodata.bin data.bin
 
 
# Generate NEORV32 executable image for bootloader update
 
 
# -----------------------------------------------------------------------------
 
# Application targets: Generate binary executable, install (as VHDL file)
 
# -----------------------------------------------------------------------------
 
# Generate NEORV32 executable image for upload via bootloader
$(APP_EXE): main.bin $(IMAGE_GEN)
$(APP_EXE): main.bin $(IMAGE_GEN)
        @set -e
        @set -e
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
        @$(IMAGE_GEN) -app_bin $< $@ $(shell basename $(CURDIR))
        @echo "Executable ($(APP_EXE)) size in bytes:"
        @echo "Executable ($(APP_EXE)) size in bytes:"
        @wc -c < $(APP_EXE)
        @wc -c < $(APP_EXE)
 
 
# Generate NEORV32 executable VHDL boot image
# Generate NEORV32 executable VHDL boot image
neorv32_application_image.vhd: main.bin $(IMAGE_GEN)
$(APP_IMG): main.bin $(IMAGE_GEN)
        @set -e
        @set -e
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
        @$(IMAGE_GEN) -app_img $< $@ $(shell basename $(CURDIR))
        @echo "Installing application image to $(NEORV32_RTL_PATH)/neorv32_application_image.vhd"
        @echo "Installing application image to $(NEORV32_RTL_PATH)/$(APP_IMG)"
        @cp neorv32_application_image.vhd $(NEORV32_RTL_PATH)/.
        @cp $(APP_IMG) $(NEORV32_RTL_PATH)/.
        @rm -f neorv32_application_image.vhd
 
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Bootloader targets
# Bootloader targets
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Assemble startup code
# Create and install bootloader VHDL init image
bootloader_crt0.elf: $(NEORV32_COM_PATH)/bootloader_crt0.S
$(BOOT_IMG): main.bin $(IMAGE_GEN)
        @$(CC) $(CC_OPTS) -c $< -o $@
 
 
 
# Compile and install bootloader
 
bootloader: bootloader_crt0.elf $(OBJ) $(IMAGE_GEN)
 
        @set -e
        @set -e
        @$(CC) $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) -T $(NEORV32_COM_PATH)/bootloader_neorv32.ld $(OBJ) -o bootloader.elf
        @$(IMAGE_GEN) -bld_img $< $(BOOT_IMG) $(shell basename $(CURDIR))
        @echo "Memory utilization:"
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/$(BOOT_IMG)"
        @$(SIZE) bootloader.elf
        @cp $(BOOT_IMG) $(NEORV32_RTL_PATH)/.
        @$(OBJDUMP) -D -S -z bootloader.elf > bootloader.s
 
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .text   -O binary text.bin
# Just an alias that
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .rodata -O binary rodata.bin
bootloader: $(BOOT_IMG)
        @$(OBJCOPY) -I elf32-little bootloader.elf -j .data   -O binary data.bin
 
        @cat text.bin rodata.bin data.bin > bootloader.bin
 
        @$(IMAGE_GEN) -bld_img bootloader.bin neorv32_bootloader_image.vhd $(shell basename $(CURDIR))
 
        @echo "Installing bootloader image to $(NEORV32_RTL_PATH)/neorv32_bootloader_image.vhd"
 
        @cp neorv32_bootloader_image.vhd $(NEORV32_RTL_PATH)/.
 
        @rm -f neorv32_bootloader_image.vhd text.bin rodata.bin data.bin
 
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Check toolchain
# Check toolchain
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
Line 243... Line 256...
info:
info:
        @echo "---------------- Info: Project ----------------"
        @echo "---------------- Info: Project ----------------"
        @echo "Project folder:    $(shell basename $(CURDIR))"
        @echo "Project folder:    $(shell basename $(CURDIR))"
        @echo "Source files:      $(APP_SRC)"
        @echo "Source files:      $(APP_SRC)"
        @echo "Include folder(s): $(APP_INC)"
        @echo "Include folder(s): $(APP_INC)"
 
        @echo "ASM include folder(s): $(ASM_INC)"
        @echo "---------------- Info: NEORV32 ----------------"
        @echo "---------------- Info: NEORV32 ----------------"
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
        @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)"
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
        @echo "IMAGE_GEN: $(IMAGE_GEN)"
 
        @echo "LD script: $(LD_SCRIPT)"
        @echo "Core source files:"
        @echo "Core source files:"
        @echo "$(CORE_SRC)"
        @echo "$(CORE_SRC)"
        @echo "Core include folder:"
        @echo "Core include folder:"
        @echo "$(NEORV32_INC_PATH)"
        @echo "$(NEORV32_INC_PATH)"
 
        @echo "---------------- Info: Objects ----------------"
        @echo "Project object files:"
        @echo "Project object files:"
        @echo "$(OBJ)"
        @echo "$(OBJ)"
        @echo "---------------- Info: RISC-V CPU ----------------"
        @echo "---------------- Info: RISC-V CPU ----------------"
        @echo "MARCH:     $(MARCH)"
        @echo "MARCH:     $(MARCH)"
        @echo "MABI:      $(MABI)"
        @echo "MABI:      $(MABI)"
        @echo "---------------- Info: RISC-V Toolchain ----------------"
        @echo "---------------- Info: Toolchain ----------------"
        @echo "Toolchain: $(RISCV_TOLLCHAIN)"
        @echo "Toolchain: $(RISCV_TOLLCHAIN)"
        @echo "CC:        $(CC)"
        @echo "CC:        $(CC)"
        @echo "OBJDUMP:   $(OBJDUMP)"
        @echo "OBJDUMP:   $(OBJDUMP)"
        @echo "OBJCOPY:   $(OBJCOPY)"
        @echo "OBJCOPY:   $(OBJCOPY)"
        @echo "SIZE:      $(SIZE)"
        @echo "SIZE:      $(SIZE)"
        @echo "---------------- Info: Libraries ----------------"
        @echo "---------------- Info: Compiler Libraries ----------------"
        @echo "LIBGCC:"
        @echo "LIBGCC:"
        @$(CC) -print-libgcc-file-name
        @$(CC) -print-libgcc-file-name
        @echo "SEARCH-DIRS:"
        @echo "SEARCH-DIRS:"
        @$(CC) -print-search-dirs
        @$(CC) -print-search-dirs
        @echo "---------------- Info: Flags ----------------"
        @echo "---------------- Info: Flags ----------------"
 
        @echo "USER_FLAGS: $(USER_FLAGS)"
        @echo "CC_OPTS:   $(CC_OPTS)"
        @echo "CC_OPTS:   $(CC_OPTS)"
        @echo "---------------- Info: Host Native GCC Flags ----------------"
        @echo "---------------- Info: Host Native GCC Flags ----------------"
        @echo "CC_X86:    $(CC_X86)"
        @echo "CC_X86:    $(CC_X86)"
 
 
 
 
Line 289... Line 306...
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
        @echo "Make sure to add the bin folder of RISC-V GCC to your PATH variable."
        @echo "Targets:"
        @echo "Targets:"
        @echo " help       - show this text"
        @echo " help       - show this text"
        @echo " check      - check toolchain"
        @echo " check      - check toolchain"
        @echo " info       - show makefile/toolchain configuration"
        @echo " info       - show makefile/toolchain configuration"
        @echo " compile    - compile and generate  executable for upload via bootloader"
        @echo " exe        - compile and generate  executable for upload via bootloader"
        @echo " install    - compile, generate and install VHDL IMEM boot image"
        @echo " install    - compile, generate and install VHDL IMEM boot image (for application)"
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image"
        @echo " all        - compile and generate  executable for upload via bootloader and generate and install VHDL IMEM boot image (for application)"
        @echo " clean      - clean up project"
        @echo " clean      - clean up project"
        @echo " clean_all  - clean up project, core libraries and image generator"
        @echo " clean_all  - clean up project, core libraries and image generator"
        @echo " bootloader - compile, generate and install VHDL BOOTROM bott image (for bootloader only!)"
        @echo " bootloader - compile, generate and install VHDL BOOTROM boot image (for bootloader only!)"
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Clean up
# Clean up
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
clean:
clean:
        @rm -f *.elf *.o *.bin *.out *.s
        @rm -f *.elf *.o *.bin *.out *.asm *.vhd
 
 
clean_all: clean
clean_all: clean
        @rm -f $(OBJ) $(IMAGE_GEN)
        @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.