Skip to content

Commit

Permalink
missing EXTERNAL CRT0 define (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseCalero authored Oct 4, 2024
1 parent 83f1563 commit 2c6d7d8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ verible:
## @param COMPILER_PREFIX=riscv32-unknown-(default)
## @param ARCH=rv32imc(default), <any RISC-V ISA string supported by the CPU>
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; \
}

Expand Down
58 changes: 42 additions & 16 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# Author: Juan Sapriza ([email protected])
# Author: Jose Miranda, Juan Sapriza (jose.mirandacalero / juan.sapriza @epfl.ch)

cmake_minimum_required(VERSION 3.15)

Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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)


Expand All @@ -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
#######################################################################
Expand All @@ -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()
Expand Down Expand Up @@ -262,6 +281,7 @@ else()
message( FATAL_ERROR "Linker specification is not correct" )
endif()

if (${VERBOSE} MATCHES "true")
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Debug messages to check the paths

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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/<relative path>
Expand All @@ -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()
Expand Down
14 changes: 9 additions & 5 deletions sw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# Author: Juan Sapriza ([email protected])
# Author: Jose Miranda, Juan Sapriza (jose.mirandacalero / juan.sapriza @epfl.ch)

MAKE = make

Expand All @@ -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-
Expand All @@ -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)/
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions sw/cmake/targets.mak
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# Author: Juan Sapriza ([email protected])
# 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 \
Expand All @@ -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:
Expand Down

0 comments on commit 2c6d7d8

Please sign in to comment.