From fddf6084184fe1f6305ca7ab1ebe87d08db06d8f Mon Sep 17 00:00:00 2001 From: Hongyu Liu Date: Fri, 20 Dec 2024 14:33:57 +0100 Subject: [PATCH] first version of working cmake --- CMakeLists.txt | 26 +++++++++++----------- bare-metal-bsp | 2 +- hello-world/CMakeLists.txt | 44 +++++++++++++++++++++++--------------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab87c75..f382307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ if(NOT DEFINED BOARD) endif() if(NOT DEFINED ISA) - set(ISA imc CACHE STRING "Target ISA") + set(ISA rv32imc CACHE STRING "Target ISA") endif() if(NOT DEFINED RISCV_ABI) @@ -69,7 +69,7 @@ if(NOT BOARD IN_LIST SUPPORTED_BOARDS) endif() if(NOT ISA IN_LIST SUPPORTED_ISAS) - message(FATAL_ERROR "Invalid ISA specified. Supported ISAs: ${SUPPORTED_ISAS}") + message(FATAL_ERROR "Invalid ISA specified(${ISA}). Supported ISAs: ${SUPPORTED_ISAS}") endif() if(NOT RISCV_ABI IN_LIST SUPPORTED_ABIS) @@ -91,8 +91,10 @@ set(BSP_BASE "${CMAKE_CURRENT_SOURCE_DIR}/bare-metal-bsp") add_compile_definitions(BOARD_${BOARD}) # RISC-V specific compiler flags -#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany") +#set(CMAKE_ASM_COMPILER riscv64-unknown-elf-as) +set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany") # Optional: Enable semihosting support option(SEMIHOSTING "Enable semihosting support" OFF) @@ -101,18 +103,18 @@ if(SEMIHOSTING) endif() #create interface library for propagating compile options -add_library(global_compile_options INTERFACE) +#add_library(global_compile_options INTERFACE) # Compile options -target_compile_options(global_compile_options INTERFACE - -march=${RISCV_ARCH}_zicsr_zifencei - -mabi=${RISCV_ABI} - -mcmodel=medany - -O2 - -g +#target_compile_options(global_compile_options INTERFACE +# -march=${RISCV_ARCH}_zicsr_zifencei + # -mabi=${RISCV_ABI} + # -mcmodel=medany + # -O2 + # -g # -ffunction-sections # -fdata-sections -) +#) diff --git a/bare-metal-bsp b/bare-metal-bsp index 87dc0ec..f419b1a 160000 --- a/bare-metal-bsp +++ b/bare-metal-bsp @@ -1 +1 @@ -Subproject commit 87dc0ec2304adcb94a25b397a357aadae1304867 +Subproject commit f419b1a3e6e9e8075d7e937ac5b1e1fb4829a976 diff --git a/hello-world/CMakeLists.txt b/hello-world/CMakeLists.txt index af71120..b1db947 100644 --- a/hello-world/CMakeLists.txt +++ b/hello-world/CMakeLists.txt @@ -6,9 +6,6 @@ if(NOT DEFINED BOARD) set(BOARD "iss" CACHE STRING "Target board") endif() -#set(BSP_BASE "${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp") - - # Source files set(SOURCES @@ -21,19 +18,19 @@ message(STATUS "Using board-specific files from: ${BSP_BASE}/env/${BOARD}") # Create executable with all objects add_executable(${PROJECT_NAME} - ${SOURCES} - ${BSP_OBJECTS} - + ${SOURCES} ) +set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf") + # Link with board library -target_link_libraries(${PROJECT_NAME} PRIVATE - ${LIBWRAP_OBJECTS} - ${ENV_OBJECTS} - #$ - #$ - ) +#target_link_libraries(${PROJECT_NAME} PRIVATE +# libwrap +# ${BOARD} +# $ +# #$ +# ) # Include directories target_include_directories(${PROJECT_NAME} PRIVATE @@ -49,14 +46,27 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE BOARD_${BOARD} ) -# link global_compile_options to this target -target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) +# link global_compile_options to this target ???? +#target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) + +get_target_property(WRAP_LIBRARY_PATH libwrap ARCHIVE_OUTPUT_DIRECTORY) +get_target_property(BOARDLIBRARY_PATH ${BOARD} ARCHIVE_OUTPUT_DIRECTORY) +## TODDO ??? +set(ASM_OBJ_LIB "${BOARDLIBRARY_PATH}/CMakeFiles/asm_obj.dir") + +message(STATUS "in hello_world WRAP_LIBRARY_PATH : ${WRAP_LIBRARY_PATH}, BOARDLIBRARY_PATH : ${BOARDLIBRARY_PATH} ASM_OBJ_LIB: ${ASM_OBJ_LIB} ") # Set linker options target_link_options(${PROJECT_NAME} PRIVATE - -T${BSP_BASE}/env/${BOARD}/link.ld - -nostartfiles - -Wl,--gc-sections + --verbose + -L${ASM_OBJ_LIB} + -L${WRAP_LIBRARY_PATH} + -L${BOARDLIBRARY_PATH} + ${ASM_OBJ_LIB}/start.S.o + ${ASM_OBJ_LIB}/entry.S.o + -L/scratch/hongyu/workarea/Firmwares/build/bare-metal-bsp/env/CMakeFiles/asm_obj.dir + -g -Wl,--wrap=printf -march=rv32imc -mabi=ilp32 -L../bare-metal-bsp/env/ -Wl,--wrap=malloc -Wl,--wrap=open -Wl,--wrap=lseek -Wl,--wrap=_lseek -Wl,--wrap=read -Wl,--wrap=_read -Wl,--wrap=write -Wl,--wrap=_write -Wl,--wrap=fstat -Wl,--wrap=_fstat -Wl,--wrap=stat -Wl,--wrap=close -Wl,--wrap=_close -Wl,--wrap=link -Wl,--wrap=unlink -Wl,--wrap=execve -Wl,--wrap=fork -Wl,--wrap=getpid -Wl,--wrap=kill -Wl,--wrap=wait -Wl,--wrap=isatty -Wl,--wrap=times -Wl,--wrap=sbrk -Wl,--wrap=_sbrk -Wl,--wrap=exit -Wl,--wrap=_exit -Wl,--wrap=puts -Wl,--wrap=_puts -Wl,--wrap=printf -Wl,--wrap=sprintf -L. -Wl,--start-group -llibwrap -liss -lc -Wl,--end-group -T /scratch/hongyu/workarea/Firmwares/bare-metal-bsp/env/iss/link.lds -Wl,--no-warn-rwx-segments -Wl,-Map=hello.map -nostartfiles -o hello.elf + ) # Install target