From f3b42aa5e475032c6af5c40effd03e8aa556132e Mon Sep 17 00:00:00 2001 From: rtel Date: Mon, 11 Feb 2019 19:44:13 +0000 Subject: [PATCH] Add makefiles that build the FreedomStudio project (provided by Dornerworks - thanks). git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2627 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../BuildEnvironment.mk | 48 +++++ .../FreeRTOS.mk | 27 +++ .../Makefile | 192 ++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/BuildEnvironment.mk create mode 100644 FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/FreeRTOS.mk create mode 100644 FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/Makefile diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/BuildEnvironment.mk b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/BuildEnvironment.mk new file mode 100644 index 000000000..1ba12e5f3 --- /dev/null +++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/BuildEnvironment.mk @@ -0,0 +1,48 @@ +BUILD_DIR = ./build +CROSS_COMPILE_PREFIX = riscv32-unknown-elf + +SDK_DIR = ./freedom-e-sdk + +LINKER_SCRIPT = $(SDK_DIR)/env/freedom-e300-hifive1/flash.lds +#----------------------------------------------------------- +GCC = $(CROSS_COMPILE_PREFIX)-gcc +OBJCOPY = $(CROSS_COMPILE_PREFIX)-objcopy +OBJDUMP = $(CROSS_COMPILE_PREFIX)-objdump +AR = $(CROSS_COMPILE_PREFIX)-ar +RANLIB = $(CROSS_COMPILE_PREFIX)-ranlib +GDB = $(CROSS_COMPILE_PREFIX)-gdb + +# if using the multi-arch (riscv64-unknown-elf-gcc): +ARCH_FLAGS = -march=rv32imac -mabi=ilp32 -mcmodel=medany +# Basic CFLAGS: +CFLAGS = -Wall -Wextra -O0 -g3 -msmall-data-limit=8 -std=gnu11 +CFLAGS += -ffunction-sections -fdata-sections -fno-builtin-printf +CFLAGS += -DDONT_USE_PLIC -DDONT_USE_M_TIME +CFLAGS += -include sys/cdefs.h +CFLAGS += $(ARCH_FLAGS) +# These flags are for outputing *.d dependency files for make +CFLAGS += -MT"$@" -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" + +ASMFLAGS = -O0 -g3 +ASMFLAGS += $(ARCH_FLAGS) +ASMFLAGS += -DportasmHANDLE_INTERRUPT=handle_trap +ASMFLAGS += -msmall-data-limit=8 +ASMFLAGS += -ffunction-sections -fdata-sections +ASMFLAGS += -x assembler-with-cpp +ASMFLAGS += -MT"$@" -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" + +# Linker arguments __________________________________________ +LDFLAGS := -Xlinker --gc-sections -Xlinker --defsym=__stack_size=1K +LDFLAGS += -O0 -g3 +LDFLAGS += -ffunction-sections -fdata-sections --specs=nano.specs +LDFLAGS += -nostartfiles +LDFLAGS += -T $(LINKER_SCRIPT) +LDFLAGS += -L../ +LDFLAGS += -Wl,--start-group -Wl,--end-group +LDFLAGS += -Wl,--wrap=malloc -Wl,--wrap=free -Wl,--wrap=open -Wl,--wrap=lseek -Wl,--wrap=read -Wl,--wrap=write +LDFLAGS += -Wl,--wrap=fstat -Wl,--wrap=stat -Wl,--wrap=close -Wl,--wrap=link -Wl,--wrap=unlink -Wl,--wrap=execve +LDFLAGS += -Wl,--wrap=fork -Wl,--wrap=getpid -Wl,--wrap=kill -Wl,--wrap=wait -Wl,--wrap=isatty -Wl,--wrap=times +LDFLAGS += -Wl,--wrap=sbrk -Wl,--wrap=_exit -Wl,--wrap=puts -Wl,--wrap=_malloc -Wl,--wrap=_free -Wl,--wrap=_open +LDFLAGS += -Wl,--wrap=_lseek -Wl,--wrap=_read -Wl,--wrap=_write -Wl,--wrap=_fstat -Wl,--wrap=_stat -Wl,--wrap=_close +LDFLAGS += -Wl,--wrap=_link -Wl,--wrap=_unlink -Wl,--wrap=_execve -Wl,--wrap=_fork -Wl,--wrap=_getpid -Wl,--wrap=_kill +LDFLAGS += -Wl,--wrap=_wait -Wl,--wrap=_isatty -Wl,--wrap=_times -Wl,--wrap=_sbrk -Wl,--wrap=__exit -Wl,--wrap=_puts diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/FreeRTOS.mk b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/FreeRTOS.mk new file mode 100644 index 000000000..e0de449dd --- /dev/null +++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/FreeRTOS.mk @@ -0,0 +1,27 @@ +-include BuildEnvironment.mk + +FREERTOS_DIR = ../.. +FREERTOS_SOURCE_DIR = $(FREERTOS_DIR)/Source + +FREERTOS_SRC = \ + $(FREERTOS_SOURCE_DIR)/croutine.c \ + $(FREERTOS_SOURCE_DIR)/list.c \ + $(FREERTOS_SOURCE_DIR)/queue.c \ + $(FREERTOS_SOURCE_DIR)/tasks.c \ + $(FREERTOS_SOURCE_DIR)/timers.c \ + $(FREERTOS_SOURCE_DIR)/event_groups.c \ + $(FREERTOS_SOURCE_DIR)/stream_buffer.c \ + $(FREERTOS_SOURCE_DIR)/portable/MemMang/heap_4.c + +FREERTOS_INC = $(FREERTOS_SOURCE_DIR)/include + +FREERTOS_INCLUDES := \ + -I $(FREERTOS_INC) + +INTERRUPT_HANDLER = main_blinky + +FREERTOS_BUILD_DIR = $(BUILD_DIR)/FreeRTOS +FREERTOS_OBJS = $(patsubst %.c,$(FREERTOS_BUILD_DIR)/%.o,$(notdir $(FREERTOS_SRC))) +VPATH += \ + $(FREERTOS_SOURCE_DIR) \ + $(FREERTOS_SOURCE_DIR)/portable/MemMang diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/Makefile b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/Makefile new file mode 100644 index 000000000..1625da5c3 --- /dev/null +++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/Makefile @@ -0,0 +1,192 @@ +PROJ_NAME ?= simple + +include BuildEnvironment.mk +include FreeRTOS.mk +-include $(wildcard $(OUTDIR)/*.d) +# Platform spcific settings for this application _____________________________________________ + +ARCH = RISC-V-RV32 +ARCH_PORTABLE_INC = $(FREERTOS_SOURCE_DIR)/portable/GCC/$(ARCH)/ +ARCH_PORTABLE_SRC = $(FREERTOS_SOURCE_DIR)/portable/GCC/$(ARCH)/port.c +ARCH_PORTABLE_ASM = $(FREERTOS_SOURCE_DIR)/portable/GCC/$(ARCH)/portASM.S + +SDK_SRC := \ + $(SDK_DIR)/libwrap/sys/_exit.c \ + $(SDK_DIR)/libwrap/sys/close.c \ + $(SDK_DIR)/libwrap/sys/execve.c \ + $(SDK_DIR)/libwrap/sys/fork.c \ + $(SDK_DIR)/libwrap/sys/fstat.c \ + $(SDK_DIR)/libwrap/sys/getpid.c \ + $(SDK_DIR)/libwrap/sys/isatty.c \ + $(SDK_DIR)/libwrap/sys/kill.c \ + $(SDK_DIR)/libwrap/sys/link.c \ + $(SDK_DIR)/libwrap/sys/lseek.c \ + $(SDK_DIR)/libwrap/sys/openat.c \ + $(SDK_DIR)/libwrap/sys/puts.c \ + $(SDK_DIR)/libwrap/sys/read.c \ + $(SDK_DIR)/libwrap/sys/sbrk.c \ + $(SDK_DIR)/libwrap/sys/stat.c \ + $(SDK_DIR)/libwrap/sys/times.c \ + $(SDK_DIR)/libwrap/sys/unlink.c \ + $(SDK_DIR)/libwrap/sys/wait.c \ + $(SDK_DIR)/libwrap/sys/write.c \ + $(SDK_DIR)/libwrap/stdlib/malloc.c \ + $(SDK_DIR)/libwrap/misc/write_hex.c \ + $(SDK_DIR)/env/freedom-e300-hifive1/init.c \ + $(SDK_DIR)/drivers/plic/plic_driver.c \ + $(SDK_DIR)/drivers/fe300prci/fe300prci_driver.c + +SDK_ASM := \ + $(SDK_DIR)/env/entry.S \ + $(SDK_DIR)/env/start.S +SDK_OBJS := $(patsubst %.c,$(FREERTOS_BUILD_DIR)/%.o,$(notdir $(SDK_SRC))) +SDK_OBJS += $(patsubst %.S,$(FREERTOS_BUILD_DIR)/%.o,$(notdir $(SDK_ASM))) +VPATH += \ + $(SDK_DIR)/env \ + $(SDK_DIR)/env/freedom-e300-hifive1 \ + $(SDK_DIR)/libwrap/sys \ + $(SDK_DIR)/libwrap/misc \ + $(SDK_DIR)/libwrap/stdlib \ + $(SDK_DIR)/drivers/plic \ + $(SDK_DIR)/drivers/fe300prci + +PORT_OBJS := $(patsubst %.c,$(FREERTOS_BUILD_DIR)/%.o,$(notdir $(ARCH_PORTABLE_SRC))) +PORT_OBJS += $(patsubst %.S,$(FREERTOS_BUILD_DIR)/%.o,$(notdir $(ARCH_PORTABLE_ASM))) +FREERTOS_OBJS += $(PORT_OBJS) $(SDK_OBJS) +VPATH += $(FREERTOS_SOURCE_DIR)/portable/GCC/$(ARCH) + + +CFLAGS += -DportasmHANDLE_INTERRUPT=$(INTERRUPT_HANDLER) + +# Set up application source, include, and object files for compilation: ______________________ +APP_SRC_DIR = . +APP_SRC = \ + $(APP_SRC_DIR)/main.c \ + $(APP_SRC_DIR)/blinky_demo/main_blinky.c \ + $(APP_SRC_DIR)/full_demo/main_full.c + +APP_ASM = \ + $(APP_SRC_DIR)/full_demo/RegTest.S + +APP_INCLUDES = \ + -I ./ \ + -I $(SDK_DIR)/include \ + -I $(SDK_DIR)/env/freedom-e300-hifive1 \ + -I $(SDK_DIR)/env \ + -I $(FREERTOS_INC) \ + -I $(ARCH_PORTABLE_INC) \ + -I $(FREERTOS_DIR)/Demo/Common/include + +APP_BUILD_DIR = $(BUILD_DIR)/app +APP_OBJS := $(patsubst %.c,$(APP_BUILD_DIR)/%.o,$(notdir $(APP_SRC))) +APP_OBJS += $(patsubst %.S,$(APP_BUILD_DIR)/%.o,$(notdir $(APP_ASM))) +VPATH += \ + $(APP_SRC_DIR)/blinky_demo \ + $(APP_SRC_DIR)/full_demo \ + $(APP_SRC_DIR) + +DEMO_COMMON_SRC = \ + $(FREERTOS_DIR)/Demo/Common/Minimal/EventGroupsDemo.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/TimerDemo.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/TaskNotify.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/GenQTest.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/blocktim.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/dynamic.c \ + $(FREERTOS_DIR)/Demo/Common/Minimal/recmutex.c + +DEMO_COMMON_OBJS := $(patsubst %.c,$(APP_BUILD_DIR)/%.o,$(notdir $(DEMO_COMMON_SRC))) +VPATH += $(FREERTOS_DIR)/Demo/Common/Minimal + +OUT_ELF = $(BUILD_DIR)/FreeRTOS-$(PROJ_NAME).elf + +# Need to tell FreeRTOS where to find the FreeRTOSConfig.h __________________________________ +FREERTOS_INCLUDES += \ + -I ./ \ + -I $(ARCH_PORTABLE_INC) \ + -I $(SDK_DIR)/include \ + -I $(SDK_DIR)/env/freedom-e300-hifive1 \ + -I $(SDK_DIR)/env \ + -I $(SDK_DIR)/drivers \ + -I $(FREERTOS_DIR)/Demo/Common/include \ + -I $(FREERTOS_SOURCE_DIR)/portable/GCC/RISC-V-RV32/chip_specific_extensions/RV32I_CLINT_no_extensions + +# List of object files to compile for the system: +OUT_OBJS = \ + $(APP_OBJS) \ + $(DEMO_COMMON_OBJS) \ + $(FREERTOS_OBJS) + +BUILD_DIRECTORIES = \ + $(APP_BUILD_DIR) \ + $(FREERTOS_BUILD_DIR) + +LDFLAGS += -Wl,-Map,"$(BUILD_DIR)/$(PROJ_NAME).map" + +.PHONY: debug clean app_compile debug-app frtos_compile print-info out_elf sim-qemu gdb +all: directories $(OUT_OBJS) $(OUT_ELF) +directories: $(BUILD_DIRECTORIES) +app_compile: directories $(APP_OBJS) +frtos_compile: directories $(FREERTOS_OBJS) +out_elf: directories $(OUT_ELF) + +# Notes +# Each "Module" needs +# - Lists of source files +# - Source Directory(ies) +# - Include Directory List (with -I prepending each entry) +# - Build Directory +# - Object list +# - OBJS = $(patsubst %.c,$(MODULE_BUILD_DIR)/%.o,$(notdir $(MODULE_SRC))) +# - Add source direcories to VPATH +# In the master make file +# - Module build directory must be created +# - Object Rules can be done with +# - $(MODULE_BUILD_DIR)/%.o : %.c + +# Compile Object Files ____________________________________________________________________ +$(APP_BUILD_DIR)/%.o : %.c + @echo "[APP Objects] : $@ ______________________________________________________________" + @echo "Building: $<" + $(GCC) $(CFLAGS) $(APP_INCLUDES) -o $@ -c $< + @echo "Finished Building: $<" + +$(APP_BUILD_DIR)/%.o : %.S + @echo "[APP Objects] : $@ ______________________________________________________________" + @echo "Building: $<" + $(GCC) $(ASMFLAGS) $(APP_INCLUDES) $(FREERTOS_INCLUDES) -o $@ -c $< + @echo "Finished Building: $<" + +$(FREERTOS_BUILD_DIR)/%.o : %.c + @echo "[FreeRTOS Objects] : $@ __________________________________________________________" + @echo "Building: $<" + $(GCC) $(CFLAGS) $(FREERTOS_INCLUDES) -o $@ -c $< + @echo "Finished Building: $<" + +$(FREERTOS_BUILD_DIR)/%.o : %.S + @echo "[FreeRTOS Objects] : $@ __________________________________________________________" + @echo "Building: $<" + $(GCC) $(ASMFLAGS) $(FREERTOS_INCLUDES) -o $@ -c $< + @echo "Finished Building: $<" + +# Generate ELF ___________________________________________________________________________ +$(OUT_ELF): $(OUT_OBJS) + @echo '___________________________________________________________________________________' + @echo 'Building target: $@' + @echo '_______________________________' + $(GCC) $(LDFLAGS) $(LDOPTS) -o $@ $(OUT_OBJS) $(LIB_FLAGS) + @echo 'Finished building target: $@' + @echo ' ' + +.PHONY: build_lib + +$(BUILD_DIRECTORIES): + mkdir -p $@ + +clean: + rm -rv $(BUILD_DIR) + +sim-qemu: $(OUT_ELF) + qemu-system-riscv32 -kernel $^ -S -s -machine sifive_e + +gdb: $(OUT_ELF) + $(GDB) -iex "set mem inaccessible-by-default off" -iex "set arch riscv:rv32" -iex "set riscv use_compressed_breakpoint off" -- 2.39.5