From f419b1a3e6e9e8075d7e937ac5b1e1fb4829a976 Mon Sep 17 00:00:00 2001 From: Hongyu Liu Date: Fri, 20 Dec 2024 14:27:45 +0100 Subject: [PATCH] first version of working cmake --- CMakeLists.txt | 3 +- env/CMakeLists.txt | 79 +++++++++++++++++++++++++++--------------- env/iss/CMakeLists.txt | 4 +++ env/iss/write.c | 38 ++++++++++++++++++++ env/start.S | 1 + libwrap/CMakeLists.txt | 24 +++++++++---- 6 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 env/iss/write.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 706a938..3020744 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.12) project(bsp C) add_subdirectory(libwrap) -message(STATUS " liu here") +add_subdirectory(env) +message(STATUS " in bsp with ${CMAKE_CXX_FLAGS}") message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}") add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE diff --git a/env/CMakeLists.txt b/env/CMakeLists.txt index f5db5e1..fbd19d6 100644 --- a/env/CMakeLists.txt +++ b/env/CMakeLists.txt @@ -1,39 +1,64 @@ -project(bsp_env) -message(STATUS " here in bsp_env") +project(env) +message(STATUS " here in bsp/env") +message(STATUS " BOARD: ${BOARD}") # Enable ASM language enable_language(ASM) -set(LIB_SOURCES +set(ASM_SOURCES entry.S start.S ) - -# Set ASM compile options -set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") - - -add_library(asm_obj OBJECT ${LIB_SOURCES}) -add_subdirectory(${BOARD}) - - - - - - - -# Include the ISS board configuration -set(ISS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/bare-metal-bsp/env/iss") -set(ISS_BINARY_DIR "${CMAKE_BINARY_DIR}/iss_build") - -add_subdirectory(${ISS_SOURCE_DIR} ${ISS_BINARY_DIR}) - - +add_library(asm_obj OBJECT ${ASM_SOURCES}) +set_target_properties(asm_obj PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME}) +target_include_directories(asm_obj PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${BSP_BASE}/include + #include/ + ${BSP_BASE}/env + ${BSP_BASE}/env/${BOARD} + ${BSP_BASE}/drivers +) # Export variables for hello-world to use set(ENV_OBJECTS - $ - $ + $ + PARENT_SCOPE ) + +set(BOARD_LIB_NAME ${BOARD}) +message(STATUS " BOARD_LIB_NAME: ${BOARD_LIB_NAME}") +set(BOARD_LIB_SRC + ${BOARD}/init.c + ${BOARD}/write.c +) +add_library(${BOARD_LIB_NAME} STATIC ${BOARD_LIB_SRC}) +set_target_properties(${BOARD_LIB_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME}) + +# Set ASM compile options +#set(CMAKE_ASM_COMPILER riscv64-unknown-elf-as) +#set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") + +#add_subdirectory(${BOARD}) + + + +target_include_directories(${BOARD_LIB_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${BSP_BASE}/include + ${BSP_BASE}/libwrap/sys + ${BSP_BASE}/env + ${BSP_BASE}/env/${BOARD} + ${BSP_BASE}/drivers +) + +# Include the ISS board configuration +#set(ISS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/bare-metal-bsp/env/iss") +#set(ISS_BINARY_DIR "${CMAKE_BINARY_DIR}/iss_build") + +#add_subdirectory(${ISS_SOURCE_DIR} ${ISS_BINARY_DIR}) + + + # Export board library -set(BOARD_LIB board_iss PARENT_SCOPE) +#set(BOARD_LIB board_iss PARENT_SCOPE) diff --git a/env/iss/CMakeLists.txt b/env/iss/CMakeLists.txt index 994cd87..f914f9b 100644 --- a/env/iss/CMakeLists.txt +++ b/env/iss/CMakeLists.txt @@ -1,3 +1,7 @@ +#cmake_minimum_required(VERSION 3.12) +project(iss) +message(STATUS " here in iss") + # Create library for ISS board support add_library(board_iss STATIC init.c diff --git a/env/iss/write.c b/env/iss/write.c new file mode 100644 index 0000000..9010703 --- /dev/null +++ b/env/iss/write.c @@ -0,0 +1,38 @@ +/* See LICENSE of license details. */ + +#include +#include +#include +#include + +#include "platform.h" +#include "stub.h" +#include "weak_under_alias.h" +#if defined(SEMIHOSTING) +#include "semihosting.h" +#endif + +ssize_t __wrap_write(int fd, const void *ptr, size_t len) { + const uint8_t *current = (const uint8_t *)ptr; +#if defined(SEMIHOSTING) + if (isatty(fd)) { + for (size_t jj = 0; jj < len; jj++) { + sh_writec(current[jj]); + } + return len; + } else { + sh_write(current, fd); + return len; + } + // return len; +#endif + if (isatty(fd)) { + for (size_t jj = 0; jj < len; jj++) { + *((uint32_t *)0xFFFF0000) = current[jj]; + } + return len; + } + + return _stub(EBADF); +} +weak_under_alias(write); diff --git a/env/start.S b/env/start.S index 0df91a6..2e839ec 100644 --- a/env/start.S +++ b/env/start.S @@ -1,3 +1,4 @@ +#include "encoding.h" // See LICENSE for license details. .section .init diff --git a/libwrap/CMakeLists.txt b/libwrap/CMakeLists.txt index a998307..81c1e74 100644 --- a/libwrap/CMakeLists.txt +++ b/libwrap/CMakeLists.txt @@ -1,6 +1,9 @@ +#cmake_minimum_required(VERSION 3.12) project(libwrap) message(STATUS " here 2 in libwrap") +set(LIBRARY_NAME libwrap) +set(STATIC_LIBRARY_FLAGS "rcs") # Create object library for libwrap set(LIB_SOURCES @@ -24,7 +27,7 @@ set(LIB_SOURCES sys/times.c sys/unlink.c sys/wait.c - sys/write.c + # sys/write.c # Standard library stdlib/malloc.c # Miscellaneous @@ -38,11 +41,20 @@ if(SEMIHOSTING) endif() -add_library(${PROJECT_NAME} OBJECT ${LIB_SOURCES}) +#add_library(${LIBRARY_NAME} OBJECT ${LIB_SOURCES}) +add_library(${LIBRARY_NAME} STATIC ${LIB_SOURCES}) +set_target_properties(${LIBRARY_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME}) +message(STATUS " CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + +# Retrieve the output directory for the library +get_target_property(LIBRARY_PATH ${LIBRARY_NAME} ARCHIVE_OUTPUT_DIRECTORY) + +# Print the path to the console (for debugging purposes) +message(STATUS "The library output path is: ${LIBRARY_PATH}") # Include directories -target_include_directories(${PROJECT_NAME} PRIVATE +target_include_directories(${LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${BSP_BASE}/include include/ @@ -51,10 +63,10 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${BSP_BASE}/drivers ) -# Compile options + #link global_compile_options to this libraries -target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) +#target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) # Compile definitions #target_compile_definitions(libwrap_objects PRIVATE @@ -62,4 +74,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) #) # Export objects to parent scope -set(LIBWRAP_OBJECTS $ PARENT_SCOPE) +#set(LIBWRAP_OBJECTS $ PARENT_SCOPE)