From 2c6d7d8f581020d4961bd08dbd3956c90b676085 Mon Sep 17 00:00:00 2001 From: jmiranda Date: Fri, 4 Oct 2024 09:54:07 +0200 Subject: [PATCH] missing EXTERNAL CRT0 define (#592) --- Makefile | 12 ++++----- sw/CMakeLists.txt | 58 ++++++++++++++++++++++++++++++++------------ sw/Makefile | 14 +++++++---- sw/cmake/targets.mak | 10 ++++---- 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index f65c4640b..e1c6deacf 100644 --- a/Makefile +++ b/Makefile @@ -150,13 +150,13 @@ verible: ## @param COMPILER_PREFIX=riscv32-unknown-(default) ## @param ARCH=rv32imc(default), app: clean-app - $(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) LINK_FOLDER=$(LINK_FOLDER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) ARCH=$(ARCH) SOURCE=$(SOURCE) \ + @$(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) LINK_FOLDER=$(LINK_FOLDER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) ARCH=$(ARCH) SOURCE=$(SOURCE) \ || { \ - echo "\033[0;31mHmmm... seems like the compilation failed...\033[0m"; \ - echo "\033[0;31mIf you do not understand why, it is likely that you either:\033[0m"; \ - echo "\033[0;31m a) offended the Leprechaun of Electronics\033[0m"; \ - echo "\033[0;31m b) forgot to run make mcu-gen\033[0m"; \ - echo "\033[0;31mI would start by checking b) if I were you!\033[0m"; \ + @echo "\033[0;31mHmmm... seems like the compilation failed...\033[0m"; \ + @echo "\033[0;31mIf you do not understand why, it is likely that you either:\033[0m"; \ + @echo "\033[0;31m a) offended the Leprechaun of Electronics\033[0m"; \ + @echo "\033[0;31m b) forgot to run make mcu-gen\033[0m"; \ + @echo "\033[0;31mI would start by checking b) if I were you!\033[0m"; \ exit 1; \ } diff --git a/sw/CMakeLists.txt b/sw/CMakeLists.txt index cdb2a8f76..adc4546eb 100644 --- a/sw/CMakeLists.txt +++ b/sw/CMakeLists.txt @@ -13,7 +13,7 @@ # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -# Author: Juan Sapriza (juan.sapriza@epfl.ch) +# Author: Jose Miranda, Juan Sapriza (jose.mirandacalero / juan.sapriza @epfl.ch) cmake_minimum_required(VERSION 3.15) @@ -154,7 +154,9 @@ ENDFOREACH() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # If the app was not found, look into the root project +# Before re-setting SOURCE_PATH, save it so we can look later for external defined files +SET(ORIGIN_SRCPATH ${SOURCE_PATH}) if( app_found EQUAL 0 ) SET(SOURCE_PATH ${ROOT_PROJECT}) @@ -185,9 +187,9 @@ if( app_found EQUAL 0 ) string(REPLACE ";" "" c_dir_list ${c_dir_list}) endif() - ENDFOREACH() - endif() - + ENDFOREACH() +endif() + LIST(REMOVE_DUPLICATES c_dir_list) @@ -204,6 +206,11 @@ else() message( "${Magenta}External application${ColourReset}") endif() +####################################################################### +# ADD CUSTOM DEFINITIONS +####################################################################### +add_compile_definitions($ENV{CDEFS}) + ####################################################################### # FIND CRT FILES TO BE INCLUDED ####################################################################### @@ -219,15 +226,27 @@ SET(LIB_VCTR_P "${ROOT_PROJECT}device/lib/crt/vectors.S") SET(CRTO "INTERNAL_CRTO") SET( LIB_CRT_EXT_P "" ) -if( internal_app EQUAL 0 ) - FILE(GLOB_RECURSE new_list FOLLOW_SYMLINKS "${SOURCE_PATH}/external/lib/crt/*.S") +FILE(GLOB_RECURSE new_list FOLLOW_SYMLINKS "${SOURCE_PATH}/external/lib/crt/*.S") +FOREACH(file_path IN LISTS new_list) + if(${file_path} MATCHES "external_crt0.S") + SET( CRTO "EXTERNAL_CRTO" ) + SET( LIB_CRT_EXT_P "${file_path}" ) + GET_FILENAME_COMPONENT(dir_path ${file_path} PATH) + SET(INCLUDE_FOLDERS "${INCLUDE_FOLDERS} -I ${dir_path}") + SET(h_dir_list_ ${h_dir_list_} "${dir_path}") + endif() +ENDFOREACH() + +#In case the application is internal, but there is still an external CRT +if(NOT ${ORIGIN_SRCPATH} MATCHES ${SOURCE_PATH}) + FILE(GLOB_RECURSE new_list FOLLOW_SYMLINKS "${ORIGIN_SRCPATH}external/lib/crt/*.S") FOREACH(file_path IN LISTS new_list) if(${file_path} MATCHES "external_crt0.S") - SET( CRTO "EXTERNAL_CRTO" ) - SET( LIB_CRT_EXT_P "${file_path}" ) - GET_FILENAME_COMPONENT(dir_path ${file_path} PATH) - SET(INCLUDE_FOLDERS "${INCLUDE_FOLDERS} -I ${dir_path}") - SET(h_dir_list_ ${h_dir_list_} "${dir_path}") + SET( CRTO "EXTERNAL_CRTO" ) + SET( LIB_CRT_EXT_P "${file_path}" ) + GET_FILENAME_COMPONENT(dir_path ${file_path} PATH) + SET(INCLUDE_FOLDERS "${INCLUDE_FOLDERS} -I ${dir_path}") + SET(h_dir_list_ ${h_dir_list_} "${dir_path}") endif() ENDFOREACH() endif() @@ -262,6 +281,7 @@ else() message( FATAL_ERROR "Linker specification is not correct" ) endif() +if (${VERBOSE} MATCHES "true") # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Debug messages to check the paths @@ -271,10 +291,10 @@ message( "${Magenta}Root project: ${ROOT_PROJECT}${ColourReset}") message( "${Magenta}Source path: ${SOURCE_PATH}${ColourReset}") message( "${Magenta}LIB_CRT PATH for Cmake: ${LIB_CRT_P}${ColourReset}") message( "${Magenta}LINKER File for Cmake: ${LINK_FILE}${ColourReset}") -message( "${Magenta}LIB_DRIVERS PATH for Cmake: ${LIB_DRIVERS}${ColourReset}") -message( "${Magenta}Targetting folder: ${INC_FOLDERS}${ColourReset}") message( "${Magenta}Target: ${TARGET}${ColourReset}") +endif() + ####################################################################### # SET LINKER PROPERTIES @@ -289,7 +309,9 @@ SET(LINKED_FILES "${LIB_CRT_P} \ ${LIB_CRT_EXT_P} \ ${c_dir_list}") -message( "${Magenta}Linked files: ${LINKED_FILES}${ColourReset}") +if (${VERBOSE} MATCHES "true") + message( "${Magenta}Linked files: ${LINKED_FILES}${ColourReset}") +endif() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Free-RTOS configurations @@ -413,7 +435,11 @@ SET(CMAKE_EXE_LINKER_FLAGS "-T ${LINKER_SCRIPT} \ -ffunction-sections -fdata-sections -specs=nano.specs") message( "${Magenta}Lib Folder RISCV-GCC: ${RISCV}/${COMPILER_PREFIX}elf/lib${ColourReset}") -SET(CMAKE_VERBOSE_MAKEFILE on) +if (${VERBOSE} MATCHES "true") + SET(CMAKE_VERBOSE_MAKEFILE ON) +else() + SET(CMAKE_VERBOSE_MAKEFILE OFF) +endif() # To make sure that .obj files are created and fetched from the same path. # When setting an inner path to add_executable, .obj files are stored in ${MAINFILE}.elf.dir/ @@ -434,7 +460,7 @@ if (${COMPILER} MATCHES "clang") _deps/freertos_kernel-build/libfreertos_kernel.a \ _deps/freertos_kernel-build/portable/libfreertos_kernel_port.a \ _deps/freertos_kernel-build/libfreertos_kernel.a \ _deps/freertos_kernel-build/portable/libfreertos_kernel_port.a \ ") else() - set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_LINKER} ${COMPILER_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS} \ + set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_LINKER} ${COMPILER_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS} \ ${SOURCE_PATH}build/CMakeFiles/${MAINFILE}.elf.dir/${OBJ_PATH}applications/${PROJECT}/${MAINFILE}.c.obj \ -o ${MAINFILE}.elf") endif() diff --git a/sw/Makefile b/sw/Makefile index e327138b5..e0fa1ff19 100644 --- a/sw/Makefile +++ b/sw/Makefile @@ -15,7 +15,7 @@ # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -# Author: Juan Sapriza (juan.sapriza@epfl.ch) +# Author: Jose Miranda, Juan Sapriza (jose.mirandacalero / juan.sapriza @epfl.ch) MAKE = make @@ -40,6 +40,8 @@ ARCH ?= rv32imc # Path relative from the location of sw/Makefile from which to fetch source files. The directory of that file is the default value. SOURCE ?= $(".") +VERBOSE ?= false + # riscv toolchain install path RISCV ?= ~/.riscv RISCV_EXE_PREFIX = $(RISCV)/bin/${COMPILER_PREFIX}elf- @@ -48,13 +50,14 @@ RISCV_GDB_PATH = $(RISCV_EXE_PREFIX)gdb # Get the absolute path mkfile_path := $(shell dirname "$(realpath $(firstword $(MAKEFILE_LIST)))") -# Check the absolute path -$(info $$You are executing from: $(mkfile_path)) - # Get the absolute path of where to fetch sources source_path := $(realpath $(mkfile_path)/$(SOURCE)) -$(info $$You are fetching sources from $(source_path) ) +ifeq ($(ARG), value1) + $(info $$You are executing from: $(mkfile_path)) +else ifeq ($(ARG), value2) + $(info $$You are fetching sources from $(source_path) ) +endif SOURCE_PATH = $(source_path)/ ROOT_PROJECT = $(mkfile_path)/ @@ -64,6 +67,7 @@ LINK_FOLDER ?= $(mkfile_path)/linker # CMake keyword CMAKE_DIR=cmake +# to distinguish between cmake distros ifeq (, $(shell which cmake3)) # cmake3 is not defined CMAKE=cmake else diff --git a/sw/cmake/targets.mak b/sw/cmake/targets.mak index 33ab17773..d7679da5e 100644 --- a/sw/cmake/targets.mak +++ b/sw/cmake/targets.mak @@ -13,17 +13,17 @@ # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -# Author: Juan Sapriza (juan.sapriza@epfl.ch) +# Author: Jose Miranda, Juan Sapriza (jose.mirandacalero / juan.sapriza @epfl.ch) build : build/Makefile @echo Build - ${MAKE} -C build + ${MAKE} -s -C build setup : build/Makefile build/Makefile : CMakeLists.txt ${CMAKE_DIR}/riscv.cmake - if [ ! -d build ] ; then mkdir build ; fi - cd build; \ + @if [ ! -d build ] ; then mkdir build ; fi + @cd build; \ ${CMAKE} \ -G "Unix Makefiles" \ -DCMAKE_TOOLCHAIN_FILE=../${CMAKE_DIR}/riscv.cmake \ @@ -32,11 +32,11 @@ build/Makefile : CMakeLists.txt ${CMAKE_DIR}/riscv.cmake -DTARGET=${TARGET} \ -DPROJECT:STRING=${PROJECT} \ -DRISCV:STRING=${RISCV} \ - -DINC_FOLDERS:STRING=${INC_FOLDERS} \ -DLINK_FOLDER:STRING=${LINK_FOLDER} \ -DLINKER:STRING=${LINKER} \ -DCOMPILER:STRING=${COMPILER} \ -DCOMPILER_PREFIX:STRING=${COMPILER_PREFIX} \ + -DVERBOSE:STRING=${VERBOSE} \ ../ clean: